// =========================================================================== // 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: April 15 1998 // // Description: // This script defines the option box for the NURBS square 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 nurbsSquareCenterX`) { optionVar -floatValue nurbsSquareCenterX 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareCenterY`) { optionVar -floatValue nurbsSquareCenterY 0.0; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareCenterZ`) { optionVar -floatValue nurbsSquareCenterZ 0.0; } string $isitYup = `upAxis -q -ax`; float $x, $y, $z ; if( "y" == $isitYup ) { if( $forceFactorySettings || !`optionVar -exists nurbsSquareNormalType` ) { optionVar -intValue nurbsSquareNormalType 2 ; } $x = 0.0 ; $y = 1.0 ; $z = 0.0 ; } else { if( $forceFactorySettings || !`optionVar -exists nurbsSquareNormalType` ) { optionVar -intValue nurbsSquareNormalType 3 ; } $x = 0.0 ; $y = 0.0 ; $z = 1.0 ; } if( $forceFactorySettings || !`optionVar -exists nurbsSquareNormalX` ) { optionVar -floatValue nurbsSquareNormalX $x; } if( $forceFactorySettings || !`optionVar -exists nurbsSquareNormalY` ) { optionVar -floatValue nurbsSquareNormalY $y; } if( $forceFactorySettings || !`optionVar -exists nurbsSquareNormalZ` ) { optionVar -floatValue nurbsSquareNormalZ $z; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareSide1`) { optionVar -floatValue nurbsSquareSide1 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareSide2`) { optionVar -floatValue nurbsSquareSide2 1.0; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareDegree`) { optionVar -intValue nurbsSquareDegree 3; } if ($forceFactorySettings || !`optionVar -exists nurbsSquareSpansPerSide`) { optionVar -intValue nurbsSquareSpansPerSide 1; } } // // Procedure Name: // nurbsSquareSetup // // 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 nurbsSquareSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. //center // float $centerX = `optionVar -q nurbsSquareCenterX`; float $centerY = `optionVar -q nurbsSquareCenterY`; float $centerZ = `optionVar -q nurbsSquareCenterZ`; floatFieldGrp -e -v1 $centerX -v2 $centerY -v3 $centerZ nurbsSquareCenter; // Axis ( normal ) // int $axisType = `optionVar -q nurbsSquareNormalType`; 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 nurbsSquareNormalX`; $axis[1] = `optionVar -q nurbsSquareNormalY`; $axis[2] = `optionVar -q nurbsSquareNormalZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } // select the normal radio button. // if( $axisType < 4 ) { radioButtonGrp -e -select $axisType nurbsSquareNormalXYZType1; } else { radioButtonGrp -e -select ($axisType - 3) nurbsSquareNormalXYZType2; } // normal values. // floatFieldGrp -e -v1 $axis[0] -v2 $axis[1] -v3 $axis[2] nurbsSquareNormalField; // length of side 1 // floatSliderGrp -e -v `optionVar -q nurbsSquareSide1` nurbsSquareSide1Slider; // length of side 2. // floatSliderGrp -e -v `optionVar -q nurbsSquareSide2` nurbsSquareSide2Slider; // Degree // int $degree = `optionVar -q nurbsSquareDegree`; int $degreeBtn; switch($degree) { case 1: radioButtonGrp -e -select 1 nurbsSquareDegree123; break; case 2: radioButtonGrp -e -select 2 nurbsSquareDegree123; break; case 3: radioButtonGrp -e -select 3 nurbsSquareDegree123; break; case 5: radioButtonGrp -e -select 1 nurbsSquareDegree57; break; case 7: radioButtonGrp -e -select 2 nurbsSquareDegree57; break; default: radioButtonGrp -e -select 3 nurbsSquareDegree123; break; } // Spans // intSliderGrp -e -v `optionVar -q nurbsSquareSpansPerSide` nurbsSquareSpans; // enable or diasable the normal field. // if ($axisType == 4) floatFieldGrp -e -enable 1 nurbsSquareNormalField; else floatFieldGrp -e -enable 0 nurbsSquareNormalField; } // // Procedure Name: // nurbsSquareCallback // // 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 nurbsSquareCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // center // optionVar -floatValue nurbsSquareCenterX `floatFieldGrp -q -v1 nurbsSquareCenter`; optionVar -floatValue nurbsSquareCenterY `floatFieldGrp -q -v2 nurbsSquareCenter`; optionVar -floatValue nurbsSquareCenterZ `floatFieldGrp -q -v3 nurbsSquareCenter`; // normal // int $axisType = `radioButtonGrp -q -select nurbsSquareNormalXYZType1`; if( 0 == $axisType ) { $axisType = `radioButtonGrp -q -select nurbsSquareNormalXYZType2` + 3; } optionVar -intValue nurbsSquareNormalType $axisType; if( ($axisType == 4) || ($axisType == 5) ) { optionVar -floatValue nurbsSquareNormalX `floatFieldGrp -q -v1 nurbsSquareNormalField`; optionVar -floatValue nurbsSquareNormalY `floatFieldGrp -q -v2 nurbsSquareNormalField`; optionVar -floatValue nurbsSquareNormalZ `floatFieldGrp -q -v3 nurbsSquareNormalField`; } // side of square // optionVar -floatValue nurbsSquareSide1 `floatSliderGrp -q -v nurbsSquareSide1Slider`; optionVar -floatValue nurbsSquareSide2 `floatSliderGrp -q -v nurbsSquareSide2Slider`; // Degree // int $degreeBtn123 = `radioButtonGrp -q -select nurbsSquareDegree123`; int $degreeBtn57 = `radioButtonGrp -q -select nurbsSquareDegree57`; 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 nurbsSquareDegree $degree; // number of spans per side. // optionVar -intValue nurbsSquareSpansPerSide `intSliderGrp -q -v nurbsSquareSpans`; if ($doIt) { performNurbsSquare 0; addToRecentCommandQueue "performNurbsSquare 0" "NURBS Square"; } } // // Procedure Name: // nurbsSquareOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc nurbsSquareOptions() { // Name of the command for this option box. // string $commandName = "nurbsSquare"; // 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("nurbsSquare"); // 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`; floatFieldGrp -label (uiRes("m_performNurbsSquare.kCenter")) -numberOfFields 3 nurbsSquareCenter; radioButtonGrp -label (uiRes("m_performNurbsSquare.kNormalAxis")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsSquare.kX")) -label2 (uiRes("m_performNurbsSquare.kY")) -label3 (uiRes("m_performNurbsSquare.kZ")) -select 1 nurbsSquareNormalXYZType1; radioButtonGrp -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsSquare.kFree")) -label2 (uiRes("m_performNurbsSquare.kActiveView")) -scl "nurbsSquareNormalXYZType1" nurbsSquareNormalXYZType2; floatFieldGrp -label (uiRes("m_performNurbsSquare.kNormalDefinition")) -numberOfFields 3 nurbsSquareNormalField; separator; floatSliderGrp -label (uiRes("m_performNurbsSquare.kLengthOfSide1")) -ss 1.0 -min 1.0 -fmn 0.1 -fmx 1000.0 -max 10.0 nurbsSquareSide1Slider; floatSliderGrp -label (uiRes("m_performNurbsSquare.kLengthOfSide2")) -ss 1.0 -min 1.0 -fmn 0.1 -fmx 1000.0 -max 10.0 nurbsSquareSide2Slider; intSliderGrp -label (uiRes("m_performNurbsSquare.kSpansPerSide")) -ss 1 -minValue 1 -fmn 1 -maxValue 100 -fmx 200 nurbsSquareSpans; radioButtonGrp -label (uiRes("m_performNurbsSquare.kCurveDegree")) -numberOfRadioButtons 3 -label1 (uiRes("m_performNurbsSquare.kOption1")) -label2 (uiRes("m_performNurbsSquare.kOption2")) -label3 (uiRes("m_performNurbsSquare.kOption3")) -select 3 nurbsSquareDegree123 ; radioButtonGrp -shareCollection nurbsSquareDegree123 -numberOfRadioButtons 2 -label1 (uiRes("m_performNurbsSquare.kOption5")) -label2 (uiRes("m_performNurbsSquare.kOption7")) nurbsSquareDegree57 ; // Set the center float fields. // floatFieldGrp -e -v1 `optionVar -q nurbsSquareCenterX` -v2 `optionVar -q nurbsSquareCenterY` -v3 `optionVar -q nurbsSquareCenterZ` nurbsSquareCenter ; // Set the axis float fields to only be enabled when "Axis Preset" is "Free" // string $axisEnable = ("floatFieldGrp -e -en 1 nurbsSquareNormalField;" + "floatFieldGrp -e" + " -v1 `optionVar -q nurbsSquareNormalX`" + " -v2 `optionVar -q nurbsSquareNormalY`" + " -v3 `optionVar -q nurbsSquareNormalZ`" + " nurbsSquareNormalField;" ); string $axisDisable = "floatFieldGrp -e -en 0 nurbsSquareNormalField;"; radioButtonGrp -edit -cc1 ($axisDisable + "floatFieldGrp -e -value 1.0 0.0 0.0 0.0 nurbsSquareNormalField;") -cc2 ($axisDisable + "floatFieldGrp -e -value 0.0 1.0 0.0 0.0 nurbsSquareNormalField;") -cc3 ($axisDisable + "floatFieldGrp -e -value 0.0 0.0 1.0 0.0 nurbsSquareNormalField;") nurbsSquareNormalXYZType1; radioButtonGrp -edit -cc1 $axisEnable -cc2 $axisDisable nurbsSquareNormalXYZType2; // 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_performNurbsSquare.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_performNurbsSquare.kNURBSSquareOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "NurbsSquare" ); // Set the current values of the option box. // ========================================= // eval (($setup + " " + $parent + " " + 0)); // Show the option box. // ==================== // showOptionBox(); } // // Procedure Name: // nurbsSquareHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string nurbsSquareHelp() { return " Command: nurbsSquare - create a NURBS square.\n"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "nurbsSquarePreset("; setOptionVars(false); float $centerX = `optionVar -q nurbsSquareCenterX`; float $centerY = `optionVar -q nurbsSquareCenterY`; float $centerZ = `optionVar -q nurbsSquareCenterZ`; $cmd = $cmd + $centerX + "," ; $cmd = $cmd + $centerY + "," ; $cmd = $cmd + $centerZ + "," ; // (Normal)Axis // int $axisType = `optionVar -q nurbsSquareNormalType`; 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 nurbsSquareNormalX`; $axis[1] = `optionVar -q nurbsSquareNormalY`; $axis[2] = `optionVar -q nurbsSquareNormalZ`; break; case 5: $axis = `nurbsViewDirectionVector 1`; break; } $cmd = $cmd + "0," ; $cmd = $cmd + $axis[0] + "," ; $cmd = $cmd + $axis[1] + "," ; $cmd = $cmd + $axis[2] + "," ; // side length. // float $sl = `optionVar -query nurbsSquareSide1` ; $cmd = $cmd + $sl + "," ; // side 2 length. // $sl = `optionVar -query nurbsSquareSide2` ; $cmd = $cmd + $sl + "," ; // # ofspans. // int $ss = `optionVar -query nurbsSquareSpansPerSide` ; $cmd = $cmd + $ss + "," ; // degree. // int $d = `optionVar -query nurbsSquareDegree` ; $cmd = $cmd + $d + "," ; // History // int $doHistory = `constructionHistory -q -toggle`; $cmd = $cmd + $doHistory ; $cmd += ")" ; if(`optionVar -q createNurbsPrimitiveAsTool`) { $cmd = "setToolTo \"CreateNurbsSquareCtx\""; } return $cmd; } // // Procedure Name: // performNurbsSquare // // Description: // Perform the square 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 nurbsSquarePreset script 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 performNurbsSquare(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 { nurbsSquareOptions; } break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }