From 24e91fded8fe083593e02dfa9139f1aa4ddbacac Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Thu, 1 Apr 2010 12:01:05 +0000 Subject: [PATCH] Fix for missing fields in table extracted from Instrument view. Re #866 --- .../InstrumentWidget/InstrumentWindow.cpp | 12 ++-- .../InstrumentWidget/InstrumentWindow.h | 2 +- Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp | 62 ++++++++++++------- Code/qtiplot/qtiplot/src/Mantid/MantidUI.h | 3 +- 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp b/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp index 8d192d7bc12..661d8cc5072 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp @@ -170,7 +170,7 @@ InstrumentWindow::InstrumentWindow(const QString& label, ApplicationWindow *app mPlotAction = new QAction(tr("&Plot Spectra"), this); connect(mPlotAction,SIGNAL(triggered()),this,SLOT(plotSelectedSpectra())); - mDetTableAction = new QAction(tr("&Detector Table"), this); + mDetTableAction = new QAction(tr("&Extract Data"), this); connect(mDetTableAction, SIGNAL(triggered()), this, SLOT(showDetectorTable())); mGroupDetsAction = new QAction(tr("&Group"), this); @@ -311,7 +311,7 @@ void InstrumentWindow::plotSelectedSpectra() */ void InstrumentWindow::showDetectorTable() { - emit createDetectorTable(mInstrumentDisplay->getWorkspaceName(), mInstrumentDisplay->getSelectedWorkspaceIndices()); + emit createDetectorTable(mInstrumentDisplay->getWorkspaceName(), mInstrumentDisplay->getSelectedWorkspaceIndices(), true); } QString InstrumentWindow::confirmDetectorOperation(const QString & opName, const QString & inputWS, int ndets) @@ -364,12 +364,10 @@ void InstrumentWindow::maskDetectors() const std::vector<int> & wksp_indices = mInstrumentDisplay->getSelectedWorkspaceIndices(); const std::vector<int> & det_ids = mInstrumentDisplay->getSelectedDetectorIDs(); QString inputWS = mInstrumentDisplay->getWorkspaceName(); - QString outputWS = confirmDetectorOperation("masked", inputWS, static_cast<int>(det_ids.size())); - if( outputWS.isEmpty() ) return; - - QString param_list = "InputWorkspace=%1;OutputWorkspace=%2;WorkspaceIndexList=%3"; + // Masking can only replace the input workspace so no need to ask for confirmation + QString param_list = "Workspace=%1;WorkspaceIndexList=%2"; QString indices = asString(mInstrumentDisplay->getSelectedWorkspaceIndices()); - emit execMantidAlgorithm("MaskDetectors",param_list.arg(inputWS, outputWS, asString(wksp_indices))); + emit execMantidAlgorithm("MaskDetectors",param_list.arg(inputWS, asString(wksp_indices))); } /** diff --git a/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.h b/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.h index 8038d9413b9..1ecc0397b3a 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.h +++ b/Code/qtiplot/qtiplot/src/Mantid/InstrumentWidget/InstrumentWindow.h @@ -107,7 +107,7 @@ public slots: signals: void plotSpectra(const QString&,const std::set<int>&); - void createDetectorTable(const QString&,const std::vector<int>&); + void createDetectorTable(const QString&,const std::vector<int>&,bool); void execMantidAlgorithm(const QString&,const QString&); private slots: diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp index 2cef60a8bd1..095e828c566 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.cpp @@ -660,12 +660,26 @@ Table* MantidUI::createTableDetectors(MantidMatrix *m) return createDetectorTable(m->workspaceName(), indices); } -Table* MantidUI::createDetectorTable(const QString & wsName, const std::vector<int>& indices) +Table* MantidUI::createDetectorTable(const QString & wsName, const std::vector<int>& indices, bool include_data) { const int nrows = indices.size(); - Table* t = new Table(appWindow()->scriptingEnv(), nrows, 6, "", appWindow(), 0); + int ncols = 6; + QStringList col_names; + col_names << "Index" << "Spectra" << "Detector ID"; + if( include_data ) + { + ncols += 2; + col_names << "Data Value" << "Data Error"; + } + col_names << "R" << "Theta" << "Phi"; + + Table* t = new Table(appWindow()->scriptingEnv(), nrows, ncols, "", appWindow(), 0); appWindow()->initTable(t, appWindow()->generateUniqueName(wsName + "-Detectors-")); - t->showNormal(); + //Set the column names + for( int col = 0; col < ncols; ++col ) + { + t->setColName(col, col_names[col]); + } MatrixWorkspace_sptr ws; if( AnalysisDataService::Instance().doesExist(wsName.toStdString()) ) @@ -673,13 +687,18 @@ Table* MantidUI::createDetectorTable(const QString & wsName, const std::vector<i ws = boost::dynamic_pointer_cast<MatrixWorkspace>(AnalysisDataService::Instance().retrieve(wsName.toStdString())); } - if( !ws ) return NULL; + if( !ws ) + { + delete t; + return NULL; + } Mantid::API::Axis *spectraAxis = ws->getAxis(1); Mantid::Geometry::IObjComponent_const_sptr sample = ws->getInstrument()->getSample(); - for( int i = 0; i < nrows; ++i ) + QList<double> col_values; + for( int row = 0; row < nrows; ++row ) { - int ws_index = indices[i]; + int ws_index = indices[row]; int currentSpec = spectraAxis->spectraNo(ws_index); int detID = 0; double R(0.0), Theta(0.0), Phi(0.0); @@ -698,24 +717,19 @@ Table* MantidUI::createDetectorTable(const QString & wsName, const std::vector<i { detID = 0; } - t->setCell(i,0,ws_index); - if (i == 0) t->setColName(0,"Index"); - - t->setCell(i,1,currentSpec); - if (i == 0) t->setColName(1,"Spectra"); - - t->setCell(i,2,detID); - if (i == 0) t->setColName(2,"Detectors"); - - t->setCell(i,3,R); - if (i == 0) t->setColName(3,"R"); - - t->setCell(i,4,Theta); - if (i == 0) t->setColName(4,"Theta"); + col_values << static_cast<double>(ws_index) << static_cast<double>(currentSpec) << static_cast<double>(detID); + if( include_data ) + { + col_values << ws->readY(ws_index)[0] << ws->readE(ws_index)[0]; + } + col_values << R << Theta << Phi; + for(int col = 0; col < ncols; ++col) + { + t->setCell(row, col, col_values[col]); + } - t->setCell(i,5,Phi); - if (i == 0) t->setColName(5,"Phi"); } + t->showNormal(); return t; } @@ -1235,8 +1249,8 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName) connect (insWin,SIGNAL(showContextMenu()), appWindow(),SLOT(showWindowContextMenu())); connect(insWin,SIGNAL(plotSpectra(const QString&,const std::set<int>&)),this, SLOT(plotSpectraList(const QString&,const std::set<int>&))); - connect(insWin,SIGNAL(createDetectorTable(const QString&,const std::vector<int>&)),this, - SLOT(createDetectorTable(const QString&,const std::vector<int>&))); + connect(insWin,SIGNAL(createDetectorTable(const QString&,const std::vector<int>&,bool)),this, + SLOT(createDetectorTable(const QString&,const std::vector<int>&,bool))); connect(insWin, SIGNAL(execMantidAlgorithm(const QString&,const QString&)), this, SLOT(executeAlgorithm(const QString&, const QString&))); return insWin; diff --git a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h index 93f1aa136c1..8bec8b38c2c 100644 --- a/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h +++ b/Code/qtiplot/qtiplot/src/Mantid/MantidUI.h @@ -186,7 +186,8 @@ public: // Creates and shows a Table with detector ids for the workspace in the MantidMatrix Table* createTableDetectors(MantidMatrix *m); public slots: - Table* createDetectorTable(const QString & wsName, const std::vector<int>& indices); + /// 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); // ***** ***** // public: -- GitLab