25bool doesExistInADS(std::string
const &workspaceName) {
29std::string cutLastOf(
const std::string &str,
const std::string &delimiter) {
30 const auto cutIndex = str.rfind(delimiter);
31 if (cutIndex != std::string::npos)
32 return str.substr(0, cutIndex);
36std::string extractLastOf(
const std::string &str,
const std::string &delimiter) {
37 const auto cutIndex = str.rfind(delimiter);
38 if (cutIndex != std::string::npos)
39 return str.substr(cutIndex + 1, str.size() - cutIndex);
43bool fileFound(std::string
const &file) {
return !
FileFinder::Instance().getFullPath(file).empty(); }
45std::string loadAlgName(
const std::string &filePath) {
46 const auto suffix = extractLastOf(filePath,
".");
47 return suffix ==
"dave" ?
"LoadDaveGrp" :
"Load";
50void loadFile(std::string
const &filename, std::string
const &workspaceName) {
52 loadAlg->initialize();
53 loadAlg->setProperty(
"Filename", filename);
54 loadAlg->setProperty(
"OutputWorkspace", workspaceName);
63 :
API::
MantidWidget(parent), m_algRunner(), m_autoLoad(true), m_showLoad(true) {
74 this->setAcceptDrops(
true);
75 m_uiForm.rfFileInput->setAcceptDrops(
false);
101 QString filename =
m_uiForm.rfFileInput->getUserInput().toString();
103 if (filename.isEmpty()) {
163 if (
isValid && !doesExistInADS(wsName)) {
166 auto const filepath =
m_uiForm.rfFileInput->getUserInput().toString().toStdString();
167 if (!filepath.empty())
168 loadFile(filepath, wsName);
170 isValid = doesExistInADS(wsName);
173 m_uiForm.rfFileInput->setFileProblem(
"The specified workspace is "
174 "missing from the analysis data "
191 QString problem =
"";
193 problem =
m_uiForm.rfFileInput->getFileProblem();
194 if (problem.compare(
"") == 0) {
195 problem =
"Input field is empty";
198 problem =
"A valid workspace has not been selected";
217 loadAlg->initialize();
218 loadAlg->setProperty(
"Filename", filepath.toStdString());
219 loadAlg->setProperty(
"OutputWorkspace", baseName);
235 m_uiForm.rfFileInput->setFileProblem(
"Could not load file. See log for details.");
243 if (
m_uiForm.stackedDataSelect->currentIndex() > 0) {
245 QString filename =
m_uiForm.wsWorkspaceInput->currentText();
246 if (filename.isEmpty())
289 QFileInfo qfio(filepath);
290 QString baseName = qfio.completeBaseName();
293 if (
m_uiForm.rfFileInput->allowMultipleFiles() && filepath.count(
",") > 0) {
294 baseName +=
"_group";
313 QString filename(
"");
320 if (
m_uiForm.rfFileInput->isValid()) {
332 filename =
m_uiForm.wsWorkspaceInput->currentText();
393 m_uiForm.pbLoadFile->setEnabled(load);
394 m_uiForm.pbLoadFile->setVisible(load);
403 const QMimeData *mimeData = de->mimeData();
404 auto before_action = de->dropAction();
406 auto const dragData = mimeData->text().toStdString();
408 if (de->mimeData() && doesExistInADS(dragData)) {
409 m_uiForm.wsWorkspaceInput->dropEvent(de);
410 if (de->dropAction() == before_action) {
412 m_uiForm.cbInputType->setCurrentIndex(1);
415 de->setDropAction(before_action);
418 m_uiForm.rfFileInput->dropEvent(de);
419 if (de->dropAction() == before_action) {
420 m_uiForm.cbInputType->setCurrentIndex(0);
423 auto const filepath =
m_uiForm.rfFileInput->getText().toStdString();
424 if (de->mimeData() && !doesExistInADS(dragData) && !filepath.empty()) {
425 auto const file = extractLastOf(filepath,
"/");
426 if (fileFound(file)) {
427 auto const workspaceName = cutLastOf(file,
".");
428 loadFile(filepath, workspaceName);
431 m_uiForm.cbInputType->setCurrentIndex(1);
442 auto const index =
m_uiForm.wsWorkspaceInput->findText(workspaceName);
451 const QMimeData *mimeData = de->mimeData();
452 if (mimeData->hasText() || mimeData->hasUrls())
453 de->acceptProposedAction();
std::map< DeltaEMode::Type, std::string > index
virtual void startAlgorithm(Mantid::API::IAlgorithm_sptr alg)
Begin asynchronous execution of an algorithm and observe its execution.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
MANTID_KERNEL_DLL std::string loadFile(const std::string &filepath, const bool unixEOL)
Load contents of file into a string.