コード例 #1
0
ファイル: monitorwidgets.py プロジェクト: umithardal/nicos
    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)
コード例 #2
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)