Пример #1
0
 def test_projection(self):
     P = QtCore.QPointF(2, 8)
     L = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(10, 0))
     D = projection(L, P)
     self.assertIsInstance(D, tuple)
     self.assertEqual(D[0], 8.0)
     self.assertEqual(D[1], QtCore.QPointF(2, 0))
Пример #2
0
 def test_projection(self):
     P = QtCore.QPointF(2, 8)
     L = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(10, 0))
     D = projection(L, P)
     self.assertIsInstance(D, tuple)
     self.assertEqual(D[0], 8.0)
     self.assertEqual(D[1], QtCore.QPointF(2, 0))
Пример #3
0
def test_projection():
    P = QtCore.QPointF(2, 8)
    L = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(10, 0))
    D = projection(L, P)
    assert isinstance(D, tuple)
    assert D[0] == 8.0
    assert D[1] == QtCore.QPointF(2, 0)
Пример #4
0
    def breakPointAdd(self, mousePos):
        """
        Create a new breakpoint from the given mouse position returning its index.
        :type mousePos: QtCore.QPointF
        :rtype: int
        """
        index = 0
        point = None
        between = None
        shortest = 999

        source = self.source.anchor(self)
        target = self.target.anchor(self)
        points = [source] + self.breakpoints + [target]

        # Estimate between which breakpoints the new one is being added.
        for subpath in (QtCore.QLineF(points[i], points[i + 1])
                        for i in range(len(points) - 1)):
            dis, pos = projection(subpath, mousePos)
            if dis < shortest:
                point = pos
                shortest = dis
                between = subpath.p1(), subpath.p2()

        # If there is no breakpoint the new one will be appended.
        for i, breakpoint in enumerate(self.breakpoints):

            if breakpoint == between[1]:
                # In case the new breakpoint is being added between
                # the source node of this edge and the last breakpoint.
                index = i
                break

            if breakpoint == between[0]:
                # In case the new breakpoint is being added between
                # the last breakpoint and the target node of this edge.
                index = i + 1
                break

        self.session.undostack.push(
            CommandEdgeBreakpointAdd(self.diagram, self, index, point))
        return index
Пример #5
0
    def breakPointAdd(self, mousePos):
        """
        Create a new breakpoint from the given mouse position returning its index.
        :type mousePos: QtCore.QPointF
        :rtype: int
        """
        index = 0
        point = None
        between = None
        shortest = 999

        source = self.source.anchor(self)
        target = self.target.anchor(self)
        points = [source] + self.breakpoints + [target]

        # Estimate between which breakpoints the new one is being added.
        for subpath in (QtCore.QLineF(points[i], points[i + 1]) for i in range(len(points) - 1)):
            dis, pos = projection(subpath, mousePos)
            if dis < shortest:
                point = pos
                shortest = dis
                between = subpath.p1(), subpath.p2()

        # If there is no breakpoint the new one will be appended.
        for i, breakpoint in enumerate(self.breakpoints):

            if breakpoint == between[1]:
                # In case the new breakpoint is being added between
                # the source node of this edge and the last breakpoint.
                index = i
                break

            if breakpoint == between[0]:
                # In case the new breakpoint is being added between
                # the last breakpoint and the target node of this edge.
                index = i + 1
                break

        self.session.undostack.push(CommandEdgeBreakpointAdd(self.diagram, self, index, point))
        return index