Skip to content

Commit 9eb95fd

Browse files
authored
Merge pull request #48 from Loop3D/fix/strat-column-colouring
fix: colour faults using stratigraphic column
2 parents 2f0f667 + 8d958b4 commit 9eb95fd

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

loopstructural/gui/modelling/stratigraphic_column/stratigraphic_column.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ def add_unit(self, *, unit_data=None, create_new=True):
107107
for k in list(unit_data.keys()):
108108
if unit_data[k] is None:
109109
unit_data.pop(k)
110+
print(f"Adding unit with data: {unit_data}")
110111
unit_widget = StratigraphicUnitWidget(**unit_data)
111112
unit_widget.deleteRequested.connect(self.delete_unit) # Connect delete signal
112113
unit_widget.nameChanged.connect(
@@ -116,8 +117,11 @@ def add_unit(self, *, unit_data=None, create_new=True):
116117
unit_widget.thicknessChanged.connect(
117118
lambda: self.update_element(unit_widget)
118119
) # Connect thickness change signal
119-
120+
120121
unit_widget.set_thickness(unit_data.get('thickness', 0.0)) # Set initial thickness
122+
unit_widget.colourChanged.connect(
123+
lambda: self.update_element(unit_widget)
124+
) # Connect colour change signal
121125
item = QListWidgetItem()
122126
item.setSizeHint(unit_widget.sizeHint())
123127
self.unitList.addItem(item)

loopstructural/gui/modelling/stratigraphic_column/stratigraphic_unit.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from typing import Optional
33

4+
import numpy as np
45
from PyQt5 import uic
56
from PyQt5.QtCore import pyqtSignal
67
from PyQt5.QtWidgets import QWidget
@@ -24,12 +25,29 @@ def __init__(
2425
uic.loadUi(os.path.join(os.path.dirname(__file__), "stratigraphic_unit.ui"), self)
2526
self.uuid = uuid
2627
self._name = name if name is not None else ""
27-
self.colour = colour if colour is not None else ""
28+
# Convert colour from RGB tuple or string to Qt-compatible hex string
29+
if colour is not None:
30+
if (
31+
isinstance(colour, tuple)
32+
or isinstance(colour, list)
33+
or isinstance(colour, np.ndarray)
34+
) and len(colour) == 3:
35+
# Convert (r, g, b) to "#RRGGBB"
36+
if all(isinstance(c, float) and 0.0 <= c <= 1.0 for c in colour):
37+
rgb = [int(c * 255) for c in colour]
38+
else:
39+
rgb = [int(c) for c in colour]
40+
self.colour = "#{:02x}{:02x}{:02x}".format(*rgb)
41+
else:
42+
self.colour = str(colour)
43+
else:
44+
self.colour = ""
2845
self.thickness = thickness # Optional thickness attribute
2946
# Add delete button
3047
self.buttonDelete.clicked.connect(self.request_delete)
3148
self.lineEditName.editingFinished.connect(self.onNameChanged)
3249
self.spinBoxThickness.valueChanged.connect(self.onThicknessChanged)
50+
self.setStyleSheet(f"background-color: {self.colour};" if self.colour else "")
3351

3452
@property
3553
def name(self):
@@ -58,7 +76,8 @@ def onColourSelectClicked(self):
5876
color = QColorDialog.getColor()
5977
if color.isValid():
6078
self.colour = color.name()
61-
self.buttonColor.setStyleSheet(f"background-color: {self.colour};")
79+
self.setStyleSheet(f"background-color: {self.colour};")
80+
self.colourChanged.emit(self.colour)
6281

6382
def onThicknessChanged(self, thickness: float):
6483
"""Handle changes to the thickness spinbox.
@@ -84,6 +103,10 @@ def request_delete(self):
84103

85104
self.deleteRequested.emit(self)
86105

106+
def mouseDoubleClickEvent(self, event):
107+
"""Handle double-click event to open color selection dialog."""
108+
self.onColourSelectClicked()
109+
87110
def validateFields(self):
88111
"""Validate the widget fields and update UI hints."""
89112
# Reset all styles first
@@ -111,11 +134,13 @@ def setData(self, data: Optional[dict] = None):
111134
self.name = str(data.get("name", ""))
112135
self.colour = data.get("colour", "")
113136
self.lineEditName.setText(self.name)
137+
self.setStyleSheet(f"background-color: {self.colour};" if self.colour else "")
114138
# self.lineEditColour.setText(self.colour)
115139
else:
116140
self.name = ""
117141
self.colour = ""
118142
self.lineEditName.clear()
143+
self.setStyleSheet("")
119144
# self.lineEditColour.clear()
120145

121146
self.validateFields()

loopstructural/gui/visualisation/feature_list_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ def add_stratigraphic_surfaces(self):
144144
return
145145
stratigraphic_surfaces = self.model_manager.model.get_stratigraphic_surfaces()
146146
for surface in stratigraphic_surfaces:
147-
self.viewer.add_mesh_object(surface.vtk(), name=surface.name)
147+
self.viewer.add_mesh_object(surface.vtk(), name=surface.name,color=surface.colour)
148148
print("Adding stratigraphic surfaces...")

0 commit comments

Comments
 (0)