MCPcopy Create free account
hub / github.com/MrKepzie/Natron / restoreFromSerialization

Method restoreFromSerialization

Engine/NodeGroupSerialization.cpp:82–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82bool
83NodeCollectionSerialization::restoreFromSerialization(const std::list< boost::shared_ptr<NodeSerialization> > & serializedNodes,
84 const boost::shared_ptr<NodeCollection>& group,
85 bool createNodes,
86 std::map<std::string, bool>* moduleUpdatesProcessed)
87{
88 bool mustShowErrorsLog = false;
89 NodeGroup* isNodeGroup = dynamic_cast<NodeGroup*>( group.get() );
90 QString groupName;
91
92 if (isNodeGroup) {
93 groupName = QString::fromUtf8( isNodeGroup->getNode()->getLabel().c_str() );
94 } else {
95 groupName = tr("top-level");
96 }
97 AppInstPtr appInst = group->getApplication();
98 if (!appInst) {
99 return !mustShowErrorsLog;
100 }
101 appInst->updateProjectLoadStatus( tr("Creating nodes in group: %1").arg(groupName) );
102
103 ///If a parent of a multi-instance node doesn't exist anymore but the children do, we must recreate the parent.
104 ///Problem: we have lost the nodes connections. To do so we restore them using the serialization of a child.
105 ///This map contains all the parents that must be reconnected and an iterator to the child serialization
106 std::map<NodePtr, std::list<boost::shared_ptr<NodeSerialization> >::const_iterator > parentsToReconnect;
107 std::list< boost::shared_ptr<NodeSerialization> > multiInstancesToRecurse;
108 std::map<NodePtr, boost::shared_ptr<NodeSerialization> > createdNodes;
109 for (std::list< boost::shared_ptr<NodeSerialization> >::const_iterator it = serializedNodes.begin(); it != serializedNodes.end(); ++it) {
110 std::string pluginID = (*it)->getPluginID();
111
112 if ( appPTR->isBackground() && ( (pluginID == PLUGINID_NATRON_VIEWER) || (pluginID == "Viewer") ) ) {
113 //if the node is a viewer, don't try to load it in background mode
114 continue;
115 }
116
117 ///If the node is a multiinstance child find in all the serialized nodes if the parent exists.
118 ///If not, create it
119
120 if ( !(*it)->getMultiInstanceParentName().empty() ) {
121 bool foundParent = false;
122 for (std::list< boost::shared_ptr<NodeSerialization> >::const_iterator it2 = serializedNodes.begin();
123 it2 != serializedNodes.end(); ++it2) {
124 if ( (*it2)->getNodeScriptName() == (*it)->getMultiInstanceParentName() ) {
125 foundParent = true;
126 break;
127 }
128 }
129 if (!foundParent) {
130 ///Maybe it was created so far by another child who created it so look into the nodes
131
132 NodePtr parent = group->getNodeByName( (*it)->getMultiInstanceParentName() );
133 if (parent) {
134 foundParent = true;
135 }
136 ///Create the parent
137 if (!foundParent) {
138 CreateNodeArgs args(pluginID, group);
139 args.setProperty<bool>(kCreateNodeArgsPropSilent, true);

Callers

nothing calls this directly

Calls 15

lookForFileRecursivelyFunction · 0.85
getApplicationMethod · 0.80
emptyMethod · 0.80
getNodeByNameMethod · 0.80
appendMethod · 0.80
toStdStringMethod · 0.80
getCurrentSettingsMethod · 0.80
removeMethod · 0.80
getPluginMethod · 0.80

Tested by

no test coverage detected