def addNode(self):
        # My First Node
        _input = [1, 2, 3]
        _output = [1]

        node1 = Node(self.scene, 'First Node', _input, _output)
        node2 = Node(self.scene, 'Second First Node', _input, _output)
        node3 = Node(self.scene, 'Third First Node', _input, _output)
        node1.setNodePos(-250, -250)
        node2.setNodePos(250, -250)

        # print('node1 id: ',id(node1))
        # print('node2 id: ',id(node2))
        # print('node3 id: ',id(node3))

        Link1 = Link(self.scene, node1.outputs[0], node2.inputs[0], 2)
예제 #2
0
    def initUI(self):
        self.setGeometry(800, 600, 1280, 720)

        # 创建画布
        self.scene = Scene()
        # self.grScene = self.scene.grScene
        self.view = QDMGraphicsView(self.scene.grScene, self)

        node = Node(self.scene, "My First Node")

        box_layout = QVBoxLayout()
        box_layout.setContentsMargins(5, 5, 5, 5)
        box_layout.addWidget(self.view)
        self.setLayout(box_layout)
        self.setWindowTitle("Node Editor")
        self.show()
예제 #3
0
    def deserialize(self, data, hashmap={}, restore_id=True):

        self.clear()

        if restore_id:
            self.id = data['id']

        hashmap = {}

        # load nodes
        for node_data in data['nodes']:
            Node(self).deserialize(node_data, hashmap, restore_id)

        # load links
        for link_data in data['links']:
            Link(self).deserialize(link_data, hashmap, restore_id)

        return True
    def deserializeFromClipboard(self, data):
        hashmap = {}

        # paste on mouse pointer
        view = self.scene.grScene.views()[0]
        mouse_scene_pos = view.last_scene_mouse_position
        #
        # claculate scene object + center
        minx, maxx, miny, maxy = 0, 0, 0, 0
        for node_data in data['nodes']:
            x, y = node_data['pos_x'], node_data['pos_y']
            if x < minx: minx = x
            if x > maxx: maxx = x
            if y < miny: miny = y
            if y > maxy: maxy = y

        bbox_center_x = (minx + maxx) / 2
        bbox_center_y = (miny + maxy) / 2

        center = view.mapToScene(view.rect().center())

        # calculate offset
        offset_x = (mouse_scene_pos.x() - bbox_center_x)
        offset_y = (mouse_scene_pos.y() - bbox_center_y)

        if DEBUG: print('node_scene_clipboard ::', data)

        # create each node
        for node_data in data['nodes']:
            new_node = Node(self.scene)
            new_node.deserialize(node_data, hashmap, restore_id=False)

            # read just the new node's position
            pos = new_node.pos
            new_node.setNodePos(pos.x() + offset_x, pos.y() + offset_y)

        # create each links
        if 'links' in data:
            for link_data in data['links']:
                new_link = Link(self.scene)
                new_link.deserialize(link_data, hashmap, restore_id=False)

        # store history
        self.scene.history.storeHistory(
            'node_scene_clipboard :: Pasted Elements in scene',
            setModified=True)
예제 #5
0
def deserialize_node(scene: Scene, data: str):
    args = data.split(" ")
    node_type = ""
    for arg in args:
        if arg.startswith("type:"):
            node_type = arg.split(":")[1]
    if node_type == "":
        return
    node = None
    for cls in Node.__subclasses__():
        if cls.get_type_name() == node_type:
            node = cls(scene)
            break
    print(node)
    if node is not None:
        properties = {}
        for arg in args:
            if ":" in arg:
                key = arg.split(":")[0]
                value = arg.split(":")[1]
                properties[key] = value
        node.load_save_text(properties)
    print("deserialized node")
예제 #6
0
    def initUI(self):
        self.setGeometry(200, 200, 800, 800)
        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.layout)

        self.scene = Scene()
        self.grScene = self.scene.grScene

        self.view = QDMGraphicsView(self.grScene, self)
        self.layout.addWidget(self.view)

        node1 = Node(self.scene, "First Node", inputs=[1, 1, 1],
                     outputs=[1])  # 数字代表 socket 类型, socket index 按数组顺序
        node2 = Node(self.scene, "Second Node", inputs=[1, 1, 1], outputs=[1])
        node3 = Node(self.scene, "Third Node", inputs=[1, 1, 1], outputs=[1])
        node1.setPos(-350, 100)
        node2.setPos(-75, 0)
        node3.setPos(200, -100)

        edge1 = Edge(self.scene, node1.outputs[0], node2.inputs[0],
                     EDGE_TYPE_BEZIER)
        edge2 = Edge(self.scene, node2.outputs[0], node3.inputs[1],
                     EDGE_TYPE_BEZIER)

        self.setWindowTitle("Node Editor")
        self.show()
예제 #7
0
 def addNodes(self):
     node1 = Node(self.scene, "Dataset Path", inputs=[0], outputs=[1])
     node2 = Node(self.scene, "Image Settings", inputs=[1], outputs=[1])
     node3 = Node(self.scene, "Train", inputs=[0], outputs=[1])
     node4 = Node(self.scene, "GPU", inputs=[0], outputs=[1])
     node5 = Node(self.scene, "Batch", inputs=[0], outputs=[1])
     node6 = Node(self.scene, "Dimensions", inputs=[0], outputs=[1])
     node7 = Node(self.scene,
                  "GAN",
                  inputs=[0, 1, 2, 3, 4, 5, 5, 5, 5, 7],
                  outputs=[2])
     node8 = Node(self.scene, "Start", inputs=[0], outputs=[0])
     node9 = Node(self.scene, "Output", inputs=[0], outputs=[1])
     node1.setPos(-450, -150)
     node2.setPos(-200, -150)
     node3.setPos(-450, 200)
     node4.setPos(-450, 350)
     node5.setPos(-450, 500)
     node6.setPos(-200, 200)
     node7.setPos(150, -150)
     node8.setPos(400, -150)
     node9.setPos(400, 250)
     edge1 = Edge(self.scene,
                  node1.outputs[0],
                  node2.inputs[0],
                  edge_type=EDGE_TYPE_BEZIER)
     edge2 = Edge(self.scene,
                  node2.outputs[0],
                  node7.inputs[0],
                  edge_type=EDGE_TYPE_BEZIER)
     edge3 = Edge(self.scene,
                  node3.outputs[0],
                  node7.inputs[1],
                  edge_type=EDGE_TYPE_BEZIER)
     edge4 = Edge(self.scene,
                  node4.outputs[0],
                  node7.inputs[2],
                  edge_type=EDGE_TYPE_BEZIER)
     edge5 = Edge(self.scene,
                  node5.outputs[0],
                  node7.inputs[3],
                  edge_type=EDGE_TYPE_BEZIER)
     edge6 = Edge(self.scene,
                  node6.outputs[0],
                  node7.inputs[4],
                  edge_type=EDGE_TYPE_BEZIER)
     edge7 = Edge(self.scene,
                  node7.outputs[0],
                  node8.inputs[0],
                  edge_type=EDGE_TYPE_BEZIER)
     edge8 = Edge(self.scene,
                  node7.outputs[0],
                  node9.inputs[0],
                  edge_type=EDGE_TYPE_BEZIER)
     self.scene.history.storeInitialHistoryStamp()
예제 #8
0
    def addNodes(self):
        node1 = Node(self.scene,
                     "My Awesome Node 1",
                     inputs=[0, 0, 0],
                     outputs=[1])
        node2 = Node(self.scene,
                     "My Awesome Node 2",
                     inputs=[3, 3, 3],
                     outputs=[1])
        node3 = Node(self.scene,
                     "My Awesome Node 3",
                     inputs=[2, 2, 2],
                     outputs=[1])
        node1.setPos(-350, -250)
        node2.setPos(-75, 0)
        node3.setPos(200, -150)

        edge1 = Edge(self.scene,
                     node1.outputs[0],
                     node2.inputs[0],
                     edge_type=EDGE_TYPE_BEZIER)
        edge2 = Edge(self.scene,
                     node2.outputs[0],
                     node3.inputs[0],
                     edge_type=EDGE_TYPE_BEZIER)
예제 #9
0
    def addNodes(self):
        node1 = Node(self.scene,
                     "Monte Carlo Driver",
                     inputs=[1, 2, 3],
                     outputs=[4])
        node2 = Node(self.scene, "Dihedral Mutator", inputs=[3], outputs=[1])
        node3 = Node(self.scene, "Energy Function", inputs=[], outputs=[2])
        node1.setPos(200, -150)
        node2.setPos(-350, 0)
        node3.setPos(-75, -250)

        edge1 = Edge(self.scene,
                     node3.outputs[0],
                     node1.inputs[1],
                     edge_type=EDGE_TYPE_BEZIER)
        edge2 = Edge(self.scene,
                     node2.outputs[0],
                     node1.inputs[0],
                     edge_type=EDGE_TYPE_BEZIER)

        self.scene.history.storeInitialHistoryStamp()