From 3a590eb8a323750008229b60d53699159dc6d4e5 Mon Sep 17 00:00:00 2001 From: Alexandre Gauthier Date: Sun, 6 Dec 2015 11:36:54 +0100 Subject: [PATCH] Alias knobs: populate the choice menu from the aliased knob when creating the link --- Engine/Knob.cpp | 15 ++++++++++++- Engine/NodeGroup.cpp | 51 +++++++++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/Engine/Knob.cpp b/Engine/Knob.cpp index 88b1573197..6264d9cda6 100644 --- a/Engine/Knob.cpp +++ b/Engine/Knob.cpp @@ -3224,7 +3224,9 @@ KnobHelper::createDuplicateOnNode(Natron::EffectInstance* effect, output = newKnob; } else if (isChoice) { boost::shared_ptr newKnob = effect->createChoiceKnob(newScriptName, newLabel); - newKnob->populateChoices(isChoice->getEntries_mt_safe(),isChoice->getEntriesHelp_mt_safe()); + if (!makeAlias) { + newKnob->populateChoices(isChoice->getEntries_mt_safe(),isChoice->getEntriesHelp_mt_safe()); + } output = newKnob; } else if (isColor) { boost::shared_ptr newKnob = effect->createColorKnob(newScriptName, newLabel,getDimension()); @@ -3359,6 +3361,17 @@ KnobHelper::setKnobAsAliasOfThis(const boost::shared_ptr& master, bool do return false; } + /* + For choices, copy exactly the menu entries because they have to be the same + */ + if (doAlias) { + KnobChoice* isChoice = dynamic_cast(master.get()); + if (isChoice) { + KnobChoice* thisChoice = dynamic_cast(this); + assert(thisChoice); + isChoice->populateChoices(thisChoice->getEntries_mt_safe(),thisChoice->getEntriesHelp_mt_safe()); + } + } beginChanges(); for (int i = 0; i < getDimension(); ++i) { diff --git a/Engine/NodeGroup.cpp b/Engine/NodeGroup.cpp index a55c6b5ac3..af26a287f4 100644 --- a/Engine/NodeGroup.cpp +++ b/Engine/NodeGroup.cpp @@ -1868,34 +1868,42 @@ static void exportUserKnob(int indentLevel,const boost::shared_ptr& knob, ", " + ESC(isChoice->getLabel()) + ")"); KnobChoice* aliasedIsChoice = dynamic_cast(aliasedParam.get()); -#pragma message WARN("TODO: if this is an aliased choice parameter, options are fetched from the aliased parameter and should not be written") - - std::vector entries = isChoice->getEntries_mt_safe(); - std::vector helps = isChoice->getEntriesHelp_mt_safe(); - if (entries.size() > 0) { - if (helps.empty()) { - for (U32 i = 0; i < entries.size(); ++i) { - helps.push_back(""); + if (!aliasedIsChoice) { + std::vector entries = isChoice->getEntries_mt_safe(); + std::vector helps = isChoice->getEntriesHelp_mt_safe(); + if (entries.size() > 0) { + if (helps.empty()) { + for (U32 i = 0; i < entries.size(); ++i) { + helps.push_back(""); + } } + WRITE_INDENT(indentLevel); ts << "entries = [ (" << ESC(entries[0]) << ", " << ESC(helps[0]) << "),\n"; + for (U32 i = 1; i < entries.size(); ++i) { + QString endToken = (i == entries.size() - 1) ? ")]" : "),"; + WRITE_INDENT(indentLevel); WRITE_STRING("(" + ESC(entries[i]) + ", " + ESC(helps[i]) + endToken); + } + WRITE_INDENT(indentLevel); WRITE_STATIC_LINE("param.setOptions(entries)"); + WRITE_INDENT(indentLevel); WRITE_STATIC_LINE("del entries"); + } + std::vector defaultValues = isChoice->getDefaultValues_mt_safe(); + assert((int)defaultValues.size() == isChoice->getDimension()); + if (defaultValues[0] != 0) { + std::string entryStr = isChoice->getEntry(defaultValues[0]); + WRITE_INDENT(indentLevel); WRITE_STRING("param.setDefaultValue(" + ESC(entryStr) + ")"); + } - WRITE_INDENT(indentLevel); ts << "entries = [ (" << ESC(entries[0]) << ", " << ESC(helps[0]) << "),\n"; - for (U32 i = 1; i < entries.size(); ++i) { - QString endToken = (i == entries.size() - 1) ? ")]" : "),"; - WRITE_INDENT(indentLevel); WRITE_STRING("(" + ESC(entries[i]) + ", " + ESC(helps[i]) + endToken); + } else { + std::vector defaultValues = isChoice->getDefaultValues_mt_safe(); + assert((int)defaultValues.size() == isChoice->getDimension()); + if (defaultValues[0] != 0) { + WRITE_INDENT(indentLevel); WRITE_STRING("param.setDefaultValue(" + NUM(defaultValues[0]) + ")"); + } - WRITE_INDENT(indentLevel); WRITE_STATIC_LINE("param.setOptions(entries)"); - WRITE_INDENT(indentLevel); WRITE_STATIC_LINE("del entries"); } - std::vector defaultValues = isChoice->getDefaultValues_mt_safe(); - assert((int)defaultValues.size() == isChoice->getDimension()); - if (defaultValues[0] != 0) { - std::string entryStr = isChoice->getEntry(defaultValues[0]); - WRITE_INDENT(indentLevel); WRITE_STRING("param.setDefaultValue(" + ESC(entryStr) + ")"); - - } + } else if (isColor) { QString hasAlphaStr = (isColor->getDimension() == 4) ? "True" : "False"; @@ -2243,7 +2251,6 @@ static void exportAllNodeKnobs(int indentLevel,const boost::shared_ptr