// =========================================================================== // 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 to retrieve the input color space names global proc string[] getInputColorSpaceNames() { return `colorManagementPrefs -q -inputSpaceNames`; } proc displayColorSpaceFileRulesDisclaimer ( string $nodeName ) { string $filePath = ""; // File texture if ( catchQuiet ( $filePath = `getAttr ($nodeName + ".fileTextureName")` ) ) { // Image Plane if ( catchQuiet ( $filePath = `getAttr ($nodeName + ".imageName")` ) ) { // Arnold aiImage if ( catchQuiet ( $filePath = `getAttr ($nodeName + ".filename")` ) ) { return; } } } if ( $filePath != "" && !`getAttr ($nodeName + ".ignoreColorSpaceFileRules")` ) { string $expectedColorSpace = `colorManagementFileRules -evaluate $filePath`; string $currentColorSpace = `getAttr ($nodeName + ".colorSpace")`; if ( $expectedColorSpace != $currentColorSpace ) { warning -noContext (uiRes("m_colorSpaceProcedures.kIgnoreColorSpaceFileRulesDisclaimer")); } } } // Procedure to update the color space widgets upon a warning proc updateColorSpaceWarning(string $menu, string $text, string $selection, string $validItems[], string $nodeName) { if ( !stringArrayContains($selection, $validItems) ) { optionMenu -e -backgroundColor 1.0 0.0 0.0 $menu ; string $fmt = (uiRes("m_colorSpaceProcedures.kColorSpaceNotFound")); string $warningMessage = `format -s $selection $fmt`; text -e -visible true -label $warningMessage $text; } else { optionMenu -e -backgroundColor 0.37109375 0.37109375 0.37109375 $menu ; text -e -visible false $text; } displayColorSpaceFileRulesDisclaimer ( $nodeName ); } // Procedure to set a given color space attribute proc setColorSpaceAttr(string $colorSpaceAttr, string $colorSpace) { setAttr $colorSpaceAttr -type "string" $colorSpace ; } proc string getColorSpaceSelection(string $colorSpaceAttr) { // Get the color space attribute value; it might be the empty string. string $colorSpace = `getAttr $colorSpaceAttr`; return $colorSpace; } // Procedure to update the contents of the option menu containing the color spaces proc updateColorSpaceMenu( string $menu, string $text, string $selection, string $colorSpaceAttr ) { if ( !`optionMenu -query -exists $menu` ) { return; } setParent -m $menu; // Clear the current menu items string $oldMenuItems[] = `optionMenu -q -ils $menu`; for($oldMenuItem in $oldMenuItems) { deleteUI -mi $oldMenuItem; } // If the "colorManagementEnabled" input is not connected, the node is // not color managed. string $nodeName[]; tokenize $colorSpaceAttr "." $nodeName; string $enabledAttr = $nodeName[0] + ".colorManagementEnabled"; int $isNodeColorManaged = `isConnected "defaultColorMgtGlobals.cmEnabled" $enabledAttr`; if ($isNodeColorManaged) { // Get the color space names from SynColor and populate the option menu string $colorSpaceNames[] = getInputColorSpaceNames(); // If the colorSpace attribute from the node does not exist // in the list of color spaces, add it to the list. string $newMenuitems[] = $colorSpaceNames; if ( !stringArrayContains($selection, $colorSpaceNames) ) { $newMenuitems[size($newMenuitems)] = $selection; $newMenuitems = `sort $newMenuitems`; } for($newMenuitem in $newMenuitems) { menuItem -label $newMenuitem; } // Make sure the correct color space menu item is selected optionMenu -e -value $selection $menu ; updateColorSpaceWarning($menu, $text, $selection, $colorSpaceNames, $nodeName[0]); optionMenu -e -enable `colorManagementPrefs -q -cmEnabled` $menu; } else { menuItem -label (uiRes("m_colorSpaceProcedures.kNoColorManagement")); optionMenu -e -enable false $menu; } setParent -m ..; } // Callback used to set the colorSpace attribute global proc setColorSpaceAttrCB(string $menu, string $text, string $colorSpaceAttr) { string $selectedItemValue = `optionMenu -query -value $menu`; setColorSpaceAttr($colorSpaceAttr, $selectedItemValue); string $nodeName[]; tokenize $colorSpaceAttr "." $nodeName; updateColorSpaceWarning($menu, $text, $selectedItemValue, getInputColorSpaceNames(), $nodeName[0]); } global proc onColorSpaceProceduresEnableChange(string $colorSpaceAttr, string $menu) { setParent -m $menu; // If the "colorManagementEnabled" input is not connected, // the node is not color managed. string $nodeName[]; tokenize $colorSpaceAttr "." $nodeName; int $isMenuEnabled = false; if (`objExists $nodeName[0]`) { string $enabledAttr = $nodeName[0] + ".colorManagementEnabled"; $isMenuEnabled = `isConnected "defaultColorMgtGlobals.cmEnabled" $enabledAttr` && `colorManagementPrefs -q -cmEnabled`; } optionMenu -e -enable $isMenuEnabled $menu; setParent -m ..; } global proc onColorSpaceProceduresConfigChange(string $colorSpaceAttr, string $menu) { string $menuRowLayout = `optionMenu -q -parent $menu`; string $menuColumnLayout = `rowLayout -q -parent $menuRowLayout`; string $warningText = $menuColumnLayout + "|colorSpaceWarningText"; string $selection = `optionMenu -q -v $menu`; updateColorSpaceMenu($menu, $warningText, $selection, $colorSpaceAttr); } global proc onColorSpaceProceduresAttributeChange(string $menu, string $warningText, string $colorSpaceAttr) { string $selection = getColorSpaceSelection($colorSpaceAttr); updateColorSpaceMenu($menu, $warningText, $selection, $colorSpaceAttr); } proc addScriptJobs(string $colorSpaceAttr, string $menu, string $warningText) { // Use the replace previous (rp) flag just once, as it is non-selective // and removes ALL script jobs with the same parent. scriptJob -rp -p $menu -event "colorMgtConfigChanged" ("onColorSpaceProceduresConfigChange " + $colorSpaceAttr + " " + $menu); string $cmd = "onColorSpaceProceduresAttributeChange " + $menu + " " + $warningText + " " + $colorSpaceAttr; // Don't use the replace previous flag here, as it would remove the // scriptJob we just added. scriptJob -p $menu -attributeChange $colorSpaceAttr $cmd; // Grey out the color Space menu if Color Mgt is off scriptJob -p $menu -event "colorMgtEnabledChanged" ("onColorSpaceProceduresEnableChange " + $colorSpaceAttr + " " + $menu); } // Add a new color space UI element to the attribute editor proc AEcolorSpaceControlImp(string $colorSpaceAttr, string $label) { columnLayout -adjustableColumn true colorSpaceColumnLayout; rowLayout -nc 2 colorSpaceRowLayout; text -l $label colorSpaceMenuText; string $menu = `optionMenu -l "" colorSpaceMenu`; setParent ..; string $warningText = `text -font "boldLabelFont" -al "center" -l "" colorSpaceWarningText`; setParent -m ..; setParent ..; // Set up the color space attribute callback optionMenu -e -cc ("setColorSpaceAttrCB " + $menu + " " + $warningText + " " + $colorSpaceAttr) $menu; // Update color space option menu items string $selection = getColorSpaceSelection($colorSpaceAttr); updateColorSpaceMenu($menu, $warningText, $selection, $colorSpaceAttr); addScriptJobs($colorSpaceAttr, $menu, $warningText); } // Add a new color space UI element to the attribute editor global proc AEcolorSpaceNew(string $colorSpaceAttr) { AEcolorSpaceControlImp($colorSpaceAttr, (uiRes("m_colorSpaceProcedures.kColorSpaceLabel"))); } // this function is called to build the color space control when using a custom template in the attribute editor global proc PPcolorSpaceControl(string $plug, string $label, string $annot) { AEcolorSpaceControlImp($plug, $label); } // Update the color space UI element in the attribute editor global proc AEcolorSpaceReplace(string $colorSpaceAttr) { string $parent = `setParent -q`; string $menu = $parent + "|colorSpaceColumnLayout|colorSpaceRowLayout|colorSpaceMenu"; string $warningText = $parent + "|colorSpaceColumnLayout|colorSpaceWarningText"; optionMenu -e -cc ("setColorSpaceAttrCB " + $menu + " " + $warningText + " " + $colorSpaceAttr) $menu; // update the optionMenu string $selection = getColorSpaceSelection($colorSpaceAttr); updateColorSpaceMenu($menu, $warningText, $selection, $colorSpaceAttr); addScriptJobs($colorSpaceAttr, $menu, $warningText); }