Beispiel #1
0
  def onEndNodeLink ( self, connector, scenePos ):
    srcConnector = self.currentGfxLink.srcConnector
    dstConnector = self.currentGfxLink.dstConnector
    
    if self.lastConnectCandidate is None :
      self.currentGfxLink.remove()
      #self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), srcConnector.parentItem(), srcConnector.param )
      #self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), dstConnector.parentItem(), dstConnector.param ) 
    else :
      # remove old link first if it exists      
      if self.lastConnectCandidate.isInput() and self.lastConnectCandidate.isLinked() :
        oldLink = self.lastConnectCandidate.getFirstLink() 
        oldLink.remove()  

      self.currentGfxLink.isLinkSelected = False
      self.currentGfxLink.update()
      
      srcNode = srcConnector.parentItem().node
      srcParam = srcConnector.param

      dstNode = self.lastConnectCandidate.parentItem().node
      dstParam = self.lastConnectCandidate.param
      
      self.currentGfxLink.setDstConnector ( self.lastConnectCandidate )
      link = NodeLink.build ( srcNode, dstNode, srcParam, dstParam )

      if dstParam.isInput is not True :
        # swap source and destination
        self.currentGfxLink.swapConnectors()
        link.swapNodes()

      self.currentGfxLink.link = link
      self.nodeNet.addLink ( link ) 
      self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), self.currentGfxLink.srcConnector.parentItem(), self.currentGfxLink.srcConnector.param )
      self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), self.currentGfxLink.dstConnector.parentItem(), self.currentGfxLink.dstConnector.param ) 
    
    self.lastConnectCandidateReset ()
    self.currentGfxLink = None
    self.state = 'idle'
Beispiel #2
0
    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)
Beispiel #3
0
    def onEndNodeLink(self, connector, scenePos):
        #
        srcConnector = self.currentGfxLink.srcConnector
        dstConnector = self.currentGfxLink.dstConnector
        swappedLink = False
        if srcConnector is None:  # link has swapped connectors
            swappedLink = True

        if self.lastConnectCandidate is None:
            self.currentGfxLink.remove()
            #self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), srcConnector.parentItem(), srcConnector.param )
            #self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), dstConnector.parentItem(), dstConnector.param )
        else:
            if self.lastConnectCandidate.isNode():
                # if connection was made to ConnectorNode
                if dstConnector is None:
                    self.lastConnectCandidate.removeInputGfxLinks()
            else:
                # remove old link first if it exists
                if self.lastConnectCandidate.isInput(
                ) and self.lastConnectCandidate.isLinked():
                    #oldLink = self.lastConnectCandidate.getFirstLink ()
                    #oldLink.remove ()
                    self.lastConnectCandidate.removeInputGfxLinks()

            self.currentGfxLink.isLinkSelected = False
            self.currentGfxLink.update()

            srcNode = dstNode = None
            srcParam = dstParam = None

            if swappedLink:
                srcNode = self.lastConnectCandidate.getNode()
                srcParam = self.lastConnectCandidate.param
                if self.lastConnectCandidate.isNode():
                    srcParam = self.lastConnectCandidate.getFirstOutputParam()
                dstNode = dstConnector.getNode()
                dstParam = dstConnector.param
                self.currentGfxLink.setSrcConnector(self.lastConnectCandidate)
            else:
                srcNode = srcConnector.getNode()
                srcParam = srcConnector.param
                dstNode = self.lastConnectCandidate.getNode()
                dstParam = self.lastConnectCandidate.param
                if self.lastConnectCandidate.isNode():
                    dstParam = self.lastConnectCandidate.getFirstInputParam()
                self.currentGfxLink.setDstConnector(self.lastConnectCandidate)

            link = NodeLink.build(srcNode, dstNode, srcParam, dstParam)

            #if not dstParam.isInput :
            # swap source and destination
            #  self.currentGfxLink.swapConnectors ()
            #  link.swapNodes ()

            self.currentGfxLink.link = link
            self.nodeNet.addLink(link)
            if usePyQt4:
                self.emit(QtCore.SIGNAL('nodeConnectionChanged'),
                          self.currentGfxLink.dstConnector.getGfxNode(),
                          self.currentGfxLink.dstConnector.param)
            else:
                self.nodeConnectionChanged.emit(
                    self.currentGfxLink.dstConnector.getGfxNode(),
                    self.currentGfxLink.dstConnector.param)

        self.lastConnectCandidateReset()
        self.currentGfxLink = None
        self.state = 'idle'
Beispiel #4
0
	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 )
Beispiel #5
0
	def onEndNodeLink ( self, connector, scenePos ) :
		#
		srcConnector = self.currentGfxLink.srcConnector
		dstConnector = self.currentGfxLink.dstConnector
		swappedLink = False
		if srcConnector is None : # link has swapped connectors
			swappedLink = True

		if self.lastConnectCandidate is None :
			self.currentGfxLink.remove ()
			#self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), srcConnector.parentItem(), srcConnector.param )
			#self.emit( QtCore.SIGNAL( 'nodeParamChanged' ), dstConnector.parentItem(), dstConnector.param )
		else :
			if self.lastConnectCandidate.isNode () :
				# if connection was made to ConnectorNode
				if dstConnector is None :
					self.lastConnectCandidate.removeInputGfxLinks ()
			else :
				# remove old link first if it exists
				if self.lastConnectCandidate.isInput () and self.lastConnectCandidate.isLinked () :
					#oldLink = self.lastConnectCandidate.getFirstLink ()
					#oldLink.remove ()
					self.lastConnectCandidate.removeInputGfxLinks ()

			self.currentGfxLink.isLinkSelected = False
			self.currentGfxLink.update ()

			srcNode = dstNode = None
			srcParam = dstParam = None

			if swappedLink :
				srcNode = self.lastConnectCandidate.getNode ()
				srcParam = self.lastConnectCandidate.param
				if self.lastConnectCandidate.isNode () :
					srcParam = self.lastConnectCandidate.getFirstOutputParam ()
				dstNode = dstConnector.getNode ()
				dstParam = dstConnector.param
				self.currentGfxLink.setSrcConnector ( self.lastConnectCandidate )
			else :
				srcNode = srcConnector.getNode ()
				srcParam = srcConnector.param
				dstNode = self.lastConnectCandidate.getNode ()
				dstParam = self.lastConnectCandidate.param
				if self.lastConnectCandidate.isNode () :
					dstParam = self.lastConnectCandidate.getFirstInputParam ()
				self.currentGfxLink.setDstConnector ( self.lastConnectCandidate )

			link = NodeLink.build ( srcNode, dstNode, srcParam, dstParam )

			#if not dstParam.isInput :
				# swap source and destination
			#  self.currentGfxLink.swapConnectors ()
			#  link.swapNodes ()

			self.currentGfxLink.link = link
			self.nodeNet.addLink ( link )
			if usePyQt4 :
				self.emit ( QtCore.SIGNAL ( 'nodeConnectionChanged' ), self.currentGfxLink.dstConnector.getGfxNode (), self.currentGfxLink.dstConnector.param )
			else :
				self.nodeConnectionChanged.emit ( self.currentGfxLink.dstConnector.getGfxNode (), self.currentGfxLink.dstConnector.param )

		self.lastConnectCandidateReset ()
		self.currentGfxLink = None
		self.state = 'idle'