示例#1
0
 def shape(self):
     path = QPainterPath()
     x0, x1, h = 20, 15, 150
     path.addPolygon(QPolygonF([QPointF(-x0, 0), QPointF(x0, 0),
                                QPointF(x1, -h), QPointF(-x1, -h)]))
     path.closeSubpath()
     return path
示例#2
0
    def paintEvent(self, event):
        w, h = self.width * self._scale, self.height * self._scale
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setPen(QColor('black'))
        painter.setBrush(_white)
        painter.drawRect(1, 1, w, h)

        # determine positions
        beam = QPolygonF([QPointF(4, 5)])
        i = 0
        for k in [
                'nok0', 'shutter_gamma', 'nok2', 'nok3', 'nok4', 'nok5a',
                'nok5b', 'nok6', 'nok7', 'nok8'
        ]:
            v = self.values[k]
            if isinstance(v, (tuple, readonlylist)):
                x, y = v  # pylint: disable=W0633
            elif isinstance(v, int):
                x, y = 0, v
            else:
                raise Exception('%r' % type(v))
            p = self._calculatePoint(i, x, y)
            beam.append(QPointF(p[0], p[1]))
            i += 1
        x, y = self.values['nok8']
        p = self._calculatePoint(i + 1, x, y)

        painter.setPen(beambackgroundpen)
        painter.drawPolyline(beam)

        # draw beam
        painter.setPen(beampen)
        painter.drawPolyline(beam)
示例#3
0
 def shape(self):
     path = QPainterPath()
     y0, y1, _l = 12, 2, 250
     path.addPolygon(
         QPolygonF([
             QPointF(0, -y0),
             QPointF(0, y0),
             QPointF(_l, y0),
             QPointF(_l, -y1)
         ]))
     path.closeSubpath()
     return path
示例#4
0
文件: sample.py 项目: ess-dmsc/nicos
 def __init__(self, x, y, size=20, parent=None, scene=None):
     if parent:
         self._color = parent._color
     TableBase.__init__(self, x, y, size, parent, scene)
     if not self._pencolor:
         self._pencolor = QColor('#666666')
     self._pen = QPen(self._pencolor, 1)
     self._pen.setBrush(QBrush(self._pencolor))
     sz = size / 3
     self._polygon = QGraphicsRectItem(
         QRectF(-QPointF(sz, sz), QPointF(sz, sz)), self)
     self._polygon.setBrush(QBrush(self._pencolor))
     self._l1 = QGraphicsLineItem(-size, 0, size, 0, self)
     self._l1.setPen(self._pen)
     self._l2 = QGraphicsLineItem(0, -size, 0, size, self)
     self._l2.setPen(self._pen)
示例#5
0
    def shape(self):
        aoffs = 5  # additional angle for the inner arc
        path = QPainterPath()

        # draw inner circle of the detector box
        path.arcMoveTo(self.circle1, self.startAngle - aoffs)
        path.arcTo(self.circle1, self.startAngle - aoffs,
                   self.spanAngle + 2 * aoffs)

        # draw outer circle of the detector box
        path.arcMoveTo(self.circle2, self.startAngle)
        path.arcTo(self.circle2, self.startAngle, self.spanAngle)

        # calculate left inner point of the box
        tmpLine = QLineF(QPointF(0, 0), QPointF(-self.radius1, 0))
        tmpLine.setAngle(tmpLine.angle() + aoffs)

        # draw left line
        path.addPolygon(QPolygonF([tmpLine.p2(),
                                   QPointF(-self.radius2, 0)]))

        # calculate right inner point of the box
        tmpLine = QLineF(QPointF(0, 0), QPointF(-self.radius1, 0))
        tmpLine.setAngle(self.startAngle - aoffs)

        # calculate right outer point of the box
        line2 = QLineF(QPointF(0, 0), QPointF(-self.radius2, 0))
        line2.setAngle(self.startAngle)

        # draw right line of the box
        path.addPolygon(QPolygonF([tmpLine.p2(), line2.p2()]))
        return path
示例#6
0
 def __init__(self, x, y, size=20, parent=None, scene=None):
     TableBase.__init__(self, x, y, size, parent, scene)
     self._halowidth = max(size / 4, 10)
     self._halo = Halo(x, y, size, self._halowidth, self, scene)
     self._tuberadius = size / 5
     p = QPointF(self._tuberadius, self._tuberadius)
     s = QSizeF(2 * self._tuberadius, 2 * self._tuberadius)
     self._tube = QGraphicsEllipseItem(QRectF(-p, s), self)
     self._tube.setPen(QPen(QColor('black'), 3))
     self._tube.setBrush(QBrush(QColor('white')))
     self._tube.setZValue(20)
示例#7
0
文件: tube.py 项目: umithardal/nicos
 def __init__(self, parent=None, scene=None):
     QGraphicsPathItem.__init__(self, parent)
     self.setPath(self.shape())
     transform = QTransform()
     transform.translate(0, -60)
     self.setTransform(transform)
     self.setTransformOriginPoint(QPointF(0, 50))
     if not parent and scene:
         scene.addItem(self)
     self._halo = TubeHalo(10, self, scene)
     self.setState(status.OK)
示例#8
0
    def __init__(self,
                 point1=QPointF(0, 0),
                 point2=QPointF(0, 1),
                 point3=QPointF(1, 1)):
        lineBC = QLineF(point2, point3)
        lineAC = QLineF(point1, point3)
        lineBA = QLineF(point2, point1)

        rad = abs(lineBC.length() / (2 * sin(radians(lineAC.angleTo(lineBA)))))

        bisectorBC = QLineF(lineBC.pointAt(0.5), lineBC.p2())
        bisectorBC.setAngle(lineBC.normalVector().angle())

        bisectorBA = QLineF(lineBA.pointAt(0.5), lineBA.p2())
        bisectorBA.setAngle(lineBA.normalVector().angle())
        center = QPointF()
        bisectorBA.intersect(bisectorBC, center)

        self.circle = QRectF(center.x() - rad,
                             center.y() - rad, 2 * rad, 2 * rad)

        lineOA = QLineF(center, point1)
        lineOB = QLineF(center, point2)
        lineOC = QLineF(center, point2)

        startAngle = lineOA.angle()
        spanAngle = lineOA.angleTo(lineOC)
        # Make sure that the span angle covers all three points with the second
        # point in the middle
        if abs(spanAngle) < abs(lineOA.angleTo(lineOB)) or \
           abs(spanAngle) < abs(lineOB.angleTo(lineOC)):
            # swap the end point and invert the spanAngle
            startAngle = lineOC.angle()
            spanAngle = 360 - self.spanAngle
        ArcGraphicsItem.__init__(self, center.x(), center.y(), rad, startAngle,
                                 spanAngle)
示例#9
0
 def setPos(self, x, y=None):
     point = x if isinstance(x, QPointF) else QPointF(x, y)
     Crystal.setPos(self, point)
示例#10
0
文件: tas.py 项目: umithardal/nicos
    def paintEvent(self, event):
        s = self.size()
        w, h = s.width(), s.height()
        # calculate the maximum length if all elements in a line
        maxL = self.values['Lms'] + self.values['Lsa'] + self.values['Lad']
        # add the size of the Monochromator and detector
        scale = min((w / 2 - anaradius) / float(maxL),
                    (h - monoradius - anaradius) / float(maxL))

        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)

        painter.setPen(QColor('black'))
        painter.setBrush(_white)
        painter.drawRect(0, 0, w, h)

        # determine positions

        # incoming beam
        if self.values['mth'] < 0:
            bx, by = 3, h - (2 + monoradius)
        else:
            bx, by = 3, 2 + monoradius
        # monochromator
        mx, my = w / 2., by

        # sample
        L = self.values['Lms'] * scale  # length is in mm -- scale down a bit
        mttangle = self.values['mtt'] * deg2rad
        mttangle_t = self.targets['mtt'] * deg2rad
        if self.values['mth'] < 0:
            mttangle = -mttangle
            mttangle_t = -mttangle_t

        sx, sy = mx + L * cos(mttangle), my - L * sin(mttangle)
        sx_t, sy_t = mx + L * cos(mttangle_t), my - L * sin(mttangle_t)

        # analyzer
        L = self.values['Lsa'] * scale  # length is in mm -- scale down a bit
        sttangle = self.values['stt'] * deg2rad
        sttangle_t = self.targets['stt'] * deg2rad
        if self.values['sth'] < 0:
            sttangle = mttangle - sttangle
            sttangle_t = mttangle_t - sttangle_t
        else:
            sttangle = mttangle + sttangle
            sttangle_t = mttangle_t + sttangle_t
        ax, ay = sx + L * cos(sttangle), sy - L * sin(sttangle)
        ax_t, ay_t = sx_t + L * cos(sttangle_t), sy_t - L * sin(sttangle_t)

        # detector
        L = self.values['Lad'] * scale  # length is in mm -- scale down a bit
        attangle = self.values['att'] * deg2rad
        attangle_t = self.targets['att'] * deg2rad
        if self.values['ath'] < 0:
            attangle = sttangle - attangle
            attangle_t = sttangle_t - attangle_t
        else:
            attangle = sttangle + attangle
            attangle_t = sttangle_t + attangle_t

        dx, dy = ax + L * cos(attangle), ay - L * sin(attangle)
        dx_t, dy_t = ax_t + L * cos(attangle_t), ay_t - L * sin(attangle_t)

        # draw table "halos"
        painter.setPen(nopen)
        if self.status['mth'] != OK:
            painter.setBrush(statusbrush[self.status['mth']])
            painter.drawEllipse(QPoint(mx, my), monoradius + halowidth,
                                monoradius + halowidth)
        elif self.status['mtt'] != OK:
            painter.setBrush(statusbrush[self.status['mtt']])
            painter.drawEllipse(QPoint(mx, my), monoradius + halowidth,
                                monoradius + halowidth)
        if self.status['sth'] != OK:
            painter.setBrush(statusbrush[self.status['sth']])
            painter.drawEllipse(QPoint(sx, sy), sampleradius + halowidth,
                                sampleradius + halowidth)
        elif self.status['stt'] != OK:
            painter.setBrush(statusbrush[self.status['stt']])
            painter.drawEllipse(QPoint(sx, sy), sampleradius + halowidth,
                                sampleradius + halowidth)
        if self.status['ath'] != OK:
            painter.setBrush(statusbrush[self.status['ath']])
            painter.drawEllipse(QPoint(ax, ay), anaradius + halowidth,
                                anaradius + halowidth)
        elif self.status['att'] != OK:
            painter.setBrush(statusbrush[self.status['att']])
            painter.drawEllipse(QPoint(ax, ay), anaradius + halowidth,
                                anaradius + halowidth)

        # draw table targets
        painter.setPen(targetpen)
        painter.setBrush(_nobrush)
        painter.drawEllipse(QPoint(sx_t, sy_t), sampleradius - .5,
                            sampleradius - .5)
        painter.drawEllipse(QPoint(ax_t, ay_t), anaradius - .5, anaradius - .5)
        painter.drawEllipse(QPoint(dx_t, dy_t), detradius - .5, detradius - .5)

        # draw the tables
        painter.setPen(defaultpen)
        painter.setBrush(monotablebrush)
        painter.drawEllipse(QPoint(mx, my), monoradius, monoradius)
        painter.setBrush(sampletablebrush)
        painter.drawEllipse(QPoint(sx, sy), sampleradius, sampleradius)
        painter.setBrush(anatablebrush)
        painter.drawEllipse(QPoint(ax, ay), anaradius, anaradius)
        painter.setBrush(dettablebrush)
        painter.drawEllipse(QPoint(dx, dy), detradius, detradius)
        painter.setBrush(_white)
        painter.setPen(nopen)
        painter.drawEllipse(QPoint(mx, my), monoradius / 2, monoradius / 2)
        # painter.drawEllipse(QPoint(sx, sy), 20, 20)
        painter.drawEllipse(QPoint(ax, ay), anaradius / 2, anaradius / 2)
        # painter.drawEllipse(QPoint(dx, dy), 20, 20)

        beam = QPolygonF([
            QPointF(bx, by),
            QPointF(mx, my),
            QPointF(sx, sy),
            QPointF(ax, ay),
            QPointF(dx, dy)
        ])
        painter.setPen(beambackgroundpen)
        painter.drawPolyline(beam)

        # draw mono crystals
        painter.setPen(monopen)
        mthangle = -self.values['mth'] * deg2rad
        painter.drawLine(mx + 10 * cos(mthangle), my - 10 * sin(mthangle),
                         mx - 10 * cos(mthangle), my + 10 * sin(mthangle))

        # draw ana crystals
        athangle = -self.values['ath'] * deg2rad
        alpha = athangle + sttangle
        # TODO if the angle is too small then it could be that the ath value
        # must be turned by 90 deg (PANDA: chair setup) ??
        if attangle < 0 and alpha < attangle:
            alpha += pi_2
        painter.drawLine(ax + 10 * cos(alpha), ay - 10 * sin(alpha),
                         ax - 10 * cos(alpha), ay + 10 * sin(alpha))

        # draw sample
        painter.setPen(samplepen)
        painter.setBrush(samplebrush)
        sthangle = self.values['sth'] * deg2rad
        alpha = sthangle + mttangle + pi_4
        # painter.drawRect(sx - 5, sy - 5, 10, 10)
        sz = 10
        painter.drawPolygon(
            QPolygonF([
                QPointF(sx + sz * cos(alpha), sy - sz * sin(alpha)),
                QPointF(sx + sz * cos(alpha + pi_2),
                        sy - sz * sin(alpha + pi_2)),
                QPointF(sx - sz * cos(alpha), sy + sz * sin(alpha)),
                QPointF(sx - sz * cos(alpha + pi_2),
                        sy + sz * sin(alpha + pi_2)),
                QPointF(sx + sz * cos(alpha), sy - sz * sin(alpha))
            ]))

        painter.setPen(samplecoordpen)
        sr = sampleradius
        for angle in [alpha - pi_4, alpha - 3 * pi_4]:
            painter.drawLine(sx - sr * cos(angle), sy + sr * sin(angle),
                             sx + sr * cos(angle), sy - sr * sin(angle))

        # draw detector
        painter.setPen(monopen)
        painter.setBrush(_white)
        painter.drawEllipse(QPoint(dx, dy), 4, 4)

        # draw beam
        painter.setPen(beampen)
        painter.drawPolyline(beam)
示例#11
0
 def setPos(self, x, y=None):
     point = x if isinstance(x, QPointF) else QPointF(x, y)
     QGraphicsItemGroup.setPos(self, point)