class OrbitCorrDlg(QDialog): 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) # draw the target orbit #self.bpm_plots[0].plotCurve2(self.val[1], self.val[0]) #self.bpm_plots[1].plotCurve2(self.val[2], self.val[0]) #self.connect(self.qdb, SIGNAL("clicked(QAbstractButton)"), self._action) #self.connect(self.qdb, SIGNAL("helpRequested()"), self._help) #def _cell_clicked(self, row, col): # print row, col def _update_orbit_plot(self, xobt, yobt): sx, vx = xobt sy, vy = yobt self.xc.setData(sx, vx) self.yc.setData(sy, vy) self.bpm_plot.replot() def _cheat(self): s = catools.caget('V:2-SR-BI{POS}-I') x = catools.caget('V:2-SR-BI{ORBIT}X-I') y = catools.caget('V:2-SR-BI{ORBIT}Y-I') p = self.bpm_plot p._cheat[0].setData(s, x) p._cheat[1].setData(s, y) p.showCurve(p._cheat[0], True) p.showCurve(p._cheat[1], True) p.replot() def _zoom_in_cors(self, corls): mks = [(c.name, c.sb) for c in corls] s0 = min([c.sb for c in corls]) s1 = max([c.se for c in corls]) ds = (s1 - s0) / 10.0 self.bpm_plot.setMarkers(mks) self.bpm_plot.setAxisScale(Qwt.QwtPlot.xBottom, s0-ds, s1+ds) self.bpm_plot.replot() self.cor_plot.setMarkers(mks) self.cor_plot.replot() self.tw_plot.setMarkers(mks) self.tw_plot.replot() def _clear_cors(self, corls): self.bpm_plot.setMarkers([]) self.bpm_plot.replot() self.cor_plot.setMarkers([]) self.cor_plot.replot() self.tw_plot.setMarkers([]) self.tw_plot.replot() def _help(self): print("HELP") #def done(self, r): # #for p in self.bpm_plots: # # p.plotCurve2(None, None)# # # QDialog.done(self, r) def _action(self, btn): #role = self.qdb.buttonRole(btn) #print "Role:", role #if role == QDialogButtonBox.ApplyRole: # self.call_apply() #elif role == QDialogButtonBox.RejectRole: # self.reject() pass def closeEvent(self, e): self.bpm_plot.close() self.cor_plot.close() self.tw_plot.close() e.accept()
class OrbitCorrDlg(QDialog): 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) # draw the target orbit #self.bpm_plots[0].plotCurve2(self.val[1], self.val[0]) #self.bpm_plots[1].plotCurve2(self.val[2], self.val[0]) #self.connect(self.qdb, SIGNAL("clicked(QAbstractButton)"), self._action) #self.connect(self.qdb, SIGNAL("helpRequested()"), self._help) #def _cell_clicked(self, row, col): # print row, col def _update_orbit_plot(self, xobt, yobt): sx, vx = xobt sy, vy = yobt self.xc.setData(sx, vx) self.yc.setData(sy, vy) self.bpm_plot.replot() def _cheat(self): s = catools.caget('V:2-SR-BI{POS}-I') x = catools.caget('V:2-SR-BI{ORBIT}X-I') y = catools.caget('V:2-SR-BI{ORBIT}Y-I') p = self.bpm_plot p._cheat[0].setData(s, x) p._cheat[1].setData(s, y) p.showCurve(p._cheat[0], True) p.showCurve(p._cheat[1], True) p.replot() def _zoom_in_cors(self, corls): mks = [(c.name, c.sb) for c in corls] s0 = min([c.sb for c in corls]) s1 = max([c.se for c in corls]) ds = (s1 - s0) / 10.0 self.bpm_plot.setMarkers(mks) self.bpm_plot.setAxisScale(Qwt.QwtPlot.xBottom, s0-ds, s1+ds) self.bpm_plot.replot() self.cor_plot.setMarkers(mks) self.cor_plot.replot() self.tw_plot.setMarkers(mks) self.tw_plot.replot() def _clear_cors(self, corls): self.bpm_plot.setMarkers([]) self.bpm_plot.replot() self.cor_plot.setMarkers([]) self.cor_plot.replot() self.tw_plot.setMarkers([]) self.tw_plot.replot() def _help(self): print "HELP" #def done(self, r): # #for p in self.bpm_plots: # # p.plotCurve2(None, None)# # # QDialog.done(self, r) def _action(self, btn): #role = self.qdb.buttonRole(btn) #print "Role:", role #if role == QDialogButtonBox.ApplyRole: # self.call_apply() #elif role == QDialogButtonBox.RejectRole: # self.reject() pass def closeEvent(self, e): self.bpm_plot.close() self.cor_plot.close() self.tw_plot.close() e.accept()