// =========================================================================== // 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. // =========================================================================== // // Calls to the switchPanes() proc may be embedded in user's shelf // buttons, making it difficult to change the method's calling sequence // without breaking users' preferences. // // To get around that, different versions of switchPanes() are each given // their own wrapper proc, all of which call back to this central proc to // do the processing. // // Parameters: // // $version - tells this proc which version of $args has been // passed to it. // // $args - array of arguments to be used. $version determines // the number of elements that the array should contain, // and their meanings. // // Version 1 Arguments: // // 0: Name of the panel configuration to switch to. // // May also be the special string "@goBack", in // which case we'll switch back to the previous // configuration in the mainPanelHistory, if there // is one. // // 1: If we're switching to the "single" // configuration, this arg provides the name of // the panel from the original configuration which // should be visible after the switch. // // May also be one of the following special // strings: // // "@focus" - use the panel which had focus // before the switch. // // "@pointer" - use the panel which was under the // mouse pointer before the switch. // // This argument is ignored if arg 0 is "@goBack". // global proc doSwitchPanes(int $version, string $args[]) { global string $gMainPane; global int $gPoppedPane = -1; global string $gPrePopConfig; global string $gPrePopControls[4]; global int $gPrePopSizes[8]; string $currPane; // Currently, there is only one version of $args. if ($version != 1) return; if ($gMainPane != "" && `paneLayout -exists $gMainPane`) { if ($args[0] == "@goBack") { if (`panelHistory -q -isEmpty mainPanelHistory`) { // // No history so go to four view, but make sure current // camera is preserved. // string $currCam = ""; string $currPanel = `getPanel -withFocus`; if ("modelPanel" == `getPanel -typeOf $currPanel`) { // // save the camera // $currCam = `modelPanel -q -cam $currPanel`; } string $config = `getPanel -cwl (localizedPanelLabel("Four View"))`; if ("" != $config) { setNamedPanelLayout (localizedPanelLabel("Four View")); } else { panelHistory -e -suspend on mainPanelHistory; paneLayout -e -manage false $gMainPane; paneLayout -e -cn "quad" $gMainPane; fillEmptyPanes; paneLayout -e -manage true $gMainPane; panelHistory -e -suspend off mainPanelHistory; } // // Make sure the previous camera view is represented // if ($currCam != "" && $currCam != "persp" && $currCam != "top" && $currCam != "front" && $currCam != "side") { // // put camera in persp view // string $perspPanel = `getPanel -withLabel (localizedPanelLabel("Persp View"))`; if (`modelPanel -exists $perspPanel`) { modelPanel -e -cam $currCam $perspPanel; } } } else { if ($gPoppedPane > 0) { // // Restore pre popped config // panelHistory -e -suspend on mainPanelHistory; $currPane = `paneLayout -q -p1 $gMainPane`; paneLayout -e -manage false $gMainPane; paneLayout -e -cn $gPrePopConfig $gMainPane; int $nArr = size($gPrePopSizes); if (`panel -exists $gPrePopControls[0]` && !`panel -q -to $gPrePopControls[0]` ) { if ("" == `panel -q -control $gPrePopControls[0]`) { // // parent the panel to the main pane first. // string $pType = `getPanel -typeOf $gPrePopControls[0]`; string $cmd = ($pType +" -e -parent $gMainPane "+ $gPrePopControls[0]); eval $cmd; } paneLayout -e -sp $gPrePopControls[0] 1 -ps 1 $gPrePopSizes[0] $gPrePopSizes[1] $gMainPane; } else { $gPrePopControls[0] = ""; } if ($nArr > 3 && `panel -exists $gPrePopControls[1]` && !`panel -q -to $gPrePopControls[1]` ) { if ("" == `panel -q -control $gPrePopControls[1]`) { // // parent the panel to the main pane first. // string $pType = `getPanel -typeOf $gPrePopControls[1]`; string $cmd = ($pType +" -e -parent $gMainPane "+ $gPrePopControls[1]); eval $cmd; } paneLayout -e -sp $gPrePopControls[1] 2 -ps 2 $gPrePopSizes[2] $gPrePopSizes[3] $gMainPane; } else { $gPrePopControls[1] = ""; } if ($nArr > 5 && `panel -exists $gPrePopControls[2]` && !`panel -q -to $gPrePopControls[2]` ) { if ("" == `panel -q -control $gPrePopControls[2]`) { // // parent the panel to the main pane first. // string $pType = `getPanel -typeOf $gPrePopControls[2]`; string $cmd = ($pType +" -e -parent $gMainPane "+ $gPrePopControls[2]); eval $cmd; } paneLayout -e -sp $gPrePopControls[2] 3 -ps 3 $gPrePopSizes[4] $gPrePopSizes[5] $gMainPane; } else { $gPrePopControls[2] = ""; } if ($nArr > 7 && `panel -exists $gPrePopControls[3]` && !`panel -q -to $gPrePopControls[3]` ) { if ("" == `panel -q -control $gPrePopControls[3]`) { // // parent the panel to the main pane first. // string $pType = `getPanel -typeOf $gPrePopControls[3]`; string $cmd = ($pType +" -e -parent $gMainPane "+ $gPrePopControls[3]); eval $cmd; } paneLayout -e -sp $gPrePopControls[3] 4 -ps 4 $gPrePopSizes[6] $gPrePopSizes[7] $gMainPane; } else { $gPrePopControls[3] = ""; } // // preserve current panel by placing it in the // popped pane. If current panel existed elsewhere // in the config then compensate. // int $swapped = -1; if ($currPane == $gPrePopControls[0]) { if ($gPoppedPane != 1) { paneLayout -e -sp $currPane $gPoppedPane $gMainPane; $swapped = 1; } } else if ($currPane == $gPrePopControls[1]) { if ($gPoppedPane != 2) { paneLayout -e -sp $currPane $gPoppedPane $gMainPane; $swapped = 2; } } else if ($currPane == $gPrePopControls[2]) { if ($gPoppedPane != 3) { paneLayout -e -sp $currPane $gPoppedPane $gMainPane; $swapped = 3; } } else if ($currPane == $gPrePopControls[3]) { if ($gPoppedPane != 4) { paneLayout -e -sp $currPane $gPoppedPane $gMainPane; $swapped = 4; } } else { paneLayout -e -sp $currPane $gPoppedPane $gMainPane; } if (0 < $swapped) { // // A pre-popped control has been swapped into the popped // pane. Try to swap positions if it is still a child. // string $childs[] = `paneLayout -q -ca $gMainPane`; for ($child in $childs) { if ($gPrePopControls[$gPoppedPane-1] == $child) { paneLayout -e -sp $child $swapped $gMainPane; } } } fillEmptyPanes; paneLayout -e -manage true $gMainPane; setFocus $currPane; panelHistory -e -suspend off mainPanelHistory; } else { paneLayout -e -manage false $gMainPane; panelHistory -e -back mainPanelHistory; paneLayout -e -manage true $gMainPane; } } } else { string $newConfig = $args[0]; string $panelToKeep = $args[1]; panelHistory -e -suspend on mainPanelHistory; if ($panelToKeep == "@focus") { $panelToKeep = `getPanel -withFocus`; } else { if ($panelToKeep == "@pointer") { $panelToKeep = `paneLayout -q -pup $gMainPane`; } if ($newConfig == "single") { // // save pane state for popping. // $gPrePopControls[0] = `paneLayout -q -p1 $gMainPane`; $gPrePopControls[1] = `paneLayout -q -p2 $gMainPane`; $gPrePopControls[2] = `paneLayout -q -p3 $gMainPane`; $gPrePopControls[3] = `paneLayout -q -p4 $gMainPane`; if ($gPrePopControls[0] == $panelToKeep) { $gPoppedPane = 1; } else if ($gPrePopControls[1] == $panelToKeep) { $gPoppedPane = 2; } else if ($gPrePopControls[2] == $panelToKeep) { $gPoppedPane = 3; } else if ($gPrePopControls[3] == $panelToKeep) { $gPoppedPane = 4; } else { $gPoppedPane = 1; } $gPrePopSizes = `paneLayout -q -ps $gMainPane`; $gPrePopConfig = `paneLayout -q -cn $gMainPane`; } } if ($panelToKeep != "") { paneLayout -e -manage false $gMainPane; // If we're going into the single-pane configuration, and // $panelToKeep is one of the existing configuration's // panels, then move it to pane 1 so that it will still be // visible after the switch. if ($newConfig == "single") { string $children[] = `paneLayout -q -ca $gMainPane`; if (stringArrayContains($panelToKeep, $children)) paneLayout -e -setPane $panelToKeep 1 $gMainPane; } // Switch to the new configuration. paneLayout -e -cn $newConfig $gMainPane; //fillEmptyPanes; paneLayout -e -manage true $gMainPane; setFocus `paneLayout -q -p1 $gMainPane`; fillEmptyPanes; } panelHistory -e -suspend off mainPanelHistory; } } }