1212from typing import TYPE_CHECKING
1313
1414from omc3 .sbs_propagation import segment_by_segment
15+ from omc3 .segment_by_segment .constants import corrections_madx
1516from qtpy import QtWidgets
1617from qtpy .QtCore import Slot
1718
18- from omc3_gui .segment_by_segment .defaults import DEFAULT_SEGMENTS
19+ from omc3_gui .segment_by_segment .defaults import DEFAULT_SEGMENTS , get_default_correctors
1920from omc3_gui .segment_by_segment .plotting import plot_segment_data
2021from omc3_gui .segment_by_segment .settings import PlotSettings , Settings
2122from omc3_gui .segment_by_segment .main_model import SegmentTableModel
@@ -70,7 +71,7 @@ def connect_signals(self):
7071 view .add_settings_to_menu (
7172 menu = "View" ,
7273 settings = self .settings .plotting ,
73- hook = partial (self .plot , weak = True ),
74+ hook = partial (self .plot , weak = True ), # update plots if possible
7475 )
7576
7677 # Measurements -------------------------------------------------------------
@@ -421,6 +422,11 @@ def edit_corrections(self) -> None:
421422 # Open the TextEditor for the selected correction file ---
422423 LOGGER .debug (f"Opening TextEditor for correction file: { correction_file } ." )
423424 edit_dialog = TextEditorDialog (correction_file )
425+
426+ if not correction_file .exists () and self .settings .main .suggest_correctors :
427+ text = get_default_correctors (selected_measurements [0 ]) # bit hacky but ok for now?
428+ edit_dialog .text_edit .setPlainText (text )
429+
424430 edit_dialog .exec_ ()
425431
426432
@@ -659,6 +665,12 @@ def load_segments_for_measurement(self, measurement: OpticsMeasurement):
659665 segment = SegmentDataModel (measurement , * segment_tuple )
660666 measurement .try_add_segment (segment )
661667
668+ for segment in measurement .segments :
669+ corrections = measurement .output_dir / corrections_madx .format (segment .name )
670+ if corrections .exists ():
671+ measurement .corrections = corrections
672+ break # for now they should all be the same corrections
673+
662674 @Slot ()
663675 def save_segments (self ):
664676 LOGGER .debug ("Saving segments to a file." )
@@ -726,26 +738,30 @@ def clear_all():
726738 )
727739
728740 # For Real Use: Run Task ---
729- # LOGGER.info(f"Starting {measurement_task.message}")
730- # self._add_running_task(task=measurement_task)
731- # measurement_task.start()
741+ LOGGER .info (f"Starting { measurement_task .message } " )
742+ self ._add_running_task (task = measurement_task )
743+ measurement_task .start ()
732744
733745 # For Debugging: Start sbs directly ---
734- sbs_function ()
735- clear_all ()
736- LOGGER .info (f"Finished { measurement_task .message } " )
746+ # sbs_function()
747+ # clear_all()
748+ # LOGGER.info(f"Finished {measurement_task.message}")
737749 # -------------------------------------
738750
739751# Plotting ---------------------------------------------------------------------
740752 def plot (self , weak : bool = False ):
741753 """ Trigger a plot update with the currently selected segments. """
742754 view : SbSWindow = self ._view
743755 settings : PlotSettings = self .settings .plotting
756+ definition , widget = view .get_current_tab ()
744757
745758 if not settings .forward and not settings .backward :
746759 LOGGER .error ("Please enable at least one propagation method to show." )
747760 return
748761
762+ widget .set_connect_x (settings .connect_x )
763+ widget .set_connect_y (settings .connect_y )
764+
749765 segments = view .get_selected_segments ()
750766 if len (segments ) != 1 :
751767 if not weak :
@@ -755,7 +771,6 @@ def plot(self, weak: bool = False):
755771 self .clear_plots ()
756772
757773 segments_data : list [SegmentDataModel ] = segments [0 ].segments
758- definition , widget = view .get_current_tab ()
759774 plot_segment_data (
760775 widget = widget ,
761776 definition = definition ,
0 commit comments