Skip to content

Commit ed015c3

Browse files
committed
fix: decouple surfaces from model if model has been reset.
1 parent ea99e14 commit ed015c3

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

loopstructural/gui/visualisation/feature_list_widget.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
from typing import Optional, Union
33

44
import numpy as np
5-
from PyQt5.QtWidgets import QMenu, QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
6-
75
from LoopStructural.datatypes import VectorPoints
6+
from PyQt5.QtWidgets import QMenu, QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget
87

98
logger = logging.getLogger(__name__)
109

@@ -277,6 +276,33 @@ def _log(msg, level=0):
277276
feature_name = None
278277
if event == 'feature_updated' and len(args) >= 1:
279278
feature_name = args[0]
279+
280+
# If the model was reset (None) or features referenced by viewer meshes
281+
# no longer exist in the current model, remove the linkage from those
282+
# meshes so they are not treated as feature-driven on subsequent updates.
283+
try:
284+
try:
285+
current_features = {f.name for f in self.model_manager.features()}
286+
except Exception:
287+
current_features = set()
288+
289+
# If the model is None or a feature referenced by a mesh is missing,
290+
# decouple that mesh from the feature so it remains visible but won't
291+
# be auto-updated or re-added when the model changes.
292+
for mesh_name, meta in list(self.viewer.meshes.items()):
293+
sf = meta.get('source_feature', None)
294+
if sf is None:
295+
continue
296+
if self.model_manager.model is None or sf not in current_features:
297+
_log(f"Decoupling mesh '{mesh_name}' from missing feature '{sf}'")
298+
meta.pop('source_feature', None)
299+
meta.pop('source_type', None)
300+
meta.pop('isovalue', None)
301+
# mark as decoupled so other logic can detect it if needed
302+
meta['decoupled_from_feature'] = True
303+
except Exception:
304+
_log('Failed while decoupling meshes from features')
305+
280306
# Build a set of features that currently have viewer meshes
281307
affected_features = set()
282308
for _, meta in list(self.viewer.meshes.items()):

loopstructural/main/model_manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@
1616
import geopandas as gpd
1717
import numpy as np
1818
import pandas as pd
19-
20-
from LoopStructural import GeologicalModel
2119
from LoopStructural.datatypes import BoundingBox
2220
from LoopStructural.modelling.core.fault_topology import FaultRelationshipType
2321
from LoopStructural.modelling.core.stratigraphic_column import StratigraphicColumn
2422
from LoopStructural.modelling.features import FeatureType, StructuralFrame
2523
from LoopStructural.modelling.features.fold import FoldFrame
26-
from loopstructural.toolbelt.preferences import PlgSettingsStructure
2724
from LoopStructural.utils.observer import Observable
2825

26+
from LoopStructural import GeologicalModel
27+
from loopstructural.toolbelt.preferences import PlgSettingsStructure
28+
2929
from ..main.helpers import qgisAttributeIsNone
3030

3131

@@ -482,7 +482,7 @@ def update_model(self, notify_observers: bool = True):
482482
# Update the model with stratigraphy
483483
self.update_fault_features()
484484
self.update_foliation_features()
485-
485+
486486
# Notify observers using the Observable framework if requested
487487
if notify_observers:
488488
self._emit('model_updated')

0 commit comments

Comments
 (0)