// =========================================================================== // 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. // =========================================================================== // Procedure Name: // assemblyEditsWindowPrint // Description: // Print the edit selected in the assemblyEditsWindow. // Called by the iconTextScrollList doubleClickCommand. // // Input Arguments: // string $textScrollList: name of the iconTextScrollList to check selection // // Return Value: // None. // global proc assemblyEditsWindowPrint(string $textScrollList){ string $edit[] = `iconTextScrollList -q -si $textScrollList`; print (uiRes("m_assemblyEditsWindow.kAssemblyEdit")); print $edit; } // FIXME: implemented this. global proc assemblyEditsWindowSelected(string $textScrollList) { } proc string getCurrentTabAssembly(string $tabLayout) { int $index = `tabLayout -query -selectTabIndex $tabLayout`; if($index > 0){ string $tabLabel[] = `tabLayout -query -tabLabel $tabLayout`; return $tabLabel[$index-1]; } return ""; } proc string getCurrentTabScrollList(string $tabLayout) { int $index = `tabLayout -query -selectTabIndex $tabLayout`; if($index > 0){ string $child[] = `tabLayout -query -childArray $tabLayout`; return ($tabLayout + "|" + $child[$index-1]); } return ""; } global proc assemblyEditsAddSelectedAssemblies(string $tabLayout) { // Add tabs for the selected assembly nodes. Filter to keep only // assembly nodes that support edit tracking. setParent $tabLayout; string $assemblies[] = `ls -selection -type assembly`; string $selections[]; int $i; for ($i=0; $i < size($assemblies); $i++) { int $supportsEdits = `python("getOpenMayaAssemblyFnSet('" +$assemblies[$i]+"').supportsEdits()")`; if ($supportsEdits) { $selections[size($selections)] = $assemblies[$i]; } } for( $node in $selections){ string $scrollList = `iconTextScrollList`; iconTextScrollList -edit -allowMultiSelection true -doubleClickCommand ("assemblyEditsWindowPrint " + $scrollList) -selectCommand ("assemblyEditsWindowSelected " + $scrollList) $scrollList; tabLayout -edit -tabLabel $scrollList $node $tabLayout; } } global proc assemblyEditsWindowAssemblyDeleted(string $window) { // Our assembly node is gone, remove the associated list edits window. deleteUI $window; } global proc assemblyEditsWindowRefreshCmd( string $tabLayout, string $filterWidget, string $listEditsOnSelectedAssemblyMenuItem, string $failedEditsMenuItem, string $unappliedEditsMenuItem, string $nonRemovableEditsMenuItem ) { string $assembly = getCurrentTabAssembly($tabLayout); string $textScrollList = getCurrentTabScrollList($tabLayout); // We keep the list edits window open even if an assembly node is // deleted, which can happen explicitly (because the user deletes a // top-level assembly node), or implicitly (because the user // inactivates a representation containing the assembly node). // Therefore, check for object existence first. if (!`objExists $assembly`) { iconTextScrollList -edit -removeAll $textScrollList; return; } assemblyEditsDisplayList($tabLayout, $filterWidget, $listEditsOnSelectedAssemblyMenuItem, $failedEditsMenuItem, $unappliedEditsMenuItem, $nonRemovableEditsMenuItem); } global proc assemblyEditsWindowRemoveSelectedEditsCmd( string $tabLayout, string $filterWidget, string $listEditsOnSelectedAssemblyMenuItem, string $failedEditsMenuItem, string $unappliedEditsMenuItem, string $nonRemovableEditsMenuItem ) { string $assembly = getCurrentTabAssembly($tabLayout); string $textScrollList = getCurrentTabScrollList($tabLayout); // We keep the list edits window open even if an assembly node is // deleted, which can happen explicitly (because the user deletes a // top-level assembly node), or implicitly (because the user // inactivates a representation containing the assembly node). // Therefore, check for object existence first. if (!`objExists $assembly`) { iconTextScrollList -edit -removeAll $textScrollList; return; } string $selectedItems[] = `iconTextScrollList -q -selectItem $textScrollList`; if(!size($selectedItems)) { return; } string $command = "editUtils.removeSelectedEdits(" + "\"" + $assembly + "\"" + ", " + "\"" + $textScrollList + "\"" + ", " + "\"" + $listEditsOnSelectedAssemblyMenuItem + "\"" + ")"; int $allRemovable = python($command); if(!$allRemovable) { warning (uiRes("m_assemblyEditsWindow.kErrorNonRemovableEdits")); } assemblyEditsDisplayList($tabLayout, $filterWidget, $listEditsOnSelectedAssemblyMenuItem, $failedEditsMenuItem, $unappliedEditsMenuItem, $nonRemovableEditsMenuItem); } // Procedure Name: // assemblyEditsDisplayList // // Description: // Adds edits to the Assembly Edits Window. Note the order of // of edits is important for processing the deletion of edits // so do not add filtering or sorting in the actual UI // // Input Arguments: // string $assembly: assembly node for which edits are listed. // string $textScrollList: name of the iconTextScrollList to add edits to // // Return Value: // None. // global proc assemblyEditsDisplayList( string $tabLayout, string $filterWidget, string $listEditsOnSelectedAssemblyMenuItem, string $failedEditsMenuItem, string $unappliedEditsMenuItem, string $nonRemovableEditsMenuItem ) { string $assembly = getCurrentTabAssembly($tabLayout); string $textScrollList = getCurrentTabScrollList($tabLayout); // Clear the whole list. iconTextScrollList -edit -removeAll $textScrollList; string $command = "\"" +$assembly + "\"" + ", " + "\"" + $textScrollList + "\"" + ", " + "\"" + $filterWidget + "\"" + ", " + "\"" + $failedEditsMenuItem + "\"" + ", " + "\"" + $unappliedEditsMenuItem + "\"" + ", " + "\"" + $nonRemovableEditsMenuItem + "\"" + ")"; int $onSelectedValue = `menuItem -q -radioButton $listEditsOnSelectedAssemblyMenuItem`; if ($onSelectedValue) { $command = "editUtils.displayEditsOn(" + $command; } else { $command = "editUtils.displayEditsThatAffect(" + $command; } python($command); } // Procedure Name: // assemblyEditsWindow // // Description: // Creates a window that lists edits for a specified assembly node. // // Input Arguments: // string $assembly: first assembly node for which edits should be listed. // // Return Value: // None. // global proc assemblyEditsWindow(string $assembly) { python("import maya.OpenMaya as OpenMaya\nimport maya.cmds as cmds"); python("import maya.app.general.editUtils as editUtils"); python( "def getOpenMayaAssemblyFnSet(assemblyNodeName):\n" + " assemblyNode = editUtils.makeDependNode(assemblyNodeName)\n" + " assemblyFn = OpenMaya.MFnAssembly(assemblyNode)\n" + " return assemblyFn" ); if ($assembly == "") { error((uiRes("m_assemblyEditsWindow.kMustSelectAssembly"))); } string $convertedAssembly = `substitute ":" $assembly "_"`; string $window = ("assemblyEditsWin_" + $convertedAssembly); if (`window -exists $window`) { deleteUI -window $window; } string $windowTitle = (uiRes("m_assemblyEditsWindow.kListAssemblyEditsTitle")); window -w 250 -h 580 -title $windowTitle $window; // Create optionVars // TODO MAYA-15150: support show NS and show dag path options if( !`optionVar -exists listEditsOnSelectedAssembly`) optionVar -iv "listEditsOnSelectedAssembly" 0; if( !`optionVar -exists assemblyShowFailedEdits`) optionVar -iv "assemblyShowFailedEdits" 1; if( !`optionVar -exists assemblyShowUnappliedEdits`) optionVar -iv "assemblyShowUnappliedEdits" 1; if( !`optionVar -exists assemblyShowNonRemovableEdits`) optionVar -iv "assemblyShowNonRemovableEdits" 1; // Create the mainForm string $mainForm = `formLayout -numberOfDivisions 100 ($window + "_formLayout")`; //Menubar string $menuBar = `menuBarLayout`; string $showMenu = `menu -label (uiRes("m_assemblyEditsWindow.kShowEdits")) -allowOptionBoxes true -tearOff true`; radioMenuItemCollection; string $listEditsOnSelectedAssemblyMenuItem = `menuItem -label (uiRes("m_assemblyEditsWindow.kListEditsOnSelectedAssembly")) -enableCommandRepeat false -radioButton true`; string $listEditsAffectingSelectedAssemblyMenuItem = `menuItem -label (uiRes("m_assemblyEditsWindow.kListEditsAffectingSelectedAssembly")) -enableCommandRepeat false -radioButton false`; menuItem -divider true; string $failedEditsMenuItem = `menuItem -label (uiRes("m_assemblyEditsWindow.kShowFailedEdits")) -enableCommandRepeat false -checkBox true`; string $unappliedEditsMenuItem = `menuItem -label (uiRes("m_assemblyEditsWindow.kShowUnappliedEdits")) -enableCommandRepeat false -checkBox true`; string $nonRemovableEditsMenuItem = `menuItem -label (uiRes("m_assemblyEditsWindow.kShowNonRemovableEdits")) -enableCommandRepeat false -checkBox true`; setParent $mainForm; string $tabs = `tabLayout -innerMarginWidth 5 -innerMarginHeight 5 -tabsClosable true`; assemblyEditsAddSelectedAssemblies($tabs); setParent $mainForm; string $filterWidget = `textFieldGrp -label (uiRes("m_assemblyEditsWindow.kFilter"))`; int $onSelectedOptionVar = `optionVar -q listEditsOnSelectedAssembly`; string $refreshEditsCmd = ("assemblyEditsDisplayList \"" + $tabs + "\" \"" + $filterWidget + "\" \"" + $listEditsOnSelectedAssemblyMenuItem + "\" \"" + $failedEditsMenuItem + "\" \"" + $unappliedEditsMenuItem + "\" \"" + $nonRemovableEditsMenuItem + "\";" ); textFieldGrp -edit -changeCommand ($refreshEditsCmd) $filterWidget; // Connect OptionVars with menuItems. menuItem -e -radioButton $onSelectedOptionVar -command ("{ optionVar -iv \"listEditsOnSelectedAssembly\" `menuItem -q -radioButton " + $listEditsOnSelectedAssemblyMenuItem + "`; " + $refreshEditsCmd + "}") $listEditsOnSelectedAssemblyMenuItem; menuItem -e -radioButton (!$onSelectedOptionVar) -command ("{ optionVar -iv \"listEditsOnSelectedAssembly\" `menuItem -q -radioButton " + $listEditsOnSelectedAssemblyMenuItem + "`; " + $refreshEditsCmd + "}") $listEditsAffectingSelectedAssemblyMenuItem; menuItem -e -checkBox `optionVar -q assemblyShowFailedEdits` -command ("{ optionVar -iv \"assemblyShowFailedEdits\" `menuItem -q -checkBox " + $failedEditsMenuItem + "`; " + $refreshEditsCmd + "}") $failedEditsMenuItem; menuItem -e -checkBox `optionVar -q assemblyShowUnappliedEdits` -command ("{ optionVar -iv \"assemblyShowUnappliedEdits\" `menuItem -q -checkBox " + $unappliedEditsMenuItem + "`; " + $refreshEditsCmd + "}") $unappliedEditsMenuItem; menuItem -e -checkBox `optionVar -q assemblyShowNonRemovableEdits` -command ("{ optionVar -iv \"assemblyShowNonRemovableEdits\" `menuItem -q -checkBox " + $nonRemovableEditsMenuItem + "`; " + $refreshEditsCmd + "}") $nonRemovableEditsMenuItem; // Populate scroll list with edits. // assemblyEditsDisplayList($tabs, $filterWidget, $listEditsOnSelectedAssemblyMenuItem, $failedEditsMenuItem, $unappliedEditsMenuItem, $nonRemovableEditsMenuItem); string $buttonForm = `formLayout -numberOfDivisions 99`; // The refresh button string $refreshButton = `button -label (uiRes("m_assemblyEditsWindow.kRefreshEdit"))`; string $windowRefreshCmd = ("assemblyEditsWindowRefreshCmd \"" + $tabs + "\" \"" + $filterWidget + "\" \"" + $listEditsOnSelectedAssemblyMenuItem + "\" \"" + $failedEditsMenuItem + "\" \"" + $unappliedEditsMenuItem + "\" \"" + $nonRemovableEditsMenuItem + "\";" ); button -edit -command ($windowRefreshCmd) $refreshButton; tabLayout -edit -selectCommand ($windowRefreshCmd) $tabs; string $addSelectedButton = `button -label (uiRes("m_assemblyEditsWindow.kAddSelectedAssemblies"))`; button -edit -command ("assemblyEditsAddSelectedAssemblies \"" + $tabs + "\"") $addSelectedButton; // The remove selected edits button string $removeSelectedEditsButton = `button -label (uiRes("m_assemblyEditsWindow.kRemoveSelectedEditsButton"))`; string $removeSelectedEditsCmd = ("assemblyEditsWindowRemoveSelectedEditsCmd \"" + $tabs + "\" \"" + $filterWidget + "\" \"" + $listEditsOnSelectedAssemblyMenuItem + "\" \"" + $failedEditsMenuItem + "\" \"" + $unappliedEditsMenuItem + "\" \"" + $nonRemovableEditsMenuItem + "\";" ); button -edit -command ($removeSelectedEditsCmd) $removeSelectedEditsButton; formLayout -edit -attachForm $refreshButton "top" 0 -attachForm $refreshButton "left" 0 -attachForm $refreshButton "bottom" 0 -attachPosition $refreshButton "right" 0 33 -attachControl $addSelectedButton "left" 0 $refreshButton -attachForm $addSelectedButton "top" 0 -attachForm $addSelectedButton "bottom" 0 -attachPosition $addSelectedButton "right" 0 66 -attachControl $removeSelectedEditsButton "left" 0 $addSelectedButton -attachForm $removeSelectedEditsButton "top" 0 -attachForm $removeSelectedEditsButton "right" 0 -attachForm $removeSelectedEditsButton "bottom" 0 $buttonForm; setParent $mainForm; formLayout -edit -attachForm $menuBar "top" 5 -attachForm $menuBar "left" 5 -attachForm $menuBar "right" 5 -attachControl $filterWidget "top" 5 $menuBar -attachForm $filterWidget "right" 5 -attachNone $filterWidget "bottom" -attachControl $tabs "top" 5 $filterWidget -attachForm $tabs "left" 5 -attachForm $tabs "bottom" 35 -attachForm $tabs "right" 5 -attachControl $buttonForm "top" 5 $tabs -attachForm $buttonForm "left" 5 -attachForm $buttonForm "bottom" 5 -attachForm $buttonForm "right" 5 $mainForm; showWindow $window; // Ensure window lifescope is bounded by scene lifescope. Don't // need script job return job number, as we won't be deleting it. scriptJob -runOnce true -parent $mainForm -e deleteAll ("assemblyEditsWindowAssemblyDeleted " + $window); }