Exemplo n.º 1
0
    def __init__(self, *args, **kwargs):

        self.first_point = FirstPoint()
        self.second_point = SecondPoint()
        self.control = Control()

        self.p1 = QPoint()
        self.p2 = QPoint()

        Figure.__init__(self, self.first_point)
        if 'x1' in kwargs and 'y1' in kwargs:
            self.p1 = QPoint(kwargs['x1'], kwargs['y1'])
        if 'x2' in kwargs and 'y2' in kwargs:
            self.p2 = QPoint(kwargs['x2'], kwargs['y2'])
        if 'p1' in kwargs:
            self.p1 = kwargs['p1']
        if 'p2' in kwargs:
            self.p2 = kwargs['p2']
        if len(args) == 2:
            self.p1 = args[0]
            self.p2 = args[1]
        if len(args) == 4:
            self.p1 = QPoint(args[0], args[1])
            self.p2 = QPoint(args[2], args[3])

        if 'figure' in kwargs:
            self.p1 = QPoint(kwargs['figure']['x1'], kwargs['figure']['y1'])
            self.p2 = QPoint(kwargs['figure']['x2'], kwargs['figure']['y2'])
            self.state = self.control
Exemplo n.º 2
0
    def draw(self, painter, scale):

        painter.save()
        painter.setPen(QPen(QBrush(QColor(232, 109, 21) if self.state is self.add_point else
                                   QColor(21, 144, 232)),
                            self.lineWidth(scale),
                            Qt.SolidLine))
        painter.drawPolygon(QPolygon(self.polygon))

        for i, poly in enumerate(self.convex_polygons):
            if poly:
                painter.setPen(QPen(QBrush(Figure.COLORS[i % len(Figure.COLORS)]),
                                    self.lineWidth(scale),
                                    Qt.SolidLine))
                color = Figure.COLORS[i % len(Figure.COLORS)]
                color.setAlpha(150)
                painter.setBrush(QBrush(QColor(color)))
                painter.drawPolygon(QPolygon(poly))

        for point in self.polygon:
            self.drawControlPoint(painter, point,
                                  QColor(31, 174, 222) if point is self.polygon[0] else
                                  QColor(222, 79, 31) if point is self.polygon[-1] else
                                  QColor(78, 222, 31), scale)

        Figure.draw(self, painter, scale)
        painter.restore()
Exemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        self.first_point = FirstPoint()
        self.second_point = SecondPoint()
        self.control = Control()

        Figure.__init__(self, self.first_point)

        self.center = QPoint()
        self.ctrl = QPoint()

        if 'center' in kwargs:
            self.center = kwargs['center']
        if 'ctrl' in kwargs:
            self.ctrl = kwargs['ctrl']
        if 'figure' in kwargs:
            self.center = QPoint(kwargs['figure']['center']['x'],
                                 kwargs['figure']['center']['y'])
            self.ctrl = QPoint(kwargs['figure']['ctrl']['x'],
                               kwargs['figure']['ctrl']['y'])
            self.state = self.control
        if len(args) == 2:
            self.center = args[0]
            self.ctrl = args[1]
        if len(args) == 4:
            self.center = QPoint(args[0], args[1])
            self.ctrl = QPoint(args[2], args[3])
Exemplo n.º 4
0
    def __init__(self, *args, **kwargs):

        self.first_point = FirstPoint()
        self.second_point = SecondPoint()
        self.control = Control()

        self.p1 = QPoint()
        self.p2 = QPoint()

        Figure.__init__(self, self.first_point)
        if 'x1' in kwargs and 'y1' in kwargs:
            self.p1 = QPoint(kwargs['x1'], kwargs['y1'])
        if 'x2' in kwargs and 'y2' in kwargs:
            self.p2 = QPoint(kwargs['x2'], kwargs['y2'])
        if 'p1' in kwargs:
            self.p1 = kwargs['p1']
        if 'p2' in kwargs:
            self.p2 = kwargs['p2']
        if len(args) == 2:
            self.p1 = args[0]
            self.p2 = args[1]
        if len(args) == 4:
            self.p1 = QPoint(args[0], args[1])
            self.p2 = QPoint(args[2], args[3])

        if 'figure' in kwargs:
            self.p1 = QPoint(kwargs['figure']['x1'], kwargs['figure']['y1'])
            self.p2 = QPoint(kwargs['figure']['x2'], kwargs['figure']['y2'])
            self.state = self.control
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        self.first_point = FirstPoint()
        self.second_point = SecondPoint()
        self.control = Control()

        Figure.__init__(self, self.first_point)

        self.center = QPoint()
        self.ctrl = QPoint()

        if 'center' in kwargs:
            self.center = kwargs['center']
        if 'ctrl' in kwargs:
            self.ctrl = kwargs['ctrl']
        if 'figure' in kwargs:
            self.center = QPoint(kwargs['figure']['center']['x'],
                                 kwargs['figure']['center']['y'])
            self.ctrl = QPoint(kwargs['figure']['ctrl']['x'],
                               kwargs['figure']['ctrl']['y'])
            self.state = self.control
        if len(args) == 2:
            self.center = args[0]
            self.ctrl = args[1]
        if len(args) == 4:
            self.center = QPoint(args[0], args[1])
            self.ctrl = QPoint(args[2], args[3])
Exemplo n.º 6
0
    def draw(self, painter, scale):
        painter.save()
        if not self.p1.isNull() and not self.p2.isNull():
            painter.setPen(QPen(QBrush(QColor(232, 109, 21) if self.state is not self.control else
                                       QColor(21, 144, 232)),
                                self.lineWidth(scale),
                                Qt.SolidLine))
            painter.setBrush(QBrush(QColor(21, 144, 232, 150)))
            painter.drawRect(QRect(self.p1, self.p2))

            self.drawControlPoint(painter, self.p1, QColor(31, 174, 222), scale)
            self.drawControlPoint(painter, self.p2, QColor(222, 79, 31), scale)

        Figure.draw(self, painter, scale)
        painter.restore()
Exemplo n.º 7
0
    def mouseDown(self, machine, *args, **kwargs):
        point = kwargs['point']
        if Figure.pointIsControl(machine.p1, point, kwargs['scale']):
            self.point = machine.p1
        if Figure.pointIsControl(machine.p2, point, kwargs['scale']):
            self.point = machine.p2

        if self.point:
            if 'event' in kwargs and kwargs['event'].button() == Qt.RightButton:
                machine.state = machine.delete
            else:
                self.point.setX(point.x())
                self.point.setY(point.y())
            return True
        else:
            return False
Exemplo n.º 8
0
    def draw(self, painter, scale):
        painter.save()
        if not self.center.isNull() and not self.ctrl.isNull():
            radius = distance(self.center, self.ctrl)
            painter.setPen(QPen(QBrush(QColor(232, 109, 21) if self.state is not self.control else
                                       QColor(21, 144, 232)),
                                self.lineWidth(scale),
                                Qt.SolidLine))
            painter.setBrush(QBrush(QColor(21, 144, 232, 150)))
            painter.drawEllipse(self.center, radius, radius)

            self.drawControlPoint(painter, self.center, QColor(31, 174, 222), scale)
            self.drawControlPoint(painter, self.ctrl, QColor(222, 79, 31), scale)

        Figure.draw(self, painter, scale)
        painter.restore()
Exemplo n.º 9
0
    def mouseDown(self, machine, *args, **kwargs):
        point = kwargs['point']
        if Figure.pointIsControl(machine.p1, point, kwargs['scale']):
            self.point = machine.p1
        if Figure.pointIsControl(machine.p2, point, kwargs['scale']):
            self.point = machine.p2

        if self.point:
            if 'event' in kwargs and kwargs['event'].button(
            ) == Qt.RightButton:
                machine.state = machine.delete
            else:
                self.point.setX(point.x())
                self.point.setY(point.y())
            return True
        else:
            return False
Exemplo n.º 10
0
    def draw(self, painter, scale):
        painter.save()
        if not self.p1.isNull() and not self.p2.isNull():
            painter.setPen(
                QPen(
                    QBrush(
                        QColor(232, 109, 21) if self.state is not self.
                        control else QColor(21, 144, 232)),
                    self.lineWidth(scale), Qt.SolidLine))
            painter.setBrush(QBrush(QColor(21, 144, 232, 150)))
            painter.drawRect(QRect(self.p1, self.p2))

            self.drawControlPoint(painter, self.p1, QColor(31, 174, 222),
                                  scale)
            self.drawControlPoint(painter, self.p2, QColor(222, 79, 31), scale)

        Figure.draw(self, painter, scale)
        painter.restore()
Exemplo n.º 11
0
    def __init__(self, *args, **kwargs):

        self.add_point = AddPoint()
        self.control = Control()

        Figure.__init__(self, self.add_point)

        self.decomposer = BayazitDecomposer()

        self.polygon = []
        self.convex_polygons = []

        if 'figure' in kwargs:
            self.polygon = [dict2qpoint(p) for p in kwargs['figure']['editor']]
            self.decompose()
            self.state = self.control

        if len(args) > 0:
            self.polygon = args
Exemplo n.º 12
0
    def mouseDown(self, machine, *args, **kwargs):
        point = kwargs.get('point')
        # Если нажатие в какой нибудь точке кроме последней то просто ничего не делаем и выходим
        for p in machine.polygon:
            if Figure.pointIsControl(p, point, kwargs['scale']) and p is not machine.polygon[-1]:
                return True  # новую фигуру добавлять не надо

        # Если у нас больше 1 точки и мы тыкаем в последнюю тогда ...
        if len(machine.polygon) > 1 and Figure.pointIsControl(machine.polygon[-1], point, kwargs['scale']):
            # ... делаем декомпозицию ломаной и ...
            machine.decompose()

            # ... и переходим в состояние управление ломаной
            machine.state = machine.control
            return True

        # в любом оставшемся случае добавляем точку в ломаную
        machine.polygon.append(point)
        return True  # новую фигуру добавлять не надо
Exemplo n.º 13
0
    def draw(self, painter, scale):
        painter.save()
        if not self.center.isNull() and not self.ctrl.isNull():
            radius = distance(self.center, self.ctrl)
            painter.setPen(
                QPen(
                    QBrush(
                        QColor(232, 109, 21) if self.state is not self.
                        control else QColor(21, 144, 232)),
                    self.lineWidth(scale), Qt.SolidLine))
            painter.setBrush(QBrush(QColor(21, 144, 232, 150)))
            painter.drawEllipse(self.center, radius, radius)

            self.drawControlPoint(painter, self.center, QColor(31, 174, 222),
                                  scale)
            self.drawControlPoint(painter, self.ctrl, QColor(222, 79, 31),
                                  scale)

        Figure.draw(self, painter, scale)
        painter.restore()
Exemplo n.º 14
0
    def mouseDown(self, machine, *args, **kwargs):
        point = kwargs['point']
        scale = kwargs['scale']
        if Figure.pointIsControl(machine.center, point, scale):
            self.point = machine.center
        if Figure.pointIsControl(machine.ctrl, point, scale):
            self.point = machine.ctrl

        if self.point:
            if 'event' in kwargs and kwargs['event'].button() is Qt.RightButton:
                machine.state = machine.delete
            elif self.point == machine.center:
                delta = point - machine.center
                machine.center += delta
                machine.ctrl += delta
            elif self.point == machine.ctrl:
                machine.ctrl.setX(point.x())
                machine.ctrl.setY(point.y())
            return True
        else:
            return False
Exemplo n.º 15
0
    def mouseDown(self, machine, *args, **kwargs):
        point = kwargs['point']
        scale = kwargs['scale']
        if Figure.pointIsControl(machine.center, point, scale):
            self.point = machine.center
        if Figure.pointIsControl(machine.ctrl, point, scale):
            self.point = machine.ctrl

        if self.point:
            if 'event' in kwargs and kwargs['event'].button(
            ) is Qt.RightButton:
                machine.state = machine.delete
            elif self.point == machine.center:
                delta = point - machine.center
                machine.center += delta
                machine.ctrl += delta
            elif self.point == machine.ctrl:
                machine.ctrl.setX(point.x())
                machine.ctrl.setY(point.y())
            return True
        else:
            return False
Exemplo n.º 16
0
 def mouseDown(self, machine, *args, **kwargs):
     for p in machine.polygon:
         if Figure.pointIsControl(p, kwargs['point'], kwargs['scale']):
             if 'event' in kwargs and kwargs['event'].button() is Qt.RightButton:
                 del machine.polygon[machine.polygon.index(p)]
                 if len(machine.polygon) < 3:
                     machine.state = machine.delete
                 else:
                     machine.decompose()
             else:
                 self.control1 = p
             return True
     return False
Exemplo n.º 17
0
 def mouseUp(self, machine, *args, **kwargs):
     point = kwargs['point']
     machine.ctrl = point
     if not Figure.pointIsControl(machine.center, point, kwargs['scale']):
         machine.state = machine.control
Exemplo n.º 18
0
 def mouseUp(self, machine, *args, **kwargs):
     machine.p2 = kwargs['point']
     if not Figure.pointIsControl(machine.p1, kwargs['point'], kwargs['scale']):
         machine.state = machine.control
Exemplo n.º 19
0
 def mouseUp(self, machine, *args, **kwargs):
     point = kwargs['point']
     machine.ctrl = point
     if not Figure.pointIsControl(machine.center, point, kwargs['scale']):
         machine.state = machine.control
Exemplo n.º 20
0
 def mouseUp(self, machine, *args, **kwargs):
     machine.p2 = kwargs['point']
     if not Figure.pointIsControl(machine.p1, kwargs['point'],
                                  kwargs['scale']):
         machine.state = machine.control