// =========================================================================== // 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. // =========================================================================== ////////////////////////////////////////////////////////////////////// // Description: // Initialize the option values. // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // forceFactorySettings - whether to set the options to default values. // // Return Value: // None. // global proc baseDeform_intializeOptionVars( string $cmdPfx, int $forceFactorySettings ) { // command specific options // eval ( ($cmdPfx + "_intializeOptionVars " + $forceFactorySettings) ); // default options common to all deformers // string $ovPfx = eval( ($cmdPfx+"_optionVarPrefix") ); string $ovPositioning = ($ovPfx+"Positioning"); string $ovExclusive = ($ovPfx+"Exclusive"); string $ovExclName= ($ovPfx+"ExclName"); if ($forceFactorySettings || !`optionVar -exists $ovPositioning`) { optionVar -stringValue $ovPositioning "default"; } if ($forceFactorySettings || !`optionVar -exists $ovExclusive`) { // 0 == no exclusive // 1 == exclusive with new name // 2 == exclusive using an existing partition // optionVar -intValue $ovExclusive 0; } if ($forceFactorySettings || !`optionVar -exists $ovExclName`) { optionVar -stringValue $ovExclName "deformPartition"; } } /////////////////////////////////////////////////////////////////////////////// // Description: // Creates the command string // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // // Return Value: // The command string. // global proc string baseDeform_assembleCmd( string $cmdPfx ) { // command specific options // string $cmd = eval(($cmdPfx + "_commandName")); $cmd += eval(($cmdPfx + "_assembleCmdOptions")); string $ovPfx = eval( ($cmdPfx+"_optionVarPrefix") ); string $ovPositioning = ($ovPfx+"Positioning"); string $ovExclusive = ($ovPfx+"Exclusive"); string $ovExclName= ($ovPfx+"ExclName"); // Build a positioning flag if needed // string $positioning = `optionVar -query $ovPositioning`; if ($positioning != "default") { $cmd += (" -" + $positioning); } int $exc=`optionVar -query $ovExclusive`; if ($exc) { string $exn=`optionVar -query $ovExclName`; if ($exn!="") { // make sure that we do not clash names with an existing // partition when the user requested a new partition, even // if the user may have entered a non-unique name // if ($exc == 1) $exn += "#"; $cmd += (" -exclusive \"" + $exn+"\""); } } return $cmd; } /////////////////////////////////////////////////////////////////////////////// // Description: // Update the option values with the current state of the option box UI. // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // 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 baseDeform_updateOptionVars( string $cmdPfx, string $parent, int $doIt) { // Set the optionVar's from the control values, and then // perform the command. // Get the deformer specific values from the controls // eval ( ( $cmdPfx + "_updateOptionVars") ); // Get the general deformer values from the controls string $ovPfx = eval( ($cmdPfx+"_optionVarPrefix") ); string $ovPositioning = ($ovPfx+"Positioning"); string $ovPositioningWidget = ($ovPfx+"PositioningWidget"); string $ovExclusive = ($ovPfx+"Exclusive"); string $ovExclName= ($ovPfx+"ExclName"); // Positioning of the deformer in the DG // string $positioning = "default"; if (`optionMenuGrp -exists $ovPositioningWidget`) { if (`optionMenuGrp -query -select $ovPositioningWidget` == 1) { $positioning = "default"; } else if (`optionMenuGrp -query -select $ovPositioningWidget` == 2){ $positioning = "before"; } else if (`optionMenuGrp -query -select $ovPositioningWidget` == 3){ $positioning = "after"; } else if (`optionMenuGrp -query -select $ovPositioningWidget` == 4){ $positioning = "split"; } else if (`optionMenuGrp -query -select $ovPositioningWidget` == 5){ $positioning = "parallel"; } } optionVar -stringValue $ovPositioning $positioning; if (`checkBoxGrp -exists exclWidget`) { optionVar -intValue $ovExclusive `checkBoxGrp -q -v1 exclWidget`; } if (`optionMenuGrp -exists partitionListWidget`) { string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`; if ($partitionNameVal == (uiRes("m_performBaseDeform.kCreateNewPartition"))) { if (`textFieldGrp -exists partitionNameWidget`) { $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`; } } else { // a value of 2 indicates that we use an existing partition // optionVar -intValue $ovExclusive 2; } optionVar -stringValue $ovExclName $partitionNameVal; } if ($doIt) { eval( ($cmdPfx+"_doIt") ); } } /////////////////////////////////////////////////////////////////////////////// // Description: // Set the optionVar based on a control of a certain type // // Input Arguments: // controlType - the type of control, like floatSlider or checkBox // name - the name of the option // Return Value: // None // global proc baseDeform_setOptionVar( string $controlType, string $name) { switch ($controlType) { case "floatSlider": if (`floatSliderGrp -exists $name`) { optionVar -floatValue $name `floatSliderGrp -query -value $name`; } break; case "intSlider": if (`intSliderGrp -exists $name`) { optionVar -intValue $name `intSliderGrp -query -value $name`; } break; case "checkBox": if (`checkBoxGrp -exists $name`) { optionVar -intValue $name `checkBoxGrp -q -v1 $name`; } break; } } /////////////////////////////////////////////////////////////////////////////// // Description: // Set the control based on an optionVar // // Input Arguments: // controlType - the type of control, like floatSlider or checkBox // name - the name of the option // Return Value: // None // global proc baseDeform_setControl( string $controlType, string $name) { switch ($controlType) { case "floatSlider": if (`floatSliderGrp -exists $name`) { floatSliderGrp -edit -value `optionVar -query $name` $name; } break; case "intSlider": if (`intSliderGrp -exists $name`) { intSliderGrp -edit -value `optionVar -query $name` $name; } break; case "checkBox": if (`checkBoxGrp -exists $name`) { checkBoxGrp -e -v1 `optionVar -query $name` $name; } break; } } /////////////////////////////////////////////////////////////////////////////// // Description: // Update the state of the option box UI to reflect the option values. // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // 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. // // tabIndex - 0 = both tabs, 1 = basic, 2 = advanced // // Return Value: // None. // global proc baseDeform_setup( string $cmdPfx, string $parent, int $forceFactorySettings, int $tabIndex ) { // Retrieve the option settings // baseDeform_intializeOptionVars($cmdPfx, $forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // if ($tabIndex != 2) { eval ( ($cmdPfx + "_updateControls") ); } if ($tabIndex != 1) { string $ovPfx = eval( ($cmdPfx+"_optionVarPrefix") ); string $ovPositioning = ($ovPfx+"Positioning"); string $ovPositioningWidget = ($ovPfx+"PositioningWidget"); string $ovExclusive = ($ovPfx+"Exclusive"); string $ovExclName= ($ovPfx+"ExclName"); // Positioning of the deformer in the DG // string $positioning = `optionVar -query $ovPositioning`; if (`optionMenuGrp -exists $ovPositioningWidget`) { if ($positioning == "default") { optionMenuGrp -edit -select 1 $ovPositioningWidget; } else if ($positioning == "before") { optionMenuGrp -edit -select 2 $ovPositioningWidget; } else if ($positioning == "after") { optionMenuGrp -edit -select 3 $ovPositioningWidget; } else if ($positioning == "split") { optionMenuGrp -edit -select 4 $ovPositioningWidget; } else if ($positioning == "parallel") { optionMenuGrp -edit -select 5 $ovPositioningWidget; } else { optionMenuGrp -edit -select 1 $ovPositioningWidget; } } int $exc=`optionVar -query $ovExclusive`; if (`checkBoxGrp -exists exclWidget`) { checkBoxGrp -e -v1 $exc exclWidget; } string $exn=`optionVar -query $ovExclName`; if (`textFieldGrp -exists partitionNameWidget`) { textFieldGrp -e -tx $exn -enable $exc partitionNameWidget; } if (`optionMenuGrp -exists partitionListWidget`) { optionMenuGrp -e -enable $exc partitionListWidget; } } } /////////////////////////////////////////////////////////////////////////////// // Description: // Create the tab UI. The contents of each tab are created only // when it is required, ie. if the tab is initially visible or // if the tab is selected by the user. // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // tabLayout - the name of the tab layout. // // Return Value: // None. // global proc baseDeform_createTabUI( string $cmdPfx, string $tabLayout) { string $tab[] = `tabLayout -query -childArray $tabLayout`; int $currentTabIndex = `tabLayout -query -selectTabIndex $tabLayout`; // Determine if the UI for this tab has been created yet. // This is accomplished by querying the number of children // in the current tab. If the tab has no children then the UI // must be created. // if (0 == `columnLayout -query -numberOfChildren $tab[$currentTabIndex-1]`) { setParent $tab[$currentTabIndex-1]; string $label; int $index; // 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; // Turn on the wait cursor. // waitCursor -state 1; // The current tab has no children. Determine which tab is // active and create its UI. // // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // if (1 == $currentTabIndex) { // Create UI for the first tab. // eval( ($cmdPfx + "_createControls") ); setParent ..; } else if (2 == $currentTabIndex) { string $ovPfx = eval( ($cmdPfx+"_optionVarPrefix") ); string $ovPositioning = ($ovPfx+"Positioning"); string $ovPositioningWidget = ($ovPfx+"PositioningWidget"); string $ovExclusive = ($ovPfx+"Exclusive"); string $ovExclName= ($ovPfx+"ExclName"); // Create UI for the second tab. // columnLayout -adjustableColumn true; // Positioning of the deformer in the DG optionMenuGrp -label (uiRes("m_performBaseDeform.kDeformationOrder")) $ovPositioningWidget; menuItem -label (uiRes("m_performBaseDeform.kDefault")) ($cmdPfx + "PosItem1"); menuItem -label (uiRes("m_performBaseDeform.kBefore")) ($cmdPfx + "PosItem2"); menuItem -label (uiRes("m_performBaseDeform.kAfter")) ($cmdPfx + "PosItem3"); menuItem -label (uiRes("m_performBaseDeform.kSplit")) ($cmdPfx + "PosItem4"); menuItem -label (uiRes("m_performBaseDeform.kParallel")) ($cmdPfx + "PosItem5"); separator; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performBaseDeform.kExclusive")) -v1 0 -on1 "optionMenuGrp -e -enable 1 partitionListWidget; updatePartitionNameWidget;" -offCommand "optionMenuGrp -e -enable 0 partitionListWidget; updatePartitionNameWidget;" exclWidget; // Create an option menu listing the partitions // optionMenuGrp -label (uiRes("m_performBaseDeform.kPartitiontoUse")) -enable `checkBoxGrp -q -v1 exclWidget` -cc "updatePartitionNameWidget" partitionListWidget; string $currentNameOption = ""; if (`optionVar -exists $ovExclName`) { $currentNameOption = `optionVar -q $ovExclName`; } // add all the partitions to the menu // int $pp; string $partitionArray[]; $partitionArray = `ls -type partition`; int $partitionCount = size($partitionArray); menuItem -label (uiRes("m_performBaseDeform.kCreateNewPartition")) ; for ($pp = 0; $pp < $partitionCount; $pp++) { // Do not list the render partition as adding items to // it is only going to cause confusion. // if ($partitionArray[$pp] != "renderPartition" && $partitionArray[$pp] != "characterPartition") { menuItem -label $partitionArray[$pp]; } if ($currentNameOption == $partitionArray[$pp]) { optionVar -stringValue $ovExclName "deformPartition"; } } textFieldGrp -label (uiRes("m_performBaseDeform.kNewPartitionName")) -enable `checkBoxGrp -q -v1 exclWidget` -tx "deformPartition" partitionNameWidget; updatePartitionNameWidget; } // Update the control values to match the options. // eval (("baseDeform_setup " + $cmdPfx + " " + $tabLayout + " "+ 0 +" "+$currentTabIndex)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } /////////////////////////////////////////////////////////////////////////////// // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // cmdPfx - the prefix for the specific commands to be called. // // Return Value: // None. // proc baseDeform_showOptionBox( string $cmdPfx ) { // 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. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName( eval(($cmdPfx+"_commandName")) ); // 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. // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // //setUITemplate -pushTemplate DefaultTemplate; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Demonstrate the delaying of UI creation via tab layouts. // Instead of creating all of the option box UI initially, only // create that which is initially visible. Wait, until the // other tabs are selected to create the remaining UI. // string $tabLayout = `tabLayout -scrollable 1`; // Attach an action that will be invoked before a tab is selected. // tabLayout -edit -preSelectCommand ("baseDeform_createTabUI " + $cmdPfx + " " + $tabLayout) $tabLayout; // Create just the immediate children of the tab layout so that // the tabs appear. // columnLayout; setParent ..; columnLayout; setParent ..; // Set the tab labels. // tabLayout -edit -tabLabelIndex 1 (uiRes("m_performBaseDeform.kBasic")) -tabLabelIndex 2 (uiRes("m_performBaseDeform.kAdvanced")) $tabLayout; // Create the UI for the tab that is initially visible. // baseDeform_createTabUI($cmdPfx, $tabLayout); // Step 5: Deactivate the default UI template. // =========================================== // // Note: this option box example delays the creation of the UI // until it is required. Therefore this step is moved to the // procedure where the UI is actually created. // // See also Step 2. // //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 -label (uiRes("m_performBaseDeform.kCreate")) -command ("baseDeform_updateOptionVars " + $cmdPfx + " " + $tabLayout + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ("baseDeform_updateOptionVars " + $cmdPfx + " " + $tabLayout + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ("baseDeform_setup " + $cmdPfx + " " + $tabLayout + " " + 1 + " " + 0) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle( eval(($cmdPfx + "_optionBoxTitle")) ); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( eval(($cmdPfx + "_helpTag")) ); // Step 9: Set the current values of the option box. // ================================================= // // NOTE: Cannot do this here since we do not know what UI is // currently visible. This is moved to where the UI is created. // // Step 10: Show the option box. // ============================= // showOptionBox(); } /////////////////////////////////////////////////////////////////////////////// // Description: // Perform the deformer 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 deformers command with the current // option box values. // // Input Arguments: // $cmdPfx : the prefix for the above commands to be called. // $action: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // The command string. // global proc string performBaseDeform( string $cmdPfx, int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // baseDeform_intializeOptionVars($cmdPfx, false); // Get the command. // $cmd = baseDeform_assembleCmd($cmdPfx); // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: baseDeform_showOptionBox($cmdPfx); break; // Return the command string. // case 2: // Retrieve the option settings. // baseDeform_intializeOptionVars($cmdPfx, false); // Get the command. // $cmd = baseDeform_assembleCmd($cmdPfx); break; } return $cmd; }