77
88from loopstructural .gui .modelling .model_definition import fault_layers
99
10+ from ...main .helpers import ColumnMatcher , get_layer_names
1011from ...main .m2l_api import extract_basal_contacts
12+ from ...main .vectorLayerWrapper import addGeoDataFrameToproject
1113
1214
1315class BasalContactsWidget (QWidget ):
@@ -58,10 +60,31 @@ def __init__(self, parent=None, data_manager=None):
5860 # Connect signals
5961 self .geologyLayerComboBox .layerChanged .connect (self ._on_geology_layer_changed )
6062 self .runButton .clicked .connect (self ._run_extractor )
61-
63+ self . _guess_layers ()
6264 # Set up field combo boxes
6365 self ._setup_field_combo_boxes ()
6466
67+ def _guess_layers (self ):
68+ """Attempt to auto-select layers based on common naming conventions."""
69+ if not self .data_manager :
70+ return
71+
72+ # Attempt to find geology layer
73+ geology_layer_names = get_layer_names (self .geologyLayerComboBox )
74+ geology_matcher = ColumnMatcher (geology_layer_names )
75+ geology_layer_match = geology_matcher .find_match ('GEOLOGY' )
76+ if geology_layer_match :
77+ geology_layer = self .data_manager .find_layer_by_name (geology_layer_match )
78+ self .geologyLayerComboBox .setLayer (geology_layer )
79+
80+ # Attempt to find faults layer
81+ fault_layer_names = get_layer_names (self .faultsLayerComboBox )
82+ fault_layer_matcher = ColumnMatcher (fault_layer_names )
83+ fault_layer_match = fault_layer_matcher .find_match ('FAULTS' )
84+ if fault_layer_match :
85+ faults_layer = self .data_manager .find_layer_by_name (fault_layer_match )
86+ self .faultsLayerComboBox .setLayer (faults_layer )
87+
6588 def _setup_field_combo_boxes (self ):
6689 """Set up field combo boxes to link to their respective layers."""
6790 geology = self .geologyLayerComboBox .currentLayer ()
@@ -76,9 +99,20 @@ def _setup_field_combo_boxes(self):
7699
77100 def _on_geology_layer_changed (self ):
78101 """Update field combo boxes when geology layer changes."""
102+ from ...main .helpers import ColumnMatcher
103+
79104 layer = self .geologyLayerComboBox .currentLayer ()
80105 self .unitNameFieldComboBox .setLayer (layer )
81106
107+ # Auto-detect appropriate fields
108+ if layer :
109+ fields = [field .name () for field in layer .fields ()]
110+ matcher = ColumnMatcher (fields )
111+
112+ # Auto-select UNITNAME field
113+ if unit_match := matcher .find_match ('UNITNAME' ):
114+ self .unitNameFieldComboBox .setField (unit_match )
115+
82116 def _run_extractor (self ):
83117 """Run the basal contacts extraction algorithm."""
84118 # Validate inputs
@@ -98,16 +132,37 @@ def _run_extractor(self):
98132 stratigraphic_order = (
99133 self .data_manager ._stratigraphic_column .get_unit_names () if self .data_manager else []
100134 )
101- extract_basal_contacts (
135+
136+ # Check if user wants all contacts or just basal contacts
137+ all_contacts = self .allContactsCheckBox .isChecked ()
138+ if all_contacts :
139+ stratigraphic_order = list (set ([g [unit_name_field ] for g in geology .getFeatures ()]))
140+ result = extract_basal_contacts (
102141 geology = geology ,
103142 stratigraphic_order = stratigraphic_order ,
104143 faults = faults ,
105144 ignore_units = ignore_units ,
106145 unit_name_field = unit_name_field ,
107- all_contacts = False ,
146+ all_contacts = all_contacts ,
108147 updater = lambda message : QMessageBox .information (self , "Extraction Progress" , message ),
109148 )
110149
150+ # Show success message based on what was extracted
151+ if all_contacts and result :
152+ addGeoDataFrameToproject (result ['all_contacts' ], "All contacts" )
153+ contact_type = "all contacts and basal contacts"
154+ else :
155+ addGeoDataFrameToproject (result ['basal_contacts' ], "Basal contacts" )
156+
157+ contact_type = "basal contacts"
158+
159+ if result :
160+ QMessageBox .information (
161+ self ,
162+ "Success" ,
163+ f"Successfully extracted { contact_type } !" ,
164+ )
165+
111166 def get_parameters (self ):
112167 """Get current widget parameters.
113168
@@ -127,6 +182,7 @@ def get_parameters(self):
127182 'unit_name_field' : self .unitNameFieldComboBox .currentField (),
128183 'faults_layer' : self .faultsLayerComboBox .currentLayer (),
129184 'ignore_units' : ignore_units ,
185+ 'all_contacts' : self .allContactsCheckBox .isChecked (),
130186 }
131187
132188 def set_parameters (self , params ):
@@ -141,6 +197,7 @@ def set_parameters(self, params):
141197 self .geologyLayerComboBox .setLayer (params ['geology_layer' ])
142198 if 'faults_layer' in params and params ['faults_layer' ]:
143199 self .faultsLayerComboBox .setLayer (params ['faults_layer' ])
144-
145200 if 'ignore_units' in params and params ['ignore_units' ]:
146201 self .ignoreUnitsLineEdit .setText (', ' .join (params ['ignore_units' ]))
202+ if 'all_contacts' in params :
203+ self .allContactsCheckBox .setChecked (params ['all_contacts' ])
0 commit comments