// =========================================================================== // 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 sets up the Create ShrinkWrap dialog box // // Input Arguments: // None. // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { // projection // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapProjection`) { optionVar -stringValue shrinkWrapProjection "inner"; } // Closest If No Intersection // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapClosestIfNoIntersection`) { optionVar -intValue shrinkWrapClosestIfNoIntersection 0; } // reverse // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapReverse`) { optionVar -intValue shrinkWrapReverse 0; } // bidirectional // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapBidirectional`) { optionVar -intValue shrinkWrapBidirectional 0; } // Bounding Box Center // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapBoundingBoxCenter`) { optionVar -intValue shrinkWrapBoundingBoxCenter 0; } // axis reference // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapAxisReference`) { optionVar -stringValue shrinkWrapAxisReference "target"; } // along X // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapAlongX`) { optionVar -intValue shrinkWrapAlongX 0; } // along Y // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapAlongY`) { optionVar -intValue shrinkWrapAlongY 0; } // along Z // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapAlongZ`) { optionVar -intValue shrinkWrapAlongZ 0; } // offset // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapOffset`) { optionVar -floatValue shrinkWrapOffset 0; } // targetInflation // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapTargetInflation`) { optionVar -floatValue shrinkWrapTargetInflation 0; } // single node // if ( $forceFactorySettings || !`optionVar -exists shrinkWrapSingleNode`) { optionVar -intValue shrinkWrapSingleNode 1; } } // // Procedure Name: // createShrinkWrapSetup // // 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 createShrinkWrapSetup (string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; int $closestIfNoIntersection = `optionVar -query shrinkWrapClosestIfNoIntersection`; checkBoxGrp -e -value1 $closestIfNoIntersection cniWidget; int $reverse = `optionVar -query shrinkWrapReverse`; checkBoxGrp -e -value1 $reverse revWidget; int $bidirectional = `optionVar -query shrinkWrapBidirectional`; checkBoxGrp -e -value1 $bidirectional biWidget; int $boundingBoxCenter = `optionVar -query shrinkWrapBoundingBoxCenter`; checkBoxGrp -e -value1 $boundingBoxCenter bbcWidget; int $alongX = `optionVar -query shrinkWrapAlongX`; checkBoxGrp -e -value1 $alongX axWidget; int $alongY = `optionVar -query shrinkWrapAlongY`; checkBoxGrp -e -value1 $alongY ayWidget; int $alongZ = `optionVar -query shrinkWrapAlongZ`; checkBoxGrp -e -value1 $alongZ azWidget; float $offset = `optionVar -query shrinkWrapOffset`; floatSliderGrp -e -value $offset oWidget; float $targetInflation = `optionVar -query shrinkWrapTargetInflation`; floatSliderGrp -e -value $targetInflation tiWidget; string $projection = `optionVar -query shrinkWrapProjection`; if($projection == "inner") { optionMenuGrp -edit -select 1 prjWidget; } else if($projection == "center") { optionMenuGrp -edit -select 2 prjWidget; } else if($projection == "parallel") { optionMenuGrp -edit -select 3 prjWidget; } else if($projection == "normals") { optionMenuGrp -edit -select 4 prjWidget; } else { optionMenuGrp -edit -select 5 prjWidget; } string $axisReference = `optionVar -query shrinkWrapAxisReference`; if($axisReference == "target") { optionMenuGrp -edit -select 1 arWidget; } else if($axisReference == "deformed") { optionMenuGrp -edit -select 2 arWidget; } else { optionMenuGrp -edit -select 3 arWidget; } int $singleNode = `optionVar -query shrinkWrapSingleNode`; checkBoxGrp -e -value1 $singleNode snWidget; shrinkWrapProjectionChanged(); } // // Procedure Name: // createShrinkWrapCallback // // 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 createShrinkWrapCallback (string $parent, int $doIt) { setParent $parent; optionVar -intValue shrinkWrapClosestIfNoIntersection `checkBoxGrp -q -value1 cniWidget`; optionVar -intValue shrinkWrapReverse `checkBoxGrp -q -value1 revWidget`; optionVar -intValue shrinkWrapBidirectional `checkBoxGrp -q -value1 biWidget`; optionVar -intValue shrinkWrapBoundingBoxCenter `checkBoxGrp -q -value1 bbcWidget`; optionVar -intValue shrinkWrapAlongX `checkBoxGrp -q -value1 axWidget`; optionVar -intValue shrinkWrapAlongY `checkBoxGrp -q -value1 ayWidget`; optionVar -intValue shrinkWrapAlongZ `checkBoxGrp -q -value1 azWidget`; optionVar -floatValue shrinkWrapOffset `floatSliderGrp -q -value oWidget`; optionVar -floatValue shrinkWrapTargetInflation `floatSliderGrp -q -value tiWidget`; string $projection = "inner"; int $projectionMode = `optionMenuGrp -q -select prjWidget`; switch ( $projectionMode ) { case 1: $projection = "inner"; break; case 2: $projection = "center"; break; case 3: $projection = "parallel"; break; case 4: $projection = "normals"; break; case 5: $projection = "closest"; break; } optionVar -stringValue shrinkWrapProjection $projection; string $axisReference = "target"; int $axisReferenceMode = `optionMenuGrp -q -select arWidget`; switch ( $axisReferenceMode ) { case 1: $axisReference = "target"; break; case 2: $axisReference = "deformed"; break; case 3: $axisReference = "global"; break; } optionVar -stringValue shrinkWrapAxisReference $axisReference; optionVar -intValue shrinkWrapSingleNode `checkBoxGrp -q -value1 snWidget`; if ($doIt) { performCreateShrinkWrap false; addToRecentCommandQueue "performCreateShrinkWrap false" "CreateShrinkWrap"; } } global proc shrinkWrapProjectionChanged() { int $projection = `optionMenuGrp -q -select prjWidget`; if ( $projection == 2 ) { checkBoxGrp -e -enable 1 bbcWidget; } else { checkBoxGrp -e -enable 0 bbcWidget; } if ( $projection == 3 ) { optionMenuGrp -e -enable 1 arWidget; checkBoxGrp -e -enable 1 axWidget; checkBoxGrp -e -enable 1 ayWidget; checkBoxGrp -e -enable 1 azWidget; } else { optionMenuGrp -e -enable 0 arWidget; checkBoxGrp -e -enable 0 axWidget; checkBoxGrp -e -enable 0 ayWidget; checkBoxGrp -e -enable 0 azWidget; } } global proc createShrinkWrapOptions () { // Name of the command for this option box // string $commandName = "createShrinkWrap"; // Build the option box "methods" // 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. // ================================================= // // 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("performShrinkWrap"); // 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_performCreateShrinkWrap.kProjection")) -cc shrinkWrapProjectionChanged prjWidget; menuItem -label (uiRes("m_performCreateShrinkWrap.kTowardInnerObject")) prjWidgetPos1; menuItem -label (uiRes("m_performCreateShrinkWrap.kTowardCenter")) prjWidgetPos2; menuItem -label (uiRes("m_performCreateShrinkWrap.kParallelToAxes")) prjWidgetPos3; menuItem -label (uiRes("m_performCreateShrinkWrap.kVertexNormals")) prjWidgetPos4; menuItem -label (uiRes("m_performCreateShrinkWrap.kClosest")) prjWidgetPos5; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kClosestIfNoIntersection")) -numberOfCheckBoxes 1 cniWidget; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kBidirectional")) -numberOfCheckBoxes 1 biWidget; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kReverse")) -numberOfCheckBoxes 1 revWidget; floatSliderGrp -label (uiRes("m_performCreateShrinkWrap.kOffset")) -field true oWidget; floatSliderGrp -label (uiRes("m_performCreateShrinkWrap.kTargetInflation")) -field true tiWidget; separator; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kBoundingBoxCenter")) -numberOfCheckBoxes 1 bbcWidget; separator; optionMenuGrp -label (uiRes("m_performCreateShrinkWrap.kAxisReference")) arWidget; menuItem -label (uiRes("m_performCreateShrinkWrap.kTargetLocal")) arWidgetPos1; menuItem -label (uiRes("m_performCreateShrinkWrap.kDeformedLocal")) arWidgetPos2; menuItem -label (uiRes("m_performCreateShrinkWrap.kGlobal")) arWidgetPos3; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kAlongX")) -numberOfCheckBoxes 1 axWidget; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kAlongY")) -numberOfCheckBoxes 1 ayWidget; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kAlongZ")) -numberOfCheckBoxes 1 azWidget; separator; checkBoxGrp -label (uiRes("m_performCreateShrinkWrap.kSingleShrinkwrapNode")) -numberOfCheckBoxes 1 snWidget; // 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 -label (uiRes("m_performCreateShrinkWrap.kCreate")) -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_performCreateShrinkWrap.kCreateShrinkWrapOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "CreateShrinkWrap" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } proc string assembleCmd () { string $cmd; setOptionVars( false ); $cmd = "doShrinkWrapArgList \"1\" { \"1\""; string $projection = `optionVar -query shrinkWrapProjection`; if($projection == "inner") { $cmd += (", \"0\""); } else if($projection == "center") { $cmd += (", \"1\""); } else if($projection == "parallel") { $cmd += (", \"2\""); } else if($projection == "normals") { $cmd += (", \"3\""); } else { $cmd += (", \"4\""); } int $closestIfNoIntersection = `optionVar -q shrinkWrapClosestIfNoIntersection`; $cmd += (", \""+$closestIfNoIntersection+"\""); int $reverse = `optionVar -q shrinkWrapReverse`; $cmd += (", \""+$reverse+"\""); int $bidirectional = `optionVar -q shrinkWrapBidirectional`; $cmd += (", \""+$bidirectional+"\""); int $boundingBoxCenter = `optionVar -q shrinkWrapBoundingBoxCenter`; $cmd += (", \""+$boundingBoxCenter+"\""); string $axisReference = `optionVar -query shrinkWrapAxisReference`; if($axisReference == "target") { $cmd += (", \"0\""); } else if($axisReference == "deformed") { $cmd += (", \"1\""); } else { $cmd += (", \"2\""); } int $alongX = `optionVar -q shrinkWrapAlongX`; $cmd += (", \""+$alongX+"\""); int $alongY = `optionVar -q shrinkWrapAlongY`; $cmd += (", \""+$alongY+"\""); int $alongZ = `optionVar -q shrinkWrapAlongZ`; $cmd += (", \""+$alongZ+"\""); float $offset = `optionVar -q shrinkWrapOffset`; $cmd += (", \""+$offset+"\""); float $targetInflation = `optionVar -q shrinkWrapTargetInflation`; $cmd += (", \""+$targetInflation+"\""); int $singleNode = `optionVar -q shrinkWrapSingleNode`; $cmd += (", \""+$singleNode+"\""); $cmd = $cmd + " }"; return $cmd; } global proc string performCreateShrinkWrap (int $action) // // The action variable means // 0 - do the command // 1 - show the option box // 2 - return the drag command { string $cmd = ""; switch ($action) { case 0: // Execute the command // Retrieve the option settings // setOptionVars (false); // Get the command and print it in the command window $cmd = `assembleCmd`; // Execute the command with the option settings eval($cmd); break; case 1: // Do the option box createShrinkWrapOptions; break; case 2: // Return the drag string // Retrieve the option settings // setOptionVars (false); // Get the command $cmd = `assembleCmd`; break; } return $cmd; }