InstrumentWidgetMaskTab.cpp 51.6 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
Roman Tolchenov's avatar
Roman Tolchenov committed
7
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetMaskTab.h"
8
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
Roman Tolchenov's avatar
Roman Tolchenov committed
9
#include "MantidQtWidgets/Common/TSVSerialiser.h"
10
#endif
Roman Tolchenov's avatar
Roman Tolchenov committed
11
12
13
14
#include "MantidQtWidgets/InstrumentView/DetXMLFile.h"
#include "MantidQtWidgets/InstrumentView/InstrumentActor.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidget.h"
#include "MantidQtWidgets/InstrumentView/ProjectionSurface.h"
15
16
17
18
19
20

#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IMaskWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
21
#include "MantidAPI/MatrixWorkspace.h"
22
// #include "MantidDataObjects/TableWorkspace.h"
Mathieu Tillet's avatar
Mathieu Tillet committed
23
#include "MantidGeometry/Instrument/ComponentInfo.h"
24
25
26
#include "MantidKernel/Logger.h"
#include "MantidKernel/Strings.h"

Roman Tolchenov's avatar
Roman Tolchenov committed
27
#include "MantidQtWidgets/Common/QtPropertyBrowser/qtpropertymanager.h"
LamarMoore's avatar
LamarMoore committed
28
#include "MantidQtWidgets/Common/QtPropertyBrowser/qttreepropertybrowser.h"
29
30
// Suppress a warning coming out of code that isn't ours
#if defined(__INTEL_COMPILER)
31
#pragma warning disable 1125
32
#elif defined(__GNUC__)
33
34
35
36
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push
#endif
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
37
#endif
Roman Tolchenov's avatar
Roman Tolchenov committed
38
#include "MantidQtWidgets/Common/QtPropertyBrowser/DoubleEditorFactory.h"
LamarMoore's avatar
LamarMoore committed
39
#include "MantidQtWidgets/Common/QtPropertyBrowser/qteditorfactory.h"
40
#if defined(__INTEL_COMPILER)
41
#pragma warning enable 1125
42
#elif defined(__GNUC__)
43
44
45
#if (__GNUC__ >= 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic pop
#endif
46
47
#endif

Samuel Jones's avatar
Samuel Jones committed
48
#include <Poco/Path.h>
49
50
#include <QAction>
#include <QApplication>
51
52
#include <QCheckBox>
#include <QGridLayout>
53
#include <QGroupBox>
54
55
56
57
58
59
#include <QHBoxLayout>
#include <QLabel>
#include <QMenu>
#include <QMessageBox>
#include <QPushButton>
#include <QRadioButton>
60
#include <QSettings>
61
62
63
64
#include <QTemporaryFile>
#include <QTextEdit>
#include <QToolTip>
#include <QVBoxLayout>
65

Roman Tolchenov's avatar
Roman Tolchenov committed
66
#include "MantidQtWidgets/Common/FileDialogHandler.h"
67
68

#include <algorithm>
LamarMoore's avatar
LamarMoore committed
69
#include <cfloat>
70
#include <fstream>
LamarMoore's avatar
LamarMoore committed
71
#include <numeric>
72

73
74
using Mantid::API::AlgorithmManager;

75
76
77
78
79
namespace MantidQt {
namespace MantidWidgets {
InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget)
    : InstrumentWidgetTab(instrWidget), m_activity(Select),
      m_hasMaskToApply(false), m_maskBins(false), m_userEditing(true),
Peterson, Peter's avatar
Peterson, Peter committed
80
81
82
      m_groupManager(nullptr), m_stringManager(nullptr),
      m_doubleManager(nullptr), m_browser(nullptr), m_left(nullptr),
      m_top(nullptr), m_right(nullptr), m_bottom(nullptr) {
83

Mathieu Tillet's avatar
Mathieu Tillet committed
84
  m_detectorsToGroup = QList<Mantid::detid_t>();
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  // main layout
  QVBoxLayout *layout = new QVBoxLayout(this);

  m_activeTool = new QLabel(this);
  layout->addWidget(m_activeTool);

  // Create the tool buttons

  m_move = new QPushButton();
  m_move->setCheckable(true);
  m_move->setAutoExclusive(true);
  m_move->setIcon(QIcon(":/PickTools/zoom.png"));
  m_move->setToolTip("Move the instrument (Ctrl+Alt+M)");
  m_move->setShortcut(QKeySequence("Ctrl+Alt+M"));

  m_pointer = new QPushButton();
  m_pointer->setCheckable(true);
  m_pointer->setAutoExclusive(true);
  m_pointer->setIcon(QIcon(":/MaskTools/selection-edit.png"));
  m_pointer->setToolTip("Select and edit shapes (Ctrl+Alt+P)");
  m_pointer->setShortcut(QKeySequence("Ctrl+Alt+P"));

  m_ellipse = new QPushButton();
  m_ellipse->setCheckable(true);
  m_ellipse->setAutoExclusive(true);
  m_ellipse->setIcon(QIcon(":/MaskTools/selection-circle.png"));
  m_ellipse->setToolTip("Draw an ellipse (Ctrl+Alt+E)");
  m_ellipse->setShortcut(QKeySequence("Ctrl+Alt+E"));

  m_rectangle = new QPushButton();
  m_rectangle->setCheckable(true);
  m_rectangle->setAutoExclusive(true);
  m_rectangle->setIcon(QIcon(":/MaskTools/selection-box.png"));
  m_rectangle->setToolTip("Draw a rectangle (Ctrl+Alt+R)");
  m_rectangle->setShortcut(QKeySequence("Ctrl+Alt+R"));

  m_ring_ellipse = new QPushButton();
  m_ring_ellipse->setCheckable(true);
  m_ring_ellipse->setAutoExclusive(true);
  m_ring_ellipse->setIcon(QIcon(":/MaskTools/selection-circle-ring.png"));
  m_ring_ellipse->setToolTip("Draw an elliptical ring (Shift+Alt+E)");
  m_ring_ellipse->setShortcut(QKeySequence("Shift+Alt+E"));

  m_ring_rectangle = new QPushButton();
  m_ring_rectangle->setCheckable(true);
  m_ring_rectangle->setAutoExclusive(true);
  m_ring_rectangle->setIcon(QIcon(":/MaskTools/selection-box-ring.png"));
  m_ring_rectangle->setToolTip("Draw a rectangular ring (Shift+Alt+R)");
  m_ring_rectangle->setShortcut(QKeySequence("Shift+Alt+R"));

Mathieu Tillet's avatar
Mathieu Tillet committed
135
136
137
  m_sector = new QPushButton();
  m_sector->setCheckable(true);
  m_sector->setAutoExclusive(true);
138
  m_sector->setIcon(QIcon(":/MaskTools/selection-sector.png"));
Mathieu Tillet's avatar
Mathieu Tillet committed
139
140
  m_sector->setToolTip("Draw a circle sector (Shift+Alt+S)");
  m_sector->setShortcut(QKeySequence("Shift+Alt+S"));
Mathieu Tillet's avatar
Mathieu Tillet committed
141

Mathieu Tillet's avatar
Mathieu Tillet committed
142
143
144
145
146
147
148
149
150
151
152
153
  m_pixel = new QPushButton();
  m_pixel->setCheckable(true);
  m_pixel->setAutoExclusive(true);
  m_pixel->setIcon(QIcon(":/PickTools/selection-pointer.png"));
  m_pixel->setToolTip("Select a pixel");

  m_tube = new QPushButton();
  m_tube->setCheckable(true);
  m_tube->setAutoExclusive(true);
  m_tube->setIcon(QIcon(":/PickTools/selection-tube.png"));
  m_tube->setToolTip("Select a tube/bank");

154
155
156
157
158
159
160
  m_free_draw = new QPushButton();
  m_free_draw->setCheckable(true);
  m_free_draw->setAutoExclusive(true);
  m_free_draw->setIcon(QIcon(":/MaskTools/brush.png"));
  m_free_draw->setToolTip("Draw an arbitrary shape (Shift+Alt+A)");
  m_free_draw->setShortcut(QKeySequence("Shift+Alt+A"));

Mathieu Tillet's avatar
Mathieu Tillet committed
161
162
163
164
165
166
167
168
169
170
171
172
173
  auto *toolBox = new QGridLayout();
  layout->addLayout(toolBox);

  toolBox->addWidget(m_move, 0, 0);
  toolBox->addWidget(m_pointer, 0, 1);
  toolBox->addWidget(m_ellipse, 0, 2);
  toolBox->addWidget(m_rectangle, 0, 3);
  toolBox->addWidget(m_ring_ellipse, 0, 4);
  toolBox->addWidget(m_ring_rectangle, 0, 5);
  toolBox->addWidget(m_sector, 0, 6);
  toolBox->addWidget(m_free_draw, 0, 7);
  toolBox->addWidget(m_pixel, 1, 0);
  toolBox->addWidget(m_tube, 1, 1);
Mathieu Tillet's avatar
Mathieu Tillet committed
174
  toolBox->setColumnStretch(8, 1);
Mathieu Tillet's avatar
Mathieu Tillet committed
175
  toolBox->setSpacing(2);
176
177
178
179
180
181
182

  connect(m_move, SIGNAL(clicked()), this, SLOT(setActivity()));
  connect(m_pointer, SIGNAL(clicked()), this, SLOT(setActivity()));
  connect(m_ellipse, SIGNAL(clicked()), this, SLOT(setActivity()));
  connect(m_rectangle, SIGNAL(clicked()), this, SLOT(setActivity()));
  connect(m_ring_ellipse, SIGNAL(clicked()), this, SLOT(setActivity()));
  connect(m_ring_rectangle, SIGNAL(clicked()), this, SLOT(setActivity()));
Mathieu Tillet's avatar
Mathieu Tillet committed
183
  connect(m_sector, SIGNAL(clicked()), this, SLOT(setActivity()));
Mathieu Tillet's avatar
Mathieu Tillet committed
184
  connect(m_tube, SIGNAL(clicked()), this, SLOT(setActivity()));
185
  connect(m_pixel, SIGNAL(clicked()), this, SLOT(setActivity()));
Mathieu Tillet's avatar
Mathieu Tillet committed
186
  connect(m_free_draw, SIGNAL(clicked()), this, SLOT(setActivity()));
187
188
189
190
191
192
193
194
195
196
  m_move->setChecked(true);

  // create mask/group switch
  m_masking_on = new QRadioButton("Mask");
  m_grouping_on = new QRadioButton("Group");
  m_roi_on = new QRadioButton("ROI");
  m_masking_on->setChecked(true);
  connect(m_masking_on, SIGNAL(clicked()), this, SLOT(toggleMaskGroup()));
  connect(m_grouping_on, SIGNAL(clicked()), this, SLOT(toggleMaskGroup()));
  connect(m_roi_on, SIGNAL(clicked()), this, SLOT(toggleMaskGroup()));
197
  auto *radioLayout = new QHBoxLayout();
198
199
200
201
  radioLayout->addWidget(m_masking_on);
  radioLayout->addWidget(m_roi_on);
  radioLayout->addWidget(m_grouping_on);
  radioLayout->setMargin(0);
202
  auto *radioGroup = new QGroupBox();
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
  radioGroup->setStyleSheet("border: none;");
  radioGroup->setLayout(radioLayout);

  layout->addWidget(radioGroup);

  // Create property browser

  /* Create property managers: they create, own properties, get and set values
   */

  m_groupManager = new QtGroupPropertyManager(this);
  m_doubleManager = new QtDoublePropertyManager(this);
  connect(m_doubleManager, SIGNAL(propertyChanged(QtProperty *)), this,
          SLOT(doubleChanged(QtProperty *)));

  /* Create editors and assign them to the managers */

  DoubleEditorFactory *doubleEditorFactory = new DoubleEditorFactory(this);

  m_browser = new QtTreePropertyBrowser();
  m_browser->setFactoryForManager(m_doubleManager, doubleEditorFactory);

  layout->addWidget(m_browser);

  // Algorithm buttons

  m_applyToData = new QPushButton("Apply to Data");
  m_applyToData->setToolTip("Apply current detector and bin masks to the data "
                            "workspace. Cannot be reverted.");
  connect(m_applyToData, SIGNAL(clicked()), this, SLOT(applyMask()));

  m_applyToView = new QPushButton("Apply to View");
  m_applyToView->setToolTip("Apply current mask to the view.");
  connect(m_applyToView, SIGNAL(clicked()), this, SLOT(applyMaskToView()));

238
239
240
241
242
243
  m_saveShapesToTable = new QPushButton("Save Shapes to Table");
  m_saveShapesToTable->setToolTip(
      "Store the current Mask/ROI/Group shapes as a table");
  connect(m_saveShapesToTable, SIGNAL(clicked()), this,
          SLOT(saveShapesToTable()));

244
245
246
247
248
249
250
251
252
  m_clearAll = new QPushButton("Clear All");
  m_clearAll->setToolTip(
      "Clear all masking that have not been applied to the data.");
  connect(m_clearAll, SIGNAL(clicked()), this, SLOT(clearMask()));

  m_save_as_workspace_exclude =
      new QAction("As Detector Mask to workspace", this);
  m_save_as_workspace_exclude->setToolTip(
      "Save current detector mask to mask workspace.");
253
  connect(m_save_as_workspace_exclude, SIGNAL(triggered()), this,
254
255
256
257
258
259
          SLOT(saveMaskToWorkspace()));

  m_save_as_workspace_include =
      new QAction("As Detector ROI to workspace", this);
  m_save_as_workspace_include->setToolTip(
      "Save current detector mask as ROI to mask workspace.");
260
  connect(m_save_as_workspace_include, SIGNAL(triggered()), this,
261
262
263
264
265
          SLOT(saveInvertedMaskToWorkspace()));

  m_save_as_file_exclude = new QAction("As Detector Mask to file", this);
  m_save_as_file_exclude->setToolTip(
      "Save current detector mask to mask file.");
266
  connect(m_save_as_file_exclude, SIGNAL(triggered()), this,
267
268
269
270
          SLOT(saveMaskToFile()));

  m_save_as_file_include = new QAction("As Detector ROI to file", this);
  m_save_as_file_include->setToolTip("Save current mask as ROI to mask file.");
271
  connect(m_save_as_file_include, SIGNAL(triggered()), this,
272
273
274
275
276
277
          SLOT(saveInvertedMaskToFile()));

  m_save_as_cal_file_exclude =
      new QAction("As Detector Mask to cal file", this);
  m_save_as_cal_file_exclude->setToolTip(
      "Save current detector mask to cal file.");
278
  connect(m_save_as_cal_file_exclude, SIGNAL(triggered()), this,
279
280
281
282
283
          SLOT(saveMaskToCalFile()));

  m_save_as_cal_file_include = new QAction("As Detector ROI to cal file", this);
  m_save_as_cal_file_include->setToolTip(
      "Save current detector mask as ROI to cal file.");
284
  connect(m_save_as_cal_file_include, SIGNAL(triggered()), this,
285
286
287
288
289
290
291
292
293
          SLOT(saveInvertedMaskToCalFile()));

  m_save_as_table_xrange_exclude =
      new QAction("As Detector Mask to table", this);
  m_save_as_table_xrange_exclude->setToolTip(
      "Save current detector mask to a table workspace with x-range. "
      "The name of output table workspace is 'MaskBinTable'. "
      "If the output table workspace has alrady exist, then "
      "the newly masked detectors will be added to output workspace.");
294
  connect(m_save_as_table_xrange_exclude, SIGNAL(triggered()), this,
295
296
297
298
299
          SLOT(saveMaskToTable()));

  m_save_group_file_include = new QAction("As include group to file", this);
  m_save_group_file_include->setToolTip(
      "Save current mask as include group to a file.");
300
  connect(m_save_group_file_include, SIGNAL(triggered()), this,
301
302
303
304
305
          SLOT(saveIncludeGroupToFile()));

  m_save_group_file_exclude = new QAction("As exclude group to file", this);
  m_save_group_file_exclude->setToolTip(
      "Save current mask as exclude group to a file.");
306
  connect(m_save_group_file_exclude, SIGNAL(triggered()), this,
307
308
309
310
          SLOT(saveExcludeGroupToFile()));

  m_extract_to_workspace = new QAction("Extract detectors to workspace", this);
  m_extract_to_workspace->setToolTip("Extract detectors to workspace.");
311
  connect(m_extract_to_workspace, SIGNAL(triggered()), this,
312
313
314
315
          SLOT(extractDetsToWorkspace()));

  m_sum_to_workspace = new QAction("Sum detectors to workspace", this);
  m_sum_to_workspace->setToolTip("Sum detectors to workspace.");
316
  connect(m_sum_to_workspace, SIGNAL(triggered()), this,
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
          SLOT(sumDetsToWorkspace()));

  // Save button and its menus
  m_saveButton = new QPushButton("Apply and Save");
  m_saveButton->setToolTip(
      "Save current masking/grouping to a file or a workspace.");

  m_saveMask = new QMenu(this);
  m_saveMask->addAction(m_save_as_workspace_exclude);
  m_saveMask->addAction(m_save_as_file_exclude);
  m_saveMask->addAction(m_save_as_cal_file_exclude);
  m_saveMask->addSeparator();
  m_saveMask->addAction(m_save_as_table_xrange_exclude);
  connect(m_saveMask, SIGNAL(hovered(QAction *)), this,
          SLOT(showSaveMenuTooltip(QAction *)));

  m_saveButton->setMenu(m_saveMask);

  m_saveGroup = new QMenu(this);
  m_saveGroup->addAction(m_extract_to_workspace);
  m_saveGroup->addAction(m_sum_to_workspace);
  m_saveGroup->addSeparator();

  connect(m_saveGroup, SIGNAL(hovered(QAction *)), this,
          SLOT(showSaveMenuTooltip(QAction *)));

  m_saveROI = new QMenu(this);
  m_saveROI->addAction(m_save_as_workspace_include);
  m_saveROI->addAction(m_save_as_file_include);
  m_saveROI->addAction(m_save_as_cal_file_include);
  m_saveROI->addSeparator();
  m_saveROI->addAction(m_extract_to_workspace);
  m_saveROI->addAction(m_sum_to_workspace);

  connect(m_saveROI, SIGNAL(hovered(QAction *)), this,
          SLOT(showSaveMenuTooltip(QAction *)));

354
355
  auto *box = new QGroupBox("View");
  auto *buttons = new QGridLayout();
356
  buttons->addWidget(m_applyToView, 0, 0, 1, 2);
357
358
359
  buttons->addWidget(m_saveShapesToTable, 1, 0, 1, 2);
  buttons->addWidget(m_saveButton, 2, 0);
  buttons->addWidget(m_clearAll, 2, 1);
360
361
362
363
364
365
366
367
368

  box->setLayout(buttons);
  layout->addWidget(box);

  box = new QGroupBox("Workspace");
  buttons = new QGridLayout();
  buttons->addWidget(m_applyToData, 0, 0);
  box->setLayout(buttons);
  layout->addWidget(box);
369
370
371

  connect(m_instrWidget, SIGNAL(maskedWorkspaceOverlayed()), this,
          SLOT(enableApplyButtons()));
372
373
374
}

/**
LamarMoore's avatar
LamarMoore committed
375
376
 * Initialize the tab when new projection surface is created.
 */
377
void InstrumentWidgetMaskTab::initSurface() {
Mathieu Tillet's avatar
Mathieu Tillet committed
378
  connect(m_instrWidget->getSurface().get(),
379
          SIGNAL(singleComponentPickedForMasking(size_t)), this,
380
          SLOT(singlePixelPicked(size_t)));
381
382
383
384
385
386
387
388
389
390
391
392
393
394
  connect(m_instrWidget->getSurface().get(), SIGNAL(shapeCreated()), this,
          SLOT(shapeCreated()));
  connect(m_instrWidget->getSurface().get(), SIGNAL(shapeSelected()), this,
          SLOT(shapeSelected()));
  connect(m_instrWidget->getSurface().get(), SIGNAL(shapesDeselected()), this,
          SLOT(shapesDeselected()));
  connect(m_instrWidget->getSurface().get(), SIGNAL(shapeChanged()), this,
          SLOT(shapeChanged()));
  connect(m_instrWidget->getSurface().get(), SIGNAL(shapesCleared()), this,
          SLOT(shapesCleared()));
  enableApplyButtons();
}

/**
LamarMoore's avatar
LamarMoore committed
395
396
397
 * Selects between masking/grouping
 * @param mode The required mode, @see Mode
 */
398
399
400
void InstrumentWidgetMaskTab::setMode(Mode mode) {
  switch (mode) {
  case Mask:
401
    m_masking_on->setChecked(true);
402
403
    break;
  case Group:
404
    m_grouping_on->setChecked(true);
405
406
    break;
  case ROI:
407
    m_roi_on->setChecked(true);
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
    break;
  default:
    throw std::invalid_argument("Invalid Mask tab mode. Use Mask/Group.");
  };
  toggleMaskGroup();
}

void InstrumentWidgetMaskTab::selectTool(Activity tool) {
  switch (tool) {
  case Move:
    m_move->setChecked(true);
    break;
  case Select:
    m_pointer->setChecked(true);
    break;
  case DrawEllipse:
    m_ellipse->setChecked(true);
    break;
  case DrawRectangle:
    m_rectangle->setChecked(true);
    break;
  case DrawEllipticalRing:
    m_ring_ellipse->setChecked(true);
    break;
  case DrawRectangularRing:
    m_ring_rectangle->setChecked(true);
    break;
Mathieu Tillet's avatar
Mathieu Tillet committed
435
436
437
  case DrawSector:
    m_sector->setChecked(true);
    break;
438
439
440
  case DrawFree:
    m_free_draw->setChecked(true);
    break;
441
442
443
  case Pixel:
    m_pixel->setChecked(true);
    break;
Mathieu Tillet's avatar
Mathieu Tillet committed
444
445
446
  case Tube:
    m_tube->setChecked(true);
    break;
447
448
449
450
451
452
453
  default:
    throw std::invalid_argument("Invalid tool type.");
  }
  setActivity();
}

/**
LamarMoore's avatar
LamarMoore committed
454
455
 * Set tab's activity based on the currently selected tool button.
 */
456
457
458
void InstrumentWidgetMaskTab::setActivity() {
  const QColor borderColor = getShapeBorderColor();
  const QColor fillColor = getShapeFillColor();
Mathieu Tillet's avatar
Mathieu Tillet committed
459
  // m_detectorsToGroup.clear();
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
  QString whatIsBeingSelected = m_maskBins && getMode() == Mode::Mask
                                    ? "Selecting bins"
                                    : "Selecting detectors";
  if (m_move->isChecked()) {
    m_activity = Move;
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::MoveMode);
    m_activeTool->setText("Tool: Navigation");
  } else if (m_pointer->isChecked()) {
    m_activity = Select;
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Shape editing. " + whatIsBeingSelected);
  } else if (m_ellipse->isChecked()) {
    m_activity = DrawEllipse;
    m_instrWidget->getSurface()->startCreatingShape2D("ellipse", borderColor,
                                                      fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Ellipse. " + whatIsBeingSelected);
  } else if (m_rectangle->isChecked()) {
    m_activity = DrawRectangle;
    m_instrWidget->getSurface()->startCreatingShape2D("rectangle", borderColor,
                                                      fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Rectangle. " + whatIsBeingSelected);
  } else if (m_ring_ellipse->isChecked()) {
    m_activity = DrawEllipticalRing;
    m_instrWidget->getSurface()->startCreatingShape2D("ring ellipse",
                                                      borderColor, fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Elliptical ring. " + whatIsBeingSelected);
  } else if (m_ring_rectangle->isChecked()) {
    m_activity = DrawRectangularRing;
    m_instrWidget->getSurface()->startCreatingShape2D("ring rectangle",
                                                      borderColor, fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Rectangular ring. " + whatIsBeingSelected);
Mathieu Tillet's avatar
Mathieu Tillet committed
501
502
503
504
505
506
507
508
  } else if (m_sector->isChecked()) {
    m_activity = DrawSector;
    m_instrWidget->getSurface()->startCreatingShape2D("sector", borderColor,
                                                      fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawRegularMode);
    m_activeTool->setText("Tool: Sector. " + whatIsBeingSelected);

509
510
511
512
513
514
  } else if (m_free_draw->isChecked()) {
    m_activity = DrawFree;
    m_instrWidget->getSurface()->startCreatingFreeShape(borderColor, fillColor);
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::DrawFreeMode);
    m_activeTool->setText("Tool: Free draw. " + whatIsBeingSelected);
Mathieu Tillet's avatar
Mathieu Tillet committed
515
  } else if (m_pixel->isChecked()) {
516
    m_activity = Pixel;
517
518
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::PickSingleMode);
Mathieu Tillet's avatar
Mathieu Tillet committed
519
520
521
522
523
524
525
    m_activeTool->setText("Tool: Pixel mask. " + whatIsBeingSelected);
  } else if (m_tube->isChecked()) {
    m_activity = Tube;
    m_instrWidget->getSurface()->setInteractionMode(
        ProjectionSurface::PickTubeMode);
    m_activeTool->setText("Tool: Tube/bank mask. " + whatIsBeingSelected);
  }
526
  m_instrWidget->updateInfoText();
Mathieu Tillet's avatar
Mathieu Tillet committed
527
  // enableApplyButtons();
528
529
}

530
531
/**
 * Slot responding on the pick of a single detector pixel for masking.
Mathieu Tillet's avatar
Mathieu Tillet committed
532
 * Can be used either to mask the picked pixel or its parent.
533
 */
Mathieu Tillet's avatar
Mathieu Tillet committed
534
void InstrumentWidgetMaskTab::singlePixelPicked(size_t pickID) {
535
  const auto &actor = m_instrWidget->getInstrumentActor();
Mathieu Tillet's avatar
Mathieu Tillet committed
536
537
538
539
540
541
  const auto &componentInfo = actor.componentInfo();
  if (!componentInfo.isDetector(pickID)) {
    return;
  }

  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
542
  std::vector<size_t> detectorsId{pickID};
Mathieu Tillet's avatar
Mathieu Tillet committed
543
  m_instrWidget->updateInstrumentView(); // to refresh the pick image
544

545
546
  if (m_masking_on->isChecked() || m_roi_on->isChecked()) {
    if (m_tube->isChecked()) {
Mathieu Tillet's avatar
Mathieu Tillet committed
547
548
549
550
      if (!componentInfo.hasParent(pickID)) {
        return;
      }
      auto parent = componentInfo.parent(pickID);
551
      detectorsId = componentInfo.detectorsInSubtree(parent);
Mathieu Tillet's avatar
Mathieu Tillet committed
552
    }
553
    storeDetectorMask(m_roi_on->isChecked(), detectorsId);
554

555
556
557
558
559
560
561
562
563
  } else if (m_grouping_on->isChecked()) {
    if (m_pixel->isChecked()) {
      Mantid::detid_t detId = actor.getDetID(pickID);
      m_detectorsToGroup.clear();
      m_detectorsToGroup.append(detId);
    } else if (m_tube->isChecked()) {
      if (!componentInfo.hasParent(pickID)) {
        return;
      }
564
565
566
      const auto parent = componentInfo.parent(pickID);
      const auto dets =
          actor.getDetIDs(componentInfo.detectorsInSubtree(parent));
567
568
569
570
      m_detectorsToGroup.clear();
      for (auto det : dets)
        m_detectorsToGroup.append(det);
    }
Mathieu Tillet's avatar
Mathieu Tillet committed
571
  }
572

Mathieu Tillet's avatar
Mathieu Tillet committed
573
574
575
576
577
  // update detector colours
  m_instrWidget->getInstrumentActor().updateColors();
  m_instrWidget->updateInstrumentDetectors();
  QApplication::restoreOverrideCursor();
  enableApplyButtons();
578
579
}

580
/**
LamarMoore's avatar
LamarMoore committed
581
582
 * Slot responding on creation of a new masking shape.
 */
583
584
585
586
587
588
589
590
591
592
void InstrumentWidgetMaskTab::shapeCreated() {
  if (!isVisible())
    return;
  if (m_activity != DrawFree) {
    setSelectActivity();
  }
  enableApplyButtons();
}

/**
LamarMoore's avatar
LamarMoore committed
593
594
 * Slot responding on selection of a new masking shape.
 */
595
596
597
void InstrumentWidgetMaskTab::shapeSelected() { setProperties(); }

/**
LamarMoore's avatar
LamarMoore committed
598
599
 * Slot responding on deselecting all masking shapes.
 */
600
601
602
void InstrumentWidgetMaskTab::shapesDeselected() { clearProperties(); }

/**
LamarMoore's avatar
LamarMoore committed
603
604
 * Slot responding on a change of a masking shape.
 */
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
void InstrumentWidgetMaskTab::shapeChanged() {
  if (!m_left)
    return; // check that everything is ok
  m_userEditing =
      false; // this prevents resetting shape properties by doubleChanged(...)
  RectF rect = m_instrWidget->getSurface()->getCurrentBoundingRect();
  m_doubleManager->setValue(m_left, rect.x0());
  m_doubleManager->setValue(m_top, rect.y1());
  m_doubleManager->setValue(m_right, rect.x1());
  m_doubleManager->setValue(m_bottom, rect.y0());
  for (QMap<QtProperty *, QString>::iterator it = m_doublePropertyMap.begin();
       it != m_doublePropertyMap.end(); ++it) {
    m_doubleManager->setValue(
        it.key(), m_instrWidget->getSurface()->getCurrentDouble(it.value()));
  }
  for (QMap<QString, QtProperty *>::iterator it = m_pointPropertyMap.begin();
       it != m_pointPropertyMap.end(); ++it) {
    QtProperty *prop = it.value();
    QList<QtProperty *> subs = prop->subProperties();
    if (subs.size() != 2)
      continue;
    QPointF p = m_instrWidget->getSurface()->getCurrentPoint(it.key());
    m_doubleManager->setValue(subs[0], p.x());
    m_doubleManager->setValue(subs[1], p.y());
  }
  m_userEditing = true;
}

/**
LamarMoore's avatar
LamarMoore committed
634
635
 * Slot responding on removing all masking shapes.
 */
636
637
638
void InstrumentWidgetMaskTab::shapesCleared() { enableApplyButtons(); }

/**
LamarMoore's avatar
LamarMoore committed
639
640
 * Removes the mask shapes from the screen.
 */
641
642
643
644
645
void InstrumentWidgetMaskTab::clearShapes() {
  m_instrWidget->getSurface()->clearMask();
  setSelectActivity();
}

646
void InstrumentWidgetMaskTab::showEvent(QShowEvent * /*unused*/) {
647
648
649
650
651
652
653
654
655
656
657
658
  setActivity();
  m_instrWidget->setMouseTracking(true);
  enableApplyButtons();
  m_instrWidget->updateInstrumentView(true);
  m_instrWidget->getSurface()->changeBorderColor(getShapeBorderColor());
}

void InstrumentWidgetMaskTab::clearProperties() {
  m_browser->clear();
  m_doublePropertyMap.clear();
  m_pointPropertyMap.clear();
  m_pointComponentsMap.clear();
659
660
661
662
  m_left = nullptr;
  m_top = nullptr;
  m_right = nullptr;
  m_bottom = nullptr;
663
664
665
666
667
668
669
}

void InstrumentWidgetMaskTab::setProperties() {
  clearProperties();
  m_userEditing = false;

  // bounding rect property
670
  QtProperty *boundingRectGroup = m_groupManager->addProperty("Bounding Rect");
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
  m_browser->addProperty(boundingRectGroup);
  m_left = addDoubleProperty("left");
  m_top = addDoubleProperty("top");
  m_right = addDoubleProperty("right");
  m_bottom = addDoubleProperty("bottom");
  boundingRectGroup->addSubProperty(m_left);
  boundingRectGroup->addSubProperty(m_top);
  boundingRectGroup->addSubProperty(m_right);
  boundingRectGroup->addSubProperty(m_bottom);

  // point properties
  QStringList pointProperties =
      m_instrWidget->getSurface()->getCurrentPointNames();
  foreach (QString name, pointProperties) {
    QtProperty *point = m_groupManager->addProperty(name);
    QtProperty *prop_x = addDoubleProperty("x");
    QtProperty *prop_y = addDoubleProperty("y");
    point->addSubProperty(prop_x);
    point->addSubProperty(prop_y);
    m_browser->addProperty(point);
    m_pointComponentsMap[prop_x] = name;
    m_pointComponentsMap[prop_y] = name;
    m_pointPropertyMap[name] = point;
  }

  // double properties
  QStringList doubleProperties =
      m_instrWidget->getSurface()->getCurrentDoubleNames();
  foreach (QString name, doubleProperties) {
    QtProperty *prop = addDoubleProperty(name);
    m_browser->addProperty(prop);
    m_doublePropertyMap[prop] = name;
  }

  shapeChanged();
}

708
709
710
711
712
713
714
/**
 * Save shapes to a table workspace
 */
void InstrumentWidgetMaskTab::saveShapesToTable() const {
  m_instrWidget->getSurface()->saveShapesToTableWorkspace();
}

715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
void InstrumentWidgetMaskTab::doubleChanged(QtProperty *prop) {
  if (!m_userEditing)
    return;
  if (prop == m_left || prop == m_top || prop == m_right || prop == m_bottom) {
    QRectF rect(
        QPointF(m_doubleManager->value(m_left), m_doubleManager->value(m_top)),
        QPointF(m_doubleManager->value(m_right),
                m_doubleManager->value(m_bottom)));
    m_instrWidget->getSurface()->setCurrentBoundingRect(RectF(rect));
  } else {
    QString name = m_doublePropertyMap[prop];
    if (!name.isEmpty()) {
      m_instrWidget->getSurface()->setCurrentDouble(
          name, m_doubleManager->value(prop));
    } else {
      name = m_pointComponentsMap[prop];
      if (!name.isEmpty()) {
        QtProperty *point_prop = m_pointPropertyMap[name];
        QList<QtProperty *> subs = point_prop->subProperties();
        if (subs.size() != 2)
          return;
        QPointF p(m_doubleManager->value(subs[0]),
                  m_doubleManager->value(subs[1]));
        m_instrWidget->getSurface()->setCurrentPoint(name, p);
      }
    }
741
742
    // when the user validates the edit of the field, the view is immediatly
    // updated this way
743
    m_instrWidget->updateInstrumentView();
744
745
746
747
748
  }
  m_instrWidget->update();
}

/**
LamarMoore's avatar
LamarMoore committed
749
750
751
 * Apply the constructed mask to the data workspace. This operation cannot be
 * reverted.
 */
752
753
754
void InstrumentWidgetMaskTab::applyMask() {
  storeMask();
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
755
  m_instrWidget->getInstrumentActor().applyMaskWorkspace();
756
757
758
759
760
  enableApplyButtons();
  QApplication::restoreOverrideCursor();
}

/**
LamarMoore's avatar
LamarMoore committed
761
762
 * Apply the constructed mask to the view only.
 */
763
764
765
766
767
768
void InstrumentWidgetMaskTab::applyMaskToView() {
  storeMask();
  enableApplyButtons();
}

/**
LamarMoore's avatar
LamarMoore committed
769
770
 * Remove all masking that has not been applied to the data workspace.
 */
771
772
void InstrumentWidgetMaskTab::clearMask() {
  clearShapes();
Mathieu Tillet's avatar
Mathieu Tillet committed
773
  m_detectorsToGroup.clear();
774
  m_instrWidget->getInstrumentActor().clearMasks();
775
776
777
778
779
  m_instrWidget->updateInstrumentView();
  enableApplyButtons();
}

/**
LamarMoore's avatar
LamarMoore committed
780
781
782
783
784
785
 * Create a MaskWorkspace from the mask defined in this tab.
 * @param invertMask ::  if true, the selected mask will be inverted; if false,
 * the mask will be used as is
 * @param temp :: Set true to create a temporary workspace with a fixed name. If
 * false the name will be unique.
 */
786
Mantid::API::MatrixWorkspace_sptr
787
InstrumentWidgetMaskTab::createMaskWorkspace(bool invertMask, bool temp) const {
788
789
  m_instrWidget->updateInstrumentView(); // to refresh the pick image
  Mantid::API::MatrixWorkspace_sptr inputWS =
790
      m_instrWidget->getInstrumentActor().getMaskMatrixWorkspace();
791
792
793
  Mantid::API::MatrixWorkspace_sptr outputWS;
  const std::string outputWorkspaceName = generateMaskWorkspaceName(temp);

794
  auto alg = AlgorithmManager::Instance().create("ExtractMask", -1);
795
796
797
798
  alg->setProperty("InputWorkspace", inputWS);
  alg->setPropertyValue("OutputWorkspace", outputWorkspaceName);
  alg->execute();

799
  outputWS = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
800
801
802
803
      Mantid::API::AnalysisDataService::Instance().retrieve(
          outputWorkspaceName));

  if (invertMask) {
Nick Draper's avatar
Nick Draper committed
804
805
    auto invertAlg =
        AlgorithmManager::Instance().create("BinaryOperateMasks", -1);
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
    invertAlg->setPropertyValue("InputWorkspace1", outputWorkspaceName);
    invertAlg->setPropertyValue("OutputWorkspace", outputWorkspaceName);
    invertAlg->setPropertyValue("OperationType", "NOT");
    invertAlg->execute();

    outputWS->setTitle("InvertedMaskWorkspace");
  } else {
    outputWS->setTitle("MaskWorkspace");
  }

  return outputWS;
}

void InstrumentWidgetMaskTab::saveInvertedMaskToWorkspace() {
  saveMaskingToWorkspace(true);
}

void InstrumentWidgetMaskTab::saveMaskToWorkspace() {
  saveMaskingToWorkspace(false);
}

void InstrumentWidgetMaskTab::saveInvertedMaskToFile() {
  saveMaskingToFile(true);
}

void InstrumentWidgetMaskTab::saveMaskToFile() { saveMaskingToFile(false); }

void InstrumentWidgetMaskTab::saveMaskToCalFile() {
  saveMaskingToCalFile(false);
}

void InstrumentWidgetMaskTab::saveInvertedMaskToCalFile() {
  saveMaskingToCalFile(true);
}

void InstrumentWidgetMaskTab::saveMaskToTable() {
  saveMaskingToTableWorkspace(false);
}

/**
LamarMoore's avatar
LamarMoore committed
846
847
 * Extract selected detectors to a new workspace
 */
848
849
void InstrumentWidgetMaskTab::extractDetsToWorkspace() {
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
850
  std::vector<size_t> dets;
851
  m_instrWidget->getSurface()->getMaskedDetectors(dets);
852
  const auto &actor = m_instrWidget->getInstrumentActor();
853
854
855
856
  QList<int> detectorIDs = actor.getDetIDs(dets);
  if (m_pixel->isChecked() || m_tube->isChecked())
    detectorIDs.append(m_detectorsToGroup);
  DetXMLFile mapFile(detectorIDs);
857
858
859
  std::string fname = mapFile();
  if (!fname.empty()) {
    std::string workspaceName = m_instrWidget->getWorkspaceName().toStdString();
Nick Draper's avatar
Nick Draper committed
860
    auto alg = AlgorithmManager::Instance().create("GroupDetectors");
861
862
863
864
865
866
867
868
869
    alg->setPropertyValue("InputWorkspace", workspaceName);
    alg->setPropertyValue("MapFile", fname);
    alg->setPropertyValue("OutputWorkspace", workspaceName + "_selection");
    alg->execute();
  }
  QApplication::restoreOverrideCursor();
}

/**
LamarMoore's avatar
LamarMoore committed
870
871
 * Sum selected detectors to a new workspace
 */
872
873
void InstrumentWidgetMaskTab::sumDetsToWorkspace() {
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
874
  std::vector<size_t> dets;
875
  m_instrWidget->getSurface()->getMaskedDetectors(dets);
876
877
878
879
  QList<int> detectorIDs = m_instrWidget->getInstrumentActor().getDetIDs(dets);
  if (m_pixel->isChecked() || m_tube->isChecked())
    detectorIDs.append(m_detectorsToGroup);
  DetXMLFile mapFile(detectorIDs, DetXMLFile::Sum);
880
881
882
883
  std::string fname = mapFile();

  if (!fname.empty()) {
    std::string workspaceName = m_instrWidget->getWorkspaceName().toStdString();
Nick Draper's avatar
Nick Draper committed
884
    auto alg = AlgorithmManager::Instance().create("GroupDetectors");
885
886
887
888
889
890
891
892
893
    alg->setPropertyValue("InputWorkspace", workspaceName);
    alg->setPropertyValue("MapFile", fname);
    alg->setPropertyValue("OutputWorkspace", workspaceName + "_sum");
    alg->execute();
  }
  QApplication::restoreOverrideCursor();
}

void InstrumentWidgetMaskTab::saveIncludeGroupToFile() {
Ian Bush's avatar
Ian Bush committed
894
895
  QString fname = m_instrWidget->getSaveFileName("Save grouping file",
                                                 "XML files (*.xml);;All (*)");
896
  if (!fname.isEmpty()) {
897
    std::vector<size_t> dets;
898
    m_instrWidget->getSurface()->getMaskedDetectors(dets);
899
900
    DetXMLFile mapFile(m_instrWidget->getInstrumentActor().getDetIDs(dets),
                       DetXMLFile::Sum, fname);
901
902
903
904
  }
}

void InstrumentWidgetMaskTab::saveExcludeGroupToFile() {
Ian Bush's avatar
Ian Bush committed
905
906
  QString fname = m_instrWidget->getSaveFileName("Save grouping file",
                                                 "XML files (*.xml);;All (*)");
907
  if (!fname.isEmpty()) {
908
    std::vector<size_t> dets;
909
    m_instrWidget->getSurface()->getMaskedDetectors(dets);
910
911
    const auto &actor = m_instrWidget->getInstrumentActor();
    DetXMLFile mapFile(actor.getAllDetIDs(), actor.getDetIDs(dets), fname);
912
913
914
915
916
917
918
919
  }
}

void InstrumentWidgetMaskTab::showSaveMenuTooltip(QAction *action) {
  QToolTip::showText(QCursor::pos(), action->toolTip(), this);
}

/**
LamarMoore's avatar
LamarMoore committed
920
921
922
 * Toggle between different modes
 *
 */
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
void InstrumentWidgetMaskTab::toggleMaskGroup() {
  Mode mode = getMode();

  enableApplyButtons();
  if (mode == Mode::Mask) {
    m_saveButton->setMenu(m_saveMask);
    m_saveButton->setText("Apply and Save");
  } else if (mode == Mode::ROI) {
    m_saveButton->setMenu(m_saveROI);
    m_saveButton->setText("Apply and Save");
  } else {
    m_saveButton->setMenu(m_saveGroup);
    m_saveButton->setText("Save");
  }
  m_instrWidget->getSurface()->changeBorderColor(getShapeBorderColor());
  m_instrWidget->updateInstrumentView();
}

/**
LamarMoore's avatar
LamarMoore committed
942
943
944
945
946
947
 * Save the constructed mask to a workspace with unique name of type
 * "MaskWorkspace_#".
 * The mask is not applied to the data workspace being displayed.
 * @param invertMask ::  if true, the selected mask will be inverted; if false,
 * the mask will be used as is
 */
948
949
950
951
952
953
void InstrumentWidgetMaskTab::saveMaskingToWorkspace(bool invertMask) {
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  // Make sure we have stored the Mask in the helper MaskWorkspace
  storeDetectorMask(invertMask);
  setSelectActivity();
  createMaskWorkspace(false, false);
954
955
956
957
958
959
960
961
962

#if 0
			// TESTCASE
			double minbinvalue = m_instrWidget->getInstrumentActor()->minBinValue();
			double maxbinvalue = m_instrWidget->getInstrumentActor()->maxBinValue();
			std::cout << "Range of X: " << minbinvalue << ", " << maxbinvalue << ".\n";

#endif

963
964
965
966
967
  enableApplyButtons();
  QApplication::restoreOverrideCursor();
}

/**
LamarMoore's avatar
LamarMoore committed
968
969
970
971
972
 * Save the constructed mask to a file.
 * The mask is not applied to the data workspace being displayed.
 * @param invertMask ::  if true, the selected mask will be inverted; if false,
 * the mask will be used as is
 */
973
974
975
976
977
978
979
980
981
982
983
984
985
void InstrumentWidgetMaskTab::saveMaskingToFile(bool invertMask) {
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

  // Make sure we have stored the Mask in the helper MaskWorkspace
  storeDetectorMask(invertMask);
  setSelectActivity();
  Mantid::API::MatrixWorkspace_sptr outputWS = createMaskWorkspace(false, true);
  if (outputWS) {
    clearShapes();

    QApplication::restoreOverrideCursor();
    QString fileName = m_instrWidget->getSaveFileName(
        "Select location and name for the mask file",
986
        "XML files (*.xml);;All (*)");
987
988
989
990
991
992
993
994
995
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

    if (!fileName.isEmpty()) {

      // Call "SaveMask()"
      Mantid::API::IAlgorithm_sptr alg =
          Mantid::API::AlgorithmManager::Instance().create("SaveMask", -1);
      alg->setProperty(
          "InputWorkspace",
996
          std::dynamic_pointer_cast<Mantid::API::Workspace>(outputWS));
997
998
999
      alg->setPropertyValue("OutputFile", fileName.toStdString());
      alg->execute();
    }
1000
    Mantid::API::AnalysisDataService::Instance().remove(outputWS->getName());