def addGfxNodeParam ( self, param ) : # if DEBUG_MODE : print ">> GfxNode.addGfxNodeParam (%s)" % param.label if param.isInput : labels = self.inputParamLabels connectors = self.inputConnectors else : labels = self.outputParamLabels connectors = self.outputConnectors label = GfxNodeLabel ( param.label, param ) label.setBgColor ( self.bgColor ) label.setNormalColor ( self.normalColor ) if not param.isInput : label.setBold () if param.help is not None : label.setWhatsThis ( self.node.help ) self.updateGfxNodeParamLabel ( param, label ) labels.append ( label ) connector = GfxNodeConnector ( param, UI.CONNECTOR_RADIUS, node = None ) if not param.isInput : connector.singleLinkOnly = False connectors.append ( connector )
def setupParams ( self, params, labels, connectors, updateConnectors = True ): # for param in params : # ignore attributes if param.provider != 'attribute' : label = GfxNodeLabel ( param.label, param ) label.setBgColor ( self.bgColor ) label.setNormalColor ( self.normalColor ) if not param.isInput : label.setBold () if param.help is not None : label.setWhatsThis ( self.node.help ) if param.type in VALID_RSL_PARAM_TYPES : label.setNormal () isVarying = ( param.detail == 'varying' ) isPrimitive = ( param.provider == 'primitive' ) label.setItalic ( isVarying ) label.setSelected ( param.shaderParam ) label.setAlternate ( isPrimitive ) # this allows to change param.shaderParam attribute by CTRL-click on label # and switch param.provide to "primitive" by ALT-click label.setProcessEvents ( True ) labels.append ( label ) if updateConnectors : connector = GfxNodeConnector ( param, UI.CONNECTOR_RADIUS, node = None ) if not param.isInput : connector.singleLinkOnly = False connectors.append ( connector )
def setupParams ( self, params, labels, connectors ): for param in params : # ignore attributes if param.provider != 'attribute' : label = GfxNodeLabel ( param.label ) label.brush = self.BrushNodeNormal label.PenNormal = self.PenBorderNormal if not param.isInput : label.font.setBold( True ) if param.shaderParam : #label.font.setBold( True ) label.PenNormal = self.PenNodeShaderParam labels.append( label ) connector = GfxNodeConnector ( param, 5 ) if not param.isInput: connector.singleLinkOnly = False if param.encodedTypeStr() in self.paramsBrushes.keys() : connector.brush = self.paramsBrushes[ param.encodedTypeStr() ] connectors.append ( connector )
def setupConnectors(self): # for param in self.node.inputParams: # ignore attributes if param.provider != 'attribute': connector = GfxNodeConnector(param, UI.CONNECTOR_RADIUS, node=None) self.inputConnectors.append(connector)
def addGfxNode(self, node, pos=None): # #print ( ">> WorkArea: addGfxNode %s" % node.label ) if node.type == 'connector': gfxNode = GfxNodeConnector(node.inputParams[0], node=node) elif node.type == 'note': gfxNode = GfxNote(node) elif node.type == 'swatch': gfxNode = GfxSwatchNode(node) else: gfxNode = GfxNode(node) scene = self.scene() if pos != None: gfxNode.moveBy(pos.x(), pos.y()) #for item in scene.selectedItems (): item.setSelected ( False ) scene.addItem(gfxNode) gfxNode.setSelected(True) if usePyQt4: self.emit(QtCore.SIGNAL('gfxNodeAdded'), gfxNode) else: self.gfxNodeAdded.emit(gfxNode)
def addGfxNode ( self, node, pos = None ) : # #print ( ">> WorkArea: addGfxNode %s" % node.label ) if node.type == 'connector' : gfxNode = GfxNodeConnector ( node.inputParams [ 0 ], node = node ) elif node.type == 'note' : gfxNode = GfxNote ( node ) elif node.type == 'swatch' : gfxNode = GfxSwatchNode ( node ) else : gfxNode = GfxNode ( node ) scene = self.scene () if pos != None : gfxNode.moveBy ( pos.x(), pos.y() ) #for item in scene.selectedItems (): item.setSelected ( False ) scene.addItem ( gfxNode ) gfxNode.setSelected ( True ) if usePyQt4 : self.emit ( QtCore.SIGNAL ( 'gfxNodeAdded' ), gfxNode ) else : self.gfxNodeAdded.emit ( gfxNode )
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)
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 )