// =========================================================================== // 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: 6 May 1997 // // Description: // This script defines the option box for the NURBS circle 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 nurbsCirclePivotType`) { optionVar -intValue nurbsCirclePivotType 1; } if ($forceFactorySettings || !`optionVar -exists nurbsCirclePivotX`) { optionVar -floatValue nurbsCirclePivotX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCirclePivotY`) { optionVar -floatValue nurbsCirclePivotY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCirclePivotZ`) { optionVar -floatValue nurbsCirclePivotZ 0.0; } string $isitYup = `upAxis -q -ax`; if( "y" == $isitYup ) { if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisType`) { optionVar -intValue nurbsCircleAxisType 2; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisX`) { optionVar -floatValue nurbsCircleAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisY`) { optionVar -floatValue nurbsCircleAxisY 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisZ`) { optionVar -floatValue nurbsCircleAxisZ 0.0; } } else { if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisType`) { optionVar -intValue nurbsCircleAxisType 3; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisX`) { optionVar -floatValue nurbsCircleAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisY`) { optionVar -floatValue nurbsCircleAxisY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleAxisZ`) { optionVar -floatValue nurbsCircleAxisZ 1.0; } } if ($forceFactorySettings || !`optionVar -exists nurbsCircleEndSweep`) { optionVar -floatValue nurbsCircleEndSweep 360.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleRadius`) { optionVar -floatValue nurbsCircleRadius 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleDegree`) { optionVar -intValue nurbsCircleDegree 3; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleUseGlobalTol`) { optionVar -intValue nurbsCircleUseGlobalTol true; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleUseTolerance`) { optionVar -intValue nurbsCircleUseTolerance false; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleTolerance`) { optionVar -floatValue nurbsCircleTolerance 0.01; } if ($forceFactorySettings || !`optionVar -exists nurbsCircleSections`) { optionVar -intValue nurbsCircleSections 8; } } // // Procedure Name: // nurbsCircleSetup // // 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 nurbsCircleSetup(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 nurbsCirclePivotType`; float $pivotX = `optionVar -q nurbsCirclePivotX`; float $pivotY = `optionVar -q nurbsCirclePivotY`; float $pivotZ = `optionVar -q nurbsCirclePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } radioButtonGrp -e -select $pivotType nurbsCirclePivotType; floatFieldGrp -e -v1 $pivotX -v2 $pivotY -v3 $pivotZ nurbsCirclePivot; // Axis // int $axisType = `optionVar -q nurbsCircleAxisType`; 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 nurbsCircleAxisX`; $axis[1] = `optionVar -q nurbsCircleAxisY`; $axis[2] = `optionVar -q nurbsCircleAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } if( $axisType < 4 ) { radioButtonGrp -e -select $axisType nurbsCircleAxisType1; } else { radioButtonGrp -e -select ($axisType - 3) nurbsCircleAxisType2; } floatFieldGrp -e -v1 $axis[0] -v2 $axis[1] -v3 $axis[2] nurbsCircleAxis; // Sweep Angle // floatSliderGrp -e -v `optionVar -q nurbsCircleEndSweep` nurbsCircleEndSweep; // Radius // floatSliderGrp -e -v `optionVar -q nurbsCircleRadius` nurbsCircleRadius; // Degree // int $degree = `optionVar -q nurbsCircleDegree`; int $degreeBtn; switch($degree) { case 1: $degreeBtn = 1; break; case 3: $degreeBtn = 2; break; } radioButtonGrp -e -select $degreeBtn nurbsCircleDegree; // Tolerance // int $useTolerance = `optionVar -q nurbsCircleUseTolerance`; int $useGlobalTol = `optionVar -q nurbsCircleUseGlobalTol`; if( $useTolerance ) { if( $useGlobalTol ) { radioButtonGrp -e -select 3 nurbsCircleUseTolerance; } else { radioButtonGrp -e -select 2 nurbsCircleUseTolerance; } } else { radioButtonGrp -e -select 1 nurbsCircleUseTolerance; } floatSliderGrp -e -v `optionVar -q nurbsCircleTolerance` nurbsCircleTolerance; // Sections // intSliderGrp -e -v `optionVar -q nurbsCircleSections` nurbsCircleSections; // Disable or enable some controls depending on other values. // if ($pivotType == 2) floatFieldGrp -e -enable 1 nurbsCirclePivot; else floatFieldGrp -e -enable 0 nurbsCirclePivot; if ($axisType == 4) floatFieldGrp -e -enable 1 nurbsCircleAxis; else floatFieldGrp -e -enable 0 nurbsCircleAxis; 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: // nurbsCircleCallback // // 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 nurbsCircleCallback(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 nurbsCirclePivotType`; optionVar -intValue nurbsCirclePivotType $pivotType; if ($pivotType == 2) { optionVar -floatValue nurbsCirclePivotX `floatFieldGrp -q -v1 nurbsCirclePivot`; optionVar -floatValue nurbsCirclePivotY `floatFieldGrp -q -v2 nurbsCirclePivot`; optionVar -floatValue nurbsCirclePivotZ `floatFieldGrp -q -v3 nurbsCirclePivot`; } // Axis // int $axisType = `radioButtonGrp -q -select nurbsCircleAxisType1`; if( 0 == $axisType ) { $axisType = `radioButtonGrp -q -select nurbsCircleAxisType2` + 3; } optionVar -intValue nurbsCircleAxisType $axisType; if( ($axisType == 4) || ($axisType == 5) ){ optionVar -floatValue nurbsCircleAxisX `floatFieldGrp -q -v1 nurbsCircleAxis`; optionVar -floatValue nurbsCircleAxisY `floatFieldGrp -q -v2 nurbsCircleAxis`; optionVar -floatValue nurbsCircleAxisZ `floatFieldGrp -q -v3 nurbsCircleAxis`; } // Sweep Angle // optionVar -floatValue nurbsCircleEndSweep `floatSliderGrp -q -v nurbsCircleEndSweep`; // Radius // optionVar -floatValue nurbsCircleRadius `floatSliderGrp -q -v nurbsCircleRadius`; // Degree // int $degreeBtn = `radioButtonGrp -q -select nurbsCircleDegree`; int $degree; switch($degreeBtn) { case 1: $degree = 1; break; case 2: $degree = 3; break; } optionVar -intValue nurbsCircleDegree $degree; // Tolerance // int $valUse = `radioButtonGrp -q -select nurbsCircleUseTolerance`; switch( $valUse ) { case 1: optionVar -intValue nurbsCircleUseTolerance false; break; case 2: optionVar -intValue nurbsCircleUseTolerance true; optionVar -intValue nurbsCircleUseGlobalTol false; break; case 3: default: optionVar -intValue nurbsCircleUseTolerance true; optionVar -intValue nurbsCircleUseGlobalTol true; break; } optionVar -floatValue nurbsCircleTolerance `floatSliderGrp -q -v nurbsCircleTolerance`; // Sections // optionVar -intValue nurbsCircleSections `intSliderGrp -q -v nurbsCircleSections`; if ($doIt) { performNurbsCircle 0; addToRecentCommandQueue "performNurbsCircle 0" "NURBS Circle"; } } // // Procedure Name: // nurbsCircleOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc nurbsCircleOptions() { // Name of the command for this option box. // string $commandName = "nurbsCircle"; // 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("circle"); // 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_performNurbsCircle.kPivot")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCircle.kObject")) -label2 (uiRes("m_performNurbsCircle.kUserDefined")) -select 1 nurbsCirclePivotType; floatFieldGrp -label (uiRes("m_performNurbsCircle.kPivotPoint")) -numberOfFields 3 nurbsCirclePivot; radioButtonGrp -label (uiRes("m_performNurbsCircle.kNormalAxis")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsCircle.kX")) -label2 (uiRes("m_performNurbsCircle.kY")) -label3 (uiRes("m_performNurbsCircle.kZ")) -select 1 nurbsCircleAxisType1; radioButtonGrp -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCircle.kFree")) -label2 (uiRes("m_performNurbsCircle.kActiveView")) -scl nurbsCircleAxisType1 nurbsCircleAxisType2; floatFieldGrp -label (uiRes("m_performNurbsCircle.kNormalDefinition")) -numberOfFields 3 nurbsCircleAxis; separator; floatSliderGrp -label (uiRes("m_performNurbsCircle.kSweepAngle")) -min 0 -max 360 -fmn -3600 -fmx 3600 nurbsCircleEndSweep; floatSliderGrp -label (uiRes("m_performNurbsCircle.kRadius")) -fmn -1000.0 -fmx 1000.0 nurbsCircleRadius; radioButtonGrp -label (uiRes("m_performNurbsCircle.kDegree")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCircle.kLinear")) -label2 (uiRes("m_performNurbsCircle.kCubic")) -select 2 nurbsCircleDegree; // "Tolerance" disappears when "Use Tolerance" is false. // "Sections" disappears when "Use Tolerance" is true. // Note that the "-rational" flag no longer exists for // the circle command. We do things as if the "-rational" // flag were always false. radioButtonGrp -nrb 3 -label (uiRes("m_performNurbsCircle.kUseTolerance")) -label1 (uiRes("m_performNurbsCircle.kNone")) -label2 (uiRes("m_performNurbsCircle.kLocal")) -label3 (uiRes("m_performNurbsCircle.kGlobal")) nurbsCircleUseTolerance; tabLayout -tabsVisible false tabLayoutForTolerance; columnLayout tabWithoutTolerance; intSliderGrp -label (uiRes("m_performNurbsCircle.kNumberOfSections")) -field true -min 4 -max 50 -fmx 200 nurbsCircleSections; setParent ..; columnLayout tabWithTolerance; floatSliderGrp -label (uiRes("m_performNurbsCircle.kPositionalTolerance")) -min 0.001 -max 1 -fmx 100.0 nurbsCircleTolerance; setParent ..; setParent ..; // Set the pivot float fields to only be enabled when "Pivot" is "User Defined" // string $pivotEnable = ("floatFieldGrp -e -en 1 nurbsCirclePivot;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsCirclePivotX`" + " -v2 `optionVar -q nurbsCirclePivotY`" + " -v3 `optionVar -q nurbsCirclePivotZ`" + " nurbsCirclePivot;" ); string $pivotDisable = "floatFieldGrp -e -en 0 nurbsCirclePivot;"; radioButtonGrp -edit -cc1 ($pivotDisable + "floatFieldGrp -e -value 0.0 0.0 0.0 0.0 nurbsCirclePivot;") -cc2 $pivotEnable nurbsCirclePivotType; // Set the axis float fields to only be enabled when "Axis Preset" is "Free" // string $axisEnable = ("floatFieldGrp -e -en 1 nurbsCircleAxis;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsCircleAxisX`" + " -v2 `optionVar -q nurbsCircleAxisY`" + " -v3 `optionVar -q nurbsCircleAxisZ`" + " nurbsCircleAxis;" ); string $axisDisable = "floatFieldGrp -e -en 0 nurbsCircleAxis;"; radioButtonGrp -edit -cc1 ($axisDisable + "floatFieldGrp -e -value 1.0 0.0 0.0 0.0 nurbsCircleAxis;") -cc2 ($axisDisable + "floatFieldGrp -e -value 0.0 1.0 0.0 0.0 nurbsCircleAxis;") -cc3 ($axisDisable + "floatFieldGrp -e -value 0.0 0.0 1.0 0.0 nurbsCircleAxis;") nurbsCircleAxisType1; radioButtonGrp -edit -cc1 $axisEnable -cc2 $axisDisable nurbsCircleAxisType2; // 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" nurbsCircleUseTolerance; // 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_performNurbsCircle.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_performNurbsCircle.kNURBSCircleOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "NurbsCircle" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // nurbsCircleHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string nurbsCircleHelp() { return " Command: circle - create a NURBS circle or arc.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "circle"; setOptionVars(false); int $pivotType = `optionVar -q nurbsCirclePivotType`; float $pivotX = `optionVar -q nurbsCirclePivotX`; float $pivotY = `optionVar -q nurbsCirclePivotY`; float $pivotZ = `optionVar -q nurbsCirclePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } // Axis int $axisType = `optionVar -q nurbsCircleAxisType`; 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 nurbsCircleAxisX`; $axis[1] = `optionVar -q nurbsCircleAxisY`; $axis[2] = `optionVar -q nurbsCircleAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } float $tol = `optionVar -query nurbsCircleTolerance`; if( `optionVar -query nurbsCircleUseGlobalTol` ) { $tol = `optionVar -q positionalTolerance`; } // History // int $doHistory = `constructionHistory -q -toggle`; $cmd = ($cmd + " -c " + $pivotX + " " + $pivotY + " " + $pivotZ + " -nr " + $axis[0] + " " + $axis[1] + " " + $axis[2] + " -sw " + `optionVar -query nurbsCircleEndSweep` + " -r " + `optionVar -query nurbsCircleRadius` + " -d " + `optionVar -query nurbsCircleDegree` + " -ut " + `optionVar -query nurbsCircleUseTolerance` + " -tol " + $tol + " -s " + `optionVar -query nurbsCircleSections` + " -ch " + $doHistory + "; objectMoveCommand"); if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = "setToolTo \"CreateNurbsCircleCtx\""; } return $cmd; } // // Procedure Name: // performNurbsCircle // // Description: // Perform the circle 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 circle 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 performNurbsCircle(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 { nurbsCircleOptions; } break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }