mirror of https://github.com/silx-kit/pyFAI.git
Save the geometry when using buttons
This commit is contained in:
parent
83e9f06b5f
commit
83bc9c0291
|
@ -43,7 +43,7 @@ class StoredGeometry(AbstractModel):
|
|||
:param float rms:
|
||||
"""
|
||||
|
||||
def __init__(self, parent, time, geometry, rms):
|
||||
def __init__(self, parent, label, time, geometry, rms):
|
||||
super(StoredGeometry, self).__init__(parent=parent)
|
||||
# Store this values in a compact format
|
||||
d = geometry.distance().value()
|
||||
|
@ -54,6 +54,7 @@ class StoredGeometry(AbstractModel):
|
|||
r2 = geometry.rotation2().value()
|
||||
r3 = geometry.rotation3().value()
|
||||
self.__geometry = (d, w, p1, p2, r1, r2, r3)
|
||||
self.__label = label
|
||||
self.__rms = rms
|
||||
self.__time = time
|
||||
|
||||
|
@ -72,6 +73,12 @@ class StoredGeometry(AbstractModel):
|
|||
geometry.rotation3().setValue(r3)
|
||||
return geometry
|
||||
|
||||
def label(self):
|
||||
"""
|
||||
:rtype: str
|
||||
"""
|
||||
return self.__label
|
||||
|
||||
def rms(self):
|
||||
"""
|
||||
:rtype: float
|
||||
|
@ -87,10 +94,11 @@ class StoredGeometry(AbstractModel):
|
|||
|
||||
class GeometryHistoryModel(ListModel):
|
||||
|
||||
def appendGeometry(self, time, geometry, rms):
|
||||
def appendGeometry(self, label, time, geometry, rms):
|
||||
"""
|
||||
:param str label: Named geometry
|
||||
:param datetime.datetime time: time of the record
|
||||
:param GeometryModel geometry: Geometry to store
|
||||
:param float rms: Root mean share of this geometry
|
||||
"""
|
||||
self.append(StoredGeometry(self, time, geometry, rms))
|
||||
self.append(StoredGeometry(self, label, time, geometry, rms))
|
||||
|
|
|
@ -633,6 +633,14 @@ class GeometryTask(AbstractCalibrationTask):
|
|||
|
||||
def __initGeometry(self):
|
||||
self.__initGeometryFromPeaks()
|
||||
|
||||
# Save this geometry into the history
|
||||
calibration = self.__getCalibration()
|
||||
geometry = self.model().fittedGeometry()
|
||||
rms = None if calibration is None else calibration.getRms()
|
||||
geometryHistory = self.model().geometryHistoryModel()
|
||||
geometryHistory.appendGeometry("Init", datetime.datetime.now(), geometry, rms)
|
||||
|
||||
self.__formatResidual()
|
||||
self.__unsetProcessing()
|
||||
|
||||
|
@ -642,9 +650,14 @@ class GeometryTask(AbstractCalibrationTask):
|
|||
self.__unsetProcessing()
|
||||
return
|
||||
self.__initGeometryFromPeaks()
|
||||
# write result to the fitted model
|
||||
model = self.model().fittedGeometry()
|
||||
calibration.toGeometryModel(model)
|
||||
# write result to the fitted geometry
|
||||
geometry = self.model().fittedGeometry()
|
||||
calibration.toGeometryModel(geometry)
|
||||
|
||||
# Save this geometry into the history
|
||||
geometryHistory = self.model().geometryHistoryModel()
|
||||
geometryHistory.appendGeometry("Reset", datetime.datetime.now(), geometry, calibration.getRms())
|
||||
|
||||
self.__formatResidual()
|
||||
self.__unsetProcessing()
|
||||
|
||||
|
@ -670,6 +683,10 @@ class GeometryTask(AbstractCalibrationTask):
|
|||
geometry = self.model().fittedGeometry()
|
||||
calibration.toGeometryModel(geometry)
|
||||
|
||||
# Save this geometry into the history
|
||||
geometryHistory = self.model().geometryHistoryModel()
|
||||
geometryHistory.appendGeometry("Fitting", datetime.datetime.now(), geometry, calibration.getRms())
|
||||
|
||||
self._fitButton.setWaiting(False)
|
||||
self.__fitting = False
|
||||
self.__unsetProcessing()
|
||||
|
@ -707,10 +724,6 @@ class GeometryTask(AbstractCalibrationTask):
|
|||
return
|
||||
model = self.model().fittedGeometry()
|
||||
if model.isValid():
|
||||
# Save this geometry into the history
|
||||
geometryHistory = self.model().geometryHistoryModel()
|
||||
geometryHistory.appendGeometry(datetime.datetime.now(), model, calibration.getRms())
|
||||
|
||||
resetResidual = self.__fitting is not True
|
||||
calibration.fromGeometryModel(model, resetResidual=resetResidual)
|
||||
self.__updateDisplay()
|
||||
|
|
|
@ -42,7 +42,8 @@ _logger = logging.getLogger(__name__)
|
|||
class _GeometryListModel(qt.QAbstractItemModel):
|
||||
|
||||
TimeColumn = 0
|
||||
RmsColumn = 1
|
||||
LabelColumn = 1
|
||||
RmsColumn = 2
|
||||
|
||||
def __init__(self, parent, historyModel):
|
||||
qt.QAbstractItemModel.__init__(self, parent=parent)
|
||||
|
@ -50,6 +51,14 @@ class _GeometryListModel(qt.QAbstractItemModel):
|
|||
self.__historyModel = historyModel
|
||||
self.__historyModel.changed[object].connect(self.__historyChanged)
|
||||
|
||||
def item(self, index):
|
||||
"""
|
||||
Returns an item from an index.
|
||||
"""
|
||||
if not index.isValid():
|
||||
return None
|
||||
return self.__historyModel[index.row()]
|
||||
|
||||
def __historyChanged(self, events):
|
||||
if events.hasOnlyStructuralEvents():
|
||||
if len(events) == 1 and events[0].added:
|
||||
|
@ -82,7 +91,7 @@ class _GeometryListModel(qt.QAbstractItemModel):
|
|||
return len(self.__historyModel)
|
||||
|
||||
def columnCount(self, parent=qt.QModelIndex()):
|
||||
return 2
|
||||
return 3
|
||||
|
||||
def data(self, index, role=qt.Qt.DisplayRole):
|
||||
if not index.isValid():
|
||||
|
@ -92,11 +101,16 @@ class _GeometryListModel(qt.QAbstractItemModel):
|
|||
if role == qt.Qt.DisplayRole:
|
||||
column = index.column()
|
||||
if column == self.RmsColumn:
|
||||
value = stringutil.to_scientific_unicode(item.rms())
|
||||
rms = item.rms()
|
||||
if rms is None:
|
||||
return "n/a"
|
||||
value = stringutil.to_scientific_unicode(rms)
|
||||
return value
|
||||
elif column == self.TimeColumn:
|
||||
time = item.time()
|
||||
return time.strftime("%Hh%M %Ss")
|
||||
elif column == self.LabelColumn:
|
||||
return item.label()
|
||||
else:
|
||||
return ""
|
||||
|
||||
|
@ -122,6 +136,11 @@ class GeometryHistoryComboBox(AdvancedComboBox):
|
|||
return None
|
||||
return None
|
||||
|
||||
def currentItem(self):
|
||||
model = self.model()
|
||||
index = model.index(self.currentIndex(), 0)
|
||||
return model.item(index)
|
||||
|
||||
def setHistoryModel(self, historyModel):
|
||||
model = _GeometryListModel(self, historyModel)
|
||||
self.setModel(model)
|
||||
|
|
Loading…
Reference in New Issue