Beispiel #1
0
    def __readDiagramInfo(self, diagramNode):
        dinfo = treenode.DiagramInfo()
        # read diagram info:
        if diagramNode is None:
            return dinfo, -1

        if diagramNode.hasAttribute('uid'):
            uid = int(diagramNode.getAttribute('uid'))
        else:
            uid = -1

        if diagramNode.hasAttribute('expanded'):
            val = diagramNode.getAttribute('expanded').lower()
            if val in ('yes', '1', 'true'):
                dinfo.expanded = True
            else:
                dinfo.expanded = False

        if diagramNode.hasAttribute('hAuto'):
            val = diagramNode.getAttribute('hAuto').lower()
            if val in ('yes', '1', 'true'):
                dinfo.autopositioning[DisplayRegime.Horizontal].autopos = True
            else:
                dinfo.autopositioning[DisplayRegime.Horizontal].autopos = False

        if diagramNode.hasAttribute('vAuto'):
            val = diagramNode.getAttribute('vAuto').lower()
            if val in ('yes', '1', 'true'):
                dinfo.autopositioning[DisplayRegime.Vertical].autopos = True
            else:
                dinfo.autopositioning[DisplayRegime.Vertical].autopos = False

        hShift = QPointF()
        if diagramNode.hasAttribute('hx'):
            hShift.setX(float(diagramNode.getAttribute('hx')))
        if diagramNode.hasAttribute('hy'):
            hShift.setY(float(diagramNode.getAttribute('hy')))
        dinfo.autopositioning[DisplayRegime.Horizontal].shift = hShift

        vShift = QPointF()
        if diagramNode.hasAttribute('vx'):
            vShift.setX(float(diagramNode.getAttribute('vx')))
        if diagramNode.hasAttribute('vy'):
            vShift.setY(float(diagramNode.getAttribute('vy')))
        dinfo.autopositioning[DisplayRegime.Vertical].shift = vShift

        if diagramNode.hasAttribute('sceneX'):
            dinfo.scenePos.setX(float(diagramNode.getAttribute('sceneX')))
        if diagramNode.hasAttribute('sceneY'):
            dinfo.scenePos.setY(float(diagramNode.getAttribute('sceneY')))

        return dinfo, uid
Beispiel #2
0
    def __readDiagramInfo(self, diagramNode):
        dinfo = treenode.DiagramInfo()
        # read diagram info:
        if diagramNode is None:
            return dinfo, -1

        if diagramNode.hasAttribute('uid'):
            uid = int(diagramNode.getAttribute('uid'))
        else:
            uid = -1

        if diagramNode.hasAttribute('expanded'):
            val = diagramNode.getAttribute('expanded').lower()
            if val in ('yes', '1', 'true'):
                dinfo.expanded = True
            else:
                dinfo.expanded = False

        if diagramNode.hasAttribute('hAuto'):
            val = diagramNode.getAttribute('hAuto').lower()
            if val in ('yes', '1', 'true'):
                dinfo.autopositioning[DisplayRegime.Horizontal].autopos = True
            else:
                dinfo.autopositioning[DisplayRegime.Horizontal].autopos = False

        if diagramNode.hasAttribute('vAuto'):
            val = diagramNode.getAttribute('vAuto').lower()
            if val in ('yes', '1', 'true'):
                dinfo.autopositioning[DisplayRegime.Vertical].autopos = True
            else:
                dinfo.autopositioning[DisplayRegime.Vertical].autopos = False

        hShift = QPointF()
        if diagramNode.hasAttribute('hx'):
            hShift.setX(float(diagramNode.getAttribute('hx')))
        if diagramNode.hasAttribute('hy'):
            hShift.setY(float(diagramNode.getAttribute('hy')))
        dinfo.autopositioning[DisplayRegime.Horizontal].shift = hShift

        vShift = QPointF()
        if diagramNode.hasAttribute('vx'):
            vShift.setX(float(diagramNode.getAttribute('vx')))
        if diagramNode.hasAttribute('vy'):
            vShift.setY(float(diagramNode.getAttribute('vy')))
        dinfo.autopositioning[DisplayRegime.Vertical].shift = vShift

        if diagramNode.hasAttribute('sceneX'):
            dinfo.scenePos.setX(float(diagramNode.getAttribute('sceneX')))
        if diagramNode.hasAttribute('sceneY'):
            dinfo.scenePos.setY(float(diagramNode.getAttribute('sceneY')))

        return dinfo, uid
    def setPosition(self, position):
        """
		Position is in values between 0 and 1.
		"""
        margins = self.boundedItem._margins
        rect = self.boundedItem.boundingRect()
        width = rect.width() - (margins.left() + margins.right() + 1)
        height = rect.height() - (margins.top() + margins.bottom() + 1)

        actualX = margins.left() + position[0] * width
        actualY = margins.top() + (1.0 - position[1]) * height

        actualPosition = QPointF()
        actualPosition.setX(actualX)
        actualPosition.setY(actualY)

        self.setPos(actualPosition)
	def setPosition(self, position):
		"""
		Position is in values between 0 and 1.
		"""
		margins = self.boundedItem._margins
		rect = self.boundedItem.boundingRect()
		width = rect.width() - (margins.left() + margins.right() + 1)
		height = rect.height() - (margins.top() + margins.bottom() + 1)

		actualX = margins.left() + position[0] * width
		actualY = margins.top() + (1.0 - position[1]) * height

		actualPosition = QPointF()
		actualPosition.setX(actualX)
		actualPosition.setY(actualY)

		self.setPos(actualPosition)
    def setPos(self, position):
        """
		@overrides(NodeItem)
		"""
        margins = self.boundedItem._margins
        rect = self.boundedItem.rect()
        width = rect.width() - (margins.left() + margins.right() + 1)
        height = rect.height() - (margins.top() + margins.bottom() + 1)

        boundedX = max(position.x(), margins.left())
        boundedX = min(boundedX, margins.left() + width)
        boundedY = max(position.y(), margins.top())
        boundedY = min(boundedY, margins.top() + height)

        boundedPosition = QPointF()
        boundedPosition.setX(boundedX)
        boundedPosition.setY(boundedY)

        super(TransferFunctionNodeItem, self).setPos(boundedPosition)
	def setPos(self, position):
		"""
		@overrides(NodeItem)
		"""
		margins = self.boundedItem._margins
		rect = self.boundedItem.rect()
		width = rect.width() - (margins.left() + margins.right() + 1)
		height = rect.height() - (margins.top() + margins.bottom() + 1)

		boundedX = max(position.x(), margins.left())
		boundedX = min(boundedX, margins.left() + width)
		boundedY = max(position.y(), margins.top())
		boundedY = min(boundedY, margins.top() + height)

		boundedPosition = QPointF()
		boundedPosition.setX(boundedX)
		boundedPosition.setY(boundedY)

		super(TransferFunctionNodeItem, self).setPos(boundedPosition)
Beispiel #7
0
    def interactive_resize(self, mouse_pos):
        """
        Perform shape interactive resize.
        """
        offset = self.handleSize + self.handleSpace
        bounding_rect = self.boundingRect()
        rect = self.rect()
        diff = QPointF(0, 0)

        self.prepareGeometryChange()

        if self.handleSelected == self.handleTopLeft:

            from_x = self.mousePressRect.left()
            from_y = self.mousePressRect.top()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setX(to_x - from_x)
            diff.setY(to_y - from_y)
            bounding_rect.setLeft(to_x)
            bounding_rect.setTop(to_y)
            rect.setLeft(bounding_rect.left() + offset)
            rect.setTop(bounding_rect.top() + offset)

        elif self.handleSelected == self.handleTopMiddle:

            from_y = self.mousePressRect.top()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setY(to_y - from_y)
            bounding_rect.setTop(to_y)
            rect.setTop(bounding_rect.top() + offset)

        elif self.handleSelected == self.handleTopRight:

            from_x = self.mousePressRect.right()
            from_y = self.mousePressRect.top()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setX(to_x - from_x)
            diff.setY(to_y - from_y)
            bounding_rect.setRight(to_x)
            bounding_rect.setTop(to_y)
            rect.setRight(bounding_rect.right() - offset)
            rect.setTop(bounding_rect.top() + offset)

        elif self.handleSelected == self.handleMiddleLeft:

            from_x = self.mousePressRect.left()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            diff.setX(to_x - from_x)
            bounding_rect.setLeft(to_x)
            rect.setLeft(bounding_rect.left() + offset)

        elif self.handleSelected == self.handleMiddleRight:
            print("MR")
            from_x = self.mousePressRect.right()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            diff.setX(to_x - from_x)
            bounding_rect.setRight(to_x)
            rect.setRight(bounding_rect.right() - offset)

        elif self.handleSelected == self.handleBottomLeft:

            from_x = self.mousePressRect.left()
            from_y = self.mousePressRect.bottom()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setX(to_x - from_x)
            diff.setY(to_y - from_y)
            bounding_rect.setLeft(to_x)
            bounding_rect.setBottom(to_y)
            rect.setLeft(bounding_rect.left() + offset)
            rect.setBottom(bounding_rect.bottom() - offset)

        elif self.handleSelected == self.handleBottomMiddle:

            from_y = self.mousePressRect.bottom()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setY(to_y - from_y)
            bounding_rect.setBottom(to_y)
            rect.setBottom(bounding_rect.bottom() - offset)

        elif self.handleSelected == self.handleBottomRight:

            from_x = self.mousePressRect.right()
            from_y = self.mousePressRect.bottom()
            to_x = from_x + mouse_pos.x() - self.mousePressPos.x()
            to_y = from_y + mouse_pos.y() - self.mousePressPos.y()
            diff.setX(to_x - from_x)
            diff.setY(to_y - from_y)
            bounding_rect.setRight(to_x)
            bounding_rect.setBottom(to_y)
            rect.setRight(bounding_rect.right() - offset)
            rect.setBottom(bounding_rect.bottom() - offset)

        # handle the case of width or height < 0
        width = abs(rect.width())
        height = abs(rect.height())
        x0 = rect.x() if rect.width() > 0 else rect.x() - width
        y0 = rect.y() if rect.height() > 0 else rect.y() - height

        self.setRect(x0, y0, width, height)
        self.update_handles_pos()
class Example(QtGui.QWidget):
    
    def __init__(self):
        global has_midi
        self.mrotation = 0
        self.mtranslate = QPointF(0.0,0.0)
        self.mscale = QPointF(1.0,1.0)
        self.dof = -2.0
        self.epx = 0.5
        self.ppx = 0.6
        self.ppy = 0.0

        self.loadFile()
        super(Example, self).__init__()
        if has_midi:
            self.midi = pypm.Input(0)
            self.timer = QtCore.QTimer(self);
            self.timer.timeout.connect(self.timerEvent)
            self.timer.start(100)
        self.initUI()

    def loadFile(self):
        try:
            json_data=open('json_data.txt')
            variables = json.load(json_data)
            json_data.close()

            self.mrotation = variables['mrotation']
            self.mtranslate.setX(variables['mtranslatex'])
            self.mtranslate.setY(variables['mtranslatey'])
            self.mscale.setX(variables['mscalex'])
            self.mscale.setY(variables['mscaley'])
            self.dof = variables['dof']
            self.epx = variables['epx']
            self.ppx = variables['ppx']
            self.ppy = variables['ppy']

        except:
            print "Could not load file"
    
    def saveFile(self):
        data = {}
        data['mrotation'] = self.mrotation
        data['mtranslatex'] = self.mtranslate.x()
        data['mtranslatey'] = self.mtranslate.y()
        data['mscalex'] = self.mscale.x()
        data['mscaley'] = self.mscale.y()
        data['dof'] = self.dof
        data['epx'] = self.epx
        data['ppx'] = self.ppx
        data['ppy'] = self.ppy
          
        try:
            json_data=open('json_data.txt', 'w')
            json_data.write(json.dumps(data))
            json_data.close()
        except:
            print "Could not save file"
        
    def initUI(self):      

        self.setGeometry(300, 300, 500, 500)
        self.setWindowTitle('Transform test')
        self.show()


    def timerEvent(self):
        gotpkg = False
        while True:
            pkg = self.midi.Read(1) 
            if pkg:
                gotpkg = True
                data, counter = pkg[0]
                bank, instrument, value, val2 = data
                if instrument==2:
                    self.mrotation = int(value*2.83)
                if instrument==3:
                    self.mscale.setX(value/75.0)
                    if(self.mscale.x()==0.0):
                        self.mscale.setX(0.001)
                if instrument==4:
                    self.mscale.setY((value/127.0)**1.25)
                    if(self.mscale.y()==0.0):
                        self.mscale.setY(0.001)
                if instrument==15:
                    self.mtranslate.setX((value/32.0)-2.0)
                if instrument==16:
                    self.mtranslate.setY((value/32.0)-2.0)
                if instrument==5:
                    self.epx = (value/20.0)-1.75
                if instrument==17:
                    self.dof = value/-32.0
                    if(self.dof==0.0):
                        self.dof = 0.001
                if instrument==6:
                    self.ppx = (value/20.0)-1.75
                if instrument==18:
                    self.ppy = value/-32.0
                    if(self.ppy==0.0):
                        self.ppy = 0.001
                print bank,instrument,value, int(value*7.88)
            else:
                break
        if gotpkg:
            self.repaint()
        
    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()
        
    def drawText(self, event, qp):
      
        qp.setPen(QtGui.QColor(168, 34, 3))
        qp.setFont(QtGui.QFont('Decorative', 10))
        qp.drawText(event.rect(), QtCore.Qt.AlignCenter, self.text)