Mantid
Loading...
Searching...
No Matches
WorkspacePresenter.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
13
14using namespace Mantid;
15
17
19 : m_view(view), m_adapter(std::make_unique<ADSAdapter>()) {}
20
22
25
28 switch (flag) {
31 break;
34 break;
37 break;
40 break;
43 break;
46 break;
49 break;
51 updateView();
52 break;
53 }
54}
55
58 switch (flag) {
61 break;
64 break;
67 break;
70 break;
73 break;
76 break;
79 break;
82 break;
85 break;
88 break;
91 break;
94 break;
97 break;
100 break;
103 break;
105 plotSpectrum();
106 break;
109 break;
112 break;
115 break;
118 break;
121 break;
123 showMDPlot();
124 break;
126 showListData();
127 break;
130 break;
133 break;
135 showLogs();
136 break;
139 break;
142 break;
145 break;
148 break;
151 break;
154 break;
157 break;
158 }
159}
160
162
164
166
168 auto selected = m_view->getSelectedWorkspaceNames();
169
170 std::string groupName("NewGroup");
171 // get selected workspaces
172 if (selected.size() < 2) {
173 m_view->showCriticalUserMessage("Cannot Group Workspaces", "Select at least two workspaces to group ");
174 return;
175 }
176
177 if (m_adapter->doesWorkspaceExist(groupName)) {
178 if (!m_view->askUserYesNo("", "Workspace " + groupName + " already exists. Do you want to replace it?"))
179 return;
180 }
181
182 try {
183 std::string algName("GroupWorkspaces");
185 alg->initialize();
186 alg->setProperty("InputWorkspaces", selected);
187 alg->setPropertyValue("OutputWorkspace", groupName);
188 // execute the algorithm
189 bool bStatus = alg->execute();
190 if (!bStatus) {
191 m_view->showCriticalUserMessage("Mantid - Algorithm error", " Error in GroupWorkspaces algorithm");
192 }
193 } catch (...) {
194 m_view->showCriticalUserMessage("Mantid - Algorithm error", " Error in GroupWorkspaces algorithm");
195 }
196}
197
199 auto selected = m_view->getSelectedWorkspaceNames();
200
201 if (selected.size() == 0) {
202 m_view->showCriticalUserMessage("Error Ungrouping Workspaces", "Select a group workspace to Ungroup.");
203 return;
204 }
205
206 try {
207 // workspace name
208 auto wsname = selected[0];
209
210 std::string algName("UnGroupWorkspace");
212 alg->initialize();
213 alg->setProperty("InputWorkspace", wsname);
214
215 // execute the algorithm
216 bool bStatus = alg->execute();
217 if (!bStatus) {
218 m_view->showCriticalUserMessage("Mantid - Algorithm error", " Error in UnGroupWorkspace algorithm");
219 }
220 } catch (...) {
221 m_view->showCriticalUserMessage("Mantid - Algorithm error", " Error in UnGroupWorkspace algorithm");
222 }
223}
224
227}
228
230 bool deleteWs = true;
231 auto selected = m_view->getSelectedWorkspaceNames();
232
233 // Ensure all workspaces exist in the ADS
234 if (!std::all_of(selected.cbegin(), selected.cend(),
235 [=](const std::string &ws) { return m_adapter->doesWorkspaceExist(ws); })) {
236 m_view->showCriticalUserMessage("Delete Workspaces",
237 "Unable to delete workspaces. Invalid workspace names provided.");
238 return;
239 }
240
241 if (m_view->isPromptDelete())
242 deleteWs = m_view->deleteConfirmation();
243
244 if (deleteWs)
245 m_view->deleteWorkspaces(selected);
246}
247
252 }
253}
254
257}
258
260
262
264
266
268
270
272
274
276
278
280
282
284
286
288
290
292
294
296
298
300
302
304 auto wsNames = m_view->getSelectedWorkspaceNames();
305
306 for (auto &ws : wsNames) {
307 auto alg = Mantid::API::AlgorithmManager::Instance().create("ClearUB", -1);
308 if (alg) {
309 alg->initialize();
310 alg->setPropertyValue("Workspace", ws);
311 // Run in this manner due to Qt dependencies within this method.
312 // otherwise it would have been implemented here.
314 } else
315 break;
316 }
317}
318
320
322
324 m_view->recordWorkspaceRename(m_adapter->getOldName(), m_adapter->getNewName());
325 m_view->updateTree(m_adapter->topLevelItems());
326}
327
331
333
335
338
339} // namespace MantidQt::MantidWidgets
virtual bool clearWorkspacesConfirmation() const =0
virtual void updateTree(const std::map< std::string, Mantid::API::Workspace_sptr > &items)=0
virtual void plotSpectrum(const std::string &type)=0
virtual SortCriteria getSortCriteria() const =0
virtual void showCriticalUserMessage(const std::string &caption, const std::string &message) const =0
virtual StringList getSelectedWorkspaceNames() const =0
virtual Mantid::API::Workspace_sptr getSelectedWorkspace() const =0
virtual void showRenameDialog(const StringList &wsNames)=0
virtual void enableClearButton(bool enable)=0
virtual void recordWorkspaceRename(const std::string &oldName, const std::string &newName)=0
virtual void saveWorkspace(const std::string &wsName, const SaveFileType type)=0
virtual WorkspacePresenterWN_wptr getPresenterWeakPtr()=0
virtual void saveWorkspaces(const StringList &wsNames)=0
virtual SortDirection getSortDirection() const =0
virtual SaveFileType getSaveFileType() const =0
virtual void sortWorkspaces(SortCriteria criteria, SortDirection direction)=0
virtual bool executeAlgorithmAsync(Mantid::API::IAlgorithm_sptr alg, const bool wait=true)=0
virtual std::string getFilterText() const =0
virtual bool askUserYesNo(const std::string &caption, const std::string &message) const =0
virtual void deleteWorkspaces(const StringList &wsNames)=0
virtual bool deleteConfirmation() const =0
virtual void filterWorkspaces(const std::string &filterText)=0
void notifyFromWorkspaceProvider(WorkspaceProviderNotifiable::Flag flag) override
Handle WorkspaceProvider (ADS) notifications.
void updateView()
Update the view by publishing the ADS contents.
void init()
Initialises the view weak pointer for the Workspace Provider.
void notifyFromView(ViewNotifiable::Flag flag) override
Handle notifications from the view.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.