def addGfxLink(self, link): # if DEBUG_MODE: print '>> WorkArea::addGfxLink (id=%d)' % link.id gfxLink = GfxLink(link) (srcNode, srcParam) = link.getSrc() (dstNode, dstParam) = link.getDst() srcConnector = None dstConnector = None for item in self.scene().items(): if isinstance(item, GfxNode) or isinstance(item, GfxSwatchNode): if item.node == srcNode: srcConnector = item.getOutputConnectorByParam(srcParam) elif item.node == dstNode: dstConnector = item.getInputConnectorByParam(dstParam) elif isinstance(item, GfxNodeConnector) and item.isNode(): if item.node == srcNode: srcConnector = item elif item.node == dstNode: dstConnector = item if (srcConnector != None and dstConnector != None): break gfxLink.setSrcConnector(srcConnector) gfxLink.setDstConnector(dstConnector) gfxLink.adjust() self.scene().addItem(gfxLink)
def addGfxLink ( self, link ) : # if DEBUG_MODE : print '>> WorkArea::addGfxLink (id=%d)' % link.id gfxLink = GfxLink ( link ) ( srcNode, srcParam ) = link.getSrc () ( dstNode, dstParam ) = link.getDst () srcConnector = None dstConnector = None for item in self.scene ().items (): if isinstance ( item, GfxNode ) or isinstance ( item, GfxSwatchNode ) : if item.node == srcNode : srcConnector = item.getOutputConnectorByParam ( srcParam ) elif item.node == dstNode : dstConnector = item.getInputConnectorByParam ( dstParam ) elif isinstance ( item, GfxNodeConnector ) and item.isNode () : if item.node == srcNode : srcConnector = item elif item.node == dstNode : dstConnector = item if ( srcConnector != None and dstConnector != None ) : break gfxLink.setSrcConnector ( srcConnector ) gfxLink.setDstConnector ( dstConnector ) gfxLink.adjust () self.scene ().addItem ( gfxLink )
def addGfxLink ( self, link ) : # #print '>> WorkArea: addGfxLink' gfxLink = GfxLink( link ) srcNode = link.srcNode dstNode = link.dstNode srcParam = link.srcParam dstParam = link.dstParam srcConnector = None dstConnector = None for item in self.scene().items(): if isinstance ( item, GfxNode ): if item.node == srcNode : srcConnector = item.getOutputConnectorByParam ( srcParam ) elif item.node == dstNode : dstConnector = item.getInputConnectorByParam ( dstParam ) if ( srcConnector != None and dstConnector != None ) : break gfxLink.setSrcConnector ( srcConnector ) gfxLink.setDstConnector ( dstConnector ) gfxLink.adjust () self.scene().addItem ( gfxLink )
def onStartNodeLink(self, connector): # #if DEBUG_MODE : print '>> WorkArea::onStartNodeLink' #if DEBUG_MODE : print connector srcNode = connector.getNode() srcParam = connector.param if DEBUG_MODE: print '>> WorkArea::onStartNodeLink from %s (%s)' % ( srcNode.label, srcParam.label) srcConnector = connector self.state = 'traceNodeLink' self.lastConnectCandidate = None if connector.isInput() and connector.isLinked(): oldLink = connector.getFirstGfxLink() srcConnector = oldLink.srcConnector oldLink.remove() gfxLink = GfxLink(None, srcConnector) self.scene().addItem(gfxLink) self.currentGfxLink = gfxLink self.currentGfxLink.isLinkSelected = True
def onStartNodeConnector(self, connector, scenePos): # if DEBUG_MODE: print '>> WorkArea::onStartNodeConnector' self.state = 'traceNodeConnector' newNode = ConnectorNode() self.nodeNet.addNode(newNode) newParam = connector.param.copy() newParam.isInput = False newInParam = newParam.copy() newOutParam = newParam.copy() newNode.addInputParam(newInParam) newNode.addOutputParam(newOutParam) newConnector = GfxNodeConnector(newParam, connector.radius, node=newNode) newConnector.brush = connector.brush newConnector.setPos(scenePos) newConnector.moveBy(-connector.radius, -connector.radius) self.lastConnectCandidate = newConnector self.scene().addItem(newConnector) newConnector.hilite(True) srcNode = connector.getNode() srcParam = connector.getOutputParam() dstNode = newConnector.getNode() dstParam = newConnector.getInputParam() # # swap link direction only for connectors # in open chain connected to input node parameter # swappedLink = False if connector.isConnectedToInput( ) and not connector.isConnectedToOutput(): if DEBUG_MODE: print '*** swap link direction ***' swappedLink = True srcNode = newConnector.getNode() srcParam = newConnector.getOutputParam() dstNode = connector.getNode() dstParam = connector.getInputParam() link = NodeLink.build(srcNode, dstNode, srcParam, dstParam) # if swappedLink : link.swapNodes () self.nodeNet.addLink(link) #if DEBUG_MODE : self.nodeNet.printInfo () # preserve existing links for parameter connectors if connector.isLinked() and not connector.isNode(): if connector.isInput(): #print '*** preserve input ***' # TODO!!! # This is very rough code -- needs to be wrapped in functions gfxLinks = connector.getInputGfxLinks() for gfxLink in gfxLinks: gfxLink.setDstConnector(newConnector) # remove gfxLink from previouse connector connector.removeGfxLink(gfxLink) # adjust destination for node link newConnector.getNode().attachInputParamToLink( newConnector.getInputParam(), gfxLink.link) newConnector.getNode().addChild(gfxLink.link.srcNode) connector.getNode().removeChild(gfxLink.link.srcNode) gfxLink.link.dstNode = newConnector.getNode() gfxLink.link.dstParam = newConnector.getInputParam() else: #print '*** preserve output ***' gfxLinks = connector.getOutputGfxLinks() for gfxLink in gfxLinks: gfxLink.setSrcConnector(newConnector) # remove gfxLink from previouse connector connector.removeGfxLink(gfxLink) # adjust source for node link connector.getNode().detachOutputParamFromLink( gfxLink.link.srcParam, gfxLink.link) newConnector.getNode().attachOutputParamToLink( newConnector.getOutputParam(), gfxLink.link) #newConnector.getNode ().childs.add ( connector.getNode () ) gfxLink.link.dstNode.addChild(newConnector.getNode()) gfxLink.link.dstNode.removeChild(connector.getNode()) gfxLink.link.srcNode = newConnector.getNode() gfxLink.link.srcParam = newConnector.getOutputParam() #if DEBUG_MODE : self.nodeNet.printInfo () gfxLink = GfxLink(link, connector, newConnector) self.scene().addItem(gfxLink)