示例#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 rotateImage(self,filepath):
		print "ROTATING FILE: " + filepath
		img = QImage(filepath)
		rot = QTransform()
		rot = rot.rotate(90)
		img = img.transformed(rot)
		img.save(filepath)
		self.imageRotated.emit(filepath)
示例#4
0
	def sendLocation(self, jid, latitude, longitude, rotate):
		latitude = latitude[:10]
		longitude = longitude[:10]

		self._d("Capturing preview...")
		QPixmap.grabWindow(QApplication.desktop().winId()).save(WAConstants.CACHE_PATH+"/tempimg.png", "PNG")
		img = QImage(WAConstants.CACHE_PATH+"/tempimg.png")

		if rotate == "true":
			rot = QTransform()
			rot = rot.rotate(90)
			img = img.transformed(rot)

		if img.height() > img.width():
			result = img.scaledToWidth(320,Qt.SmoothTransformation);
			result = result.copy(result.width()/2-50,result.height()/2-50,100,100);
		elif img.height() < img.width():
			result = img.scaledToHeight(320,Qt.SmoothTransformation);
			result = result.copy(result.width()/2-50,result.height()/2-50,100,100);
		#result = img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation);

		result.save( WAConstants.CACHE_PATH+"/tempimg2.jpg", "JPG" );

		f = open(WAConstants.CACHE_PATH+"/tempimg2.jpg", 'r')
		stream = base64.b64encode(f.read())
		f.close()


		os.remove(WAConstants.CACHE_PATH+"/tempimg.png")
		os.remove(WAConstants.CACHE_PATH+"/tempimg2.jpg")

		fmsg = WAXMPP.message_store.createMessage(jid);
		
		mediaItem = WAXMPP.message_store.store.Media.create()
		mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_LOCATION
		mediaItem.remote_url = None
		mediaItem.preview = stream
		mediaItem.local_path ="%s,%s"%(latitude,longitude)
		mediaItem.transfer_status = 2

		fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Location")
		fmsg.Media = mediaItem

		if fmsg.Conversation.type == "group":
			contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid)
			fmsg.setContact(contact);
		
		fmsg.setData({"status":0,"content":fmsg.content,"type":1})
		WAXMPP.message_store.pushMessage(jid,fmsg)
		
		
		resultId = self.interfaceHandler.call("message_locationSend", (jid, latitude, longitude, stream))
		k = Key(jid, True, resultId)
		fmsg.key = k.toString()
		fmsg.save()
示例#5
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
示例#6
0
文件: aref.py 项目: billowen/pygds
    def bbox(self):
        """ Get the bounding rect of a AREF.

        Returns
            bbox: the Rect which indicates the bbox of current gds element or none if failed to calculate the bbox.
        """
        if self.refer_to is None or self.pts is None or self.row <= 0 or self.col <= 0 or len(self.pts) != 3:
            return None
        row_pitch_x = (self.pts[2].x - self.pts[0].x) / self.row
        row_pitch_y = (self.pts[2].y - self.pts[0].y) / self.row
        col_pitch_x = (self.pts[1].x - self.pts[0].x) / self.col
        col_pitch_y = (self.pts[1].y - self.pts[0].y) / self.col

        ref_bbox = self.refer_to.bbox()
        if ref_bbox is None:
            return None

        rect1 = QRect(ref_bbox.x, ref_bbox.y, ref_bbox.width, ref_bbox.height)
        reflect_transform = QTransform()
        if self.reflect is True:
            reflect_transform.scale(1, -1)
        mag_transform = QTransform().scale(self.mag, self.mag)
        rotate_transform = QTransform().rotate(self.angle)
        shift_transforms = [QTransform().translate(self.pts[0].x, self.pts[0].y),
                            QTransform().translate(self.pts[0].x + col_pitch_x * (self.col-1),
                                                   self.pts[0].y + col_pitch_y * (self.col-1)),
                            QTransform().translate(self.pts[0].x + row_pitch_x * (self.row-1),
                                                   self.pts[0].y + row_pitch_y * (self.row-1)),
                            QTransform().translate(self.pts[0].x
                                                   + row_pitch_x * (self.row-1)
                                                   + col_pitch_x * (self.col-1),
                                                   self.pts[0].y
                                                   + row_pitch_y * (self.row-1)
                                                   + col_pitch_y * (self.col-1))]

        llx = lly = GDS_MAX_INT
        urx = ury = GDS_MIN_INT
        for shift in shift_transforms:
            transform = reflect_transform*mag_transform*rotate_transform*shift
            map_rect = transform.mapRect(rect1)
            if map_rect.x() < llx:
                llx = map_rect.x()
            if map_rect.y() < lly:
                lly = map_rect.y()
            if map_rect.x() + map_rect.width() > urx:
                urx = map_rect.x() + map_rect.width()
            if map_rect.y() + map_rect.height() > ury:
                ury = map_rect.y() + map_rect.height()

        return BBox(llx, lly, urx - llx, ury - lly)
示例#7
0
 def handleLeftClick(self, _, event):
     clickPos = event.scenePos()
     if self.itemAt(clickPos.x(), clickPos.y(), QTransform()) == None:
         print("missed")
         self.dragBoxRect.setStartPos(event.scenePos())
         self.dragging = True
     else:
         print("hit")
         self.selectedItem = self.itemAt(clickPos.x(), clickPos.y(),
                                         QTransform())
         # self.dragItemStartPos = self.selectedItem.scenePos()
         self.dragItemStartPos = self.selectedItem.pos()
         self.zIncrementer += 1
         self.selectedItem.setZValue(self.zIncrementer)
示例#8
0
    def testsquareToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        t1 = QTransform()
        r1 = QTransform.squareToQuad(q1, t1)
        r2 = QTransform.squareToQuad(q1)

        self.assertTrue(r1)
        self.assert_(r2)

        self.assertEqual(t1, r2)
示例#9
0
    def testsquareToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        t1 = QTransform()
        r1 = QTransform.squareToQuad(q1, t1)
        r2 = QTransform.squareToQuad(q1)

        self.assertTrue(r1)
        self.assert_(r2)

        self.assertEqual(t1, r2)
示例#10
0
 def resize(self):
     
     trValue = QTransform().scale( self.transInfo.scaleX(), self.transInfo.scaleY() )
     trValue *= QTransform().rotate( self.transInfo.rotValue )
     imageTransformed = self.image.transformed(trValue)
     
     imageWidth = imageTransformed.width()
     imageHeight = imageTransformed.height()
     
     self.pixmap = QPixmap.fromImage( imageTransformed )
     self.label.setPixmap( self.pixmap )
     
     marginLeft = (self.width() - imageWidth)/2.0
     marginTop  = (self.height() - imageHeight)/2.0
     
     self.label.setGeometry( marginLeft + self.transInfo.x,marginTop + self.transInfo.y, imageWidth, imageHeight )
示例#11
0
	def _getPictureForSending(self, jid, filepath):
		print "Preparing picture " + filepath + " for " + jid
		image = filepath.replace("file://","")
		rotation = 0

		ret = {}
		im = Image.open(image)
		try:
			info = im._getexif()
			for tag, value in info.items():
				decoded = TAGS.get(tag, value)
				ret[decoded] = value
			if ret['Orientation'] == 6:
				rotation = 90
		except:
			rotation = 0

		user_img = QImage(image)

		if rotation == 90:
			rot = QTransform()
			rot = rot.rotate(90)
			user_img = user_img.transformed(rot)


		if user_img.height() > user_img.width():
			preimg = user_img.scaledToWidth(480, Qt.SmoothTransformation)
			preimg = preimg.copy( 0, preimg.height()/2-240, 480, 480);
		elif user_img.height() < user_img.width():
			preimg = user_img.scaledToHeight(480, Qt.SmoothTransformation)
			preimg = preimg.copy( preimg.width()/2-240, 0, 480, 480);
		else:
			preimg = user_img.scaled(480, 480, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)

		preimg.save(WAConstants.CACHE_PATH+"/temp.jpg", "JPG")

		''''f = open(WAConstants.CACHE_PATH+"/temp.jpg", 'r')
		stream = f.read()
		stream = bytearray(stream)
		f.close()
		'''
		
		return WAConstants.CACHE_PATH+"/temp.jpg"
示例#12
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
示例#13
0
    def testquadToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        q2 = QPolygonF()
        q2.append(QPointF(20.0, 20.0))
        q2.append(QPointF(30.0, 20.0))
        q2.append(QPointF(20.0, -20.0))
        q2.append(QPointF(30.0, -20.0))

        t1 = QTransform()
        r1 = QTransform.quadToQuad(q1, q2, t1)
        r2 = QTransform.quadToQuad(q1, q2)

        self.assertTrue(r1)
        self.assert_(r2)

        self.assertEqual(t1, r2)
示例#14
0
    def testquadToQuad(self):
        q1 = QPolygonF()
        q1.append(QPointF(10.0, 10.0))
        q1.append(QPointF(20.0, 10.0))
        q1.append(QPointF(10.0, -10.0))
        q1.append(QPointF(20.0, -10.0))

        q2 = QPolygonF()
        q2.append(QPointF(20.0, 20.0))
        q2.append(QPointF(30.0, 20.0))
        q2.append(QPointF(20.0, -20.0))
        q2.append(QPointF(30.0, -20.0))

        t1 = QTransform()
        r1 = QTransform.quadToQuad(q1, q2, t1)
        r2 = QTransform.quadToQuad(q1, q2)

        self.assertTrue(r1)
        self.assert_(r2)

        self.assertEqual(t1, r2)
示例#15
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)
示例#16
0
    def resize(self):

        if self.imageClean: return None

        trValue = QTransform().scale(self.transInfo.scaleX(),
                                     self.transInfo.scaleY())
        trValue *= QTransform().rotate(self.transInfo.rotValue)
        imageTransformed = self.image.transformed(trValue)

        imageWidth = imageTransformed.width()
        imageHeight = imageTransformed.height()

        self.pixmap = QPixmap.fromImage(imageTransformed)
        self.label.setPixmap(self.pixmap)

        marginLeft = (self.width() - imageWidth) / 2.0
        marginTop = (self.height() - imageHeight) / 2.0

        self.label.setGeometry(marginLeft + self.transInfo.x,
                               marginTop + self.transInfo.y, imageWidth,
                               imageHeight)
        self.label.paintEvent(
            QPaintEvent(QtCore.QRect(0, 0, self.width(), self.height())))
示例#17
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)
示例#18
0
文件: sref.py 项目: billowen/pygds
    def bbox(self):
        """ Get the bounding rect of a SREF.

        Returns
            bbox: the BBox which indicates the bbox of current gds element or none if failed to calculate the bbox.
        """
        if self.refer_to is None or self.pt is None:
            return None

        ref_bbox = self.refer_to.bbox()
        if ref_bbox is None:
            return None

        reflect_transform = QTransform()
        if self.reflect is True:
            reflect_transform.scale(1, -1)
        mag_transform = QTransform().scale(self.mag, self.mag)
        rotate_transform = QTransform().rotate(self.angle)
        shift_transform = QTransform().translate(self.pt.x, self.pt.y)
        transform = reflect_transform * mag_transform * rotate_transform * shift_transform

        rect = QRect(ref_bbox.x, ref_bbox.y, ref_bbox.width, ref_bbox.height)
        rect2 = transform.mapRect(rect)
        return BBox(rect2.x(), rect2.y(), rect2.width(), rect2.height())
示例#19
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)
示例#20
0
    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)
    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)
示例#23
0
    def firstPage(self):
        
        for i in range( self.mainLayout.count() ):
            item = self.mainLayout.itemAt(0)
            item.widget().setParent( None )
        
        title = QLabel( "<p style='color:rgb( 137,129,120 )'>Welcome to the PingoTools Installer</p>" )
        title.setFixedHeight( 50 )
        titleFont  = QFont()
        titleFont.setPixelSize( 18 )
        titleFont.setBold( True )
        titleFont.setFamily( "Helvetica [Cronyx]" )
        title.setAlignment( QtCore.Qt.AlignCenter )
        title.setFont( titleFont )
        
        description = QLabel()
        description.setAlignment( QtCore.Qt.AlignCenter )
        
        buttonsWidget = QWidget(); buttonsWidget.setMaximumHeight( 50 )
        buttonsLayout = QHBoxLayout( buttonsWidget )
        emptyArea = QLabel()
        buttonNext = QPushButton( 'Next > ' )
        buttonCancel = QPushButton( 'Cancel' )
        buttonsLayout.addWidget( emptyArea )
        buttonsLayout.addWidget( buttonNext ); buttonNext.setFixedWidth( 100 )
        buttonsLayout.addWidget( buttonCancel ); buttonCancel.setFixedWidth( 100 )
        
        self.mainLayout.addWidget( title )
        self.mainLayout.addWidget( description )
        self.mainLayout.addWidget( buttonsWidget )
        
        origWidth = 500

        frontImage = QImage()
        frontImage.load( os.path.dirname( __file__ ) + '/images/pingoTools_main.jpg' )
        trValue = QTransform().scale( float(origWidth)/frontImage.width(), float(origWidth)/frontImage.width() )
        transformedImage = frontImage.transformed( trValue )
        pixmap     = QPixmap.fromImage( transformedImage )
        description.setPixmap( pixmap )
        description.setGeometry( 0,0, transformedImage.width() , transformedImage.height() )
        description.paintEvent(QPaintEvent(QtCore.QRect( 0,0,self.width(), self.height() )))
        
        QtCore.QObject.connect( buttonNext, QtCore.SIGNAL( 'clicked()' ), self.secondPage )
        QtCore.QObject.connect( buttonCancel, QtCore.SIGNAL( 'clicked()' ), self.cmd_cancel )
示例#24
0
    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
示例#26
0
    def __init__(self, *args, **kwargs):

        super(Label_descriptionImage, self).__init__(*args, **kwargs)

        self.setAlignment(QtCore.Qt.AlignCenter)

        if Label_descriptionImage.descriptionImagePath:
            frontImage = QImage()
            frontImage.load(Label_descriptionImage.descriptionImagePath)
            origWidth = frontImage.width()
            trValue = QTransform().scale(
                float(origWidth) / frontImage.width(),
                float(origWidth) / frontImage.width())
            transformedImage = frontImage.transformed(trValue)
            pixmap = QPixmap.fromImage(transformedImage)
            self.setPixmap(pixmap)
            self.setGeometry(0, 0, transformedImage.width(),
                             transformedImage.height())
            self.paintEvent(
                QPaintEvent(QtCore.QRect(0, 0, self.width(), self.height())))
示例#27
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)
示例#28
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)
示例#29
0
    def paintEvent(self, event):
        painter = QPainter(self)

        # Фон
        painter_path = QPainterPath()
        painter_path.addRect(0, 0, self.width() - 1, self.height() - 1)
        painter.fillPath(painter_path, QBrush(QImage(':/main/background.png')))

        if self.image:
            painter.drawText(10, 20, str(self.image.draw_scale))

            painter.setTransform(QTransform().scale(
                self.image.draw_scale,
                self.image.draw_scale).translate(self.image.draw_offset.x(),
                                                 self.image.draw_offset.y()))
            old_pen = painter.pen()

            new_pen = QPen()
            new_pen.setColor(QColor(0, 150, 0))
            painter.setPen(new_pen)

            self.image.draw(painter)

            painter.setPen(old_pen)
示例#30
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)
示例#31
0
 def zoomReset(self):
     self.scale = 1
     self.view.setTransform(QTransform())
 def rotate(self):
     myTransform = QTransform()
     myTransform.rotate(90)
     self.image = self.image.transformed(myTransform)
     self.update()
示例#33
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
示例#34
0
    def _paint_crop(self, painter, option, index):
        """Paints the crop
        """
        source_rect = index.data(RectRole)
        crop_rect = self.crop_rect.translated(option.rect.topLeft())
        angle = index.data(RotationRole)

        # Target rect with same aspect ratio as source
        source_aspect = float(source_rect.width()) / source_rect.height()
        crop_aspect = float(crop_rect.width()) / crop_rect.height()

        # True if the item has been rotated by a multiple of 90 degrees
        perpendicular = 1 == (angle / 90) % 2

        # Some nasty logic to compute the target rect
        if perpendicular:
            crop_aspect = 1.0 / crop_aspect

        if source_aspect > 1.0:
            # Crop is wider than is is tall
            if crop_aspect > source_aspect:
                fit_to = 'height'
                f = 1.0 / source_aspect
            else:
                fit_to = 'width'
                f = source_aspect
        else:
            # Crop is taller than is is wide
            if crop_aspect < source_aspect:
                fit_to = 'width'
                f = source_aspect
            else:
                fit_to = 'height'
                f = 1.0 / source_aspect

        if perpendicular:
            if 'width' == fit_to:
                size = QSize(crop_rect.height(),
                             crop_rect.height() / f)
            else:
                size = QSize(crop_rect.width() / f,
                             crop_rect.width())
        else:
            if 'width' == fit_to:
                size = QSize(crop_rect.width(),
                             crop_rect.width() / f)
            else:
                size = QSize(crop_rect.height() / f,
                             crop_rect.height())

        target_rect = QRect(crop_rect.topLeft(), size)
        target_rect.moveCenter(option.rect.center())

        # Draw rotated
        if angle:
            t = QTransform()
            t.translate(option.rect.width() / 2+option.rect.left(),
                        option.rect.height() / 2+option.rect.top())
            t.rotate(angle)
            t.translate(-option.rect.width() / 2-option.rect.left(),
                        -option.rect.height() / 2-option.rect.top())

        with painter_state(painter):
            if angle:
                painter.setTransform(t)
            painter.drawPixmap(target_rect, index.data(PixmapRole), source_rect)

            if QStyle.State_Selected & option.state:
                painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
                painter.drawRect(target_rect)
示例#35
0
    def _paint_crop(self, painter, option, index):
        """The cropped image
        """
        source_rect = index.data(RectRole)
        crop_rect = self.CROP_RECT.translated(option.rect.topLeft())
        angle = index.data(RotationRole)

        # Target rect with same aspect ratio as source
        source_aspect = float(source_rect.width()) / source_rect.height()
        crop_aspect = float(crop_rect.width()) / crop_rect.height()

        # True is the item has been rotated by a multiple of 90 degrees
        perpendicular = 1 == (angle / 90) % 2

        # Some nasty logic to compute the target rect
        if perpendicular:
            crop_aspect = 1.0 / crop_aspect

        if source_aspect > 1.0:
            # Crop is wider than is is tall
            if crop_aspect > source_aspect:
                fit_to = 'height'
                f = 1.0 / source_aspect
            else:
                fit_to = 'width'
                f = source_aspect
        else:
            # Crop is taller than is is wide
            if crop_aspect < source_aspect:
                fit_to = 'width'
                f = source_aspect
            else:
                fit_to = 'height'
                f = 1.0 / source_aspect

        if perpendicular:
            if 'width' == fit_to:
                size = QSize(crop_rect.height(), crop_rect.height() / f)
            else:
                size = QSize(crop_rect.width() / f, crop_rect.width())
        else:
            if 'width' == fit_to:
                size = QSize(crop_rect.width(), crop_rect.width() / f)
            else:
                size = QSize(crop_rect.height() / f, crop_rect.height())

        target_rect = QRect(crop_rect.topLeft(), size)
        target_rect.moveCenter(option.rect.center())

        # Draw rotated
        if angle:
            t = QTransform()
            t.translate(option.rect.width() / 2 + option.rect.left(),
                        option.rect.height() / 2 + option.rect.top())
            t.rotate(angle)
            t.translate(-option.rect.width() / 2 - option.rect.left(),
                        -option.rect.height() / 2 - option.rect.top())

        with painter_state(painter):
            if angle:
                painter.setTransform(t)
            painter.drawPixmap(target_rect, index.data(PixmapRole),
                               source_rect)

            painter.setPen(QPen(Qt.white, 1, Qt.SolidLine))
            painter.drawRect(target_rect)
示例#36
0
 def setUp(self):
     self.original = QTransform(1, 2, 3, 4, 5, 6, 7, 8)
示例#37
0
    def drawHb(self, hbDict):
        viewIndex = 1
        if not hbDict.has_key(self.ijk[viewIndex]):
            return
        if hbDict[self.ijk[viewIndex]].insert < 4:
            return

        a, b, c, d = [
            self.ij2point(viewIndex, i, j)
            for (i, j) in hbDict[self.ijk[viewIndex]].get_points()
        ]

        cp = hbDict[self.ijk[viewIndex]].cp
        cp = self.ij2point(viewIndex, cp[0], cp[1])

        vA = (a[0] - cp[0], a[1] - cp[1])
        vB = (b[0] - cp[0], b[1] - cp[1])
        vD = (d[0] - cp[0], d[1] - cp[1])

        arcAD = QPainterPath()
        arcDB = QPainterPath()

        if hbDict['name'] == 'HbRight':
            sign = 1
            startAngle = 0
        else:
            sign = -1
            startAngle = 180

        angleADlad = sign * angleBw2Vectors(vA, vD)
        angleAD = 180 / np.pi * angleADlad

        if vD[0] * vD[0] + vD[1] * vD[1] >= vA[0] * vA[0] + vA[1] * vA[1]:
            rotD = (np.sqrt(vD[0] * vD[0] + vD[1] * vD[1]), 0)
            coefA = rotD[0]

            rotA = rotateVector(vA, angleADlad)
            coefB = np.sqrt(coefA * coefA /
                            (coefA * coefA - rotA[0] * rotA[0]) * rotA[1] *
                            rotA[1])
            eccentricAnomalyAD = -180 / np.pi * np.arctan(
                coefA / coefB * np.tan(angleADlad))
            arcAD.moveTo(cp[0] + sign * coefA, cp[1])
            arcAD.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB,
                        startAngle, eccentricAnomalyAD)
        else:
            rotA = (np.sqrt(vA[0] * vA[0] + vA[1] * vA[1]), 0)
            coefA = rotA[0]

            angleDAlad = sign * angleBw2Vectors(vD, vA)
            angleDA = 180 / np.pi * angleDAlad

            rotD = vD
            coefB = np.sqrt(coefA * coefA /
                            (coefA * coefA - rotD[0] * rotD[0]) * rotD[1] *
                            rotD[1])
            eccentricAnomalyDA = 180 / np.pi * np.arctan(
                coefA / coefB * np.tan(angleDAlad))
            arcAD.moveTo(cp[0] + sign * coefA, cp[1])
            arcAD.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB,
                        startAngle, eccentricAnomalyDA)
            angleAD = 0.0

        if vD[0] * vD[0] + vD[1] * vD[1] >= vB[0] * vB[0] + vB[1] * vB[1]:
            rotD = (np.sqrt(vD[0] * vD[0] + vD[1] * vD[1]), 0)
            coefA = rotD[0]

            angleBDlad = sign * angleBw2Vectors(vD, vB)
            angleBD = 180 / np.pi * angleBDlad

            rotB = rotateVector(vB, angleADlad)
            coefB = np.sqrt(coefA * coefA /
                            (coefA * coefA - rotB[0] * rotB[0]) * rotB[1] *
                            rotB[1])
            eccentricAnomalyDB = 180 / np.pi * np.arctan(
                coefA / coefB * np.tan(angleBDlad))
            arcDB.moveTo(cp[0] + sign * coefA, cp[1])
            arcDB.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB,
                        startAngle, eccentricAnomalyDB)

            angleAB = 180 / np.pi * sign * angleBw2Vectors(vA, vD)
        else:
            rotB = (np.sqrt(vB[0] * vB[0] + vB[1] * vB[1]), 0)
            coefA = rotB[0]

            angleABlad = sign * angleBw2Vectors(vA, vB)
            angleAB = 180 / np.pi * angleABlad

            angleDBlad = sign * angleBw2Vectors(vD, vB)
            angleDB = 180 / np.pi * angleDBlad

            rotD = rotateVector(vD, angleABlad)
            coefB = np.sqrt(coefA * coefA /
                            (coefA * coefA - rotD[0] * rotD[0]) * rotD[1] *
                            rotD[1])
            eccentricAnomalyDB = -180 / np.pi * np.arctan(
                coefA / coefB * np.tan(angleDBlad))
            arcDB.moveTo(cp[0] + sign * coefA, cp[1])
            arcDB.arcTo(cp[0] - coefA, cp[1] - coefB, 2 * coefA, 2 * coefB,
                        startAngle, eccentricAnomalyDB)

        imgAC = self.scenes[viewIndex].addLine(a[0],
                                               a[1],
                                               cp[0],
                                               cp[1],
                                               pen=QPen(QColor(
                                                   hbDict['color'])))
        imgBC = self.scenes[viewIndex].addLine(b[0],
                                               b[1],
                                               c[0],
                                               c[1],
                                               pen=QPen(QColor(
                                                   hbDict['color'])))
        imgAD = self.scenes[viewIndex].addPath(arcAD,
                                               pen=QPen(QColor(
                                                   hbDict['color'])))
        imgAD.setTransform(QTransform().translate(
            cp[0], cp[1]).rotate(-angleAD).translate(-cp[0], -cp[1]))
        imgDB = self.scenes[viewIndex].addPath(arcDB,
                                               pen=QPen(QColor(
                                                   hbDict['color'])))
        imgDB.setTransform(QTransform().translate(
            cp[0], cp[1]).rotate(-angleAB).translate(-cp[0], -cp[1]))
        hbDict['images'] = [imgAD, imgDB, imgBC, imgAC]
示例#38
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)
    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()