示例#1
0
    def __init__(self, bpms = None, cors = None, parent = None):
        super(OrbitCorrDlg, self).__init__(parent)
        # add bpms
        bpmls = bpms
        if bpms is None:
            bpmls = getElements("BPM")
        bpmls = [bpm for bpm in bpmls if bpm.isEnabled()]
        pvx = [bpm.pv(field="x", handle="readback")[0] for bpm in bpmls]
        pvy = [bpm.pv(field="y", handle="readback")[0] for bpm in bpmls]
        #
        #self._update_current_orbit()

        s = [bpm.sb for bpm in bpmls]
        self.bpm_plot = ApCaArrayPlot([pvx, pvy], x = [s, s])
        magprof = getBeamlineProfile()
        self.bpm_plot.setMagnetProfile(magprof)

        self.xc = Qwt.QwtPlotCurve()
        self.xc.setTitle("Target X")
        self.xc.attach(self.bpm_plot)
        #self.xc.setData(s, self.x0)
        self.bpm_plot.showCurve(self.xc, True)

        self.yc = Qwt.QwtPlotCurve()
        self.yc.setTitle("Target Y")
        self.yc.attach(self.bpm_plot)
        #self.yc.setData(s, self.y0)
        self.bpm_plot.showCurve(self.yc, True)

        #self.bpm_plot._cheat = [Qwt.QwtPlotCurve(), Qwt.QwtPlotCurve()]
        #self.bpm_plot._cheat[0].setTitle("_CHEAT_ X")
        #self.bpm_plot._cheat[1].setTitle("_CHEAT_ Y")
        #self.bpm_plot._cheat[0].attach(self.bpm_plot)
        #self.bpm_plot._cheat[1].attach(self.bpm_plot)
        #self.bpm_plot._set_symbol(self.bpm_plot._cheat[0],
        #                          Qwt.QwtSymbol.Triangle, dsize=2)
        #self.bpm_plot._set_symbol(self.bpm_plot._cheat[1],
        #                          Qwt.QwtSymbol.Diamond, dsize=2)
        #self.bpm_plot.showCurve(self.bpm_plot._cheat[0], False)
        #self.bpm_plot.showCurve(self.bpm_plot._cheat[1], False)
        self.bpm_plot.setContentsMargins(12, 10, 10, 10)

        # add corrector plots
        corls = cors
        if cors is None:
            corls = []
            for c in getElements("HCOR") + getElements("VCOR"):
                if c not in corls:
                    corls.append(c)
        pvx = [c.pv(field="x", handle="setpoint")[0]
               for c in getElements("HCOR") if c in corls]
        pvy = [c.pv(field="y", handle="setpoint")[0]
               for c in getElements("VCOR") if c in corls]
        s = [c.sb for c in corls]
        self.cor_plot = ApCaArrayPlot([pvx, pvy], x = [s, s],
                                      labels=["HCOR Sp", "VCOR Sp"])
        #magprof = aphla.getBeamlineProfile()
        self.cor_plot.setMagnetProfile(magprof)
        self.cor_plot.setContentsMargins(12, 10, 10, 10)
        #self.cor_plot.setMinimumHeight(200)
        #self.cor_plot.setMaximumHeight(250)
        #print s, pvx

        # add twiss plots
        self._twiss = getTwiss("*", ["s", "betax", "betay", "etax"])
        #for i in range(len(self._twiss)):
        #    print i, self._twiss[i,0], self._twiss[i,1]

        self.tw_plot = ApCaPlot()
        cbetax = Qwt.QwtPlotCurve()
        pen = cbetax.pen()
        pen.setColor(Qt.red)
        cbetax.setPen(pen)
        cbetay = Qwt.QwtPlotCurve()
        pen.setColor(Qt.green)
        cbetay.setPen(pen)
        cetax  = Qwt.QwtPlotCurve()
        pen.setColor(Qt.blue)
        cetax.setPen(pen)
        cbetax.setData(self._twiss[:,0], self._twiss[:,1])
        cbetay.setData(self._twiss[:,0], self._twiss[:,2])
        cetax.setData(self._twiss[:,0], 10.0*self._twiss[:,3])
        cbetax.attach(self.tw_plot)
        cbetax.setTitle("Beta X")
        cbetay.attach(self.tw_plot)
        cbetay.setTitle("Beta Y")
        cetax.attach( self.tw_plot)
        cetax.setTitle("10*Eta X")
        self.tw_plot.setMagnetProfile(magprof)
        self.tw_plot.setContentsMargins(12, 10, 10, 10)
        self.tw_plot.showCurve(cbetax, True)
        self.tw_plot.showCurve(cbetay, True)
        self.tw_plot.showCurve(cetax, True)

        # top tabs for plotting
        tabs = QtGui.QTabWidget()
        tabs.addTab(self.bpm_plot, "Orbit")
        tabs.addTab(self.cor_plot, "Correctors")
        tabs.addTab(self.tw_plot, "Twiss (Design)")
        tabs.setMinimumHeight(200)
        tabs.setMaximumHeight(280)

        layout = QVBoxLayout()
        layout.addWidget(tabs, 1)

        tabs = QtGui.QTabWidget()
        tab_general_cor = OrbitCorrGeneral(bpmls, corls)
        self.connect(tab_general_cor,
                     SIGNAL("targetOrbitChanged(PyQt_PyObject, PyQt_PyObject)"),
                     self._update_orbit_plot)
        xobt, yobt = tab_general_cor.getTargetOrbit()
        self._update_orbit_plot(xobt, yobt)
        tabs.addTab(tab_general_cor, "General Bump")

        tab_bump3xcor = Bump3XCor(corls, "x")
        tab_bump3xsrc = Bump3XSrc(corls, "x")
        tab_bump4xcor = Bump4XCor(corls, "x")
        tab_bump4xsrc = Bump4XSrc(corls, "x")
        #plots=[self.bpm_plot, self.cor_plot, self.tw_plot])
        #self.connect(tab_nbump_cor,
        #             SIGNAL("correctorChanged(PyQt_PyObject)"),
        #             self._update_corr_plot)
        tabs.addTab(tab_bump3xcor, "3 Cors. dI")
        tabs.addTab(tab_bump3xsrc, "3 Cors. dX")
        tabs.addTab(tab_bump4xcor, "4 Cors. dI")
        tabs.addTab(tab_bump4xsrc, "4 Cors. dX dTheta")
        layout.addWidget(tabs, 3)

        self.connect(tab_bump3xcor, SIGNAL("zoomInCorrectors(PyQt_PyObject)"),
                     self._zoom_in_cors)
        self.connect(tab_bump3xsrc, SIGNAL("zoomInCorrectors(PyQt_PyObject)"),
                     self._zoom_in_cors)
        self.connect(tab_bump4xcor, SIGNAL("zoomInCorrectors(PyQt_PyObject)"),
                     self._zoom_in_cors)
        self.connect(tab_bump4xsrc, SIGNAL("zoomInCorrectors(PyQt_PyObject)"),
                     self._zoom_in_cors)

        self.connect(tab_bump3xcor, SIGNAL("clearCorrectors(PyQt_PyObject)"),
                     self._clear_cors)
        self.connect(tab_bump3xsrc, SIGNAL("clearCorrectors(PyQt_PyObject)"),
                     self._clear_cors)
        self.connect(tab_bump4xcor, SIGNAL("clearCorrectors(PyQt_PyObject)"),
                     self._clear_cors)
        self.connect(tab_bump4xsrc, SIGNAL("clearCorrectors(PyQt_PyObject)"),
                     self._clear_cors)

        #hln = QtGui.QFrame()
        #hln.setLineWidth(3)
        #hln.setFrameStyle(QtGui.QFrame.Sunken)
        #hln.setFrameShape(QtGui.QFrame.HLine)
        #layout.addWidget(hln)

        # the cheat button
        #hbox = QHBoxLayout()
        #hbox.addStretch()
        #btn = QPushButton("__CHEAT__")
        #self.connect(btn, SIGNAL("clicked()"), self._cheat)
        #hbox.addWidget(btn)
        #layout.addLayout(hbox)

        self.setLayout(layout)
        #self.update_orbit = update_orbit
        #self._x0 = tuple(x)  # save for reset
        #self._y0 = tuple(y)  # save for reset
        #self.val = [s, x, y]
        self.setMinimumWidth(1000)
        self.setWindowFlags(Qt.Window)