// =========================================================================== // 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: 11 April 1997 // // Description: // Initialize the option values for attach menu item. // // Input Arguments: // int action // 0 - just execute the attach operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Keep multiple knots (on-1 or off-0 to be used if attach is on). // if ($forceFactorySettings || !`optionVar -exists attachCrvKeepMultKnots`) { optionVar -intValue attachCrvKeepMultKnots 1; } // keep original (for in place operations is on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists attachCrvKeepOriginal`) { optionVar -intValue attachCrvKeepOriginal 1; } // blend method // if ($forceFactorySettings || !`optionVar -exists attachCrvMethod`) { optionVar -intValue attachCrvMethod 1; } // insert knots for blend // if ($forceFactorySettings || !`optionVar -exists attachCrvBlendInsert`) { optionVar -intValue attachCrvBlendInsert 0; } // blend bias // if ($forceFactorySettings || !`optionVar -exists attachCrvBlendBias`) { optionVar -floatValue attachCrvBlendBias 0.5; } // blend insert // if ($forceFactorySettings || !`optionVar -exists attachCrvBlendParameter`) { optionVar -floatValue attachCrvBlendParameter 0.1; } } global proc attachCrvVisibility( string $parent, int $method, int $insert ) { if( $method < 0 ) { $method = `radioButtonGrp -q -sl attachCrvMethodWidget` - 1; } if( $insert < 0 ) { $insert = `checkBoxGrp -q -v1 attachCrvBlendInsertWidget`; } switch( $method ) { case 0: default: floatSliderGrp -e -en false attachCrvBlendBiasWidget; checkBoxGrp -e -en1 false attachCrvBlendInsertWidget; floatSliderGrp -e -en false attachCrvBlendParameterWidget; radioButtonGrp -e -en true attachMultKnotBtn; break; case 1: floatSliderGrp -e -en true attachCrvBlendBiasWidget; checkBoxGrp -e -en1 true attachCrvBlendInsertWidget; floatSliderGrp -e -en $insert attachCrvBlendParameterWidget; radioButtonGrp -e -en false attachMultKnotBtn; break; } } // // Procedure Name: // attachCrvSetup // // Description: // Update the state of the option box UI to reflect the attach // 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 attachCrvSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); attachCrvToolSetup( $forceFactorySettings, $goToTool ); setParent $parent; // Query the optionVar's and set the values into the controls. int $method = `optionVar -query attachCrvMethod`; float $bias = `optionVar -query attachCrvBlendBias`; int $insert = `optionVar -query attachCrvBlendInsert`; float $parameter = `optionVar -query attachCrvBlendParameter`; int $keep = `optionVar -query attachCrvKeepMultKnots`; int $keepOrig = `optionVar -query attachCrvKeepOriginal`; radioButtonGrp -e -select ($method+1) attachCrvMethodWidget; floatSliderGrp -e -v $bias attachCrvBlendBiasWidget; checkBoxGrp -e -v1 $insert attachCrvBlendInsertWidget; floatSliderGrp -e -v $parameter attachCrvBlendParameterWidget; radioButtonGrp -edit -select (2 - $keep) attachMultKnotBtn; checkBoxGrp -edit -value1 $keepOrig attachCrvKeepOriginalBox; if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } attachCrvVisibility $parent -1 -1; } // // Procedure Name: // attachCrvCallback // // 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 attachCrvCallback( string $parent, int $doIt, string $goToTool ) { if( "" != $goToTool ) { optionVar -iv attachCurveEuc `scriptCtx -q -euc $goToTool`; optionVar -iv attachCurveLac `scriptCtx -q -lac $goToTool`; } setParent $parent; // Set the optionVar's from the control values, and then // perform the command. int $method = `radioButtonGrp -q -select attachCrvMethodWidget` - 1; float $bias = `floatSliderGrp -q -v attachCrvBlendBiasWidget`; int $insert = `checkBoxGrp -q -v1 attachCrvBlendInsertWidget`; float $parameter = `floatSliderGrp -q -v attachCrvBlendParameterWidget`; int $keep = 2 - `radioButtonGrp -query -select attachMultKnotBtn`; int $keepOrig = `checkBoxGrp -query -value1 attachCrvKeepOriginalBox`; optionVar -intValue attachCrvMethod $method; optionVar -floatValue attachCrvBlendBias $bias; optionVar -intValue attachCrvBlendInsert $insert; optionVar -floatValue attachCrvBlendParameter $parameter; optionVar -intValue attachCrvKeepMultKnots $keep; optionVar -intValue attachCrvKeepOriginal $keepOrig; if( 1 == $doIt ) { performAttachCrv( 0, $goToTool ); string $tmpCmd = "performAttachCrv( 0, \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Attach Curves"; } else if( $doIt ) { setToolTo $goToTool; } } // // Procedure Name: // createAttachCrvUI // // Description: // Fill the contents of the option box for attach command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createAttachCrvUI(string $parent, int $inTheTool, string $goToTool) { setParent $parent; radioButtonGrp -label (uiRes("m_performAttachCrv.kAttachMethod")) -nrb 2 -label1 (uiRes("m_performAttachCrv.kConnect")) -label2 (uiRes("m_performAttachCrv.kBlend")) -on1 ("attachCrvVisibility " + $parent + " 0 -1" ) -on2 ("attachCrvVisibility " + $parent + " 1 -1" ) attachCrvMethodWidget; radioButtonGrp -label (uiRes("m_performAttachCrv.kMultipleKnots")) -numberOfRadioButtons 2 -label1 (uiRes("m_performAttachCrv.kKeep")) -label2 (uiRes("m_performAttachCrv.kRemove")) attachMultKnotBtn; floatSliderGrp -label (uiRes("m_performAttachCrv.kBlendBias")) -min 0.0 -max 1.0 attachCrvBlendBiasWidget; checkBoxGrp -ncb 1 -label1 (uiRes("m_performAttachCrv.kInsertKnot")) -on1 ("attachCrvVisibility " + $parent + " -1 1" ) -of1 ("attachCrvVisibility " + $parent + " -1 0" ) attachCrvBlendInsertWidget; floatSliderGrp -label (uiRes("m_performAttachCrv.kInsertParameter")) -min 0.0 -max 1.0 attachCrvBlendParameterWidget; checkBoxGrp -numberOfCheckBoxes 1 -label1 (uiRes("m_performAttachCrv.kKeepOriginals")) attachCrvKeepOriginalBox; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performAttachCrv.kToolBehavior")) -label1 (uiRes("m_performAttachCrv.kExitOnCompletion")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performAttachCrv.kAutoCompletion")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // attachOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc attachOptions( string $inTheTool, string $goToTool ) { // Name of the command for this option box. // string $commandName = "attach"; // Build the option box actions. // string $callback = ($commandName + "CrvCallback"); string $setup = ($commandName + "CrvSetup"); // The value returned is the name of the layout to be used as // the parent for the option box UI. // global string $gOptionBoxActionToolItem; $gOptionBoxActionToolItem = "modelWithToolAttachCurve"; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItemCB = "attachCrvToolScript 3"; string $layout = getOptionBox(); setParent $layout; // 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+"Curve"); // 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; // RECOMMENDATION: Place the UI in a scroll layout. If the // option box window is ever resized such that it's entire // contents is not visible then the scroll bars provided by the // scroll layout will allow the user to access the hidden UI. // tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // Create the UI for the tab that is initially visible. // createAttachCrvUI($parent, $inTheTool, $goToTool); // Turn off the wait cursor. // waitCursor -state 0; // Deactivate the default UI template. // setUITemplate -popTemplate; // Attach actions to those buttons that are applicable to the option // box. Note that the 'Close' button has a default action attached // to it that will hide the window. If a a custom action is // attached to the 'Close' button then be sure to call the 'hide the // option box' procedure within the custom action so that the option // box is hidden properly. // 'Attach' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -edit -label (uiRes("m_performAttachCrv.kAttachTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" ) $applyBtn; } else { button -edit -label (uiRes("m_performAttachCrv.kAttach")) -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; // Set the option box title. // if( $inTheTool ) { setOptionBoxTitle (uiRes("m_performAttachCrv.kAttachCurvesToolOptions")); } else { setOptionBoxTitle (uiRes("m_performAttachCrv.kAttachCurvesOptions")); } // Customize the 'Help' menu item text. // setOptionBoxHelpTag( "AttachCurves" ); // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // attachHelp // // Description: // Returns a short description about the attach command. // // Input Arguments: // None. // // Return Value: // string. // proc string attachHelp() { return " Command: Attach - joins two curves together\n" + "Selection: two curves or a parameter point on two curves."; } // // Procedure Name: // assembleCmd // // Description: // Construct the attach command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // The attach command string. // proc string assembleCmd() { setOptionVars(false); // get the global history flag value int $doHistory = `constructionHistory -q -tgl`; // is replace original on/off int $replaceOriginal = !`optionVar -q attachCrvKeepOriginal`; // attach related values int $keepMultKnots = `optionVar -query attachCrvKeepMultKnots`; int $method = `optionVar -query attachCrvMethod`; float $bias = `optionVar -query attachCrvBlendBias`; int $insert = `optionVar -query attachCrvBlendInsert`; float $parameter = `optionVar -query attachCrvBlendParameter`; // set up string for preset function call string $cmd = "doAttachCurveArgList 2 { "; $cmd = $cmd + "\"" + $doHistory + "\", "; $cmd = $cmd + "\"" + $replaceOriginal + "\", "; $cmd = $cmd + "\"" + $keepMultKnots + "\", "; $cmd = $cmd + "\"" + $method + "\", "; $cmd = $cmd + "\"" + $bias + "\", "; $cmd = $cmd + "\"" + $insert + "\", "; $cmd = $cmd + "\"" + $parameter + "\" }"; return $cmd; } // // Procedure Name: // performAttachCrv // // Description: // Perform the attach 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 attach 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: // The attach command string. // global proc string performAttachCrv( 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: attachOptions( $inTheTool, $goToTool ); break; case 2: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }