diff options
Diffstat (limited to 'silx/gui/plot3d/SFViewParamTree.py')
-rw-r--r-- | silx/gui/plot3d/SFViewParamTree.py | 142 |
1 files changed, 90 insertions, 52 deletions
diff --git a/silx/gui/plot3d/SFViewParamTree.py b/silx/gui/plot3d/SFViewParamTree.py index 38d4e37..8b144df 100644 --- a/silx/gui/plot3d/SFViewParamTree.py +++ b/silx/gui/plot3d/SFViewParamTree.py @@ -30,15 +30,18 @@ from __future__ import absolute_import __authors__ = ["D. N."] __license__ = "MIT" -__date__ = "10/01/2017" +__date__ = "02/10/2017" import logging import sys +import weakref import numpy from silx.gui import qt from silx.gui.icons import getQIcon +from silx.gui.plot.Colormap import Colormap +from silx.gui.widgets.FloatEdit import FloatEdit from .ScalarFieldView import Isosurface @@ -111,14 +114,20 @@ class SubjectItem(qt.QStandardItem): value = setValue super(SubjectItem, self).setData(value, role) - subject = property(lambda self: self.__subject) + @property + def subject(self): + """The subject this item is observing""" + return None if self.__subject is None else self.__subject() @subject.setter def subject(self, subject): if self.__subject is not None: raise ValueError('Subject already set ' ' (subject change not supported).') - self.__subject = subject + if subject is None: + self.__subject = None + else: + self.__subject = weakref.ref(subject) if subject is not None: self._init() self._connectSignals() @@ -343,6 +352,44 @@ class HighlightColorItem(ColorItem): return self.subject.getHighlightColor() +class BoundingBoxItem(SubjectItem): + """Bounding box, axes labels and grid visibility item. + + Item is checkable. + """ + itemName = 'Bounding Box' + + def _init(self): + visible = self.subject.isBoundingBoxVisible() + self.setCheckable(True) + self.setCheckState(qt.Qt.Checked if visible else qt.Qt.Unchecked) + + def leftClicked(self): + checked = (self.checkState() == qt.Qt.Checked) + if checked != self.subject.isBoundingBoxVisible(): + self.subject.setBoundingBoxVisible(checked) + + +class OrientationIndicatorItem(SubjectItem): + """Orientation indicator visibility item. + + Item is checkable. + """ + itemName = 'Axes indicator' + + def _init(self): + plot3d = self.subject.getPlot3DWidget() + visible = plot3d.isOrientationIndicatorVisible() + self.setCheckable(True) + self.setCheckState(qt.Qt.Checked if visible else qt.Qt.Unchecked) + + def leftClicked(self): + plot3d = self.subject.getPlot3DWidget() + checked = (self.checkState() == qt.Qt.Checked) + if checked != plot3d.isOrientationIndicatorVisible(): + plot3d.setOrientationIndicatorVisible(checked) + + class ViewSettingsItem(qt.QStandardItem): """Viewport settings""" @@ -352,7 +399,9 @@ class ViewSettingsItem(qt.QStandardItem): self.setEditable(False) - classes = BackgroundColorItem, ForegroundColorItem, HighlightColorItem + classes = (BackgroundColorItem, ForegroundColorItem, + HighlightColorItem, + BoundingBoxItem, OrientationIndicatorItem) for cls in classes: titleItem = qt.QStandardItem(cls.itemName) titleItem.setEditable(False) @@ -534,8 +583,8 @@ class _IsoLevelSlider(qt.QSlider): """Set slider from iso-surface level""" dataRange = self.subject.parent().getDataRange() - if dataRange is not None and None not in dataRange: - width = dataRange[1] - dataRange[0] + if dataRange is not None: + width = dataRange[-1] - dataRange[0] if width > 0: sliderWidth = self.maximum() - self.minimum() sliderPosition = sliderWidth * (level - dataRange[0]) / width @@ -548,10 +597,12 @@ class _IsoLevelSlider(qt.QSlider): def __sliderReleased(self): value = self.value() dataRange = self.subject.parent().getDataRange() - width = dataRange[1] - dataRange[0] - sliderWidth = self.maximum() - self.minimum() - level = dataRange[0] + width * value / sliderWidth - self.subject.setLevel(level) + if dataRange is not None: + min_, _, max_ = dataRange + width = max_ - min_ + sliderWidth = self.maximum() - self.minimum() + level = min_ + width * value / sliderWidth + self.subject.setLevel(level) class IsoSurfaceLevelSlider(IsoSurfaceLevelItem): @@ -771,7 +822,8 @@ class IsoSurfaceAddRemoveWidget(qt.QWidget): if dataRange is None: dataRange = [0, 1] - sfview.addIsosurface(numpy.mean(dataRange), '#0000FF') + sfview.addIsosurface( + numpy.mean((dataRange[0], dataRange[-1])), '#0000FF') def __removeClicked(self): self.sigViewTask.emit('remove_iso') @@ -867,30 +919,24 @@ class PlaneMinRangeItem(ColormapBase): self._setVMin(value) def _setVMin(self, value): - cutPlane = self.subject.getCutPlanes()[0] - colormap = cutPlane.getColormap() + colormap = self.subject.getCutPlanes()[0].getColormap() vMin = value vMax = colormap.getVMax() if vMax is not None and value > vMax: vMin = vMax vMax = value - cutPlane.setColormap(name=colormap.getName(), - norm=colormap.getNorm(), - vmin=vMin, - vmax=vMax) + colormap.setVRange(vMin, vMax) def getEditor(self, parent, option, index): - editor = qt.QLineEdit(parent) - editor.setValidator(qt.QDoubleValidator()) - return editor + return FloatEdit(parent) def setEditorData(self, editor): - editor.setText(str(self._pullData())) + editor.setValue(self._pullData()) return True def _setModelData(self, editor): - value = float(editor.text()) + value = editor.value() self._setVMin(value) return True @@ -910,29 +956,23 @@ class PlaneMaxRangeItem(ColormapBase): return self.subject.getCutPlanes()[0].getColormap().getVMax() def _setVMax(self, value): - cutPlane = self.subject.getCutPlanes()[0] - colormap = cutPlane.getColormap() + colormap = self.subject.getCutPlanes()[0].getColormap() vMin = colormap.getVMin() vMax = value if vMin is not None and value < vMin: vMax = vMin vMin = value - cutPlane.setColormap(name=colormap.getName(), - norm=colormap.getNorm(), - vmin=vMin, - vmax=vMax) + colormap.setVRange(vMin, vMax) def getEditor(self, parent, option, index): - editor = qt.QLineEdit(parent) - editor.setValidator(qt.QDoubleValidator()) - return editor + return FloatEdit(parent) def setEditorData(self, editor): editor.setText(str(self._pullData())) return True def _setModelData(self, editor): - value = float(editor.text()) + value = editor.value() self._setVMax(value) return True @@ -1028,7 +1068,8 @@ class PlaneColormapItem(ColormapBase): listValues = ['gray', 'reversed gray', 'temperature', 'red', - 'green', 'blue'] + 'green', 'blue', + 'viridis', 'magma', 'inferno', 'plasma'] def getEditor(self, parent, option, index): editor = qt.QComboBox(parent) @@ -1038,17 +1079,18 @@ class PlaneColormapItem(ColormapBase): return editor def __editorChanged(self, index): - colorMapName = self.listValues[index] - colorMap = self.subject.getCutPlanes()[0].getColormap() - self.subject.getCutPlanes()[0].setColormap(name=colorMapName, - norm=colorMap.getNorm(), - vmin=colorMap.getVMin(), - vmax=colorMap.getVMax()) + colormapName = self.listValues[index] + colormap = self.subject.getCutPlanes()[0].getColormap() + colormap.setName(colormapName) def setEditorData(self, editor): colormapName = self.subject.getCutPlanes()[0].getColormap().getName() - index = self.listValues.index(colormapName) - editor.setCurrentIndex(index) + try: + index = self.listValues.index(colormapName) + except ValueError: + _logger.error('Unsupported colormap: %s', colormapName) + else: + editor.setCurrentIndex(index) return True def _setModelData(self, editor): @@ -1078,22 +1120,18 @@ class PlaneAutoScaleItem(ColormapBase): def _setAutoScale(self, auto): view3d = self.subject - cutPlane = view3d.getCutPlanes()[0] - colormap = cutPlane.getColormap() + colormap = view3d.getCutPlanes()[0].getColormap() if auto != colormap.isAutoscale(): if auto: vMin = vMax = None else: dataRange = view3d.getDataRange() - if dataRange is None or None in dataRange: + if dataRange is None: vMin = vMax = None else: - vMin, vMax = dataRange - cutPlane.setColormap(colormap.getName(), - colormap.getNorm(), - vMin, - vMax) + vMin, vMax = dataRange[0], dataRange[-1] + colormap.setVRange(vMin, vMax) def _pullData(self): auto = self.subject.getCutPlanes()[0].getColormap().isAutoscale() @@ -1111,7 +1149,7 @@ class NormalizationNode(ColormapBase): Item is a QComboBox. """ editable = True - listValues = ['linear', 'log'] + listValues = list(Colormap.NORMALIZATIONS) def getEditor(self, parent, option, index): editor = qt.QComboBox(parent) @@ -1129,7 +1167,7 @@ class NormalizationNode(ColormapBase): vmax=colorMap.getVMax()) def setEditorData(self, editor): - normalization = self.subject.getCutPlanes()[0].getColormap().getNorm() + normalization = self.subject.getCutPlanes()[0].getColormap().getNormalization() index = self.listValues.index(normalization) editor.setCurrentIndex(index) return True @@ -1139,7 +1177,7 @@ class NormalizationNode(ColormapBase): return True def _pullData(self): - return self.subject.getCutPlanes()[0].getColormap().getNorm() + return self.subject.getCutPlanes()[0].getColormap().getNormalization() class PlaneGroup(SubjectItem): |