Skip to content

Commit

Permalink
Alias knobs: populate the choice menu from the aliased knob when crea…
Browse files Browse the repository at this point in the history
…ting the link
  • Loading branch information
MrKepzie committed Dec 6, 2015
1 parent 455c2c4 commit 3a590eb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
15 changes: 14 additions & 1 deletion Engine/Knob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3224,7 +3224,9 @@ KnobHelper::createDuplicateOnNode(Natron::EffectInstance* effect,
output = newKnob;
} else if (isChoice) {
boost::shared_ptr<KnobChoice> 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<KnobColor> newKnob = effect->createColorKnob(newScriptName, newLabel,getDimension());
Expand Down Expand Up @@ -3359,6 +3361,17 @@ KnobHelper::setKnobAsAliasOfThis(const boost::shared_ptr<KnobI>& 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<KnobChoice*>(master.get());
if (isChoice) {
KnobChoice* thisChoice = dynamic_cast<KnobChoice*>(this);
assert(thisChoice);
isChoice->populateChoices(thisChoice->getEntries_mt_safe(),thisChoice->getEntriesHelp_mt_safe());
}
}
beginChanges();
for (int i = 0; i < getDimension(); ++i) {

Expand Down
51 changes: 29 additions & 22 deletions Engine/NodeGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1868,34 +1868,42 @@ static void exportUserKnob(int indentLevel,const boost::shared_ptr<KnobI>& knob,
", " + ESC(isChoice->getLabel()) + ")");

KnobChoice* aliasedIsChoice = dynamic_cast<KnobChoice*>(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<std::string> entries = isChoice->getEntries_mt_safe();
std::vector<std::string> 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<std::string> entries = isChoice->getEntries_mt_safe();
std::vector<std::string> 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<int> 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<int> 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<int> 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";
Expand Down Expand Up @@ -2243,7 +2251,6 @@ static void exportAllNodeKnobs(int indentLevel,const boost::shared_ptr<Natron::N
if (paramName.empty()) {
continue;
}
qDebug() << paramName.c_str();
getParamStr += paramName.c_str();
getParamStr += "\")";
if (exportKnobValues(indentLevel,*it2,getParamStr, true, ts)) {
Expand Down

0 comments on commit 3a590eb

Please sign in to comment.