// =========================================================================== // 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. // =========================================================================== global proc createMASHPresetsVisorTab (string $path) { VisorWindow; string $panel=visorPanelName(); string $tabLabel = "MASH Presets"; string $tabLayout = "firstPaneTabs"; string $tabType = "Disk"; string $newTab = ""; string $rootDirectory = $path; int $showFilesOnly = 0; $newTab = createDiskTab( $panel, $tabLayout, $tabLabel, $rootDirectory); string $libraryUI = lookupComponentName($newTab); if ($showFilesOnly) { libraryUIShowFilesOnly($libraryUI); } updateTabLayoutOptionVar($panel, $tabLayout); if ($newTab != "") { // Bring the new tab to the front // selectTab($panel, $newTab); } } ////////////////////////////////////////////// proc selectTab( string $panel, string $tab) { // // Description: // This procedure selects the specified tab, bringing it to the front of // its tab layout. // // Remember the current parent so we can revert to it when we're done here. // string $oldParent = `setParent -query`; string $oldMenuParent = `setParent -menu -query`; string $tabLayout = "firstPaneTabs"; string $tabPathTokens[]; tokenize($tab, "|", $tabPathTokens); string $tabShortName = $tabPathTokens[size($tabPathTokens) - 1]; // Select the tab // tabLayout -edit -selectTab $tabShortName $tabLayout; // Revert to the original parent. // if ($oldParent != "NONE") setParent $oldParent; if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent; } proc string createDiskTab( string $panel, string $parentLayout, string $tabLabel, string $directory) { // // Description: // This procedure is called when the user creates a new disk tab, or when // the default tabs are being created (ie the first time the user uses the // visor panel or as a result of a revert to default tabs). // This procedure creates a disk tab. // // Returns: // The name of the newly created tab. // setParent $panel; setParent $parentLayout; string $tab = `formLayout`; // Create the library UI. The second and third parameters are blank // because we want to have new directory and files visors created, // rather than specifying existing ones to be used. // string $libraryUI = libraryUI( $tab, "", // directoriesVisorName ""); // filesVisorName setParent ..; // from $tab setParent ..; // from $parentLayout // Set the label on the tab // tabLayout -edit -tabLabel $tab $tabLabel $parentLayout; // Configure the libraryUI // libraryUISetRootDirectory($libraryUI, $directory); libraryUISetFilesPopupMenuScript( $libraryUI, ("visorPanelDiskTabPopupMenu " + $panel)); string $optionVar = generateUniqueTabOptionVarName(); registerTab($tab, "disk", $libraryUI, $optionVar); updateTabOptionVar($optionVar, $tab); // Update the tab layout option var now that a new tab has been added // updateTabLayoutOptionVar($panel, $parentLayout); // Return the name of the tab which was created. // return $tab; } proc string generateUniqueTabOptionVarName() { // // Description: // This procedure is used to create a unique name for an optionVar in // which information about a tab will be stored. // // Returns: // A unique name for an optionVar. // int $i = 1; string $optionVarName; do { $optionVarName = ("visorTab" + $i); $i++; } while (`optionVar -exists $optionVarName`); return $optionVarName; } proc registerTab( string $tab, string $type, string $componentUI, string $optionVar) { // // Description: // This procedure enters information about the specified tab into the // lookup table that contains information about all of the tabs in the // visor panel. // if ( ($type != "disk") && ($type != "paint effects") && ($type != "scene")) { string $registerError = (uiRes("m_visorPanel.kTabRegisterError")); error -showLineNumber true $registerError ; } global string $gVisorPanelLookupTable[]; string $row[]; $row[0] = $tab; $row[1] = $type; $row[2] = $componentUI; $row[3] = $optionVar; lookupTableAddRow($gVisorPanelLookupTable, $row); } proc updateTabOptionVar( string $optionVar, string $tab) { // // Description: // This procedure is called from updateTabOptionVar() and from // createTabOptionVar(). It encapsulates some shared functionality of the // two other procedures. // This procedure generates a unique name for a tab option var if no name // is provided in $optionVar. This procedure looks up the type of the tab // in the lookup table if the type is not specified in $type. // This procedure then gathers all of the information about the specified // tab which needs to be stored in the optionVar, and saves that // information in the optionVar in a known format. // // Returns: // This procedure returns the name of the optionVar into which the // information was stored. // if ($optionVar == "") { // No optionVar name was specified, so we create a new one. // $optionVar = generateUniqueTabOptionVarName(); } // // Now we gather all of the information we need to store about the tab. // string $type = lookupTabType($tab); string $tabLabel = tabLabel($tab); string $component = lookupComponentName($tab); string $stateDescription[]; optionVar -intValue $optionVar 1; optionVar -stringValue ($optionVar + "Label") $tabLabel; optionVar -stringValue ($optionVar + "Type") $type; if ($type == "disk" || $type == "paint effects") { optionVar -stringValue ($optionVar + "DirectoriesVisorName") `libraryUIDirectoriesVisor($component)`; optionVar -stringValue ($optionVar + "FilesVisorName") `libraryUIFilesVisor($component)`; optionVar -stringValue ($optionVar + "RootDirectory") `libraryUIRootDirectory($component)`; optionVar -stringValue ($optionVar + "CurrentDirectory") `libraryUICurrentDirectory($component)`; optionVar -intValue ($optionVar + "DirectoriesShown") `libraryUIDirectoriesShown($component)`; optionVar -intValue ($optionVar + "FilesShown") `libraryUIFilesShown($component)`; } else if ($type == "scene") { optionVar -stringValue ($optionVar + "HypershadeName") `collectionUIHypershadeName($component)`; optionVar -stringValue ($optionVar + "Filter") `collectionUIFilter($component)`; } else { string $errorMsg = (uiRes("m_visorPanel.kUnexpectedTabType")); string $errorDisplay = `format -s $type $errorMsg`; error -showLineNumber true $errorDisplay; } } proc string lookupTabType( string $tab) { // // Description: // This procedure uses the lookup table to look up the type (disk, scene, // graph, protected graph) of the specified tab. // // Returns: // The type of the specified tab. // global string $gVisorPanelLookupTable[]; return lookupTableLookup( $gVisorPanelLookupTable, "tab", $tab, "type"); } proc string tabLabel( string $tab) { // // Description: // This procedure determines the label of the specified tab. // // Returns: // The label of the specified tab. // // Remember the current parent so we can revert to it when we're done here. // string $oldParent = `setParent -query`; string $oldMenuParent = `setParent -menu -query`; string $tabLabel = ""; setParent $tab; setParent ..; string $tabLayout = `setParent -query`; string $tabLabelArray[] = `tabLayout -query -tabLabel $tabLayout`; string $tabArray[] = `tabLayout -query -childArray $tabLayout`; int $i; for ($i = 0; ($i < size($tabArray)) && ($tabLabel == ""); $i++) { setParent $tabLayout; $tabArray[$i] = `setParent $tabArray[$i]`; if ($tabArray[$i] == $tab) { $tabLabel = $tabLabelArray[$i]; } } // Revert to the original parent. // if ($oldParent != "NONE") setParent $oldParent; if ($oldMenuParent != "NONE") setParent -menu $oldMenuParent; return $tabLabel; } proc string lookupComponentName( string $tab) { // // Description: // This procedure uses the lookup table to look up the name of the // UI component (ie libraryUI, collectionUI or graphUI) associated with // the specified tab. // // Returns: // The name of the UI component associated with the specified tab. // global string $gVisorPanelLookupTable[]; return lookupTableLookup( $gVisorPanelLookupTable, "tab", $tab, "componentName"); } proc updateTabLayoutOptionVar( string $panel, string $tabLayout) { // // Description: // This procedure should be called whenever a change is made to the tab // layouts in the visor panel which we want to save to an optionVar // in order to be able to recreate the same tab layout structure at a // later time. For example, we would want to call this procedure if we had // moved a tab left or right within the tab layout. // This procedure writes out an option var which names all of the option // vars describing properties of the tabs in the specified tab layout. // The tab option vars are named in order from left to right. // string $oldParent = `setParent -query`; setParent $panel; string $tabLayoutOptionVar; if ($tabLayout == "firstPaneTabs") { $tabLayoutOptionVar = "visorFirstPaneTabs"; } else { string $tabMsg = (uiRes("m_visorPanel.kUnexpectedTabLayout")); string $tabDisplay = `format -s $tabLayout $tabMsg`; error -showLineNumber true $tabDisplay; } // Delete the existing optionVar for the tabs in this pane, because we are // going to rebuild it. // optionVar -remove $tabLayoutOptionVar; // Unmanage the tabLayout because what we are about to do can cause some // flicker. // tabLayout -edit -manage false $tabLayout; // Take note of the currently selected tab because we will be changing the // tab selection and will want to restore the current selection later // int $selectedTabIndex = `tabLayout -query -selectTabIndex $tabLayout`; int $numTabs = `tabLayout -query -numberOfChildren $tabLayout`; string $tabArray[]; int $i; // For each tab in the tabLayout of the first pane // for ($i = 0; $i < $numTabs; $i++) { // Select the tab and query the layout associated with the selected // tab. The name of the layout is stored in $tabArray and will be used // later as the key to be used in looking up the optionVar of the tab // in the lookup table. // // Previously, a more straightforward approach of using the tabLayout // -childArray flag was used, but it turned out the -childArray flag // does not return the names of the children in the order in which they // appear in the tab layout, but instead in the order in which they // were added to the tab layout. // tabLayout -edit -selectTabIndex ($i + 1) $tabLayout; $tabArray[$i] = `tabLayout -query -selectTab $tabLayout`; } // Reselect the previously selected tab // tabLayout -edit -selectTabIndex $selectedTabIndex $tabLayout; // Remanage the tab layout // tabLayout -edit -manage true $tabLayout; // Now that we have a list of the layouts associated with the tabs, we can // lookup the name of the optionVar associated with each and store it in // the optionVar which describes the ordering of the tabs. // string $tab; string $tabOptionVar; for ($i = 0; $i < size($tabArray); $i++) { $tab = $tabArray[$i]; setParent $panel; $tab = `setParent $tab`; // Lookup the optionVar which describes this tab // $tabOptionVar = lookupTabOptionVar($tab); if ($tabOptionVar == "") { global string $gVisorPanelLookupTable[]; lookupTablePrint($gVisorPanelLookupTable); error -showLineNumber true (uiRes("m_visorPanel.kNonemptyTabOptionVarName")) ; } // Append the name of the optionVar to the optionVar describing the // tabs in this pane // optionVar -stringValueAppend $tabLayoutOptionVar $tabOptionVar; } if ($oldParent != "NONE") setParent $oldParent; } proc string lookupTabOptionVar( string $tab) { // // Description: // This procedure uses the lookup table to look up the name of the // optionVar which stores information about the specified tab. The // information stored in these optionVars is used to recreate tabs with // the same characteristics in subsequent Maya sessions, and also to // recreate tabs when the panel is torn off into a window. // // Returns: // The name of the optionVar associated with the specified tab. // global string $gVisorPanelLookupTable[]; return lookupTableLookup( $gVisorPanelLookupTable, "tab", $tab, "optionVar"); }