Skip to content

Commit 6dec6e2

Browse files
fix: Persist and auto-guess layer/field selections across map2loop and LoopStructural setup widgets (#73)
* Initial plan * Persist widget selections Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * Address review feedback Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * Refine persistence and params Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * Tighten matching and params Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * Fix thickness params Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * don't guess sampler layer * Persist selections in model setup Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> * updating imports and adding faults loop up table --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: lachlangrose <7371904+lachlangrose@users.noreply.github.com> Co-authored-by: Lachlan Grose <lachlan.grose@monash.edu>
1 parent 42f175d commit 6dec6e2

File tree

9 files changed

+439
-123
lines changed

9 files changed

+439
-123
lines changed

loopstructural/gui/map2loop_tools/basal_contacts_widget.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self, parent=None, data_manager=None, debug_manager=None):
6363
self._guess_layers()
6464
# Set up field combo boxes
6565
self._setup_field_combo_boxes()
66+
self._restore_selection()
6667

6768
def set_debug_manager(self, debug_manager):
6869
"""Attach a debug manager instance."""
@@ -145,6 +146,35 @@ def _guess_layers(self):
145146
faults_layer = self.data_manager.find_layer_by_name(fault_layer_match)
146147
self.faultsLayerComboBox.setLayer(faults_layer)
147148

149+
def _restore_selection(self):
150+
"""Restore persisted selections from data manager."""
151+
if not self.data_manager:
152+
return
153+
settings = self.data_manager.get_widget_settings('basal_contacts_widget', {})
154+
if not settings:
155+
return
156+
if layer_name := settings.get('geology_layer'):
157+
layer = self.data_manager.find_layer_by_name(layer_name)
158+
if layer:
159+
self.geologyLayerComboBox.setLayer(layer)
160+
if layer_name := settings.get('faults_layer'):
161+
layer = self.data_manager.find_layer_by_name(layer_name)
162+
if layer:
163+
self.faultsLayerComboBox.setLayer(layer)
164+
if field := settings.get('unit_name_field'):
165+
self.unitNameFieldComboBox.setField(field)
166+
167+
def _persist_selection(self):
168+
"""Persist current selections into data manager."""
169+
if not self.data_manager:
170+
return
171+
settings = {
172+
'geology_layer': self.geologyLayerComboBox.currentLayer().name() if self.geologyLayerComboBox.currentLayer() else None,
173+
'faults_layer': self.faultsLayerComboBox.currentLayer().name() if self.faultsLayerComboBox.currentLayer() else None,
174+
'unit_name_field': self.unitNameFieldComboBox.currentField(),
175+
}
176+
self.data_manager.set_widget_settings('basal_contacts_widget', settings)
177+
148178
def _setup_field_combo_boxes(self):
149179
"""Set up field combo boxes to link to their respective layers."""
150180
geology = self.geologyLayerComboBox.currentLayer()
@@ -174,6 +204,7 @@ def _run_extractor(self):
174204
"""Run the basal contacts extraction algorithm."""
175205
self._log_params("basal_contacts_widget_run")
176206

207+
self._persist_selection()
177208
# Validate inputs
178209
if not self.geologyLayerComboBox.currentLayer():
179210
QMessageBox.warning(self, "Missing Input", "Please select a geology layer.")

loopstructural/gui/map2loop_tools/sampler_widget.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def _on_sampler_type_changed(self):
131131

132132
def _run_sampler(self):
133133
"""Run the sampler algorithm using the map2loop API."""
134+
134135
from qgis.core import (
135136
QgsCoordinateReferenceSystem,
136137
QgsFeature,

loopstructural/gui/map2loop_tools/sorter_widget.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self, parent=None, data_manager=None, debug_manager=None):
7070

7171
# Set up field combo boxes
7272
self._setup_field_combo_boxes()
73+
self._restore_selection()
7374

7475
# Initial state update
7576
self._on_algorithm_changed()
@@ -153,6 +154,56 @@ def _guess_layers(self):
153154
dem_layer = self.data_manager.find_layer_by_name(dem_layer_match, layer_type=QgsRasterLayer)
154155
self.dtmLayerComboBox.setLayer(dem_layer)
155156

157+
def _restore_selection(self):
158+
"""Restore persisted selections from data manager."""
159+
if not self.data_manager:
160+
return
161+
settings = self.data_manager.get_widget_settings('sorter_widget', {})
162+
if not settings:
163+
return
164+
for key, combo in (
165+
('geology_layer', self.geologyLayerComboBox),
166+
('structure_layer', self.structureLayerComboBox),
167+
('contacts_layer', self.contactsLayerComboBox),
168+
('dtm_layer', self.dtmLayerComboBox),
169+
):
170+
if layer_name := settings.get(key):
171+
layer = self.data_manager.find_layer_by_name(layer_name)
172+
if layer:
173+
combo.setLayer(layer)
174+
if 'sorting_algorithm' in settings:
175+
self.sortingAlgorithmComboBox.setCurrentIndex(settings['sorting_algorithm'])
176+
if 'orientation_type' in settings:
177+
self.orientationTypeComboBox.setCurrentIndex(settings['orientation_type'])
178+
for key, combo in (
179+
('unit_name_field', self.unitNameFieldComboBox),
180+
('min_age_field', self.minAgeFieldComboBox),
181+
('max_age_field', self.maxAgeFieldComboBox),
182+
('dip_field', self.dipFieldComboBox),
183+
('dipdir_field', self.dipDirFieldComboBox),
184+
):
185+
if field := settings.get(key):
186+
combo.setField(field)
187+
188+
def _persist_selection(self):
189+
"""Persist current selections into data manager."""
190+
if not self.data_manager:
191+
return
192+
settings = {
193+
'geology_layer': self.geologyLayerComboBox.currentLayer().name() if self.geologyLayerComboBox.currentLayer() else None,
194+
'structure_layer': self.structureLayerComboBox.currentLayer().name() if self.structureLayerComboBox.currentLayer() else None,
195+
'contacts_layer': self.contactsLayerComboBox.currentLayer().name() if self.contactsLayerComboBox.currentLayer() else None,
196+
'dtm_layer': self.dtmLayerComboBox.currentLayer().name() if self.dtmLayerComboBox.currentLayer() else None,
197+
'sorting_algorithm': self.sortingAlgorithmComboBox.currentIndex(),
198+
'orientation_type': self.orientationTypeComboBox.currentIndex(),
199+
'unit_name_field': self.unitNameFieldComboBox.currentField(),
200+
'min_age_field': self.minAgeFieldComboBox.currentField(),
201+
'max_age_field': self.maxAgeFieldComboBox.currentField(),
202+
'dip_field': self.dipFieldComboBox.currentField(),
203+
'dipdir_field': self.dipDirFieldComboBox.currentField(),
204+
}
205+
self.data_manager.set_widget_settings('sorter_widget', settings)
206+
156207
def _setup_field_combo_boxes(self):
157208
"""Set up field combo boxes to link to their respective layers."""
158209
self.unitNameFieldComboBox.setLayer(self.geologyLayerComboBox.currentLayer())
@@ -283,6 +334,7 @@ def _run_sorter(self):
283334
"""Run the stratigraphic sorter algorithm."""
284335
from ...main.m2l_api import sort_stratigraphic_column
285336

337+
self._persist_selection()
286338
self._log_params("sorter_widget_run")
287339

288340
# Validate inputs

0 commit comments

Comments
 (0)