示例#1
0
 def testMap(self):
     transform = QTransform()
     values = (10.0, 20.0)
     tx, ty = transform.map(*values)
     self.assert_(isinstance(tx, float))
     self.assert_(isinstance(ty, float))
     self.assertEqual((tx, ty), values)
示例#2
0
 def testMap(self):
     transform = QTransform()
     values = (10.0, 20.0)
     tx, ty = transform.map(*values)
     self.assert_(isinstance(tx, float))
     self.assert_(isinstance(ty, float))
     self.assertEqual((tx, ty), values)
示例#3
0
    def _draw_arrow(painter, from_point, to_point, arrow_size=5):
        painter.drawLine(from_point, to_point)
        painter.setPen(Qt.NoPen)
        center = (from_point + to_point) / 2

        center_to_t = QVector2D(to_point - center)

        center_to_t.normalize()

        center_to_t *= arrow_size
        t = QTransform()
        arrow_points = [center + center_to_t.toPointF()]
        t.rotate(120)
        arrow_points.append(center + t.map(center_to_t.toPointF()))
        t.rotate(120)
        arrow_points.append(center + t.map(center_to_t.toPointF()))
        painter.drawPolygon(arrow_points)
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(self.normalPath)
示例#5
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(normalPath)
示例#6
0
 def shape(self):
     bound = QPainterPath()
     rotMatrix = QTransform().rotate(self.angle)
     poly = QPolygonF([
         QPointF(0, 0),
         QPointF(self.w, 0),
         QPointF(self.w, self.h),
         QPointF(0, self.h),
     ])
     poly = rotMatrix.map(poly)
     bound.addPolygon(poly)
     return bound
示例#7
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        closedPath = self.normalPath  # QPainterPath
        closedPath.closeSubpath()
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(closedPath)
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        closedPath = normalPath  # QPainterPath
        closedPath.closeSubpath()
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(closedPath)
    def subPathList(self):
        """
        TOWRITE

        :rtype: QList<QPainterPath>
        """
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)

        ## QList<QPainterPath> pathList;
        pathList = []
        path = self.objTextPath  # QPainterPath

        element = QPainterPath.Element
        pathMoves = []  # QList<int>
        numMoves = 0  # int

        for i in range(0, path.elementCount()):  # for(int i = 0; i < path.elementCount(); i++)

            element = path.elementAt(i)
            if element.isMoveTo():

                pathMoves.append(i)  # pathMoves << i;
                numMoves += 1  # numMoves++;

        pathMoves.append(path.elementCount())  # pathMoves << path.elementCount();

        for p in range(0, len(pathMoves) - 1):  #  for(int p = 0; p < pathMoves.size()-1 && p < numMoves; p++)
            if not (p < numMoves):
                break

            subPath = QPainterPath()
            for i in range(pathMoves[p], pathMoves[p + 1]):  # for(int i = pathMoves.value(p); i < pathMoves.value(p+1); i++)

                element = path.elementAt(i)
                if element.isMoveTo():
                    subPath.moveTo(element.x, element.y)

                elif element.isLineTo():
                    subPath.lineTo(element.x, element.y)

                elif element.isCurveTo():
                    subPath.cubicTo(path.elementAt(i).x, path.elementAt(i).y,          # control point 1
                                    path.elementAt(i + 1).x, path.elementAt(i + 1).y,  # control point 2
                                    path.elementAt(i + 2).x, path.elementAt(i + 2).y)  # end point

            pathList.append(trans.map(subPath))

        return pathList
    def subPathList(self):
        """
        TOWRITE

        :rtype: QList<QPainterPath>
        """
        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)

        ## QList<QPainterPath> pathList;
        pathList = []
        path = objTextPath  # QPainterPath

        element = QPainterPath.Element
        pathMoves = []  # QList<int>
        numMoves = 0  # int

        for i in range(0, path.elementCount()):  # for(int i = 0; i < path.elementCount(); i++)

            element = path.elementAt(i)
            if element.isMoveTo():

                pathMoves.append(i)  # pathMoves << i;
                numMoves += 1 # numMoves++;

        pathMoves.append(path.elementCount())  # pathMoves << path.elementCount();

        for p in range(0, pathMoves.size() - 1 and numMoves):  #  for(int p = 0; p < pathMoves.size()-1 && p < numMoves; p++)

            subPath = QPainterPath()
            for i in range(pathMoves.value(p), pathMoves.value(p + 1)):  # for(int i = pathMoves.value(p); i < pathMoves.value(p+1); i++)

                element = path.elementAt(i)
                if element.isMoveTo():
                    subPath.moveTo(element.x, element.y)

                elif element.isLineTo():
                    subPath.lineTo(element.x, element.y)

                elif element.isCurveTo():
                    subPath.cubicTo(path.elementAt(i).x, path.elementAt(i).y,          # control point 1
                                    path.elementAt(i + 1).x, path.elementAt(i + 1).y,  # control point 2
                                    path.elementAt(i + 2).x, path.elementAt(i + 2).y)  # end point

            pathList.append(trans.map(subPath))

        return pathList
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        r = self.rect()  # QRectF
        path.arcMoveTo(r, 0)
        path.arcTo(r, 0, 360)

        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(path)
示例#12
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        r = self.rect()  # QRectF
        path.arcMoveTo(r, 0)
        path.arcTo(r, 0, 360)

        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(path)
示例#13
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        r = self.rect()  # QRectF
        path.moveTo(r.bottomLeft())
        path.lineTo(r.bottomRight())
        path.lineTo(r.topRight())
        path.lineTo(r.topLeft())
        path.lineTo(r.bottomLeft())

        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(path)
示例#14
0
    def objectSavePath(self):
        """
        TOWRITE

        :rtype: `QPainterPath`_
        """
        path = QPainterPath()
        r = self.rect()  # QRectF
        path.moveTo(r.bottomLeft())
        path.lineTo(r.bottomRight())
        path.lineTo(r.topRight())
        path.lineTo(r.topLeft())
        path.lineTo(r.bottomLeft())

        s = self.scale()  # qreal
        trans = QTransform()
        trans.rotate(self.rotation())
        trans.scale(s, s)
        return trans.map(path)
示例#15
0
    def layout_nodes(self):
        nodes_count = len(self.nodes)
        if nodes_count == 0:
            return

        step = 360 / nodes_count

        total_width = 0
        for node_name in self.nodes:
            total_width += self.nodes.get(node_name).boundingRect().width()

        index = 0
        for node in self.nodes:
            # noinspection PyUnresolvedReferences
            xform = QTransform()
            angle = index * step
            xform.rotate(angle)

            mapped = xform.map(QPointF(total_width / 2, 0))
            self.nodes.get(node).setPos(mapped)
            index += 1
    def paintEvent(self, event):
        #mtx = self.mtx
        mtx = QTransform()
        mtx.rotate(self.mrotation)
        mtx.scale(self.mscale.x(), self.mscale.y())
        mtx.translate(self.mtranslate.x(), self.mtranslate.y())
        eyepos = QPointF(self.epx, self.dof)
        ppoi = QPointF(self.ppx, self.ppy)
        point = QRectF(0.0,0.0,0.05,0.05);

        tpoi = mtx.map(ppoi)
        teyepos = mtx.map(eyepos)
        evec = QVector2D(tpoi - teyepos).normalized()

        pts = find_points(float2(tpoi.x(),tpoi.y()), float2(evec.x(), evec.y()))
        print pts
        qp = QtGui.QPainter()
        qp.begin(self)
        qp.scale(self.width()/5.0,self.height()/5.0)
        qp.translate(2.5,2.5)
        #draw voxel bounds
        qp.drawRect(QRectF(0.0,0.0,1.0,1.0))
        #qp.transform(mtx)
        #draw eyepos
        point.moveTo(mtx.map(eyepos))
        qp.fillRect(point, QColor("black"))
        point.moveTo(mtx.map(ppoi))
        qp.fillRect(point, QColor("grey"))
        qp.setPen(QColor("cyan"))
        qp.drawLine(mtx.map(QLineF(-0.5,0.0,1.5,0.0)))
        qp.setPen(QColor("blue"))
        qp.drawLine(mtx.map(QLineF(-0.0,0.0,1.0,0.0)))
        qp.setPen(QColor("lime"))
        qp.drawLine(QLineF(eyepos,ppoi))
        qp.setPen(QColor("green"))
        qp.drawLine(QLineF(teyepos,tpoi))
        qp.setPen(QColor("orange"))
        qp.drawLine(QLineF(pts['x'],pts['y'],pts['z'], pts['w']))
        point.moveTo(QPointF(pts['x'],pts['y']))
        qp.fillRect(point, QColor("red"))
        point.moveTo(QPointF(pts['z'],pts['w']))
        qp.fillRect(point, QColor("pink"))
        qp.end()
示例#17
0
    def paint(self, painter, option, widget=None):
        """
        Override of QGraphicsItem.paint method. Implement this in your child classes to
        make nodes with the look you want.
            :param QPainter painter:
            :param option:
            :param widget:
        """
        painter.setRenderHint(QPainter.Antialiasing)

        f = self.get_node_from_pos()
        t = self.get_node_to_pos()
        if not self.two_way:
            if self.conditional_to:
                pen = QPen(CONDITIONAL_TRANSITION_COLOR)
                pen.setWidth(4)
                painter.setPen(pen)
                painter.setBrush(CONDITIONAL_TRANSITION_COLOR)
            else:
                pen = QPen(NON_CONDITIONAL_TRANSITION_COLOR)
                pen.setWidth(4)
                painter.setPen(pen)
                painter.setBrush(NON_CONDITIONAL_TRANSITION_COLOR)
            self._draw_arrow(painter, f, t, self.arrow_length)
            return

        to_vector = QVector2D(t - f)
        to_vector.normalize()
        to_vector *= self.arrow_length

        xform = QTransform()
        xform.rotate(90)

        mapped = xform.map(to_vector.toPointF())

        from_start = mapped + f
        from_end = mapped + t
        if self.conditional_to:
            pen = QPen(CONDITIONAL_TRANSITION_COLOR)
            pen.setWidth(4)
            painter.setPen(pen)
            painter.setBrush(CONDITIONAL_TRANSITION_COLOR)
        else:
            pen = QPen(NON_CONDITIONAL_TRANSITION_COLOR)
            pen.setWidth(4)
            painter.setPen(pen)
            painter.setBrush(NON_CONDITIONAL_TRANSITION_COLOR)
        self._draw_arrow(painter, from_start, from_end, self.arrow_length)

        from_start = -mapped + t
        from_end = -mapped + f
        if self.conditional_from:
            pen = QPen(CONDITIONAL_TRANSITION_COLOR)
            pen.setWidth(4)
            painter.setPen(pen)
            painter.setBrush(CONDITIONAL_TRANSITION_COLOR)
        else:
            pen = QPen(NON_CONDITIONAL_TRANSITION_COLOR)
            pen.setWidth(4)
            painter.setPen(pen)
            painter.setBrush(NON_CONDITIONAL_TRANSITION_COLOR)
        self._draw_arrow(painter, from_start, from_end, self.arrow_length)
示例#18
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, o.z, 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 xrange(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)

            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
                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