// =========================================================================== // 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 cube 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 nurbsCubePivotType`) { optionVar -intValue nurbsCubePivotType 1; } if ($forceFactorySettings || !`optionVar -exists nurbsCubePivotX`) { optionVar -floatValue nurbsCubePivotX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubePivotY`) { optionVar -floatValue nurbsCubePivotY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubePivotZ`) { optionVar -floatValue nurbsCubePivotZ 0.0; } string $isitYup = `upAxis -q -ax`; if( "y" == $isitYup ) { if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisType`) { optionVar -intValue nurbsCubeAxisType 2; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisX`) { optionVar -floatValue nurbsCubeAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisY`) { optionVar -floatValue nurbsCubeAxisY 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisZ`) { optionVar -floatValue nurbsCubeAxisZ 0.0; } } else { if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisType`) { optionVar -intValue nurbsCubeAxisType 3; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisX`) { optionVar -floatValue nurbsCubeAxisX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisY`) { optionVar -floatValue nurbsCubeAxisY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeAxisZ`) { optionVar -floatValue nurbsCubeAxisZ 1.0; } } if ($forceFactorySettings || !`optionVar -exists nurbsCubeWidth`) { optionVar -floatValue nurbsCubeWidth 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeLengthRatio`) { optionVar -floatValue nurbsCubeLengthRatio 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeHeightRatio`) { optionVar -floatValue nurbsCubeHeightRatio 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsCubeDegree`) { optionVar -intValue nurbsCubeDegree 3; } if ($forceFactorySettings || !`optionVar -exists nurbsCubePatchesU`) { optionVar -intValue nurbsCubePatchesU 1; } if ($forceFactorySettings || !`optionVar -exists nurbsCubePatchesV`) { optionVar -intValue nurbsCubePatchesV 1; } } // // Procedure Name: // nurbsCubeSetup // // 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 nurbsCubeSetup(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 nurbsCubePivotType`; float $pivotX = `optionVar -q nurbsCubePivotX`; float $pivotY = `optionVar -q nurbsCubePivotY`; float $pivotZ = `optionVar -q nurbsCubePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } radioButtonGrp -e -select $pivotType nurbsCubePivotType; floatFieldGrp -e -v1 $pivotX -v2 $pivotY -v3 $pivotZ nurbsCubePivot; // Axis // int $axisType = `optionVar -q nurbsCubeAxisType`; 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 nurbsCubeAxisX`; $axis[1] = `optionVar -q nurbsCubeAxisY`; $axis[2] = `optionVar -q nurbsCubeAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } if( $axisType < 4 ) { radioButtonGrp -e -select $axisType nurbsCubeAxisType1; } else { radioButtonGrp -e -select ($axisType - 3) nurbsCubeAxisType2; } floatFieldGrp -e -v1 $axis[0] -v2 $axis[1] -v3 $axis[2] nurbsCubeAxis; // Width // float $cubeWidth = `optionVar -q nurbsCubeWidth`; floatSliderGrp -e -v $cubeWidth nurbsCubeWidth; // Length Ratio // float $ratio = `optionVar -q nurbsCubeLengthRatio`; floatSliderGrp -e -v `nurbsRatioConvert $cubeWidth $ratio false` nurbsCubeLength; // Height Ratio // $ratio = `optionVar -q nurbsCubeHeightRatio`; floatSliderGrp -e -v `nurbsRatioConvert $cubeWidth $ratio false` nurbsCubeHeight; // Degree // int $degree = `optionVar -q nurbsCubeDegree`; int $degreeBtn; switch($degree) { case 1: radioButtonGrp -e -select 1 nurbsCubeDegree123; break; case 2: radioButtonGrp -e -select 2 nurbsCubeDegree123; break; case 3: radioButtonGrp -e -select 3 nurbsCubeDegree123; break; case 5: radioButtonGrp -e -select 1 nurbsCubeDegree57; break; case 7: radioButtonGrp -e -select 2 nurbsCubeDegree57; break; default: radioButtonGrp -e -select 3 nurbsCubeDegree123; break; } // Patches U // intSliderGrp -e -v `optionVar -q nurbsCubePatchesU` nurbsCubePatchesU; // Patches V // intSliderGrp -e -v `optionVar -q nurbsCubePatchesV` nurbsCubePatchesV; // Disable or enable some controls depending on other values. // if ($pivotType == 2) floatFieldGrp -e -enable 1 nurbsCubePivot; else floatFieldGrp -e -enable 0 nurbsCubePivot; if ($axisType == 4) floatFieldGrp -e -enable 1 nurbsCubeAxis; else floatFieldGrp -e -enable 0 nurbsCubeAxis; } // // Procedure Name: // nurbsCubeCallback // // 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 nurbsCubeCallback(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 nurbsCubePivotType`; optionVar -intValue nurbsCubePivotType $pivotType; if ($pivotType == 2) { optionVar -floatValue nurbsCubePivotX `floatFieldGrp -q -v1 nurbsCubePivot`; optionVar -floatValue nurbsCubePivotY `floatFieldGrp -q -v2 nurbsCubePivot`; optionVar -floatValue nurbsCubePivotZ `floatFieldGrp -q -v3 nurbsCubePivot`; } // Axis // int $axisType = `radioButtonGrp -q -select nurbsCubeAxisType1`; if( 0 == $axisType ) { $axisType = `radioButtonGrp -q -select nurbsCubeAxisType2` + 3; } optionVar -intValue nurbsCubeAxisType $axisType; if( ($axisType == 4) || ($axisType == 5) ) { optionVar -floatValue nurbsCubeAxisX `floatFieldGrp -q -v1 nurbsCubeAxis`; optionVar -floatValue nurbsCubeAxisY `floatFieldGrp -q -v2 nurbsCubeAxis`; optionVar -floatValue nurbsCubeAxisZ `floatFieldGrp -q -v3 nurbsCubeAxis`; } // Width // float $cubeWidth = `floatSliderGrp -q -v nurbsCubeWidth`; optionVar -floatValue nurbsCubeWidth $cubeWidth; // Length Ratio // float $ratio = nurbsRatioConvert($cubeWidth, `floatSliderGrp -q -v nurbsCubeLength`, true); optionVar -floatValue nurbsCubeLengthRatio $ratio; // Height Ratio // $ratio = nurbsRatioConvert($cubeWidth, `floatSliderGrp -q -v nurbsCubeHeight`, true); optionVar -floatValue nurbsCubeHeightRatio $ratio; // Degree // int $degreeBtn123 = `radioButtonGrp -q -select nurbsCubeDegree123`; int $degreeBtn57 = `radioButtonGrp -q -select nurbsCubeDegree57`; int $degree; switch($degreeBtn123) { case 1: $degree = 1; break; case 2: $degree = 2; break; case 3: $degree = 3; break; default: switch($degreeBtn57) { case 1: $degree = 5; break; case 2: $degree = 7; break; default: $degree = 3; break; } break; } optionVar -intValue nurbsCubeDegree $degree; // Patches U // optionVar -intValue nurbsCubePatchesU `intSliderGrp -q -v nurbsCubePatchesU`; // Patches V // optionVar -intValue nurbsCubePatchesV `intSliderGrp -q -v nurbsCubePatchesV`; if ($doIt) { performNurbsCube 0; addToRecentCommandQueue "performNurbsCube 0" "NURBS Cube"; } } // // Procedure Name: // nurbsCubeOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc nurbsCubeOptions() { // Name of the command for this option box. // string $commandName = "nurbsCube"; // 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_performNurbsCube.kPivot")) -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCube.kObject")) -label2 (uiRes("m_performNurbsCube.kUserDefined")) -select 1 nurbsCubePivotType; floatFieldGrp -label (uiRes("m_performNurbsCube.kPivotPoint")) -numberOfFields 3 nurbsCubePivot; radioButtonGrp -label (uiRes("m_performNurbsCube.kAxis")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsCube.kX")) -label2 (uiRes("m_performNurbsCube.kY")) -label3 (uiRes("m_performNurbsCube.kZ")) -select 1 nurbsCubeAxisType1; radioButtonGrp -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCube.kFree")) -label2 (uiRes("m_performNurbsCube.kActiveView")) -scl nurbsCubeAxisType1 nurbsCubeAxisType2; floatFieldGrp -label (uiRes("m_performNurbsCube.kAxisDefinition")) -numberOfFields 3 nurbsCubeAxis; separator; floatSliderGrp -label (uiRes("m_performNurbsCube.kWidth")) -fmn 0.0001 -min 0.0001 -fmx 1000 -max 100 nurbsCubeWidth; floatSliderGrp -label (uiRes("m_performNurbsCube.kLength")) -fmn 0 -min 0 -fmx 1000 -max 100 nurbsCubeLength; floatSliderGrp -label (uiRes("m_performNurbsCube.kHeight")) -fmn 0 -min 0 -fmx 1000 -max 100 nurbsCubeHeight; radioButtonGrp -label (uiRes("m_performNurbsCube.kSurfaceDegree")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsCube.kOption1Linear")) -label2 (uiRes("m_performNurbsCube.kOption2")) // Quadratic -label3 (uiRes("m_performNurbsCube.kOption3Cubic")) -select 3 nurbsCubeDegree123; radioButtonGrp -shareCollection nurbsCubeDegree123 -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsCube.kOption5")) // Quintic -label2 (uiRes("m_performNurbsCube.kOption7")) nurbsCubeDegree57; intSliderGrp -label (uiRes("m_performNurbsCube.kUPatches")) -field true -min 1 nurbsCubePatchesU; intSliderGrp -label (uiRes("m_performNurbsCube.kVPatches")) -field true -min 1 nurbsCubePatchesV; // Set the pivot float fields to only be enabled when "Pivot" is "User Defined" // string $pivotEnable = ("floatFieldGrp -e -en 1 nurbsCubePivot;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsCubePivotX`" + " -v2 `optionVar -q nurbsCubePivotY`" + " -v3 `optionVar -q nurbsCubePivotZ`" + " nurbsCubePivot;" ); string $pivotDisable = "floatFieldGrp -e -en 0 nurbsCubePivot;"; radioButtonGrp -edit -cc1 ($pivotDisable + "floatFieldGrp -e -value 0.0 0.0 0.0 0.0 nurbsCubePivot;") -cc2 $pivotEnable nurbsCubePivotType; // Set the axis float fields to only be enabled when "Axis Preset" is "Free" // string $axisEnable = ("floatFieldGrp -e -en 1 nurbsCubeAxis;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsCubeAxisX`" + " -v2 `optionVar -q nurbsCubeAxisY`" + " -v3 `optionVar -q nurbsCubeAxisZ`" + " nurbsCubeAxis;" ); string $axisDisable = "floatFieldGrp -e -en 0 nurbsCubeAxis;"; radioButtonGrp -edit -cc1 ($axisDisable + "floatFieldGrp -e -value 1.0 0.0 0.0 0.0 nurbsCubeAxis;") -cc2 ($axisDisable + "floatFieldGrp -e -value 0.0 1.0 0.0 0.0 nurbsCubeAxis;") -cc3 ($axisDisable + "floatFieldGrp -e -value 0.0 0.0 1.0 0.0 nurbsCubeAxis;") nurbsCubeAxisType1; radioButtonGrp -edit -cc1 $axisEnable -cc2 $axisDisable nurbsCubeAxisType2; // 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_performNurbsCube.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_performNurbsCube.kNURBSCubeOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "NurbsCube" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // nurbsCubeHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string nurbsCubeHelp() { return " Command: nurbsCube - create a NURBS cube.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "nurbsCube"; setOptionVars(false); int $pivotType = `optionVar -q nurbsCubePivotType`; float $pivotX = `optionVar -q nurbsCubePivotX`; float $pivotY = `optionVar -q nurbsCubePivotY`; float $pivotZ = `optionVar -q nurbsCubePivotZ`; if ($pivotType == 1) { $pivotX = 0; $pivotY = 0; $pivotZ = 0; } // Axis // int $axisType = `optionVar -q nurbsCubeAxisType`; 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 nurbsCubeAxisX`; $axis[1] = `optionVar -q nurbsCubeAxisY`; $axis[2] = `optionVar -q nurbsCubeAxisZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } // History // int $doHistory = `constructionHistory -q -toggle`; $cmd = ($cmd + " -p " + $pivotX + " " + $pivotY + " " + $pivotZ + " -ax " + $axis[0] + " " + $axis[1] + " " + $axis[2] + " -w " + `optionVar -query nurbsCubeWidth` + " -lr " + `optionVar -query nurbsCubeLengthRatio` + " -hr " + `optionVar -query nurbsCubeHeightRatio` + " -d " + `optionVar -query nurbsCubeDegree` + " -u " + `optionVar -query nurbsCubePatchesU` + " -v " + `optionVar -query nurbsCubePatchesV` + " -ch " + $doHistory + "; objectMoveCommand"); if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = "setToolTo \"CreateNurbsCubeCtx\""; } return $cmd; } // // Procedure Name: // performNurbsCube // // Description: // Perform the nurbsCube 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 nurbsCube 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 performNurbsCube(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 { nurbsCubeOptions; } break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }