// =========================================================================== // 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 align menu item. // // Input Arguments: // int action // 0 - just execute the align operation // 1 - show the option box dialog // 2 - drag to shelf // // Return Value: // None. // proc setOptionVars(int $forceFactorySettings) { // Attach (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists alignAttach`) { optionVar -intValue alignAttach 0; } // Keep multiple knots (on-1 or off-0 to be used if attach is on). // if ($forceFactorySettings || !`optionVar -exists alignKeepMultKnots`) { optionVar -intValue alignKeepMultKnots 1; } // Positional continuity type (1-6). // if ($forceFactorySettings || !`optionVar -exists alignPositionalType`) { optionVar -intValue alignPositionalType 1; } // Tangent continuity (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists alignTangent`) { optionVar -intValue alignTangent 1; } // Tangent continuity type (1-2). // if ($forceFactorySettings || !`optionVar -exists alignTangentType`) { optionVar -intValue alignTangentType 1; } // Curvature continuity (on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists alignCurvature`) { optionVar -intValue alignCurvature 0; } // Tangent scale for object1 (only used if tangent continuity is on). // if ($forceFactorySettings || !`optionVar -exists alignTangentScale1`) { optionVar -floatValue alignTangentScale1 1.0; } // Tangent scale for object2 (only used if tangent continuity is on). // if ($forceFactorySettings || !`optionVar -exists alignTangentScale2`) { optionVar -floatValue alignTangentScale2 1.0; } // Curvature scale for object1 (only used if curvature continuity is on). // if ($forceFactorySettings || !`optionVar -exists alignCurvatureScale1`) { optionVar -floatValue alignCurvatureScale1 0.0; } // Curvature scale for object2 (only used if curvature continuity is on). // if ($forceFactorySettings || !`optionVar -exists alignCurvatureScale2`) { optionVar -floatValue alignCurvatureScale2 0.0; } // keep original (for in place operations is on-1 or off-0). // if ($forceFactorySettings || !`optionVar -exists alignKeepOriginal`) { optionVar -intValue alignKeepOriginal 0; } } // // Procedure Name: // alignSetup // // Description: // Update the state of the option box UI to reflect the align // 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 alignSetup( string $parent, int $forceFactorySettings, string $goToTool ) { // Retrieve the option settings // setOptionVars($forceFactorySettings); setParent $parent; // Query the optionVar's and set the values into the controls. // Attach. // int $doAttach = `optionVar -q alignAttach`; checkBoxGrp -e -value1 $doAttach alignAttachBox; // Keep mult knots (if remove multiple knots then the 2nd button should // be selected). // int $keep = `optionVar -q alignKeepMultKnots`; if ( $keep == 0 ) $keep = 2; radioButtonGrp -e -select $keep -enable $doAttach alignMultKnotBtn; // Continuity type. // int $contType = 1; if ( `optionVar -q alignTangent` ) $contType++; if ( `optionVar -q alignCurvature` ) $contType++; // select the appriate button in the first group radioButtonGrp -e -sl $contType alignContinuityBtn; if ( $contType == 1 ) { // just positional continuity is on // tabLayout -e -st emptyBlendingTab tangentBlendingTabs; tabLayout -e -st tangentOff_tab tangentOptionTabs; } else if ( $contType == 2 ) { // positional and tangent continuity is on // tabLayout -e -st alignScaleOptions tangentBlendingTabs; tabLayout -e -st tangentOn_tab tangentOptionTabs; floatSliderGrp -e -enable false alignCrvScale1Slider; floatSliderGrp -e -enable false alignCrvScale2Slider; } else { // positional, tangent and curvature continuity is on // tabLayout -e -st alignScaleOptions tangentBlendingTabs; tabLayout -e -st tangentOn_tab tangentOptionTabs; floatSliderGrp -e -enable true alignCrvScale1Slider; floatSliderGrp -e -enable true alignCrvScale2Slider; } // Positional continuity type (values range 1-6). // int $posType = `optionVar -q alignPositionalType`; if ( $posType < 4 ) { // select the appropriate button in the first group radioButtonGrp -e -select $posType alignModPosBtn; } else { // select the appropriate button in the second group (from 1 to 3) $posType = $posType - 3; radioButtonGrp -e -select $posType alignModBndBtn; } // Tangent continuity type (if not just positional continuity). // radioButtonGrp -e -select `optionVar -q alignTangentType` alignModTanBtn; // Tangent and curvature scale values. // floatSliderGrp -e -value `optionVar -q alignTangentScale1` alignTanScale1Slider; floatSliderGrp -e -value `optionVar -q alignTangentScale2` alignTanScale2Slider; floatSliderGrp -e -value `optionVar -q alignCurvatureScale1` alignCrvScale1Slider; floatSliderGrp -e -value `optionVar -q alignCurvatureScale2` alignCrvScale2Slider; if ( $forceFactorySettings == 1 ) { // reset the floatSliderGrps default range for the slider part // floatSliderGrp -e -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignTanScale1Slider; floatSliderGrp -e -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignTanScale2Slider; floatSliderGrp -e -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignCrvScale1Slider; floatSliderGrp -e -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignCrvScale2Slider; } // Keep original. // checkBoxGrp -e -value1 `optionVar -q alignKeepOriginal` alignKeepOrigBox; if( "" != $goToTool ) { checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool` scriptToolExtraWidget; checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool` scriptToolExtraWidget; } } global proc alignCurveSetup( string $parent, int $forceFactorySettings, string $goToTool ) { alignCurveToolSetup( $forceFactorySettings, $goToTool ); alignSetup( $parent, $forceFactorySettings, $goToTool ); } global proc alignSurfaceSetup( string $parent, int $forceFactorySettings, string $goToTool ) { alignSurfaceToolSetup( $forceFactorySettings, $goToTool ); alignSetup( $parent, $forceFactorySettings, $goToTool ); } // // Procedure Name: // alignCallback // // 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 alignCallback(string $parent, int $doIt, string $goToTool) { setParent $parent; // Set the optionVar's from the control values, and then // perform the command. // Attach. // optionVar -intValue alignAttach `checkBoxGrp -q -value1 alignAttachBox`; // Keep mult knots (if remove multiple knots the query will guve 2 as the // selected button but we need the value as 0 for remove and 1 for keep). // int $keep = `radioButtonGrp -q -select alignMultKnotBtn`; if ( $keep == 2 ) $keep = 0; optionVar -intValue alignKeepMultKnots $keep; // The continuity types - always have positional continuity at least. // int $whichPosType = `radioButtonGrp -q -select alignModPosBtn`; if ( $whichPosType == 0 ) { // a button in the second group was selected so make the optionVar // value range 1-6 // $whichPosType = `radioButtonGrp -q -select alignModBndBtn`; $whichPosType = $whichPosType + 3; } optionVar -intValue alignPositionalType $whichPosType; int $whichContinuity = `radioButtonGrp -q -select alignContinuityBtn`; if ( $whichContinuity == 1 ) { // just have positional continuity // optionVar -intValue alignTangent 0; optionVar -intValue alignCurvature 0; } else if ( $whichContinuity == 2 ) { // also have tangent continuity // optionVar -intValue alignTangent 1; optionVar -intValue alignCurvature 0; int $whichTanType = `radioButtonGrp -q -select alignModTanBtn`; optionVar -intValue alignTangentType $whichTanType; optionVar -floatValue alignTangentScale1 `floatSliderGrp -q -value alignTanScale1Slider`; optionVar -floatValue alignTangentScale2 `floatSliderGrp -q -value alignTanScale2Slider`; } else if ( $whichContinuity == 3 ) { // also have tangent and curvature continuity // optionVar -intValue alignTangent 1; optionVar -intValue alignCurvature 1; int $whichTanType = `radioButtonGrp -q -select alignModTanBtn`; optionVar -intValue alignTangentType $whichTanType; optionVar -floatValue alignTangentScale1 `floatSliderGrp -q -value alignTanScale1Slider`; optionVar -floatValue alignCurvatureScale1 `floatSliderGrp -q -value alignCrvScale1Slider`; optionVar -floatValue alignTangentScale2 `floatSliderGrp -q -value alignTanScale2Slider`; optionVar -floatValue alignCurvatureScale2 `floatSliderGrp -q -value alignCrvScale2Slider`; } // Keep original. // optionVar -intValue alignKeepOriginal `checkBoxGrp -q -value1 alignKeepOrigBox`; if( 1 == $doIt ) { performAlign( 0, "", $goToTool); string $tmpCmd = "performAlign( 0, \"\", \"" + $goToTool + "\")"; addToRecentCommandQueue $tmpCmd "Align"; } else if ($doIt) { setToolTo $goToTool; } } global proc alignCurveCallback(string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv alignCurveEuc `scriptCtx -q -euc $goToTool`; optionVar -iv alignCurveLac `scriptCtx -q -lac $goToTool`; } alignCallback( $parent, $doIt, $goToTool ); } global proc alignSurfaceCallback(string $parent, int $doIt, string $goToTool) { if( "" != $goToTool ) { optionVar -iv alignSurfaceEuc `scriptCtx -q -euc $goToTool`; optionVar -iv alignSurfaceLac `scriptCtx -q -lac $goToTool`; } alignCallback( $parent, $doIt, $goToTool ); } // // Procedure Name: // createAlignUI // // Description: // Fill the contents of the option box for align command. // // Input Arguments: // The name of the parent layout. // // Return Value: // None. // proc createAlignUI(string $parent, int $inTheTool, string $goToTool) { setParent $parent; // the attach options // checkBoxGrp -label "" -numberOfCheckBoxes 1 -label1 (uiRes("m_performAlign.kAttach")) -onCommand1 ("radioButtonGrp -e -enable true alignMultKnotBtn;") -offCommand1 ("radioButtonGrp -e -enable false alignMultKnotBtn;") alignAttachBox; // the first time the option box is opened these buttons // should be dimmed because attach is off by default // radioButtonGrp -enable false -label (uiRes("m_performAlign.kMultipleKnots")) -numberOfRadioButtons 2 -label1 (uiRes("m_performAlign.kKeep")) -label2 (uiRes("m_performAlign.kRemove")) alignMultKnotBtn; separator; tabLayout -tabsVisible false positionalOptionTabs; columnLayout positionalOn_tab; radioButtonGrp -label (uiRes("m_performAlign.kContinuity")) -nrb 3 -label1 (uiRes("m_performAlign.kPosition")) -label2 (uiRes("m_performAlign.kTangent")) -label3 (uiRes("m_performAlign.kCurvature")) -onCommand1 ("tabLayout -e -st emptyBlendingTab " + "tangentBlendingTabs; tabLayout -e -st " + "tangentOff_tab tangentOptionTabs;") -onCommand2 ("tabLayout -e -st alignScaleOptions " + "tangentBlendingTabs; tabLayout -e -st " + "tangentOn_tab tangentOptionTabs; " + "floatSliderGrp -e -enable false " + "alignCrvScale1Slider; floatSliderGrp -e " + "-enable false alignCrvScale2Slider;") -onCommand3 ("tabLayout -e -st alignScaleOptions " + "tangentBlendingTabs; tabLayout -e -st " + "tangentOn_tab tangentOptionTabs; " + "floatSliderGrp -e -enable true " + "alignCrvScale1Slider; floatSliderGrp -e " + "-enable true alignCrvScale2Slider;") alignContinuityBtn; string $first = (uiRes("m_performAlign.kFirst")); string $second = (uiRes("m_performAlign.kSecond")); string $both = (uiRes("m_performAlign.kBoth")); radioButtonGrp -label (uiRes("m_performAlign.kModifyPosition")) -numberOfRadioButtons 3 -label1 $first -da1 1 -label2 $second -da2 2 -label3 $both -da3 3 alignModPosBtn; radioButtonGrp -label (uiRes("m_performAlign.kModifyBoundary")) -scl alignModPosBtn -numberOfRadioButtons 3 -label1 $first -da1 4 -label2 $second -da2 5 -label3 $both -da3 6 alignModBndBtn; setParent ..; setParent ..; tabLayout -tabsVisible false tangentOptionTabs; columnLayout tangentOn_tab; radioButtonGrp -label (uiRes("m_performAlign.kModifyTangent")) -numberOfRadioButtons 2 -label1 $first -da1 1 -label2 $second -da2 2 alignModTanBtn; setParent ..; columnLayout tangentOff_tab; separator -h 5 -style "none"; setParent ..; setParent ..; separator; tabLayout -tabsVisible false tangentBlendingTabs; // Scale options // columnLayout alignScaleOptions; floatSliderGrp -label (uiRes("m_performAlign.kTangentScaleFirst")) -field true -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignTanScale1Slider; // the first time the option box is opened this field // should be dimmed because curvature is off by default // floatSliderGrp -enable false -label (uiRes("m_performAlign.kCurvatureScaleFirst")) -field true -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignCrvScale1Slider; floatSliderGrp -label (uiRes("m_performAlign.kTangentScaleSecond")) -field true -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignTanScale2Slider; // the first time the option box is opened this field // should be dimmed because curvature is off by default // floatSliderGrp -enable false -label (uiRes("m_performAlign.kCurvatureScaleSecond")) -field true -min -5.0 -max 5.0 -fmn -100.0 -fmx 100.0 alignCrvScale2Slider; setParent ..; // Empty section when tangent/curvature is turned OFF // columnLayout emptyBlendingTab; setParent ..; setParent ..; separator; // keep original option // checkBoxGrp -label "" -numberOfCheckBoxes 1 -label1 (uiRes("m_performAlign.kKeepOriginals")) alignKeepOrigBox; if( $inTheTool ) { separator; checkBoxGrp -ncb 2 -label (uiRes("m_performAlign.kToolBehavior")) -label1 (uiRes("m_performAlign.kExit")) -v1 off -on1 ("scriptCtx -e -euc true " + $goToTool) -of1 ("scriptCtx -e -euc false " + $goToTool) -label2 (uiRes("m_performAlign.kAuto")) -v2 on -on2 ("scriptCtx -e -lac true " + $goToTool) -of2 ("scriptCtx -e -lac false " + $goToTool) scriptToolExtraWidget; } } // // Procedure Name: // alignOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // string $objectType: Is this Align Curves or Align Surfaces? // // Return Value: // None. // proc alignOptions(string $objectType, int $inTheTool, string $goToTool) { // Name of the command for this option box. // string $commandName = "align"; // Build the option box actions. // string $callback = ($commandName + $objectType + "Callback"); string $setup = ($commandName + $objectType + "Setup"); global string $gOptionBoxActionToolItem; global string $gOptionBoxActionToolItemCB; $gOptionBoxActionToolItem = "modelWithToolAlign" + $objectType; $gOptionBoxActionToolItemCB = "align" + $objectType + "ToolScript 3"; // 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; // Any default option box behavior based on the command name is set // up with this call. // setOptionBoxCommandName($commandName+$objectType); // 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; tabLayout -scr true -tv false; string $parent = `columnLayout -adjustableColumn 1`; // Create the UI for the tab that is initially visible. // createAlignUI($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. // 'Align' button. // string $applyBtn = getOptionBoxApplyBtn(); if( $inTheTool ) { button -e -label (uiRes("m_performAlign.kAlignTool")) -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" ) $applyBtn; } else { button -e -label (uiRes("m_performAlign.kAlign")) -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"" ) $applyBtn; } // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -e -command ($callback + " " + $parent + " 0 \"" + $goToTool + "\"; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -e -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"") $resetBtn; // Set the option box title. // string $optionTitle; string $alignTitle; if( $inTheTool ) { if($objectType == "Curve") { setOptionBoxTitle (uiRes("m_performAlign.kAlignCurvesToolOptions")); } else { setOptionBoxTitle (uiRes("m_performAlign.kAlignSurfacesToolOptions")); } } else { if($objectType == "Curve") { setOptionBoxTitle (uiRes("m_performAlign.kAlignCurvesOptions")); } else { setOptionBoxTitle (uiRes("m_performAlign.kAlignSurfacesOptions")); } } // Customize the 'Help' menu item text. // if ($objectType == "Curve") { setOptionBoxHelpTag( "AlignCurves" ); } else { setOptionBoxHelpTag( "AlignSurfaces" ); } // Set the current values of the option box. // eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\""); // Show the option box. // showOptionBox(); } // // Procedure Name: // alignHelp // // Description: // Returns a short description about the align command. // // Input Arguments: // None. // // Return Value: // string. // proc string alignHelp() { return " Command: Align - aligns two curves or surfaces with positional continuity and with optional tangent or curvature continuity.\n" + "Selection: two curves or a parameter point on two curves. Or two surfaces or an isoparm on two surfaces."; } // // Procedure Name: // assembleCmd // // Description: // Construct the align command that will apply the option box values. // // Input Arguments: // None. // // Return Value: // The align 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 alignKeepOriginal`; // attach related values int $attach = `optionVar -q alignAttach`; int $keepMultKnots = `optionVar -q alignKeepMultKnots`; // positional continuity type int $positionalContinuityType = `optionVar -q alignPositionalType`; // tangent continuity related values int $doTangentContinuity = `optionVar -q alignTangent`; int $tangentContinuityType = `optionVar -q alignTangentType`; float $tangentScale1 = `optionVar -q alignTangentScale1`; float $tangentScale2 = `optionVar -q alignTangentScale2`; // curvature continuity related values int $doCurvatureContinuity = `optionVar -q alignCurvature`; float $curvatureScale1 = `optionVar -q alignCurvatureScale1`; float $curvatureScale2 = `optionVar -q alignCurvatureScale2`; // set up string for preset function call string $cmd = "alignPreset"; $cmd = $cmd + "(" ; $cmd = $cmd + $doHistory; $cmd = $cmd + ","; $cmd = $cmd + $replaceOriginal; $cmd = $cmd + ","; $cmd = $cmd + $attach; $cmd = $cmd + ","; $cmd = $cmd + $keepMultKnots; $cmd = $cmd + ","; $cmd = $cmd + $positionalContinuityType; $cmd = $cmd + ","; $cmd = $cmd + $doTangentContinuity; $cmd = $cmd + ","; $cmd = $cmd + $tangentContinuityType; $cmd = $cmd + ","; $cmd = $cmd + $doCurvatureContinuity; $cmd = $cmd + ","; $cmd = $cmd + $tangentScale1; $cmd = $cmd + ","; $cmd = $cmd + $tangentScale2; $cmd = $cmd + ","; $cmd = $cmd + $curvatureScale1; $cmd = $cmd + ","; $cmd = $cmd + $curvatureScale2; $cmd = $cmd + ")"; return $cmd; } // // Procedure Name: // performAlign // // Description: // Perform the align 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 align 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: // The align command string. // global proc string performAlign( int $action, string $objectType, 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: alignOptions( $objectType, $inTheTool, $goToTool ); break; case 2: default: setOptionVars(false); $cmd = `assembleCmd`; break; } return $cmd; }