summaryrefslogtreecommitdiff
path: root/silx/gui/plot3d/_model/items.py
diff options
context:
space:
mode:
Diffstat (limited to 'silx/gui/plot3d/_model/items.py')
-rw-r--r--silx/gui/plot3d/_model/items.py96
1 files changed, 85 insertions, 11 deletions
diff --git a/silx/gui/plot3d/_model/items.py b/silx/gui/plot3d/_model/items.py
index 9fe3e51..7f3921a 100644
--- a/silx/gui/plot3d/_model/items.py
+++ b/silx/gui/plot3d/_model/items.py
@@ -45,7 +45,7 @@ from ...utils.image import convertArrayToQImage
from ...colors import preferredColormaps
from ... import qt, icons
from .. import items
-from ..items.volume import Isosurface, CutPlane
+from ..items.volume import Isosurface, CutPlane, ComplexIsosurface
from ..Plot3DWidget import Plot3DWidget
@@ -867,6 +867,17 @@ class ColormapRow(_ColormapBaseProxyRow):
self._sigColormapChanged.connect(self._updateColormapImage)
+ def getColormapImage(self):
+ """Returns image representing the colormap or None
+
+ :rtype: Union[QImage,None]
+ """
+ if self._colormapImage is None and self._colormap is not None:
+ image = numpy.zeros((16, 130, 3), dtype=numpy.uint8)
+ image[1:-1, 1:-1] = self._colormap.getNColors(image.shape[1] - 2)[:, :3]
+ self._colormapImage = convertArrayToQImage(image)
+ return self._colormapImage
+
def _get(self):
"""Getter for ProxyRow subclass"""
return None
@@ -908,13 +919,9 @@ class ColormapRow(_ColormapBaseProxyRow):
def data(self, column, role):
if column == 1 and role == qt.Qt.DecorationRole:
- if self._colormapImage is None:
- image = numpy.zeros((16, 130, 3), dtype=numpy.uint8)
- image[1:-1, 1:-1] = self._colormap.getNColors(image.shape[1] - 2)[:, :3]
- self._colormapImage = convertArrayToQImage(image)
- return self._colormapImage
-
- return super(ColormapRow, self).data(column, role)
+ return self.getColormapImage()
+ else:
+ return super(ColormapRow, self).data(column, role)
class SymbolRow(ItemProxyRow):
@@ -1055,12 +1062,12 @@ class ComplexModeRow(ItemProxyRow):
:param Item3D item: Scene item with symbol property
"""
- def __init__(self, item):
+ def __init__(self, item, name='Mode'):
names = [m.value.replace('_', ' ').title()
for m in item.supportedComplexModes()]
super(ComplexModeRow, self).__init__(
item=item,
- name='Mode',
+ name=name,
fget=item.getComplexMode,
fset=item.setComplexMode,
events=items.ItemChangedType.COMPLEX_MODE,
@@ -1283,6 +1290,71 @@ class IsosurfaceRow(Item3DRow):
return super(IsosurfaceRow, self).setData(column, value, role)
+class ComplexIsosurfaceRow(IsosurfaceRow):
+ """Represents an :class:`ComplexIsosurface` item.
+
+ :param ComplexIsosurface item:
+ """
+
+ _EVENTS = (items.ItemChangedType.VISIBLE,
+ items.ItemChangedType.COLOR,
+ items.ItemChangedType.COMPLEX_MODE)
+ """Events for which to update the first column in the tree"""
+
+ def __init__(self, item):
+ super(ComplexIsosurfaceRow, self).__init__(item)
+
+ self.addRow(ComplexModeRow(item, "Color Complex Mode"), index=1)
+ for row in self.children():
+ if isinstance(row, ColorProxyRow):
+ self._colorRow = row
+ break
+ else:
+ raise RuntimeError("Cannot retrieve Color tree row")
+ self._colormapRow = ColormapRow(item)
+
+ self.__updateRowsForItem(item)
+ item.sigItemChanged.connect(self.__itemChanged)
+
+ def __itemChanged(self, event):
+ """Update enabled/disabled rows"""
+ if event == items.ItemChangedType.COMPLEX_MODE:
+ item = self.sender()
+ self.__updateRowsForItem(item)
+
+ def __updateRowsForItem(self, item):
+ """Update rows for item
+
+ :param item:
+ """
+ if not isinstance(item, ComplexIsosurface):
+ return
+
+ if item.getComplexMode() == items.ComplexMixIn.ComplexMode.NONE:
+ removed = self._colormapRow
+ added = self._colorRow
+ else:
+ removed = self._colorRow
+ added = self._colormapRow
+
+ # Remove unwanted rows
+ if removed in self.children():
+ self.removeRow(removed)
+
+ # Add required rows
+ if added not in self.children():
+ self.addRow(added, index=2)
+
+ def data(self, column, role):
+ if column == 0 and role == qt.Qt.DecorationRole:
+ item = self.item()
+ if (item is not None and
+ item.getComplexMode() != items.ComplexMixIn.ComplexMode.NONE):
+ return self._colormapRow.getColormapImage()
+
+ return super(ComplexIsosurfaceRow, self).data(column, role)
+
+
class AddIsosurfaceRow(BaseRow):
"""Class for Isosurface create button
@@ -1358,7 +1430,7 @@ class VolumeIsoSurfacesRow(StaticRow):
volume.sigIsosurfaceRemoved.connect(self._isosurfaceRemoved)
if isinstance(volume, items.ComplexMixIn):
- self.addRow(ComplexModeRow(volume))
+ self.addRow(ComplexModeRow(volume, "Complex Mode"))
for item in volume.getIsosurfaces():
self.addRow(nodeFromItem(item))
@@ -1581,6 +1653,8 @@ def nodeFromItem(item):
# Item with specific model row class
if isinstance(item, (items.GroupItem, items.GroupWithAxesItem)):
return GroupItemRow(item)
+ elif isinstance(item, ComplexIsosurface):
+ return ComplexIsosurfaceRow(item)
elif isinstance(item, Isosurface):
return IsosurfaceRow(item)