Skip to content

Commit 369d5fc

Browse files
committed
plotting rdts
1 parent b1f1b0a commit 369d5fc

File tree

5 files changed

+214
-71
lines changed

5 files changed

+214
-71
lines changed

omc3_gui/plotting/classes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setVisible(self, visible):
2020
self.visibilityChanged.emit(visible)
2121

2222

23-
class DualPlot(pg.LayoutWidget):
23+
class DualPlotWidget(pg.LayoutWidget):
2424

2525
def __init__(self, *args, **kwargs) -> None:
2626
super().__init__(*args, **kwargs)

omc3_gui/plotting/latex_to_html.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
r'\Chi': 'Χ',
5050
r'\Psi': 'Ψ',
5151
r'\Omega': 'Ω',
52+
# Symbols ---
53+
r'\pm': '±',
54+
r'\times': '×',
55+
r'\Re': 'ℜ',
56+
r'\Im': 'ℑ',
5257
# Spacing ---
5358
r'\quad': ' ',
5459
r'\;': ' ',
@@ -65,5 +70,6 @@ def latex_to_html_converter(latex_str):
6570
latex_str = re.sub(r'_(.)', r'<sub>\1</sub>', latex_str)
6671
latex_str = re.sub(r'\\frac{([^}]*)}{([^}]*)}', r'<sup>\1</sup>/<sub>\2</sub>', latex_str)
6772
latex_str = re.sub(r'\\left\((.*?)\\right\)', r'(\1)', latex_str) # Basic parentheses
73+
latex_str = re.sub(r'\\left\|(.*?)\\right\|', r'|\1|', latex_str) # Absolute values
6874

6975
return latex_str

omc3_gui/segment_by_segment/main_controller.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from omc3_gui.ui_components.text_editor import TextEditorDialog
3838
from omc3_gui.ui_components.threads import BackgroundThread
3939
from omc3_gui.ui_components.base_classes_cvm import Controller
40-
from omc3_gui.plotting.classes import DualPlot
40+
from omc3_gui.plotting.classes import DualPlotWidget
4141

4242
if TYPE_CHECKING:
4343
from collections.abc import Sequence
@@ -103,7 +103,8 @@ def connect_signals(self):
103103

104104
view.sig_table_segments_selected.connect(self.segment_selection_changed)
105105
view.sig_thread_spinner_double_clicked.connect(self._show_running_tasks)
106-
106+
107+
# Tasks --------------------------------------------------------------------
107108
@Slot()
108109
def _update_tasks_status(self):
109110
""" Update the status bar with the number of running tasks. """
@@ -811,6 +812,8 @@ def plot(self, fail_ok: bool = True):
811812
view: SbSWindow = self._view
812813
settings: PlotSettings = self.settings.plotting
813814
definition, widget = view.get_current_tab()
815+
816+
self.clear_plots()
814817

815818
if not settings.forward and not settings.backward:
816819
LOGGER.error("Please enable at least one propagation method to show.")
@@ -835,18 +838,17 @@ def plot(self, fail_ok: bool = True):
835838
log_function("Not plotting, segments have different start BPMs (see 'Same Start' in settings).")
836839
return
837840

838-
self.clear_plots()
839841
plot_segment_data(
840842
widget=widget,
841-
definition=definition,
843+
definitions=definition,
842844
segments=segments_data,
843845
settings=settings,
844846
)
845847

846848
def clear_plots(self):
847849
""" Clear the plots. """
848850
view: SbSWindow = self._view
849-
widget: DualPlot = view.get_current_tab()[1]
851+
widget: DualPlotWidget = view.get_current_tab()[1]
850852
widget.clear()
851853

852854
# Other ------------------------------------------------------------------------

omc3_gui/segment_by_segment/main_view.py

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,56 @@
77
# from omc3_gui.segment_by_segment.segment_by_segment_ui import Ui_main_window
88
from __future__ import annotations
99

10-
from dataclasses import fields
11-
from functools import partial
1210
import logging
1311
from collections.abc import Sequence
12+
from dataclasses import fields
13+
from functools import partial
1414

15-
from omc3.definitions.optics import PHASE_COLUMN, BETA_COLUMN, ALPHA_COLUMN, ColumnsAndLabels
15+
from omc3.definitions.optics import (
16+
ALPHA_COLUMN,
17+
BETA_COLUMN,
18+
DISPERSION_COLUMN,
19+
PHASE_COLUMN,
20+
)
1621
from qtpy import QtGui, QtWidgets
1722
from qtpy.QtCore import QItemSelectionModel, QModelIndex, Qt, Signal, Slot
1823

19-
from omc3_gui.plotting.classes import DualPlot
24+
from omc3_gui.plotting.classes import DualPlotWidget
2025
from omc3_gui.segment_by_segment.main_model import (
2126
MeasurementListModel,
2227
SegmentTableModel,
2328
)
2429
from omc3_gui.segment_by_segment.measurement_model import OpticsMeasurement
30+
from omc3_gui.segment_by_segment.plotting import DualPlotDefinition
2531
from omc3_gui.segment_by_segment.segment_model import SegmentItemModel
2632
from omc3_gui.ui_components import colors
27-
from omc3_gui.utils.counter import HorizontalGridLayoutFiller
28-
from omc3_gui.utils.iteration_classes import IterClass
29-
from omc3_gui.ui_components.styles import MONOSPACED_TOOLTIP
3033
from omc3_gui.ui_components.base_classes_cvm import View
34+
from omc3_gui.ui_components.styles import MONOSPACED_TOOLTIP
3135
from omc3_gui.ui_components.widgets import (
32-
DefaultButton,
3336
ChangeButton,
37+
DefaultButton,
3438
OpenButton,
3539
RemoveButton,
3640
RunButton,
3741
)
42+
from omc3_gui.utils.counter import HorizontalGridLayoutFiller
43+
from omc3_gui.utils.iteration_classes import IterClass
3844

3945
ItemDataRole = Qt.ItemDataRole
4046
LOGGER = logging.getLogger(__name__)
4147

42-
class Tabs(IterClass):
43-
PHASE: ColumnsAndLabels = PHASE_COLUMN
44-
BETA: ColumnsAndLabels = BETA_COLUMN
45-
ALPHA: ColumnsAndLabels = ALPHA_COLUMN
4648

49+
class Tabs(IterClass):
50+
""" Define the Tabs and the things to plot in them. """
51+
PHASE: DualPlotDefinition = DualPlotDefinition.generate_xy("Phase", "phase", PHASE_COLUMN)
52+
BETA: DualPlotDefinition = DualPlotDefinition.generate_xy("Beta", "beta_phase", BETA_COLUMN)
53+
ALPHA: DualPlotDefinition = DualPlotDefinition.generate_xy("Alpha", "alpha_phase", ALPHA_COLUMN)
54+
DISPERSION: DualPlotDefinition = DualPlotDefinition.generate_xy("Dispersion", "dispersion", DISPERSION_COLUMN)
55+
F1001AP: DualPlotDefinition = DualPlotDefinition.generate_amplitude_phase("f1001")
56+
F1001RI: DualPlotDefinition = DualPlotDefinition.generate_real_imag("f1001")
57+
F1010AP: DualPlotDefinition = DualPlotDefinition.generate_amplitude_phase("f1010")
58+
F1010RI: DualPlotDefinition = DualPlotDefinition.generate_real_imag("f1010")
59+
4760

4861
class SbSWindow(View):
4962
WINDOW_TITLE = "OMC Segment-by-Segment"
@@ -125,7 +138,7 @@ def _handle_tab_changed(self):
125138
LOGGER.debug("Tab changed.")
126139
self.sig_tab_changed.emit()
127140

128-
# GUI-Elements -------------------------------------------------------------
141+
# Menu ---------------------------------------------------------------------
129142
def _add_menus(self):
130143
# File ---
131144
file_menu: QtWidgets.QMenu = self.get_action_by_title("File") # defined in View-class
@@ -212,6 +225,7 @@ def update_menu_settings(self, menu: str, settings: object, names: Sequence[str]
212225

213226
entry.setChecked(getattr(settings, field.name))
214227

228+
# Build Main UI-------------------------------------------------------------
215229
def _build_gui(self):
216230
self._central = QtWidgets.QSplitter(Qt.Horizontal)
217231

@@ -331,7 +345,8 @@ def build_segment_buttons():
331345
def build_tabs_widget(): # --- Right Hand Side
332346
self._tabs_widget = QtWidgets.QTabWidget()
333347
for tab in Tabs.values():
334-
self._tabs_widget.addTab(DualPlot(), tab.text_label.capitalize())
348+
tab: DualPlotDefinition
349+
self._tabs_widget.addTab(DualPlotWidget(), tab.name)
335350
return self._tabs_widget
336351

337352
self._central.addWidget(build_tabs_widget())
@@ -341,8 +356,9 @@ def build_tabs_widget(): # --- Right Hand Side
341356
self._central.setStretchFactor(1, 3)
342357

343358
self.setCentralWidget(self._central)
344-
345-
def get_current_tab(self) -> tuple[ColumnsAndLabels, DualPlot]:
359+
360+
# Interactors --------------------------------------------------------------
361+
def get_current_tab(self) -> tuple[DualPlotDefinition, DualPlotWidget]:
346362
widget = self._tabs_widget.currentWidget()
347363
index = self._tabs_widget.currentIndex()
348364
return list(Tabs.values())[index], widget
@@ -388,6 +404,7 @@ def get_selected_segments(self) -> tuple[SegmentItemModel]:
388404

389405

390406
class MeasurementListView(QtWidgets.QListView):
407+
""" Defines the view for the measurement list (on the top left). """
391408

392409
def __init__(self):
393410
super().__init__()
@@ -398,6 +415,7 @@ def __init__(self):
398415

399416

400417
class SegmentTableView(QtWidgets.QTableView):
418+
""" Defines the view for the segment table (on the bottom left). """
401419

402420
def __init__(self):
403421
super().__init__()
@@ -425,6 +443,7 @@ def __init__(self):
425443

426444

427445
class ColoredItemDelegate(QtWidgets.QStyledItemDelegate):
446+
""" Defines an ItemDelegate that uses a custom color for the text. """
428447

429448
COLOR_MAP = {
430449
MeasurementListModel.ColorIDs.NONE: colors.TEXT_DARK,

0 commit comments

Comments
 (0)