Commit 014c4b18 authored by Zhang, Tong's avatar Zhang, Tong
Browse files

Merge branch 'devel' into 'master'

Monitor selector and drawing updates

See merge request !7
parents 90fbbd52 91e297c6
......@@ -81,6 +81,9 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
self.last_bs = None
self.fm = None
# initial elemlist_cbb
self.init_elemlist()
# envelope curves
o = self.envelope_plot
o.add_curve()
......@@ -91,6 +94,12 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
o.setLineColor(QColor('#FF0000'))
o.setLineLabel("$\sigma_y$")
# update drawing
self.quad1_grad_dsbox.valueChanged.emit(self.quad1_grad_dsbox.value())
# reset current selected element with the last element
self.elemlist_cbb.setCurrentIndex(self.elemlist_cbb.count() - 1)
self.elemlist_cbb.currentTextChanged.emit(self.elemlist_cbb.currentText())
@pyqtSlot('QString')
def on_quad1_name_changed(self, name: str) -> None:
"""When the current selected quad name is changed, do:
......@@ -125,8 +134,11 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
# update simulation
ARIS_LAT.sync_settings()
_, fm = ARIS_LAT.run()
self.results, self.last_bs = fm.run(monitor='all')
self.fm = fm
self.results, _ = fm.run(monitor='all')
r, _ = fm.run(monitor=[self.elemlist_cbb.currentText()])
if r != []:
self.last_bs = r[0][-1]
# update drawing
self.update_drawing()
......@@ -188,16 +200,46 @@ class MyAppWindow(BaseAppForm, Ui_MainWindow):
anote=False)
def _plot_ellipse(self, figure_obj, params, **kws):
xoy = kws.get('xoy', 'x')
xlbl = f"{xoy} [mm]"
ylbl = f"{xoy}' [mrad]"
figure_obj.clear_figure()
draw_beam_ellipse_with_params(params,
ax=figure_obj.axes,
color=kws.get('color', 'b'),
factor=kws.get('factor', 4),
xoy=kws.get('xoy', 'x'),
xoy=xoy,
fill=kws.get('fill', 'g'),
anote=kws.get('anote', False))
figure_obj.setFigureXlabel(xlbl)
figure_obj.setFigureYlabel(ylbl)
figure_obj.update_figure()
def init_elemlist(self):
#
# this should be called after machine/segment is changed
# now only work with ARIS/F1, todo in the future with LatticeWidget
#
ename_list = [i.name for i in ARIS_LAT]
self.elemlist_cbb.addItems(ename_list)
self.elemlist_cbb.currentTextChanged.connect(self.on_target_element_changed)
@pyqtSlot('QString')
def on_target_element_changed(self, ename: str):
"""Get beam state result after the selected element from FLAME model.
"""
elem = ARIS_LAT[ename]
self.family_lineEdit.setText(elem.family)
self.pos_lineEdit.setText(f"{elem.sb:.3f} m")
r, _ = self.fm.run(monitor=[ename])
if r == []:
QMessageBox.warning(self, "Select Element",
"Selected element cannot be located in model, probably for splitable element, select the closest one.",
QMessageBox.Ok, QMessageBox.Ok)
return
self.last_bs = r[0][-1]
self.draw_ellipse()
if __name__ == "__main__":
from PyQt5.QtWidgets import QApplication
......
......@@ -12,7 +12,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1381, 641)
MainWindow.resize(1341, 687)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icons/default.png"),
QtGui.QIcon.Normal, QtGui.QIcon.Off)
......@@ -21,12 +21,72 @@ class Ui_MainWindow(object):
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.quad1_name_cbb = QtWidgets.QComboBox(self.centralwidget)
self.quad1_name_cbb.setObjectName("quad1_name_cbb")
self.horizontalLayout.addWidget(self.quad1_name_cbb)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.quad1_grad_dsbox = QtWidgets.QDoubleSpinBox(self.centralwidget)
self.quad1_grad_dsbox.setDecimals(3)
self.quad1_grad_dsbox.setMinimum(-200.0)
self.quad1_grad_dsbox.setMaximum(200.0)
self.quad1_grad_dsbox.setObjectName("quad1_grad_dsbox")
self.horizontalLayout.addWidget(self.quad1_grad_dsbox)
self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1)
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.tab)
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.tab)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label_3 = QtWidgets.QLabel(self.tab)
self.label_3.setObjectName("label_3")
self.horizontalLayout_2.addWidget(self.label_3)
self.elemlist_cbb = QtWidgets.QComboBox(self.tab)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred,
QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.elemlist_cbb.sizePolicy().hasHeightForWidth())
self.elemlist_cbb.setSizePolicy(sizePolicy)
self.elemlist_cbb.setObjectName("elemlist_cbb")
self.horizontalLayout_2.addWidget(self.elemlist_cbb)
self.pos_lineEdit = QtWidgets.QLineEdit(self.tab)
self.pos_lineEdit.setReadOnly(True)
self.pos_lineEdit.setObjectName("pos_lineEdit")
self.horizontalLayout_2.addWidget(self.pos_lineEdit)
self.family_lineEdit = QtWidgets.QLineEdit(self.tab)
self.family_lineEdit.setReadOnly(True)
self.family_lineEdit.setObjectName("family_lineEdit")
self.horizontalLayout_2.addWidget(self.family_lineEdit)
self.verticalLayout_3.addLayout(self.horizontalLayout_2)
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.verticalLayout = QtWidgets.QVBoxLayout()
self.verticalLayout.setObjectName("verticalLayout")
self.x_ellipse_plot = MatplotlibBaseWidget(self.tab)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Fixed)
......@@ -59,7 +119,10 @@ class Ui_MainWindow(object):
self.x_ellipse_plot.setFigureXYticksFont(font)
self.x_ellipse_plot.setProperty("figureToolbarToggle", False)
self.x_ellipse_plot.setObjectName("x_ellipse_plot")
self.horizontalLayout_2.addWidget(self.x_ellipse_plot)
self.verticalLayout.addWidget(self.x_ellipse_plot)
self.horizontalLayout_4.addLayout(self.verticalLayout)
self.verticalLayout_2 = QtWidgets.QVBoxLayout()
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.y_ellipse_plot = MatplotlibBaseWidget(self.tab)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Fixed)
......@@ -91,13 +154,16 @@ class Ui_MainWindow(object):
self.y_ellipse_plot.setFigureXYticksFont(font)
self.y_ellipse_plot.setProperty("figureToolbarToggle", False)
self.y_ellipse_plot.setObjectName("y_ellipse_plot")
self.horizontalLayout_2.addWidget(self.y_ellipse_plot)
self.verticalLayout_2.addWidget(self.y_ellipse_plot)
self.horizontalLayout_4.addLayout(self.verticalLayout_2)
self.verticalLayout_3.addLayout(self.horizontalLayout_4)
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.tab_2)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.envelope_plot = MatplotlibCurveWidget(self.tab_2)
self.envelope_plot.setFigureAutoScale(True)
font = QtGui.QFont()
font.setFamily("sans-serif")
font.setPointSize(14)
......@@ -110,39 +176,9 @@ class Ui_MainWindow(object):
self.horizontalLayout_3.addWidget(self.envelope_plot)
self.tabWidget.addTab(self.tab_2, "")
self.gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.quad1_name_cbb = QtWidgets.QComboBox(self.centralwidget)
self.quad1_name_cbb.setObjectName("quad1_name_cbb")
self.horizontalLayout.addWidget(self.quad1_name_cbb)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(
self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setObjectName("label_2")
self.horizontalLayout.addWidget(self.label_2)
self.quad1_grad_dsbox = QtWidgets.QDoubleSpinBox(self.centralwidget)
self.quad1_grad_dsbox.setDecimals(3)
self.quad1_grad_dsbox.setObjectName("quad1_grad_dsbox")
self.horizontalLayout.addWidget(self.quad1_grad_dsbox)
self.gridLayout.addLayout(self.horizontalLayout, 1, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1381, 30))
self.menubar.setGeometry(QtCore.QRect(0, 0, 1341, 30))
self.menubar.setObjectName("menubar")
self.menu_File = QtWidgets.QMenu(self.menubar)
self.menu_File.setObjectName("menu_File")
......@@ -175,6 +211,10 @@ class Ui_MainWindow(object):
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label.setText(_translate("MainWindow", "Select quadrupole"))
self.label_2.setText(_translate("MainWindow", "Gradient Setting"))
self.quad1_grad_dsbox.setSuffix(_translate("MainWindow", " T/m"))
self.label_3.setText(_translate("MainWindow", "Show results after"))
self.x_ellipse_plot.setFigureXlabel(_translate("MainWindow", "X (mm)"))
self.x_ellipse_plot.setFigureYlabel(
_translate("MainWindow", "X\' (mrad)"))
......@@ -188,9 +228,6 @@ class Ui_MainWindow(object):
_translate("MainWindow", "Envelop [mm]"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2),
_translate("MainWindow", "Beam Envelope"))
self.label.setText(_translate("MainWindow", "Select quadrupole"))
self.label_2.setText(_translate("MainWindow", "Gradient Setting"))
self.quad1_grad_dsbox.setSuffix(_translate("MainWindow", " T/m"))
self.menu_File.setTitle(_translate("MainWindow", "&File"))
self.menu_Help.setTitle(_translate("MainWindow", "&Help"))
self.action_About.setText(_translate("MainWindow", "&About"))
......
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1381</width>
<height>641</height>
<width>1341</width>
<height>687</height>
</rect>
</property>
<property name="windowTitle">
......@@ -19,6 +19,55 @@
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Select quadrupole</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="quad1_name_cbb"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Gradient Setting</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="quad1_grad_dsbox">
<property name="suffix">
<string> T/m</string>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="minimum">
<double>-200.000000000000000</double>
</property>
<property name="maximum">
<double>200.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
......@@ -28,101 +77,148 @@
<attribute name="title">
<string>Beam Ellipse</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="MatplotlibBaseWidget" name="x_ellipse_plot">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="figureXlabel">
<string>X (mm)</string>
</property>
<property name="figureYlabel">
<string>X' (mrad)</string>
</property>
<property name="figureTitle">
<string/>
</property>
<property name="figureXYlabelFont">
<font>
<family>sans-serif</family>
<pointsize>14</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureTitleFont">
<font>
<family>sans-serif</family>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureXYticksFont">
<font>
<family>sans-serif</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureToolbarToggle" stdset="0">
<bool>false</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Show results after</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="elemlist_cbb">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="pos_lineEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="family_lineEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="MatplotlibBaseWidget" name="y_ellipse_plot">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="figureXlabel">
<string>Y (mm)</string>
</property>
<property name="figureYlabel">
<string>Y' (mrad)</string>
</property>
<property name="figureXYlabelFont">
<font>
<family>sans-serif</family>
<pointsize>14</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureTitleFont">
<font>
<family>sans-serif</family>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureXYticksFont">
<font>
<family>sans-serif</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureToolbarToggle" stdset="0">
<bool>false</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="MatplotlibBaseWidget" name="x_ellipse_plot">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="figureXlabel">
<string>X (mm)</string>
</property>
<property name="figureYlabel">
<string>X' (mrad)</string>
</property>
<property name="figureTitle">
<string/>
</property>
<property name="figureXYlabelFont">
<font>
<family>sans-serif</family>
<pointsize>14</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureTitleFont">
<font>
<family>sans-serif</family>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureXYticksFont">
<font>
<family>sans-serif</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureToolbarToggle" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="MatplotlibBaseWidget" name="y_ellipse_plot">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="figureXlabel">
<string>Y (mm)</string>
</property>
<property name="figureYlabel">
<string>Y' (mrad)</string>
</property>
<property name="figureXYlabelFont">
<font>
<family>sans-serif</family>
<pointsize>14</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureTitleFont">
<font>
<family>sans-serif</family>
<pointsize>16</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureXYticksFont">
<font>
<family>sans-serif</family>
<pointsize>12</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
</font>
</property>
<property name="figureToolbarToggle" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
......@@ -133,6 +229,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="MatplotlibCurveWidget" name="envelope_plot">
<property name="figureAutoScale">
<bool>true</bool>
</property>
<property name="figureXlabel">
<string>s [m]</string>
</property>
......@@ -157,49 +256,6 @@
</widget>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Select quadrupole</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="quad1_name_cbb"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Gradient Setting</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="quad1_grad_dsbox">
<property name="suffix">
<string> T/m</string>
</property>
<property name="decimals">