Пример #1
0
    def new_python_node(self):
        """ Create a new node """

        dialog = NewGraph("New Python Node", self.pkgmanager, self)
        ret = dialog.exec_()

        if(ret > 0):
            dialog.create_nodefactory(self.pkgmanager)
            self.reinit_treeview()
Пример #2
0
    def new_python_node(self):
        """ Create a new node """

        dialog = NewGraph("New Python Node", self.pkgmanager, self)
        ret = dialog.exec_()

        if (ret > 0):
            dialog.create_nodefactory(self.pkgmanager)
            self.reinit_treeview()
Пример #3
0
    def new_graph(self):
        """ Create a new graph """

        dialog = NewGraph("New Composite Node", self.pkgmanager, self)
        ret = dialog.exec_()

        if (ret > 0):
            newfactory = dialog.create_cnfactory(self.pkgmanager)
            self.reinit_treeview()
            self.open_compositenode(newfactory)
Пример #4
0
    def add_composite_node(self):
        """ """
        pman = self.model().pman # pkgmanager
        pkg = self.get_current_pkg()

        dialog = NewGraph("New Composite Node", pman, self, pkg_id=pkg.name)
        ret = dialog.exec_()

        if(ret>0):
            newfactory = dialog.create_cnfactory(pman)
Пример #5
0
    def add_python_node(self):
        """ """
        pman = self.model().pman # pkgmanager
        pkg = self.get_current_pkg()

        dialog = NewGraph("New Python Node", pman, self, pkg_id=pkg.name)
        ret = dialog.exec_()

        if(ret>0):
            dialog.create_nodefactory(pman)
Пример #6
0
    def new_graph(self):
        """ Create a new graph """

        dialog = NewGraph("New Composite Node", self.pkgmanager, self)
        ret = dialog.exec_()

        if(ret > 0):
            newfactory = dialog.create_cnfactory(self.pkgmanager)
            self.reinit_treeview()
            self.open_compositenode(newfactory)
Пример #7
0
    def edit_properties(self):
        """ Edit Node info"""

        item = self.currentIndex()
        obj =  item.internalPointer()

        if(isinstance(obj, DataFactory)):
            qt.QtGui.QMessageBox.information(self, "Properties", "Data : %s"%(obj.name))
            return

        d = NewGraph("Node Properties", PackageManager(), self, obj)
        ret = d.exec_()
        if(ret):
            d.update_factory()
Пример #8
0
    def edit_properties(self):
        """ Edit Node info"""

        index = self.currentIndex()
        obj   = self.model().data(index, PkgModel.pkgmodelRole)

        if(isinstance(obj, DataFactory)):
            QtGui.QMessageBox.information(self, "Properties", "Data : %s"%(obj.name))
            return

        d = NewGraph("Node Properties", PackageManager(), self, obj)
        ret = d.exec_()
        if(ret):
            d.update_factory()
Пример #9
0
    def edit_properties(self):
        """ Edit Node info"""

        item = self.currentIndex()
        obj = item.internalPointer()

        if (isinstance(obj, DataFactory)):
            qt.QtGui.QMessageBox.information(self, "Properties",
                                             "Data : %s" % (obj.name))
            return

        d = NewGraph("Node Properties", PackageManager(), self, obj)
        ret = d.exec_()
        if (ret):
            d.update_factory()
Пример #10
0
    def graph_group_selection(self):
        """Export selected nodes in a new factory"""
        master = self.master
        widget = master.get_sensible_parent()
        graph  = master.get_graph()
        scene  = master.get_graph_scene()

        # FIRST WE PREPARE THE USER INTERFACE STUFF
        # ------------------------------------------
        # Get default package id
        default_factory = graph.factory
        if(default_factory and default_factory.package):
            pkg_id = default_factory.package.name
            name = default_factory.name + "_grp_" + str(len(default_factory.package))
        else:
            pkg_id = None
            name = ""

        pm = master.get_package_manager()
        dialog = NewGraph("Group Selection", pm, widget,
                          io=False, pkg_id=pkg_id, name=name)
        ret = dialog.exec_()
        if(not ret): return

        # NOW WE DO THE HARD WORK
        # -----------------------
        factory = dialog.create_cnfactory(pm)
        items = scene.get_selected_items(master.vertexType)
        if(not items): return None

        pos = scene.get_selection_center(items)
        def cmp_x(i1, i2):
            return cmp(i1.scenePos().x(), i2.scenePos().x())
        items.sort(cmp=cmp_x)

        # Instantiate the new node:
        itemIds = [i.vertex().get_id() for i in items]
        graph.to_factory(factory, itemIds, auto_io=True)
        newVert = factory.instantiate([graph.factory.get_id()])

        # Evaluate the new connections:
        def evaluate_new_connections(newGraph, newGPos, idList):
            newId    = scene.add_vertex(newGraph, [newGPos.x(), newGPos.y()])
            newEdges = graph.compute_external_io(idList, newId)
            for edges in newEdges:
                scene.add_edge((edges[0], edges[1]),
                                 (edges[2], edges[3]))
            self.graph_remove_selection(items)

        def correct_positions(newGraph):
            _minX = _minY = float("inf")
            for vid in newGraph.vertices():
                if vid in (newGraph.id_in, newGraph.id_out): continue
                node = newGraph.node(vid)
                _nminX, _nminY = node.get_ad_hoc_dict().get_metadata("position")
                _minX= min(_minX, _nminX)
                _minY= min(_minY, _nminY)
            for vid in newGraph.vertices():
                if vid in (newGraph.id_in, newGraph.id_out): continue
                pos = newGraph.node(vid).get_ad_hoc_dict().get_metadata("position")
                # the 50 is there to have a margin at the top and right of the
                # nodes.
                pos[0] = pos[0] - _minX + 50
                pos[1] = pos[1] - _minY + 50

        if newVert:
            #to prevent too many redraws during the grouping we queue events then process
            #them all at once.
            scene.queue_call_notifications(evaluate_new_connections, newVert, pos, itemIds)
            correct_positions(newVert)


        try:
            factory.package.write()
        except AttributeError, e:
            mess = qt.QtGui.QMessageBox.warning(widget, "Error",
                                             "Cannot write Graph model on disk. :\n"+
                                             "You try to write in a System Package:\n")
Пример #11
0
    def graph_group_selection(self):
        """Export selected nodes in a new factory"""
        master = self.master
        widget = master.get_sensible_parent()
        graph = master.get_graph()
        scene = master.get_graph_scene()

        # FIRST WE PREPARE THE USER INTERFACE STUFF
        # ------------------------------------------
        # Get default package id
        default_factory = graph.factory
        if (default_factory and default_factory.package):
            pkg_id = default_factory.package.name
            name = default_factory.name + "_grp_" + str(
                len(default_factory.package))
        else:
            pkg_id = None
            name = ""

        pm = master.get_package_manager()
        dialog = NewGraph("Group Selection",
                          pm,
                          widget,
                          io=False,
                          pkg_id=pkg_id,
                          name=name)
        ret = dialog.exec_()
        if (not ret): return

        # NOW WE DO THE HARD WORK
        # -----------------------
        factory = dialog.create_cnfactory(pm)
        items = scene.get_selected_items(master.vertexType)
        if (not items): return None

        pos = scene.get_selection_center(items)

        def cmp_x(i1, i2):
            return cmp(i1.scenePos().x(), i2.scenePos().x())

        items.sort(cmp=cmp_x)

        # Instantiate the new node:
        itemIds = [i.vertex().get_id() for i in items]
        graph.to_factory(factory, itemIds, auto_io=True)
        newVert = factory.instantiate([graph.factory.get_id()])

        # Evaluate the new connections:
        def evaluate_new_connections(newGraph, newGPos, idList):
            newId = scene.add_vertex(newGraph, [newGPos.x(), newGPos.y()])
            newEdges = graph.compute_external_io(idList, newId)
            for edges in newEdges:
                scene.add_edge((edges[0], edges[1]), (edges[2], edges[3]))
            self.graph_remove_selection(items)

        def correct_positions(newGraph):
            _minX = _minY = float("inf")
            for vid in newGraph.vertices():
                if vid in (newGraph.id_in, newGraph.id_out): continue
                node = newGraph.node(vid)
                _nminX, _nminY = node.get_ad_hoc_dict().get_metadata(
                    "position")
                _minX = min(_minX, _nminX)
                _minY = min(_minY, _nminY)
            for vid in newGraph.vertices():
                if vid in (newGraph.id_in, newGraph.id_out): continue
                pos = newGraph.node(vid).get_ad_hoc_dict().get_metadata(
                    "position")
                # the 50 is there to have a margin at the top and right of the
                # nodes.
                pos[0] = pos[0] - _minX + 50
                pos[1] = pos[1] - _minY + 50

        if newVert:
            #to prevent too many redraws during the grouping we queue events then process
            #them all at once.
            scene.queue_call_notifications(evaluate_new_connections, newVert,
                                           pos, itemIds)
            correct_positions(newVert)

        try:
            factory.package.write()
        except AttributeError, e:
            mess = qt.QtGui.QMessageBox.warning(
                widget, "Error", "Cannot write Graph model on disk. :\n" +
                "You try to write in a System Package:\n")