// =========================================================================== // 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: August 14, 1996 // // Description: // This is a helper script to perfrom the cutKey command // using the various options that have been set // // Input Arguments: // int action 0 - just execute the command // 1 - show the option box dialog // 2 - return the drag command // // Return Value: // None. // proc setOptionVars (int $forceFactorySettings) { keySetOptionBoxCommon( { "cutKey", "unknown", "setOptionVars", $forceFactorySettings } ); // -options // if ($forceFactorySettings || !`optionVar -exists cutKeyOption`) { optionVar -stringValue cutKeyOption "keys"; } // help images // if ($forceFactorySettings || !`optionVar -exists cutKeyHelpPictures`) { optionVar -intValue cutKeyHelpPictures 0; } } global proc cutKeySetup (string $parent, string $selectionConnection, int $forceFactorySettings) { // Retrieve the option settings // setOptionVars( $forceFactorySettings ); setParent $parent; keySetOptionBoxCommon( { "cutKey", $selectionConnection, "setup" } ); // -option // string $option = `optionVar -query cutKeyOption`; int $attach = 1; int $connect = 0; if (substring ($option, 1, 4) == "keys") { radioButtonGrp -edit -select 1 method; } else { radioButtonGrp -edit -select 2 method; if ($option == "curveCollapse") { $attach = 2; } else if ($option == "curveConnect") { $attach = 2; $connect = 1; } } radioButtonGrp -edit -select $attach adjustment; checkBoxGrp -e -value1 $connect connect; // help images // int $pictures = `optionVar -q cutKeyHelpPictures`; checkBoxGrp -e -value1 $pictures helpPictures; // Now get all the dependent widgets in the right // enabled/disabled/collapsed/expanded state // cutKeyWidgetsEnable ($selectionConnection); } global proc cutKeyCallback( string $parent, int $doIt, string $selectionConnection, int $fromGraphEditor, int $performAction ) { setParent $parent; keySetOptionBoxCommon( { "cutKey", $selectionConnection, "callback" } ); // -option // string $option; if (`radioButtonGrp -query -select method` == 1) { $option = "keys"; } else if (`radioButtonGrp -query -select method` == 2 ) { $option = "curve"; } else { $option = "area"; } if (`radioButtonGrp -query -select adjustment` == 2) { if( `checkBoxGrp -query -value1 connect` ) { $option = $option + "Connect"; } else { $option = $option + "Collapse"; } } optionVar -stringValue cutKeyOption $option; // help // int $pictures = `checkBoxGrp -query -value1 helpPictures`; optionVar -intValue cutKeyHelpPictures $pictures; if( $doIt ) { performCutKeyArgList 1 { (string) $performAction, $selectionConnection, (string) $fromGraphEditor }; string $tmpCmd = "performCutKeyArgList 1 {\""; $tmpCmd += $performAction + "\", \""; $tmpCmd += $selectionConnection + "\", \""; $tmpCmd += $fromGraphEditor + "\"}"; addToRecentCommandQueue $tmpCmd "Cut Key"; } } global proc cutKeyHelpPictures () { int $doPictures = (`checkBoxGrp -q -value1 helpPictures` && `checkBoxGrp -q -enable helpPictures`); if( $doPictures == 0 ) { frameLayout -e -collapse yes methodPictureFrame; frameLayout -e -collapse yes adjustmentPictureFrame; return; } int $method = `radioButtonGrp -q -select method`; int $adjustment = `radioButtonGrp -q -select adjustment`; string $adjustmentPicture = "CCP"; string $methodPicture; if( $method == 1 ) { $adjustmentPicture = $adjustmentPicture + "cutKeys"; $methodPicture = "CCPkeyframesOnly.png"; } else if( $method == 2 ) { $adjustmentPicture = $adjustmentPicture + "cutCurve"; $methodPicture = "CCPcurveExact.png"; } else { $adjustmentPicture = $adjustmentPicture + "cutRegion"; $methodPicture = "CCPregionExact.png"; } if( $adjustment == 2 ) { if( `checkBoxGrp -q -value1 connect` ) { $adjustmentPicture = $adjustmentPicture + "Connect.png"; } else { $adjustmentPicture = $adjustmentPicture + "Collapse.png"; } } else { $adjustmentPicture = $adjustmentPicture + ".png"; } picture -e -image (languageResourcePath( $methodPicture)) methodPicture; picture -e -image (languageResourcePath( $adjustmentPicture)) adjustmentPicture; frameLayout -e -collapse no methodPictureFrame; frameLayout -e -collapse no adjustmentPictureFrame; } global proc cutKeyDoSelectionChanged (string $selectionConnection) // // Description: // Since timeRange is irrelevant when there are // picked keyframes, collapse the timeRange // when there are. (This is hooked in to a SelectionChanged // trigger.) // { keySetOptionBoxCommon( { "cutKey", $selectionConnection, "selectionChanged" } ); if (match ("dopeSheet", $selectionConnection) != "") { string $currentPanel = `getPanel -withFocus`; string $dopeSheet = $currentPanel + "DopeSheetEd"; float $region[] = `dopeSheetEditor -q -sel $dopeSheet`; if ($region[0] < $region[1] && $region[2] < $region[3] ) { floatFieldGrp -edit -value1 $region[0] frameStart; floatFieldGrp -edit -value1 $region[1] frameEnd; keySetOptionBoxCommon( { "cutKey", $selectionConnection, "callback" } ); } } else { if( `keyframe -q -sl -kc` > 0) { radioButtonGrp -e -enable2 false -select 1 method; radioButtonGrp -e -enable2 false -select 1 adjustment; } else if( `radioButtonGrp -q -enable method` ) { radioButtonGrp -e -enable2 true method; } } } global proc cutKeyWidgetsEnable (string $selectionConnection) // // Description: // These are the widgets that get enabled and // disabled based on the certain states. Put them // here so they're all in one place. // { keySetOptionBoxCommon( { "cutKey", $selectionConnection, "enable" } ); // Options frame // int $enableIt = ( `radioButtonGrp -q -select timeRange` != 1 ); frameLayout -e -enable $enableIt optionsFrame; // Collapse adjustment // if( `radioButtonGrp -q -select method` != 2 && `radioButtonGrp -q -enable method` ) { if (`radioButtonGrp -q -select method` == 3) { radioButtonGrp -e -select 2 adjustment; radioButtonGrp -e -enable1 false adjustment; radioButtonGrp -e -enable2 true adjustment; } else { radioButtonGrp -e -select 1 adjustment; radioButtonGrp -e -enable1 true adjustment; radioButtonGrp -e -enable2 false adjustment; } } else if( `radioButtonGrp -q -enable method` ) { radioButtonGrp -e -enable2 true adjustment; radioButtonGrp -e -enable1 true adjustment; } else { radioButtonGrp -e -enable1 false adjustment; radioButtonGrp -e -enable2 false adjustment; } // Connect Check box // $enableIt = (( `radioButtonGrp -q -select adjustment` == 2 ) && ( `radioButtonGrp -q -enable2 adjustment` )); checkBoxGrp -e -enable $enableIt connect; cutKeyHelpPictures; } proc string cutKeyWidgets( string $tabLayout, string $selectionConnection, int $fromGraphEditor ) { global int $gOptionBoxTextColumnWidthIndex; setParent $tabLayout; string $tabForm = `columnLayout -adjustableColumn true`; keySetOptionBoxCommon( { "cutKey", $selectionConnection, "widgets", $fromGraphEditor } ); frameLayout -bv no -lv no -collapsable no optionsFrame; columnLayout -adjustableColumn true; checkBoxGrp -label (uiRes("m_performCutKeyArgList.kHelpImages")) -ncb 1 -value1 off -label1 "" -cc1 "cutKeyHelpPictures;" helpPictures; radioButtonGrp -numberOfRadioButtons 3 -label (uiRes("m_performCutKeyArgList.kMethod")) -label1 (uiRes("m_performCutKeyArgList.kKeys")) -cc1 ("cutKeyWidgetsEnable " + $selectionConnection) -label2 (uiRes("m_performCutKeyArgList.kSegments")) -cc2 ("cutKeyWidgetsEnable " + $selectionConnection) -label3 (uiRes("m_performCutKeyArgList.kRange")) -cc3 ("cutKeyWidgetsEnable " + $selectionConnection) method; frameLayout -bv no -lv no -collapsable yes -collapse yes methodPictureFrame; columnLayout -columnAttach "left" $gOptionBoxTextColumnWidthIndex; picture methodPicture; setParent ..; setParent ..; radioButtonGrp -numberOfRadioButtons 2 -label (uiRes("m_performCutKeyArgList.kAdjustment")) -label1 (uiRes("m_performCutKeyArgList.kNone")) -cc1 ("cutKeyWidgetsEnable " + $selectionConnection) -label2 (uiRes("m_performCutKeyArgList.kCollapse")) -cc2 ("cutKeyWidgetsEnable " + $selectionConnection) adjustment; checkBoxGrp -label (uiRes("m_performCutKeyArgList.kConnect")) -ncb 1 -label1 "" -value1 off -cc1 "cutKeyHelpPictures;" connect; frameLayout -bv no -lv no -collapsable yes -collapse yes adjustmentPictureFrame; columnLayout -columnAttach "left" $gOptionBoxTextColumnWidthIndex; picture adjustmentPicture; setParent ..; setParent ..; setParent ..; setParent ..; return $tabForm; } proc cutKeyOptions ( string $selectionConnection, int $performAction, int $fromGraphEditor ) { // Customisation options // // Name of the command for this option box (think of it as the base class) string $commandName = "cutKey"; // Title for the option box window string $optionBoxTitle = (uiRes("m_performCutKeyArgList.kCutKeysOptions")); // Title for the apply button string $applyTitle = (uiRes("m_performCutKeyArgList.kCutKeys")); // Build the option box "methods" // string $callback = ($commandName + "Callback"); string $setup = ($commandName + "Setup"); // Build the window, with a tab layout // string $widgetList[] = `getStandardWindow $optionBoxTitle 0 "noOptions"`; setUITemplate -pushTemplate DefaultTemplate; // Make the form invisible while we create the widgets in the window // formLayout -e -vis false $widgetList[1]; // Attach the widgets. No tab layout needed. // cutKeyWidgets $widgetList[2] $selectionConnection $fromGraphEditor; // Attach the standard buttons // string $buttonList[] = `addStandardButtons $commandName $applyTitle $widgetList[1] $widgetList[2] "noOptions"`; // attach commands to the standard buttons // // Save // button -e -c ($callback + " " + $widgetList[0] + " false \"\" " + $fromGraphEditor + " " + $performAction + "; hideOptionBox()") $buttonList[3]; // Close // button -edit -command hideOptionBox $buttonList[2]; // Reset // button -edit -command ($setup + " " + $widgetList[2] + " " + $selectionConnection + " true") $buttonList[1]; // Do It // button -edit -command ($callback + " " + $widgetList[0] + " true \"" + $selectionConnection + "\"" + $fromGraphEditor + " " + $performAction) $buttonList[0]; // Make the form layout visible so we can see what we built, and // reset the template // formLayout -e -vis true $widgetList[1]; setUITemplate -popTemplate; // Customize the 'Help' menu item text. // This is called from 3 different places so look at the selection // connection to try to figure out which one. // if (match ("graphEditor", $selectionConnection) != "") { setOptionBoxHelpTag( "GraphCut" ); } else if (match ("dopeSheet", $selectionConnection) != "") { setOptionBoxHelpTag( "DopeCut" ); } else { setOptionBoxHelpTag( "KeysCutKeys" ); } // Call the setup "method" to fill in the current settings // eval (($setup + " " + $widgetList[2] + " " + $selectionConnection + " false")); showOptionBox(); showWindow $widgetList[0]; if( $fromGraphEditor ) { cutKeyDoSelectionChanged($selectionConnection); scriptJob -protected -event "SelectionChanged" ("cutKeyDoSelectionChanged " + $selectionConnection + "; cutKeyWidgetsEnable " + $selectionConnection + ";") -parent $widgetList[2]; } } proc string assembleCmd( string $selectionConnection, int $fromGraphEditor, string $options ) { // doCutKeyArgList takes a string array. // string $cmd = "doCutKeyArgList 3 { " + "\"" + `optionVar -q cutKeyWhichRange` + "\"" + ",\"" + `optionVar -q cutKeyRange` + "\"" + ",\"" + `optionVar -q cutKeyOption` + "\"" + ",\"" + `optionVar -q cutKeyHierarchy` + "\"" + ",\"" + `optionVar -q cutKeyControlPoints` + "\"" + ",\"" + `optionVar -q cutKeyShapes` + "\"" + ",\"" + `optionVar -q cutKeyUseChannelBox` + "\"" + ",\"" + $selectionConnection + "\"" + ",\"" + $options + "\"" + ",\"" + $fromGraphEditor + "\"" + ",\"" + `optionVar -q cutKeyDriven`+ "\"" + " };"; return $cmd; } global proc string performCutKeyArgList (string $version, string $args[]) // // Input Arguments: // $version: The version of this option box. Used to know how to // interpret the $args array. // "1" : $action, $selectionConnection, $fromGraphEditor // // $args // Version 1 // [0] $action 0 - do the command // 1 - show the option box // 2 - return the drag command // 3 - do the command (bufferCurve version) // 4 - show the option box (bufferCurve version) // 5 - return the drag command (bufferCurve version) // [1] $selectionConnection name of selection connection to use // unless $options has "bufferCurve" in which // case this is the name of the editor // [2] $fromGraphEditor true if being called from the graph editor // // Return Value: // The actual command to execute. // { int $versionNum = $version; int $action = $args[0]; string $selectionConnection = $args[1]; int $fromGraphEditor = $args[2]; string $cmd = ""; switch( $action ) { case 0: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "noOptions" ); eval( $cmd ); break; case 1: cutKeyOptions( $selectionConnection, 0, $fromGraphEditor ); break; case 2: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "noOptions" ); break; case 3: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "bufferCurve" ); eval( $cmd ); break; case 4: cutKeyOptions( $selectionConnection, 3, $fromGraphEditor ); break; case 5: setOptionVars( false ); $cmd = assembleCmd( $selectionConnection, $fromGraphEditor, "bufferCurve" ); break; } return ($cmd); }