/
MantidUI.h
543 lines (407 loc) · 21.1 KB
/
MantidUI.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#ifndef MANTIDUI_H
#define MANTIDUI_H
//----------------------------------
// Includes
//----------------------------------
#include "../ApplicationWindow.h"
#include "../Graph.h"
#include "MantidAlgorithmMetatype.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AlgorithmFactory.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Workspace.h"
#include "MantidQtAPI/AlgorithmDialog.h"
#include <Poco/NObserver.h>
#include <QDockWidget>
#include <QTreeWidget>
#include <QProgressDialog>
#include <QMap>
#include <QMutex>
//----------------------------------
// Forward declarations
//----------------------------------
class Graph3D;
class ScriptingEnv;
class MantidMatrix;
class MantidDockWidget;
class AlgorithmDockWidget;
class RemoteClusterDockWidget;
class AlgorithmMonitor;
class InstrumentWindow;
namespace MantidQt
{
namespace API
{
class Message;
}
namespace MantidWidgets
{
class FitPropertyBrowser;
}
}
namespace Ui
{
class SequentialFitDialog;
}
namespace Mantid
{
namespace API
{
class AlgorithmObserver;
}
}
/**
MantidUI is the extension of QtiPlot's ApplicationWindow which deals with Mantid framework.
@author Roman Tolchenov, Tessella Support Services plc
@date 02/07/2008
Copyright © 2008 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
/// Required by Qt to use Mantid::API::Workspace_sptr as a parameter type in signals
Q_DECLARE_METATYPE(Mantid::API::Workspace_sptr)
Q_DECLARE_METATYPE(Mantid::API::MatrixWorkspace_sptr)
Q_DECLARE_METATYPE(Mantid::API::MatrixWorkspace_const_sptr)
Q_DECLARE_METATYPE(std::string)
class MantidUI:public QObject
{
Q_OBJECT
public:
// Constructor
MantidUI(ApplicationWindow *aw);
// Destructor
~MantidUI();
//Clear the framework
void shutdown();
// Save settings to a persistent store
void saveSettings() const;
// Initialization
void init();
// Insert relevant items into a menu
void addMenuItems(QMenu *menu);
// Pointer to QtiPLot main window
ApplicationWindow *appWindow(){return m_appWindow;}
// Returns a list of open workspaces
QStringList getWorkspaceNames();
// Returns a list of registered algorithms
QStringList getAlgorithmNames();
// Returns the number of algorithms currently executing
int runningAlgCount() const;
// Create an algorithm using Mantid FrameworkManager
// Create a pointer to the named algorithm and version
Mantid::API::IAlgorithm_sptr createAlgorithm(const QString& algName, int version = -1);
// Execute algorithm asinchronously
bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, const bool wait = false);
// Gets a pointer to workspace workspaceName
Mantid::API::Workspace_const_sptr getWorkspace(const QString& workspaceName);
// Deletes workspace from QtiPlot
void deleteWorkspace(const QString& workspaceName);
// Returns the name of selected workspace in exploreMantid window
QString getSelectedWorkspaceName();
// Returns the pointer of workspace selected in exploreMantid window
Mantid::API::Workspace_const_sptr getSelectedWorkspace();
// Returns the name and version of the algorithm selected in algorithm dock window
void getSelectedAlgorithm(QString& algName, int& version);
// Adjusts QtiPlot's main menu if a MantidMatrix becomes active (receives focus)
bool menuAboutToShow(MdiSubWindow *w);
// Prepares the contex menu for MantidMatrix
void showContextMenu(QMenu& cm, MdiSubWindow* w);
// Handles workspace drop operation to QtiPlot (imports the workspace to MantidMatrix)
bool drop(QDropEvent* e);
// ***** Plotting Methods ***** //
// Creates a 3D plot in QtiPlot if the active window is a MantidMatrix
Graph3D *plot3DMatrix(int style);
// Creates a 2D plot in QtiPlot if the active window is a MantidMatrix
MultiLayer *plotSpectrogram(Graph::CurveType type);
/// Create a Table form specified spectra in a MatrixWorkspace
Table* createTableFromSpectraList(const QString& tableName, const QString& workspaceName, QList<int> indexList, bool errs=true, bool binCentres=false);
// Copies selected rows from MantidMatrix to Y and errY columns of a new Table.
Table* createTableFromSelectedRows(MantidMatrix *m, bool errs = true, bool binCentres=false);
/// Create a 1d graph form a Table
MultiLayer* createGraphFromTable(Table* t, int type = 0);
// Shows 1D graphs of the spectra (rows) selected in a MantidMatrix
MultiLayer* plotSelectedRows(const MantidMatrix * const m, bool errs = true, bool distr = false);
AlgorithmMonitor* getAlgMonitor(){return m_algMonitor;}
/// updates the algorithms tree
void updateAlgorithms();
/// Show the algorithm dock widget
void showAlgWidget(bool on = true);
/// Plot a 1D graph for an integrated mdworkspace
MultiLayer* plotMDList(const QStringList& wsNames, const int plotAxis,
const Mantid::API::MDNormalization normalization, const bool showError, MultiLayer* plotWindow = NULL,
bool clearWindow = false);
public slots:
// Create a 1d graph form specified spectra in a MatrixWorkspace
MultiLayer* plotSpectraList(const QStringList& wsnames, const QList<int>& spec_list, bool errs=true,
Graph::CurveType style = Graph::Unspecified, MultiLayer* plotWindow = NULL, bool clearWindow = false);
MultiLayer* plotSpectraList(const QString& wsName, const std::set<int>& indexList, bool errs=false,
bool distr=false, MultiLayer* plotWindow = NULL, bool clearWindow = false);
MultiLayer* plotSpectraList(const QMultiMap<QString,int>& toPlot, bool errs=false, bool distr=false,
Graph::CurveType style = Graph::Unspecified, MultiLayer* plotWindow = NULL, bool clearWindow = false);
MultiLayer* plotSpectraList(const QMultiMap<QString,std::set<int> >& toPlot, bool errs=false, bool distr=false,
MultiLayer* plotWindow = NULL, bool clearWindow = false);
/// Draw a color fill plot for each of the listed workspaces
void drawColorFillPlots(const QStringList & wsNames, Graph::CurveType curveType = Graph::ColorMap);
/// Draw a color fill plot for the named workspace
MultiLayer* drawSingleColorFillPlot(const QString & wsName, Graph::CurveType curveType = Graph::ColorMap,
MultiLayer* window = NULL);
// Create a 1d graph form specified spectra in a MatrixWorkspace
MultiLayer* plotSpectraRange(const QString& wsName, int i0, int i1, bool errs=true, bool distr=false);
// Set properties of a 1d graph which plots data from a workspace
static void setUpBinGraph(MultiLayer* ml, const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace);
// Copy to a Table Y-values (and Err-values if errs==true) of bins with indeces from i0 to i1 (inclusive) from a workspace
Table* createTableFromBins(const QString& wsName, Mantid::API::MatrixWorkspace_const_sptr workspace, const QList<int>& bins, bool errs=true,int fromRow = -1, int toRow = -1);
// Copies selected columns (time bins) in a MantidMatrix to a Table
Table* createTableFromSelectedColumns(MantidMatrix *m, bool errs);
// Shows 1D graphs of selected time bins (columns) in a MantidMatrix
MultiLayer* createGraphFromSelectedColumns(MantidMatrix *m, bool errs = true, bool tableVisible = false);
// Creates and shows a Table with detector ids for the workspace in the MantidMatrix
Table* createTableDetectors(MantidMatrix *m);
/// Create a table showing detector information for the given workspace and indices and optionally the data for that detector
Table* createDetectorTable(const QString & wsName, const std::vector<int>& indices, bool include_data = false);
/// Create the instrument detector table from a MatrixWorkspace
Table* createDetectorTable(const QString & wsName, const Mantid::API::MatrixWorkspace_sptr & ws,
const std::vector<int>& indices, bool include_data = false);
/// Create a table of detectors from a PeaksWorkspace
Table* createDetectorTable(const QString & wsName, const Mantid::API::IPeaksWorkspace_sptr & ws);
// Determine whether the workspace has a UB matrix
bool hasUB(const QString& wsName);
// Clear the UB via the ClearUB algorithm
void clearUB(const QStringList& workspaces);
// ***** ***** //
void renameWorkspace(QStringList = QStringList());
/**
* Set the currently used fit property browser. Is needed because e.g. Muon Analysis is using its
* own fit browser.
* @param newBrowser The browser to be used. If is null, is set to default one.
*/
void setFitFunctionBrowser(MantidQt::MantidWidgets::FitPropertyBrowser* newBrowser);
public:
// Return pointer to the fit function property browser
MantidQt::MantidWidgets::FitPropertyBrowser* fitFunctionBrowser(){return m_fitFunction;}
MultiLayer* mergePlots(MultiLayer* g1, MultiLayer* g2);
MantidMatrix* getMantidMatrix(const QString& wsName);
MantidMatrix* newMantidMatrix(const QString& name, int start=-1, int end=-1);
MultiLayer* plotBin(const QString& wsName, const QList<int> & bins, bool errors = false,
Graph::CurveType style = Graph::Line, MultiLayer* plotWindow = NULL, bool clearWindow = false);
void setIsRunning(bool running);
bool createPropertyInputDialog(const QString & alg_name, const QString & preset_values,
const QString & optional_msg, const QStringList & enabled, const QStringList & disabled);
/// Group selected workspaces
void groupWorkspaces();
/// UnGroup selected groupworkspace
void ungroupWorkspaces();
/** save the workspace data to nexus file
This method is useful when a project is saved from mantidplot
*/
void savedatainNexusFormat(const std::string& fileName,const std::string & wsName);
/** load data from nexus file.This method is useful
when a project is opened from mantidplot
*/
void loaddataFromNexusFile(const std::string& wsname,const std::string& fileName,bool project=false);
void loadadataFromRawFile(const std::string& wsname,const std::string& fileName,bool project=false);
MantidMatrix* openMatrixWorkspace(ApplicationWindow* parent,const QString& wsName,int lower,int upper);
void saveProject(bool save);
void enableSaveNexus(const QString & wsName);
signals:
//A signal to indicate that we want a script to produce a dialog
void showPropertyInputDialog(const QString & algName);
// Broadcast that an algorithm is about to be created
void algorithmAboutToBeCreated();
public:
signals:
// These signals are to be fired from methods run in threads other than the main one
// (e.g. handlers of algorithm notifications)
void workspaces_cleared();
void ADS_updated();
void workspace_renamed(QString,QString);
void needToCreateLoadDAEMantidMatrix(const QString&);
// Display a critical error dialog box
void needToShowCritical(const QString&);
// Signals that the fit property browser has updated its X range
void x_range_update(double, double);
public slots:
// Receives a new X range from a PeakPickerTool and re-emits it.
void x_range_from_picker(double, double);
void test();
void showSequentialPlot(Ui::SequentialFitDialog* ui, MantidQt::MantidWidgets::FitPropertyBrowser* fitbrowser);
// Import the workspace selected in the Workspace dock window
void importWorkspace();
void importBoxDataTable();
void importTransposed();
// Invoke the Vates Simple User Interface
void showVatesSimpleInterface();
// Invoke the plot of MD intensity vs non-integrated dimension.
void showMDPlot();
// Invoke a grid showing a table of MD summary list data.
void showListData();
// SpectrumViewer
void showSpectrumViewer();
// SliceViewer
void showSliceViewer();
// #539: For adding Workspace History display to MantidPlot
void showAlgorithmHistory();
// Import a workspace wsName
void importWorkspace(const QString& wsName, bool showDlg = true, bool makeVisible = true);
// Create a MantidMatrix from workspace wsName
MantidMatrix *importMatrixWorkspace(const QString& wsName, int lower = -1, int upper = -1,
bool showDlg = true, bool makeVisible = true);
// Create a MantidMatrix from workspace wsName
Table *importTableWorkspace(const QString& wsName, bool showDlg = true, bool makeVisible = true, bool transpose = false);
void createLoadDAEMantidMatrix(const QString&);
// Slots responding to MantidMatrix context menu commands
void copyRowToTable();
void copyColumnToTable();
void copyRowToGraph();
void copyColumnToGraph();
void copyRowToGraphErr();
void copyColumnToGraphErr();
void copyDetectorsToTable();
void copyValues();
void copyRowsToWaterfall();
// Slot callable from Workspace menu item
void plotWholeAsWaterfall();
/// Common method to convert a plot of a set of spectra into a waterfall plot
void convertToWaterfall(MultiLayer* ml);
// Execute algorithm given name and version
bool executeAlgorithm(const QString & algName, int version = -1);
//Execute an algorithm with the given parameter list
void executeAlgorithm(const QString & algName, const QString & paramList,Mantid::API::AlgorithmObserver* obs = NULL);
//Execute an algorithm with the given parameter list
void executeAlgorithm(QString algName, QMap<QString,QString> paramList,Mantid::API::AlgorithmObserver* obs = NULL);
//Execute an algorithm with the given parameter list
void executeAlgorithmDlg(QString algName, QMap<QString,QString> paramList,Mantid::API::AlgorithmObserver* obs = NULL);
// Execute an algorithm
void executeAlgorithm(Mantid::API::IAlgorithm_sptr alg);
// Find the name of the first input workspace for an algorithm
QString findInputWorkspaceProperty(Mantid::API::IAlgorithm_sptr algorithm) const;
// Show Qt critical error message box
void showCritical(const QString&);
// Show the dialog monitoring currently running algorithms
void showAlgMonitor();
// Called from ApplicationWindow to customize the main menu
void mantidMenuAboutToShow();
void manageMantidWorkspaces();
//Python related functions
InstrumentWindow* getInstrumentView(const QString & wsName, int tab = -1);
void showMantidInstrument();
// Show instrument for the selected workspace
void showMantidInstrumentSelected();
// Show instrument. Workspace name is passed as the argument
void showMantidInstrument(const QString&);
// Show log files for selected workspace
void showLogFileWindow();
void insertMenu();
// Customize MantidMatrix menu.
void menuMantidMatrixAboutToShow();
// Show / hide the FitPropertyBrowser
void showFitPropertyBrowser(bool on = true);
// Plot a spectrum in response from a InstrumentWindow signal
MultiLayer* plotInstrumentSpectrum(const QString&,int);
MultiLayer* plotInstrumentSpectrumList(const QString&,std::set<int>);
void importString(const QString &logName, const QString &data);
void importString(const QString &logName, const QString &data, const QString &sep, const QString &wsName = QString());
void importStrSeriesLog(const QString &logName, const QString &data, const QString &wsName = QString());
void importNumSeriesLog(const QString &wsName, const QString &logname, int filter);
// Clear all Mantid related memory
void clearAllMemory();
void releaseFreeMemory();
// Ticket #672
void saveNexusWorkspace();
QString saveToString(const std::string &workingDir);
#ifdef _WIN32
public:
// Shows 2D plot of current memory usage.
void memoryImage();
void memoryImage2();
#endif
private:
// Notification handlers and corresponding observers.
void handleLoadDAEFinishedNotification(const Poco::AutoPtr<Mantid::API::Algorithm::FinishedNotification>& pNf);
Poco::NObserver<MantidUI, Mantid::API::Algorithm::FinishedNotification> m_finishedLoadDAEObserver;
void handleAddWorkspace(Mantid::API::WorkspaceAddNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspaceAddNotification> m_addObserver;
void handleReplaceWorkspace(Mantid::API::WorkspaceAfterReplaceNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspaceAfterReplaceNotification> m_replaceObserver;
void handleDeleteWorkspace(Mantid::API::WorkspacePostDeleteNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspacePostDeleteNotification> m_deleteObserver;
void handleClearADS(Mantid::API::ClearADSNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::ClearADSNotification> m_clearADSObserver;
//handles rename workspace notification
void handleRenameWorkspace(Mantid::API::WorkspaceRenameNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspaceRenameNotification> m_renameObserver;
//handles notification send by Groupworkspaces algorithm
void handleGroupWorkspaces(Mantid::API::WorkspacesGroupedNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspacesGroupedNotification> m_groupworkspacesObserver;
//handles notification send by UnGroupworkspaces algorithm
void handleUnGroupWorkspace(Mantid::API::WorkspaceUnGroupingNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::WorkspaceUnGroupingNotification> m_ungroupworkspaceObserver;
//handles notification send by a WorkspaceGroup instance
void handleWorkspaceGroupUpdate(Mantid::API::GroupUpdatedNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::API::GroupUpdatedNotification> m_workspaceGroupUpdateObserver;
// handles notification send by ConfigService, change on pythonscripts.directories
void handleConfigServiceUpdate(Mantid::Kernel::ConfigValChangeNotification_ptr pNf);
Poco::NObserver<MantidUI, Mantid::Kernel::ConfigValChangeNotification> m_configServiceObserver;
//#678
//for savenexus algorithm
void executeSaveNexus(QString algName,int version);
void copyWorkspacestoVector(const QList<QTreeWidgetItem*> &list,std::vector<std::string> &inputWS);
void PopulateData(Mantid::API::Workspace_sptr ws_ptr,QTreeWidgetItem* wsid_item);
/// This creates an algorithm dialog.
MantidQt::API::AlgorithmDialog * createAlgorithmDialog(Mantid::API::IAlgorithm_sptr alg);
/// This method accepts user inputs and executes loadraw/load nexus algorithm
void executeAlgorithm(MantidQt::API::AlgorithmDialog* dlg,Mantid::API::IAlgorithm_sptr alg);
/// This method accepts user inputs and executes loadraw/load nexus algorithm
std::string extractLogTime(Mantid::Kernel::DateAndTime value,bool useAbsoluteDate, Mantid::Kernel::DateAndTime start);
///extracts the files from a mimedata object that have a .py extension
QStringList extractPyFiles(const QList<QUrl>& urlList) const;
// Private variables
ApplicationWindow *m_appWindow; // QtiPlot main ApplicationWindow
MantidDockWidget *m_exploreMantid; // Dock window for manipulating workspaces
AlgorithmDockWidget *m_exploreAlgorithms; // Dock window for using algorithms
RemoteClusterDockWidget *m_exploreRemoteTasks; // Dock window for using remote tasks
/// Current fit property browser being used
MantidQt::MantidWidgets::FitPropertyBrowser* m_fitFunction;
/// Default fit property browser (the one docked on the left)
MantidQt::MantidWidgets::FitPropertyBrowser* m_defaultFitFunction;
QAction *actionCopyRowToTable;
QAction *actionCopyRowToGraph;
QAction *actionCopyRowToGraphErr;
QAction *actionWaterfallPlot;
QAction *actionCopyColumnToTable;
QAction *actionCopyColumnToGraph;
QAction *actionCopyColumnToGraphErr;
QAction *actionToggleMantid;
QAction *actionToggleAlgorithms;
QAction *actionToggleRemoteTasks;
QAction *actionToggleFitFunction;
QAction *actionCopyDetectorsToTable;
QAction *actionCopyValues;
QMenu *mantidMenu;
QMenu *menuMantidMatrix; // MantidMatrix specific menu
AlgorithmMonitor *m_algMonitor; // Class for monitoring running algorithms
// Map of <workspace_name,update_interval> pairs. Positive update_intervals mean
// UpdateDAE must be launched after LoadDAE for this workspace
QMap<std::string,int> m_DAE_map;
// Stores dependent mdi windows. If the 'key' window closes, all 'value' ones must be closed as well.
std::multimap<MdiSubWindow*,MdiSubWindow*> m_mdiDependency;
QMdiSubWindow *m_vatesSubWindow; ///< Holder for the Vates interface sub-window
//prevents some repeated code realtating to log names
void formatLogName(QString &label, const QString &wsName);
};
#endif