Example #1
0
    def keyPressEvent(self, event):
        """Handles deleting and rotating the selected
        item when dedicated keys are pressed.

        Args:
            event (QKeyEvent): Key event
        """
        if event.key() == Qt.Key_Delete and self.isSelected():
            self._project_item._project.remove_item(self.name())
            event.accept()
        elif event.key() == Qt.Key_R and self.isSelected():
            # TODO:
            # 1. Change name item text direction when rotating
            # 2. Save rotation into project file
            rect = self.mapToScene(self.boundingRect()).boundingRect()
            center = rect.center()
            t = QTransform()
            t.translate(center.x(), center.y())
            t.rotate(90)
            t.translate(-center.x(), -center.y())
            self.setPos(t.map(self.pos()))
            self.setRotation(self.rotation() + 90)
            links = set(lnk for conn in self.connectors.values()
                        for lnk in conn.links)
            for link in links:
                link.update_geometry()
            event.accept()
        else:
            super().keyPressEvent(event)
Example #2
0
 def mvp(self):
     view_center = self.rect().center()
     mvp = QTransform()
     mvp.translate(view_center.x(), view_center.y())
     mvp.scale(self.camera.zoom, self.camera.zoom)
     mvp.translate(self.camera.pos.x(), self.camera.pos.y())
     return mvp
Example #3
0
 def mouseMoveEvent(self, event):
     """
     Mouse move event handler
     @param event:
     @type event:
     """
     modifiers = QApplication.keyboardModifiers()
     # mouse coordinates, relative to parent widget
     pos = self.mapToParent(event.pos())
     img = self.tool.layer.parentImage
     r = self.tool.resizingCoeff
     self.tool.targetQuad_old = self.tool.getTargetQuad(
     )  # TODO added 15/05/18 validate
     self.posRelImg = (pos - QPoint(img.xOffset, img.yOffset)) / r
     if modifiers == Qt.ControlModifier | Qt.AltModifier:
         if self.tool.isModified():
             dlgWarn("A transformation is in progress", "Reset first")
             return
         # update the new starting  position
         self.posRelImg_ori = self.posRelImg  # (pos - QPoint(img.xOffset, img.yOffset)) / r
         self.posRelImg_frozen = self.posRelImg
         self.tool.moveRotatingTool()
         self.tool.parent().repaint()
         return
     curimg = self.tool.layer.getCurrentImage()
     w, h = curimg.width(), curimg.height()
     s = w / self.tool.img.width()
     form = self.tool.getForm()
     if form.options['Free']:
         pass
     elif form.options['Rotation']:
         center = self.tool.getTargetQuad().boundingRect().center()
         v = QPointF(self.posRelImg.x() - center.x(),
                     self.posRelImg.y() - center.y())
         v0 = QPointF(self.posRelImg_frozen.x() - center.x(),
                      self.posRelImg_frozen.y() - center.y())
         theta = (np.arctan2(v.y(), v.x()) -
                  np.arctan2(v0.y(), v0.x())) * 180.0 / np.pi
         T = QTransform()  # self.tool.geoTrans_ori)
         T.translate(center.x(), center.y()).rotate(theta).translate(
             -center.x(), -center.y())
         q = T.map(self.tool.getFrozenQuad())
         for i, role in enumerate(
             ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']):
             self.tool.btnDict[role].posRelImg = q.at(i)
     elif form.options['Translation']:
         # translation vector (coordinates are relative to the full size image)
         p = QPointF(self.posRelImg) - QPointF(self.posRelImg_frozen)
         T = QTransform()
         T.translate(p.x(), p.y())
         q = T.map(self.tool.getFrozenQuad())
         for i, role in enumerate(
             ['topLeft', 'topRight', 'bottomRight', 'bottomLeft']):
             self.tool.btnDict[role].posRelImg = q.at(i)
     self.tool.moveRotatingTool()
     self.tool.modified = True
     self.tool.layer.applyToStack()
     self.parent().repaint()
Example #4
0
    def updateTransform(self):
        if self.x > 0:
            self.x = 0

        self.resetTransform()
        m = QTransform()
        m.translate(self.x, self.y)
        m.scale(self.scale_factor, 1.0)
        self.setTransform(m)
Example #5
0
    def rotateCW(self):
        transform = QTransform()
        transform.translate(self.image.width() / 2, self.image.height() / 2)
        transform.rotate(90)

        self.image = self.image.transformed(transform)
        self.image.save(self.path)
        self.thumbnail = self.image.scaled(QSize(110, 110),
                                           aspectMode=Qt.KeepAspectRatio,
                                           mode=Qt.SmoothTransformation)
Example #6
0
def render_image(painter,
                 image,
                 source_centre,
                 source_window,
                 canvas_center,
                 canvas_size,
                 rotation=0.0):
    # type: (QPainter, Image, Point, Size, Point, Size, float) -> None
    """Renders an image or portion of it on the canvas with optional rotation and scaling.

    :param painter: the painter to draw with (which knows the canvas to draw on)
    :param image: the :class:`~simplequi._image.Image` to render
    :param source_centre: the center point of the portion of the original image to render
    :param source_window: the width and height of the portion of the original image to render
    :param canvas_center: the location to render the image on the canvas
    :param canvas_size: the size to render the image on the canvas
    :param rotation: amount in radians to rotate the image by, with 0.0 at the 3 o'clock position, increasing clockwise
    """
    pixmap = get_pixmap(image, source_centre, source_window, canvas_size)
    if pixmap is None:
        # Image not loaded yet, shouldn't get here but just in case...
        return

    if rotation != 0.0:
        transform = QTransform()
        transform = transform.translate(*canvas_center)
        transform = transform.rotateRadians(rotation)
        painter.save()
        painter.setTransform(transform)
        canvas_center = 0, 0
    x, y = canvas_center
    x -= canvas_size[0] / 2.
    y -= canvas_size[1] / 2.
    painter.drawPixmap(x, y, pixmap)
    if rotation != 0.0:
        painter.restore()
Example #7
0
    def getObjectInteraction(self, persons, objects, interaction, d):

        # print("getObjectInteration")
        plt.close('all')

        polylines_object = []
        polylines_interacting = []

        for o in objects:
            obj = Object(o.x / 1000., o.z / 1000., o.angle, o.space)
            # print("OBJETO")
            ##para dibujarlo
            if d:
                plt.figure('ObjectSpace')
                rect = plt.Rectangle((obj.x - 0.25, obj.y - 0.25),
                                     0.5,
                                     0.5,
                                     fill=False)

                plt.gca().add_patch(rect)
                x_aux = obj.x + 0.25 * cos(pi / 2 - obj.th)
                y_aux = obj.y + 0.25 * sin(pi / 2 - obj.th)
                heading = plt.Line2D((obj.x, x_aux), (obj.y, y_aux),
                                     lw=1,
                                     color='k')
                plt.gca().add_line(heading)

            w = 1.0
            # print (obj.x,obj.y)
            ##para calcular el rectangulo
            s = QRectF(QPointF(0, 0), QSizeF(w, obj.sp))

            # if (d):
            #     plt.plot (s.bottomLeft().x(),s.bottomLeft().y(),"go")
            #     plt.plot(s.bottomRight().x(), s.bottomRight().y(), "ro")
            #     plt.plot(s.topRight().x(), s.topRight().y(), "yo")
            #     plt.plot(s.topLeft().x(), s.topLeft().y(), "bo")

            space = QPolygonF()
            space.append(s.topLeft())
            space.append(s.topRight())
            space.append(
                QPointF(s.bottomRight().x() + obj.sp / 4,
                        s.bottomRight().y()))
            space.append(
                QPointF(s.bottomLeft().x() - obj.sp / 4,
                        s.bottomLeft().y()))

            t = QTransform()
            t.translate(-w / 2, 0)
            space = t.map(space)
            t = QTransform()
            t.rotateRadians(-obj.th)
            space = t.map(space)

            t = QTransform()
            t.translate(obj.x, obj.y)
            space = t.map(space)

            # points = []
            # for x in xrange(space.count()-1):
            #     point = space.value(x)
            #     print ("valor", point)
            #     points.append([point.x(),point.y()])
            #     plt.plot(point.x(),point.y(),"go")

            polyline = []

            for x in range(space.count()):
                point = space.value(x)
                if (d):
                    plt.plot(point.x(), point.y(), "go")

                p = SNGPoint2D()
                p.x = point.x()
                p.z = point.y()
                polyline.append([p.x, p.z])

            polylines_object.append(polyline)

            for p in persons:
                pn = Person(p.x, p.z, p.angle)
                # print("PERSONA", persons.index(p)+1)
                if d:
                    body = plt.Circle((pn.x, pn.y), radius=0.3, fill=False)
                    plt.gca().add_patch(body)

                    x_aux = pn.x + 0.30 * cos(pi / 2 - pn.th)
                    y_aux = pn.y + 0.30 * sin(pi / 2 - pn.th)
                    heading = plt.Line2D((pn.x, x_aux), (pn.y, y_aux),
                                         lw=1,
                                         color='k')
                    plt.gca().add_line(heading)
                    plt.axis('equal')

                ##CHECKING THE ORIENTATION
                print("obj.angle", obj.th, "person.angle", pn.th)
                a = abs(obj.th - abs(pn.th - math.pi))
                if a < math.radians(45):
                    checkangle = True
                else:
                    checkangle = False

                ##CHECKING IF THE PERSON IS INSIDE THE POLYGON
                if space.containsPoint(QPointF(pn.x, pn.y),
                                       Qt.OddEvenFill):  # and checkangle:
                    print("DENTROOOOO Y MIRANDO")
                    if not polyline in polylines_interacting:
                        polylines_interacting.append(polyline)

        if d:
            for ps in polylines_interacting:
                #  plt.figure()
                for p in ps:
                    plt.plot(p.x, p.z, "ro")
                    plt.axis('equal')
                    plt.xlabel('X')
                    plt.ylabel('Y')
            plt.show()
        plt.show()

        if (interaction):
            return polylines_interacting
        else:
            return polylines_object