-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtopo_chronia.py
772 lines (658 loc) · 36.7 KB
/
topo_chronia.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# -*- coding: utf-8 -*-
"""
/***************************************************************************
TopoChronia
A QGIS plugin
A tool to reconstruct quantitative and evolutive topography of 100% of the
Earth surface for the entire Phanerozoic, based on the PANALESIS model.
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2023-10-20
git sha : $Format:%H$
copyright : (C) 2025 by Florian Franziskakis
email : florian.franziskakis@unige.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
import os
import os.path
import json
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QAction, QFileDialog, QDialog
from qgis.core import QgsProject, Qgis, QgsMessageLog
from qgis.core import QgsLayerTreeLayer, QgsApplication
from .dialogs.check_configuration_dialog import CheckConfigurationDialog
from .dialogs.create_node_grid_dialog import CreateNodeGridDialog
from .dialogs.interpolate_raster_dialog import InterpolateRasterDialog
from .dialogs.match_fields_dialog import MatchFieldsDialog
from .functions.check_configuration_functions import check_fields, check_file_geometry, check_values, create_age_list
class TopoChronia:
"""TopoChronia QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initializes plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initializes locale
locale = QSettings().value('locale/userLocale')[0:2]
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'TopoChronia_{}.qm'.format(locale))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)
# Declares instance attributes
self.actions = []
self.menu = self.tr(u'&TopoChronia')
# Initializes layers attribute
self.layers = None
# Initializes age lists as class attributes
self.PM_age_list = None
self.PP_age_list = None
self.CP_age_list = None
self.all_age_list = None
self.check_results = {
"check_plate_model": None,
"check_plate_polygons": None,
"check_continent_polygons": None,
"check_geodesic_grid": None,
"check_accretion_rates": None,
"check_output_folder": None,
}
self.input_fc = {
"Plate Model": None,
"Plate Polygons": None,
"Continent Polygons": None,
"Geodesic Grid": None,
"Accretion Rates": None,
"Output Folder": None
}
# Checks if plugin was started the first time in the current QGIS session
# Must be set in initGui() to survive plugin reloads
self.first_start = None
def tr(self, message):
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('TopoChronia', message)
def add_action(self,icon_path,text,callback,enabled_flag=True,add_to_menu=True,add_to_toolbar=True,status_tip=None,
whats_this=None,data=None,parent=None):
"""
Adds plugin related buttons to the QGIS toolbar.
"""
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
# Adds plugin icon to Plugins toolbar
self.iface.addToolBarIcon(action)
if add_to_menu:
self.iface.addPluginToMenu(
self.menu,
action)
self.actions.append(action)
return action
def initGui(self):
"""
Creates the menu entries and toolbar icons inside the QGIS GUI.
"""
# Adds an icon for each phase
icon_path_phase0 = f"{self.plugin_dir}/icons/check.png"
icon_path_phase1 = f"{self.plugin_dir}/icons/grid.png"
icon_path_phase2 = f"{self.plugin_dir}/icons/mountain.png"
# Adds menu entries for each phase
self.add_action(
icon_path_phase0,
text=self.tr(u'TC Phase 0: Check Configuration'),
callback=self.run_check_configuration,
parent=self.iface.mainWindow(),
data={'phase': 0},
enabled_flag= True,
status_tip= "Click here to check the configuration of input data for TopoChronia")
self.add_action(
icon_path_phase1,
text=self.tr(u'TC Phase I: Create Node Grid'),
callback=self.run_create_node_grid,
parent=self.iface.mainWindow(),
data={'phase': 1},
enabled_flag = True,
status_tip= "Click here to start the features conversion into nodes with elevation")
self.add_action(
icon_path_phase2,
text=self.tr(u'TC Phase II: Interpolate Raster'),
callback=self.run_interpolate_raster,
parent=self.iface.mainWindow(),
data={'phase': 2},
enabled_flag= True,
status_tip= "Click here to interpolate from nodes to raster and correct water load")
def unload(self):
"""
Removes the plugin menu item and icon from QGIS GUI.
"""
for action in self.actions:
self.iface.removePluginMenu(
self.tr(u'&Topography Maker'),
action)
self.iface.removeToolBarIcon(action)
def get_selected_layer(self, tab_index):
"""Gets the selected layer based on the current combo box index."""
if self.layers is None:
# Fetches the currently loaded layers if not done already
self.layers = QgsProject.instance().layerTreeRoot().children()
# Determines the current comboBox based on the tab index
current_combo_box = None
if tab_index == 0: # PlateModel tab
current_combo_box = self.check_configuration_dialog.InputFile_PlateModel_comboBox
elif tab_index == 1: # PlatePolygons tab
current_combo_box = self.check_configuration_dialog.InputFile_PlatePolygons_comboBox
elif tab_index == 2: # ContinentsPolygons tab
current_combo_box = self.check_configuration_dialog.InputFile_ContinentPolygons_comboBox
elif tab_index == 3: # GeodesicGrid tab
current_combo_box = self.check_configuration_dialog.InputFile_GeodesicGrid_comboBox
elif tab_index == 4: # AccretionRates tab
current_combo_box = self.check_configuration_dialog.InputFile_AccretionRates_comboBox
if current_combo_box is not None:
selectedLayerIndex = current_combo_box.currentIndex()
return self.layers[selectedLayerIndex].layer()
else:
return None
def check_plate_model(self):
"""
Checks geometry, fields, values, and create age list for Plate Model.
"""
# Clears the message labels at the beginning
self.check_configuration_dialog.Status_PlateModel.setText("")
self.check_configuration_dialog.Progress_PlateModel.setText("")
check_configuration_step = "PlateModel"
self.check_configuration_step = check_configuration_step
selected_layer = self.get_selected_layer(0) # 0 corresponds to the PlateModel tab
# Progress status
progress = 0
progress_message = ""
# Step 1: Checks if a layer is loaded
if selected_layer is not None:
progress += 1
# Display a message that the layer was successfully loaded
layer_message = "Layer successfully loaded."
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlateModel.setText("No layer selected.")
self.check_configuration_dialog.Progress_PlateModel.setText(f"Progress: {progress}/5")
expected_geometry_type = "Line"
expected_field_names = ["APPEARANCE", "PLATE", "AGE", "TYPE", "COB_LIMIT", "LIMIT", "POSITION"]
# Step 2: Checks geometry
geometry_validation_message = check_file_geometry(selected_layer, expected_geometry_type)
if "Geometry ok." in geometry_validation_message:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlateModel.setText(geometry_validation_message)
self.check_configuration_dialog.Progress_PlateModel.setText(f"Progress: {progress}/5")
return
# Step 3: Checks fields
fields_validation_messages = check_fields(selected_layer, expected_field_names)
if "Fields ok." in fields_validation_messages["message"]:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlateModel.setText(fields_validation_messages["message"])
self.check_configuration_dialog.Progress_PlateModel.setText(f"Progress: {progress}/5")
self.check_configuration_dialog.Action_PlateModel_pushButton.setText("Match Fields")
# Shows the Action_PlateModel_pushButton if there is an error
self.check_configuration_dialog.Action_PlateModel_pushButton.show()
self.expected_field_names = expected_field_names
self.selected_layer = selected_layer
self.fields_validation_messages = fields_validation_messages
return
# Step 4: Checks values
values_validation_messages = check_values(selected_layer, expected_field_names)
if "Values ok." in values_validation_messages:
progress += 1
else:
# Sets the error messages in the label
self.check_configuration_dialog.Status_PlateModel.setText("\n".join(values_validation_messages))
self.check_configuration_dialog.Progress_PlateModel.setText(f"Progress: {progress}/5")
return
# Step 5: Creates age list
self.PM_age_list, age_list_message = create_age_list(selected_layer, "APPEARANCE")
if self.PM_age_list is not None:
progress += 1
progress_message = f"Progress: {progress}/5"
# Set the age list message
self.check_configuration_dialog.Status_PlateModel.setText(age_list_message)
# QgsMessageLog.logMessage(''.join(map(str, self.PM_age_list)), "Match Fields", Qgis.Info)
else:
self.check_configuration_dialog.Status_PlateModel.setText(age_list_message)
self.check_configuration_dialog.Progress_PlateModel.setText(progress_message)
return
# Sets the combined message to the label
validation_message = ' '.join([layer_message, geometry_validation_message, fields_validation_messages["message"],
' '.join(values_validation_messages), age_list_message])
self.check_configuration_dialog.Status_PlateModel.setText(validation_message)
# Sets the progress status in the label
self.check_configuration_dialog.Progress_PlateModel.setText(progress_message)
# All checks passed, logs success message
success_message = "All checks passed:"
validation_message = ' '.join([success_message, layer_message, geometry_validation_message,
fields_validation_messages["message"], ' '.join(values_validation_messages),
age_list_message])
self.check_configuration_dialog.Status_PlateModel.setText(validation_message)
self.check_results["check_plate_model"] = "success"
self.input_fc["Plate Model"] = selected_layer.source()
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def check_plate_polygons(self):
"""
Checks geometry, fields, values, and create age list for Plate Polygons.
"""
# Clears the message labels at the beginning
self.check_configuration_dialog.Status_PlatePolygons.setText("")
self.check_configuration_dialog.Progress_PlatePolygons.setText("")
check_configuration_step = "PlatePolygons"
self.check_configuration_step = check_configuration_step
self.PP_age_list = None
selected_layer = self.get_selected_layer(1) # 1 corresponds to the PlatePolygons tab
# Progress status
progress = 0
progress_message = ""
# Step 1: Checks if a layer is loaded
if selected_layer is not None:
progress += 1
# Displays a message that the layer was successfully loaded
layer_message = "Layer successfully loaded."
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlatePolygons.setText("No layer selected.")
self.check_configuration_dialog.Progress_PlatePolygons.setText(f"Progress: {progress}/5")
expected_geometry_type = "Polygon"
expected_field_names = ["APPEARANCE", "PLATE"]
# Step 2: Checks geometry
geometry_validation_message = check_file_geometry(selected_layer, expected_geometry_type)
if "Geometry ok." in geometry_validation_message:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlatePolygons.setText(geometry_validation_message)
self.check_configuration_dialog.Progress_PlatePolygons.setText(f"Progress: {progress}/5")
return
# Step 3: Checks fields
fields_validation_messages = check_fields(selected_layer, expected_field_names)
if "Fields ok." in fields_validation_messages["message"]:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_PlatePolygons.setText(fields_validation_messages["message"])
self.check_configuration_dialog.Progress_PlatePolygons.setText(f"Progress: {progress}/5")
self.check_configuration_dialog.Action_PlatePolygons_pushButton.setText("Match Fields")
# Shows the Action_PlatePolygons_pushButton if there is an error
self.check_configuration_dialog.Action_PlatePolygons_pushButton.show()
self.expected_field_names = expected_field_names
self.selected_layer = selected_layer
self.fields_validation_messages = fields_validation_messages
return
# Step 4: Checks values
values_validation_messages = check_values(selected_layer, expected_field_names)
if "Values ok." in values_validation_messages:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
# Set the error messages in the label
self.check_configuration_dialog.Status_PlatePolygons.setText("\n".join(values_validation_messages))
self.check_configuration_dialog.Progress_PlatePolygons.setText(f"Progress: {progress}/5")
return
# Step 5: Creates age list
self.PP_age_list, age_list_message = create_age_list(selected_layer, "APPEARANCE")
if self.PP_age_list is not None:
progress += 1
progress_message = f"Progress: {progress}/5"
# Sets the age list message
self.check_configuration_dialog.Status_PlatePolygons.setText(age_list_message)
else:
self.check_configuration_dialog.Status_PlatePolygons.setText(age_list_message)
self.check_configuration_dialog.Progress_PlatePolygons.setText(progress_message)
return
# Sets the combined message to the label
validation_message = ' '.join([layer_message, geometry_validation_message, fields_validation_messages["message"],
' '.join(values_validation_messages), age_list_message])
self.check_configuration_dialog.Status_PlatePolygons.setText(validation_message)
# Set the progress status in the label
self.check_configuration_dialog.Progress_PlatePolygons.setText(progress_message)
# All checks passed, logs success message
success_message = "All checks passed:"
validation_message = ' '.join([success_message,layer_message, geometry_validation_message,
fields_validation_messages["message"],' '.join(values_validation_messages),
age_list_message])
self.check_configuration_dialog.Status_PlatePolygons.setText(validation_message)
self.check_results["check_plate_polygons"] = "success"
self.input_fc["Plate Polygons"] = selected_layer.source()
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def check_continent_polygons(self):
"""
Checks geometry, fields, values, and create age list for Continents Polygons.
"""
# Clears the message labels at the beginning
self.check_configuration_dialog.Status_ContinentPolygons.setText("")
self.check_configuration_dialog.Progress_ContinentPolygons.setText("")
check_configuration_step = "ContinentPolygons"
self.check_configuration_step = check_configuration_step
self.CP_age_list = None
selected_layer = self.get_selected_layer(2) # 2 corresponds to the ContinentPolygons tab
# Progress status
progress = 0
progress_message = ""
# Step 1: Checks if a layer is loaded
if selected_layer is not None:
progress += 1
# Display a message that the layer was successfully loaded
layer_message = "Layer successfully loaded."
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_ContinentPolygons.setText("No layer selected.")
self.check_configuration_dialog.Progress_ContinentPolygons.setText(f"Progress: {progress}/5")
expected_geometry_type = "Polygon"
expected_field_names = ["APPEARANCE"]
# Step 2: Checks geometry
geometry_validation_message = check_file_geometry(selected_layer, expected_geometry_type)
if "Geometry ok." in geometry_validation_message:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_ContinentPolygons.setText(geometry_validation_message)
self.check_configuration_dialog.Progress_ContinentPolygons.setText(f"Progress: {progress}/5")
return
# Step 3: Checks fields
fields_validation_messages = check_fields(selected_layer, expected_field_names)
if "Fields ok." in fields_validation_messages["message"]:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
self.check_configuration_dialog.Status_ContinentPolygons.setText(fields_validation_messages["message"])
self.check_configuration_dialog.Progress_ContinentPolygons.setText(f"Progress: {progress}/5")
self.check_configuration_dialog.Action_ContinentPolygons_pushButton.setText("Match Fields")
# Shows the Action_ContinentPolygons_pushButton if there is an error
self.check_configuration_dialog.Action_ContinentPolygons_pushButton.show()
self.expected_field_names = expected_field_names
self.selected_layer = selected_layer
self.fields_validation_messages = fields_validation_messages
return
# Step 4: Checks values
values_validation_messages = check_values(selected_layer, expected_field_names)
if "Values ok." in values_validation_messages:
progress += 1
progress_message = f"Progress: {progress}/5"
else:
# Sets the error messages in the label
self.check_configuration_dialog.Status_ContinentPolygons.setText("\n".join(values_validation_messages))
self.check_configuration_dialog.Progress_ContinentPolygons.setText(f"Progress: {progress}/5")
return
# Step 5: Creates age list
self.CP_age_list, age_list_message = create_age_list(selected_layer, "APPEARANCE")
if self.CP_age_list is not None:
progress += 1
progress_message = f"Progress: {progress}/5"
# Sets the age list message
self.check_configuration_dialog.Status_ContinentPolygons.setText(age_list_message)
else:
self.check_configuration_dialog.Status_ContinentPolygons.setText(age_list_message)
self.check_configuration_dialog.Progress_ContinentPolygons.setText(progress_message)
return
# Sets the combined message to the label
validation_message = ' '.join([layer_message, geometry_validation_message, fields_validation_messages["message"],
' '.join(values_validation_messages), age_list_message])
self.check_configuration_dialog.Status_ContinentPolygons.setText(validation_message)
# Sets the progress status in the label
self.check_configuration_dialog.Progress_ContinentPolygons.setText(progress_message)
# All checks passed, logs success message
success_message = "All checks passed:"
validation_message = ' '.join([success_message, layer_message, geometry_validation_message,
fields_validation_messages["message"], ' '.join(values_validation_messages)
,age_list_message])
self.check_configuration_dialog.Status_ContinentPolygons.setText(validation_message)
self.check_results["check_continent_polygons"] = "success"
self.input_fc["Continent Polygons"] = selected_layer.source()
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def check_geodesic_grid(self):
"""
Checks geometry, fields, values, and create age list for the Geodesic grid.
"""
# Clears the message labels at the beginning
self.check_configuration_dialog.Status_GeodesicGrid.setText("")
self.check_configuration_dialog.Progress_GeodesicGrid.setText("")
check_configuration_step = "GeodesicGrid"
self.check_configuration_step = check_configuration_step
selected_layer = self.get_selected_layer(3) # 3 corresponds to the GeodesicGrid tab
# Progress status
progress = 0
progress_message = ""
# Step 1: Check if a layer is loaded
if selected_layer is not None:
progress += 1
# Displays a message that the layer was successfully loaded
layer_message = "Layer successfully loaded."
progress_message = f"Progress: {progress}/2"
else:
self.check_configuration_dialog.Status_GeodesicGrid.setText("No layer selected.")
self.check_configuration_dialog.Progress_GeodesicGrid.setText(f"Progress: {progress}/2")
expected_geometry_type = "Point"
# Step 2: Checks geometry
geometry_validation_message = check_file_geometry(selected_layer, expected_geometry_type)
if "Geometry ok." in geometry_validation_message:
progress += 1
progress_message = f"Progress: {progress}/2"
else:
self.check_configuration_dialog.Status_GeodesicGrid.setText(geometry_validation_message)
self.check_configuration_dialog.Progress_GeodesicGrid.setText(f"Progress: {progress}/2")
return
# Sets the combined message to the label
validation_message = ' '.join([layer_message, geometry_validation_message])
self.check_configuration_dialog.Status_GeodesicGrid.setText(validation_message)
# Sets the progress status in the label
self.check_configuration_dialog.Progress_GeodesicGrid.setText(progress_message)
# All checks passed, logs success message
success_message = "All checks passed:"
validation_message = ' '.join([success_message, layer_message, geometry_validation_message])
self.check_configuration_dialog.Status_GeodesicGrid.setText(validation_message)
self.check_results["check_geodesic_grid"] = "success"
self.input_fc["Geodesic Grid"] = selected_layer.source()
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def check_accretion_rates(self):
"""
Checks if required fields are present in the AccretionRates table.
"""
# Clear the message labels at the beginning
self.check_configuration_dialog.Status_AccretionRates.setText("")
self.check_configuration_dialog.Progress_AccretionRates.setText("")
check_configuration_step = "AccretionRates"
self.check_configuration_step = check_configuration_step
selected_layer = self.get_selected_layer(4) # 4 corresponds to the AccretionRates tab
# Progress status
progress = 0
progress_message = ""
# Step 1: Checks if a layer is loaded
if selected_layer is not None:
progress += 1
# Displays a message that the layer was successfully loaded
layer_message = "Layer successfully loaded."
progress_message = f"Progress: {progress}/2"
else:
self.check_configuration_dialog.Status_AccretionRates.setText("No layer selected.")
self.check_configuration_dialog.Progress_AccretionRates.setText(f"Progress: {progress}/2")
expected_field_names = ["Age", "VELOCITY"]
# Step 2: Checks fields
fields_validation_messages = check_fields(selected_layer, expected_field_names)
if "Fields ok." in fields_validation_messages["message"]:
progress += 1
progress_message = f"Progress: {progress}/2"
else:
self.check_configuration_dialog.Status_AccretionRates.setText(fields_validation_messages["message"])
self.check_configuration_dialog.Progress_AccretionRates.setText(f"Progress: {progress}/2")
self.check_configuration_dialog.Action_AccretionRates_pushButton.setText("Match Fields")
# Shows the Action_AccretionRates_pushButton if there is an error
self.check_configuration_dialog.Action_AccretionRates_pushButton.show()
self.expected_field_names = expected_field_names
self.selected_layer = selected_layer
self.fields_validation_messages = fields_validation_messages
return
# Sets the combined message to the label
validation_message = ' '.join([layer_message,fields_validation_messages["message"]])
self.check_configuration_dialog.Status_AccretionRates.setText(validation_message)
# Sets the progress status in the label
self.check_configuration_dialog.Progress_AccretionRates.setText(progress_message)
# All checks passed, logs success message
success_message = "All checks passed:"
validation_message = ' '.join([success_message, layer_message, fields_validation_messages["message"]])
self.check_configuration_dialog.Status_AccretionRates.setText(validation_message)
self.check_results["check_accretion_rates"] = "success"
self.input_fc["Accretion Rates"] = selected_layer.source()
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def check_output_folder(self):
"""
Selects an output folder to write out the palaeotopographic reconstructions.
"""
progress = 0
progress_message = ""
check_configuration_step = "OutputFolder"
self.check_configuration_step = check_configuration_step
# Step 1 - Defines output folder
output_folder_path = QFileDialog.getExistingDirectory(
self.check_configuration_dialog, "Select output folder", "/path/to/default/folder")
self.check_configuration_dialog.OutputFolder_lineEdit.setText(output_folder_path)
# Displays a message indicating that the path was successfully set
if output_folder_path:
progress += 1
validation_message = f"Output folder path set to: {output_folder_path}"
progress_message = f"Progress: {progress}/1"
# Sets the progress status.
self.check_configuration_dialog.Progress_OutputFolder.setText(progress_message)
self.check_configuration_dialog.Status_OutputFolder.setText(validation_message)
self.check_results["check_output_folder"] = "success"
self.input_fc["Output Folder"] = output_folder_path
message = f"Check Configuration: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
def setup_dialog(self):
"""
Setups the dialog and connect signals.
"""
self.check_configuration_dialog = CheckConfigurationDialog()
def connect_button_signals(self):
"""
Connects signals for button clicks.
"""
# Connects the various check buttons for each function.
self.check_configuration_dialog.Check_PlateModel_pushButton.clicked.connect(self.check_plate_model)
self.check_configuration_dialog.Check_PlatePolygons_pushButton.clicked.connect(self.check_plate_polygons)
self.check_configuration_dialog.Check_ContinentPolygons_pushButton.clicked.connect(self.check_continent_polygons)
self.check_configuration_dialog.Check_GeodesicGrid_pushButton.clicked.connect(self.check_geodesic_grid)
self.check_configuration_dialog.Check_AccretionRates_pushButton.clicked.connect(self.check_accretion_rates)
self.check_configuration_dialog.OutputFolder_toolButton.clicked.connect(self.check_output_folder)
self.check_configuration_dialog.GoToNextPhase_pushButton.clicked.connect(self.check_and_run_create_node_grid)
# Connects the various action buttons to the run_match_fields method for each function.
self.check_configuration_dialog.Action_PlateModel_pushButton.clicked.connect(self.run_match_fields)
self.check_configuration_dialog.Action_PlatePolygons_pushButton.clicked.connect(self.run_match_fields)
self.check_configuration_dialog.Action_ContinentPolygons_pushButton.clicked.connect(self.run_match_fields)
self.check_configuration_dialog.Action_AccretionRates_pushButton.clicked.connect(self.run_match_fields)
def run_check_configuration(self):
"""
Connects all tools and buttons needed to perform the check configuration phase.
"""
# Sets phase to 0 and defines the correct dialog for configuration check.
self.current_phase = 0
self.check_configuration_dialog = CheckConfigurationDialog()
# Fetches the currently loaded layers
self.layers = QgsProject.instance().layerTreeRoot().children()
# Creates the dialog with elements (after translation) and keep reference
# Only creates GUI ONCE in callback, so that it will only load when the plugin is started
if self.first_start:
self.first_start = False
self.setup_dialog()
# Connects signals for button clicks
self.connect_button_signals()
# Hides the Action pushButtons when the check_configuration_dialog is open
self.check_configuration_dialog.Action_PlateModel_pushButton.hide()
self.check_configuration_dialog.Action_PlatePolygons_pushButton.hide()
self.check_configuration_dialog.Action_ContinentPolygons_pushButton.hide()
self.check_configuration_dialog.Action_AccretionRates_pushButton.hide()
# Clears the contents of the comboBox from previous runs
self.check_configuration_dialog.InputFile_PlateModel_comboBox.clear()
self.check_configuration_dialog.InputFile_PlatePolygons_comboBox.clear()
self.check_configuration_dialog.InputFile_ContinentPolygons_comboBox.clear()
self.check_configuration_dialog.InputFile_GeodesicGrid_comboBox.clear()
self.check_configuration_dialog.InputFile_AccretionRates_comboBox.clear()
# Populates the comboBox with names of all the loaded layers
layer_names = [layer.name() for layer in self.layers if isinstance(layer, QgsLayerTreeLayer)]
if layer_names:
self.check_configuration_dialog.InputFile_PlateModel_comboBox.addItems(layer_names)
self.check_configuration_dialog.InputFile_PlatePolygons_comboBox.addItems(layer_names)
self.check_configuration_dialog.InputFile_ContinentPolygons_comboBox.addItems(layer_names)
self.check_configuration_dialog.InputFile_GeodesicGrid_comboBox.addItems(layer_names)
self.check_configuration_dialog.InputFile_AccretionRates_comboBox.addItems(layer_names)
else:
self.check_configuration_dialog.InputFile_PlateModel_comboBox.addItem("No layers loaded")
self.check_configuration_dialog.InputFile_PlatePolygons_comboBox.addItem("No layers loaded")
self.check_configuration_dialog.InputFile_ContinentPolygons_comboBox.addItem("No layers loaded")
self.check_configuration_dialog.InputFile_GeodesicGrid_comboBox.addItem("No layers loaded")
self.check_configuration_dialog.InputFile_AccretionRates_comboBox.addItem("No layers loaded")
message = f"Check Results: {self.check_results}"
QgsMessageLog.logMessage(message, "Check Configuration", Qgis.Info)
self.check_configuration_dialog.show()
def check_and_run_create_node_grid(self):
"""
Checks if all checks are successful and run create node grid if true.
"""
if all(value == "success" for value in self.check_results.values()):
# All checks are successful, proceed with creating the node grid
QgsMessageLog.logMessage("All checks successful, moving to Phase I: Create Node Grid.",
"Check Configuration", Qgis.Info)
file_path = "input_files.txt"
with open(file_path, "w") as json_file:
json.dump(self.input_fc, json_file)
self.run_create_node_grid()
else:
QgsMessageLog.logMessage("Some checks are not yet successful. Please check the input data above.",
"Check Configuration", Qgis.Info)
def run_match_fields(self):
"""
Connects all tools and buttons needed to perform the run match fields dialog.
"""
self.match_fields_dialog = MatchFieldsDialog()
self.match_fields_dialog.set_configuration_check_step(self.check_configuration_step)
self.match_fields_dialog.set_selected_layer(self.selected_layer)
self.match_fields_dialog.set_fields_names(self.expected_field_names, self.fields_validation_messages)
self.match_fields_dialog.show()
def run_create_node_grid(self):
"""
Connects all tools and buttons needed to perform the create node grid phase.
"""
self.create_node_grid_dialog = CreateNodeGridDialog(self.PM_age_list, self.PP_age_list, self.CP_age_list, self.input_fc)
self.create_node_grid_dialog.show()
def run_interpolate_raster(self):
"""
Connects all tools and buttons needed to perform the interpolate raster phase.
"""
# Sets phase to 2 and defines the correct dialog for interpolate raster.
self.current_phase = 2
self.interpolate_raster_dialog = InterpolateRasterDialog()
self.interpolate_raster_dialog.show()