// =========================================================================== // 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: 27 Aug 1999 // // Description: // Performs freeze transformations on objects. // // // 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) { // Add optionVar to store what's being frozen - translate, rotate, scale, // or jointOrient // if ($forceFactorySettings || !`optionVar -exists freezeTransformationsTranslate`){ optionVar -intValue freezeTransformationsTranslate 1; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsRotate`){ optionVar -intValue freezeTransformationsRotate 1; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsScale`){ optionVar -intValue freezeTransformationsScale 1; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsJointOrient`){ optionVar -intValue freezeTransformationsJointOrient 0; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsNormal`){ optionVar -intValue freezeTransformationsNormal 0; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsWhen`){ optionVar -intValue freezeTransformationsWhen 1; } if ($forceFactorySettings || !`optionVar -exists freezeTransformationsPreserveNormals`){ optionVar -intValue freezeTransformationsPreserveNormals 1; } } // // Procedure Name: // performFreezeTransformationsSetup // // 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 performFreezeTransformationsSetup(string $parent, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars ($forceFactorySettings); setParent $parent; // Radio button to select what gets moved // int $trans = `optionVar -q freezeTransformationsTranslate`; int $rotate = `optionVar -q freezeTransformationsRotate`; int $scale = `optionVar -q freezeTransformationsScale`; int $jointOrient = `optionVar -q freezeTransformationsJointOrient`; int $normal = `optionVar -q freezeTransformationsNormal`; int $when = `optionVar -q freezeTransformationsWhen`; int $preserveNormals = `optionVar -q freezeTransformationsPreserveNormals`; checkBoxGrp -e -v1 $trans freezeCheckBoxGrp; checkBoxGrp -e -v2 $rotate freezeCheckBoxGrp; checkBoxGrp -e -v3 $scale freezeCheckBoxGrp; checkBoxGrp -e -v4 $jointOrient freezeCheckBoxGrp; if ($normal == 0) { optionMenuGrp -e -sl 1 freezeOptionMenuGrpLockNormals; } else { optionMenuGrp -e -sl ($when+2) freezeOptionMenuGrpLockNormals; } checkBoxGrp -e -v1 $preserveNormals freezeCheckBoxGrpPreserveNormals; } // // Procedure Name: // performFreezeTransformationsCallback // // 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 performFreezeTransformationsCallback(string $parent, int $doIt) { setParent $parent; // Set the optionVar's from the control values, and then perform command // int $i = `checkBoxGrp -q -v1 freezeCheckBoxGrp`; optionVar -intValue freezeTransformationsTranslate $i; $i = `checkBoxGrp -q -v2 freezeCheckBoxGrp`; optionVar -intValue freezeTransformationsRotate $i; $i = `checkBoxGrp -q -v3 freezeCheckBoxGrp`; optionVar -intValue freezeTransformationsScale $i; $i = `checkBoxGrp -q -v4 freezeCheckBoxGrp`; optionVar -intValue freezeTransformationsJointOrient $i; $i = `optionMenuGrp -q -sl freezeOptionMenuGrpLockNormals`; optionVar -intValue freezeTransformationsNormal ($i > 1); optionVar -intValue freezeTransformationsWhen ($i == 3); $i = `checkBoxGrp -q -v1 freezeCheckBoxGrpPreserveNormals`; optionVar -intValue freezeTransformationsPreserveNormals $i; if ($doIt) { performFreezeTransformations 0; addToRecentCommandQueue "performFreezeTransformations 0" "FreezeTransformations"; } } // // Procedure Name: // performFreezeTransformationsOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc performFreezeTransformationsOptions() { // Name of the command for this option box. // string $commandName = "performFreezeTransformations"; // 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 - see STEP 8. // ============================================================== // 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; // STEP 4: Create option box contents. // =================================== // // This, of course, will vary from option box to option box. // Turn on the wait cursor. // waitCursor -state 1; // RECOMMENDATION: Place the UI in a 'scrollable' layout. A // scrollable layout ensures that if the option box window is ever // resized such that it's entire contents is not visible then the // scroll bars provided by the scrollable layout will allow the user // to access the hidden UI. Two layouts currently supporting // scrollable behaviour are the 'scrollLayout' and the 'tabLayout'. // // scrollLayout; // // or... // tabLayout -tabsVisible 0 -scrollable 1; string $parent = `columnLayout -adjustableColumn 1`; // RECOMMENDATION: Use the 'Grp' commands where possible because // they obey the formatting specified in the default template. // This will result in a more consistent look throughout the // application. // checkBoxGrp -label (uiRes("m_performFreezeTransformations.kFreeze")) -ncb 4 -vertical -label1 (uiRes("m_performFreezeTransformations.kTranslate")) -label2 (uiRes("m_performFreezeTransformations.kRotate")) -label3 (uiRes("m_performFreezeTransformations.kScale")) -label4 (uiRes("m_performFreezeTransformations.kJointOrient")) freezeCheckBoxGrp; separator; optionMenuGrp -label (uiRes("m_performFreezeTransformations.kLockNormals")) freezeOptionMenuGrpLockNormals; menuItem -label (uiRes("m_performFreezeTransformations.kNever")); menuItem -label (uiRes("m_performFreezeTransformations.kAlways")); menuItem -label (uiRes("m_performFreezeTransformations.kNonRigidTransformationsOnly")); checkBoxGrp -label " " -ncb 1 -label1 (uiRes("m_performFreezeTransformations.kPreserveNormals")) freezeCheckBoxGrpPreserveNormals; // 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. This is not // necessary, but in some cases, for example, a button labelled // 'Create' may be more meaningful to the user than one labelled // 'Apply'. // // Disable those buttons that are not applicable to the option box. // // 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. // 'Apply' button. // string $applyBtn = getOptionBoxApplyBtn(); button -edit -label (uiRes("m_performFreezeTransformations.kFreezeTransform")) -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox") $saveBtn; // 'Freeze' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // setOptionBoxTitle (uiRes("m_performFreezeTransformations.kFreezeTransformationsOptions")); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "FreezeTransformations" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); } // // Procedure Name: // performParentHelp // // Description: // Return a short description about this command. // // Input Arguments: // None. // // Return Value: // string. // proc string performParentHelp() { return " Command: Freeze Transformations.\n" + " will freeze the select object's transformations to identity."; } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd = "makeIdentity"; setOptionVars(false); int $trans = `optionVar -q freezeTransformationsTranslate`; int $rotate = `optionVar -q freezeTransformationsRotate`; int $scale = `optionVar -q freezeTransformationsScale`; int $jointOrient = `optionVar -q freezeTransformationsJointOrient`; int $normal = `optionVar -q freezeTransformationsNormal`; if ($normal) { $normal += `optionVar -q freezeTransformationsWhen`; } // 0 - dont freeze Normals // 1 - freeze always // 2 - freeze only when there is a non rigid transformation int $preserveNormals = `optionVar -q freezeTransformationsPreserveNormals`; // Execute the command with the option settings // $cmd = $cmd+ " -apply true" + " -t "+$trans +" -r " + $rotate + " -s " + $scale + " -n " + $normal; $cmd = $cmd + " -pn " + $preserveNormals; if ($jointOrient) { $cmd += " -jointOrient"; } return $cmd; } // // Procedure Name: // performParent // // Description: // Perform the performParent 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 optionBoxExample1 command with the current // option box values. // // Input Arguments: // 0 - Execute the command. // 1 - Show the option box dialog. // 2 - Return the command. // global proc string performFreezeTransformations(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: performFreezeTransformationsOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; }