|
2 | 2 | from typing import Optional, Union |
3 | 3 |
|
4 | 4 | import numpy as np |
5 | | -from PyQt5.QtWidgets import QMenu, QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget |
6 | | - |
7 | 5 | from LoopStructural.datatypes import VectorPoints |
| 6 | +from PyQt5.QtWidgets import QMenu, QPushButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget |
8 | 7 |
|
9 | 8 | logger = logging.getLogger(__name__) |
10 | 9 |
|
@@ -277,6 +276,33 @@ def _log(msg, level=0): |
277 | 276 | feature_name = None |
278 | 277 | if event == 'feature_updated' and len(args) >= 1: |
279 | 278 | 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 | + |
280 | 306 | # Build a set of features that currently have viewer meshes |
281 | 307 | affected_features = set() |
282 | 308 | for _, meta in list(self.viewer.meshes.items()): |
|
0 commit comments