// =========================================================================== // 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: 5 May 1997 // // Description: // This script defines the option box for the NURBS cone menu item. // // // 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) { if( $forceFactorySettings || !`optionVar -exists nurbsConeGroupCaps`){ optionVar -intValue nurbsConeGroupCaps true; } if( $forceFactorySettings || !`optionVar -exists nurbsConeUseGlobalTolerance`){ optionVar -intValue nurbsConeUseGlobalTolerance false; } if ($forceFactorySettings || !`optionVar -exists nurbsConePivotType`) { optionVar -intValue nurbsConePivotType 1; } if ($forceFactorySettings || !`optionVar -exists nurbsConePivotX`) { optionVar -floatValue nurbsConePivotX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConePivotY`) { optionVar -floatValue nurbsConePivotY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConePivotZ`) { optionVar -floatValue nurbsConePivotZ 0.0; } string $isitYup = `upAxis -q -ax`; if( "y" == $isitYup ) { if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisType`) { optionVar -intValue nurbsConeAxisType 2; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisX`) { optionVar -floatValue nurbsConeAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisY`) { optionVar -floatValue nurbsConeAxisY 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisZ`) { optionVar -floatValue nurbsConeAxisZ 0.0; } } else { if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisType`) { optionVar -intValue nurbsConeAxisType 3; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisX`) { optionVar -floatValue nurbsConeAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisY`) { optionVar -floatValue nurbsConeAxisY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeAxisZ`) { optionVar -floatValue nurbsConeAxisZ 1.0; } } if ($forceFactorySettings || !`optionVar -exists nurbsConeStartSweep`) { optionVar -floatValue nurbsConeStartSweep 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeEndSweep`) { optionVar -floatValue nurbsConeEndSweep 360.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeRadius`) { optionVar -floatValue nurbsConeRadius 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeHeightRatio`) { optionVar -floatValue nurbsConeHeightRatio 2.0; } if ($forceFactorySettings || !`optionVar -exists nurbsConeDegree`) { optionVar -intValue nurbsConeDegree 3; } if ($forceFactorySettings || !`optionVar -exists nurbsConeUseTolerance`) { optionVar -intValue nurbsConeUseTolerance false; } if ($forceFactorySettings || !`optionVar -exists nurbsConeTolerance`) { optionVar -floatValue nurbsConeTolerance 0.01; } if ($forceFactorySettings || !`optionVar -exists nurbsConeSections`) { optionVar -intValue nurbsConeSections 8; } if ($forceFactorySettings || !`optionVar -exists nurbsConeSpans`) { optionVar -intValue nurbsConeSpans 1; } if ($forceFactorySettings || !`optionVar -exists nurbsConeCaps`) { optionVar -intValue nurbsConeCaps 0; } } // // Procedure Name: // nurbsConeSetup // // 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 nurbsConeSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // Pivot // int $pivotType = `optionVar -q nurbsConePivotType`; float $pivotX = `optionVar -q nurbsConePivotX`; float $pivotY = `optionVar -q nurbsConePivotY`; float $pivotZ = `optionVar -q nurbsConePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } radioButtonGrp -e -select $pivotType nurbsConePivotType; floatFieldGrp -e -v1 $pivotX -v2 $pivotY -v3 $pivotZ nurbsConePivot; // Axis // int $axisType = `optionVar -q nurbsConeAxisType`; float $axis[3]; switch($axisType) { case 1: $axis[0] = 1; $axis[1] = 0; $axis[2] = 0; break; case 2: $axis[0] = 0; $axis[1] = 1; $axis[2] = 0; break; case 3: $axis[0] = 0; $axis[1] = 0; $axis[2] = 1; break; case 4: $axis[0] = `optionVar -q nurbsConeAxisX`; $axis[1] = `optionVar -q nurbsConeAxisY`; $axis[2] = `optionVar -q nurbsConeAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } if( $axisType < 4 ) { radioButtonGrp -e -select $axisType nurbsConeAxisType1; } else { radioButtonGrp -e -select ( $axisType - 3 ) nurbsConeAxisType2; } floatFieldGrp -e -v1 $axis[0] -v2 $axis[1] -v3 $axis[2] nurbsConeAxis; // Sweep Angle (Start and End) // floatSliderGrp -e -v `optionVar -q nurbsConeStartSweep` nurbsConeStartSweep; floatSliderGrp -e -v `optionVar -q nurbsConeEndSweep` nurbsConeEndSweep; // Radius // float $radius = `optionVar -q nurbsConeRadius`; floatSliderGrp -e -v $radius nurbsConeRadius; // Height Ratio // float $ratio = `optionVar -q nurbsConeHeightRatio`; floatSliderGrp -e -v `nurbsRatioConvert $radius $ratio false` nurbsConeHeight; // Degree // int $degree = `optionVar -q nurbsConeDegree`; int $degreeBtn; switch($degree) { case 1: $degreeBtn = 1; break; case 3: $degreeBtn = 2; break; } radioButtonGrp -e -select $degreeBtn nurbsConeDegree; int $groupCaps = `optionVar -q nurbsConeGroupCaps`; checkBoxGrp -e -v1 $groupCaps nurbsConeGroupCapsWidget; // Tolerance // int $useGlobalTol = `optionVar -q nurbsConeUseGlobalTolerance`; int $useTolerance = `optionVar -q nurbsConeUseTolerance`; if( $useTolerance ) { if( $useGlobalTol ) { radioButtonGrp -e -select 3 coneUseTolerance; } else { radioButtonGrp -e -select 2 coneUseTolerance; } } else { radioButtonGrp -e -select 1 coneUseTolerance; } floatSliderGrp -e -v `optionVar -q nurbsConeTolerance` coneTolerance; // Sections // intSliderGrp -e -v `optionVar -q nurbsConeSections` nurbsConeSections; // Spans // intSliderGrp -e -v `optionVar -q nurbsConeSpans` nurbsConeSpans; radioButtonGrp -e -select (`optionVar -q nurbsConeCaps`+1) nurbsConeCaps; // Disable or enable some controls depending on other values. // if ($pivotType == 2) floatFieldGrp -e -enable 1 nurbsConePivot; else floatFieldGrp -e -enable 0 nurbsConePivot; if ($axisType == 4) floatFieldGrp -e -enable 1 nurbsConeAxis; else floatFieldGrp -e -enable 0 nurbsConeAxis; if ($useTolerance) { if( $useGlobalTol ) { tabLayout -e -vis false tabLayoutForTolerance; } else { tabLayout -e -vis true -selectTab tabWithTolerance tabLayoutForTolerance; } } else { tabLayout -e -vis true -selectTab tabWithoutTolerance tabLayoutForTolerance; } } // // Procedure Name: // nurbsConeCallback // // 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 nurbsConeCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // Pivot // int $pivotType = `radioButtonGrp -q -select nurbsConePivotType`; optionVar -intValue nurbsConePivotType $pivotType; if ($pivotType == 2) { optionVar -floatValue nurbsConePivotX `floatFieldGrp -q -v1 nurbsConePivot`; optionVar -floatValue nurbsConePivotY `floatFieldGrp -q -v2 nurbsConePivot`; optionVar -floatValue nurbsConePivotZ `floatFieldGrp -q -v3 nurbsConePivot`; } // Axis // int $axisType = `radioButtonGrp -q -select nurbsConeAxisType1`; if( 0 == $axisType ) { $axisType = `radioButtonGrp -q -select nurbsConeAxisType2` + 3; } optionVar -intValue nurbsConeAxisType $axisType; if( ($axisType == 4) || ($axisType == 5) ) { optionVar -floatValue nurbsConeAxisX `floatFieldGrp -q -v1 nurbsConeAxis`; optionVar -floatValue nurbsConeAxisY `floatFieldGrp -q -v2 nurbsConeAxis`; optionVar -floatValue nurbsConeAxisZ `floatFieldGrp -q -v3 nurbsConeAxis`; } // Sweep Angle (Start and End) // optionVar -floatValue nurbsConeStartSweep `floatSliderGrp -q -v nurbsConeStartSweep`; optionVar -floatValue nurbsConeEndSweep `floatSliderGrp -q -v nurbsConeEndSweep`; // Radius // float $radius = `floatSliderGrp -q -v nurbsConeRadius`; optionVar -floatValue nurbsConeRadius $radius; // Height Ratio // float $height = `floatSliderGrp -q -v nurbsConeHeight`; optionVar -floatValue nurbsConeHeightRatio `nurbsRatioConvert $radius $height true`; optionVar -iv nurbsConeGroupCaps `checkBoxGrp -q -v1 nurbsConeGroupCapsWidget`; // Degree // int $degreeBtn = `radioButtonGrp -q -select nurbsConeDegree`; int $degree; switch($degreeBtn) { case 1: $degree = 1; break; case 2: $degree = 3; break; } optionVar -intValue nurbsConeDegree $degree; // Tolerance // int $useTolerance = `radioButtonGrp -q -select coneUseTolerance`; switch( $useTolerance ) { case 1: optionVar -intValue nurbsConeUseTolerance false; break; case 2: optionVar -intValue nurbsConeUseTolerance true; optionVar -intValue nurbsConeUseGlobalTolerance false; break; case 3: default: optionVar -intValue nurbsConeUseTolerance true; optionVar -intValue nurbsConeUseGlobalTolerance true; break; } optionVar -floatValue nurbsConeTolerance `floatSliderGrp -q -v coneTolerance`; // Sections // optionVar -intValue nurbsConeSections `intSliderGrp -q -v nurbsConeSections`; // Spans // optionVar -intValue nurbsConeSpans `intSliderGrp -q -v nurbsConeSpans`; // Caps // optionVar -intValue nurbsConeCaps ( `radioButtonGrp -q -select nurbsConeCaps` - 1 ); if ($doIt) { performNurbsCone 0; addToRecentCommandQueue "performNurbsCone 0" "NURBS Cone"; } } // // Procedure Name: // nurbsConeOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc nurbsConeOptions() { // Name of the command for this option box. // string $commandName = "nurbsCone"; // Build the option box actions. // 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("cone"); // 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; // Turn on the wait cursor. // waitCursor -state 1; // STEP 4: Create option box contents. // =================================== // tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; radioButtonGrp -label (uiRes("m_performNurbsCone.kPivot")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCone.kObject")) -label2 (uiRes("m_performNurbsCone.kUserDefined")) -select 1 nurbsConePivotType; floatFieldGrp -label (uiRes("m_performNurbsCone.kPivotPoint")) -numberOfFields 3 nurbsConePivot; string $axis = (uiRes("m_performNurbsCone.kAxis")); radioButtonGrp -label $axis -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsCone.kX")) -label2 (uiRes("m_performNurbsCone.kY")) -label3 (uiRes("m_performNurbsCone.kZ")) -select 1 nurbsConeAxisType1; radioButtonGrp -label $axis -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCone.kFree")) -label2 (uiRes("m_performNurbsCone.kActiveView")) -scl "nurbsConeAxisType1" nurbsConeAxisType2; floatFieldGrp -label (uiRes("m_performNurbsCone.kAxisDefinition")) -numberOfFields 3 nurbsConeAxis; separator; floatSliderGrp -label (uiRes("m_performNurbsCone.kStartSweepAngle")) -min 0 -max 360 -fmn -3600 -fmx 3600 nurbsConeStartSweep; floatSliderGrp -label (uiRes("m_performNurbsCone.kEndSweepAngle")) -min 0 -max 360 -fmn -3600 -fmx 3600 nurbsConeEndSweep; floatSliderGrp -label (uiRes("m_performNurbsCone.kRadius")) -fmn 0.0001 -fmx 1000.0 -min 0.0001 -max 100 nurbsConeRadius; floatSliderGrp -label (uiRes("m_performNurbsCone.kHeight")) -fmn 0 -fmx 1000.0 -min 0 -max 100 nurbsConeHeight; radioButtonGrp -label (uiRes("m_performNurbsCone.kSurfaceDegree")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCone.kLinear")) -label2 (uiRes("m_performNurbsCone.kCubic")) -select 2 nurbsConeDegree; // "Tolerance" disappears when "Use Tolerance" is false. // "Sections" disappears when "Use Tolerance" is true. // Note that the "-rational" flag no longer exists for // the cone command. We do things as if the "-rational" // flag were always false. string $none = (uiRes("m_performNurbsCone.kNone")) ; radioButtonGrp -label (uiRes("m_performNurbsCone.kCaps")) -numberOfRadioButtons 2 -label1 $none -label2 (uiRes("m_performNurbsCone.kBottom")) nurbsConeCaps; checkBoxGrp -label "" -ncb 1 -label1 (uiRes("m_performNurbsCone.kExtraTransformOnCaps")) nurbsConeGroupCapsWidget; radioButtonGrp -nrb 3 -label (uiRes("m_performNurbsCone.kUseTolerance")) -label1 $none -label2 (uiRes("m_performNurbsCone.kLocal")) -label3 (uiRes("m_performNurbsCone.kGlobal")) coneUseTolerance; tabLayout -tabsVisible false tabLayoutForTolerance; columnLayout tabWithoutTolerance; intSliderGrp -label (uiRes("m_performNurbsCone.kNumberOfSections")) -field true -min 4 -max 50 -fmx 200 nurbsConeSections; intSliderGrp -label (uiRes("m_performNurbsCone.kNumberOfSpans")) -field true -min 1 -max 50 -fmx 200 nurbsConeSpans; setParent ..; columnLayout tabWithTolerance; floatSliderGrp -label (uiRes("m_performNurbsCone.kPositionalTolerance")) -min 0.001 -max 1 -fmx 100.0 coneTolerance; setParent ..; setParent ..; // Set the pivot float fields to only be enabled when "Pivot" is "User Defined" // string $pivotEnable = ("floatFieldGrp -e -en 1 nurbsConePivot;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsConePivotX`" + " -v2 `optionVar -q nurbsConePivotY`" + " -v3 `optionVar -q nurbsConePivotZ`" + " nurbsConePivot;" ); string $pivotDisable = "floatFieldGrp -e -en 0 nurbsConePivot;"; radioButtonGrp -edit -cc1 ($pivotDisable + "floatFieldGrp -e -value 0.0 0.0 0.0 0.0 nurbsConePivot;") -cc2 $pivotEnable nurbsConePivotType; // Set the axis float fields to only be enabled when "Axis Preset" is "Free" // string $axisEnable = ("floatFieldGrp -e -en 1 nurbsConeAxis;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsConeAxisX`" + " -v2 `optionVar -q nurbsConeAxisY`" + " -v3 `optionVar -q nurbsConeAxisZ`" + " nurbsConeAxis;" ); string $axisDisable = "floatFieldGrp -e -en 0 nurbsConeAxis;"; radioButtonGrp -edit -cc1 ($axisDisable + "floatFieldGrp -e -value 1.0 0.0 0.0 0.0 nurbsConeAxis;") -cc2 ($axisDisable + "floatFieldGrp -e -value 0.0 1.0 0.0 0.0 nurbsConeAxis;") -cc3 ($axisDisable + "floatFieldGrp -e -value 0.0 0.0 1.0 0.0 nurbsConeAxis;") nurbsConeAxisType1; radioButtonGrp -edit -cc1 $axisEnable -cc2 $axisDisable nurbsConeAxisType2; // Set the "Use Tolerance" checkbox so that if the checkbox is on, // then the tolerance slider is visible. // radioButtonGrp -edit -on1 "tabLayout -e -vis true -selectTab tabWithoutTolerance tabLayoutForTolerance" -on2 "tabLayout -e -vis true -selectTab tabWithTolerance tabLayoutForTolerance" -on3 "tabLayout -e -vis false tabLayoutForTolerance" coneUseTolerance; // 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. // Disable those buttons that are not applicable to the option box. // Attach actions to those buttons that are applicable to the option box. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performNurbsCone.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_performNurbsCone.kNURBSConeOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "NurbsCone" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // nurbsConeHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string nurbsConeHelp() { return " Command: cone - create a NURBS cone.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "cone"; setOptionVars(false); int $pivotType = `optionVar -q nurbsConePivotType`; float $pivotX = `optionVar -q nurbsConePivotX`; float $pivotY = `optionVar -q nurbsConePivotY`; float $pivotZ = `optionVar -q nurbsConePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } // Axis // int $axisType = `optionVar -q nurbsConeAxisType`; float $axis[3]; switch($axisType) { case 1: $axis[0] = 1; $axis[1] = 0; $axis[2] = 0; break; case 2: $axis[0] = 0; $axis[1] = 1; $axis[2] = 0; break; case 3: $axis[0] = 0; $axis[1] = 0; $axis[2] = 1; break; case 4: $axis[0] = `optionVar -q nurbsConeAxisX`; $axis[1] = `optionVar -q nurbsConeAxisY`; $axis[2] = `optionVar -q nurbsConeAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } // History // int $doHistory = `constructionHistory -q -toggle`; float $tol = `optionVar -query nurbsConeTolerance`; if( `optionVar - q nurbsConeUseGlobalTolerance` ) { $tol = `optionVar -q positionalTolerance`; } $cmd = ($cmd + " -p " + $pivotX + " " + $pivotY + " " + $pivotZ + " -ax " + $axis[0] + " " + $axis[1] + " " + $axis[2] + " -ssw " + `optionVar -query nurbsConeStartSweep` + " -esw " + `optionVar -query nurbsConeEndSweep` + " -r " + `optionVar -query nurbsConeRadius` + " -hr " + `optionVar -query nurbsConeHeightRatio` + " -d " + `optionVar -query nurbsConeDegree` + " -ut " + `optionVar -query nurbsConeUseTolerance` + " -tol " + $tol + " -s " + `optionVar -query nurbsConeSections` + " -nsp " + `optionVar -query nurbsConeSpans` ); int $groupCaps = `optionVar -q nurbsConeGroupCaps`; int $caps = `optionVar -query nurbsConeCaps`; if( $caps ) { $cmd = $cmd + " -ch 1; nurbsPrimitiveCap " + $caps + " " + $doHistory + " " + $groupCaps; } else { $cmd = ($cmd + " -ch " + $doHistory ); } $cmd = $cmd + "; objectMoveCommand;"; if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = "setToolTo \"CreateNurbsConeCtx\""; } return $cmd; } // // Procedure Name: // performNurbsCone // // Description: // Perform the cone 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 cone 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 performNurbsCone(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // evalEcho($cmd); break; // Show the option box. // case 1: if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = `assembleCmd`; evalEcho($cmd); toolPropertyWindow; } else { nurbsConeOptions; } break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }