Skip to content

Commit 997f022

Browse files
authored
feat: model step and direct interpolation (usability plan, phase 4) (#135)
* feat: model step with one build button and direct interpolation Phase 4 of the usability plan. - One primary button replaces Initialize Model, Solve Model and Update Model Data. Its text and action come from the model state. The problems of all steps show above the feature list. - A build calculates out-of-date basal contacts and thicknesses first, on a background task with progress. With "Calculate from geology polygons" the model reads the extracted contacts directly; the project layer is for display only. - Start choice: build from a geological map, or interpolate surfaces from constraints (hides steps 2 and 3). Saved with the state. - Constraint types: value, interface, gradient/normal, tangent, form line, inequality and pairwise inequality, each with a weight and a Z source (layer, DEM or constant). - Detach a generated feature to keep a fixed copy of its data. Rows added to a generated feature are now used in the build. - Preview one feature as isolines on the map. - Add Fault from a centre, strike, dip and size. * style: fix the ruff errors in the step bar - Make the step titles with dict(). - Rename the unused loop variable. * fix: give the new contacts to the thickness step of a build - When the contacts and the thicknesses are calculated together, the thickness calculation uses the new contacts, not the out-of-date layer. - The background thread does not change the data manager. finish() puts the contacts into the model on the GUI thread. - Read the inputs with basal_contacts_inputs() and thickness_inputs() without arguments. #134 changed these functions, so the build failed. - qgsLayerToGeoDataFrame accepts a GeoDataFrame. - Add unit tests for the order and for the thread rule. * fix: name the fault sizes from the slip, as LoopStructural uses them LoopStructural puts the major axis along cross(normal, slip) and the intermediate axis along the slip. The dialog said along strike and down dip, which is correct only for dip slip. The labels are now "across the slip" and "along the slip". Add axis_vectors() and tests for the axes. * fix: added rows of a generated feature - A row that the user adds to or deletes from a generated feature makes the model stale, so that the next action is a rebuild. - A bad added row is left out, and the build tells the user. Before, one bad row removed all the added rows of the feature. - Inequality and Pairwise Inequality have no weight, because LoopStructural ignores it. - Test the save and load of detached data through JSON.
1 parent 4308354 commit 997f022

27 files changed

Lines changed: 3336 additions & 382 deletions

‎docs/development/usability-plan.md‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,27 +304,27 @@ Acceptance: a new user can go from an empty project to a solved model with the
304304

305305
### Phase 4: Model step and direct interpolation
306306

307-
- [ ] Replace "Initialize Model", "Solve Model" and "Update Model Data" with one
307+
- [x] Replace "Initialize Model", "Solve Model" and "Update Model Data" with one
308308
primary button. Its text and action come from the model state.
309-
- [ ] Show the problems from all steps before the build.
310-
- [ ] Before the build, calculate all out-of-date derived data again: basal
309+
- [x] Show the problems from all steps before the build.
310+
- [x] Before the build, calculate all out-of-date derived data again: basal
311311
contacts first, then calculated thicknesses. Run this in a background
312312
task with progress. If the calculation fails, stop the build and show
313313
the error.
314-
- [ ] With "Calculate from geology polygons", give the extracted contacts
314+
- [x] With "Calculate from geology polygons", give the extracted contacts
315315
directly to the model. Update the project contacts layer for display
316316
only.
317-
- [ ] Add the start choice: "Build from a geological map" or "Interpolate
317+
- [x] Add the start choice: "Build from a geological map" or "Interpolate
318318
surfaces from constraints". Save the choice with the state.
319-
- [ ] Constraint list for each feature: source layer, constraint type, field
319+
- [x] Constraint list for each feature: source layer, constraint type, field
320320
mapping, weight, Z source (layer Z, DEM or constant).
321-
- [ ] Add the constraint types: value, interface, gradient/normal, tangent,
321+
- [x] Add the constraint types: value, interface, gradient/normal, tangent,
322322
inequality, pairwise inequality.
323-
- [ ] Show generated constraints as read-only rows. Add "Detach" to make a
323+
- [x] Show generated constraints as read-only rows. Add "Detach" to make a
324324
generated feature editable.
325-
- [ ] Build and preview one feature: an isoline on the map canvas, or a surface
325+
- [x] Build and preview one feature: an isoline on the map canvas, or a surface
326326
in the 3D view.
327-
- [ ] Implement "Add Fault" in the model step.
327+
- [x] Implement "Add Fault" in the model step.
328328

329329
Files: `geological_model_tab/*.py`, `layer_selection_table.py`,
330330
`feature_details_panel/*.py`, `main/model_manager.py`.
@@ -363,9 +363,10 @@ model, the model uses basal contacts and thicknesses that match the new order.
363363
done), or only a guide? Recommendation: only a guide. Show problems, but do
364364
not lock steps.
365365
2. Is the Data Conversion dialog part of step 1, or a separate tool?
366-
3. In direct mode, which constraint types does each interpolator (FDI, PLI,
367-
surfe) support? The UI must hide types that the selected interpolator does
368-
not support.
366+
3. ~~In direct mode, which constraint types does each interpolator (FDI, PLI,
367+
surfe) support?~~ Resolved: all interpolators accept the same constraint
368+
types. LoopStructural converts them as needed. The UI shows the same types
369+
for every interpolator and does not hide any.
369370
4. Is there a minimum QGIS version for the new widgets?
370371
5. Must the Processing algorithms also use the derived-data record, or only
371372
the dock? Recommendation: only the dock. Processing runs are single runs
Lines changed: 138 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,150 @@
1-
import os
1+
from qgis.PyQt.QtWidgets import (
2+
QDialog,
3+
QDialogButtonBox,
4+
QDoubleSpinBox,
5+
QFormLayout,
6+
QGroupBox,
7+
QHBoxLayout,
8+
QLabel,
9+
QLineEdit,
10+
QVBoxLayout,
11+
)
212

3-
from qgis.PyQt.QtWidgets import QDialog
4-
from qgis.PyQt.uic import loadUi
13+
from ....main import parametric_fault
14+
15+
16+
def _spin(low, high, decimals=2, step=1.0):
17+
spin = QDoubleSpinBox()
18+
spin.setRange(low, high)
19+
spin.setDecimals(decimals)
20+
spin.setSingleStep(step)
21+
return spin
522

623

724
class AddFaultDialog(QDialog):
8-
def __init__(self, parent=None):
25+
"""Ask for a fault that is given by numbers: a centre, a strike, a dip and a size.
26+
27+
Faults that have a trace on the map come from the fault layer in step 3.
28+
The start values come from the bounding box of the model.
29+
"""
30+
31+
def __init__(self, parent=None, *, model_manager=None):
932
super().__init__(parent)
10-
ui_path = os.path.join(os.path.dirname(__file__), 'add_fault_dialog.ui')
11-
loadUi(ui_path, self)
12-
self.setWindowTitle('Add Fault Feature')
13-
# You can access widgets by their objectName from the .ui file
14-
# Example: self.strike_input, self.dip_input, etc.
33+
self.model_manager = model_manager
34+
self.setWindowTitle('Add Fault')
35+
36+
layout = QVBoxLayout(self)
37+
name_form = QFormLayout()
38+
self.name_input = QLineEdit()
39+
name_form.addRow("Name:", self.name_input)
40+
layout.addLayout(name_form)
41+
42+
orientation = QGroupBox("Orientation")
43+
form = QFormLayout(orientation)
44+
self.strike_input = _spin(0, 360)
45+
self.strike_input.setToolTip("Degrees clockwise from north. The fault dips to the right.")
46+
self.dip_input = _spin(0.01, 90)
47+
self.pitch_input = _spin(-180, 180)
48+
self.pitch_input.setToolTip(
49+
"The angle of the slip in the fault plane, from the strike direction towards "
50+
"the down-dip direction. 0 is strike-slip. 90 is dip-slip."
51+
)
52+
self.displacement_input = _spin(-1e9, 1e9)
53+
self.displacement_input.setToolTip("The size of the slip, in model units.")
54+
form.addRow("Strike (°):", self.strike_input)
55+
form.addRow("Dip (°):", self.dip_input)
56+
form.addRow("Pitch (°):", self.pitch_input)
57+
form.addRow("Displacement:", self.displacement_input)
58+
layout.addWidget(orientation)
59+
60+
position = QGroupBox("Position")
61+
form = QFormLayout(position)
62+
centre_row = QHBoxLayout()
63+
self.centre_inputs = [_spin(-1e9, 1e9) for _ in range(3)]
64+
for label, spin in zip("XYZ", self.centre_inputs):
65+
centre_row.addWidget(QLabel(label))
66+
centre_row.addWidget(spin)
67+
form.addRow("Centre:", centre_row)
68+
layout.addWidget(position)
69+
70+
size = QGroupBox("Size")
71+
form = QFormLayout(size)
72+
self.major_input = _spin(0.01, 1e9)
73+
self.major_input.setToolTip(
74+
"The full length of the fault in its plane, at right angles to the slip. "
75+
"With a pitch of 90 (dip slip), this is along the strike."
76+
)
77+
self.intermediate_input = _spin(0.01, 1e9)
78+
self.intermediate_input.setToolTip(
79+
"How far the fault extends from the centre in the direction of the slip. "
80+
"With a pitch of 90 (dip slip), this is down the dip."
81+
)
82+
self.minor_input = _spin(0.01, 1e9)
83+
self.minor_input.setToolTip("How far the fault changes the field, across the fault.")
84+
form.addRow("Length across the slip:", self.major_input)
85+
form.addRow("Extent along the slip:", self.intermediate_input)
86+
form.addRow("Influence distance:", self.minor_input)
87+
layout.addWidget(size)
88+
89+
self.problem_label = QLabel()
90+
self.problem_label.setWordWrap(True)
91+
layout.addWidget(self.problem_label)
92+
self.button_box = QDialogButtonBox(
93+
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
94+
)
95+
self.button_box.accepted.connect(self.accept)
96+
self.button_box.rejected.connect(self.reject)
97+
layout.addWidget(self.button_box)
98+
99+
self._set_start_values()
100+
for spin in (
101+
self.strike_input,
102+
self.dip_input,
103+
self.pitch_input,
104+
self.displacement_input,
105+
self.major_input,
106+
self.intermediate_input,
107+
self.minor_input,
108+
*self.centre_inputs,
109+
):
110+
spin.valueChanged.connect(self._validate)
111+
self.name_input.textChanged.connect(self._validate)
112+
self._validate()
113+
114+
def _set_start_values(self):
115+
model = getattr(self.model_manager, 'model', None)
116+
box = getattr(model, 'bounding_box', None)
117+
if box is None:
118+
spec = parametric_fault.default_spec([0, 0, 0], [1000, 1000, 1000])
119+
else:
120+
spec = parametric_fault.default_spec(box.origin, box.maximum)
121+
self.strike_input.setValue(spec['strike'])
122+
self.dip_input.setValue(spec['dip'])
123+
self.pitch_input.setValue(spec['pitch'])
124+
self.displacement_input.setValue(spec['displacement'])
125+
for spin, value in zip(self.centre_inputs, spec['centre']):
126+
spin.setValue(value)
127+
self.major_input.setValue(spec['major_axis'])
128+
self.intermediate_input.setValue(spec['intermediate_axis'])
129+
self.minor_input.setValue(spec['minor_axis'])
130+
131+
def _taken_names(self):
132+
return self.model_manager.used_names() if self.model_manager is not None else set()
133+
134+
def _validate(self, *args):
135+
found = parametric_fault.problems(self.get_fault_data(), self._taken_names())
136+
self.problem_label.setText("\n".join(found))
137+
self.button_box.button(QDialogButtonBox.StandardButton.Ok).setEnabled(not found)
15138

16139
def get_fault_data(self):
17140
return {
141+
'name': self.name_input.text().strip(),
18142
'strike': self.strike_input.value(),
19143
'dip': self.dip_input.value(),
20-
'centre': (
21-
self.centre_x_input.value(),
22-
self.centre_y_input.value(),
23-
self.centre_z_input.value(),
24-
),
25-
'ellipsoid_extents': (
26-
self.extent_x_input.value(),
27-
self.extent_y_input.value(),
28-
self.extent_z_input.value(),
29-
),
30-
'displacement': self.displacement_input.value(),
31144
'pitch': self.pitch_input.value(),
32-
'name': self.name_input.text(),
145+
'displacement': self.displacement_input.value(),
146+
'centre': tuple(spin.value() for spin in self.centre_inputs),
147+
'major_axis': self.major_input.value(),
148+
'intermediate_axis': self.intermediate_input.value(),
149+
'minor_axis': self.minor_input.value(),
33150
}

‎loopstructural/gui/modelling/geological_model_tab/add_fault_dialog.ui‎

Lines changed: 0 additions & 141 deletions
This file was deleted.

0 commit comments

Comments
 (0)