Example #1
0
    def __init__(self, library, fname, mypath, runflag, parent=None):
        super(SupsiSimMainWindow, self).__init__(parent)
        self.resize(1024, 768)
        self.centralWidget = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.centralWidget)
        #self.verticalLayout.setMargin(0)
        self.view = GraphicsView(self.centralWidget)
        self.view.setMouseTracking(True)
        self.scene = Scene(self)
        self.view.setScene(self.scene)
        self.view.setRenderHint(QPainter.Antialiasing)
        self.verticalLayout.addWidget(self.view)
        self.setCentralWidget(self.centralWidget)
        self.addactions()
        self.addMenubar()
        self.addToolbars()
        self.filename = fname
        self.path = mypath
        self.library = library
        self.runflag = runflag
        if fname != 'untitled':
            self.scene.loadDgm(self.getFullFileName())

        self.setWindowTitle(self.filename)
        self.status = self.statusBar()
        self.evpos = QtCore.QPointF(0, 0)
        self.editor = Editor(self)
        self.editor.install(self.scene)
        self.status.showMessage('Ready')

        self.modified = False
Example #2
0
    def P09(self, obj, event):
        try:
            item = self.itemAt(event.scenePos())
        except:
            item = None
        if isinstance(item, InPort):
            if len(item.connections) == 0:
                self.scene.DgmToUndo()
                self.conn.port2 = item
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)
                if isinstance(self.conn.port1, OutPort):
                    pos = QtCore.QPointF(
                        (self.conn.pos2.x() + self.conn.pos1.x()) / 2,
                        self.conn.pos1.y())
                    self.newNode(self.conn, pos)

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')
        else:
            pt = self.genInterPoint(self.conn.pos2)
            b = Node(None, self.scene)
            b.setPos(pt)
            self.conn.port2 = b.port_in
            self.conn.pos2 = b.scenePos()
            self.conn.port1.connections.append(self.conn)
            self.conn.port2.connections.append(self.conn)
            self.conn.update_path()
            self.conn = None
            self.state = IDLE
Example #3
0
 def find_itemAt(self, pos):
     items = self.items(
         QtCore.QRectF(pos - QtCore.QPointF(1, 1), QtCore.QSizeF(3, 3)))
     for item in items:
         if isinstance(item,
                       QGraphicsItem) and not isinstance(item, Connection):
             return item
     return None
Example #4
0
 def setPos(self, *args):
     if len(args) == 1:
         pt = self.gridPos(args[0])
         super(Block, self).setPos(pt)
     else:
         pt = QtCore.QPointF(args[0], args[1])
         pt = self.gridPos(pt)
         super(Block, self).setPos(pt)
Example #5
0
 def itemAt(self, pos):
     items = self.scene.items(
         QtCore.QRectF(pos - QtCore.QPointF(DB, DB),
                       QtCore.QSizeF(2 * DB, 2 * DB)))
     for item in items:
         if isinstance(item, QGraphicsItem):
             return item
     return None
Example #6
0
    def update_path(self):
        p = QPainterPath()
        item = None
        if self.port2 == None:
            item = self.scene.find_itemAt(self.pos2)
        if isinstance(self.port1, OutPort):
            pt = QtCore.QPointF(self.pos2.x(),self.pos1.y())
        elif isinstance(self.port2, InPort) or isinstance(item, InPort):
            pt = QtCore.QPointF(self.pos1.x(),self.pos2.y())
        else:
            dx = np.abs(self.pos2.x()-self.pos1.x())
            dy = np.abs(self.pos2.y()-self.pos1.y())
            if dx > dy:
                pt = QtCore.QPointF(self.pos2.x(),self.pos1.y())
            else:
                pt = QtCore.QPointF(self.pos1.x(),self.pos2.y())

        p.moveTo(self.pos1)
        p.lineTo(pt)
        p.lineTo(self.pos2)
        self.setPath(p)
Example #7
0
 def bindNode(self):
     self.scene.DgmToUndo()
     item = self.scene.item
     if len(item.port_out.connections) == 1:
         c1 = item.port_in.connections[0]
         c2 = item.port_out.connections[0]
         c = Connection(None, self.scene)
         c.pos1 = c1.pos1
         c.pos2 = c2.pos2
         item.remove()
         c.update_ports_from_pos()
         if isinstance(c.port1, OutPort) and isinstance(c.port2, InPort):
             pos = QtCore.QPointF((c.pos2.x() + c.pos1.x()) / 2, c.pos1.y())
             self.newNode(c, pos)
     else:
         self.scene.clearLastUndo()
Example #8
0
    def P08(self, obj, event):
        item = self.itemAt(event.scenePos())
        if isinstance(item, InPort):
            if len(item.connections) == 0:
                self.scene.DgmToUndo()
                self.conn.port2 = item
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)
                if isinstance(self.conn.port1, OutPort):
                    pos = QtCore.QPointF(
                        (self.conn.pos2.x() + self.conn.pos1.x()) / 2,
                        self.conn.pos1.y())
                    self.newNode(self.conn, pos)

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')

        if isinstance(item, Node):
            if item.port_in.connections == []:
                self.scene.DgmToUndo()
                self.conn.port2 = item.port_in
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)  # Problema qui!

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')

        if item == None:
            pt = self.genInterPoint(event.scenePos())
            b = Node(None, self.scene)
            b.setPos(pt)
            self.conn.port2 = b.port_in
            self.conn.pos2 = b.scenePos()
            self.conn.port1.connections.append(self.conn)
            self.conn.port2.connections.append(self.conn)
            self.conn.update_path()

            self.conn = Connection(None, self.scene)
            self.conn.port1 = b.port_out
            self.conn.pos1 = b.scenePos()
            self.conn.pos2 = b.scenePos()
Example #9
0
 def gridPos(self, pt):
     gr = GRID
     x = gr * ((pt.x() + gr / 2) // gr)
     y = gr * ((pt.y() + gr / 2) // gr)
     return QtCore.QPointF(x, y)
Example #10
0
 def cloneBlock(self):
     self.scene.DgmToUndo()
     item = self.scene.item
     item.clone(QtCore.QPointF(100, 100))