def createVariable(self, dataType=str('AnyPin'), accessLevel=AccessLevel.public, uid=None, name=str("var")): """Creates variable inside this graph scope :param dataType: Variable data type :type dataType: str :param accessLevel: Variable access level :type accessLevel: :class:`~PyFlow.Core.Common.AccessLevel` :param uid: Variable unique identifier :type uid: :class:`uuid.UUID` :param name: Variable name :type name: str """ name = self.graphManager.getUniqVariableName(name) var = Variable(self, getPinDefaultValueByType(dataType), name, dataType, accessLevel=accessLevel, uid=uid) self._vars[var.uid] = var return var
def populateFromJson(self, jsonData): self.clear() parentGraphName = jsonData['parentGraphName'] parentGraph = self.graphManager.findGraph(parentGraphName) self.parentGraph = parentGraph self.name = jsonData['name'] self.category = jsonData['category'] self.setIsRoot(jsonData['isRoot']) # restore vars for varJson in jsonData['vars']: var = Variable.deserialize(self, varJson) self.vars[var.uid] = var # restore nodes for nodeJson in jsonData['nodes']: # check if variable getter or setter and pass variable nodeArgs = () nodeKwargs = {} if nodeJson['type'] in ('getVar', 'setVar'): nodeKwargs['var'] = self.vars[uuid.UUID(nodeJson['varUid'])] nodeJson['owningGraphName'] = self.name node = getRawNodeInstance(nodeJson['type'], packageName=nodeJson['package'], libName=nodeJson['lib'], *nodeArgs, **nodeKwargs) self.addNode(node, nodeJson) # restore connections for nodeJson in jsonData['nodes']: for nodeOutputJson in nodeJson['outputs']: lhsPin = self.findPin(str(nodeOutputJson['fullName'])) for rhsPinFullName in nodeOutputJson['linkedTo']: rhsPin = self.findPin(str(rhsPinFullName)) connected = connectPins(lhsPin, rhsPin) assert (connected is True), "Failed to restore connection"
def populateFromJson(self, jsonData): """Populates itself from serialized data :param jsonData: serialized graph :type jsonData: dict """ self.clear() parentGraphName = jsonData['parentGraphName'] parentGraph = self.graphManager.findGraph(parentGraphName) self.parentGraph = parentGraph self.name = self.graphManager.getUniqGraphName(jsonData['name']) self.category = jsonData['category'] self.setIsRoot(jsonData['isRoot']) if self.isRoot(): self.name = "root" # restore vars for varJson in jsonData['vars']: var = Variable.deserialize(self, varJson) self._vars[var.uid] = var # restore nodes for nodeJson in jsonData['nodes']: # check if variable getter or setter and pass variable nodeArgs = () nodeKwargs = {} if nodeJson['type'] in ('getVar', 'setVar'): nodeKwargs['var'] = self._vars[uuid.UUID(nodeJson['varUid'])] nodeJson['owningGraphName'] = self.name node = getRawNodeInstance(nodeJson['type'], packageName=nodeJson['package'], libName=nodeJson['lib'], *nodeArgs, **nodeKwargs) self.addNode(node, nodeJson) # restore connection for nodeJson in jsonData['nodes']: for nodeOutputJson in nodeJson['outputs']: for linkData in nodeOutputJson['linkedTo']: try: lhsNode = self._nodes[uuid.UUID(linkData["lhsNodeUid"])] except Exception as e: lhsNode = self.findNode(linkData["lhsNodeName"]) try: lhsPin = lhsNode.orderedOutputs[linkData["outPinId"]] except Exception as e: continue try: rhsNode = self._nodes[uuid.UUID(linkData["rhsNodeUid"])] except Exception as e: rhsNode = self.findNode(linkData["rhsNodeName"]) try: rhsPin = rhsNode.orderedInputs[linkData["inPinId"]] except Exception as e: continue if not arePinsConnected(lhsPin, rhsPin): connected = connectPins(lhsPin, rhsPin) # assert(connected is True), "Failed to restore connection" if not connected: print("Failed to restore connection", lhsPin, rhsPin) connectPins(lhsPin, rhsPin)
def createVariable(self, dataType=str('AnyPin'), accessLevel=AccessLevel.public, uid=None, name=str("var")): name = self.graphManager.getUniqVariableName(name) var = Variable(self, getPinDefaultValueByType(dataType), name, dataType, accessLevel=accessLevel, uid=uid) self.vars[var.uid] = var return var