// =========================================================================== // 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: January 3, 1997 // // Description: // This script is use to display and update the grid spacing options. // // Input Arguments: // int showOptionBox true - show the option box dialog // false - just execute the command // // Return Value: // None. // // // 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) { // grid spacing // if ($forceFactorySettings || !`optionVar -exists gridSpacing`) { global float $gGridSpacingDefault; optionVar -fv gridSpacing $gGridSpacingDefault; } // grid divisions // if ($forceFactorySettings || !`optionVar -exists gridDivisions`) { global float $gGridDivisionsDefault; optionVar -fv gridDivisions $gGridDivisionsDefault; } // grid size // if ($forceFactorySettings || !`optionVar -exists gridSize`) { global float $gGridSizeDefault; optionVar -fv gridSize $gGridSizeDefault; } // Display grid axes. // if ($forceFactorySettings || !`optionVar -exists displayGridAxes`) { global int $gGridDisplayAxesDefault; optionVar -intValue displayGridAxes $gGridDisplayAxesDefault; } // Display grid lines. // if ($forceFactorySettings || !`optionVar -exists displayGridLines`) { global int $gGridDisplayGridLinesDefault; optionVar -intValue displayGridLines $gGridDisplayGridLinesDefault; } // Display division lines. // if ($forceFactorySettings || !`optionVar -exists displayDivisionLines`) { global int $gGridDisplayDivisionLinesDefault; optionVar -intValue displayDivisionLines $gGridDisplayDivisionLinesDefault; } // Display grid labels. // if ($forceFactorySettings || !`optionVar -exists displayGridPerspLabels`) { global int $gGridDisplayGridPerspLabelsDefault; optionVar -intValue displayGridPerspLabels $gGridDisplayGridPerspLabelsDefault; } if ($forceFactorySettings || !`optionVar -exists displayGridOrthoLabels`) { global int $gGridDisplayGridOrthoLabelsDefault; optionVar -intValue displayGridOrthoLabels $gGridDisplayGridOrthoLabelsDefault; } // Display axes accented. // if ($forceFactorySettings || !`optionVar -exists displayGridAxesAccented`) { global int $gGridDisplayAxesAccentedDefault; optionVar -intValue displayGridAxesAccented $gGridDisplayAxesAccentedDefault; } // Display location of labels. // if ($forceFactorySettings || !`optionVar -exists displayGridPerspLabelPosition`) { global string $gGridDisplayPerspLabelPositionDefault; optionVar -stringValue displayGridPerspLabelPosition $gGridDisplayPerspLabelPositionDefault; } if ($forceFactorySettings || !`optionVar -exists displayGridOrthoLabelPosition`) { global string $gGridDisplayOrthoLabelPositionDefault; optionVar -stringValue displayGridOrthoLabelPosition $gGridDisplayOrthoLabelPositionDefault; } } // // Procedure Name: // gridSetup // // 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 gridSetup(string $parent, int $forceFactorySettings) { setParent $parent; setOptionVars($forceFactorySettings); // Get the grid dimension values. // float $spacing = `optionVar -query gridSpacing`; float $size = `optionVar -query gridSize`; int $divisions = `optionVar -query gridDivisions`; // Get the grid color values. // int $axesColor = `displayColor -query "gridAxis"` + 1; int $gridLineColor = `displayColor -query "gridHighlight"` + 1; int $divisionLineColor = `displayColor -query "grid"` + 1; // Get the grid display values. // int $displayAxes = `optionVar -query displayGridAxes`; int $displayAxesAccented = `optionVar -query displayGridAxesAccented`; int $displayGridLines = `optionVar -query displayGridLines`; int $displayDivisionLines = `optionVar -query displayDivisionLines`; int $displayGridPerspLabels = `optionVar -query displayGridPerspLabels`; int $displayGridOrthoLabels = `optionVar -query displayGridOrthoLabels`; string $perspLabelPosition = `optionVar -query displayGridPerspLabelPosition`; string $orthoLabelPosition = `optionVar -query displayGridOrthoLabelPosition`; int $perspLocation, $orthoLocation; // Update the grid controls. // floatFieldGrp -edit -value1 $size GridOptionsSize; floatFieldGrp -edit -value1 $spacing GridOptionsDistance; intSliderGrp -edit -value $divisions GridOptionsDivisions; // Update the grid color controls. // colorIndexSliderGrp -edit -value $axesColor GridOptionsAxesColor; colorIndexSliderGrp -edit -value $gridLineColor GridOptionsGridLineColor; colorIndexSliderGrp -edit -value $divisionLineColor GridOptionsDivisionLineColor; // Update the state of the display controls. // checkBoxGrp -edit -value1 $displayAxes GridOptionsDisplayAxes; checkBoxGrp -edit -value1 $displayAxesAccented GridOptionsDisplayAxesAccented; checkBoxGrp -edit -value1 $displayGridLines GridOptionsDisplayGridLines; checkBoxGrp -edit -value1 $displayDivisionLines GridOptionsDisplayDivisionLines; if ($displayGridPerspLabels) { if ("axis" == $perspLabelPosition) { $perspLocation = 2; } else { $perspLocation = 3; } } else { $perspLocation = 1; } radioButtonGrp -edit -select $perspLocation GridOptionsPerspLabelPosition; if ($displayGridOrthoLabels) { if ("axis" == $orthoLabelPosition) { $orthoLocation = 2; } else { $orthoLocation = 3; } } else { $orthoLocation = 1; } radioButtonGrp -edit -select $orthoLocation GridOptionsOrthoLabelPosition; } // // Procedure Name: // gridCallback // // 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 gridCallback(string $parent, int $doIt) { // Get the grid values from the UI. // float $size = `floatFieldGrp -query -value1 GridOptionsSize`; float $spacing = `floatFieldGrp -query -value1 GridOptionsDistance`; int $divisions = `intSliderGrp -query -value GridOptionsDivisions`; // Get the grid color values from the UI. // int $axesColor = `colorIndexSliderGrp -query -value GridOptionsAxesColor`; int $gridLineColor = `colorIndexSliderGrp -query -value GridOptionsGridLineColor`; int $divisionLineColor = `colorIndexSliderGrp -query -value GridOptionsDivisionLineColor`; // Get the grid display values. // int $displayAxes = `checkBoxGrp -query -value1 GridOptionsDisplayAxes`; int $displayAxesAccented = `checkBoxGrp -query -value1 GridOptionsDisplayAxesAccented`; int $displayGridLines = `checkBoxGrp -query -value1 GridOptionsDisplayGridLines`; int $displayDivisionLines = `checkBoxGrp -query -value1 GridOptionsDisplayDivisionLines`; int $perspLabelPosition = `radioButtonGrp -query -select GridOptionsPerspLabelPosition`; int $orthoLabelPosition = `radioButtonGrp -query -select GridOptionsOrthoLabelPosition`; // Verify the values. // if (1.0 > $size) { error (uiRes("m_performGridOptions.kErrorLength")); return; } if (0.0 >= $spacing) { error (uiRes("m_performGridOptions.kErrorSpacing")); return; } // Update the grid values. // optionVar -floatValue gridSpacing $spacing; optionVar -floatValue gridSize $size; optionVar -floatValue gridDivisions $divisions; // Update the grid color values. // displayColor -dormant "gridAxis" ($axesColor - 1); displayColor -dormant "gridHighlight" ($gridLineColor - 1); displayColor -dormant "grid" ($divisionLineColor - 1); // Update the grid display values. // optionVar -intValue displayGridAxes $displayAxes; optionVar -intValue displayGridAxesAccented $displayAxesAccented; optionVar -intValue displayGridLines $displayGridLines; optionVar -intValue displayDivisionLines $displayDivisionLines; if (1 == $perspLabelPosition) { optionVar -intValue displayGridPerspLabels false; } else if (2 == $perspLabelPosition) { optionVar -stringValue displayGridPerspLabelPosition "axis"; optionVar -intValue displayGridPerspLabels true; } else { optionVar -stringValue displayGridPerspLabelPosition "edge"; optionVar -intValue displayGridPerspLabels true; } if (1 == $orthoLabelPosition) { optionVar -intValue displayGridOrthoLabels false; } else if (2 == $orthoLabelPosition) { optionVar -stringValue displayGridOrthoLabelPosition "axis"; optionVar -intValue displayGridOrthoLabels true; } else { optionVar -stringValue displayGridOrthoLabelPosition "edge"; optionVar -intValue displayGridOrthoLabels true; } if ($doIt) { performGridOptions 0; addToRecentCommandQueue "performGridOptions 0" "GridOptions"; // Bug #148950. // // If the grid is not visible then make it visible as a // convenience to the user. Otherwise, they'd have to go // back to the grid menu item and select it to see their // option box changes. // if (!`grid -query -toggle`) ToggleGrid; } savePrefs -g; } // // Procedure Name: // gridOptions // // Description: // Construct the option box UI. Involves accessing the standard option // box and customizing the UI accordingly. // // Input Arguments: // None. // // Return Value: // None. // proc gridOptions() { // Name of the command for this option box. // string $commandName = "grid"; // 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. // ================================================= // // Any default option box behaviour based on the command name is set // up with this call. For example, updating the 'Help' menu item with // the name of the command. // setOptionBoxCommandName($commandName); // 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; tabLayout -tabsVisible 0 -scrollable 1 -innerMarginWidth 4; string $parent = `columnLayout -adjustableColumn 1 -rowSpacing 4`; // Grid size. // frameLayout -label (uiRes("m_performGridOptions.kSize")) -collapsable false -collapse false; columnLayout; string $units = (uiRes("m_performGridOptions.kUnits")); $gridSize = `floatFieldGrp -label (uiRes("m_performGridOptions.kLength")) -extraLabel $units GridOptionsSize`; $gridDistance = `floatFieldGrp -label (uiRes("m_performGridOptions.kGridLinesEvery")) -extraLabel $units GridOptionsDistance`; $divisions = `intSliderGrp -label (uiRes("m_performGridOptions.kSubdivisions")) -field true -min 1 -max 20 -fieldMinValue 1 -fieldMaxValue 100 -step 1 GridOptionsDivisions`; setParent ..; setParent ..; // Grid colors. // Note: Do not change the name of these controls without also // changing colorPrefWnd.mel // frameLayout -label (uiRes("m_performGridOptions.kColor")) -collapsable false -collapse false; columnLayout; $color = `displayColor -query "gridAxis"` + 1; $axesColor = `colorIndexSliderGrp -label (uiRes("m_performGridOptions.kColorAxes")) -extraLabel "" -min 2 -max 24 -value 2 GridOptionsAxesColor`; $color = `displayColor -query "gridHighlight"` + 1; $gridColor = `colorIndexSliderGrp -label (uiRes("m_performGridOptions.kGridLines")) -extraLabel "" -min 2 -max 24 -value 2 GridOptionsGridLineColor`; $color = `displayColor -query "grid"` + 1; $divisionColor = `colorIndexSliderGrp -label (uiRes("m_performGridOptions.kColorSubdivision")) -extraLabel "" -min 2 -max 24 -value 2 GridOptionsDivisionLineColor`; setParent ..; setParent ..; frameLayout -label (uiRes("m_performGridOptions.kDisplay")) -collapsable false -collapse false; columnLayout; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performGridOptions.kDisplayAxes")) GridOptionsDisplayAxes; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performGridOptions.kDisplayThickerLine")) GridOptionsDisplayAxesAccented; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performGridOptions.kDisplayGrid")) GridOptionsDisplayGridLines; checkBoxGrp -numberOfCheckBoxes 1 -label "" -label1 (uiRes("m_performGridOptions.kDisplaySubdivision")) GridOptionsDisplayDivisionLines; string $hide = (uiRes("m_performGridOptions.kHide")); string $onAxes = (uiRes("m_performGridOptions.kOnAxes")); string $alongEdge = (uiRes("m_performGridOptions.kAlongEdge")); radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performGridOptions.kPerspectiveGrid")) -labelArray3 $hide $onAxes $alongEdge GridOptionsPerspLabelPosition; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performGridOptions.kOrthographicGrid")) -labelArray3 $hide $onAxes $alongEdge GridOptionsOrthoLabelPosition; setParent ..; setParent ..; // 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 -command ($callback + " " + $parent + " " + 1) $applyBtn; // 'Save' button. // string $saveBtn = getOptionBoxSaveBtn(); button -edit -command ($callback + " " + $parent + " " + 1 + "; hideOptionBox") $saveBtn; // 'Reset' button. // string $resetBtn = getOptionBoxResetBtn(); button -edit -command ($setup + " " + $parent + " " + 1) $resetBtn; // Step 7: Set the option box title. // ================================= // string $optionBoxTitle = (uiRes("m_performGridOptions.kGridOptions")); setOptionBoxTitle($optionBoxTitle); // Step 8: Customize the 'Help' menu item text. // ============================================ // setOptionBoxHelpTag( "GridOptions" ); // Step 9: Set the current values of the option box. // ================================================= // eval (($setup + " " + $parent + " " + 0)); // Step 10: Show the option box. // ============================= // showOptionBox(); scriptJob -p $parent -e "linearUnitChanged" ("updateUnitsForGridOptions " + $layout); } // // Procedure Name: // assembleCmd // // Description: // Construct the command that will apply the option box values. // // Input Arguments: // None. // proc string assembleCmd() { string $cmd; setOptionVars(false); float $spacing = `optionVar -query gridSpacing`; int $divisions = `optionVar -query gridDivisions`; float $size = `optionVar -query gridSize`; int $displayAxes = `optionVar -query displayGridAxes`; int $displayAxesAccented = `optionVar -query displayGridAxesAccented`; int $displayGridLines = `optionVar -query displayGridLines`; int $displayDivisionLines = `optionVar -query displayDivisionLines`; int $displayGridPerspLabels = `optionVar -query displayGridPerspLabels`; int $displayGridOrthoLabels = `optionVar -query displayGridOrthoLabels`; string $perspLabelPosition = `optionVar -query displayGridPerspLabelPosition`; string $orthoLabelPosition = `optionVar -query displayGridOrthoLabelPosition`; int $axesColor = `colorIndexSliderGrp -query -value GridOptionsAxesColor`; int $gridLineColor = `colorIndexSliderGrp -query -value GridOptionsGridLineColor`; int $divisionLineColor = `colorIndexSliderGrp -query -value GridOptionsDivisionLineColor`; $cmd = "grid -spacing " + $spacing + " -divisions " + $divisions + " -size " + $size + " -displayAxes " + $displayAxes + " -displayGridLines " + $displayGridLines + " -displayDivisionLines " + $displayDivisionLines + " -displayPerspectiveLabels " + $displayGridPerspLabels + " -displayOrthographicLabels " + $displayGridOrthoLabels + " -displayAxesBold " + $displayAxesAccented + " -perspectiveLabelPosition " + $perspLabelPosition + " -orthographicLabelPosition " + $orthoLabelPosition + "; " + "displayColor -dormant \"gridAxis\" " + ($axesColor - 1) + "; " + "displayColor -dormant \"gridHighlight\" " + ($gridLineColor - 1) + "; " + "displayColor -dormant \"grid\" " + ($divisionLineColor - 1) + "; " ; return $cmd; } // // Procedure Name: // performGridOptions // // Description: // Perform the grid 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 grid 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 performGridOptions(int $action) { string $cmd = ""; switch ($action) { // Execute the command. // case 0: // Get the command. // $cmd = `assembleCmd`; // Execute the command with the option settings. // eval($cmd); break; // Show the option box. // case 1: gridOptions; break; // Return the command string. // case 2: // Get the command. // $cmd = `assembleCmd`; break; } return $cmd; } global proc updateUnitsForGridOptions(string $windowName) { // Check if the option box is up and if it's displaying Grid Options. // The window title is set to "CentraOptionBox" in getStandardWindow.mel // if (`window -exists $windowName`) { string $windowTitle = `window -q -title $windowName`; if ($windowTitle == (uiRes("m_performGridOptions.kGridOptions"))) { string $newUnit = `currentUnit -query -label`; floatFieldGrp -edit -extraLabel $newUnit GridOptionsSize; floatFieldGrp -edit -extraLabel $newUnit GridOptionsDistance; } } }