def createFrame(self):
        self.sels = self.UIMgr.getCurrentGraphSelection()
        expand = [100, 100]
        sizeX = None
        sizeY = None
        leftNode = None
        select = False
        if self.sels:

            self.currentGraph = self.UIMgr.getCurrentGraph()
            leftNode = self._getNodeOnLeft(self.sels)
            rightNode = self._getNodeOnRight(self.sels)
            topNode = self._getTopNode(self.sels)
            bottomNode = self._getBottomNode(self.sels)

            leftPos = leftNode.getPosition()
            rightPos = rightNode.getPosition()
            topPos = topNode.getPosition()
            bottomPos = bottomNode.getPosition()

            sizeX = rightPos[0] - leftPos[0] + 2 * expand[0]
            sizeY = bottomPos[1] - topPos[1] + 2 * expand[1]
            select = True
        frame = SDGraphObjectFrame.sNew(self.currentGraph)

        if select:
            frame.setSize(float2(sizeX, sizeY))
        if select:
            frame.setPosition(
                float2(leftPos[0] - expand[0], topPos[1] - expand[1]))
示例#2
0
    def __snapPosition(aPosition, aNodeWidth, aNodeHeight, aSnapSize):
        def __alignvalue(aValue, aSnapSize):
            hSnapCellCountf = aValue / aSnapSize
            hSnapCellCounti = int(hSnapCellCountf)
            hSnapCellCountFrac = hSnapCellCountf - hSnapCellCounti
            newValue = aSnapSize * hSnapCellCounti
            if hSnapCellCountFrac > 0 and hSnapCellCountFrac > 0.5:
                newValue += aSnapSize
            elif hSnapCellCountFrac < 0 and abs(hSnapCellCountFrac) > 0.5:
                newValue -= aSnapSize
            return newValue

        newPosition = float2(aPosition.x, aPosition.y)

        # Apply offset
        offset = float2(aNodeWidth / 2.0, aNodeHeight / 2.0)
        newPosition.x -= offset.x
        newPosition.y -= offset.y

        # Align horizontally
        newPosition.x = __alignvalue(newPosition.x, aSnapSize)

        # Align vertically
        newPosition.y = __alignvalue(newPosition.y, aSnapSize)

        # undo offset
        newPosition.x += offset.x
        newPosition.y += offset.y
        return newPosition
示例#3
0
def addFrame(item):
    uiMgr = getQt()[2]
    cGridSize = GraphGrid.sGetFirstLevelSize()
    try:
        graph = uiMgr.getCurrentGraph()
    except:
        print("ERROR: No graph active")
        return

    frame = SDGraphObjectFrame.sNew(graph)
    frame.setTitle('Title')
    frame.setDescription('Description')

    if item['rand'] == 1:
        #TODO: adjust size and pos based on selection
        frame.setColor(
            ColorRGBA(random.uniform(0, 1), random.uniform(0, 1),
                      random.uniform(0, 1), item['alpha']))
    else:
        frame.setColor(
            ColorRGBA(item['color'][0], item['color'][1], item['color'][2],
                      item['alpha']))

    selection = uiMgr.getCurrentGraphSelection()
    if len(selection) > 0:
        min = getMin(selection)
        max = getMax(selection)

        size = [max[0] - min[0], max[1] - min[1]]
        frame.setPosition(float2(min[0] - cGridSize, min[1] - cGridSize))
        frame.setSize(float2(size[0] + cGridSize * 2, size[1] + cGridSize * 2))
    else:
        frame.setPosition(float2(-cGridSize, -cGridSize))
        frame.setSize(float2(2 * cGridSize, 2 * cGridSize))
示例#4
0
	def draw_line(self, func_graph, graph_pos: float2, p1: float2, p2: float2, thickness):
		f = func_graph
		segment_dist = self.const_float1(f, math.sqrt((p2.x-p1.x)**2 + (p2.y-p1.y)**2))
		constant = self.const_float1(f, p2.x*p1.y - p2.y*p1.x)
		pvec = self.const_float2(f, float2(p2.y-p1.y, -(p2.x-p1.x)))
		current_pos = self.get_current_pos(f, graph_pos)
		
		dist_to_line = self.div(f, self.abs(f, self.add(f, self.dot_prod(f, pvec, current_pos), constant)), segment_dist)
		
		p1_node = self.const_float2(f, p1)
		p2_node = self.const_float2(f, p2)
		p1_to_cur = self.subtract(f, current_pos, p1_node)
		p2_to_cur = self.subtract(f, current_pos, p2_node)
		p1_to_p2 = self.subtract(f, p2_node, p1_node)
		p2_to_p1 = self.subtract(f, p1_node, p2_node)
		dot1 = self.dot_prod(f, p1_to_cur, p1_to_p2)
		dot2 = self.dot_prod(f, p2_to_cur, p2_to_p1)
		zero = self.const_float1(f, 0)
		on_segment = self.and_nodes(f, self.lessthan(f, zero, dot1), self.lessthan(f, zero, dot2))
		
		
		return self.ifelse(f, 
		self.and_nodes(f,
			self.lessthan(f, dist_to_line, self.const_float1(f, thickness)),
			on_segment),
		self.const_float1(f, 1), 
		self.const_float1(f, 0))
    def createNewNode(self):
        self.currentGraph = self.UIMgr.getCurrentGraph()
        if self.currentGraph and self.nodeName:
            if '::' in self.nodeName:
                newNode = self.currentGraph.newNode(self.nodeName)
            elif 'sbs' in self.nodeName:
                newNode = self._createInstanceNode()
            self.newNode = newNode

            if len(self.inputPropertyInheritanceMethods) > 0:
                method = None
                for inheritanceMethod in self.inputPropertyInheritanceMethods:
                    print(inheritanceMethod)
                    if inheritanceMethod['value'] == 'Absolute':
                        method = SDPropertyInheritanceMethod.Absolute
                    elif inheritanceMethod['value'] == 'RelativeToInput':
                        method = SDPropertyInheritanceMethod.RelativeToInput
                    elif inheritanceMethod['value'] == 'RelativeToParent':
                        method = SDPropertyInheritanceMethod.RelativeToParent
                    newNode.setInputPropertyInheritanceMethodFromId(
                        inheritanceMethod['id'], method)

            if len(self.inputProps) > 0:
                for prop in self.inputProps:
                    value = None
                    if prop["type"] == 'int':
                        value = SDValueInt.sNew(prop["value"])
                    elif prop["type"] == 'int2':
                        value = SDValueInt2.sNew(
                            int2(prop["value"][0], prop["value"][1]))
                    elif prop["type"] == 'int3':
                        value = SDValueInt3.sNew(
                            int3(prop["value"][0], prop["value"][1],
                                 prop["value"][2]))
                    elif prop["type"] == 'int4':
                        value = SDValueInt4.sNew(
                            int4(prop["value"][0], prop["value"][1],
                                 prop["value"][2], prop["value"][3]))
                    elif prop["type"] == 'float':
                        value = SDValueFloat.sNew(prop["value"])
                    elif prop["type"] == 'float2':
                        value = SDValueFloat2.sNew(
                            float2(prop["value"][0], prop["value"][1]))
                    elif prop["type"] == 'float3':
                        value = SDValueFloat3.sNew(
                            float3(prop["value"][0], prop["value"][1],
                                   prop["value"][2]))
                    elif prop["type"] == 'float4':
                        value = SDValueFloat4.sNew(
                            float4(prop["value"][0], prop["value"][1],
                                   prop["value"][2], prop["value"][3]))
                    elif prop["type"] == 'bool':
                        value = SDValueBool.sNew(prop["value"])
                    elif prop["type"] == 'enum':
                        value = SDValueInt.sNew(prop["value"])
                    elif prop["type"] == 'string':
                        value = SDValueString.sNew(prop["value"])
                    newNode.setInputPropertyValueFromId(prop["id"], value)
示例#6
0
def addComment(item):
    uiMgr = getQt()[2]
    cGridSize = GraphGrid.sGetFirstLevelSize()
    try:
        graph = uiMgr.getCurrentGraph()
    except:
        print("ERROR: No graph active")
        return

    selection = uiMgr.getCurrentGraphSelection()
    if len(selection) > 0:
        comment = SDGraphObjectComment.sNewAsChild(selection[0])
        comment.setPosition(float2(-cGridSize * 0.5, cGridSize * 0.5))
        comment.setDescription('Comment')

    else:
        comment = SDGraphObjectComment.sNew(graph)
        comment.setPosition(float2(-cGridSize * 0.5, cGridSize * 0.5))
        comment.setDescription('Comment')
示例#7
0
	def __render_command(self, util, func_graph, c, current_image, graph_pos):
		if c == "F":
			new_pos = float2(self.turtle_state.pos.x + self.turtle_state.dist*math.cos(math.pi/180 * self.turtle_state.angle), self.turtle_state.pos.y + self.turtle_state.dist*math.sin(math.pi/180 * self.turtle_state.angle))
			line = util.draw_line(func_graph, graph_pos, self.turtle_state.pos, new_pos, self.turtle_state.thickness)
			self.turtle_state.pos = new_pos
			return util.union(func_graph, line, current_image)
		elif c == "f":
			self.turtle_state.pos = float2(self.turtle_state.pos.x + self.turtle_state.dist*math.cos(math.pi/180 * self.turtle_state.angle), self.turtle_state.pos.y + self.turtle_state.dist*math.sin(math.pi/180 * self.turtle_state.angle))
		elif c == "+":
			self.turtle_state.angle -= self.angle_change
		elif c == "-":
			self.turtle_state.angle += self.angle_change
		elif c == "[":
			self.turtle_states.append(self.turtle_state.copy())
			pass
		elif c == "]":
			if len(self.turtle_states) >= 1:
				self.turtle_state = self.turtle_states.pop()
			else:
				raise ValueError("No states left to POP")
		else:
			raise ValueError("Invalid character: " + c)
示例#8
0
	def lessthan(self, func_graph, node1, node2):
		lt = func_graph.newNode(LESSTHAN)

		input1 = lt.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, lt, input1)

		input2 = lt.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, lt, input2)

		lt.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return lt
    def _setNewNodeToMousePos(self):
        pos = QtGui.QCursor.pos()
        qtGraphWidget = self.mainWindow.childAt(pos)

        if qtGraphWidget:
            qtGraphViewer = qtGraphWidget.parent()
            if qtGraphViewer.metaObject().className(
            ) == 'Pfx::Editor::Components::Graph::GraphView':

                viewPos = qtGraphViewer.mapFromGlobal(QtGui.QCursor().pos())
                scenePos = qtGraphViewer.mapToScene(viewPos)

                moveTo = float2(scenePos.x(), scenePos.y())
                self.newNode.setPosition(moveTo)
示例#10
0
	def dot_prod(self, func_graph, node1, node2):
		dot_prod = func_graph.newNode(DOT_PROD)

		input1 = dot_prod.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, dot_prod, input1)

		input2 = dot_prod.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, dot_prod, input2)

		dot_prod.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return dot_prod
示例#11
0
	def mul(self, func_graph, node1, node2):
		mul = func_graph.newNode(MUL)

		input1 = mul.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, mul, input1)

		input2 = mul.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, mul, input2)

		mul.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return mul
示例#12
0
	def add(self, func_graph, node1, node2):
		add = func_graph.newNode(ADD)

		input1 = add.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, add, input1)

		input2 = add.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, add, input2)

		add.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return add
示例#13
0
	def div(self, func_graph, node1, node2):
		div = func_graph.newNode(DIV)

		input1 = div.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, div, input1)

		input2 = div.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, div, input2)

		div.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return div
示例#14
0
	def render(self, util, graph_pos: float2):
			pixel_processor = util.pixel_processor(graph_pos)
			perpixel_prop = pixel_processor.getPropertyFromId('perpixel', SDPropertyCategory.Input)
			func_graph = pixel_processor.newPropertyGraph(perpixel_prop, 'SDSBSFunctionGraph')

			bg = util.const_float1(func_graph, 0)
			current_image = bg
			for i in range(0, len(self.state)):
				c = self.state[i]
				new_image = self.__render_command(util, func_graph, c, current_image, float2(450, i*100))
				if new_image is not None:
					current_image = new_image
			func_graph.setOutputNode(current_image, True)
			return pixel_processor
示例#15
0
	def subtract(self, func_graph, node1, node2):
		sub = func_graph.newNode(SUBTRACT)

		input1 = sub.getPropertyFromId('a', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, sub, input1)

		input2 = sub.getPropertyFromId('b', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, sub, input2)

		sub.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return sub
    def setNewNodePosition(self):
        self.sels = self.UIMgr.getCurrentGraphSelection()
        if self.newNode:
            if len(self.sels) < 1:
                self._setNewNodeToMousePos()

            elif len(self.sels) == 1:
                sel = self.sels[0]
                selNodePos = sel.getPosition()
                if self.newNode:
                    self.newNode.setPosition(
                        float2(selNodePos[0] + self.rightOffset,
                               selNodePos[1]))

            elif len(self.sels) > 1:
                firstTwoNodes = [self.sels[0], self.sels[1]]
                rightNode = self._getNodeOnRight(firstTwoNodes)
                posX = rightNode.getPosition()[0] + self.rightOffset

                yTotal = 0
                for node in firstTwoNodes:
                    yTotal += node.getPosition()[1]
                posY = yTotal / len(firstTwoNodes)
                self.newNode.setPosition(float2(posX, posY))
示例#17
0
	def ifelse(self, func_graph, condition_node, node1, node2):
		ifelse = func_graph.newNode(IFELSE)

		input = ifelse.getPropertyFromId('condition', SDPropertyCategory.Input)
		output = condition_node.getProperties(SDPropertyCategory.Output)[0]
		condition_node.newPropertyConnection(output, ifelse, input)

		input1 = ifelse.getPropertyFromId('ifpath', SDPropertyCategory.Input)
		output1 = node1.getProperties(SDPropertyCategory.Output)[0]
		node1.newPropertyConnection(output1, ifelse, input1)

		input2 = ifelse.getPropertyFromId('elsepath', SDPropertyCategory.Input)
		output2 = node2.getProperties(SDPropertyCategory.Output)[0]
		node2.newPropertyConnection(output2, ifelse, input2)

		ifelse.setPosition(float2(max(node1.getPosition().x, node2.getPosition().x) + 150, (node1.getPosition().y + node2.getPosition().y) / 2))

		return ifelse
示例#18
0
    def align_nodes(self):
        nodes = self.graph.getNodes()
        self.align_queue.clear()

        node: sd.api.SDNode
        output_nodes = self.graph.getOutputNodes()
        output_node_id = ""
        if len(output_nodes):
            output_node: sd.api.SDNode = output_nodes[0]
            output_node_id = output_node.getIdentifier()

        for node in nodes:
            out_property: sd.api.SDProperty = node.getPropertyFromId(
                output_id, sd.api.sdproperty.SDPropertyCategory.Output)
            is_output_connected = False
            if out_property:
                out_connections = node.getPropertyConnections(out_property)
                if len(out_connections):
                    is_output_connected = True

            is_output_node = node.getIdentifier() == output_node_id
            if (not isinstance(node, sd.api.SDGraphObject)
                    and not is_output_connected) or is_output_node:
                self.add_node_to_aligh_queue(node, 0)

        self.align_queue = [l for l in self.align_queue if len(l)]

        max_rows = len(max(self.align_queue, key=lambda l: len(l)))
        grid_size_h = grid_size * 1.3

        graph_height = max_rows * grid_size
        graph_width = len(self.align_queue) * grid_size_h

        for col_index, col_nodes in enumerate(self.align_queue):
            col_x = graph_width - (col_index + 1) * grid_size_h
            col_y = graph_height / 2.0 - len(col_nodes) / 2.0 * grid_size

            for row_index, node in enumerate(col_nodes):
                node.setPosition(float2(col_x, col_y + row_index * grid_size))
示例#19
0
def alignSDNodes(aSDNodes,
                 aAlignDirection=AlignmentDirection.Horizontal,
                 aSDNodeSpace=graphgrid.GraphGrid.sGetFirstLevelSize()):
    """
    Align the specified SDNodes
    :param aSDNodes: A list of SDNode objects
    :param aAlignDirection: The alignment direction
    :param aSDNodeSpace: The space between nodes
    :return: None
    """
    class NodeInfo:
        def __init__(self, aSDNode, aPosition):
            self.mSDNode = aSDNode
            self.mPosition = aPosition

    if not aSDNodes or len(aSDNodes) < 2:
        return

    # Collect node info
    # Find top most Node
    nodeInfoList = []
    for sdNode in aSDNodes:
        nodePos = sdNode.getPosition()
        nodeInfoList.append(NodeInfo(sdNode, nodePos))

    if aAlignDirection == AlignmentDirection.Horizontal:
        dirComponentIndex = 0  # X
    else:
        dirComponentIndex = 1  # Y

    oppositeDirComponentIndex = 1 - dirComponentIndex

    # Sort along the opposite axis
    nodeInfoList = sorted(
        nodeInfoList,
        key=lambda nodeInfo: nodeInfo.mPosition[oppositeDirComponentIndex])

    # Get the mean value of X
    vMin = nodeInfoList[0].mPosition[oppositeDirComponentIndex]
    vMax = vMin
    i = 1
    while i < len(nodeInfoList):
        v = nodeInfoList[i].mPosition[oppositeDirComponentIndex]
        if v < vMin:
            vMin = v
        elif v > vMax:
            vMax = v
        i = i + 1
    vPos = (vMin + vMax) / 2.0

    # Change positions
    # Sort along the opposite axis
    nodeInfoList = sorted(
        nodeInfoList,
        key=lambda nodeInfo: nodeInfo.mPosition[dirComponentIndex])

    reverseIteration = False
    graphDirectionLeftToRight = True  # TODO: expose as argument
    if aAlignDirection == AlignmentDirection.Horizontal:
        if graphDirectionLeftToRight:
            reverseIteration = True

    nodeCount = len(nodeInfoList)
    if reverseIteration:
        nodeInfoStartIndex = nodeCount - 1
        nodeInfoLastIndex = 0
        nodeInfoIndexIncrement = -1
        directionFactor = -1
    else:
        nodeInfoStartIndex = 0
        nodeInfoLastIndex = nodeCount - 1
        nodeInfoIndexIncrement = 1
        directionFactor = 1

    nodeInfoIndex = nodeInfoStartIndex
    while nodeInfoIndex != (nodeInfoLastIndex + nodeInfoIndexIncrement):
        if aAlignDirection == AlignmentDirection.Horizontal:
            newPosition = [nodeInfoList[nodeInfoIndex].mPosition[0], vPos]
        else:
            newPosition = [vPos, nodeInfoList[nodeInfoIndex].mPosition[1]]

        nodeInfoList[nodeInfoIndex].mSDNode.setPosition(
            float2(newPosition[0], newPosition[1]))

        nodeInfoIndex = nodeInfoIndex + nodeInfoIndexIncrement

    return True
    def runTest(self):
        context = sd.getContext()
        srcPackageFileName = '2_sbs_graphs.sbs'
        sdPackage = tools.loadSDPackage(context, srcPackageFileName)
        self.assertTrue(sdPackage, 'Fail to load package')

        filePath = sdPackage.getFilePath()
        self.assertEqual(os.path.split(filePath)[1], srcPackageFileName, 'Fail to load package')

        sdResourceArray = sdPackage.getChildrenResources(True)
        self.assertTrue(sdResourceArray)

        # self.assertTrue(len(sbsGraphArray) == 2)
        sdGraphIndex = -1
        tab = '\t'
        for sdResource in sdResourceArray:
            sdResourceIdentifier = sdResource.getIdentifier()
            # Check if the resource is a SDGraph
            if not issubclass(type(sdResource), sdgraph.SDGraph):
                continue
            sdGraphIndex = sdGraphIndex + 1
            sdNodeArray = sdResource.getNodes()
            self.assertTrue(sdNodeArray, 'Fail to get Nodes from SD Graph')
            sdNodeArraySize = len(sdNodeArray)

            if sdGraphIndex == 0:
                self.assertEqual(sdResourceIdentifier, 'myGraph1', 'Graph identifier comparison failed')
                self.assertEqual(sdNodeArraySize, 7, 'Invalid Node count')
            elif sdGraphIndex == 1:
                self.assertEqual(sdResourceIdentifier, 'mySubGraph2', 'Graph identifier comparison failed')
                self.assertEqual(sdNodeArraySize, 5, 'Invalid Node count')
            # put nodes horizontally
            for sdNode in sdNodeArray:
                pos = sdNode.getPosition()
                self.assertTrue(pos, 'Fail to get node Position')

                # Check node position modification
                newPosX = 1234
                newPosY = -654
                sdNode.setPosition(float2(newPosX, newPosY))

                pos = sdNode.getPosition()
                self.assertTrue(pos, 'Fail to get node Position')
                self.assertEqual(pos.x, newPosX, 'Node Position X has not been set correctly')
                self.assertEqual(pos.y, newPosY, 'Node Position Y has not been set correctly')

                nodeDefinition = sdNode.getDefinition()
                inputProperties = nodeDefinition.getProperties(sdproperty.SDPropertyCategory.Input)
                logging.debug(tab + 'Node: ')
                for sdProperty in inputProperties:
                    name = sdProperty.getId()
                    sdType = sdProperty.getType()
                    category = sdProperty.getCategory()
                    logging.debug(tab*2 + '"%s" : "%s" (%s)' % (name, sdType.getId(), str(category)))
                    self.assertTrue(name, 'Empty property name')
                    # self.assertTrue(sdType, 'Empty property sdType for "' + name +'"')
                outputProperties = nodeDefinition.getProperties(sdproperty.SDPropertyCategory.Output)
                logging.debug(tab + 'Node: ')
                for sdProperty in outputProperties:
                    name = sdProperty.getId()
                    sdType = sdProperty.getType()
                    category = sdProperty.getCategory()
                    logging.debug(tab*2 + '"%s" : "%s" (%s)' % (name, sdType.getId(), str(category)))
                    self.assertTrue(name, 'Empty property name')
                    # self.assertTrue(sdType, 'Empty property sdType for "' + name +'"')

            # Save package to new file
            dstFileAbsPath = os.path.join(tools.getTestOutputDir(__file__), 'output.sbs')
            context.getSDApplication().getPackageMgr().savePackageAs(sdPackage, dstFileAbsPath)
示例#21
0
 def set_new_node_position(self, node: sd.api.SDNode):
     node.setPosition(float2(self.node_pos_x, self.node_pos_y))
     self.node_pos_y += grid_size
     if self.node_pos_y >= grid_size * max_nodes_in_row:
         self.node_pos_x += grid_size
         self.node_pos_y = 0
示例#22
0
	def __init__(self, initiator, angle_change, forward_dist, thickness, rules):
		self.state = initiator
		self.angle_change = angle_change
		self.turtle_state = TurtleState(0.0, float2(0.5, 0.5), forward_dist, thickness)
		self.turtle_states = []
		self.rules = [self.__parse_rule(rule) for rule in rules]
示例#23
0
def addNode(item):
    ctx, app, uiMgr = getQt()
    cGridSize = GraphGrid.sGetFirstLevelSize()

    try:
        graph = uiMgr.getCurrentGraph()
    except:
        print("ERROR: No graph active")
        return

    if item["type"] == "NODE":
        node = graph.newNode(item['src'])
    else:
        url = item['src']
        pkgMgr = app.getPackageMgr()
        pkg = pkgMgr.loadUserPackage(item["file"])
        resource = pkg.findResourceFromUrl(url.split("?")[0])
        print(item["file"], resource, url.split("?")[0])
        node = graph.newInstanceNode(resource)
        #pkgMgr.unloadUserPackage(pkg)

    for prop in item['props']:
        value = None
        if prop["type"] == 'int':
            value = SDValueInt.sNew(prop["value"])
        elif prop["type"] == 'int2':
            value = SDValueInt2.sNew(int2(prop["value"][0], prop["value"][1]))
        elif prop["type"] == 'int3':
            value = SDValueInt3.sNew(
                int3(prop["value"][0], prop["value"][1], prop["value"][2]))
        elif prop["type"] == 'int4':
            value = SDValueInt4.sNew(
                int4(prop["value"][0], prop["value"][1], prop["value"][2],
                     prop["value"][3]))
        elif prop["type"] == 'float':
            value = SDValueFloat.sNew(prop["value"])
        elif prop["type"] == 'float2':
            value = SDValueFloat2.sNew(
                float2(prop["value"][0], prop["value"][1]))
        elif prop["type"] == 'float3':
            value = SDValueFloat3.sNew(
                float3(prop["value"][0], prop["value"][1], prop["value"][2]))
        elif prop["type"] == 'float4':
            value = SDValueFloat4.sNew(
                float4(prop["value"][0], prop["value"][1], prop["value"][2],
                       prop["value"][3]))
        elif prop["type"] == 'bool':
            value = SDValueBool.sNew(prop["value"])
        elif prop["type"] == 'enum':
            value = SDValueInt.sNew(prop["value"])

        if value is not None:
            if prop["inheritance"] != -1:
                inheritance = SDPropertyInheritanceMethod.RelativeToInput
                if prop['inheritance'] == 1:
                    inheritance = SDPropertyInheritanceMethod.RelativeToParent
                elif prop['inheritance'] == 2:
                    inheritance = SDPropertyInheritanceMethod.Absolute
                node.setInputPropertyInheritanceMethodFromId(
                    prop["id"], inheritance)

            node.setInputPropertyValueFromId(prop["id"], value)

    selection = uiMgr.getCurrentGraphSelection()
    if len(selection) > 0:
        origin = getOrigin(selection)
        node.setPosition(float2(origin[0] + cGridSize * 1.5, origin[1]))
 def _moveNode(self, node, vector):
     origPos = node.getPosition()
     node.setPosition(float2(origPos[0] + vector[0],
                             origPos[1] + vector[1]))