// Thermal Branch

// - This 'shortcut' script creates an thermal branch under the Project object in
//   the DesignSpace tree, including typical thermal results

// copied from DSConstants.js
//
var id_Temperature                            = 49;
var id_TotalHeatFlux                          = 50;

// make sure there's an active tree object
//
if( DS.Tree )
{
    var MBBT_OK = 0;
    var MBBT_ICONWARNING = 48;
    var buttonType = MBBT_OK + MBBT_ICONWARNING;
    var caption = DS.Script.localString("ID_DesignSpaceWarning");
    var message;
    var branchObj = null;
    var resultObj;
    branchObj = DS.Tree.FirstActiveBranch;
    if( !branchObj )
    {
        message = DS.Script.localString("ID_CannotFindBranch");
        DS.Script.WBScript.Out( message, true, caption, buttonType, this );
    }

    if( branchObj )
    {
        // get the Answers object
        var answersObj = branchObj.AnswerSet;
        if( answersObj )
        {
            var activeId = DS.Tree.FirstActiveObjectID;
            var answersObjId = answersObj.ID;
            DS.Script.changeActiveObject( answersObjId );

            if( DS.GUIState.AnswerSetLayer.CanInsertTemperature() )
            {
                // make sure there's nothing selected
                //
                SM.Clear();
                // add the thermal results to the branch
                //
                resultObj = answersObj.AddResult( SM, id_Temperature );
                resultObj = answersObj.AddResult( SM, id_TotalHeatFlux );

                DS.Script.fillTree();

                WizObj.ShowWizard( "ThermalWizard.xml" );
            }
            else
            {
                //if an error occurs, alert the user that the branch was not added
                var message = DS.Script.localString("ID_InsertOutlineBranchNotValid");
                DS.Script.WBScript.Out( message, true, caption, buttonType, this );
            }

            DS.Script.changeActiveObject( activeId );
        }
    }
}

