// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: January 07, 1997 // // // Description: // Display Control option box script. // // Input Arguments: // bool if true show option box // if false perform command with current values // Return Value: // none // global int $displayControlScopeCount = 5; // // Procedure Name: // setOptionVars // // Description: // Initialize the option values. // // Input Arguments: // Whether to set the options to default values. // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { int $i; global int $displayControlScopeCount; if ($forceFactorySettings || !`optionVar -exists displayControlScope`) { optionVar -intValue displayControlScope 1; } // Edit Points // if ($forceFactorySettings || !`optionVar -exists displayControlEditPoints`) { optionVar -clearArray displayControlEditPoints; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlEditPoints false; } } // Hulls // if ($forceFactorySettings || !`optionVar -exists displayControlHulls`) { optionVar -clearArray displayControlHulls; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlHulls false; } } // CVs // if ($forceFactorySettings || !`optionVar -exists displayControlCVs`) { optionVar -clearArray displayControlCVs; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlCVs false; } } // Normals // if ($forceFactorySettings || !`optionVar -exists displayControlNormals`) { optionVar -clearArray displayControlNormals; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlNormals false; } } // Faces // if ($forceFactorySettings || !`optionVar -exists displayControlSurfaceFace`) { optionVar -clearArray displayControlSurfaceFace; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlSurfaceFace false; } } // Origin // if ($forceFactorySettings || !`optionVar -exists displayControlOrigin`) { optionVar -clearArray displayControlOrigin; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlOrigin false; } } // Selection Handles // if ($forceFactorySettings || !`optionVar -exists displayControlSelectHandles`) { optionVar -clearArray displayControlSelectHandles; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlSelectHandles false; } } // All ON // if ($forceFactorySettings || !`optionVar -exists displayControlAllON`) { optionVar -intValue displayControlAllON false; } // All OFF // if ($forceFactorySettings || !`optionVar -exists displayControlAllOFF`) { optionVar -intValue displayControlAllOFF false; } } // // Procedure Name: // displayControlSetup // // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. // Required so that UI object names can be // successfully resolved. // // forceFactorySettings - Whether the option values should be set to // default values. // // Return Value: // None. // global proc displayControlSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // print ( $parent + "\n" ); // Scope Pop-up // optionMenuGrp -e -sl `optionVar -q displayControlScope` scopePopup; int $index = `optionVar -q displayControlScope`; tabLayout -e -sti $index displayTabs; $index--; // to make it 0-based displayControlSetUpHelper "active_tab" 0; displayControlSetUpHelper "all_tab" 1; displayControlSetUpHelper "NewCurve_tab" 2; if( `isTrue SurfaceUIExists` ) { displayControlSetUpHelper "NewSurface_tab" 3; } } // // Procedure Name: // displayControlCallback // // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // doIt - Whether the command should execute. // // Return Value: // None. // global proc displayControlCallback(string $parent, int $doIt) { global int $displayControlScopeCount; setParent $parent; // Set the optionVar's from the control values, and then perform the command // // Scope Pop-up // int $scopeValue = `optionMenuGrp -q -sl scopePopup`; optionVar -intValue displayControlScope $scopeValue; $scopeValue--; // to make it 0-based // Set the parent to be the current tab // string $currentTab = `tabLayout -q -st displayTabs`; setParent $currentTab; // Set the optionvars for the current tab // int $editPoints[] = `optionVar -q displayControlEditPoints`; $editPoints[$scopeValue] = `checkBoxGrp -q -v1 editPointsCheck`; optionVar -clearArray displayControlEditPoints; int $hulls[] = `optionVar -q displayControlHulls`; $hulls[$scopeValue] = `checkBoxGrp -q -v1 hullsCheck`; optionVar -clearArray displayControlHulls; int $cvs[] = `optionVar -q displayControlCVs`; $cvs[$scopeValue] = `checkBoxGrp -q -v1 CVsCheck`; optionVar -clearArray displayControlCVs; int $normals[] = `optionVar -q displayControlNormals`; if( `isTrue SurfaceUIExists` ) { $normals[$scopeValue] = `checkBoxGrp -q -v1 normalsCheck`; } else { $normals[$scopeValue] = 0; } optionVar -clearArray displayControlNormals; int $sf[] = `optionVar -q displayControlSurfaceFace`; $sf[$scopeValue] = `checkBoxGrp -q -v1 SurfaceFaceCheck`; optionVar -clearArray displayControlSurfaceFace; int $origin[] = `optionVar -q displayControlOrigin`; if( `isTrue SurfaceUIExists` ) { $origin[$scopeValue] = `checkBoxGrp -q -v1 originCheck`; } else { $origin[$scopeValue] = 0; } optionVar -clearArray displayControlOrigin; int $selectHandles[] = `optionVar -q displayControlSelectHandles`; $selectHandles[$scopeValue] = `checkBoxGrp -q -v1 selectHandlesCheck`; optionVar -clearArray displayControlSelectHandles; for ($i = 0; $i < $displayControlScopeCount; $i++) { optionVar -intValueAppend displayControlEditPoints $editPoints[$i]; optionVar -intValueAppend displayControlHulls $hulls[$i]; optionVar -intValueAppend displayControlCVs $cvs[$i]; optionVar -intValueAppend displayControlNormals $normals[$i]; optionVar -intValueAppend displayControlSurfaceFace $sf[$i]; optionVar -intValueAppend displayControlOrigin $origin[$i]; optionVar -intValueAppend displayControlSelectHandles $selectHandles[$i]; } if ($doIt) { performDisplayControl 0; addToRecentCommandQueue "performDisplayControl 0" "DisplayControl"; } } // // Procedure Name: // performDisplayControlOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc displayControlOptions() { // Name of the command for this option box. // string $commandName = "displayControl"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // STEP 1: Get the option box. // ============================ // // The value returned is the name of the layout to be used as // the parent for the option box UI. // string $layout = getOptionBox(); setParent $layout; // STEP 2: Pass the command name to the option box - see STEP 8. // ============================================================== // STEP 3: Activate the default UI template. // ========================================== // // Activate the default UI template so that the layout of this // option box is consistent with the layout of the rest of the // application. // setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; optionMenuGrp -label (uiRes("m_performDisplayControl.kScope")) -cc displayControlEditOptions scopePopup; menuItem -label (uiRes("m_performDisplayControl.kActiveObjects")) activeMenuItem; menuItem -label (uiRes("m_performDisplayControl.kAllObjects")) allMenuItem; menuItem -label (uiRes("m_performDisplayControl.kNewCurves")) newCrvMenuItem; if( `isTrue SurfaceUIExists` ) { menuItem -label (uiRes("m_performDisplayControl.kNewSurfaces")) newSrfMenuItem; } setParent -m ..; // // Create tabs for all the buttons but only show one set of buttons // Buttons displayed will change based on the menu above // tabLayout -tabsVisible false displayTabs; columnLayout active_tab; displayControlBuildButtons (`setParent -query`); setParent ..; columnLayout all_tab; displayControlBuildButtons (`setParent -query`); setParent ..; columnLayout NewCurve_tab; displayControlBuildButtons (`setParent -query`); setParent ..; columnLayout NewSurface_tab; displayControlBuildButtons (`setParent -query`); setParent ..; setParent ..; setParent; tabLayout -e -tl active_tab (uiRes("m_performDisplayControl.kActiveTab")) -tl all_tab (uiRes("m_performDisplayControl.kAllTab")) -tl NewCurve_tab (uiRes("m_performDisplayControl.kCurvesTab")) -tl NewSurface_tab (uiRes("m_performDisplayControl.kSurfacesTab")) displayTabs; // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // // Provide more descriptive labels for the buttons. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performDisplayControl.kCustomNURBSDisplayOptions")); // Step 8: Set the 'Help' tag. // ============================================ // setOptionBoxHelpTag( "CustomNURBSDisplay" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = ""; setOptionVars(false); int $scope = `optionVar -q displayControlScope`; int $editPoints[] = `optionVar -q displayControlEditPoints`; int $hulls[] = `optionVar -q displayControlHulls`; int $CVs[] = `optionVar -q displayControlCVs`; int $sf[] = `optionVar -q displayControlSurfaceFace`; int $origin[] = `optionVar -q displayControlOrigin`; int $normals[] = `optionVar -q displayControlNormals`; int $selectHandles[] = `optionVar -q displayControlSelectHandles`; if ($scope == 1) { // Work only on the active objects // // toggle -cv -ep -hull -normal -selectHandle -state false; $cmd = "toggle -cv -state " + $CVs[0] + ";"; $cmd = $cmd + "toggle -ep -state " + $editPoints[0] + ";"; $cmd = $cmd + "toggle -hull -state " + $hulls[0] + ";"; $cmd = $cmd + "toggle -normal -state " + $normals[0] + ";"; $cmd = $cmd + "toggle -sf -state " + $sf[0] + ";"; $cmd = $cmd + "toggle -origin -state " + $origin[0] + ";"; $cmd = $cmd + "toggle -selectHandle -state " + $selectHandles[0] + ";"; } else if ($scope == 2) { // Work on all the geometric objects // string $gmtyObjs[] = `ls -g`; // toggle -cv -ep -hull -normal -selectHandle -state false $gmtyObjs; int $i, $n; $n = size($gmtyObjs); if( $n > 0 ) { $cmd = $cmd + "toggle -cv -state " + $CVs[1]; int $needEP = true; int $needH = true; int $needN = true; int $needSF = true; int $needOrigin = true; if( $CVs[1] == $editPoints[1] ) { $cmd = $cmd + "-ep "; $needEP = false; } if( $CVs[1] == $hulls[1] ) { $cmd = $cmd + "-hull "; $needH = false; } if( $CVs[1] == $normals[1] ) { $cmd = $cmd + "-normal "; $needN = false; } if( $CVs[1] == $sf[1] ) { $cmd = $cmd + "-sf "; $needSF = false; } if( $CVs[1] == $origin[1] ) { $cmd = $cmd + "-origin "; $needOrigin = false; } for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; if( $needEP ) { $cmd = $cmd + "toggle -ep -state " + $editPoints[1]; if( $needH && ($editPoints[1] == $hulls[1] ) ) { $cmd = $cmd + "-hull "; $needH = false; } if( $needN && ($editPoints[1] == $normals[1]) ) { $cmd = $cmd + "-normal "; $needN = false; } for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; } if( $needH ) { $cmd = $cmd + "toggle -hull -state " + $hulls[1]; if( $needN && ($hulls[1] == $normals[1] ) ) { $cmd = $cmd + "-normal "; $needN = false; } for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; } if( $needN ) { $cmd = $cmd + "toggle -normal -state " + $normals[1]; for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; } if( $needSF ) { $cmd = $cmd + "toggle -sf -state " + $sf[1]; for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; } if( $needOrigin ) { $cmd = $cmd + "toggle -origin -state " + $origin[1]; for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $gmtyObjs[$i]; } $cmd = $cmd + ";"; } } // Work on all the transformation objects // string $tfmObjs[] = `ls -tr`; $n = size($tfmObjs); if( $n > 0 ) { $cmd = $cmd + "toggle -selectHandle -state " + $selectHandles[1]; for ($i = 0; $i < $n; $i++) { $cmd = $cmd + " " + $tfmObjs[$i]; } $cmd = $cmd + ";"; } } else if ($scope == 3) { // Set the component display flags for all new curves // // toggle -nc -cv -ep -hull -state false; $cmd = "toggle -nc -cv -state " + $CVs[2] + ";"; $cmd = $cmd + "toggle -nc -ep -state " + $editPoints[2] + ";"; $cmd = $cmd + "toggle -nc -sf -state " + $sf[2] + ";"; $cmd = $cmd + "toggle -nc -origin -state " + $origin[2] + ";"; $cmd = $cmd + "toggle -nc -hull -state " + $hulls[2] +";"; } else if ($scope == 4) { // Set the component display flags for all new surfaces // // toggle -nc -cv -ep -hull -state false; $cmd = "toggle -ns -cv -state " + $CVs[3] + ";"; $cmd = $cmd + "toggle -ns -ep -state " + $editPoints[3] +";"; $cmd = $cmd + "toggle -ns -sf -state " + $sf[3] +";"; $cmd = $cmd + "toggle -ns -origin -state " + $origin[3] +";"; $cmd = $cmd + "toggle -ns -hull -state " + $hulls[3] +";"; } return $cmd; } // // Procedure Name: // performDisplayControl // // Description: // Perform the display control command using the corresponding // option values. This procedure will also show the option box // window if necessary as well as construct the command string // that will invoke the display control command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performDisplayControl(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: displayControlOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; } // +++++++++++++++++++++++ Helper Functions ++++++++++++++++++++++++++++++++++++ global proc displayControlSetUpHelper (string $parent, int $index) { setParent $parent; // Edit Points check box // int $editPoints[] = `optionVar -q displayControlEditPoints`; checkBoxGrp -e -v1 $editPoints[$index] editPointsCheck; // Hulls check box // int $hulls[] = `optionVar -q displayControlHulls`; checkBoxGrp -e -v1 $hulls[$index] hullsCheck; // CVs check box // int $cvs[] = `optionVar -q displayControlCVs`; checkBoxGrp -e -v1 $cvs[$index] CVsCheck; // Normals check box // if( `isTrue SurfaceUIExists` ) { int $normals[] = `optionVar -q displayControlNormals`; checkBoxGrp -e -v1 $normals[$index] normalsCheck; } // SurfaceFaces check box // int $sf[] = `optionVar -q displayControlSurfaceFace`; checkBoxGrp -e -v1 $sf[$index] SurfaceFaceCheck; // Origin check box // if( `isTrue SurfaceUIExists` ) { int $origin[] = `optionVar -q displayControlOrigin`; checkBoxGrp -e -v1 $origin[$index] originCheck; } // Selection Handles check box // int $selHandles[] = `optionVar -q displayControlSelectHandles`; checkBoxGrp -e -v1 $selHandles[$index] selectHandlesCheck; } global proc displayControlBuild (string $parent) { setParent $parent; // print ( $parent + "\n" ); checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kEditPoints")) editPointsCheck; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kHulls")) hullsCheck; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kCVs")) CVsCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kNormal")) normalsCheck; } checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kFaceCenters")) SurfaceFaceCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kSurfaceOrigins")) originCheck; } checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kSelHandles")) selectHandlesCheck; int $childrenCount = `tabLayout -q -nch displayTabs`; // print ( $childrenCount + "\n" ); if ($childrenCount > 2) { // print ("one of the three parents \n"); if( `isTrue SurfaceUIExists` ) { checkBoxGrp -e -en false normalsCheck; } checkBoxGrp -e -en false selectHandlesCheck; } rowLayout -nc 3 -cw 1 170 -cw 2 50 -cw 3 50 -columnAlign 2 "center" -columnAlign 3 "center" -columnAttach 1 "right" 0 allOnOffLayout; text -label (uiRes("m_performDisplayControl.kAllOptions")) allText; // We need to pass in the correct parent so we are // adjusting the correct set of buttons // button -label (uiRes("m_performDisplayControl.kOn")) -c ("displayControlOnButtonPressed " + $parent) onButton; button -label (uiRes("m_performDisplayControl.kOff")) -c ("displayControlOffButtonPressed " + $parent) offButton; setParent ..; } global proc displayControlEditOptions() { int $selectedScopeIndex = `optionMenuGrp -q -sl scopePopup`; tabLayout -e -sti $selectedScopeIndex displayTabs; } global proc displayControlOnButtonPressed (string $parent) { setParent $parent; // Switch on all the check boxes // checkBoxGrp -e -v1 1 editPointsCheck; checkBoxGrp -e -v1 1 hullsCheck; checkBoxGrp -e -v1 1 CVsCheck; checkBoxGrp -e -v1 1 SurfaceFaceCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -e -v1 1 normalsCheck; checkBoxGrp -e -v1 1 originCheck; } checkBoxGrp -e -v1 1 selectHandlesCheck; } global proc displayControlOffButtonPressed (string $parent) { setParent $parent; // Switch off all the check boxes // checkBoxGrp -e -v1 0 editPointsCheck; checkBoxGrp -e -v1 0 hullsCheck; checkBoxGrp -e -v1 0 CVsCheck; checkBoxGrp -e -v1 0 SurfaceFaceCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -e -v1 0 normalsCheck; checkBoxGrp -e -v1 0 originCheck; } checkBoxGrp -e -v1 0 selectHandlesCheck; } global proc displayControlBuildButtons (string $parent) { setParent $parent; // print ( $parent + "\n" ); checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kEditPoints")) editPointsCheck; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kHulls")) hullsCheck; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kCVs")) CVsCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kNormal")) normalsCheck; } checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kFaceCenters")) SurfaceFaceCheck; if( `isTrue SurfaceUIExists` ) { checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kSurfaceOrigins")) originCheck; } checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performDisplayControl.kSelHandles")) selectHandlesCheck; int $childrenCount = `tabLayout -q -nch displayTabs`; // print ( $childrenCount + "\n" ); if ($childrenCount > 2) { // print ("one of the three parents \n"); if( `isTrue SurfaceUIExists` ) { checkBoxGrp -e -en false normalsCheck; } checkBoxGrp -e -en false selectHandlesCheck; } rowLayout -nc 3 -cw 1 170 -cw 2 50 -cw 3 50 -columnAlign 2 "center" -columnAlign 3 "center" -columnAttach 1 "right" 5 allOnOffLayout; text -label (uiRes("m_performDisplayControl.kAllOptions")) allText; // We need to pass in the correct parent so we are // adjusting the correct set of buttons // button -label (uiRes("m_performDisplayControl.kOn")) -w 50 -c ("displayControlOnButtonPressed " + $parent) onButton; button -label (uiRes("m_performDisplayControl.kOff")) -w 50 -c ("displayControlOffButtonPressed " + $parent) offButton; setParent ..; }