MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / initNodeScriptName

Method initNodeScriptName

Engine/NodeName.cpp:52–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void
53Node::initNodeScriptName(const NodeSerialization* serialization, const QString& fixedName)
54{
55 /*
56 If the serialization is not null, we are either pasting a node or loading it from a project.
57 */
58 NodeCollectionPtr group = getGroup();
59 bool isMultiInstanceChild = false;
60 if ( !_imp->multiInstanceParentName.empty() ) {
61 isMultiInstanceChild = true;
62 }
63
64 if (!fixedName.isEmpty()) {
65
66 std::string name = fixedName.toStdString();
67 // If the script name is available, use it as is (else we get issue #755).
68 // Else look for a similar name by adding a (different) number suffix.
69 if ( group && group->checkIfNodeNameExists(name, this) ) {
70 std::string baseName = name;
71 trimNumber(baseName);
72 int no = 1;
73 do {
74 name = baseName;
75 if (no > 1) {
76 name += '_';
77 std::stringstream ss;
78 ss << no;
79 name += ss.str();
80 }
81 ++no;
82 } while ( group && group->checkIfNodeNameExists(name, this) );
83 }
84 //This version of setScriptName will not error if the name is invalid or already taken
85 setScriptName_no_error_check(name);
86
87 } else if (serialization) {
88 if ( group && !group->isCacheIDAlreadyTaken( serialization->getCacheID() ) ) {
89 QMutexLocker k(&_imp->nameMutex);
90 _imp->cacheID = serialization->getCacheID();
91 }
92 std::string name = serialization->getNodeScriptName();
93 // If the serialized script name is available, use it as is (else we get issue #755).
94 // Else look for a similar name by adding a (different) number suffix.
95 if ( group && group->checkIfNodeNameExists(name, this) ) {
96 std::string baseName = name;
97 trimNumber(baseName);
98 int no = 1;
99 do {
100 name = baseName;
101 if (no > 1) {
102 name += '_';
103 std::stringstream ss;
104 ss << no;
105 name += ss.str();
106 }
107 ++no;
108 } while ( group->checkIfNodeNameExists(name, this) );
109 }

Callers 1

createOfxEffectMethod · 0.80

Calls 11

setLabelFunction · 0.85
emptyMethod · 0.80
toStdStringMethod · 0.80
checkIfNodeNameExistsMethod · 0.80
isCacheIDAlreadyTakenMethod · 0.80
getAppTypeMethod · 0.80
initNodeNameMethod · 0.80
trimNumberFunction · 0.70
isEmptyMethod · 0.45
getCacheIDMethod · 0.45
getPluginLabelMethod · 0.45

Tested by

no test coverage detected