Skip to content

Commit

Permalink
refs #4328 #3641. Improve merge process.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jan 6, 2012
1 parent 4abbbfb commit 21eb202
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ namespace MantidQt

void setGoniometerClicked();

void mergeClicked(bool);

private:
Ui::CreateMDWorkspace m_uiForm;
WorkspaceMementoCollection m_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,42 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="ck_merge">
<property name="text">
<string>Merge All MD Workspaces</string>
</property>
</widget>
<layout class="QHBoxLayout" name="mergeLayout">
<item>
<widget class="QCheckBox" name="ck_merge">
<property name="text">
<string>Merge All MD Workspaces</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lbl_merged_name">
<property name="text">
<string>name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="txt_merged_workspace_name">
<property name="toolTip">
<string>Name for the merged workspace</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="btn_create">
Expand All @@ -291,6 +322,9 @@
<bold>true</bold>
</font>
</property>
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Create MD Workspace(s)</string>
</property>
Expand Down
47 changes: 43 additions & 4 deletions Code/Mantid/MantidQt/CustomInterfaces/src/CreateMDWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Initalize the layout.
void CreateMDWorkspace::initLayout()
{
m_uiForm.setupUi(this);
connect(m_uiForm.ck_merge, SIGNAL(clicked(bool)), this, SLOT(mergeClicked(bool)));
connect(m_uiForm.btn_create, SIGNAL(clicked()), this, SLOT(createMDWorkspaceClicked()));
connect(m_uiForm.btn_add_workspace, SIGNAL(clicked()), this, SLOT(addWorkspaceClicked()));
connect(m_uiForm.btn_add_nexus_file, SIGNAL(clicked()), this, SLOT(addNexusFileClicked()));
Expand All @@ -106,6 +107,8 @@ void CreateMDWorkspace::initLayout()
//Set MVC Model
m_uiForm.tableView->setModel(m_model);
this->setWindowTitle("Create MD Workspaces");
m_uiForm.txt_merged_workspace_name->setEnabled(m_uiForm.ck_merge->isChecked());
m_uiForm.lbl_merged_name->setEnabled(m_uiForm.ck_merge->isChecked());
}

/*
Expand Down Expand Up @@ -185,6 +188,14 @@ void CreateMDWorkspace::findUBMatrixClicked()
}
}

/// Event handler for selecting merging.
void CreateMDWorkspace::mergeClicked(bool)
{
bool isEnabled = m_uiForm.ck_merge->isChecked();
m_uiForm.txt_merged_workspace_name->setEnabled(isEnabled);
m_uiForm.lbl_merged_name->setEnabled(isEnabled);
}

/*
Getter for the first selected memento.
@return the first selected memento
Expand Down Expand Up @@ -415,6 +426,19 @@ int CreateMDWorkspace::runConfirmation(const std::string& message)

void CreateMDWorkspace::createMDWorkspaceClicked()
{
QString mergedWorkspaceName = m_uiForm.txt_merged_workspace_name->text().trimmed();

if(m_data.size() == 0)
{
runConfirmation("Nothing to process. Add workspaces first.");
return;
}
if(m_uiForm.ck_merge->isChecked() && mergedWorkspaceName.isEmpty())
{
runConfirmation("A name must be provided for the merged workspace");
return;
}

CreateMDWorkspaceAlgDialog algDlg;
algDlg.setModal(true);
int result = algDlg.exec();
Expand All @@ -438,36 +462,51 @@ void CreateMDWorkspace::createMDWorkspaceClicked()
}

//2) Run ConvertToMDEvents on each workspace.
QString fileNames;
for(WorkspaceMementoCollection::size_type i = 0; i < m_data.size(); i++)
{
WorkspaceMemento_sptr currentMemento = m_data[i];
Workspace_sptr ws = currentMemento->applyActions();

//
QString command = "try:\n"
" ConvertToMDEvents(InputWorkspace='%1',OutputWorkspace='%1_md',OtherDimensions='%2',dEAnalysisMode='%3',QDimensions='%4',MinValues='%5',MaxValues='%6')\n"
" SaveMD(InputWorkspace='%1_md', Filename='%7/%1_md.nxs',MakeFileBacked='1')\n"
" mtd.deleteWorkspace('%1_md')\n"
"except:\n"
" print 'FAIL'";

command = command.arg(QString(currentMemento->getId().c_str()), otherDimensions, analysisMode, qDimension, minExtents, maxExtents, location);
QString id(currentMemento->getId().c_str());
command = command.arg(id, otherDimensions, analysisMode, qDimension, minExtents, maxExtents, location);
QString pyOutput = runPythonCode(command).trimmed();
if(pyOutput == "FAIL")
{
runConfirmation("Aborted during conversion. See log messages.");
return; //Abort.
}

if(i != 0)
{
fileNames += ",";
}
fileNames += location + "/" + id + "_md.nxs";
currentMemento->cleanUp();
}


//3) Run Merge algorithm (if required)
if(m_uiForm.ck_merge->isChecked())
{
//QString command = ""
// "";
QString command = "try:"
" MergeMD(Filenames='%1',OutputFilename='%2/%3.nxs',OutputWorkspace='%3')\n"
"except:\n"
" print 'FAIL'";

command = command.arg(fileNames, location, mergedWorkspaceName);
QString pyOutput = runPythonCode(command).trimmed();
if(pyOutput == "FAIL")
{
runConfirmation("Aborted during merge. See log messages.");
}
}

}
Expand Down

0 comments on commit 21eb202

Please sign in to comment.