// =========================================================================== // 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 sphere 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 sphereUseGlobalTolerance`){ optionVar -intValue sphereUseGlobalTolerance false; } if ($forceFactorySettings || !`optionVar -exists spherePivotType`) { optionVar -intValue spherePivotType 1; } if ($forceFactorySettings || !`optionVar -exists spherePivotX`) { optionVar -floatValue spherePivotX 0.0; } if ($forceFactorySettings || !`optionVar -exists spherePivotY`) { optionVar -floatValue spherePivotY 0.0; } if ($forceFactorySettings || !`optionVar -exists spherePivotZ`) { optionVar -floatValue spherePivotZ 0.0; } string $isitYup = `upAxis -q -ax`; if( "y" == $isitYup ) { if ($forceFactorySettings || !`optionVar -exists sphereAxisType`) { optionVar -intValue sphereAxisType 2; } if ($forceFactorySettings || !`optionVar -exists sphereAxisX`) { optionVar -floatValue sphereAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists sphereAxisY`) { optionVar -floatValue sphereAxisY 1.0; } if ($forceFactorySettings || !`optionVar -exists sphereAxisZ`) { optionVar -floatValue sphereAxisZ 0.0; } } else { if ($forceFactorySettings || !`optionVar -exists sphereAxisType`) { optionVar -intValue sphereAxisType 3; } if ($forceFactorySettings || !`optionVar -exists sphereAxisX`) { optionVar -floatValue sphereAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists sphereAxisY`) { optionVar -floatValue sphereAxisY 0.0; } if ($forceFactorySettings || !`optionVar -exists sphereAxisZ`) { optionVar -floatValue sphereAxisZ 1.0; } } if ($forceFactorySettings || !`optionVar -exists sphereStartSweep`) { optionVar -floatValue sphereStartSweep 0.0; } if ($forceFactorySettings || !`optionVar -exists sphereEndSweep`) { optionVar -floatValue sphereEndSweep 360.0; } if ($forceFactorySettings || !`optionVar -exists sphereRadius`) { optionVar -floatValue sphereRadius 1.0; } if ($forceFactorySettings || !`optionVar -exists sphereDegree`) { optionVar -intValue sphereDegree 3; } if ($forceFactorySettings || !`optionVar -exists sphereUseTolerance`) { optionVar -intValue sphereUseTolerance false; } if ($forceFactorySettings || !`optionVar -exists sphereTolerance`) { optionVar -floatValue sphereTolerance 0.01; } if ($forceFactorySettings || !`optionVar -exists sphereSections`) { optionVar -intValue sphereSections 8; } if ($forceFactorySettings || !`optionVar -exists sphereSpans`) { optionVar -intValue sphereSpans 4; } } // // Procedure Name: // sphereSetup // // 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 sphereSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. int $useGlobalTol = false; // Pivot // int $pivotType = `optionVar -q spherePivotType`; float $pivotX = `optionVar -q spherePivotX`; float $pivotY = `optionVar -q spherePivotY`; float $pivotZ = `optionVar -q spherePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } radioButtonGrp -e -select $pivotType spherePivotType; floatFieldGrp -e -v1 $pivotX -v2 $pivotY -v3 $pivotZ spherePivot; // Axis // int $axisType = `optionVar -q sphereAxisType`; 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 sphereAxisX`; $axis[1] = `optionVar -q sphereAxisY`; $axis[2] = `optionVar -q sphereAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } if( $axisType < 4 ) { radioButtonGrp -e -select $axisType sphereAxisType1; } else { radioButtonGrp -e -select ($axisType - 3) sphereAxisType2; } floatFieldGrp -e -v1 $axis[0] -v2 $axis[1] -v3 $axis[2] sphereAxis; // Sweep Angle (Start and End) // floatSliderGrp -e -v `optionVar -q sphereStartSweep` sphereStartSweep; floatSliderGrp -e -v `optionVar -q sphereEndSweep` sphereEndSweep; // Radius // floatSliderGrp -e -v `optionVar -q sphereRadius` sphereRadius; // Degree // int $degree = `optionVar -q sphereDegree`; int $degreeBtn; switch($degree) { case 1: $degreeBtn = 1; break; case 3: $degreeBtn = 2; break; } radioButtonGrp -e -select $degreeBtn sphereDegree; // Tolerance // $useGlobalTol = `optionVar -q sphereUseGlobalTolerance`; int $useTolerance = `optionVar -q sphereUseTolerance`; if( $useTolerance ) { if( $useGlobalTol ) { radioButtonGrp -e -select 3 sphereUseTolerance; } else { radioButtonGrp -e -select 2 sphereUseTolerance; } } else { radioButtonGrp -e -select 1 sphereUseTolerance; } floatSliderGrp -e -v `optionVar -q sphereTolerance` sphereTolerance; // Sections // intSliderGrp -e -v `optionVar -q sphereSections` sphereSections; // Spans // intSliderGrp -e -v `optionVar -q sphereSpans` sphereSpans; // Disable or enable some controls depending on other values. // if ($pivotType == 2) floatFieldGrp -e -enable 1 spherePivot; else floatFieldGrp -e -enable 0 spherePivot; if ($axisType == 4) floatFieldGrp -e -enable 1 sphereAxis; else floatFieldGrp -e -enable 0 sphereAxis; 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: // sphereCallback // // 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 sphereCallback(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 spherePivotType`; optionVar -intValue spherePivotType $pivotType; if ($pivotType == 2) { optionVar -floatValue spherePivotX `floatFieldGrp -q -v1 spherePivot`; optionVar -floatValue spherePivotY `floatFieldGrp -q -v2 spherePivot`; optionVar -floatValue spherePivotZ `floatFieldGrp -q -v3 spherePivot`; } // Axis // int $axisType = `radioButtonGrp -q -select sphereAxisType1`; if( 0 == $axisType ) { $axisType = `radioButtonGrp -q -select sphereAxisType2` + 3; } optionVar -intValue sphereAxisType $axisType; if (($axisType == 4) || ($axisType == 5)) { optionVar -floatValue sphereAxisX `floatFieldGrp -q -v1 sphereAxis`; optionVar -floatValue sphereAxisY `floatFieldGrp -q -v2 sphereAxis`; optionVar -floatValue sphereAxisZ `floatFieldGrp -q -v3 sphereAxis`; } // Sweep Angle (Start and End) // optionVar -floatValue sphereStartSweep `floatSliderGrp -q -v sphereStartSweep`; optionVar -floatValue sphereEndSweep `floatSliderGrp -q -v sphereEndSweep`; // Radius // optionVar -floatValue sphereRadius `floatSliderGrp -q -v sphereRadius`; // Degree // int $degreeBtn = `radioButtonGrp -q -select sphereDegree`; int $degree; switch($degreeBtn) { case 1: $degree = 1; break; case 2: $degree = 3; break; } optionVar -intValue sphereDegree $degree; // Tolerance // int $useTolerance = `radioButtonGrp -q -select sphereUseTolerance`; switch( $useTolerance ) { case 1: optionVar -intValue sphereUseTolerance false; break; case 2: optionVar -intValue sphereUseTolerance true; optionVar -intValue sphereUseGlobalTolerance false; break; case 3: default: optionVar -intValue sphereUseTolerance true; optionVar -intValue sphereUseGlobalTolerance true; break; } optionVar -floatValue sphereTolerance `floatSliderGrp -q -v sphereTolerance`; // Sections // optionVar -intValue sphereSections `intSliderGrp -q -v sphereSections`; // Spans // optionVar -intValue sphereSpans `intSliderGrp -q -v sphereSpans`; if ($doIt) { performNurbsSphere 0; addToRecentCommandQueue "performNurbsSphere 0" "NURBS Sphere"; } } // // Procedure Name: // sphereOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc sphereOptions() { // Name of the command for this option box. // string $commandName = "sphere"; // 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($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. // 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_performNurbsSphere.kPivot")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsSphere.kObject")) -label2 (uiRes("m_performNurbsSphere.kUserDefined")) -select 1 spherePivotType; floatFieldGrp -label (uiRes("m_performNurbsSphere.kPivotPoint")) -numberOfFields 3 spherePivot; radioButtonGrp -label (uiRes("m_performNurbsSphere.kAxis")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsSphere.kX")) -label2 (uiRes("m_performNurbsSphere.kY")) -label3 (uiRes("m_performNurbsSphere.kZ")) -select 1 sphereAxisType1; radioButtonGrp -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsSphere.kFree")) -label2 (uiRes("m_performNurbsSphere.kActiveView")) -scl "sphereAxisType1" sphereAxisType2; floatFieldGrp -label (uiRes("m_performNurbsSphere.kAxisDefinition")) -numberOfFields 3 sphereAxis; separator; floatSliderGrp -label (uiRes("m_performNurbsSphere.kStartSweepAngle")) -min 0 -max 360 -fmn -3600 -fmx 3600 sphereStartSweep; floatSliderGrp -label (uiRes("m_performNurbsSphere.kEndSweepAngle")) -min 0 -max 360 -fmn -3600 -fmx 3600 sphereEndSweep; floatSliderGrp -label (uiRes("m_performNurbsSphere.kRadius")) -fmn -1000.0 -fmx 1000.0 sphereRadius; radioButtonGrp -label (uiRes("m_performNurbsSphere.kSurfaceDegree")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsSphere.kLinear")) -label2 (uiRes("m_performNurbsSphere.kCubic")) -select 2 sphereDegree; // "Tolerance" disappears when "Use Tolerance" is false. // "Sections" disappears when "Use Tolerance" is true. // Note that the "-rational" flag no longer exists for // the sphere command. We do things as if the "-rational" // flag were always false. radioButtonGrp -nrb 3 -label (uiRes("m_performNurbsSphere.kUseTolerance")) -label1 (uiRes("m_performNurbsSphere.kNone")) -label2 (uiRes("m_performNurbsSphere.kLocal")) -label3 (uiRes("m_performNurbsSphere.kGlobal")) sphereUseTolerance; tabLayout -tabsVisible false tabLayoutForTolerance; columnLayout tabWithoutTolerance; intSliderGrp -label (uiRes("m_performNurbsSphere.kNumberOfSections")) -field true -min 4 -max 50 -fmx 200 sphereSections; intSliderGrp -label (uiRes("m_performNurbsSphere.kNumberOfSpans")) -field true -min 2 -max 50 -fmx 200 sphereSpans; setParent ..; columnLayout tabWithTolerance; floatSliderGrp -label (uiRes("m_performNurbsSphere.kPositionalTolerance")) -min 0.001 -max 1 -fmx 100.0 sphereTolerance; setParent ..; setParent ..; // Set the pivot float fields to only be enabled when "Pivot" is "User Defined" // string $pivotEnable = ("floatFieldGrp -e -en 1 spherePivot;" + "floatFieldGrp -e" + " -v1 `optionVar -q spherePivotX`" + " -v2 `optionVar -q spherePivotY`" + " -v3 `optionVar -q spherePivotZ`" + " spherePivot;" ); string $pivotDisable = "floatFieldGrp -e -en 0 spherePivot;"; radioButtonGrp -edit -cc1 ($pivotDisable + "floatFieldGrp -e -value 0.0 0.0 0.0 0.0 spherePivot;") -cc2 $pivotEnable spherePivotType; // Set the axis float fields to only be enabled when "Axis Preset" is "Free" // string $axisEnable = ("floatFieldGrp -e -en 1 sphereAxis;" + "floatFieldGrp -e" + " -v1 `optionVar -q sphereAxisX`" + " -v2 `optionVar -q sphereAxisY`" + " -v3 `optionVar -q sphereAxisZ`" + " sphereAxis;" ); string $axisDisable = "floatFieldGrp -e -en 0 sphereAxis;"; radioButtonGrp -edit -cc1 ($axisDisable + "floatFieldGrp -e -value 1.0 0.0 0.0 0.0 sphereAxis;") -cc2 ($axisDisable + "floatFieldGrp -e -value 0.0 1.0 0.0 0.0 sphereAxis;") -cc3 ($axisDisable + "floatFieldGrp -e -value 0.0 0.0 1.0 0.0 sphereAxis;") sphereAxisType1; radioButtonGrp -edit -cc1 $axisEnable -cc2 $axisDisable sphereAxisType2; // 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" sphereUseTolerance; // 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_performNurbsSphere.kCreateButton")) -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_performNurbsSphere.kNURBSSphereOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "NurbsSphere" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // sphereHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string sphereHelp() { return " Command: sphere - create a NURBS sphere.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "sphere"; setOptionVars(false); int $pivotType = `optionVar -q spherePivotType`; float $pivotX = `optionVar -q spherePivotX`; float $pivotY = `optionVar -q spherePivotY`; float $pivotZ = `optionVar -q spherePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } // Axis // int $axisType = `optionVar -q sphereAxisType`; 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 sphereAxisX`; $axis[1] = `optionVar -q sphereAxisY`; $axis[2] = `optionVar -q sphereAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } // History // int $doHistory = `constructionHistory -q -toggle`; float $tol = `optionVar -query sphereTolerance`; if( `optionVar - q sphereUseGlobalTolerance` ) { $tol = `optionVar -q positionalTolerance`; } $cmd = ($cmd + " -p " + $pivotX + " " + $pivotY + " " + $pivotZ + " -ax " + $axis[0] + " " + $axis[1] + " " + $axis[2] + " -ssw " + `optionVar -query sphereStartSweep` + " -esw " + `optionVar -query sphereEndSweep` + " -r " + `optionVar -query sphereRadius` + " -d " + `optionVar -query sphereDegree` + " -ut " + `optionVar -query sphereUseTolerance` + " -tol " + $tol + " -s " + `optionVar -query sphereSections` + " -nsp " + `optionVar -query sphereSpans` + " -ch " + $doHistory + ";objectMoveCommand"); if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = "setToolTo \"CreateNurbsSphereCtx\""; } return $cmd; } // // Procedure Name: // performNurbsSphere // // Description: // Perform the sphere 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 sphere 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 performNurbsSphere(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 { sphereOptions; } break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }