Пример #1
0
    def __init__(self, graph, pos):
        self._graph = graph

        self._id = id(self)

        self._label = ''
        self._scrollArea_layoutWindow = None
        self._layoutWindow = None
        self.newLayoutWindow(config=0)

        self._collapsed = False
        # for load/paste
        self._destined_collapse = False

        # connected node groups
        self._src_cn = []
        self._sink_cn = []
        self._encap_nodes = []
        self._encap_nodepos = []

        self._src = PortEdge(self, graph, MacroAPI, role=0)
        self._src.setPos(pos)

        # self._sink = PortEdge(self, graph, nodeIF=self._src._nodeIF,
        # nodeIFscroll=self._src._nodeIF_scrollArea)
        self._sink = PortEdge(self, graph, MacroAPI, role=1)
        self._sink.setPos(QtCore.QPointF(0, 100) + pos)
        self._sink_pos = QtCore.QPointF(0, 100) + pos

        self._face = PortEdge(self, graph, MacroAPI, role=2)
        self._face.setPos(pos)
        self._face.inportList = []
        self._face.outportList = []

        # save expanded positions
        self._src_exppos = self._src.getPos()
        self._sink_exppos = self._sink.getPos()
        self._face_colpos = self._face.getPos()

        self._macroedge = MacroNodeEdge(self._src, self._sink)

        self._graph.scene().addItem(self._src)
        self._graph.scene().addItem(self._sink)
        self._graph.scene().addItem(self._macroedge)
        self._graph.scene().addItem(self._face)
        self._face.hide()

        self._anim_timeline = None
        self._anim = None

        self._scrollArea_layoutWindow.setWindowTitle('Macro')
Пример #2
0
 def shape(self):
     # hitbox for selecting
     path = super(Edge, self).shape()
     delta = QtCore.QPointF(3, 3)  # padding to make it thicker
     line = QtGui.QPolygonF([
         self.sourcePoint + delta, self.destPoint + delta,
         self.destPoint - delta, self.sourcePoint - delta
     ])
     path.addPolygon(line)
     return path
Пример #3
0
    def __init__(self, sourcePort, destPort):
        super(Edge, self).__init__()

        self.sourcePoint = QtCore.QPointF()
        self.destPoint = QtCore.QPointF()

        self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable)
        self.setCacheMode(QtWidgets.QGraphicsItem.DeviceCoordinateCache)

        self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
        self.source = sourcePort
        self.dest = destPort
        self.source.addEdge(self)
        self.dest.addEdge(self)
        self.adjust()
        self.setZValue(1)

        self.setAcceptHoverEvents(True)
        self._beingHovered = False
Пример #4
0
    def __init__(self, parent=None):
        super(CanvasScene, self).__init__(parent)

        self.graph = parent
        self.line = None
        self.rubberBand = None
        self.origin = QtCore.QPointF()

        # during a port connection this is used to hold
        # a list of matching port types for highlighting
        self.portMatches = []
Пример #5
0
    def __init__(self, source, dest):
        super(MacroNodeEdge, self).__init__()

        self.setZValue(0)

        self.source = source  # PortEdge(pos, self)
        self.dest = dest  # PortEdge(QtCore.QPointF(0, 30)+pos, self)

        self.arrowSize = 20.0
        self.penWidth = 10.0
        self.sourcePoint = QtCore.QPointF()
        self.destPoint = QtCore.QPointF()

        self.setFlag(QtGui.QGraphicsItem.ItemSendsGeometryChanges)
        self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)

        self.setAcceptedMouseButtons(QtCore.Qt.NoButton)
        self.source.addMacroEdge(self)
        self.dest.addMacroEdge(self)
        self.adjust()

        self.fontHeight = 20
Пример #6
0
    def paint(self, painter, option, widget):  # EDGE
        if not self.source or not self.dest:
            return

        # Draw the line itself.
        line = QtCore.QLineF(self.sourcePoint, self.destPoint)

        if line.length() == 0.0:
            return

        if self.isSelected(
        ) or self._beingHovered or self.connectedPortIsHovered():
            fade = QtGui.QColor(QtCore.Qt.red)
            fade.setAlpha(200)
            #painter.setPen(QtGui.QPen(QtCore.Qt.red, 1, QtCore.Qt.DashLine,
            painter.setPen(
                QtGui.QPen(fade, 2, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                           QtCore.Qt.RoundJoin))
        elif self.isCyclicConnection():
            painter.setPen(
                QtGui.QPen(QtCore.Qt.red, 2, QtCore.Qt.SolidLine,
                           QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        else:
            fade = QtGui.QColor(QtCore.Qt.black)
            fade.setAlpha(150)
            #painter.setPen(QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine,
            painter.setPen(
                QtGui.QPen(fade, 2, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                           QtCore.Qt.RoundJoin))

        painter.drawLine(line)
        x = (line.x1() + line.x2()) / 2.0
        y = (line.y1() + line.y2()) / 2.0
        xa = (line.x1() - line.x2())
        ya = (line.y1() - line.y2())
        m = math.sqrt(xa * xa + ya * ya)
        a = math.atan2(ya, xa) * 180.0 / math.pi
        buf = self.source.getDataString()
        if self._beingHovered:
            f = QtGui.QFont("Times New Roman", 8)
        else:
            f = QtGui.QFont("Times New Roman", 6)
        fm = QtGui.QFontMetricsF(f)
        bw = fm.width(buf)
        bw2 = -bw * 0.5
        #bh = fm.height()

        # bezier curves
        if False:
            sa = (a + 90.) * 0.5
            path = QtGui.QPainterPath(line.p1())
            path.cubicTo(x - sa, y - sa, x + sa, y + sa, line.x2(), line.y2())
            painter.drawPath(path)

        # bezier curves, change direction on the angle
        if False:
            sa = (a + 90.) * 0.5
            if a > 90 or a < -90:
                path = QtGui.QPainterPath(line.p1())
                path.cubicTo(x - sa, y - sa, x + sa, y + sa, line.x2(),
                             line.y2())
                painter.drawPath(path)
            else:
                path = QtGui.QPainterPath(line.p1())
                path.cubicTo(x + sa, y + sa, x - sa, y - sa, line.x2(),
                             line.y2())
                painter.drawPath(path)

        painter.setFont(f)
        if self._beingHovered:
            painter.setPen(QtGui.QPen(QtCore.Qt.red, 1))
        else:
            painter.setPen(QtGui.QPen(QtCore.Qt.darkGray, 1))

        painter.save()
        painter.translate(QtCore.QPointF(x, y))
        if m > bw * 1.1 or self._beingHovered:
            if a > 90 or a < -90:
                painter.rotate(a + 180.0)
                painter.drawText(QtCore.QPointF(bw2, -2.0), buf)
            else:
                painter.rotate(a)
                painter.drawText(QtCore.QPointF(bw2, -2.0), buf)
        else:
            painter.drawText(QtCore.QPointF(bw2, -2.0), '')
        painter.restore()
Пример #7
0
    def loadSettings(self, s, nodeList, pos):
        '''load all settings from a description generated by getSettings()
        '''
        self.setID(s['id'])
        self.setLabelWdg(s['label'])
        self.setLabel(s['label'])

        self.newLayoutWindowFromSettings(s['layoutWindow'], nodeList)

        if s['collapse']:
            x = s['face_settings']['pos'][0] + pos[0]
            y = s['face_settings']['pos'][1] + pos[1]
            #x = s['src_pos'][0] + pos[0]
            #y = s['src_pos'][1] + pos[1]
            self._src.setPos(QtCore.QPointF(x, y))

            # need relative jaw pos
            #x = s['sink_settings']['pos'][0] + pos[0]
            #y = s['sink_settings']['pos'][1] + pos[1]
            #self._sink.setPos(QtCore.QPoint(x, y))
            x += s['rel_jaw_pos'][0]
            y += s['rel_jaw_pos'][1]
            self._sink.setPos(QtCore.QPointF(x, y))

            x = s['face_settings']['pos'][0] + pos[0]
            y = s['face_settings']['pos'][1] + pos[1]
            self._face.setPos(QtCore.QPointF(x, y))

            rel = QtCore.QPointF(x, y)
            for nid, epos in list(s['nodes_rel_pos'].items()):
                enode = self.getNodeByID(nodeList, int(nid))
                if enode:
                    enode.setPos(rel + QtCore.QPointF(*epos))
                    log.debug("node found by nid: " + enode.name)
                    log.debug("pos: ")
                    log.debug(str(epos))
                    log.debug(str(rel))
                    log.debug(str(QtCore.QPointF(*epos)))
                    log.debug(str(rel + QtCore.QPointF(*epos)))
                else:
                    log.warn("nid not found: " + str(nid))

        else:
            x = s['src_settings']['pos'][0] + pos[0]
            y = s['src_settings']['pos'][1] + pos[1]
            self._src.setPos(QtCore.QPointF(x, y))

            x = s['sink_settings']['pos'][0] + pos[0]
            y = s['sink_settings']['pos'][1] + pos[1]
            self._sink.setPos(QtCore.QPointF(x, y))

            x = s['src_settings']['pos'][0] + pos[0]
            y = s['src_settings']['pos'][1] + pos[1]
            self._face.setPos(QtCore.QPointF(x, y))

        self._src.setID(s['src_settings']['id'])
        self._sink.setID(s['sink_settings']['id'])
        self._face.setID(s['face_settings']['id'])

        # save expanded positions
        self._src_exppos = self._src.getPos()
        self._sink_exppos = self._sink.getPos()
        self._face_colpos = self._face.getPos()

        # self.setCollapse(s['collapse'])
        self._destined_collapse = s['collapse']
Пример #8
0
    def paint(self, painter, option, widget):
        if not self.source or not self.dest:
            return

        # Draw the line itself.
        line = QtCore.QLineF(self.sourcePoint, self.destPoint)

        if line.length() == 0.0:
            return

        painter.setPen(
            QtGui.QPen(QtCore.Qt.gray, self.penWidth, QtCore.Qt.SolidLine,
                       QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        painter.drawLine(line)

        # drawing text
        x = (line.x1() + line.x2()) / 2.0
        y = (line.y1() + line.y2()) / 2.0
        xa = (line.x1() - line.x2())
        ya = (line.y1() - line.y2())
        m = math.sqrt(xa * xa + ya * ya)
        a = math.atan2(ya, xa) * 180.0 / math.pi
        buf = "Macro"
        f = QtGui.QFont("times", 20)
        fm = QtGui.QFontMetricsF(f)
        bw = fm.width(buf)
        bw2 = -bw * 0.5
        # bh = fm.height()

        # Draw the arrows if there's enough room.
        angle = math.acos(line.dx() / line.length())
        if line.dy() >= 0:
            angle = self.TwoPi - angle

        sourceArrowP1 = self.sourcePoint + QtCore.QPointF(
            math.sin(angle + self.Pi / 3) * self.arrowSize,
            math.cos(angle + self.Pi / 3) * self.arrowSize)
        sourceArrowP2 = self.sourcePoint + QtCore.QPointF(
            math.sin(angle + self.Pi - self.Pi / 3) * self.arrowSize,
            math.cos(angle + self.Pi - self.Pi / 3) * self.arrowSize)
        destArrowP1 = self.destPoint + QtCore.QPointF(
            math.sin(angle - self.Pi / 3) * self.arrowSize,
            math.cos(angle - self.Pi / 3) * self.arrowSize)
        destArrowP2 = self.destPoint + QtCore.QPointF(
            math.sin(angle - self.Pi + self.Pi / 3) * self.arrowSize,
            math.cos(angle - self.Pi + self.Pi / 3) * self.arrowSize)

        painter.setBrush(QtCore.Qt.gray)
        painter.drawPolygon(
            QtGui.QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
        painter.drawPolygon(
            QtGui.QPolygonF([line.p2(), destArrowP1, destArrowP2]))

        # drawing text
        painter.setFont(f)
        painter.setPen(QtGui.QPen(QtCore.Qt.darkGray, 1))
        painter.save()
        painter.translate(QtCore.QPointF(x, y))
        if m > bw * 1.1:
            if a > 90 or a < -90:
                painter.rotate(a + 180.0)
                painter.drawText(QtCore.QPointF(bw2, -5.0), buf)
            else:
                painter.rotate(a)
                painter.drawText(QtCore.QPointF(bw2, -5.0), buf)
        else:
            painter.drawText(QtCore.QPointF(bw2, -5.0), '')
        painter.restore()
Пример #9
0
    def __init__(self,
                 nodeWidget,
                 CanvasBackend,
                 portTitle,
                 portNum,
                 intype=None,
                 dtype=None,
                 ndim=None,
                 menuWidget=None):
        super(Port, self).__init__()

        self._id = None
        self.setID()

        self.node = nodeWidget
        self.menuWidget = menuWidget  # a reference to a module menu widget
        self.graph = CanvasBackend
        self.edgeList = []
        self.newPos = QtCore.QPointF()

        self.setFlag(QtGui.QGraphicsItem.ItemSendsGeometryChanges)
        self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
        self.setZValue(3)

        ## TYPE info
        self._GPIType = intype  # basic data type
        # for NPY arrays
        self._dtype = dtype  # array data type
        self._ndim = ndim
        self._obligation = None  # inport use only
        # a link to the data
        self._data = None

        # position
        self.portNum = portNum
        self.portTitle = portTitle
        if portTitle is None:
            self.portTitle = str(portNum)

        # port shape
        self.largenessFact = 3.0
        self.pointsCoord = [[0.0, 0.0], [7.0, 0.0], [3.5, 5]]
        self.setTransformOriginPoint(3.5, 5)
        if isinstance(self, OutPort):
            self.setTransformOriginPoint(3.5, 0)
        # self.portShape = trianglePolygon = QtGui.QPolygonF()
        self.portShape = QtGui.QPolygonF()
        for i in self.pointsCoord:
            self.portShape.append(QtCore.QPointF(i[0], i[1]))

        # box
        # self.pointsCoord_canvasConnect = [[0.0, 0.0], [7.0, 0.0], [7.0, 5], [0.0, 5]]
        # bowtie
        #self.pointsCoord_canvasConnect = [[0.0, 0.0], [7.0, 0.0], [3.5, 2.5], [0.0, 5.0], [7.0, 5.0], [3.5, 2.5]]
        #self.portShape_canvasConnect = QtGui.QPolygonF()
        #for i in self.pointsCoord_canvasConnect:
        #    self.portShape_canvasConnect.append(QtCore.QPointF(i[0], i[1]))

        # box
        # self.pointsCoord_canvasConnect = [[0.0, 0.0], [7.0, 0.0], [7.0, 5], [0.0, 5]]
        # bowtie
        self.pointsCoord_memSave = [[0.0, 0.0], [7.0, 0.0], [3.5, 2.5],
                                    [0.0, 5.0], [7.0, 5.0], [3.5, 2.5]]
        self.portShape_memSave = QtGui.QPolygonF()
        for i in self.pointsCoord_memSave:
            self.portShape_memSave.append(QtCore.QPointF(i[0], i[1]))

        self.setCursor(QtCore.Qt.CrossCursor)

        self.setAcceptHoverEvents(True)
        self._beingHovered = False
        self.updateToolTip()

        # src or sink
        self._canvasConnect = False

        # save memory
        self._savemem = False