def displayGraph(self, rig): self.reset() self.__rig = rig guideComponents = self.__rig.getChildrenByType('Component') print "displayGraph :", guideComponents for component in guideComponents: node = KNode(self, component) self.addNode(node) for component in guideComponents: for i in range(component.getNumInputs()): componentInput = component.getInputByIndex(i) if componentInput.isConnected(): componentOutput = componentInput.getConnection() self.connectPorts( srcNode=componentOutput.getParent().getDecoratedName(), outputName=componentOutput.getName(), tgtNode=component.getDecoratedName(), inputName=componentInput.getName()) # Get backdrops from meta data metaData = self.__rig.getMetaData() if 'backdrops' in metaData: for backdrop in metaData['backdrops']: backdropNode = KBackdrop(self, backdrop.get('name', 'Backdrop')) self.addNode(backdropNode) backdropNode.setData(backdrop) self.frameAllNodes()
def displayGraph(self, rig): print "KGraphView.displayGraph" self.reset() self.__rig = rig guideComponents = self.__rig.getChildrenByType('Component') for component in guideComponents: node = KNode(self, component) self.addNode(node)
def createNode(self): if self.nodesList.currentItem() is not None: componentClassName = self.nodesList.currentItem().data( QtCore.Qt.UserRole) componentClass = self.ks.getComponentClass(componentClassName) component = componentClass(parent=self.graph.getRig()) component.setGraphPos(Vec2(self.graphpos.x(), self.graphpos.y())) self.graph.addNode(KNode(self.graph, component)) if self.isVisible(): self.close()
def createNode(self): if self.nodesList.currentItem() is not None: componentClassName = self.nodesList.currentItem().data( QtCore.Qt.UserRole) componentClass = self.ks.getComponentClass(componentClassName) component = componentClass(parent=self.graph.getRig()) component.setGraphPos(Vec2(self.graphpos.x(), self.graphpos.y())) node = KNode(self.graph, component) self.graph.addNode(node) self.graph.selectNode(node, clearSelection=True, emitSignal=False) if self.isVisible(): self.close()
def dropEvent(self, event): textParts = event.mimeData().text().split(':') if textParts[0] == 'KrakenComponent': componentClassName = textParts[1] # Add a component to the rig placed at the given position. dropPosition = self.mapToScene(event.pos()) # construct the node and add it to the graph. krakenSystem = KrakenSystem.getInstance() componentClass = krakenSystem.getComponentClass(componentClassName) component = componentClass(parent=self.getRig()) component.setGraphPos(Vec2(dropPosition.x(), dropPosition.y())) self.addNode(KNode(self, component)) event.acceptProposedAction() else: super(GraphView, self).dropEvent(event)
def dropEvent(self, event): textParts = event.mimeData().text().split(':') print "dropEvent.textParts :%s" % (textParts) if textParts[0] == 'BeamComponent': componentClassName = textParts[1] # Add a component to the rig placed at the given position. dropPosition = self.mapToScene(event.pos()) # construct the node and add it to the graph. beamSystem = BeamSystem.getInstance() componentClass = beamSystem.getComponentClass(componentClassName) component = componentClass(parent=self.getRig()) component.setGraphPos(Vec2(dropPosition.x(), dropPosition.y())) node = KNode(self, component) self.addNode(node) self.selectNode(node, clearSelection=True, emitSignal=False) event.acceptProposedAction() else: super(GraphView, self).dropEvent(event)
def displayGraph(self, rig): self.reset() self.__rig = rig guideComponents = self.__rig.getChildrenByType('Component') for component in guideComponents: self.addNode(KNode(self, component)) for component in guideComponents: for i in range(component.getNumInputs()): componentInput = component.getInputByIndex(i) if componentInput.isConnected(): componentOutput = componentInput.getConnection() self.connectPorts( srcNode=componentOutput.getParent().getDecoratedName(), outputName=componentOutput.getName(), tgtNode=component.getDecoratedName(), inputName=componentInput.getName()) self.frameAllNodes()
def pasteSettings(self, pos, mirrored=False, createConnectionsToExistingNodes=True): clipboardData = self.__class__._clipboardData krakenSystem = BeamSystem.getInstance() delta = pos - clipboardData['copyPos'] self.clearSelection() pastedComponents = {} nameMapping = {} for componentData in clipboardData['components']: componentClass = krakenSystem.getComponentClass( componentData['class']) component = componentClass(parent=self.__rig) decoratedName = componentData[ 'name'] + component.getNameDecoration() nameMapping[decoratedName] = decoratedName if mirrored: config = Config.getInstance() mirrorMap = config.getNameTemplate()['mirrorMap'] component.setLocation(mirrorMap[componentData['location']]) nameMapping[decoratedName] = componentData[ 'name'] + component.getNameDecoration() component.pasteData(componentData, setLocation=False) else: component.pasteData(componentData, setLocation=True) graphPos = component.getGraphPos() component.setGraphPos( Vec2(graphPos.x + delta.x(), graphPos.y + delta.y())) node = KNode(self, component) self.addNode(node) self.selectNode(node, False) # save a dict of the nodes using the orignal names pastedComponents[nameMapping[decoratedName]] = component # Create Connections for connectionData in clipboardData['connections']: sourceComponentDecoratedName, outputName = connectionData[ 'source'].split('.') targetComponentDecoratedName, inputName = connectionData[ 'target'].split('.') sourceComponent = None # The connection is either between nodes that were pasted, or from pasted nodes # to unpasted nodes. We first check that the source component is in the pasted group # else use the node in the graph. if sourceComponentDecoratedName in nameMapping: sourceComponent = pastedComponents[ nameMapping[sourceComponentDecoratedName]] else: if not createConnectionsToExistingNodes: continue # When we support copying/pasting between rigs, then we may not find the source # node in the target rig. if not self.hasNode(sourceComponentDecoratedName): continue node = self.getNode(sourceComponentDecoratedName) sourceComponent = node.getComponent() targetComponentDecoratedName = nameMapping[ targetComponentDecoratedName] targetComponent = pastedComponents[targetComponentDecoratedName] outputPort = sourceComponent.getOutputByName(outputName) inputPort = targetComponent.getInputByName(inputName) inputPort.setConnection(outputPort) self.connectPorts(srcNode=sourceComponent.getDecoratedName(), outputName=outputPort.getName(), tgtNode=targetComponent.getDecoratedName(), inputName=inputPort.getName())
def pasteSettings(self, pos, mirrored=False, createConnectionsToExistingNodes=True): clipboardData = self.__class__._clipboardData krakenSystem = KrakenSystem.getInstance() delta = pos - clipboardData['copyPos'] self.clearSelection() pastedComponents = {} nameMapping = {} for componentData in clipboardData['components']: componentClass = krakenSystem.getComponentClass(componentData['class']) component = componentClass(parent=self.__rig) decoratedName = componentData['name'] + component.getNameDecoration() nameMapping[decoratedName] = decoratedName if mirrored: config = Config.getInstance() mirrorMap = config.getNameTemplate()['mirrorMap'] component.setLocation(mirrorMap[componentData['location']]) nameMapping[decoratedName] = componentData['name'] + component.getNameDecoration() component.pasteData(componentData, setLocation=False) else: component.pasteData(componentData, setLocation=True) graphPos = component.getGraphPos() component.setGraphPos(Vec2(graphPos.x + delta.x(), graphPos.y + delta.y())) node = KNode(self, component) self.addNode(node) self.selectNode(node, False) # save a dict of the nodes using the orignal names pastedComponents[nameMapping[decoratedName]] = component for connectionData in clipboardData['connections']: sourceComponentDecoratedName, outputName = connectionData['source'].split('.') targetComponentDecoratedName, inputName = connectionData['target'].split('.') sourceComponent = None # The connection is either between nodes that were pasted, or from pasted nodes # to unpasted nodes. We first check that the source component is in the pasted group # else use the node in the graph. if sourceComponentDecoratedName in nameMapping: sourceComponent = pastedComponents[nameMapping[sourceComponentDecoratedName]] else: if not createConnectionsToExistingNodes: continue # When we support copying/pasting between rigs, then we may not find the source # node in the target rig. if not self.hasNode(sourceComponentDecoratedName): continue node = self.getNode(sourceComponentDecoratedName) sourceComponent = node.getComponent() targetComponentDecoratedName = nameMapping[targetComponentDecoratedName] targetComponent = pastedComponents[targetComponentDecoratedName] outputPort = sourceComponent.getOutputByName(outputName) inputPort = targetComponent.getInputByName(inputName) inputPort.setConnection(outputPort) self.connectPorts( srcNode=sourceComponent.getDecoratedName(), outputName=outputPort.getName(), tgtNode=targetComponent.getDecoratedName(), inputName=inputPort.getName() )