Skip to content

Commit

Permalink
when crating/pasting nodes, only use a different name if necessary
Browse files Browse the repository at this point in the history
closes #755
  • Loading branch information
devernay committed Jan 20, 2022
1 parent ba72633 commit fca2be3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 46 deletions.
65 changes: 36 additions & 29 deletions Engine/NodeName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@ Node::initNodeScriptName(const NodeSerialization* serialization, const QString&

if (!fixedName.isEmpty()) {

std::string baseName = fixedName.toStdString();
trimNumber(baseName);
std::string name;
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( group && group->checkIfNodeNameExists(name, this) );

std::string name = fixedName.toStdString();
// If the script name is available, use it as is (else we get issue #755).
// Else look for a similar name by adding a (different) number suffix.
if ( group && group->checkIfNodeNameExists(name, this) ) {
std::string baseName = name;
trimNumber(baseName);
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( group && group->checkIfNodeNameExists(name, this) );
}
//This version of setScriptName will not error if the name is invalid or already taken
setScriptName_no_error_check(name);

Expand All @@ -86,20 +89,24 @@ Node::initNodeScriptName(const NodeSerialization* serialization, const QString&
QMutexLocker k(&_imp->nameMutex);
_imp->cacheID = serialization->getCacheID();
}
std::string baseName = serialization->getNodeScriptName();
trimNumber(baseName);
std::string name;
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( group && group->checkIfNodeNameExists(name, this) );
std::string name = serialization->getNodeScriptName();
// If the serialized script name is available, use it as is (else we get issue #755).
// Else look for a similar name by adding a (different) number suffix.
if ( group && group->checkIfNodeNameExists(name, this) ) {
std::string baseName = name;
trimNumber(baseName);
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( group->checkIfNodeNameExists(name, this) );
}

//This version of setScriptName will not error if the name is invalid or already taken
setScriptName_no_error_check(name);
Expand Down
36 changes: 19 additions & 17 deletions Gui/NodeGraphPrivate10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,24 +189,26 @@ NodeGraphPrivate::pasteNode(const NodeSerializationPtr & internalSerialization,
NodeGuiPtr gui = boost::dynamic_pointer_cast<NodeGui>(gui_i);
assert(gui);

std::string name;
if ( ( grp == group.lock() ) && ( !internalSerialization->getNode() || ( internalSerialization->getNode()->getGroup() == group.lock() ) ) ) {
//We pasted the node in the same group, give it another label
std::string baseName = internalSerialization->getNodeLabel();
trimNumber(baseName);
std::string name;
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( grp->checkIfNodeLabelExists( name, n.get() ) );

// We pasted the node in the same group, give it another label.
// If the label is available, use it as is.
// Else look for a similar name by adding a (different) number suffix.
std::string name = internalSerialization->getNodeLabel();
if ( grp->checkIfNodeLabelExists( name, n.get() ) ) {
std::string baseName = name;
trimNumber(baseName);
int no = 1;
do {
name = baseName;
if (no > 1) {
name += '_';
std::stringstream ss;
ss << no;
name += ss.str();
}
++no;
} while ( grp->checkIfNodeLabelExists( name, n.get() ) );
}
n->setLabel(name);
} else {
//If we paste the node in a different graph, it can keep its scriptname/label
Expand Down

0 comments on commit fca2be3

Please sign in to comment.