// =========================================================================== // 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 planarTrim 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 planarTrimDegree`) { optionVar -intValue planarTrimDegree 3; } if ($forceFactorySettings || !`optionVar -exists planarTrimPartial`){ optionVar -intValue planarTrimPartial 0; } if ($forceFactorySettings || !`optionVar -exists planarTrimPolys`){ optionVar -intValue planarTrimPolys 0; } } // // Procedure Name: // planarTrimSetup // // 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 planarTrimSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); planarToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. // Query the optionVar's and set the values into the controls // int $degree = `optionVar -query planarTrimDegree`; int $partial = `optionVar -query planarTrimPartial`; int $polys = `optionVar -query planarTrimPolys`; if( ! `isTrue "SurfaceUIExists"` ) $polys = 1; // We get a single patch plane, trimmed. No point in making // a subd or a Bezier out of it, you'd always get the same // result. if( $polys > 1 ) $polys = 0; if( 1 == $degree ) { radioButtonGrp -edit -select 1 degreeRadio; } else { radioButtonGrp -edit -select 2 degreeRadio; } radioButtonGrp -edit -select ($partial+1) partialRadio; // set polygons | Nurbs option. // if( `isTrue "SurfaceUIExists"` ) { radioButtonGrp -edit -select ($polys+1) outputPolyRadioButtonGrp; } switch( $polys ) { case 0: default: tabLayout -e -vis false polyOptions; // there are currently no NURBS options break; case 1: tabLayout -e -vis true polyOptions; break; case 2: tabLayout -e -vis false polyOptions; // there are currently no subdiv options break; } if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } nurbsToPolySetup( $parent, $forceFactorySettings ); nurbsToSubdivSetup( $parent, $forceFactorySettings ); } // // Procedure Name: // planarTrimCallback // // 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 planarTrimCallback( string $parent, int $doIt, string $goToTool ) { if( "" != $goToTool ) { optionVar -iv planarTrimEuc `scriptCtx -q -euc $goToTool`; optionVar -iv planarTrimLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the current control values, and then perform // the command // int $degree = 3; if( 1 == `radioButtonGrp -q -select degreeRadio` ) { $degree = 1; } int $partial = `radioButtonGrp -q -select partialRadio` - 1; if( `isTrue "SurfaceUIExists"` ) { int $polys = `radioButtonGrp -q -select outputPolyRadioButtonGrp` -1; optionVar -intValue planarTrimPolys $polys; } optionVar -intValue planarTrimDegree $degree; optionVar -intValue planarTrimPartial $partial; nurbsToPolyCallback( $parent, 0 ); nurbsToSubdivCallback( $parent, 0 ); if( 1 == $doIt ) { performPlanarTrim( 0, $goToTool ); string $tmpCmd = "performPlanarTrim( 0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Planar"; } else if( $doIt ) { setToolTo $goToTool; } } // // Procedure Name: // planarTrimOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc planarTrimOptions( int $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "planarTrim"; // Build the option box actions. // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolPlanar"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "planarToolScript 3"; // Step 1: Get the option box. // ============================ string $layout = getOptionBox(); setParent $layout; // Step 2: Pass the command name to the option box. // ================================================= setOptionBoxCommandName("planarSrf"); // 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`; radioButtonGrp -nrb 2 -label (uiRes("m_performPlanarTrim.kDegree")) -label1 (uiRes("m_performPlanarTrim.kLinear")) -label2 (uiRes("m_performPlanarTrim.kCubic")) degreeRadio; separator; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performPlanarTrim.kCurveRange")) -label1 (uiRes("m_performPlanarTrim.kComplete")) -label2 (uiRes("m_performPlanarTrim.kPartial")) partialRadio; // output Geometry // // Since this mostly produces trimmed surfaces and we are not // dealing with those at this time as conversion to subdivs goes, // we won't display the third option in this tool. string $outputGeometry = (uiRes("m_performPlanarTrim.kOutputGeometry")); string $nurbs = (uiRes("m_performPlanarTrim.kNurbs")); string $polygons = (uiRes("m_performPlanarTrim.kPolygons")); if( false && `isTrue "SubdivUIExists"` ) { radioButtonGrp -numberOfRadioButtons 3 -label $outputGeometry -label1 $nurbs -label2 $polygons -label3 (uiRes("m_performPlanarTrim.kSubdiv")) -cc1 "tabLayout -e -vis false polyOptions" // there are currently no NURBS options -cc2 "tabLayout -e -vis true polyOptions" -cc3 "tabLayout -e -vis false polyOptions" // there are currently no subdiv options outputPolyRadioButtonGrp; } else if( `isTrue "SurfaceUIExists"` ) { radioButtonGrp -numberOfRadioButtons 2 -label $outputGeometry -label1 $nurbs -label2 $polygons -cc1 "tabLayout -e -vis false polyOptions" // there are currently no NURBS options -cc2 "tabLayout -e -vis true polyOptions" outputPolyRadioButtonGrp; } tabLayout -tabsVisible false polyOptions; string $par = `columnLayout polyOptionsOK`; nurbsToPolyAddOptions $par; setParent ..; setParent ..; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performPlanarTrim.kToolBehavior")) -label1 (uiRes("m_performPlanarTrim.kExitOnCompletion")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performPlanarTrim.kAutoCompletion")) -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_performPlanarTrim.kPlanarTrimTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"") $applyBtn; } else { button -edit -label (uiRes("m_performPlanarTrim.kPlanarTrim")) -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 ) { setOptionBoxTitle (uiRes("m_performPlanarTrim.kPlanarTrimSurfaceToolOptions")); } else { setOptionBoxTitle (uiRes("m_performPlanarTrim.kPlanarTrimSurfaceOptions")); } // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "Planar" ); // Step 9: Set the current values of the option box. // ================================================= // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // planarTrimHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string planarTrimHelp() { return " Command: PlanarTrim - create a planar trimmed surface curves.\n" + "Selection: curves, surface isoparms, curve on surface, surface edges"; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // None. // proc string assembleCmd() { string $cmd = "performPlanarTrimPreset"; setOptionVars(false); int $doHistory = `constructionHistory -q -tgl`; int $degree = `optionVar -q planarTrimDegree`; int $partial = `optionVar -q planarTrimPartial`; int $polys = `optionVar -q planarTrimPolys`; if( ! `isTrue "SurfaceUIExists"` ) $polys = 1; float $pntTol = `optionVar -q positionalTolerance`; $cmd = ( $cmd + " " + $doHistory + " " + $degree + " " + "0" + " " + $pntTol + " " + $partial + " " + $polys ); return $cmd; } // // Procedure Name: // performPlanarTrim // // Description: // Perform the planarTrim 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 planarTrim command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // 3 - Show the tool option box dialog. // // Return Value: // None. // global proc string performPlanarTrim( int $action, string $goToTool ) { int $inTheTool = false; if( 3 == $action ) { $action = 1; $inTheTool = true; } string $cmd = ""; switch ($action) { case 0: setOptionVars(false); $cmd = `assembleCmd`; eval($cmd); break; case 1: planarTrimOptions( $inTheTool, $goToTool ); break; case 2: default: setOptionVars (false); $cmd = `assembleCmd`; break; } return $cmd; }