Skip to content

Commit

Permalink
oldNewScriptNamesMapping: more consistent naming
Browse files Browse the repository at this point in the history
  • Loading branch information
devernay committed Apr 4, 2021
1 parent 552c3a0 commit 67afa2d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions Gui/NodeGraph40.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,25 +299,25 @@ NodeGraph::cloneSelectedNodes(const QPointF& scenePos)
std::list<std::pair<std::string, NodeGuiPtr> > newNodes;
std::list<NodeSerializationPtr> serializations;
std::list<NodeGuiPtr> newNodesList;
std::map<std::string, std::string> oldNewScriptNameMapping;
std::map<std::string, std::string> oldNewScriptNamesMapping;
for (NodesGuiList::iterator it = nodesToCopy.begin(); it != nodesToCopy.end(); ++it) {
NodeSerializationPtr internalSerialization( new NodeSerialization( (*it)->getNode() ) );
NodeGuiSerializationPtr guiSerialization = boost::make_shared<NodeGuiSerialization>();
(*it)->serialize( guiSerialization.get() );
NodeGuiPtr clone = _imp->pasteNode(internalSerialization, guiSerialization, offset,
_imp->group.lock(), std::string(), true, &oldNewScriptNameMapping );
_imp->group.lock(), std::string(), true, &oldNewScriptNamesMapping);

newNodes.push_back( std::make_pair(internalSerialization->getNodeScriptName(), clone) );
newNodesList.push_back(clone);
serializations.push_back(internalSerialization);

oldNewScriptNameMapping[internalSerialization->getNodeScriptName()] = clone->getNode()->getScriptName();
oldNewScriptNamesMapping[internalSerialization->getNodeScriptName()] = clone->getNode()->getScriptName();
}


assert( serializations.size() == newNodes.size() );
///restore connections
_imp->restoreConnections(serializations, newNodes, oldNewScriptNameMapping);
_imp->restoreConnections(serializations, newNodes, oldNewScriptNamesMapping);


NodesList allNodes;
Expand All @@ -326,8 +326,8 @@ NodeGraph::cloneSelectedNodes(const QPointF& scenePos)
//Restore links once all children are created for alias knobs/expressions
std::list<NodeSerializationPtr>::iterator itS = serializations.begin();
for (std::list<NodeGuiPtr> ::iterator it = newNodesList.begin(); it != newNodesList.end(); ++it, ++itS) {
(*it)->getNode()->storeKnobsLinks(**itS, oldNewScriptNameMapping);
(*it)->getNode()->restoreKnobsLinks(allNodes, oldNewScriptNameMapping, true); // clone should never fail
(*it)->getNode()->storeKnobsLinks(**itS, oldNewScriptNamesMapping);
(*it)->getNode()->restoreKnobsLinks(allNodes, oldNewScriptNamesMapping, true); // clone should never fail
}


Expand Down
2 changes: 1 addition & 1 deletion Gui/NodeGraphPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class NodeGraphPrivate
const NodeCollectionPtr& group,
const std::string& parentName,
bool clone,
std::map<std::string, std::string>* oldNewScriptNameMapping);
std::map<std::string, std::string>* oldNewScriptNamesMapping);


/**
Expand Down
26 changes: 13 additions & 13 deletions Gui/NodeGraphPrivate10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ NodeGraphPrivate::pasteNodesInternal(const NodeClipBoard & clipboard,

///The script-name of the copy node is different than the one of the original one
///We store the mapping so we can restore node links correctly
std::map<std::string, std::string> oldNewScriptNamesMap;
std::map<std::string, std::string> oldNewScriptNamesMapping;
{
CreatingNodeTreeFlag_RAII createNodeTree( _publicInterface->getGui()->getApp() );
const std::list<NodeSerializationPtr>& internalNodesClipBoard = clipboard.nodes;
std::list<NodeSerializationPtr>::const_iterator itOther = internalNodesClipBoard.begin();
for (std::list<NodeGuiSerializationPtr>::const_iterator it = clipboard.nodesUI.begin();
it != clipboard.nodesUI.end(); ++it, ++itOther) {
const std::string& oldScriptName = (*itOther)->getNodeScriptName();
NodeGuiPtr node = pasteNode( *itOther, *it, offset, group.lock(), std::string(), false, &oldNewScriptNamesMap);
NodeGuiPtr node = pasteNode( *itOther, *it, offset, group.lock(), std::string(), false, &oldNewScriptNamesMapping);

if (!node) {
continue;
Expand All @@ -111,20 +111,20 @@ NodeGraphPrivate::pasteNodesInternal(const NodeClipBoard & clipboard,
newNodesMap.push_back( std::make_pair( *itOther, node->getNode() ) );

const std::string& newScriptName = node->getNode()->getScriptName();
oldNewScriptNamesMap[oldScriptName] = newScriptName;
oldNewScriptNamesMapping[oldScriptName] = newScriptName;
}
assert( internalNodesClipBoard.size() == newNodes->size() );

///Now that all nodes have been duplicated, try to restore nodes connections
restoreConnections(internalNodesClipBoard, *newNodes, oldNewScriptNamesMap);
restoreConnections(internalNodesClipBoard, *newNodes, oldNewScriptNamesMapping);

NodesList allNodes;
_publicInterface->getGui()->getApp()->getProject()->getActiveNodesExpandGroups(&allNodes);

//Restore links once all children are created for alias knobs/expressions
for (std::list<std::pair<NodeSerializationPtr, NodePtr> > ::iterator it = newNodesMap.begin(); it != newNodesMap.end(); ++it) {
it->second->storeKnobsLinks(*(it->first), oldNewScriptNamesMap);
it->second->restoreKnobsLinks(allNodes, oldNewScriptNamesMap, false); // may fail
it->second->storeKnobsLinks(*(it->first), oldNewScriptNamesMapping);
it->second->restoreKnobsLinks(allNodes, oldNewScriptNamesMapping, false); // may fail
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ NodeGraphPrivate::pasteNode(const NodeSerializationPtr & internalSerialization,
const NodeCollectionPtr& grp,
const std::string& parentName,
bool clone,
std::map<std::string, std::string>* oldNewScriptNameMapping)
std::map<std::string, std::string>* oldNewScriptNamesMapping)
{
CreateNodeArgs args(internalSerialization->getPluginID(), grp);
args.setProperty<NodeSerializationPtr>(kCreateNodeArgsPropNodeSerialization, internalSerialization);
Expand Down Expand Up @@ -240,7 +240,7 @@ NodeGraphPrivate::pasteNode(const NodeSerializationPtr & internalSerialization,
assert( nodes.size() == nodesUi.size() || nodesUi.empty() );

if ( internalSerialization->getNodeScriptName() != n->getScriptName() ) {
(*oldNewScriptNameMapping)[internalSerialization->getNodeScriptName()] = n->getScriptName();
(*oldNewScriptNamesMapping)[internalSerialization->getNodeScriptName()] = n->getScriptName();
}

// For PyPlugs, don't recurse otherwise we would recreate all nodes on top of the ones created by the python script
Expand All @@ -259,11 +259,11 @@ NodeGraphPrivate::pasteNode(const NodeSerializationPtr & internalSerialization,
std::list<NodeGuiSerializationPtr>::const_iterator itUi = nodesUi.begin();
for (std::list<NodeSerializationPtr>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
NodeGuiSerializationPtr guiS = nodesUi.empty() ? NodeGuiSerializationPtr() : *itUi;
NodeGuiPtr newChild = pasteNode(*it, guiS, QPointF(0, 0), collection, parentName, clone, oldNewScriptNameMapping);
NodeGuiPtr newChild = pasteNode(*it, guiS, QPointF(0, 0), collection, parentName, clone, oldNewScriptNamesMapping);
if (newChild) {
newNodes.push_back( std::make_pair( (*it)->getNodeScriptName(), newChild ) );
if ( (*it)->getNodeScriptName() != newChild->getNode()->getScriptName() ) {
(*oldNewScriptNameMapping)[(*it)->getNodeScriptName()] = newChild->getNode()->getScriptName();
(*oldNewScriptNamesMapping)[(*it)->getNodeScriptName()] = newChild->getNode()->getScriptName();
}
allNodes.push_back( newChild->getNode() );
newNodesMap.push_back(std::make_pair(*it,newChild->getNode()));
Expand All @@ -272,12 +272,12 @@ NodeGraphPrivate::pasteNode(const NodeSerializationPtr & internalSerialization,
++itUi;
}
}
restoreConnections(nodes, newNodes, *oldNewScriptNameMapping);
restoreConnections(nodes, newNodes, *oldNewScriptNamesMapping);

//Restore links once all children are created for alias knobs/expressions
for (std::list<std::pair<NodeSerializationPtr, NodePtr> > ::iterator it = newNodesMap.begin(); it != newNodesMap.end(); ++it) {
it->second->storeKnobsLinks(*(it->first), *oldNewScriptNameMapping);
it->second->restoreKnobsLinks(allNodes, *oldNewScriptNameMapping, false); // may fail
it->second->storeKnobsLinks(*(it->first), *oldNewScriptNamesMapping);
it->second->restoreKnobsLinks(allNodes, *oldNewScriptNamesMapping, false); // may fail
}
}

Expand Down

0 comments on commit 67afa2d

Please sign in to comment.