// =========================================================================== // 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: 18 Dec 2000 // // Description: // jiggle default options box. The content for each tab // is not created until it is accessed for the first time. // ////////////////////////////////////////////////////////////////////// // // 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) { // stiffness // if ($forceFactorySettings || !`optionVar -exists jiggleStiffness`) { optionVar -floatValue jiggleStiffness 0.5; } // damping // if ($forceFactorySettings || !`optionVar -exists jiggleDamping`) { optionVar -floatValue jiggleDamping 0.5; } // weight // if ($forceFactorySettings || !`optionVar -exists jiggleWeight`) { optionVar -floatValue jiggleWeight 1.0; } // ignore transform // if ($forceFactorySettings || !`optionVar -exists jiggleIgnoreTransform`) { optionVar -intValue jiggleIgnoreTransform 0; } // enable only when resting // if ($forceFactorySettings || !`optionVar -exists jiggleEnableOnlyIfResting`) { optionVar -intValue jiggleEnableOnlyIfResting 0; } // default options common to all deformers // if ($forceFactorySettings || !`optionVar -exists jigglePositioning`) { optionVar -stringValue jigglePositioning "default"; } if ($forceFactorySettings || !`optionVar -exists jiggleExclusive`) { // 0 == no exclusive // 1 == exclusive with new name // 2 == exclusive using an existing partition // optionVar -intValue jiggleExclusive 0; } if ($forceFactorySettings || !`optionVar -exists jiggleExclName`) { optionVar -stringValue jiggleExclName "deformPartition"; } } // // Procedure Name: // jiggleSetup // // 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. // // tabIndex - 0 = both tabs, 1 = basic, 2 = advanced // // Return Value: // None. // global proc jiggleSetup(string $parent, int $forceFactorySettings, int $tabIndex) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // if ($tabIndex != 2) { // min. // if (`floatSliderGrp -exists jiggleStiffness`) { floatSliderGrp -edit -value `optionVar -query jiggleStiffness` jiggleStiffness; } // max. // if (`floatSliderGrp -exists jiggleDamping`) { floatSliderGrp -edit -value `optionVar -query jiggleDamping` jiggleDamping; } // curvature. // if (`floatSliderGrp -exists jiggleWeight`) { floatSliderGrp -edit -value `optionVar -query jiggleWeight` jiggleWeight; } if (`checkBoxGrp -exists jiggleEnableOnlyIfRestingWidget`) { checkBoxGrp -e -v1 `optionVar -query jiggleEnableOnlyIfResting` jiggleEnableOnlyIfRestingWidget; } if (`checkBoxGrp -exists jiggleIgnoreTWidget`) { checkBoxGrp -e -v1 `optionVar -query jiggleIgnoreTransform` jiggleIgnoreTWidget; } } if ($tabIndex != 1) { // Positioning of the jiggle deformer in the DG // string $positioning = `optionVar -query jigglePositioning`; if (`optionMenuGrp -exists jigglePositioningWidget`) { if ($positioning == "default") { optionMenuGrp -edit -select 1 jigglePositioningWidget; } else if ($positioning == "before") { optionMenuGrp -edit -select 2 jigglePositioningWidget; } else if ($positioning == "after") { optionMenuGrp -edit -select 3 jigglePositioningWidget; } else if ($positioning == "split") { optionMenuGrp -edit -select 4 jigglePositioningWidget; } else if ($positioning == "parallel") { optionMenuGrp -edit -select 5 jigglePositioningWidget; } else { optionMenuGrp -edit -select 1 jigglePositioningWidget; } } int $exc=`optionVar -query jiggleExclusive`; if (`checkBoxGrp -exists exclWidget`) { checkBoxGrp -e -v1 $exc exclWidget; } string $exn=`optionVar -query jiggleExclName`; if (`textFieldGrp -exists partitionNameWidget`) { textFieldGrp -e -tx $exn -enable $exc partitionNameWidget; } if (`optionMenuGrp -exists partitionListWidget`) { optionMenuGrp -e -enable $exc partitionListWidget; } } } // // Procedure Name: // jiggleCallback // // 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 jiggleCallback(string $parent, int $doIt) { // Set the optionVar's from the control values, and then // perform the command. // stiffness // if (`floatSliderGrp -exists jiggleStiffness`) { optionVar -floatValue jiggleStiffness `floatSliderGrp -query -value jiggleStiffness`; } // damping // if (`floatSliderGrp -exists jiggleDamping`) { optionVar -floatValue jiggleDamping `floatSliderGrp -query -value jiggleDamping`; } // Curvature. // if (`floatSliderGrp -exists jiggleWeight`) { optionVar -floatValue jiggleWeight `floatSliderGrp -query -value jiggleWeight`; } if (`checkBoxGrp -exists jiggleEnableOnlyIfRestingWidget`) { optionVar -intValue jiggleEnableOnlyIfResting `checkBoxGrp -q -v1 jiggleEnableOnlyIfRestingWidget`; } if (`checkBoxGrp -exists jiggleIgnoreTWidget`) { optionVar -intValue jiggleIgnoreTransform `checkBoxGrp -q -v1 jiggleIgnoreTWidget`; } // Positioning of the jiggle deformer in the DG // string $positioning = "default"; if (`optionMenuGrp -exists jigglePositioningWidget`) { if (`optionMenuGrp -query -select jigglePositioningWidget` == 1) { $positioning = "default"; } else if (`optionMenuGrp -query -select jigglePositioningWidget` == 2){ $positioning = "before"; } else if (`optionMenuGrp -query -select jigglePositioningWidget` == 3){ $positioning = "after"; } else if (`optionMenuGrp -query -select jigglePositioningWidget` == 4){ $positioning = "split"; } else if (`optionMenuGrp -query -select jigglePositioningWidget` == 5){ $positioning = "parallel"; } } optionVar -stringValue jigglePositioning $positioning; if (`checkBoxGrp -exists exclWidget`) { optionVar -intValue jiggleExclusive `checkBoxGrp -q -v1 exclWidget`; } if (`optionMenuGrp -exists partitionListWidget`) { string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`; if ($partitionNameVal == (uiRes("m_performJiggle.kCreateNewPartition"))) { if (`textFieldGrp -exists partitionNameWidget`) { $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`; } } else { // a value of 2 indicates that we use an existing partition // optionVar -intValue jiggleExclusive 2; } optionVar -stringValue jiggleExclName $partitionNameVal; } if ($doIt) { performJiggle 0; addToRecentCommandQueue "performJiggle 0" "Jiggle"; } } // // Procedure Name: // createJiggleTabUI // // 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: // The name of the tab layout. // // Return Value: // None. // global proc createJiggleTabUI(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. // floatSliderGrp -label (uiRes("m_performJiggle.kStiffness")) -minValue 0.0 -maxValue 1.0 jiggleStiffness; floatSliderGrp -label (uiRes("m_performJiggle.kDamping")) -minValue 0.0 -maxValue 1.0 jiggleDamping; floatSliderGrp -label (uiRes("m_performJiggle.kWeight")) -minValue 0.0 -maxValue 1.0 jiggleWeight; checkBoxGrp -label "" -label1 (uiRes("m_performJiggle.kJiggleWhenObjectStops")) -annotation (uiRes("m_performJiggle.kCheckedJiggleAnnot")) -numberOfCheckBoxes 1 jiggleEnableOnlyIfRestingWidget; checkBoxGrp -label "" -label1 (uiRes("m_performJiggle.kIgnoreTransform")) -annotation (uiRes("m_performJiggle.kJiggleBasedOnCVAnnot")) -numberOfCheckBoxes 1 jiggleIgnoreTWidget; setParent ..; } else if (2 == $currentTabIndex) { // Create UI for the second tab. // columnLayout -adjustableColumn true; // Positioning of the jiggle deformer in the DG optionMenuGrp -label (uiRes("m_performJiggle.kDeformationOrder")) jigglePositioningWidget; menuItem -label (uiRes("m_performJiggle.kDefault")) jigglePosItem1; menuItem -label (uiRes("m_performJiggle.kBefore")) jigglePosItem2; menuItem -label (uiRes("m_performJiggle.kAfter")) jigglePosItem3; menuItem -label (uiRes("m_performJiggle.kSplit")) jigglePosItem4; menuItem -label (uiRes("m_performJiggle.kParallel")) jigglePosItem5; separator; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performJiggle.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_performJiggle.kPartitionToUse")) -enable `checkBoxGrp -q -v1 exclWidget` -cc "updatePartitionNameWidget" partitionListWidget; string $currentNameOption = ""; if (`optionVar -exists jiggleExclName`) { $currentNameOption = `optionVar -q jiggleExclName`; } // add all the partitions to the menu // int $pp; string $partitionArray[]; $partitionArray = `ls -type partition`; int $partitionCount = size($partitionArray); menuItem -label (uiRes("m_performJiggle.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 jiggleExclName "deformPartition"; } } textFieldGrp -label (uiRes("m_performJiggle.kNewPartitionName")) -enable `checkBoxGrp -q -v1 exclWidget` -tx "deformPartition" partitionNameWidget; updatePartitionNameWidget; } // Update the control values to match the options. // eval (("jiggleSetup " + $tabLayout + " "+0+" "+$currentTabIndex)); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // jiggleOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // // ********* Change 'jiggle' in this proc to be the name of your command proc jiggleOptions() { // Name of the command for this option box. // string $commandName = "deformer"; // Build the option box actions. // string $callback = ("jiggleCallback"); string $setup = ("jiggleSetup"); // 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($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 ("createJiggleTabUI " + $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_performJiggle.kBasic")) -tabLabelIndex 2 (uiRes("m_performJiggle.kAdvanced")) $tabLayout; // Create the UI for the tab that is initially visible. // createJiggleTabUI($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_performJiggle.kCreate")) -command ($callback + " " + $tabLayout + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $tabLayout + " " + 0 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $tabLayout + " " + 1 + " " + 0) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performJiggle.kCreateJiggleDeformerOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "CreateJiggleDeformer" ); // 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. // //eval (($setup + " " + $tabLayout + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // optionBoxExample1Help // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string jiggleHelp() { return " Command: jiggle - creates a jiggle\n" + "Selection: Deformable geometry."; } proc string assembleCmd() { float $stiffness = `optionVar -query jiggleStiffness`; float $damping = `optionVar -query jiggleDamping`; float $weight = `optionVar -query jiggleWeight`; int $ignoreTransform = `optionVar -query jiggleIgnoreTransform`; int $ifResting = `optionVar -query jiggleEnableOnlyIfResting`; string $positioning = `optionVar -query jigglePositioning`; int $exc=`optionVar -query jiggleExclusive`; string $exn; if ($exc) { $exn=`optionVar -query jiggleExclName`; 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 += "#"; } } string $cmd = "doJiggle 1 { " + "\"" + $stiffness + "\", " + "\"" + $damping + "\", " + "\"" + $weight + "\", " + "\"" + $ignoreTransform + "\", " + "\"" + $ifResting + "\", " + "\"" + $positioning + "\", " + "\"" + $exn + "\"" + " };"; return $cmd; } // // Procedure Name: // performJiggle // // Description: // Perform the jiggle 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 jiggle command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // // Return Value: // None. // global proc string performJiggle(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Retrieve the option settings // setOptionVars(false); // Get the command. // $cmd = assembleCmd(); // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: jiggleOptions; break; // Return the command string. // case 2: // Retrieve the option settings. // setOptionVars (false); // Get the command. // $cmd = assembleCmd(); break; } return $cmd; }