Python PyQt5.QtGui.QPolygonF() Examples

The following are code examples for showing how to use PyQt5.QtGui.QPolygonF(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 2
Project: phidl   Author: amccaugh   File: quickplotter.py    MIT License 6 votes vote down vote up
def add_polygons(self, polygons, color = '#A8F22A', alpha = 1):
        qcolor = QColor()
        qcolor.setNamedColor(color)
        qcolor.setAlphaF(alpha)
        for points in polygons:
            qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in points] )
            scene_poly = self.scene.addPolygon(qpoly)
            scene_poly.setBrush(qcolor)
            scene_poly.setPen(self.pen)
            self.scene_polys.append(scene_poly)
            # Update custom bounding box
            sr = scene_poly.sceneBoundingRect()
            if len(self.scene_polys) == 1:
                self.scene_xmin = sr.left()
                self.scene_xmax = sr.right()
                self.scene_ymin = sr.top()
                self.scene_ymax = sr.bottom()
            else:
                self.scene_xmin = min(self.scene_xmin, sr.left())
                self.scene_xmax = max(self.scene_xmax, sr.right())
                self.scene_ymin = min(self.scene_ymin, sr.top())
                self.scene_ymax = max(self.scene_ymax, sr.bottom()) 
Example 3
Project: echolocation   Author: hgross   File: radar.py    MIT License 6 votes vote down vote up
def _add_latest_input_line(self, angle):
        """Adds a line to the graphic scene that visualizes a scanned angle"""
        mx, my = self._get_middle()
        angle_rad = deg2rad(angle)
        angle_1_rad = deg2rad(angle - self.measurement_angle/2.0)
        angle_2_rad = deg2rad(angle + self.measurement_angle/2.0)
        length = max(self.width(), self.height())

        start_point = (mx, my)
        p1 = (mx + length * math.cos(angle_1_rad), my + length * math.sin(angle_1_rad))
        p2 = (mx + length * math.cos(angle_2_rad), my + length * math.sin(angle_2_rad))

        gradient_start_point, gradient_end_point = (mx, my), (mx + length * math.cos(angle_rad), my + length * math.sin(angle_rad))
        gradient = QLinearGradient(*gradient_start_point, *gradient_end_point)
        gradient.setColorAt(0, Qt.transparent)
        gradient.setColorAt(0.8, Qt.red)
        gradient.setColorAt(1, Qt.darkRed)

        triangle = QPolygonF()
        triangle.append(QPointF(*start_point))
        triangle.append(QPointF(*p1))
        triangle.append(QPointF(*p2))
        triangle.append(QPointF(*start_point))

        self.scene.addPolygon(triangle, pen=QPen(Qt.transparent), brush=QBrush(gradient)) 
Example 4
Project: PyRHEED   Author: yux1991   File: canvas.py    MIT License 6 votes vote down vote up
def draw_rect(self,start,end,width,EnablePlot = True):
        self.clear_canvas()
        rect = QtGui.QPolygonF()
        if QtGui.QGuiApplication.queryKeyboardModifiers().__eq__(QtCore.Qt.ShiftModifier):
            if end.x() == start.x():
                slope = 10
            else:
                slope = (end.y()-start.y())/(end.x()-start.x())
            if slope > np.tan(np.pi/3):
                end.setX(start.x())
            elif slope < np.tan(np.pi/6):
                end.setY(start.y())
            else:
                end.setY(end.x()-start.x()+start.y())
        p1,p2,p3,p4 = self.get_rectangle_position(start,end,width)
        rect.append(p1)
        rect.append(p2)
        rect.append(p3)
        rect.append(p4)
        self._rectItem = self._scene.addPolygon(rect,QtGui.QPen(QtCore.Qt.yellow,1))
        self._rectItem.show()
        self.canvasObject = "rectangle"
        self.saveStart,self.saveEnd,self.saveWidth = start,end,width
        if EnablePlot:
            self.PLOT_INTEGRAL.emit(self.saveStart,self.saveEnd,self.saveWidth) 
Example 5
Project: BUAAAIHomeWork   Author: potato-cat   File: small_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        path.moveTo(self.start)
        path.lineTo(self.end)

        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.end - QPointF(SMALL_ARROW_WIDTH * math.cos(sita),
                                SMALL_ARROW_WIDTH * math.sin(sita))
        p2 = p1 - QPointF(-(SMALL_ARROW_WIDTH / 2) * math.sin(sita),
                          (SMALL_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p1 + QPointF(-SMALL_ARROW_WIDTH / 2 * math.sin(sita),
                          SMALL_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p2, p3, self.end, p2]))
        # path = path.simplified()
        painter.setPen(QPen(self.color, 2))
        painter.setBrush(self.color)
        painter.drawPath(path)
        painter.setPen(Qt.red)
        painter.drawPoint(p1) 
Example 6
Project: BUAAAIHomeWork   Author: potato-cat   File: big_arrow.py    GNU General Public License v3.0 6 votes vote down vote up
def paint(self, painter, option, widget):
        path = QPainterPath()
        l_arrow = self.end - self.start
        length = math.sqrt(l_arrow.x() ** 2 + l_arrow.y() ** 2)
        sita = math.atan2(l_arrow.y(), l_arrow.x())
        p1 = self.start + QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p2 = self.start - QPointF(-(BIG_ARROW_WIDTH / 2) * math.sin(sita),
                                  (BIG_ARROW_WIDTH / 2) * math.cos(sita))
        p3 = p2 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p4 = p3 - QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        p5 = self.end
        p7 = p1 + QPointF((length - BIG_ARROW_WIDTH) * math.cos(sita),
                          (length - BIG_ARROW_WIDTH) * math.sin(sita))
        p6 = p7 + QPointF(-BIG_ARROW_WIDTH / 2 * math.sin(sita),
                          BIG_ARROW_WIDTH / 2 * math.cos(sita))
        path.addPolygon(QPolygonF([p1, p2, p3, p4, p5, p6, p7, p1]))
        # path = path.simplified()
        painter.setPen(Qt.black)
        painter.setBrush(Qt.yellow)
        painter.drawPath(path) 
Example 7
Project: PyQtSamples   Author: Upcios   File: text_balloon.py    MIT License 6 votes vote down vote up
def paint( self, painter ):
        brush = QtGui.QBrush( QtGui.QColor( "#007430" ) )

        painter.setBrush( brush )
        painter.setPen( QtCore.Qt.NoPen )
        painter.setRenderHint( QtGui.QPainter.Antialiasing )

        painter.drawRoundedRect( 0, 0, self.boundingRect().width(), self.boundingRect().height() - 10, 10, 10 )

        if self.rightAligned:
            points = []
            points.append( QtCore.QPointF( self.boundingRect().width() - 10.0, self.boundingRect().height() - 10.0 ) )
            points.append( QtCore.QPointF( self.boundingRect().width() - 20.0, self.boundingRect().height() ) )
            points.append( QtCore.QPointF( self.boundingRect().width() - 30.0, self.boundingRect().height() - 10.0 ) )
            #needle = QtCore.Qt.QPolygon(points)
            painter.drawConvexPolygon( QtGui.QPolygonF(points) )
        else:
            points = []
            points.append( QtCore.QPointF( 10.0, self.boundingRect().height() - 10.0 ) )
            points.append( QtCore.QPointF( 20.0, self.boundingRect().height() ) )
            points.append( QtCore.QPointF( 30.0, self.boundingRect().height() - 10.0 ) )
            painter.drawConvexPolygon( QtGui.QPolygonF(points) ) 
Example 8
Project: GeoMop   Author: GeoMop   File: scene.py    GNU General Public License v3.0 6 votes vote down vote up
def update(self):
        def com_point(seg1, seg2):
            p0 = seg1.points[0]
            if (p0 is seg2.points[0]) or (p0 is seg2.points[1]):
                return p0
            p1 = seg1.points[1]
            if (p1 is seg2.points[0]) or (p1 is seg2.points[1]):
                return p1
            return None

        def pol_append(pol, seg1, seg2):
            p = com_point(seg1, seg2)
            pol.append(QtCore.QPointF(p.xy[0], p.xy[1]))

        pol = QtGui.QPolygonF()
        segs = self.polygon_data.segments
        pol_append(pol, segs[-1], segs[0])
        for i in range(len(self.polygon_data.segments) - 1):
            pol_append(pol, segs[i], segs[i+1])

        self.setPolygon(pol)
        self.region_brush = GsPolygon.brush_table(self.polygon_data.region.color)
        super().update() 
Example 9
Project: GeoMop   Author: GeoMop   File: diagram_structures.py    GNU General Public License v3.0 6 votes vote down vote up
def get_area_poly(self, layers, diagram_id):
        """Return init area as squads intersection"""
        quads = layers.get_diagram_quads(diagram_id)
        if len(quads)==0:
            return self.area.gtpolygon
        poly = None
        for quad in quads:
            new_poly = QtGui.QPolygonF([
                QtCore.QPointF(quad[0][0], -quad[0][1]), 
                QtCore.QPointF(quad[1][0], -quad[1][1]), 
                QtCore.QPointF(quad[2][0], -quad[2][1]), 
                QtCore.QPointF(quad[3][0], -quad[3][1]), 
                QtCore.QPointF(quad[0][0], -quad[0][1])])
            if poly is None:
                poly = new_poly
            else:
                poly = new_poly.intersected(poly)
        return poly 
Example 10
Project: GeoMop   Author: GeoMop   File: polygon_operation.py    GNU General Public License v3.0 6 votes vote down vote up
def _get_lines_and_qtpoly(self, diagram, polygon):
        """Return lines and qt polygon"""
        points = polygon.vertices()
        qtpolygon = QtGui.QPolygonF()
        lines = []        
        for i in range(0, len(points)):            
            qtpolygon.append(QtCore.QPointF(points[i].xy[0], -points[i].xy[1]))
            if i==0:
                line = diagram.find_line(points[-1].id, points[0].id)
            else:
                line = diagram.find_line(points[i-1].id, points[i].id)
            if line is None:
                raise Exception("Can't find polygon line in diagram")
            lines.append(line)
        qtpolygon.append(QtCore.QPointF(points[0].xy[0], -points[0].xy[1]))
        return lines, qtpolygon 
Example 11
Project: eddy   Author: danielepantaleone   File: common.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, geometry=QtGui.QPolygonF(),
         brush=QtGui.QBrush(QtCore.Qt.NoBrush),
         pen=QtGui.QPen(QtCore.Qt.NoPen)):
        """
        Initialize the polygon.
        :type geometry: T <= QRectF|QtGui.QPolygonF|QPainterPath
        :type brush: QBrush
        :type pen: QPen
        """
        self._geometry = geometry
        self._brush = brush
        self._pen = pen

    #############################################
    #   INTERFACE
    ################################# 
Example 12
Project: tierpsy-tracker   Author: ver228   File: MWTrackerViewer.py    MIT License 6 votes vote down vote up
def draw_food_contour(self, image):
        if self.food_coordinates is None or not self.ui.checkBox_showFood.isChecked():
            return

        painter = QPainter()
        painter.begin(image)

        penwidth = max(1, max(image.height(), image.width()) // 800)
        col = Qt.darkMagenta
        p = QPolygonF()
        for x,y in self.food_coordinates:
            p.append(QPointF(x,y))
            
        pen = QPen()
        pen.setWidth(penwidth)
        pen.setColor(col)
        painter.setPen(pen)

        painter.drawPolyline(p)
        painter.end() 
Example 13
Project: PyQt   Author: PyQt5   File: RewriteHandle.py    GNU General Public License v3.0 6 votes vote down vote up
def paintEvent(self, event):
        # 绘制默认的样式
        super(SplitterHandle, self).paintEvent(event)
        # 绘制顶部扩展按钮
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing, True)
        painter.setPen(Qt.red)
        # 画矩形
        painter.drawRect(0, 0, self.width(), 24)
        # 画三角形
        painter.setBrush(Qt.red)
        painter.drawPolygon(QPolygonF([
            QPointF(0, (24 - 8) / 2),
            QPointF(self.width() - 2, 24 / 2),
            QPointF(0, (24 + 8) / 2)
        ])) 
Example 14
Project: EGame   Author: digital-bauhaus   File: heal_potion.py    MIT License 6 votes vote down vote up
def draw_polygon(self, painter):
        color = QColor(self.color)
        painter.setPen(QColor(0, 0, 0))
        painter.setBrush(color)

        r = self.size/2

        polygon = QPolygonF()
        polygon.append(QPointF(self._position[0] + r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0]    , self._position[1] + r  ))
        polygon.append(QPointF(self._position[0] - r, self._position[1] + r/2))
        polygon.append(QPointF(self._position[0] - r, self._position[1] - r/2))
        polygon.append(QPointF(self._position[0]    , self._position[1] - r  ))
        polygon.append(QPointF(self._position[0] + r, self._position[1] - r/2))

        painter.drawPolygon(polygon) 
Example 15
Project: eddy   Author: obdasystems   File: geometry.py    GNU General Public License v3.0 5 votes vote down vote up
def createArea(p1, p2, degrees, size):
    """
    Creates an area between the given QPointF and according to the given angle and size.
    :type p1: QPointF
    :type p2: QPointF
    :type degrees: float
    :type size: int
    :rtype: QPolygonF
    """
    rad = math.radians(degrees)
    x = size / 2 * math.sin(rad)
    y = size / 2 * math.cos(rad)
    a = QtCore.QPointF(+x, +y)
    b = QtCore.QPointF(-x, -y)
    return QtGui.QPolygonF([p1 + a, p1 + b, p2 + b, p2 + a]) 
Example 16
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        """
        Initialize the edge.
        """
        super().__init__(**kwargs)
        self.tail = Polygon(QtGui.QPolygonF())

    #############################################
    #   INTERFACE
    ################################# 
Example 17
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 18
Project: eddy   Author: obdasystems   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createTail(p1, angle, size):
        """
        Create the tail polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 + QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 + QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 19
Project: eddy   Author: obdasystems   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 4.0) * size, cos(rad + M_PI / 4.0) * size)
        p3 = p2 - QtCore.QPointF(sin(rad + 3.0 / 4.0 * M_PI) * size, cos(rad + 3.0 / 4.0 * M_PI) * size)
        p4 = p3 - QtCore.QPointF(sin(rad - 3.0 / 4.0 * M_PI) * size, cos(rad - 3.0 / 4.0 * M_PI) * size)
        return QtGui.QPolygonF([p1, p2, p3, p4]) 
Example 20
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, source, target=None, breakpoints=None, **kwargs):
        """
        Initialize the edge.
        :type source: AbstractNode
        :type target: AbstractNode
        :type breakpoints: list
        """
        super().__init__(**kwargs)

        self.source = source
        self.target = target

        self.anchors = {} # {AbstractNode: Polygon}
        self.breakpoints = breakpoints or [] # [QtCore.QPointF]
        self.handles = [] # [Polygon]
        self.head = Polygon(QtGui.QPolygonF())
        self.path = Polygon(QtGui.QPainterPath())
        self.selection = Polygon(QtGui.QPainterPath())

        self.mp_AnchorNode = None
        self.mp_AnchorNodePos = None
        self.mp_BreakPoint = None
        self.mp_BreakPointPos = None
        self.mp_Pos = None

        self.setAcceptHoverEvents(True)
        self.setCacheMode(AbstractItem.DeviceCoordinateCache)
        self.setFlag(AbstractItem.ItemIsSelectable, True)

    #############################################
    #   INTERFACE
    ################################# 
Example 21
Project: eddy   Author: obdasystems   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 22
Project: eddy   Author: obdasystems   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=60, height=60, brush=None, remaining_characters='individual', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        w = max(width, 60)
        h = max(height, 60)
        brush = brush or IndividualNode.DefaultBrush
        pen = IndividualNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
        ])

        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='individual', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos() 
Example 23
Project: eddy   Author: obdasystems   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=70, height=50, brush=None, remaining_characters='role', **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        
        w = max(width, 70)
        h = max(height, 50)
        brush = brush or RoleNode.DefaultBrush
        pen = RoleNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(0, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(0, -y / 2),
            QtCore.QPointF(-x / 2, 0)
        ])

        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.ipolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)

        self.remaining_characters = remaining_characters

        self.label = NodeLabel(template='role', pos=self.center, parent=self, editable=True)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   INTERFACE
    ################################# 
Example 24
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygon(w, h):
        """
        Returns the initialized polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10, -h / 2),
            QtCore.QPointF(+w / 2, -h / 2),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10, -h / 2),
        ]) 
Example 25
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygonB(w, h):
        """
        Returns the initialized bottom-half polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
        ]) 
Example 26
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryA(self):
        """
        Returns the geometry of the shape A of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonA.geometry() 
Example 27
Project: eddy   Author: obdasystems   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryB(self):
        """
        Returns the geometry of the shape B of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonB.geometry() 
Example 28
Project: eddy   Author: obdasystems   File: operator.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=50, height=30, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(-x / 2 + 6, +y / 2),
            QtCore.QPointF(+x / 2 - 6, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(+x / 2 - 6, -y / 2),
            QtCore.QPointF(-x / 2 + 6, -y / 2),
            QtCore.QPointF(-x / 2, 0),
        ])

        self.background = Polygon(createPolygon(58, 38))
        self.selection = Polygon(createPolygon(58, 38))
        self.polygon = Polygon(createPolygon(50, 30), brush or OperatorNode.DefaultBrush, OperatorNode.DefaultPen)

    #############################################
    #   INTERFACE
    ################################# 
Example 29
Project: eddy   Author: obdasystems   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the geometry of the shape of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygon.geometry() 
Example 30
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def geometry(self):
        """
        Returns the polygon geometry.
        :rtype: T <= QRectF | QPolygonF | QPainterPath
        """
        return self._geometry 
Example 31
Project: eddy   Author: obdasystems   File: common.py    GNU General Public License v3.0 5 votes vote down vote up
def setGeometry(self, geometry):
        """
        Set the shape polygon.
        :type geometry: T <= QRectF | QPolygonF | QPainterPath
        """
        self._geometry = geometry 
Example 32
Project: phidl   Author: amccaugh   File: quickplotter.py    MIT License 5 votes vote down vote up
def add_port(self, port, is_subport = False):
        if (port.width is None) or (port.width == 0):
            x,y = port.midpoint
            cs = 1 # cross size
            pn = QPointF(x, y+cs)
            ps = QPointF(x, y-cs)
            pe = QPointF(x+cs, y)
            pw = QPointF(x-cs, y)
            qline1 = self.scene.addLine(QLineF(pn, ps))
            qline2 = self.scene.addLine(QLineF(pw, pe))
            port_shapes = [qline1,qline2]
        else:
            point1, point2 = port.endpoints
            point1 = QPointF(point1[0], point1[1])
            point2 = QPointF(point2[0], point2[1])
            qline = self.scene.addLine(QLineF(point1, point2))
            arrow_points = np.array([[0,0],[10,0],[6,4],[6,2],[0,2]])/(40)*port.width
            arrow_qpoly = QPolygonF( [QPointF(p[0], p[1]) for p in arrow_points] )
            port_scene_poly = self.scene.addPolygon(arrow_qpoly)
            port_scene_poly.setRotation(port.orientation)
            port_scene_poly.moveBy(port.midpoint[0], port.midpoint[1])
            port_shapes = [qline,port_scene_poly]
        qtext = self.scene.addText(str(port.name), self.portfont)
        port_items = port_shapes + [qtext]
        rad = port.orientation*np.pi/180
        x,y = port.endpoints[0]*1/4 +  port.endpoints[1]*3/4 + np.array([np.cos(rad), np.sin(rad)])*port.width/8
#        x,y = port.midpoint[0], port.midpoint[1]
#        x,y  = x - qtext.boundingRect().width()/2, y - qtext.boundingRect().height()/2
        qtext.setPos(QPointF(x,y))
        qtext.setFlag(QGraphicsItem.ItemIgnoresTransformations)

        if not is_subport:
            [shape.setPen(self.portpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.portfontcolor)
            self.portitems += port_items
        else:
            [shape.setPen(self.subportpen) for shape in port_shapes]
            qtext.setDefaultTextColor(self.subportfontcolor)
            self.subportitems += port_items
#        self.portlabels.append(qtext) 
Example 33
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab2.py    MIT License 5 votes vote down vote up
def turn():
    global epi_x, epi_y, p1, p2, p3, p4, rect
    write_log()
    teta = math.radians(window.spin_deg.value())
    t_x = window.spin_turn_x.value()
    t_y = window.spin_turn_y.value()
    scene.clear()

    rect_t = QPolygonF(4)
    p1 = [t_x + (p1[0] - t_x) * math.cos(teta) + (p1[1] - t_y) * math.sin(teta),
          t_y - (p1[0] - t_x) * math.sin(teta) + (p1[1] - t_y) * math.cos(teta)]
    p2 = [t_x + (p2[0] - t_x) * math.cos(teta) + (p2[1] - t_y) * math.sin(teta),
          t_y - (p2[0] - t_x) * math.sin(teta) + (p2[1] - t_y) * math.cos(teta)]
    p3 = [t_x + (p3[0] - t_x) * math.cos(teta) + (p3[1] - t_y) * math.sin(teta),
          t_y - (p3[0] - t_x) * math.sin(teta) + (p3[1] - t_y) * math.cos(teta)]
    p4 = [t_x + (p4[0] - t_x) * math.cos(teta) + (p4[1] - t_y) * math.sin(teta),
          t_y - (p4[0] - t_x) * math.sin(teta) + (p4[1] - t_y) * math.cos(teta)]
    rect[0] = QPointF(p1[0], p1[1])
    rect[1] = QPointF(p2[0], p2[1])
    rect[2] = QPointF(p3[0], p3[1])
    rect[3] = QPointF(p4[0], p4[1])
    scene.addPolygon(rect, pen=p, brush=b)
    l = len(epi_x)
    for i in range(l):
        x1 = t_x + (epi_x[i] - t_x) * math.cos(teta) + (epi_y[i] - t_y) * math.sin(teta)
        y1 = t_y - (epi_x[i] - t_x) * math.sin(teta) + (epi_y[i] - t_y) * math.cos(teta)
        epi_x[i] = x1
        epi_y[i] = y1
        scene.addLine(epi_x[i], epi_y[i], epi_x[i] + 0.01, epi_y[i] + 0.01, pen=p) 
Example 34
Project: Computer-graphics   Author: Panda-Lewandowski   File: lab9.py    MIT License 5 votes vote down vote up
def sutherland_hodgman(clip, pol, norm):
    # дублируем начальную вершину отсекателя в конец
    clip.append(clip[0])

    s = None
    f = None
    # цикл по вершинам отсекателя
    for i in range(len(clip) - 1):
        new = []  # новый массив вершин
        for j in range(len(pol)):    # цикл по вершинам многоугольника
            if j == 0:
                f = pol[j]
            else:
                t = is_intersection([s, pol[j]], [clip[i], clip[i + 1]], norm)
                if t:
                    new.append(t)

            s = pol[j]
            if is_visiable(s,  clip[i], clip[i + 1], norm):
                    new.append(s)

        if len(new) != 0:
            t = is_intersection([s, f], [clip[i], clip[i + 1]], norm)
            if t:
                new.append(t)

        pol = copy.deepcopy(new)

    if len(pol) == 0:
        return False
    else:
        return QPolygonF(pol) 
Example 35
Project: GeoMop   Author: GeoMop   File: diagram_structures.py    GNU General Public License v3.0 5 votes vote down vote up
def set_area(self, points):
        """Set rectangular arrea containing given points."""
        self.gtpolygon = QtGui.QPolygonF()
        self.xmin = points[0][0]
        self.xmax = points[0][0]
        self.ymin = -points[0][1]
        self.ymax = -points[0][1]
        for x, y in points:
            self.gtpolygon.append(QtCore.QPointF(x, -y))
            self.xmin = min(self.xmin, x)
            self.xmax = max(self.xmax, x)
            self.ymin = min(self.ymin, -y)
            self.ymax = max(self.ymax, -y)
        self.gtpolygon.append(QtCore.QPointF(points[0][0], -points[0][1])) 
Example 36
Project: GeoMop   Author: GeoMop   File: polygon_operation.py    GNU General Public License v3.0 5 votes vote down vote up
def _add_to_painter_path(cls, path, wire):
        vtxs = cls._get_wire_oriented_vertices(wire)
        point_list = [QtCore.QPointF(vtxx, -vtxy) for vtxx, vtxy in vtxs]
        sub_poly = QtGui.QPolygonF(point_list)
        path.addPolygon(sub_poly) 
Example 37
Project: GeoMop   Author: GeoMop   File: grid.py    GNU General Public License v3.0 5 votes vote down vote up
def set_quad(self, quad, nuv):
        """Set quad"""
        self.quad = quad
        polygon = QtGui.QPolygonF()
        for point in quad:
            polygon.append(QtCore.QPointF(point[0], -point[1]))
        polygon.append(QtCore.QPointF(quad[0][0], -quad[0][1]))
        self.u, self.v  = nuv
        self.setPolygon(polygon)
        self.update() 
Example 38
Project: GeoMop   Author: GeoMop   File: init_area.py    GNU General Public License v3.0 5 votes vote down vote up
def reload(self):
        """Reload new init area"""
        bbox = cfg.diagram.get_diagram_all_rect(cfg.diagram.rect, cfg.layers, cfg.diagrams.index(cfg.diagram))
        poly = QtGui.QPolygonF(bbox)
        self.setPolygon(poly)
        cfg.diagram.area.gtpolygon = poly 
Example 39
Project: eddy   Author: danielepantaleone   File: geometry.py    GNU General Public License v3.0 5 votes vote down vote up
def createArea(p1, p2, degrees, size):
    """
    Creates an area between the given QPointF and according to the given angle and size.
    :type p1: QPointF
    :type p2: QPointF
    :type degrees: float
    :type size: int
    :rtype: QPolygonF
    """
    rad = math.radians(degrees)
    x = size / 2 * math.sin(rad)
    y = size / 2 * math.cos(rad)
    a = QtCore.QPointF(+x, +y)
    b = QtCore.QPointF(-x, -y)
    return QtGui.QPolygonF([p1 + a, p1 + b, p2 + b, p2 + a]) 
Example 40
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, **kwargs):
        """
        Initialize the edge.
        """
        super().__init__(**kwargs)
        self.tail = Polygon(QtGui.QPolygonF())

    #############################################
    #   INTERFACE
    ################################# 
Example 41
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 42
Project: eddy   Author: danielepantaleone   File: equivalence.py    GNU General Public License v3.0 5 votes vote down vote up
def createTail(p1, angle, size):
        """
        Create the tail polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 + QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 + QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 43
Project: eddy   Author: danielepantaleone   File: input.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 4.0) * size, cos(rad + M_PI / 4.0) * size)
        p3 = p2 - QtCore.QPointF(sin(rad + 3.0 / 4.0 * M_PI) * size, cos(rad + 3.0 / 4.0 * M_PI) * size)
        p4 = p3 - QtCore.QPointF(sin(rad - 3.0 / 4.0 * M_PI) * size, cos(rad - 3.0 / 4.0 * M_PI) * size)
        return QtGui.QPolygonF([p1, p2, p3, p4]) 
Example 44
Project: eddy   Author: danielepantaleone   File: base.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, source, target=None, breakpoints=None, **kwargs):
        """
        Initialize the edge.
        :type source: AbstractNode
        :type target: AbstractNode
        :type breakpoints: list
        """
        super().__init__(**kwargs)

        self.source = source
        self.target = target

        self.anchors = {} # {AbstractNode: Polygon}
        self.breakpoints = breakpoints or [] # [QtCore.QPointF]
        self.handles = [] # [Polygon]
        self.head = Polygon(QtGui.QPolygonF())
        self.path = Polygon(QtGui.QPainterPath())
        self.selection = Polygon(QtGui.QPainterPath())

        self.mp_AnchorNode = None
        self.mp_AnchorNodePos = None
        self.mp_BreakPoint = None
        self.mp_BreakPointPos = None
        self.mp_Pos = None

        self.setAcceptHoverEvents(True)
        self.setCacheMode(AbstractItem.DeviceCoordinateCache)
        self.setFlag(AbstractItem.ItemIsSelectable, True)

    #############################################
    #   INTERFACE
    ################################# 
Example 45
Project: eddy   Author: danielepantaleone   File: membership.py    GNU General Public License v3.0 5 votes vote down vote up
def createHead(p1, angle, size):
        """
        Create the head polygon.
        :type p1: QPointF
        :type angle: float
        :type size: int
        :rtype: QPolygonF
        """
        rad = radians(angle)
        p2 = p1 - QtCore.QPointF(sin(rad + M_PI / 3.0) * size, cos(rad + M_PI / 3.0) * size)
        p3 = p1 - QtCore.QPointF(sin(rad + M_PI - M_PI / 3.0) * size, cos(rad + M_PI - M_PI / 3.0) * size)
        return QtGui.QPolygonF([p1, p2, p3]) 
Example 46
Project: eddy   Author: danielepantaleone   File: individual.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=60, height=60, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)

        w = max(width, 60)
        h = max(height, 60)
        brush = brush or IndividualNode.DefaultBrush
        pen = IndividualNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), +(y / 2)),
            QtCore.QPointF(+(x / 2), +((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
            QtCore.QPointF(+((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-((x / (1 + math.sqrt(2))) / 2), -(y / 2)),
            QtCore.QPointF(-(x / 2), -((y / (1 + math.sqrt(2))) / 2)),
        ])

        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)
        self.label = NodeLabel(template='individual', pos=self.center, parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   PROPERTIES
    ################################# 
Example 47
Project: eddy   Author: danielepantaleone   File: role.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, width=70, height=50, brush=None, **kwargs):
        """
        Initialize the node.
        :type width: int
        :type height: int
        :type brush: QBrush
        """
        super().__init__(**kwargs)
        
        w = max(width, 70)
        h = max(height, 50)
        brush = brush or RoleNode.DefaultBrush
        pen = RoleNode.DefaultPen

        createPolygon = lambda x, y: QtGui.QPolygonF([
            QtCore.QPointF(-x / 2, 0),
            QtCore.QPointF(0, +y / 2),
            QtCore.QPointF(+x / 2, 0),
            QtCore.QPointF(0, -y / 2),
            QtCore.QPointF(-x / 2, 0)
        ])

        self.fpolygon = Polygon(QtGui.QPainterPath())
        self.ipolygon = Polygon(QtGui.QPainterPath())
        self.background = Polygon(createPolygon(w + 8, h + 8))
        self.selection = Polygon(createPolygon(w + 8, h + 8))
        self.polygon = Polygon(createPolygon(w, h), brush, pen)
        self.label = NodeLabel(template='role', pos=self.center, parent=self)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.updateNode()
        self.updateTextPos()

    #############################################
    #   INTERFACE
    ################################# 
Example 48
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygon(w, h):
        """
        Returns the initialized polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10, -h / 2),
            QtCore.QPointF(+w / 2, -h / 2),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10, -h / 2),
        ]) 
Example 49
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def createPolygonB(w, h):
        """
        Returns the initialized bottom-half polygon according to the given width/height.
        :type w: int
        :type h: int
        :rtype: QtGui.QPolygonF
        """
        return QtGui.QPolygonF([
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10 / 2, 0),
            QtCore.QPointF(+w / 2 - 10, +h / 2),
            QtCore.QPointF(-w / 2, +h / 2),
            QtCore.QPointF(-w / 2 + 10 / 2, 0),
        ]) 
Example 50
Project: eddy   Author: danielepantaleone   File: facet.py    GNU General Public License v3.0 5 votes vote down vote up
def geometryA(self):
        """
        Returns the geometry of the shape A of this node.
        :rtype: QtGui.QPolygonF
        """
        return self.polygonA.geometry()