Example #1
0
def find_axis(top_line, bot_line):
    type, origin = top_line.intersect(bot_line)
    # Force angles into right half-plane regardless of click order
    top_angle = (top_line.angle() + 90) % 180 - 90
    bot_angle = (bot_line.angle() + 90) % 180 - 90
    xaxis = QLineF(origin, QPointF(0, 0))  # Need to make non-zero vector
    xaxis.setLength(100)
    xaxis.setAngle((top_angle + bot_angle) / 2)
    yaxis = QLineF(xaxis)
    yaxis.setAngle(xaxis.angle() + 90)
    return origin, xaxis, yaxis
Example #2
0
def find_axis(top_line, bot_line):
    type, origin = top_line.intersect(bot_line)
    # Force angles into right half-plane regardless of click order
    top_angle = (top_line.angle() + 90)%180 - 90
    bot_angle = (bot_line.angle() + 90)%180 - 90
    xaxis = QLineF(origin, QPointF(0, 0)) # Need to make non-zero vector
    xaxis.setLength(100)
    xaxis.setAngle((top_angle + bot_angle)/2)
    yaxis = QLineF(xaxis)
    yaxis.setAngle(xaxis.angle() + 90)
    return origin, xaxis, yaxis
    def __init__(self, x, y, scaleFactor, text, obj, v, parent):
        """
        Default class constructor.

        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `scaleFactor`: TOWRITE
        :type `scaleFactor`: qreal
        :param `text`: TOWRITE
        :type `text`: QString
        :param `obj`: TOWRITE
        :type `obj`: `BaseObject`
        :param `v`: TOWRITE
        :type `v`: `View`
        :param `parent`: TOWRITE
        :type `parent`: `QUndoCommand`_
        """
        super(UndoableScaleCommand, self).__init__(parent)

        self.gview = v
        self.object = obj
        self.setText(text)

        # Prevent division by zero and other wacky behavior
        if scaleFactor <= 0.0:
            self.dx = 0.0
            self.dy = 0.0
            self.factor = 1.0
            QMessageBox.critical(
                0, QObject.tr("ScaleFactor Error"),
                QObject.
                tr("Hi there. If you are not a developer, report this as a bug. "
                   "If you are a developer, your code needs examined, and possibly your head too."
                   ))
        else:
            # Calculate the offset
            oldX = self.object.x()  # qreal
            oldY = self.object.y()  # qreal
            scaleLine = QLineF(x, y, oldX, oldY)
            scaleLine.setLength(scaleLine.length() * scaleFactor)
            newX = scaleLine.x2()  # qreal
            newY = scaleLine.y2()  # qreal

            self.dx = newX - oldX
            self.dy = newY - oldY
            self.factor = scaleFactor
    def __init__(self, x, y, scaleFactor, text, obj, v, parent=None):
        """
        Default class constructor.

        :param `x`: TOWRITE
        :type `x`: qreal
        :param `y`: TOWRITE
        :type `y`: qreal
        :param `scaleFactor`: TOWRITE
        :type `scaleFactor`: qreal
        :param `text`: TOWRITE
        :type `text`: QString
        :param `obj`: TOWRITE
        :type `obj`: `BaseObject`
        :param `v`: TOWRITE
        :type `v`: `View`
        :param `parent`: TOWRITE
        :type `parent`: `QUndoCommand`_
        """
        super(UndoableScaleCommand, self).__init__(parent)

        self.gview = v
        self.object = obj
        self.setText(text)

        # Prevent division by zero and other wacky behavior
        if scaleFactor <= 0.0:
            self.dx = 0.0
            self.dy = 0.0
            self.factor = 1.0
            QMessageBox.critical(0, QObject.tr("ScaleFactor Error"),
                                 QObject.tr("Hi there. If you are not a developer, report this as a bug. "
                                 "If you are a developer, your code needs examined, and possibly your head too."))
        else:
            # Calculate the offset
            oldX = self.object.x()  # qreal
            oldY = self.object.y()  # qreal
            scaleLine = QLineF(x, y, oldX, oldY)
            scaleLine.setLength(scaleLine.length() * scaleFactor)
            newX = scaleLine.x2()  # qreal
            newY = scaleLine.y2()  # qreal

            self.dx = newX - oldX
            self.dy = newY - oldY
            self.factor = scaleFactor
    def setObjectRadius(self, radius):
        """
        TOWRITE

        :param `radius`: TOWRITE
        :type `radius`: qreal
        """
        # qreal rad;
        if radius <= 0:
            rad = 0.0000001
        else:
            rad = radius

        center = self.scenePos()  # QPointF
        startLine = QLineF(center, self.objectStartPoint())  # QLineF
        midLine   = QLineF(center, self.objectMidPoint())    # QLineF
        endLine   = QLineF(center, self.objectEndPoint())    # QLineF
        startLine.setLength(rad)
        midLine.setLength(rad)
        endLine.setLength(rad)
        arcStartPoint = startLine.p2()
        arcMidPoint = midLine.p2()
        arcEndPoint = endLine.p2()

        self.calculateArcData(arcStartPoint.x(), arcStartPoint.y(), arcMidPoint.x(), arcMidPoint.y(), arcEndPoint.x(), arcEndPoint.y())
Example #6
0
    def renewplot(self):
        """ Do not layout anything, but redraw all lines"""
        scene = self.graphicsView.scene()
        self.roots = set()
        # scene.changed.disconnect(self.renewplot)
        for i in self.qLines:
            scene.removeItem(i)

        self.qLines = []

        for edge in self.gv.edges_iter():

            qnode1 = self.nodesToQNodes[edge[0]]
            qnode2 = self.nodesToQNodes[edge[1]]
            line = QLineF(qnode1.pos(), qnode2.pos())
            line.setLength(line.length() - 40)
            end = line.p2()

            arrowLine1 = QLineF()
            arrowLine1.setP1(end)
            arrowLine1.setLength(10)
            arrowLine1.setAngle(line.angle() + 210)

            arrowLine2 = QLineF()
            arrowLine2.setP1(end)
            arrowLine2.setLength(10)
            arrowLine2.setAngle(line.angle() - 210)
            if edge.attr['color'] not in self.qpens:
                self.qpens[edge.attr['color']] = QPen(
                    QColor(edge.attr['color']))

            item = scene.addLine(line, self.qpens[edge.attr['color']])
            item.setZValue(-1)
            item.setFlag(QGraphicsItem.ItemIsSelectable, True)
            self.qLines.append(item)
            item = scene.addLine(arrowLine1, self.qpens[edge.attr['color']])
            self.qLines.append(item)
            item = scene.addLine(arrowLine2, self.qpens[edge.attr['color']])
            self.qLines.append(item)

            self.roots.add(edge[0])