Commit 0917dfdd authored by Damien Naudet's avatar Damien Naudet

WIP

parent 8a72d061
......@@ -37,10 +37,12 @@ from .Widgets import (AcqParamsWidget,
# processDoneEvent)
from .process.RecipSpaceWidget import RecipSpaceWidget
from .view.IntensityView import IntensityView
from .view.QspaceView import QSpaceView
from .project.XsocsProject import XsocsProject
from .model.TreeView import TreeView
from .model.Model import Model
from .project.IntensityGroup import IntensityGroup, IntensityItem
from .project.IntensityGroup import IntensityGroup
from .project.QSpaceGroup import QSpaceItem
from .project.XsocsH5Factory import XsocsH5Factory, h5NodeToProjectItem
from .project.Hdf5Nodes import setH5NodeFactory, H5File
from .Utils import nextFileName
......@@ -70,7 +72,7 @@ class XsocsGui(Qt.QMainWindow):
setH5NodeFactory(XsocsH5Factory)
self.__intensityView = None
self.__qspaceView = None
self.__qspaceViews = {}
mdiArea = Qt.QMdiArea()
self.setCentralWidget(mdiArea)
......@@ -100,9 +102,12 @@ class XsocsGui(Qt.QMainWindow):
raise ValueError('Unknwown event for node {0} : {1}.'
''.format(node, event))
if isinstance(projectItem, (IntensityGroup, IntensityItem))\
if isinstance(projectItem, IntensityGroup)\
and event['event'] == 'scatter':
self.__showIntensity(node)
elif isinstance(projectItem, QSpaceItem)\
and event['event'] == 'qspace':
self.__showQSpace(node)
else:
ValueError('Unknwown event for item {0} : {1}.'
''.format(projectItem, event))
......@@ -130,12 +135,21 @@ class XsocsGui(Qt.QMainWindow):
widget.exec_()
if widget.status == RecipSpaceWidget.StatusCompleted:
qspaceF = widget.qspaceH5
qspaceGroup = self.__project.qspaceGroup()
qspaceGroup.addQSpace(qspaceF)
self.model().refresh()
qspaceGroup = self.__project.qspaceGroup()
qspaceGroup.addQSpace(qspaceF)
self.model().reset()
def __showQSpace(self, node):
print node
view = self.__qspaceViews.get(node)
if not view:
view = QSpaceView(self, model=node.model, node=node)
self.__qspaceViews[node] = view
# view.sigProcessApplied.connect(self.__intensityRoiApplied)
view.show()
def model(self):
self.centralWidget().model()
return self.centralWidget().model()
def showEvent(self, event):
super(XsocsGui, self).showEvent(event)
......
......@@ -202,7 +202,6 @@ class Model(Qt.QAbstractItemModel):
for child in children:
child.clear()
print 'adding', child
self.__root.appendChild(child)
def rowCount(self, parent=Qt.QModelIndex(), **kwargs):
......
......@@ -178,6 +178,7 @@ class TreeView(Qt.QTreeView):
else:
self.__userRoot = False
self.__updateUniqueGroupVisibility()
self.__setHiddenNodes(self.rootIndex())
self.__openPersistentEditors(self.rootIndex(), True)
def setModel(self, model):
......
......@@ -254,6 +254,8 @@ class H5DatasetNode(H5Base):
text = data.replace('\n', ' ')
else:
text = str(data)
elif ndims == 1 and item.shape[0] < 5:
text = str(item[:])
else:
text = '...'
del item
......
......@@ -61,6 +61,29 @@ class ScatterPlotButton(EditorMixin, Qt.QWidget):
self.notifyView(event)
class QSpaceButton(EditorMixin, Qt.QWidget):
persistent = True
sigValueChanged = Qt.Signal()
def __init__(self, parent, option, index):
super(QSpaceButton, self).__init__(parent, option, index)
layout = Qt.QHBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
icon = icons.getQIcon('item-ndim')
button = Qt.QToolButton()
button.setIcon(icon)
layout.addWidget(button)
layout.addStretch(1)
button.clicked.connect(self.__clicked)
def __clicked(self):
# node = self.node
event = {'event': 'qspace'}
self.notifyView(event)
@H5NodeClassDef('IntensityGroupNode',
attribute=('XsocsClass', 'IntensityGroup'))
class IntensityGroupNode(H5GroupNode):
......@@ -77,3 +100,9 @@ class IntensityNode(H5DatasetNode):
self.setData(ModelColumns.NameColumn,
str(item.projectRoot().shortName(item.entry)),
Qt.Qt.DisplayRole)
@H5NodeClassDef('QSpaceItem',
attribute=('XsocsClass', 'QSpaceItem'))
class QSpaceItemNode(H5GroupNode):
editors = QSpaceButton
......@@ -31,6 +31,8 @@ __date__ = "15/09/2016"
import os
import numpy as np
# from .ProjectDef import ProcessId
# from .HybridItem import HybridItem
from ...io.QSpaceH5 import QSpaceH5
......@@ -45,6 +47,7 @@ class QSpaceGroup(ProjectItem):
itemPath = self.path + '/' + itemName
item = QSpaceItem(self.filename, itemPath, mode='a')
item.qspaceFile = qspaceFile
return item
@ItemClassDef('QSpaceItem')
......@@ -85,11 +88,31 @@ class QSpaceItem(ProjectItem):
self._createItem()
def _createItem(self):
print 'CREATE', self.qspaceFile
qspaceFile = self.qspaceFile
if qspaceFile is None:
return
with QSpaceH5(qspaceFile) as qspaceH5:
with self:
pathTpl = self.path + '/info/{0}'
with qspaceH5.qspace_dset_ctx() as ctx:
shape = np.array(ctx.shape)
itemPath = pathTpl.format('#')
self._set_scalar_data(itemPath, shape[0])
itemPath = pathTpl.format('shape')
self._set_array_data(itemPath, shape[1:])
qx = qspaceH5.qx
qy = qspaceH5.qy
qz = qspaceH5.qz
itemPath = pathTpl.format('qx range')
self._set_array_data(itemPath, np.array([qx[0], qx[-1]]))
itemPath = pathTpl.format('qy range')
self._set_array_data(itemPath, np.array([qy[0], qy[-1]]))
itemPath = pathTpl.format('qz range')
self._set_array_data(itemPath, np.array([qz[0], qz[-1]]))
# @ItemClassDef('QSpaceItem')
# class QSpaceItem(ProjectItem):
# QSpaceFilePath = 'File'
......
......@@ -197,6 +197,8 @@ class IntensityView(Qt.QMainWindow):
tree.setRootIndex(index)
tree.sigCurrentChanged.connect(self.__itemSelected)
dock.setWidget(tree)
features = dock.features() ^ Qt.QDockWidget.DockWidgetClosable
dock.setFeatures(features)
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, dock)
self.__roiManager = roiManager = ImageRoiManager(plotWindow)
......
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2015-2016 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/
from __future__ import absolute_import
__authors__ = ["D. Naudet"]
__license__ = "MIT"
__date__ = "15/09/2016"
import numpy as np
from matplotlib import cm
from silx.gui import qt as Qt
from silx.gui.plot import PlotWindow
from plot3d.ScalarFieldView import ScalarFieldView
from ...io.QSpaceH5 import QSpaceH5
from ..model.ModelDef import ModelRoles
# from ..project.HybridItem import HybridItem
from ..project.QSpaceGroup import QSpaceItem
from ..model.TreeView import TreeView
class QSpaceTree(TreeView):
pass
# sigCurrentChanged = Qt.Signal(object)
# def __init__(self, *args, **kwargs):
# super(IntensityTree, self).__init__(*args, **kwargs)
# self.disableDelegateForColumn(1, True)
# for col in range(ModelColumns.ColumnMax):
# if col != ModelColumns.NameColumn:
# self.setColumnHidden(col, True)
#
# def currentChanged(self, current, previous):
# node = current.data(ModelRoles.InternalDataRole)
# if not node:
# return
# projectItem = h5NodeToProjectItem(node)
# self.sigCurrentChanged.emit(projectItem)
class QSpaceView(Qt.QMainWindow):
sigProcessApplied = Qt.Signal(object)
plot = property(lambda self: self.__plotWindow)
def __init__(self,
parent,
model,
node,
**kwargs):
super(QSpaceView, self).__init__(parent)
self.__plotWindow = plotWindow = PlotWindow(aspectRatio=True,
curveStyle=False,
mask=False,
roi=False,
**kwargs)
plotWindow.sigPlotSignal.connect(self.__plotSignal)
plotWindow.setKeepDataAspectRatio(True)
plotWindow.setActiveCurveHandling(False)
# self.setCentralWidget(plotWindow)
self.__isoView = None
self.__isoPosition = None
self.__plotType = None
treeDock = Qt.QDockWidget(self)
tree = TreeView(self, model=model)
index = node.index()
tree.setRootIndex(index)
# tree.sigCurrentChanged.connect(self.__itemSelected)
treeDock.setWidget(tree)
features = treeDock.features() ^ Qt.QDockWidget.DockWidgetClosable
treeDock.setFeatures(features)
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, treeDock)
plotDock = Qt.QDockWidget(self)
# tree.sigCurrentChanged.connect(self.__itemSelected)
plotDock.setWidget(plotWindow)
features = plotDock.features() ^ Qt.QDockWidget.DockWidgetClosable
plotDock.setFeatures(features)
self.addDockWidget(Qt.Qt.RightDockWidgetArea, plotDock)
# self.splitDockWidget(treeDock, plotDock, Qt.Qt.Vertical)
def _emitEvent(self, event):
self.sigProcessApplied.emit(event)
# TODO : refactor this in a common base with RealSpaceViewWidget
def setPlotData(self, x, y, data):
plot = self.__plotWindow
if data.ndim == 1:
# scatter
min_, max_ = data.min(), data.max()
colormap = cm.jet
colors = colormap((data.astype(np.float64) - min_) / (max_ - min_))
plot.addCurve(x, y,
color=colors,
symbol='s',
linestyle='')
self.__plotType = 'scatter'
elif data.ndim == 2:
# image
min_, max_ = data.min(), data.max()
colormap = {'name': 'temperature',
'normalization': 'linear',
'autoscale': True,
'vmin': min_,
'vmax': max_}
origin = x[0], y[0]
scale = (x[-1] - x[0]) / len(x), (y[-1] - y[0]) / len(y)
plot.addImage(data,
origin=origin,
scale=scale,
colormap=colormap)
self.__plotType = 'image'
else:
raise ValueError('data has {0} dimensions, expected 1 or 2.'
''.format(data.ndim))
def __plotSignal(self, event):
if event['event'] not in ('curveClicked',): # , 'mouseClicked'):
return
x, y = event['xdata'], event['ydata']
self.__showIsoView(x, y)
def __showIsoView(self, x, y):
print 'SHOW'
# if self.__isoPosition is not None:
# if self.__isoPosition[0] == x and self.__isoPosition[1] == y:
# return
# isoView = self.__isoView
# if isoView is None:
# isoView = IsoViewMainWindow(parent=self)
# if isinstance(self.parent(), Qt.QMdiSubWindow):
# self.parent().mdiArea().addSubWindow(isoView)
# node = self.index.data(ModelRoles.InternalDataRole)
# item = HybridItem(node.projectFile, node.path)
# if item.hasScatter():
# xPos, yPos, _ = item.getScatter()
# elif item.hasImage():
# xPos, yPos, _ = item.getImage()
# else:
# return None
# # TODO : this wont work with images
# try:
# xIdx = (np.abs(xPos - x)).argmin()
# except:
# print x
# xIdx = (np.abs(xPos - x[0])).argmin()
#
# # TODO : this is not robust at all
# qspaceNode = node.parent()
# qspaceItem = QSpaceItem(qspaceNode.projectFile, qspaceNode.path)
# qspaceH5 = QSpaceH5(qspaceItem.qspaceFile)
#
# qspace = qspaceH5.qspace_slice(xIdx)
#
# isoView.setData(qspace)
# self.__isoView = isoView
# isoView.show()
#
# class IsoViewMainWindow(ScalarFieldView):
# """Window displaying an isosurface and some controls."""
#
# def __init__(self, *args, **kwargs):
# super(IsoViewMainWindow, self).__init__(*args, **kwargs)
# self.setAttribute(Qt.Qt.WA_DeleteOnClose)
#
# # Adjust lighting
# self.plot3D.viewport.light.direction = 0., 0., -1.
# self.plot3D.viewport.light.shininess = 32
# self.plot3D.viewport.bgColor = 0.2, 0.2, 0.2, 1.
#
# # Add controller dock widget
# self._control = _Controller(viewer=self)
# self._control.setWindowTitle('Isosurface')
# self.addDockWidget(Qt.Qt.RightDockWidgetArea, self._control)
#
# def setData(self, data, copy=True):
# data = np.asarray(data)
# self._control.setRange(data.min(), data.max())
# super(IsoViewMainWindow, self).setData(data, copy)
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment