Skip to content

Commit

Permalink
IDFF.ENH: implement improvements in graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
anacso17 committed Nov 1, 2024
1 parent cae865e commit a09bcf8
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 54 deletions.
26 changes: 26 additions & 0 deletions pyqt-apps/siriushla/si_ap_idff/custom_widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"""Custom widgets."""

import numpy as np

from qtpy.QtCore import Qt, Slot

from pydm.widgets import PyDMLineEdit
from pydm.widgets.waveformplot import WaveformCurveItem

from ..as_ap_configdb import LoadConfigDialog as _LoadConfigDialog

Expand All @@ -19,3 +24,24 @@ def _config_changed(self, configname):
self.setText(configname)
self.send_value()
self.value_changed(configname)


class SectionedWaveformCurveItem(WaveformCurveItem):

GAP_MIN = 0 # [mm]
GAP_MAX = 24 # [mm]

def __init__(self, section, **kwargs):
super().__init__(**kwargs)
self.section = section

@Slot(np.ndarray)
def receiveYWaveform(self, new_waveform):
size = len(new_waveform)/4
min = int(size*self.section)
max = int(size*(self.section+1))
ydata = new_waveform[min:max]
npts = len(ydata)
xdata = self.GAP_MIN + (self.GAP_MAX - self.GAP_MIN) * np.arange(0, npts) / (npts - 1)
super().receiveXWaveform(xdata)
super().receiveYWaveform(ydata)
108 changes: 54 additions & 54 deletions pyqt-apps/siriushla/si_ap_idff/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Main window."""

from qtpy.QtCore import Qt, Slot
from time import strftime, localtime

from qtpy.QtCore import Qt
from qtpy.QtWidgets import QLabel, QGridLayout, QSizePolicy as QSzPlcy, \
QWidget, QGroupBox, QHBoxLayout, QVBoxLayout, QPushButton, QSpacerItem, \
QHeaderView, QRadioButton, QButtonGroup, QStackedWidget
QRadioButton, QButtonGroup, QStackedWidget
from qtpy.QtGui import QColor

from time import strftime, localtime
import qtawesome as qta
import numpy as np

from pydm.widgets import PyDMPushButton
from pydm.widgets.waveformplot import WaveformCurveItem

from siriuspy.envars import VACA_PREFIX as _VACA_PREFIX
from siriuspy.namesys import SiriusPVName as _PVName
Expand All @@ -24,24 +25,10 @@
from ..as_ps_control.control_widget.ControlWidgetFactory import \
ControlWidgetFactory
from ..as_ps_control import PSDetailWindow
from .custom_widgets import ConfigLineEdit
from .custom_widgets import ConfigLineEdit, SectionedWaveformCurveItem
from .util import get_idff_icon


class SectionedWaveformCurveItem(WaveformCurveItem):

def __init__(self, section, **kwargs):
super().__init__(**kwargs)
self.section = section

@Slot(np.ndarray)
def receiveYWaveform(self, new_waveform):
size = len(new_waveform)/4
min = int(size*self.section)
max = int(size*(self.section+1))
super().receiveYWaveform(new_waveform[min:max])


class IDFFWindow(SiriusMainWindow):
"""ID FF main window."""

Expand Down Expand Up @@ -90,10 +77,10 @@ def _ivuStatusWidget(self):
gap_val = SiriusLabel(
self, self.dev_pref.substitute(propty='IDPos-Mon'))
gap_val.showUnits = True

hlay.addWidget(lbl_gap)
hlay.addWidget(gap_val)

return gbox

def _format_timestamp_label(self, value):
Expand All @@ -104,23 +91,20 @@ def _ivuSettingsWidget(self):
gbox = QGroupBox('Settings', self)
lay = QGridLayout(gbox)

ld_loopstate = QLabel(
'Loop State: ', self)
ld_loopstate = QLabel('Loop State: ', self)
self.sb_loopstate = PyDMStateButton(
self, self.dev_pref.substitute(propty='LoopState-Sel'))
self.lb_loopstate = SiriusLedState(
self, self.dev_pref.substitute(propty='LoopState-Sts'))

lbl_table_pointer = QLabel(
'Table Pointer: ', self)

lbl_table_pointer = QLabel('Table Pointer: ', self)
self.table_pointer = SiriusLabel(
self, self.dev_pref.substitute(propty='TablePointer-Mon'))

lbl_alarm = QLabel(
'Alarm: ', self)
lbl_alarm = QLabel('Alarm: ', self)
self.alarm_led = SiriusLedState(
self, self.dev_pref.substitute(propty='Alarms-Mon'))

alarm_details = QPushButton('', self)
alarm_details.setIcon(qta.icon('fa5s.list-ul'))
alarm_details.setToolTip('Open Detailed Alarms View')
Expand All @@ -135,42 +119,49 @@ def _ivuSettingsWidget(self):
section='ID', title='FeedForward Status')

self.clear_alarms = PyDMPushButton(
self, "Clear Alarms",
self, "Clear Alarms",
init_channel=self.dev_pref.substitute(propty='ClearFlags-Cmd'))

lbl_plc_counter = QLabel(
'PLC Counter: ', self)
lbl_plc_counter = QLabel('PLC Counter: ', self)
self.plc_counter = SiriusLabel(
self, self.dev_pref.substitute(propty='PLCCounter-Mon'))

lbl_timestamp = QLabel(
'PLC Timestamp: ', self)

lbl_timestamp = QLabel('PLC Timestamp: ', self)
self.timestamp = QLabel('0:00:00', self)
self.timestamp_mon = SiriusConnectionSignal(
self.dev_pref.substitute(propty='PLCTimestamp-Mon'))
self.timestamp_mon.new_value_signal[float].connect(
self._format_timestamp_label)

buttonGroupWid = QWidget()
vlay = QVBoxLayout(buttonGroupWid)
self.button_group = QButtonGroup(buttonGroupWid)
self.button_group.buttonClicked.connect(lambda btn: self.stack.setCurrentIndex(self.button_group.id(btn)))

self.stack = QStackedWidget()
self.plot_dict = {}
for id, name in enumerate(["CH1", "CH2", "CV1", "CV2"]):
for idx, name in enumerate(["CH1", "CH2", "CV1", "CV2"]):
channel_btn = QRadioButton(name)
vlay.addWidget(channel_btn)
self.button_group.addButton(channel_btn, id)
self.button_group.addButton(channel_btn, idx)

if name == "CH1":
channel_btn.setChecked(True)

self.plot_dict[name] = SiriusWaveformPlot()
self.plot_dict[name].setShowLegend(True)
self.addNewTableCurve(self.plot_dict[name], id)
self.stack.addWidget(self.plot_dict[name])

graph = SiriusWaveformPlot()
graph.setShowLegend(True)
graph.autoRangeX = True
graph.autoRangeY = True
graph.showXGrid = True
graph.showYGrid = True
graph.showLegend = True
graph.setLabel('bottom', text='Index')
graph.setLabel('left', text='Current [A]')
graph.setBackgroundColor(QColor(255, 255, 255))
self.addNewTableCurve(graph, name, idx)
self.stack.addWidget(graph)
self.plot_dict[name] = graph

lay.addWidget(ld_loopstate, 0, 0)
lay.addWidget(self.sb_loopstate, 0, 1)
lay.addWidget(self.lb_loopstate, 0, 2)
Expand All @@ -186,25 +177,34 @@ def _ivuSettingsWidget(self):
lay.addWidget(self.timestamp, 5, 1, 1, 2)
lay.addWidget(buttonGroupWid, 6, 0)
lay.addWidget(self.stack, 6, 1, 1, 2)

return gbox

def addNewTableCurve(self, plt, section):
curve1 = SectionedWaveformCurveItem(
def addNewTableCurve(self, plt, name, section):
if 'CH' in name:
color_sp, color_rb = 'blue', 'darkBlue'
else:
color_sp, color_rb = 'red', 'darkRed'

curve_sp = SectionedWaveformCurveItem(
section=section,
y_addr=self.dev_pref.substitute(propty='Table-SP'), name="SP"
y_addr=self.dev_pref.substitute(propty='Table-SP'),
name="SP",
color=QColor(color_sp),
)
plt._needs_redraw = False
plt.addCurve(curve1)
curve1.data_changed.connect(plt.set_needs_redraw)
plt.addCurve(curve_sp, curve_color=QColor(color_sp))
curve_sp.data_changed.connect(plt.set_needs_redraw)

curve2 = SectionedWaveformCurveItem(
curve_rb = SectionedWaveformCurveItem(
section=section,
y_addr=self.dev_pref.substitute(propty='Table-RB'), name="RB"
y_addr=self.dev_pref.substitute(propty='Table-RB'),
name="RB",
color=QColor(color_rb),
)
plt._needs_redraw = False
plt.addCurve(curve2)
curve2.data_changed.connect(plt.set_needs_redraw)
plt.addCurve(curve_rb, curve_color=QColor(color_rb))
curve_rb.data_changed.connect(plt.set_needs_redraw)

return plt

Expand Down

0 comments on commit a09bcf8

Please sign in to comment.