QXRD  0.11.16
qxrddetectorcontrolwindow.cpp
Go to the documentation of this file.
2 #include "ui_qxrddetectorcontrolwindow.h"
3 #include "qxrdacquisition.h"
7 #include "qxrdroicalculator.h"
8 #include <QMessageBox>
9 #include <QFileDialog>
10 #include "qxrdroicoordinates.h"
11 #include "qxrdapplication.h"
12 #include "qcepmutexlocker.h"
13 #include "qxrddetector.h"
14 #include "qxrdroitypedelegate.h"
15 
19  QxrdDetectorWPtr det,
21  QWidget *parent) :
22  QxrdMainWindow(parent),
23  m_Saver(saver),
24  m_Experiment(exp),
25  m_Acquisition(acq),
26  m_Detector(det),
27  m_Processor(proc)
28 {
29  setupUi(this);
30 
31  setAttribute(Qt::WA_DeleteOnClose, false);
32 
34  QxrdApplication *app = qobject_cast<QxrdApplication*>(g_Application);
37 
38  if (dp) {
39  dp->prop_DetectorDisplayMode() -> linkTo(m_DetectorDisplayMode);
40  dp->prop_PerformDarkSubtraction() -> linkTo(m_PerformDarkSubtraction);
41  dp->prop_SaveRawImages() -> linkTo(m_SaveRawData);
42  dp->prop_SaveDarkImages() -> linkTo(m_SaveDarkData);
43  dp->prop_PerformBadPixels() -> linkTo(m_BadPixelCorrection);
44  dp->prop_PerformGainCorrection() -> linkTo(m_GainCorrection);
45  dp->prop_SaveSubtracted() -> linkTo(m_SaveSubtractedData);
46 
47  dp->prop_DarkImagePath() -> linkTo(m_DarkImagePath);
48  dp->prop_RawDataSubdir() -> linkTo(m_RawDataSubdir);
49  dp->prop_DarkDataSubdir() -> linkTo(m_DarkDataSubdir);
50  dp->prop_BadPixelsPath() -> linkTo(m_BadPixelPath);
51  dp->prop_GainMapPath() -> linkTo(m_GainCorrectionPath);
52  dp->prop_SubtractedSubdir() -> linkTo(m_SubtractedDataSubdir);
53 
54  dp->prop_MaskPath() -> linkTo(m_MaskImagePath);
55 
56  dp->prop_PerformIntegration() -> linkTo(m_PerformIntegration);
57  dp->prop_DisplayIntegratedData() -> linkTo(m_DisplayIntegratedData);
58  dp->prop_SaveIntegratedData() -> linkTo(m_SaveIntegratedData);
59  dp->prop_IntegratedDataFile() -> linkTo(m_IntegratedDataFile);
60  dp->prop_SaveIntegratedDataSeparate() -> linkTo(m_SaveIntegratedDataSeparate);
61  dp->prop_IntegratedDataSubdir() -> linkTo(m_IntegratedDataSubdir);
62 
63  dp->prop_AccumulateIntegrated2D() -> linkTo(m_AccumulateIntegratedData);
64  dp->prop_AccumulateIntegratedName()-> linkTo(m_AccumulateIntegratedName);
65 
66  dp->prop_CalculateROICounts() -> linkTo(m_CalculateROICounts);
67  dp->prop_DisplayROIBorders() -> linkTo(m_DisplayROIBorders);
68 
69  connect(dp->prop_DisplayROIBorders(), &QcepBoolProperty::valueChanged, this, &QxrdDetectorControlWindow::updateROIDisplay);
70 
71  connect(m_BrowseMask, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doBrowseMask);
72  connect(m_ClearMask, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doClearMask);
73  connect(m_BrowseDarkImage, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doBrowseDark);
74  connect(m_ClearDarkImage, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doClearDark);
75  connect(m_BrowseBadPixels, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doBrowseBadPixels);
76  connect(m_ClearBadPixels, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doClearBadPixels);
77  connect(m_BrowseGainImage, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doBrowseGainCorrection);
78  connect(m_ClearGainImage, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doClearGainCorrection);
79  connect(m_ActionLoadDarkImage, &QAction::triggered, this, &QxrdDetectorControlWindow::doBrowseDark);
80  connect(m_ActionLoadMask, &QAction::triggered, this, &QxrdDetectorControlWindow::doBrowseMask);
81 
82  updateROIDisplay(dp->get_DisplayROIBorders());
83 
84  QxrdROICalculatorPtr calc(dp->roiCalculator());
85 
86  if (calc) {
87  m_ROIModel = calc->roiModel();
88 
89  m_ROIWidget->setItemDelegateForColumn(QxrdROICoordinatesListModel::TypeCol, new QxrdROITypeDelegate());
90  m_ROIWidget->setModel(m_ROIModel.data());
91 
92  connect(m_NewROI, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doAppendROI);
93  connect(m_DeleteROI, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doDeleteROI);
94  connect(m_MoveROIDown, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doMoveROIDown);
95  connect(m_MoveROIUp, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doMoveROIUp);
96 
97  connect(m_RecalculateButton, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doRecalculate);
98  connect(m_VisualizeROIBackground, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doVisualizeBackground);
99  connect(m_VisualizeROIPeak, &QAbstractButton::clicked, this, &QxrdDetectorControlWindow::doVisualizePeak);
100 
101  m_ROIWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
102  }
103 
104  m_DetectorImage->init(dp->imagePlotSettings());
105 
106  m_DetectorImage->setROIModel(m_ROIModel);
107  m_DetectorImage->setROISelection(m_ROIWidget->selectionModel());
108  }
109 
110  if (app) {
111  connect(app->prop_UpdateIntervalMsec(), &QcepIntProperty::valueChanged,
113 
114  connect(&m_UpdateTimer, &QTimer::timeout,
116 
117  m_UpdateTimer.start(app->get_UpdateIntervalMsec());
118  }
119 
120  if (expt) {
121  int fs = expt->get_FontSize();
122  int sp = expt->get_Spacing();
123 
124  if (fs > 0) {
125  setFontSize(fs);
126  }
127 
128  if (sp >= 0) {
129  setSpacing(sp);
130  }
131 
132  connect(expt->prop_FontSize(), &QcepIntProperty::valueChanged, this, &QxrdDetectorControlWindow::setFontSize);
133  connect(expt->prop_Spacing(), &QcepIntProperty::valueChanged, this, &QxrdDetectorControlWindow::setSpacing);
134  }
135 
136  if (dt) {
137  connect(dt->prop_DetectorNumber(), &QcepIntProperty::valueChanged, this, &QxrdDetectorControlWindow::updateWindowTitle);
138  connect(dt->prop_DetectorTypeName(), &QcepStringProperty::valueChanged, this, &QxrdDetectorControlWindow::updateWindowTitle);
139  connect(dt->prop_DetectorName(), &QcepStringProperty::valueChanged, this, &QxrdDetectorControlWindow::updateWindowTitle);
140 
142  }
143 }
144 
146 {
147 #ifndef QT_NO_DEBUG
148  printf("Deleting detector control window\n");
149 #endif
150 }
151 
153 {
155 
156  if (dt) {
157  setWindowTitle(tr("%1: Control %2 detector \"%3\"")
158  .arg(dt->get_DetectorNumber())
159  .arg(dt->get_DetectorTypeName())
160  .arg(dt->get_DetectorName()));
161  }
162 }
163 
165 {
166  QMainWindow::changeEvent(e);
167  switch (e->type()) {
168  case QEvent::LanguageChange:
169  retranslateUi(this);
170  break;
171  default:
172  break;
173  }
174 }
175 
176 void QxrdDetectorControlWindow::printMessage(QString msg, QDateTime ts)
177 {
179 
180  if (acq) {
181  acq->printMessage(msg, ts);
182  }
183 }
184 
186 {
187  QVector<int> res;
188 
189  if (m_ROIModel) {
190  int roiCount = m_ROIModel->rowCount(QModelIndex());
191 
192  QItemSelectionModel *selected = m_ROIWidget->selectionModel();
193 
194  for (int i=0; i<roiCount; i++) {
195  if (selected->rowIntersectsSelection(i, QModelIndex())) {
196  res.append(i);
197  }
198  }
199  }
200 
201  return res;
202 }
203 
205 {
206  QVector<int> rois = selectedROIs();
207 
208  if (m_ROIModel) {
209  QMenu menu;
210 
211  for (int i=0; i<QxrdROICoordinates::roiTypeCount(); i++) {
212  QAction *a = new QAction(QxrdROICoordinates::roiTypeName(i), &menu);
213  a->setData(i);
214 
215  menu.addAction(a);
216  }
217 
218  QAction *choice = menu.exec(QCursor::pos());
219 
220  if (choice) {
221  int roiType = choice->data().toInt();
222 
225 
226  m_ROIModel->append(roi);
227  }
228  }
229 }
230 
232 {
233  QVector<int> rois = selectedROIs();
234 
235  int res = QMessageBox::Cancel;
236 
237  if (rois.count() == 0) {
238  QMessageBox::information(this, "No ROIs Selected", "Select ROIs to delete", QMessageBox::Ok);
239  } else if (rois.count() == 1) {
240  res = QMessageBox::information(this, "Delete ROI?",
241  tr("Do you really want to delete ROI %1").arg(rois.value(0)),
242  QMessageBox::Ok, QMessageBox::Cancel);
243  } else {
244  QString roimsg;
245  foreach (int i, rois) {
246  if (roimsg=="") {
247  roimsg = tr("%1").arg(i);
248  } else {
249  roimsg += tr(", %1").arg(i);
250  }
251  }
252 
253  res = QMessageBox::information(this, "Delete ROIs?",
254  tr("Do you really want to delete ROIs %1").arg(roimsg));
255  }
256 
257  if (res == QMessageBox::Ok && m_ROIModel) {
258  for (int i=rois.count()-1; i>=0; i--) {
259  m_ROIModel->removeROI(rois.value(i));
260  }
261  }
262 }
263 
265 {
266  QVector<int> rois = selectedROIs();
267 
268  if (rois.count() != 1) {
269  QMessageBox::information(this, "Only Move One", "Must have a single ROI selected before moving it", QMessageBox::Ok);
270  } else {
271  if (m_ROIModel) {
272  m_ROIModel->moveROIDown(rois.first());
273  }
274  }
275 }
276 
278 {
279  QVector<int> rois = selectedROIs();
280 
281  if (rois.count() != 1) {
282  QMessageBox::information(this, "Only Move One", "Must have a single ROI selected before moving it", QMessageBox::Ok);
283  } else {
284  if (m_ROIModel) {
285  m_ROIModel->moveROIUp(rois.first());
286  }
287  }
288 }
289 
291 {
292  if (m_NewDataAvailable.fetchAndStoreOrdered(0)) {
293  QcepMutexLocker lock(__FILE__, __LINE__, &m_UpdateMutex);
294 
297 
300 
302 
303  if (proc) {
304  if (proc->get_DetectorDisplayMode() == QxrdDetectorProcessor::ImageDisplayMode) {
305  m_DetectorImage->onProcessedImageAvailable(m_DisplayedImage, m_DisplayedOverflow);
306  }
307  }
308  } else if (m_NewMaskAvailable.fetchAndStoreOrdered(0)) {
309  QcepMutexLocker lock(__FILE__, __LINE__, &m_UpdateMutex);
310 
313 
315 
316  if (proc) {
317  if (proc->get_DetectorDisplayMode() == QxrdDetectorProcessor::ImageDisplayMode) {
318  m_DetectorImage->onMaskedImageAvailable(m_DisplayedImage, m_DisplayedMask);
319  }
320  }
321  }
322 }
323 
325 {
326  m_UpdateTimer.setInterval(newVal);
327 }
328 
330 {
331  QcepMutexLocker lock(__FILE__, __LINE__, &m_UpdateMutex);
332 
333  m_NewImage = img;
334  m_NewOverflow = overflow;
335 
336  m_NewDataAvailable.fetchAndStoreOrdered(1);
337 }
338 
340 {
341  QcepMutexLocker lock(__FILE__, __LINE__, &m_UpdateMutex);
342 
343  m_NewMask = mask;
344 
345  m_NewMaskAvailable.fetchAndStoreOrdered(1);
346 }
347 
349 {
350  m_DetectorImage -> enableROIDisplay(show);
351 }
352 
354 {
356 
357  if (dp) {
358  QString newPath = QFileDialog::getOpenFileName(this, "Select Mask Image",
359  dp->get_MaskPath());
360 
361  if (newPath.length() > 0) {
362  dp->set_MaskPath(newPath);
363  }
364  }
365 }
366 
368 {
370 
371  if (dp) {
372  int res = QMessageBox::information(this, "Clear Mask?", "Do you really want to clear the mask?", QMessageBox::Ok, QMessageBox::Cancel);
373 
374  if (res == QMessageBox::Ok) {
375  dp->set_MaskPath("");
376  }
377  }
378 }
379 
381 {
383 
384  if (dp) {
385  QString newPath = QFileDialog::getOpenFileName(this, "Select Dark Image",
386  dp->get_DarkImagePath());
387 
388  if (newPath.length() > 0) {
389  dp->set_DarkImagePath(newPath);
390  }
391  }
392 }
393 
395 {
397 
398  if (dp) {
399  int res = QMessageBox::information(this, "Clear Dark?", "Do you really want to clear the dark image?", QMessageBox::Ok, QMessageBox::Cancel);
400 
401  if (res == QMessageBox::Ok) {
402  dp->set_DarkImagePath("");
403  }
404  }
405 }
406 
408 {
410 
411  if (dp) {
412  QString newPath = QFileDialog::getOpenFileName(this, "Select Bad Pixels Image",
413  dp->get_BadPixelsPath());
414 
415  if (newPath.length() > 0) {
416  dp->set_BadPixelsPath(newPath);
417  }
418  }
419 }
420 
422 {
424 
425  if (dp) {
426  int res = QMessageBox::information(this, "Clear Bad Pixels?", "Do you really want to clear the bad pixels image?", QMessageBox::Ok, QMessageBox::Cancel);
427 
428  if (res == QMessageBox::Ok) {
429  dp->set_BadPixelsPath("");
430  }
431  }
432 }
433 
435 {
437 
438  if (dp) {
439  QString newPath = QFileDialog::getOpenFileName(this, "Select Gain Correction Image",
440  dp->get_GainMapPath());
441 
442  if (newPath.length() > 0) {
443  dp->set_GainMapPath(newPath);
444  }
445  }
446 }
447 
449 {
451 
452  if (dp) {
453  int res = QMessageBox::information(this, "Clear Gain Correction?", "Do you really want to clear the gain correction image?", QMessageBox::Ok, QMessageBox::Cancel);
454 
455  if (res == QMessageBox::Ok) {
456  dp->set_GainMapPath("");
457  }
458  }
459 }
460 
462 {
464 
465  if (dp) {
466  if (m_ROIModel) {
467  m_ROIModel->recalculate(dp->data(), dp->mask());
468  }
469  }
470 }
471 
473 {
475 
476  if (dp) {
477  QVector<int> rois = selectedROIs();
478 
479  if (rois.count() != 1) {
480  QMessageBox::information(this, "Visualize ROI", "Select one ROI to visualize", QMessageBox::Ok);
481  } else if (m_ROIModel) {
482  m_ROIModel->visualizeBackground(rois.first(), dp->data(), dp->mask());
483 
484  displayNewData(dp->data(), QcepMaskDataPtr());
485  }
486  }
487 }
488 
490 {
492 
493  if (dp) {
494  QVector<int> rois = selectedROIs();
495 
496  if (rois.count() != 1) {
497  QMessageBox::information(this, "Visualize ROI", "Select one ROI to visualize", QMessageBox::Ok);
498  } else if (m_ROIModel) {
499  m_ROIModel->visualizePeak(rois.first(), dp->data(), dp->mask());
500 
501  displayNewData(dp->data(), QcepMaskDataPtr());
502  }
503  }
504 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
void valueChanged(QString val, int index)
QSharedPointer< QxrdAcquisition > QxrdAcquisitionPtr
QxrdDetectorControlWindow(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr exp, QxrdAcquisitionWPtr acq, QxrdDetectorWPtr det, QxrdDetectorProcessorWPtr proc, QWidget *parent=0)
QWeakPointer< QxrdDetectorProcessor > QxrdDetectorProcessorWPtr
QSharedPointer< QxrdROICoordinates > QxrdROICoordinatesPtr
void displayNewData(QcepImageDataBasePtr img, QcepMaskDataPtr overflow)
void displayNewMask(QcepMaskDataPtr mask)
void printMessage(QString msg, QDateTime ts=QDateTime::currentDateTime())
QSharedPointer< QxrdROICalculator > QxrdROICalculatorPtr
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QxrdDetectorProcessorWPtr m_Processor
QxrdROICoordinatesListModelPtr m_ROIModel
QSharedPointer< QxrdDetectorProcessor > QxrdDetectorProcessorPtr
QWeakPointer< QxrdDetector > QxrdDetectorWPtr
void setSpacing(int spacing)
QcepImageDataBasePtr m_DisplayedImage
QWeakPointer< QxrdAcquisition > QxrdAcquisitionWPtr
QcepApplication * g_Application
void setFontSize(int fontSize)
QSharedPointer< QxrdDetector > QxrdDetectorPtr
void valueChanged(int val, int index)
QSharedPointer< QcepImageDataBase > QcepImageDataBasePtr
QSharedPointer< QcepMaskData > QcepMaskDataPtr
void valueChanged(bool val, int index)
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr