// =========================================================================== // 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: // This script provides an option box dialog template for deformers. // It creates a option box and implements its "advanced" tab. // All common UI widgets are in that tab, including "positioningWidget", // "exclWidget", "partitionListWidget" and "partitionNameWidget". // // The method deformerCommonUISetup() can update the state of these common UI when // the option values are changed. // The method deformerCommonUICallback() can update the option values // when these UI are modified. // // To use this template, user needs to implement their own specific deformer methods // to add widget on UI and update the relevant option values. // The methods should be named based on the name of the deformer to let // the template can call them. // // To use this template, you need to implement(XXX is the name of your deformer): // XXXTabUI() - add specific tab widget, add the widget and option value // XXXSetOptionVars() - initialize option variables // XXXSetup() - update the state of the specific UI to reflect the option values // XXXCallback() - update the option values to reflect the specific UI // XXXOptionBoxTitle() - set the box title, it can be a localized string // XXXOptionBoxHelpTag() - set the help tag of option box // // Then call // deformerOptions("XXX"); // to run the option box window. // source updatePartitionNameWidget.mel; // // Procedure Name: // setCommonOptionVars // // Description: // Initialize the common option values. // // Input Arguments: // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // proc setCommonOptionVars(int $forceFactorySettings) { if ($forceFactorySettings || !`optionVar -exists deformerPositioning`) { optionVar -intValue deformerPositioning 1; } if ($forceFactorySettings || !`optionVar -exists deformerExclusive`) { // 0 == no exclusive // 1 == exclusive with new name // 2 == exclusive using an existing partition // optionVar -intValue deformerExclusive 0; } if ($forceFactorySettings || !`optionVar -exists deformerExclName`) { optionVar -stringValue deformerExclName "deformPartition"; } } // // Procedure Name: // deformerCommonUISetup // // Description: // Update the state of the common option box UI to reflect the option values. // Only common UI options. // // 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 deformerCommonUISetup(string $parent, int $forceFactorySettings, int $tabIndex) { setParent $parent; if ($tabIndex != 1) { // Positioning of the deformer in the DG // It has five items "default", "before", "after", "split", "parallel" int $positioning = `optionVar -query deformerPositioning`; if (`optionMenuGrp -exists positioningWidget`) { optionMenuGrp -edit -select $positioning positioningWidget; } if (`checkBoxGrp -exists exclWidget`) { int $exc=`optionVar -query deformerExclusive`; checkBoxGrp -e -v1 $exc exclWidget; } if (`textFieldGrp -exists partitionNameWidget`) { string $exn=`optionVar -query deformerExclName`; int $exc=`optionVar -query deformerExclusive`; textFieldGrp -e -tx $exn -enable $exc partitionNameWidget; } if (`optionMenuGrp -exists partitionListWidget`) { int $exc=`optionVar -query deformerExclusive`; optionMenuGrp -e -enable $exc partitionListWidget; } } } // // Procedure Name: // deformerCommonUICallback // // Description: // Update the option values with the current // state of the option box UI. // Only common option values. // // Input Arguments: // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // // Return Value: // None. // global proc deformerCommonUICallback(string $parent) { setParent $parent; // Positioning of the deformer in the DG int $positioning = 1; if (`optionMenuGrp -exists positioningWidget`) { $positioning = `optionMenuGrp -query -select positioningWidget`; } optionVar -intValue deformerPositioning $positioning; if (`checkBoxGrp -exists exclWidget`) { int $exc=`checkBoxGrp -q -v1 exclWidget`; optionVar -intValue deformerExclusive $exc; } if (`optionMenuGrp -exists partitionListWidget`) { string $partitionNameVal = `optionMenuGrp -q -v partitionListWidget`; if ($partitionNameVal == (uiRes("m_deformerOptionsTemplate.kCreateNewPartition"))) { if (`textFieldGrp -exists partitionNameWidget`) { $partitionNameVal = `textFieldGrp -q -tx partitionNameWidget`; } } else { // a value of 2 indicates that we use an existing partition // optionVar -intValue deformerExclusive 2; } optionVar -stringValue deformerExclName $partitionNameVal; } } // // Procedure Name: // deformerSetOptionVars // // Description: // Initialize the option values. // // Input Arguments: // deformerName - The name of the deformer. // It is used to get the specific method // of the deformer // forceFactorySettings - Whether to set the options to default values. // // Return Value: // None. // global proc deformerSetOptionVars(string $deformerName, int $forceFactorySettings) { setCommonOptionVars($forceFactorySettings); // customized part // command: deformerNameSetOptionVars($forceFactorySettings) string $customizedFunName = $deformerName + "SetOptionVars( " + $forceFactorySettings + ")"; eval($customizedFunName); } // // Procedure Name: // deformerUISetup // // Description: // Update the state of the common option box // UI to reflect the option values. // Both specific and common options values // will be updated. // User need to implement "XXXSetup" // (XXX is the name of the deformer) to make // the specific option values of the deformer // be handled. // // Input Arguments: // deformerName - The name of the deformer. // It is used to get the specific method // of the deformer // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // forceFactorySettings - Whether to set option values to the default values. // tabIndex - 0 = both tabs, 1 = basic, 2 = advanced // // Return Value: // None. // global proc deformerUISetup(string $deformerName, string $parent, int $forceFactorySettings, int $tabIndex) { // Retrieve the option settings // deformerSetOptionVars($deformerName, $forceFactorySettings); // common part deformerCommonUISetup($parent, $forceFactorySettings, $tabIndex); // customized part // command: deformerNameSetup("parent", $forceFactorySettings, $tabIndex) string $customizedFunName = $deformerName + "Setup( \"" + $parent + "\", " + $forceFactorySettings + ", " + $tabIndex + ")"; eval($customizedFunName); } // // Procedure Name: // deformerUICallback // // Description: // Update the option values with the current // state of the option box UI. // Both specific and common options values // will be updated. // // User need to implement "XXXCallBack" // (XXX is the name of the deformer) to make // the specific option values of the deformer // be handled. // // Input Arguments: // deformerName - The name of the specific deformer which is using // this call back function. // parent - Top level parent layout of the option box UI. Required so // that UI object names can be successfully resolved. // doIt - Whether to execute the command. // // Return Value: // None. // global proc deformerUICallback(string $deformerName, string $parent, int $doIt) { // common part deformerCommonUICallback($parent); // customized part // command: deformerNameCallback("parent", $doIt) string $customizedFunName = $deformerName + "Callback( \"" + $parent + "\", " + $doIt + ")"; eval($customizedFunName); } // // Procedure Name: // createTabUI // // Description: // create menu option tab for the deformer // This is a template method which only create the option box window // and "advanced" tab. // User need to implement "XXXTableUI()"(XXX is the name of the deformer) // method to add the widget in "basic" tab. // // Input Arguments: // deformerName - The name of the deformer. // It is used to get the specific method // of the deformer. // tabLayout - The name of the tab layout. // // Return Value: // None. // global proc createTabUI(string $deformerName, 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. Make common UI in tab "advanced" // if (2 == $currentTabIndex) { // Create UI for the second tab. // // Positioning of the deformer in the DG optionMenuGrp -label (uiRes("m_deformerOptionsTemplate.kDeformationOrder")) positioningWidget ; menuItem -label (uiRes("m_deformerOptionsTemplate.kDefault")) positionItem1; menuItem -label (uiRes("m_deformerOptionsTemplate.kBefore")) positionItem2; menuItem -label (uiRes("m_deformerOptionsTemplate.kAfter")) positionItem3; menuItem -label (uiRes("m_deformerOptionsTemplate.kSplit")) positionItem4; menuItem -label (uiRes("m_deformerOptionsTemplate.kParallel")) positionItem5; separator; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_deformerOptionsTemplate.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_deformerOptionsTemplate.kPartitiontoUse")) -enable `checkBoxGrp -q -v1 exclWidget` -cc "updatePartitionNameWidget" partitionListWidget; string $currentNameOption = ""; string $exclName = $deformerName + "ExclName"; if (`optionVar -exists $exclName`) { $currentNameOption = `optionVar -q $exclName`; } // add all the partitions to the menu // int $pp; string $partitionArray[]; $partitionArray = `ls -type partition`; int $partitionCount = size($partitionArray); menuItem -label (uiRes("m_deformerOptionsTemplate.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 $exclName "deformPartition"; } } textFieldGrp -label (uiRes("m_deformerOptionsTemplate.kNewPartitionName")) -enable `checkBoxGrp -q -v1 exclWidget` -tx "deformPartition" partitionNameWidget; updatePartitionNameWidget(); } // Make specific UI for deformer string $customizedFunName = $deformerName + "TabUI( \"" + $tab[$currentTabIndex-1] + "\", \"" + $currentTabIndex + "\")"; eval($customizedFunName); // Update the control values to match the options. // string $setupCmd = "deformerUISetup( \"" + $deformerName + "\", \"" + $tabLayout + "\", " + 0 + ", " + $currentTabIndex + ")"; eval($setupCmd); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; } } // // Procedure Name: // deformerOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // deformerName - The name of the deformer // It is used to get the specific method name // of the deformer. // // Return Value: // None. // global proc deformerOptions(string $deformerName) { // 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($deformerName); // STEP 3: 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 ("createTabUI(\"" + $deformerName + "\", \"" + $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_deformerOptionsTemplate.kBasic")) -tabLabelIndex 2 (uiRes("m_deformerOptionsTemplate.kAdvanced")) $tabLayout; // Create the UI for the tab that is initially visible. // createTabUI($deformerName, $tabLayout); // Step 5: Deactivate the default UI template. // =========================================== // // Note: this option box example delays the creation of the UI // until it's 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. // // command: deformerUICallback("deformerName", "tabLayout", 1); string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_deformerOptionsTemplate.kCreate")) -command ("deformerUICallback( \"" + $deformerName + "\", \"" + $tabLayout + "\", " + 1 + " )") $applyBtn; // 'Save' button. // // command: deformerUICallback("deformerName", "tabLayout", 0);hideOptionBox; string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ("deformerUICallback( \"" + $deformerName + "\", \"" + $tabLayout + "\", " + 0 + " )" + "; hideOptionBox") $saveBtn; // 'Reset' button. // // command: deformerUISetup("deformerName", "tabLayout", 1, 0) string $resetBtn = getOptionBoxResetBtn(); button -edit -command ("deformerUISetup( \"" + $deformerName + "\", \"" + $tabLayout + "\", " + 1 + ", " + 0 + ")") $resetBtn; // Step 7: Set the option box title. // ================================= // string $titleNameFun = $deformerName + "OptionBoxTitle();"; eval($titleNameFun); // Step 8: Customize the 'Help' menu item text. // ============================================ // string $helpTagFun = $deformerName + "OptionBoxHelpTag();"; eval($helpTagFun); // Step 9: Show the option box. // ============================= // showOptionBox(); }