Exemple #1
0
    def updateLeader(self):
        """
        TOWRITE
        """
        arrowStyle = Closed  # int # TODO: Make this customizable
        arrowStyleAngle = 15.0  # qreal # TODO: Make this customizable
        arrowStyleLength = 1.0  # qreal # TODO: Make this customizable
        self.lineStyleAngle = 45.0  # qreal # TODO: Make this customizable
        self.lineStyleLength = 1.0  # qreal # TODO: Make this customizable

        lyne = self.line()  # QLineF
        angle = lyne.angle()  # qreal
        ap0 = lyne.p1()  # QPointF
        lp0 = lyne.p2()  # QPointF

        # Arrow
        lynePerp = QLineF(lyne.pointAt(arrowStyleLength / lyne.length()), lp0)
        lynePerp.setAngle(angle + 90)
        lyne1 = QLineF(ap0, lp0)
        lyne2 = QLineF(ap0, lp0)
        lyne1.setAngle(angle + arrowStyleAngle)
        lyne2.setAngle(angle - arrowStyleAngle)
        # ap1 = QPointF()
        # ap2 = QPointF()
        _, ap1 = lynePerp.intersect(lyne1)
        _, ap2 = lynePerp.intersect(lyne2)

        # Math Diagram
        #                  .(ap1)                     .(lp1)
        #                 /|                         /|
        #                / |                        / |
        #               /  |                       /  |
        #              /   |                      /   |
        #             /    |                     /    |
        #            /     |                    /     |
        #           /      |                   /      |
        #          /       |                  /       |
        #         /+(aSA)  |                 /+(lSA)  |
        #  (ap0)./__(aSL)__|__________(lp0)./__(lSL)__|
        #        \ -(aSA)  |                \ -(lSA)  |
        #         \        |                 \        |
        #          \       |                  \       |
        #           \      |                   \      |
        #            \     |                    \     |
        #             \    |                     \    |
        #              \   |                      \   |
        #               \  |                       \  |
        #                \ |                        \ |
        #                 \|                         \|
        #                  .(ap2)                     .(lp2)

        if arrowStyle == Open:
            arrowStylePath = QPainterPath()
            arrowStylePath.moveTo(ap1)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap2)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap1)
        elif arrowStyle == Closed:
            arrowStylePath = QPainterPath()
            arrowStylePath.moveTo(ap1)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap2)
            arrowStylePath.lineTo(ap1)
        elif arrowStyle == Dot:
            arrowStylePath = QPainterPath()
            arrowStylePath.addEllipse(ap0, arrowStyleLength, arrowStyleLength)
        elif arrowStyle == Box:
            arrowStylePath = QPainterPath()
            side = QLineF(ap1, ap2).length()  # qreal
            ar0 = QRectF(0, 0, side, side)
            ar0.moveCenter(ap0)
            arrowStylePath.addRect(ar0)
        elif arrowStyle == Tick:
            pass  #TODO/PORT# Is this supposed to be empty?

        lineStylePath = QPainterPath()
        lineStylePath.moveTo(ap0)
        lineStylePath.lineTo(lp0)
    def updateLeader(self):
        """
        TOWRITE
        """
        arrowStyle = Closed     # int # TODO: Make this customizable
        arrowStyleAngle = 15.0  # qreal # TODO: Make this customizable
        arrowStyleLength = 1.0  # qreal # TODO: Make this customizable
        self.lineStyleAngle = 45.0   # qreal # TODO: Make this customizable
        self.lineStyleLength = 1.0   # qreal # TODO: Make this customizable

        lyne = self.line()  # QLineF
        angle = lyne.angle()  # qreal
        ap0 = lyne.p1()  # QPointF
        lp0 = lyne.p2()  # QPointF

        # Arrow
        lynePerp = QLineF(lyne.pointAt(arrowStyleLength / lyne.length()), lp0)
        lynePerp.setAngle(angle + 90)
        lyne1 = QLineF(ap0, lp0)
        lyne2 = QLineF(ap0, lp0)
        lyne1.setAngle(angle + arrowStyleAngle)
        lyne2.setAngle(angle - arrowStyleAngle)
        # ap1 = QPointF()
        # ap2 = QPointF()
        _, ap1 = lynePerp.intersect(lyne1)
        _, ap2 = lynePerp.intersect(lyne2)

        # Math Diagram
        #                  .(ap1)                     .(lp1)
        #                 /|                         /|
        #                / |                        / |
        #               /  |                       /  |
        #              /   |                      /   |
        #             /    |                     /    |
        #            /     |                    /     |
        #           /      |                   /      |
        #          /       |                  /       |
        #         /+(aSA)  |                 /+(lSA)  |
        #  (ap0)./__(aSL)__|__________(lp0)./__(lSL)__|
        #        \ -(aSA)  |                \ -(lSA)  |
        #         \        |                 \        |
        #          \       |                  \       |
        #           \      |                   \      |
        #            \     |                    \     |
        #             \    |                     \    |
        #              \   |                      \   |
        #               \  |                       \  |
        #                \ |                        \ |
        #                 \|                         \|
        #                  .(ap2)                     .(lp2)

        if arrowStyle == Open:
            arrowStylePath = QPainterPath()
            arrowStylePath.moveTo(ap1)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap2)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap1)
        elif arrowStyle == Closed:
            arrowStylePath = QPainterPath()
            arrowStylePath.moveTo(ap1)
            arrowStylePath.lineTo(ap0)
            arrowStylePath.lineTo(ap2)
            arrowStylePath.lineTo(ap1)
        elif arrowStyle == Dot:
            arrowStylePath = QPainterPath()
            arrowStylePath.addEllipse(ap0, arrowStyleLength, arrowStyleLength)
        elif arrowStyle == Box:
            arrowStylePath = QPainterPath()
            side = QLineF(ap1, ap2).length()  # qreal
            ar0 = QRectF(0, 0, side, side)
            ar0.moveCenter(ap0)
            arrowStylePath.addRect(ar0)
        elif arrowStyle == Tick:
            pass  #TODO/PORT# Is this supposed to be empty?

        lineStylePath = QPainterPath()
        lineStylePath.moveTo(ap0)
        lineStylePath.lineTo(lp0)
Exemple #3
0
    def updateRubber(self, painter=None):
        """
        TOWRITE

        :param `painter`: TOWRITE
        :type `painter`: `QPainter`_
        """
        rubberMode = self.objectRubberMode()  # int
        if rubberMode == OBJ_RUBBER_POLYGON:

            self.setObjectPos(self.objectRubberPoint("POLYGON_POINT_0"))

            ok = False  # bool
            numStr = self.objectRubberText("POLYGON_NUM_POINTS")  # QString
            if not numStr:
                return

            try:
                num = int(numStr)
            except ValueError:
                return

            appendStr = ''  # QString
            rubberPath = QPainterPath()
            rubberPath.moveTo(
                self.mapFromScene(self.objectRubberPoint("POLYGON_POINT_0")))
            for i in range(1, num):  # for(int i = 1; i <= num; i++)

                appendStr = "POLYGON_POINT_" + '%s' % i  # QString().setNum(i)
                appendPoint = self.mapFromScene(
                    self.objectRubberPoint(appendStr))  # QPointF
                rubberPath.lineTo(appendPoint)

            ## rubberPath.lineTo(0,0)
            self.updatePath(rubberPath)

            # Ensure the path isn't updated until the number of points is changed again.
            self.setObjectRubberText("POLYGON_NUM_POINTS", '')

        elif rubberMode == OBJ_RUBBER_POLYGON_INSCRIBE:

            self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER"))

            numSides = self.objectRubberPoint(
                "POLYGON_NUM_SIDES").x()  # quint16

            inscribePoint = self.mapFromScene(
                self.objectRubberPoint("POLYGON_INSCRIBE_POINT"))  # QPointF
            inscribeLine = QLineF(QPointF(0, 0), inscribePoint)  # QLineF
            inscribeAngle = inscribeLine.angle()  # qreal
            inscribeInc = 360.0 / numSides  # qreal

            if painter:
                self.drawRubberLine(inscribeLine, painter,
                                    "VIEW_COLOR_CROSSHAIR")

            inscribePath = QPainterPath()
            # First Point.
            inscribePath.moveTo(inscribePoint)
            # Remaining Points.
            for i in range(1, numSides):  # for(int i = 1; i < numSides; i++)

                inscribeLine.setAngle(inscribeAngle + inscribeInc * i)
                inscribePath.lineTo(inscribeLine.p2())

            self.updatePath(inscribePath)

        elif rubberMode == OBJ_RUBBER_POLYGON_CIRCUMSCRIBE:

            self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER"))

            numSides = self.objectRubberPoint(
                "POLYGON_NUM_SIDES").x()  # quint16

            circumscribePoint = self.mapFromScene(
                self.objectRubberPoint(
                    "POLYGON_CIRCUMSCRIBE_POINT"))  # QPointF
            circumscribeLine = QLineF(QPointF(0, 0),
                                      circumscribePoint)  # QLineF
            circumscribeAngle = circumscribeLine.angle()  # qreal
            circumscribeInc = 360.0 / numSides  # qreal

            if painter:
                self.drawRubberLine(circumscribeLine, painter,
                                    "VIEW_COLOR_CROSSHAIR")

            circumscribePath = QPainterPath()
            # First Point.
            prev = QLineF(circumscribeLine.p2(), QPointF(0, 0))
            prev = prev.normalVector()
            circumscribeLine.setAngle(circumscribeAngle + circumscribeInc)
            perp = QLineF(circumscribeLine.p2(), QPointF(0, 0))
            perp = perp.normalVector()
            # iPoint = QPointF()
            _, iPoint = perp.intersect(prev)
            circumscribePath.moveTo(iPoint)
            # Remaining Points.
            for i in range(2, numSides):  # for(int i = 2; i <= numSides; i++)

                prev = perp
                circumscribeLine.setAngle(circumscribeAngle +
                                          circumscribeInc * i)
                perp = QLineF(circumscribeLine.p2(), QPointF(0, 0))
                perp = perp.normalVector()
                perp.intersect(prev, iPoint)
                circumscribePath.lineTo(iPoint)

            self.updatePath(circumscribePath)

        elif rubberMode == OBJ_RUBBER_GRIP:

            if painter:

                elemCount = self.normalPath.elementCount()  # int
                gripPoint = self.objectRubberPoint("GRIP_POINT")  # QPointF
                if self.gripIndex == -1:
                    self.gripIndex = self.findIndex(gripPoint)
                if self.gripIndex == -1:
                    return

                m = 0  # int
                n = 0  # int

                if not self.gripIndex:
                    m = elemCount - 1
                    n = 1
                elif self.gripIndex == elemCount - 1:
                    m = elemCount - 2
                    n = 0
                else:
                    m = self.gripIndex - 1
                    n = self.gripIndex + 1
                em = self.normalPath.elementAt(m)  # QPainterPath::Element
                en = self.normalPath.elementAt(n)  # QPainterPath::Element
                emPoint = QPointF(em.x, em.y)  # QPointF
                enPoint = QPointF(en.x, en.y)  # QPointF
                painter.drawLine(emPoint,
                                 self.mapFromScene(self.objectRubberPoint("")))
                painter.drawLine(enPoint,
                                 self.mapFromScene(self.objectRubberPoint("")))

                rubLine = QLineF(self.mapFromScene(gripPoint),
                                 self.mapFromScene(self.objectRubberPoint("")))
                self.drawRubberLine(rubLine, painter, "VIEW_COLOR_CROSSHAIR")
    def updateRubber(self, painter=None):
        """
        TOWRITE

        :param `painter`: TOWRITE
        :type `painter`: `QPainter`_
        """
        rubberMode = self.objectRubberMode()  # int
        if rubberMode == OBJ_RUBBER_POLYGON:

            self.setObjectPos(self.objectRubberPoint("POLYGON_POINT_0"))

            ok = False  # bool
            numStr = self.objectRubberText("POLYGON_NUM_POINTS")  # QString
            if not numStr:
                return

            try:
                num = int(numStr)
            except ValueError:
                return

            appendStr = ''  # QString
            rubberPath = QPainterPath()
            rubberPath.moveTo(self.mapFromScene(self.objectRubberPoint("POLYGON_POINT_0")))
            for i in range(1, num): # for(int i = 1; i <= num; i++)

                appendStr = "POLYGON_POINT_" + '%s' % i  # QString().setNum(i)
                appendPoint = self.mapFromScene(self.objectRubberPoint(appendStr))  # QPointF
                rubberPath.lineTo(appendPoint)

            ## rubberPath.lineTo(0,0)
            self.updatePath(rubberPath)

            # Ensure the path isn't updated until the number of points is changed again.
            self.setObjectRubberText("POLYGON_NUM_POINTS", '')

        elif rubberMode == OBJ_RUBBER_POLYGON_INSCRIBE:

            self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER"))

            numSides = self.objectRubberPoint("POLYGON_NUM_SIDES").x()  # quint16

            inscribePoint = self.mapFromScene(self.objectRubberPoint("POLYGON_INSCRIBE_POINT"))  # QPointF
            inscribeLine = QLineF(QPointF(0, 0), inscribePoint)  # QLineF
            inscribeAngle = inscribeLine.angle()  # qreal
            inscribeInc = 360.0 / numSides        # qreal

            if painter:
                self.drawRubberLine(inscribeLine, painter, "VIEW_COLOR_CROSSHAIR")

            inscribePath = QPainterPath()
            # First Point.
            inscribePath.moveTo(inscribePoint)
            # Remaining Points.
            for i in range(1, numSides): # for(int i = 1; i < numSides; i++)

                inscribeLine.setAngle(inscribeAngle + inscribeInc * i)
                inscribePath.lineTo(inscribeLine.p2())

            self.updatePath(inscribePath)

        elif rubberMode == OBJ_RUBBER_POLYGON_CIRCUMSCRIBE:

            self.setObjectPos(self.objectRubberPoint("POLYGON_CENTER"))

            numSides = self.objectRubberPoint("POLYGON_NUM_SIDES").x()  # quint16

            circumscribePoint = self.mapFromScene(self.objectRubberPoint("POLYGON_CIRCUMSCRIBE_POINT"))  # QPointF
            circumscribeLine = QLineF(QPointF(0, 0), circumscribePoint)  # QLineF
            circumscribeAngle = circumscribeLine.angle()  # qreal
            circumscribeInc = 360.0 / numSides            # qreal

            if painter:
                self.drawRubberLine(circumscribeLine, painter, "VIEW_COLOR_CROSSHAIR")

            circumscribePath = QPainterPath()
            # First Point.
            prev = QLineF(circumscribeLine.p2(), QPointF(0, 0))
            prev = prev.normalVector()
            circumscribeLine.setAngle(circumscribeAngle + circumscribeInc)
            perp = QLineF(circumscribeLine.p2(), QPointF(0, 0))
            perp = perp.normalVector()
            # iPoint = QPointF()
            _, iPoint = perp.intersect(prev)
            circumscribePath.moveTo(iPoint)
            # Remaining Points.
            for i in range(2, numSides): # for(int i = 2; i <= numSides; i++)

                prev = perp
                circumscribeLine.setAngle(circumscribeAngle + circumscribeInc * i)
                perp = QLineF(circumscribeLine.p2(), QPointF(0, 0))
                perp = perp.normalVector()
                perp.intersect(prev, iPoint)
                circumscribePath.lineTo(iPoint)

            self.updatePath(circumscribePath)

        elif rubberMode == OBJ_RUBBER_GRIP:

            if painter:

                elemCount = self.normalPath.elementCount()  # int
                gripPoint = self.objectRubberPoint("GRIP_POINT")  # QPointF
                if self.gripIndex == -1:
                    self.gripIndex = self.findIndex(gripPoint)
                if self.gripIndex == -1:
                    return

                m = 0  # int
                n = 0  # int

                if not self.gripIndex:
                    m = elemCount - 1
                    n = 1
                elif self.gripIndex == elemCount - 1:
                    m = elemCount - 2
                    n = 0
                else:
                    m = self.gripIndex - 1
                    n = self.gripIndex + 1
                em = self.normalPath.elementAt(m)  # QPainterPath::Element
                en = self.normalPath.elementAt(n)  # QPainterPath::Element
                emPoint = QPointF(em.x, em.y)  # QPointF
                enPoint = QPointF(en.x, en.y)  # QPointF
                painter.drawLine(emPoint, self.mapFromScene(self.objectRubberPoint("")))
                painter.drawLine(enPoint, self.mapFromScene(self.objectRubberPoint("")))

                rubLine = QLineF(self.mapFromScene(gripPoint), self.mapFromScene(self.objectRubberPoint("")))
                self.drawRubberLine(rubLine, painter, "VIEW_COLOR_CROSSHAIR")