[core][io] store nodes position in graph file

* increment file minor version (no incompatibility)
* nodeFactory: reload file position if available
This commit is contained in:
Yann Lanthony 2018-07-26 15:08:20 +02:00
parent dfb0934ef4
commit e2155ba962
2 changed files with 10 additions and 3 deletions

View file

@ -162,7 +162,7 @@ class Graph(BaseObject):
class IO(object):
""" Centralize Graph file keys and IO version. """
__version__ = "1.0"
__version__ = "1.1"
class Keys(object):
""" File Keys. """
@ -179,6 +179,7 @@ class Graph(BaseObject):
Header = "header"
NodesVersions = "nodesVersions"
PrecomputedOutputs = "precomputedOutputs"
NodesPositions = "nodesPositions"
@staticmethod
def getFeaturesForVersion(fileVersion):
@ -199,6 +200,8 @@ class Graph(BaseObject):
Graph.IO.Features.NodesVersions,
Graph.IO.Features.PrecomputedOutputs,
]
if fileVersion >= Version("1.1"):
features += [Graph.IO.Features.NodesPositions]
return features
def __init__(self, name, parent=None):

View file

@ -669,6 +669,7 @@ class Node(BaseNode):
return {
'nodeType': self.nodeType,
'position': self._position,
'parallelization': {
'blockSize': self.nodeDesc.parallelization.blockSize if self.isParallelized else 0,
'size': self.size,
@ -883,6 +884,8 @@ class CompatibilityNode(BaseNode):
"""
# update inputs to get up-to-date connections
self.nodeDict.update({"inputs": self.inputs})
# update position
self.nodeDict.update({"position": self.position})
return self.nodeDict
@property
@ -931,6 +934,7 @@ def nodeFactory(nodeDict, name=None):
outputs = nodeDict.get("outputs", {})
version = nodeDict.get("version", None)
internalFolder = nodeDict.get("internalFolder", None)
position = Position(*nodeDict.get("position", []))
compatibilityIssue = None
@ -956,11 +960,11 @@ def nodeFactory(nodeDict, name=None):
# no compatibility issues: instantiate a Node
if compatibilityIssue is None:
n = Node(nodeType, **inputs)
n = Node(nodeType, position, **inputs)
# otherwise, instantiate a CompatibilityNode
else:
logging.warning("Compatibility issue detected for node '{}': {}".format(name, compatibilityIssue.name))
n = CompatibilityNode(nodeType, nodeDict, compatibilityIssue)
n = CompatibilityNode(nodeType, nodeDict, position, compatibilityIssue)
# retro-compatibility: no internal folder saved
# can't spawn meaningful CompatibilityNode with precomputed outputs
# => automatically try to perform node upgrade