// =========================================================================== // 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. // =========================================================================== proc string optionVarName(string $input, string $context) { return $input + "Option" + $context; } proc string uiItemName(string $input) { return $input + "UI"; } proc resetOptions(int $force, string $context) { if ($force || !`optionVar -exists (optionVarName("cacheTimeRange", $context))`) optionVar -intValue (optionVarName("cacheTimeRange", $context)) 3; if ($force || !`optionVar -exists (optionVarName("startFrame", $context))`) optionVar -floatValue (optionVarName("startFrame", $context)) 0; if ($force || !`optionVar -exists (optionVarName("endFrame", $context))`) optionVar -floatValue (optionVarName("endFrame", $context)) 0; if ($force || !`optionVar -exists (optionVarName("evaluateEvery", $context))`) optionVar -floatValue (optionVarName("evaluateEvery", $context)) 1; } proc saveOptions(string $context) { optionVar -intValue (optionVarName("cacheTimeRange", $context)) `radioButtonGrp -q -sl (uiItemName("cacheTimeRange"))`; optionVar -floatValue (optionVarName("startFrame", $context)) `floatFieldGrp -q -value1 (uiItemName("startEnd"))`; optionVar -floatValue (optionVarName("endFrame", $context)) `floatFieldGrp -q -value2 (uiItemName("startEnd"))`; optionVar -floatValue (optionVarName("evaluateEvery", $context)) `floatFieldGrp -q -value1 (uiItemName("evaluateEvery"))`; } proc loadOptions(string $context) { int $cacheTimeRange = `optionVar -q (optionVarName("cacheTimeRange", $context))`; radioButtonGrp -e -select $cacheTimeRange (uiItemName("cacheTimeRange")); floatFieldGrp -e -enable ($cacheTimeRange == 4) (uiItemName("startEnd")); floatFieldGrp -e -value1 `optionVar -q (optionVarName("startFrame", $context))` -value2 `optionVar -q (optionVarName("endFrame", $context))` (uiItemName("startEnd")); floatFieldGrp -e -value1 `optionVar -q (optionVarName("evaluateEvery", $context))` (uiItemName("evaluateEvery")); } proc createUI() { string $startEndLabel = (uiRes("m_cacheTimeRangeOptions.kStartEnd")); radioButtonGrp -label (uiRes("m_cacheTimeRangeOptions.kCacheTimerange")) -nrb 4 -vr -labelArray4 (uiRes("m_cacheTimeRangeOptions.kCurrentFrame")) (uiRes("m_cacheTimeRangeOptions.kRenderSettings")) (uiRes("m_cacheTimeRangeOptions.kTimeSlider")) $startEndLabel (uiItemName("cacheTimeRange")); floatFieldGrp -label $startEndLabel -nf 2 (uiItemName("startEnd")); radioButtonGrp -e -on4 ("floatFieldGrp -e -en true " + uiItemName("startEnd")) -of4 ("floatFieldGrp -e -en false " + uiItemName("startEnd")) (uiItemName("cacheTimeRange")); floatFieldGrp -label (uiRes("m_cacheTimeRangeOptions.kEvaluateEvery")) -extraLabel (uiRes("m_cacheTimeRangeOptions.kFrames")) -nf 1 (uiItemName("evaluateEvery")); } proc float[] queryTimeRange(string $context) { // Initialze the options before access resetOptions(0, $context); int $cacheTimeRange = `optionVar -q (optionVarName("cacheTimeRange", $context))`; float $startFrame = `optionVar -q (optionVarName("startFrame", $context))`; float $endFrame = `optionVar -q (optionVarName("endFrame", $context))`; if ($cacheTimeRange == 1) // current frame { $startFrame = `currentTime -q`; $endFrame = $startFrame; } else if ($cacheTimeRange == 2) // render settings { if (`control -q -exists startFrameCtrl` && `control -q -enable startFrameCtrl`) { $startFrame = `getAttr "defaultRenderGlobals.startFrame"`; $endFrame = `getAttr "defaultRenderGlobals.endFrame"`; } else { $startFrame = `currentTime -q`; $endFrame = $startFrame; } } else if ($cacheTimeRange == 3) // time slider { $startFrame = `playbackOptions -q -min`; $endFrame = `playbackOptions -q -max`; } return {$startFrame, $endFrame}; } proc float[] queryEvaluationRate(string $context) { // Initialze the options before access resetOptions(0, $context); float $evaluationRate = `optionVar -q (optionVarName("evaluateEvery", $context))`; return {$evaluationRate}; } // Global interface, working as message dispatcher. // UI module for initialize, save, load and access the time range options. // UI shared between gpuCache, bbox & locator commands. global proc float[] cacheTimeRangeOptions(string $message, string $context) { float $result[]; if ($message == "initialize") resetOptions(0, $context); else if ($message == "reset") resetOptions(1, $context); else if ($message == "load") loadOptions($context); else if ($message == "save") saveOptions($context); else if ($message == "createUI") createUI(); else if ($message == "queryTimeRange") $result = queryTimeRange($context); else if ($message == "queryEvaluationRate") $result = queryEvaluationRate($context); return $result; }