// =========================================================================== // 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: Mar 14, 1997 // // Description: // This script is defines the option box for the insertKnot menu item. // // Input Arguments: // int showOptionBox true - show the option box dialog // false - just execute the insertKnot operation // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { insertKnotSetOptionVars( $forceFactorySettings ); } global proc insertKnotSetup (string $parent, int $forceFactorySettings, string $goToTool) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; int $isItSurface = `radioButtonGrp -q -exists isoparmRadio`; // Query the optionVar's and set the values into the controls // int $keepOriginal, $addOrComplement, $between; int $isoparm, $numKnots; if( $isItSurface ) { $keepOriginal = `optionVar -query insertIsoKeepOriginal`; $addOrComplement = `optionVar -query insertIsoAddOrComplement`; $between = `optionVar -query insertIsoBetween`; $isoparm = `optionVar -query insertKnotIsoparm`; $numKnots = `optionVar -query insertIsoNumberOfIsosToInsert`; } else { $keepOriginal = `optionVar -query insertKnotKeepOriginal`; $addOrComplement = `optionVar -query insertKnotAddOrComplement`; $between = `optionVar -query insertKnotBetween`; $numKnots = `optionVar -query insertKnotNumberOfKnotsToInsert`; } checkBoxGrp -edit -value1 $keepOriginal keepOriginalCheckBox; radioButtonGrp -edit -select ($addOrComplement+1) addOrCompRadio; radioButtonGrp -edit -select ($between+1) betweenRadio; if( $isItSurface ) { radioButtonGrp -edit -select ($isoparm+1) isoparmRadio; } int $max = 3, $fmx = 7; int $enableIso = false; int $enableAdd = true; if( $between ) { $max = 10; $fmx = 20; $enableIso = true; $enableAdd = false; } if( $isItSurface ) { radioButtonGrp -edit -enable $enableIso isoparmRadio; } radioButtonGrp -edit -enable $enableAdd addOrCompRadio; if( $between || $numKnots < 4 ) { intSliderGrp -e -min 1 -max $max -fmn 1 -fmx $fmx numKnotsIntSlider; } if( $between ) { if( $isItSurface ) { intSliderGrp -edit -label (uiRes("m_performInsertKnot.kIsoparms")) numKnotsIntSlider; } else { intSliderGrp -edit -label (uiRes("m_performInsertKnot.kKnots")) numKnotsIntSlider; } } else { intSliderGrp -edit -label (uiRes("m_performInsertKnot.kMultiplicity")) numKnotsIntSlider; } intSliderGrp -edit -value $numKnots numKnotsIntSlider; if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } } global proc insertKnotCurveSetup (string $parent, int $forceFactorySettings, string $goToTool) { insertCurveToolSetup( $forceFactorySettings, $goToTool ); insertKnotSetup( $parent, $forceFactorySettings, $goToTool ); } global proc insertKnotSurfaceSetup (string $parent, int $forceFactorySettings, string $goToTool) { insertSurfaceToolSetup( $forceFactorySettings, $goToTool ); insertKnotSetup( $parent, $forceFactorySettings, $goToTool ); } global proc insertKnotCallback (string $parent, int $doIt, string $goToTool) { setParent $parent; int $isItSurface = `radioButtonGrp -q -exists isoparmRadio`; // Set the optionVar's from the control values, and then perform // the command // int $keep = `checkBoxGrp -query -value1 keepOriginalCheckBox`; int $addOrComplement = `radioButtonGrp -q -select addOrCompRadio` - 1; int $between = `radioButtonGrp -q -select betweenRadio` - 1; int $numKnots = `intSliderGrp -query -value numKnotsIntSlider`; string $objectType; if( $isItSurface ) { $objectType = "Surface"; int $isoparm = `radioButtonGrp -q -select isoparmRadio` - 1; optionVar -intValue insertKnotIsoparm $isoparm; optionVar -intValue insertIsoKeepOriginal $keep; optionVar -intValue insertIsoAddOrComplement $addOrComplement; optionVar -intValue insertIsoBetween $between; optionVar -intValue insertIsoNumberOfIsosToInsert $numKnots; } else { $objectType = "Curve"; optionVar -intValue insertKnotKeepOriginal $keep; optionVar -intValue insertKnotAddOrComplement $addOrComplement; optionVar -intValue insertKnotBetween $between; optionVar -intValue insertKnotNumberOfKnotsToInsert $numKnots; } if( 1 == $doIt ) { performInsertKnot( 0, $objectType, $goToTool ); string $tmpCmd = "performInsertKnot( 0, \""; $tmpCmd += $objectType + "\", \""; $tmpCmd += $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Insert Knot"; } else if( $doIt ) { setToolTo $goToTool; } } global proc insertKnotCurveCallback (string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv insertCurveEuc `scriptCtx -q -euc $goToTool`; optionVar -iv insertCurveLac `scriptCtx -q -lac $goToTool`; } insertKnotCallback( $parent, $doIt, $goToTool ); } global proc insertKnotSurfaceCallback (string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv insertSurfaceEuc `scriptCtx -q -euc $goToTool`; optionVar -iv insertSurfaceLac `scriptCtx -q -lac $goToTool`; } insertKnotCallback( $parent, $doIt, $goToTool ); } // // Procedure Name: // insertKnotOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // string $objectType: Is this insertKnot Curves or insertKnot Surfaces? // None. // // Return Value: // None. // proc insertKnotOptions (string $objectType, int $inTheTool, string $goToTool) { int $isItCurve = ("Surface" != $objectType); int $isItSurface = ("Curve" != $objectType); // Name of the command for this option box. // string $commandName = "insertKnot"; // Build the option box actions. // string $callback = ($commandName + $objectType + "Callback"); string $setup = ($commandName + $objectType + "Setup"); // Step 1: Get the option box. // ============================ global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolInsert" + $objectType; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "insert" + $objectType + "ToolScript 3"; string $layout = getOptionBox(); setParent $layout; // Step 2: Pass the command name to the option box. // ================================================= // Any default option box behavior based on the command name is set // up with this call. // setOptionBoxCommandName($commandName+$objectType); // Step 3: Activate the default UI template. // ========================================== setUITemplate -pushTemplate DefaultTemplate; // Step 4: Create option box contents. // =================================== // Turn on the wait cursor. // waitCursor -state 1; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; string $isoWidget; radioButtonGrp -nrb 2 -label (uiRes("m_performInsertKnot.kInsertLocation")) -label1 (uiRes("m_performInsertKnot.kAtSelection")) -label2 (uiRes("m_performInsertKnot.kBetweenSelections")) betweenRadio; if( $isItSurface ) { $isoWidget = `radioButtonGrp -nrb 2 -label (uiRes("m_performInsertKnot.kUseSurfaceIsoparm")) -label1 (uiRes("m_performInsertKnot.kUAxis")) -label2 (uiRes("m_performInsertKnot.kVAxis")) isoparmRadio`; } string $multiplicity = (uiRes("m_performInsertKnot.kMultiplicityValue")); string $addWidget = `radioButtonGrp -nrb 2 -label $multiplicity -label1 (uiRes("m_performInsertKnot.kSet")) -label2 (uiRes("m_performInsertKnot.kIncrease")) addOrCompRadio`; string $sliderWidget = `intSliderGrp -field true -min 1 -max 3 -fmn 1 -fmx 7 -label $multiplicity numKnotsIntSlider`; checkBoxGrp -ncb 1 -label1 (uiRes("m_performInsertKnot.kKeepOriginal")) keepOriginalCheckBox; string $isoParms = uiRes("m_performInsertKnot.kIsoparms"); string $knots = uiRes("m_performInsertKnot.kKnots"); if( $isItSurface ) { radioButtonGrp -edit -onCommand1 ( "intSliderGrp -edit -max 3 -fmx 7 " + $sliderWidget + "; " + "intSliderGrp -edit -label \"" + $multiplicity + "\" " + $sliderWidget + "; " + "radioButtonGrp -edit -enable false " + $isoWidget + "; " + "radioButtonGrp -edit -enable true " + $addWidget + "; " ) -onCommand2 ( "intSliderGrp -edit -max 10 -fmx 20 " + $sliderWidget + "; " + "intSliderGrp -edit -label \"" + $isoParms + "\" " + $sliderWidget + "; " + "radioButtonGrp -edit -enable true " + $isoWidget + "; " + "radioButtonGrp -edit -enable false " + $addWidget + "; " ) betweenRadio; } else { radioButtonGrp -edit -onCommand1 ( "intSliderGrp -edit -max 3 -fmx 7 " + $sliderWidget + "; " + "intSliderGrp -edit -label \"" + $multiplicity + "\" " + $sliderWidget + "; " + "radioButtonGrp -edit -enable true " + $addWidget + "; " ) -onCommand2 ( "intSliderGrp -edit -max 10 -fmx 20 " + $sliderWidget + "; " + "intSliderGrp -edit -label \"" + $knots + "\" " + $sliderWidget + "; " + "radioButtonGrp -edit -enable false " + $addWidget + "; " ) betweenRadio; } if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performInsertKnot.kToolBehavior")) -label1 (uiRes("m_performInsertKnot.kExit")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performInsertKnot.kAuto")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } // Turn off the wait cursor. // waitCursor -state 0; // Step 5: Deactivate the default UI template. // =========================================== // setUITemplate -popTemplate; // Step 6: Customize the buttons. // ============================== // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performInsertKnot.kInsertTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" ) $applyBtn; } else { button -edit -label (uiRes("m_performInsertKnot.kInsert")) -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"" ) $applyBtn; } // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " 0 \"" + $goToTool + "\"; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"") $resetBtn; // Step 7: Set the option box title. // ================================= // if( $inTheTool ) { if( $isItCurve ) { setOptionBoxTitle (uiRes("m_performInsertKnot.kKnotToolTitle")); } else { setOptionBoxTitle (uiRes("m_performInsertKnot.kIsoparmsToolTitle")); } } else { if( $isItCurve ) { setOptionBoxTitle (uiRes("m_performInsertKnot.kKnotTitle")); } else { setOptionBoxTitle (uiRes("m_performInsertKnot.kIsoparmsTitle")); } } // Step 8: Customize the 'Help' menu item text. // ============================================ // if( $isItCurve ) { setOptionBoxHelpTag( "InsertKnot" ); } else { setOptionBoxHelpTag( "InsertIsoparms" ); } // Step 9: Set the current values of the option box. // ================================================= // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // insertKnotHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string insertKnotHelp() { return ( " Command: Insert Knot - insert an edit point into a NURBS " + "curve or an isoparm into a NURBS surface.\n" + "Selection: curve point(s), curve on surface point(s), " + "surface isoparm(s), surface points or a complete NURBS surface."); } proc string assembleCmd( string $objectType ) { string $cmd; int $isItSurface = ("Curve" != $objectType); setOptionVars( false ); int $doHistory = `constructionHistory -q -tgl`; int $replaceOriginal, $addOrComplement, $between; int $isoparm, $numKnots; if( $isItSurface ) { $replaceOriginal = !`optionVar -query insertIsoKeepOriginal`; $addOrComplement = `optionVar -query insertIsoAddOrComplement`; $between = `optionVar -query insertIsoBetween`; $isoparm = `optionVar -query insertKnotIsoparm`; $numKnots = `optionVar -query insertIsoNumberOfIsosToInsert`; } else { $replaceOriginal = !`optionVar -query insertKnotKeepOriginal`; $addOrComplement = `optionVar -query insertKnotAddOrComplement`; $between = `optionVar -query insertKnotBetween`; $isoparm = `optionVar -query insertKnotIsoparm`; $numKnots = `optionVar -query insertKnotNumberOfKnotsToInsert`; } $cmd = ("insertKnotPreset " + $doHistory + " " + $replaceOriginal + " " + $addOrComplement + " " + $numKnots + " " + $between + " " + $isoparm ); return $cmd; } global proc string performInsertKnot( int $action, string $objectType, string $goToTool ) // For $action: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // 3 - Show the tool option box dialog. { int $inTheTool = false; if( 3 == $action ) { $action = 1; $inTheTool = true; } string $cmd = ""; switch ($action) { case 0: setOptionVars (false); $cmd = `assembleCmd $objectType`; eval($cmd); break; case 1: insertKnotOptions( $objectType, $inTheTool, $goToTool ); break; case 2: default: setOptionVars (false); $cmd = `assembleCmd $objectType`; break; } return $cmd; }