Ejemplo n.º 1
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")
Ejemplo n.º 2
0
    def updateRubber(self, painter=None):
        """
        TOWRITE

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

            sceneLinePoint1 = self.objectRubberPoint("ELLIPSE_LINE_POINT1")  # QPointF
            sceneLinePoint2 = self.objectRubberPoint("ELLIPSE_LINE_POINT2")  # QPointF
            itemLinePoint1  = self.mapFromScene(sceneLinePoint1)             # QPointF
            itemLinePoint2  = self.mapFromScene(sceneLinePoint2)             # QPointF
            itemLine = QLineF(itemLinePoint1, itemLinePoint2)
            if painter:
                self.drawRubberLine(itemLine, painter, "VIEW_COLOR_CROSSHAIR")
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_ELLIPSE_MAJORDIAMETER_MINORRADIUS:

            sceneAxis1Point1 = self.objectRubberPoint("ELLIPSE_AXIS1_POINT1")  # QPointF
            sceneAxis1Point2 = self.objectRubberPoint("ELLIPSE_AXIS1_POINT2")  # QPointF
            sceneCenterPoint = self.objectRubberPoint("ELLIPSE_CENTER")        # QPointF
            sceneAxis2Point2 = self.objectRubberPoint("ELLIPSE_AXIS2_POINT2")  # QPointF
            ellipseWidth = self.objectRubberPoint("ELLIPSE_WIDTH").x()  # qreal
            ellipseRot = self.objectRubberPoint("ELLIPSE_ROT").x()      # qreal

            # TODO: incorporate perpendicularDistance() into libcgeometry
            px = sceneAxis2Point2.x()  # qreal
            py = sceneAxis2Point2.y()  # qreal
            x1 = sceneAxis1Point1.x()  # qreal
            y1 = sceneAxis1Point1.y()  # qreal
            line = QLineF(sceneAxis1Point1, sceneAxis1Point2)
            norm = line.normalVector()  # QLineF
            dx = px - x1  # qreal
            dy = py - y1  # qreal
            norm.translate(dx, dy)
            # iPoint = QPointF()
            _, iPoint = norm.intersect(line)
            ellipseHeight = QLineF(px, py, iPoint.x(), iPoint.y()).length() * 2.0  # qreal

            self.setObjectCenter(sceneCenterPoint)
            self.setObjectSize(ellipseWidth, ellipseHeight)
            self.setRotation(-ellipseRot)

            itemCenterPoint = self.mapFromScene(sceneCenterPoint)  # QPointF
            itemAxis2Point2 = self.mapFromScene(sceneAxis2Point2)  # QPointF
            itemLine = QLineF(itemCenterPoint, itemAxis2Point2)
            if painter:
                self.drawRubberLine(itemLine, painter, "VIEW_COLOR_CROSSHAIR")
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_ELLIPSE_MAJORRADIUS_MINORRADIUS:

            sceneAxis1Point2 = self.objectRubberPoint("ELLIPSE_AXIS1_POINT2")  # QPointF
            sceneCenterPoint = self.objectRubberPoint("ELLIPSE_CENTER")        # QPointF
            sceneAxis2Point2 = self.objectRubberPoint("ELLIPSE_AXIS2_POINT2")  # QPointF
            ellipseWidth = self.objectRubberPoint("ELLIPSE_WIDTH").x()  # qreal
            ellipseRot = self.objectRubberPoint("ELLIPSE_ROT").x()      # qreal

            # TODO: incorporate perpendicularDistance() into libcgeometry
            px = sceneAxis2Point2.x()  # qreal
            py = sceneAxis2Point2.y()  # qreal
            x1 = sceneCenterPoint.x()  # qreal
            y1 = sceneCenterPoint.y()  # qreal
            line = QLineF(sceneCenterPoint, sceneAxis1Point2)
            norm = line.normalVector()  # QLineF
            dx = px - x1  # qreal
            dy = py - y1  # qreal
            norm.translate(dx, dy)
            # iPoint = QPointF()
            _, iPoint = norm.intersect(line)
            ellipseHeight = QLineF(px, py, iPoint.x(), iPoint.y()).length() * 2.0  # qreal

            self.setObjectCenter(sceneCenterPoint)
            self.setObjectSize(ellipseWidth, ellipseHeight)
            self.setRotation(-ellipseRot)

            itemCenterPoint = self.mapFromScene(sceneCenterPoint)  # QPointF
            itemAxis2Point2 = self.mapFromScene(sceneAxis2Point2)  # QPointF
            itemLine = QLineF(itemCenterPoint, itemAxis2Point2)
            if painter:
                self.drawRubberLine(itemLine, painter, "VIEW_COLOR_CROSSHAIR")
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_GRIP:

            pass # TODO: updateRubber() gripping for EllipseObject
Ejemplo n.º 3
0
    def updateRubber(self, painter):
        """
        TOWRITE

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

            sceneLinePoint1 = self.objectRubberPoint(
                "ELLIPSE_LINE_POINT1")  # QPointF
            sceneLinePoint2 = self.objectRubberPoint(
                "ELLIPSE_LINE_POINT2")  # QPointF
            itemLinePoint1 = self.mapFromScene(sceneLinePoint1)  # QPointF
            itemLinePoint2 = self.mapFromScene(sceneLinePoint2)  # QPointF
            itemLine = QLineF(itemLinePoint1, itemLinePoint2)
            if painter:
                self.drawRubberLine(itemLine, painter, VIEW_COLOR_CROSSHAIR)
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_ELLIPSE_MAJORDIAMETER_MINORRADIUS:

            sceneAxis1Point1 = self.objectRubberPoint(
                "ELLIPSE_AXIS1_POINT1")  # QPointF
            sceneAxis1Point2 = self.objectRubberPoint(
                "ELLIPSE_AXIS1_POINT2")  # QPointF
            sceneCenterPoint = self.objectRubberPoint(
                "ELLIPSE_CENTER")  # QPointF
            sceneAxis2Point2 = self.objectRubberPoint(
                "ELLIPSE_AXIS2_POINT2")  # QPointF
            ellipseWidth = self.objectRubberPoint("ELLIPSE_WIDTH").x()  # qreal
            ellipseRot = self.objectRubberPoint("ELLIPSE_ROT").x()  # qreal

            # TODO: incorporate perpendicularDistance() into libcgeometry
            px = sceneAxis2Point2.x()  # qreal
            py = sceneAxis2Point2.y()  # qreal
            x1 = sceneAxis1Point1.x()  # qreal
            y1 = sceneAxis1Point1.y()  # qreal
            line = QLineF(sceneAxis1Point1, sceneAxis1Point2)
            norm = line.normalVector()  # QLineF
            dx = px - x1  # qreal
            dy = py - y1  # qreal
            norm.translate(dx, dy)
            iPoint = QPointF()
            norm.intersect(line, iPoint)
            ellipseHeight = QLineF(px, py, iPoint.x(),
                                   iPoint.y()).length() * 2.0  # qreal

            self.setObjectCenter(sceneCenterPoint)
            self.setObjectSize(ellipseWidth, ellipseHeight)
            self.setRotation(-ellipseRot)

            itemCenterPoint = self.mapFromScene(sceneCenterPoint)  # QPointF
            itemAxis2Point2 = self.mapFromScene(sceneAxis2Point2)  # QPointF
            itemLine = QLineF(itemCenterPoint, itemAxis2Point2)
            if painter:
                self.drawRubberLine(itemLine, painter, VIEW_COLOR_CROSSHAIR)
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_ELLIPSE_MAJORRADIUS_MINORRADIUS:

            sceneAxis1Point2 = self.objectRubberPoint(
                "ELLIPSE_AXIS1_POINT2")  # QPointF
            sceneCenterPoint = self.objectRubberPoint(
                "ELLIPSE_CENTER")  # QPointF
            sceneAxis2Point2 = self.objectRubberPoint(
                "ELLIPSE_AXIS2_POINT2")  # QPointF
            ellipseWidth = self.objectRubberPoint("ELLIPSE_WIDTH").x()  # qreal
            ellipseRot = self.objectRubberPoint("ELLIPSE_ROT").x()  # qreal

            # TODO: incorporate perpendicularDistance() into libcgeometry
            px = sceneAxis2Point2.x()  # qreal
            py = sceneAxis2Point2.y()  # qreal
            x1 = sceneCenterPoint.x()  # qreal
            y1 = sceneCenterPoint.y()  # qreal
            line = QLineF(sceneCenterPoint, sceneAxis1Point2)
            norm = line.normalVector()  # QLineF
            dx = px - x1  # qreal
            dy = py - y1  # qreal
            norm.translate(dx, dy)
            iPoint = QPointF()
            norm.intersect(line, iPoint)
            ellipseHeight = QLineF(px, py, iPoint.x(),
                                   iPoint.y()).length() * 2.0  # qreal

            self.setObjectCenter(sceneCenterPoint)
            self.setObjectSize(ellipseWidth, ellipseHeight)
            self.setRotation(-ellipseRot)

            itemCenterPoint = self.mapFromScene(sceneCenterPoint)  # QPointF
            itemAxis2Point2 = self.mapFromScene(sceneAxis2Point2)  # QPointF
            itemLine = QLineF(itemCenterPoint, itemAxis2Point2)
            if painter:
                self.drawRubberLine(itemLine, painter, VIEW_COLOR_CROSSHAIR)
            self.updatePath()

        elif rubberMode == OBJ_RUBBER_GRIP:

            pass  # TODO: updateRubber() gripping for EllipseObject
Ejemplo n.º 4
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")