// =========================================================================== // 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: 29 April 1997 // // Description: // Initialize the option values for offset curve on surface menu item. // // Input Arguments: // int action // 0 - just execute the offset curve operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Global or local tolerance: if( $forceFactorySettings || !`optionVar -exists offsetCosUseGlobalTol` ){ optionVar -intValue offsetCosUseGlobalTol false; } // Connect breaks (0=off 1=circular 2=linear). // if ($forceFactorySettings || !`optionVar -exists offsetCosConnectBreaks`) { optionVar -intValue offsetCosConnectBreaks 2; } // Stitch (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists offsetCosStitch`) { optionVar -intValue offsetCosStitch 1; } // Cut loops (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists offsetCosCutLoop`) { optionVar -intValue offsetCosCutLoop 0; } // Offset distance. // if ($forceFactorySettings || !`optionVar -exists offsetCosDistance`) { optionVar -floatValue offsetCosDistance 1.0; } // Tolerance control (on-1 or off-0 used for depth and bias). // if ($forceFactorySettings || !`optionVar -exists offsetCosTolerance`) { optionVar -floatValue offsetCosTolerance 0.01; } // Subdivision density // if ($forceFactorySettings || !`optionVar -exists offsetCosSubdivDensity`) { optionVar -intValue offsetCosSubdivDensity 5; } // curve range if ($forceFactorySettings || !`optionVar -exists offsetCosRangePartial`){ optionVar -intValue offsetCosRangePartial 0; } } // // Procedure Name: // offsetCosSetup // // Description: // Update the state of the option box UI to reflect the offsetCos // 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 offsetCosSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); offsetCosToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. // Global vs. local tolerance int $useGlobalTol = `optionVar -q offsetCosUseGlobalTol`; radioButtonGrp -e -sl (2 - $useGlobalTol) useGlobalTol; // Distance // floatSliderGrp -edit -value `optionVar -q offsetCosDistance` offsetCosDistanceFloatSliderGrp; // Connect breaks. // int $doConnectBreaks = `optionVar -q offsetCosConnectBreaks`; if( 0 == $doConnectBreaks ) $doConnectBreaks = 3; radioButtonGrp -edit -sl $doConnectBreaks offsetCosConnectBreaksRadioButtonGrp; // Loop cutting. // int $doCutLoop = `optionVar -q offsetCosCutLoop`; radioButtonGrp -edit -sl (2 - $doCutLoop) offsetCosCutLoopRadioButtonGrp; // Subdivision density // intSliderGrp -edit -value `optionVar -q offsetCosSubdivDensity` offsetCosSubdivDensityIntSliderGrp; // Tolerance // floatSliderGrp -edit -v `optionVar -q offsetCosTolerance` offsetCosTolerance; // curve range on inputs. // int $offsetCosRangePartial = `optionVar -q offsetCosRangePartial`+1 ; radioButtonGrp -edit -sl $offsetCosRangePartial offsetCosRangeRadioButtonGrp ; if( $useGlobalTol ) { tabLayout -e -selectTab noSlider useGlobalTolTab; } else { tabLayout -e -selectTab slider useGlobalTolTab; } if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } } // // Procedure Name: // offsetCosCallback // // 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 offsetCosCallback(string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv offsetCosEuc `scriptCtx -q -euc $goToTool`; optionVar -iv offsetCosLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // get Values from controls. int $offsetCosRangePartial = `radioButtonGrp -q -sl offsetCosRangeRadioButtonGrp` - 1 ; optionVar -intValue offsetCosRangePartial $offsetCosRangePartial; // distance optionVar -floatValue offsetCosDistance `floatSliderGrp -q -value offsetCosDistanceFloatSliderGrp`; // connect breaks int $breaks = `radioButtonGrp -q -sl offsetCosConnectBreaksRadioButtonGrp`; if( 3 == $breaks ) $breaks = 0; optionVar -intValue offsetCosConnectBreaks $breaks; // loop cutting int $lc = 2 - `radioButtonGrp -q -sl offsetCosCutLoopRadioButtonGrp`; optionVar -intValue offsetCosCutLoop $lc; // subdivision density optionVar -intValue offsetCosSubdivDensity `intSliderGrp -q -value offsetCosSubdivDensityIntSliderGrp`; // tolerance optionVar -floatValue offsetCosTolerance `floatSliderGrp -q -v offsetCosTolerance`; // global vs. local: int $useGlobalTol = 2 - `radioButtonGrp -q -sl useGlobalTol`; optionVar -intValue offsetCosUseGlobalTol $useGlobalTol; if (1 == $doIt) { performOffsetCos( 0, $goToTool ); string $tmpCmd = "performOffsetCos( 0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Offset Curve On Surface"; } else if( $doIt ) { setToolTo $goToTool; } } // // Procedure Name: // createoffsetCosUI // // Description: // Fill the contents of the option box for offsetCos command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createOffsetCosUI(string $parent, int $inTheTool, string $goToTool) { setParent $parent; floatSliderGrp -field on -fmn -1000. -fmx 1000. -min -10. -max 10. -label (uiRes("m_performOffsetCos.kOffsetDistance")) offsetCosDistanceFloatSliderGrp; radioButtonGrp -nrb 3 -sl 1 -label (uiRes("m_performOffsetCos.kConnectBreaks")) -label1 (uiRes("m_performOffsetCos.kCircular")) -da1 1 -label2 (uiRes("m_performOffsetCos.kLinear")) -da2 2 -label3 (uiRes("m_performOffsetCos.kConnectBreaksOff")) -da3 0 offsetCosConnectBreaksRadioButtonGrp; string $tabLayoutName = (`setParent -q` + "|offsetCosLoopCutOptions_Tabs"); radioButtonGrp -nrb 2 -sl 1 -label (uiRes("m_performOffsetCos.kLoopCutting")) -label1 (uiRes("m_performOffsetCos.kOn")) -da1 1 -label2 (uiRes("m_performOffsetCos.kOff")) -da2 0 offsetCosCutLoopRadioButtonGrp; intSliderGrp -field on -min 0 -max 10 -fmn 0 -fmx 100 -label (uiRes("m_performOffsetCos.kMaxSubdivisionDensity")) offsetCosSubdivDensityIntSliderGrp; radioButtonGrp -nrb 2 -label (uiRes("m_performOffsetCos.kUseTolerance")) -label1 (uiRes("m_performOffsetCos.kGlobal")) -label2 (uiRes("m_performOffsetCos.kLocal")) -on1 "tabLayout -e -selectTab noSlider useGlobalTolTab" -on2 "tabLayout -e -selectTab slider useGlobalTolTab" useGlobalTol; tabLayout -tabsVisible false useGlobalTolTab; columnLayout slider; floatSliderGrp -label (uiRes("m_performOffsetCos.kTolerance")) -min 0.001 -max 1.0 -fmn 0.00001 -fmx 10.0 offsetCosTolerance; setParent ..; columnLayout noSlider; setParent ..; setParent ..; separator; // layout for add curve range, create as polygons. // radioButtonGrp -nrb 2 -label (uiRes("m_performOffsetCos.kCurveRange")) -label1 (uiRes("m_performOffsetCos.kComplete")) -da1 0 -label2 (uiRes("m_performOffsetCos.kPartial")) -da2 1 -sl 1 offsetCosRangeRadioButtonGrp; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performOffsetCos.kToolBehavior")) -label1 (uiRes("m_performOffsetCos.kExitOnCompletion")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performOffsetCos.kAutoCompletion")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // offsetCosOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc offsetCosOptions( int $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "offsetCos"; string $optionBoxTitle; if( $inTheTool ) { $optionBoxTitle = (uiRes("m_performOffsetCos.kOffsetSurfaceToolOptions")); } else { $optionBoxTitle = (uiRes("m_performOffsetCos.kOffsetSurfaceOptions")); } // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolOffsetCoS"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "offsetCosToolScript 3"; // 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; // Pass the command name to the option box. // // Any default option box behavior based on the command name is set // up with this call. // setOptionBoxCommandName("offsetCurveOnSurface"); // 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; // RECOMMENDATION: Place the UI in a scroll layout. If the // option box window is ever resized such that it's entire // contents is not visible then the scroll bars provided by the // scroll layout will allow the user to access the hidden UI. // tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // Create the UI for the tab that is initially visible. // createOffsetCosUI($parent, $inTheTool, $goToTool); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // 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. // 'offsetCos' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performOffsetCos.kOffsetTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"") $applyBtn; } else { button -edit -label (uiRes("m_performOffsetCos.kOffset")) -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"") $applyBtn; } // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " 0 \"" + $goToTool + "\"; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"") $resetBtn; // Set the option box title. // setOptionBoxTitle($optionBoxTitle); // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "OffsetCurveOnSurface" ); // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // offsetCosHelp // // Description: // Returns a short description about the offsetCos command. // // Input Arguments: // None. // // Return Value: // string. // proc string offsetCosHelp() { return " Command: offsetCos - create a offset 2d curve from a 2d curve.\n" + "Select at least one curve on surface to offset."; } // // Procedure Name: // assembleCmd // // Description: // Construct the offsetCos command that will apply the option box // values. // // Input Arguments: // None. // // Return Value: // The offsetCos command string. // proc string assembleCmd() { setOptionVars(false); string $cmd = "offsetCosPreset"; $cmd = $cmd + "(" ; // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; $cmd = $cmd + $doHistory + ","; int $curveRangePartial = `optionVar -q offsetCosRangePartial`; $cmd = $cmd + $curveRangePartial + "," ; int $connectBreaks = `optionVar -q offsetCosConnectBreaks`; $cmd = $cmd + $connectBreaks + ","; int $stitch = `optionVar -q offsetCosStitch`; $cmd = $cmd + $stitch + ","; int $cutLoop = `optionVar -q offsetCosCutLoop`; $cmd = $cmd + $cutLoop + ","; float $distance = `optionVar -q offsetCosDistance`; $cmd = $cmd + $distance + ","; float $tolerance = `optionVar -q offsetCosTolerance`; if( `optionVar -q offsetCosUseGlobalTol` ) { $tolerance = `optionVar -q positionalTolerance`; } $cmd = $cmd + $tolerance + ","; int $subdivDensity = `optionVar -q offsetCosSubdivDensity`; $cmd = $cmd + $subdivDensity; $cmd = $cmd + ")"; return $cmd; } // // Procedure Name: // performoffsetCos // // Description: // Perform the offsetCos 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 offsetCos command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command to drag to shelf. // // Return Value: // The offsetCos command string. // global proc string performOffsetCos( int $action, string $goToTool ) { int $inTheTool = false; if( 3 == $action ) { $action = 1; $inTheTool = true; } string $cmd = ""; switch ($action) { case 0: setOptionVars(false); $cmd = `assembleCmd`; eval($cmd); break; case 1: offsetCosOptions( $inTheTool, $goToTool ); break; case 2: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }