Commit 5bcf733d authored by Lamar Moore's avatar Lamar Moore
Browse files

Re #14911 Refactoring and encapsulation improvements

parent 47b9ac0b
......@@ -38,12 +38,16 @@ std::string InstrumentWindow::saveToProject(ApplicationWindow *app) {
TSVSerialiser tsv;
tsv.writeRaw("<instrumentwindow>");
tsv.writeLine("WorkspaceName")
<< m_instrumentWidget->getWorkspaceName().toStdString();
<< m_instrumentWidget->getWorkspaceNameStdString();
tsv.writeRaw(app->windowGeometryInfo(this));
tsv.writeRaw("</instrumentwindow>");
return tsv.outputLines();
}
void InstrumentWindow::selectTab(int tab) {
return m_instrumentWidget->selectTab(tab);
}
/**
* Closes the window if the associated workspace is deleted.
* @param ws_name :: Name of the deleted workspace.
......@@ -52,7 +56,7 @@ std::string InstrumentWindow::saveToProject(ApplicationWindow *app) {
void InstrumentWindow::preDeleteHandle(
const std::string &ws_name,
const boost::shared_ptr<Workspace> workspace_ptr) {
if (ws_name == m_instrumentWidget->getWorkspaceName().toStdString()) {
if (m_instrumentWidget->hasWorkspace(ws_name)) {
confirmClose(false);
close();
return;
......@@ -60,49 +64,20 @@ void InstrumentWindow::preDeleteHandle(
Mantid::API::IPeaksWorkspace_sptr pws =
boost::dynamic_pointer_cast<Mantid::API::IPeaksWorkspace>(workspace_ptr);
if (pws) {
m_instrumentWidget->getSurface()->deletePeaksWorkspace(pws);
m_instrumentWidget->updateInstrumentView();
m_instrumentWidget->deletePeaksWorkspace(pws);
return;
}
}
void InstrumentWindow::afterReplaceHandle(
const std::string &wsName, const boost::shared_ptr<Workspace> workspace) {
// Replace current workspace
if (wsName == m_instrumentWidget->getWorkspaceName().toStdString()) {
if (m_instrumentWidget->getInstrumentActor()) {
// Check if it's still the same workspace underneath (as well as having
// the same name)
auto matrixWS =
boost::dynamic_pointer_cast<const MatrixWorkspace>(workspace);
bool sameWS = false;
try {
sameWS = (matrixWS ==
m_instrumentWidget->getInstrumentActor()->getWorkspace());
} catch (std::runtime_error &) {
// Carry on, sameWS should stay false
}
// try to detect if the instrument changes (unlikely if the workspace
// hasn't, but theoretically possible)
bool resetGeometry =
matrixWS->getInstrument()->getNumberDetectors() !=
m_instrumentWidget->getInstrumentActor()->ndetectors();
// if workspace and instrument don't change keep the scaling
if (sameWS && !resetGeometry) {
m_instrumentWidget->getInstrumentActor()->updateColors();
} else {
m_instrumentWidget->resetInstrument(resetGeometry);
}
}
}
m_instrumentWidget->handleWorkspaceReplacement(wsName, workspace);
}
void InstrumentWindow::renameHandle(const std::string &oldName,
const std::string &newName) {
if (oldName == m_instrumentWidget->getWorkspaceName().toStdString()) {
m_instrumentWidget->renameWorkspace(QString::fromStdString(newName));
if (m_instrumentWidget->hasWorkspace(oldName)) {
m_instrumentWidget->renameWorkspace(newName);
setWindowTitle(QString("Instrument - ") +
m_instrumentWidget->getWorkspaceName());
}
......
......@@ -26,6 +26,7 @@ public:
const int fileVersion);
std::string saveToProject(ApplicationWindow *app);
InstrumentWidget *getInstrumentWidget() { return m_instrumentWidget; }
void selectTab(int tab);
private:
/// ADS notification handlers
......
......@@ -2043,31 +2043,27 @@ InstrumentWidget* MantidUI::getInstrumentView(const QString & wsName, int tab)
//Need a new window
const QString windowName(QString("InstrumentWindow:") + wsName);
InstrumentWindow *insWin = new InstrumentWindow(wsName, QString("Instrument"), appWindow(), windowName);
try
{
insWin->getInstrumentWidget()->init();
InstrumentWindow *insWin = new InstrumentWindow(
wsName, QString("Instrument"), appWindow(), windowName);
insWin->getInstrumentWidget()->selectTab(tab);
appWindow()->addMdiSubWindow(insWin);
QApplication::restoreOverrideCursor();
return insWin->getInstrumentWidget();
}
catch(const std::exception& e)
{
QApplication::restoreOverrideCursor();
QString errorMessage = "Instrument view cannot be created:\n\n" + QString(e.what());
QMessageBox::critical(appWindow(),"MantidPlot - Error",errorMessage);
if (insWin)
{
appWindow()->closeWindow(insWin);
insWin->close();
}
return NULL;
}
insWin->getInstrumentWidget()->selectTab(tab);
appWindow()->addMdiSubWindow(insWin);
QApplication::restoreOverrideCursor();
return insWin->getInstrumentWidget();
}
MdiSubWindow *MantidUI::getInstrumentWindow(const QString & wsName, int tab)
......
#ifndef INSTRUMENTWIDGET_H_
#define INSTRUMENTWIDGET_H_
#include "WidgetDllOption.h"
#include "MantidGLWidget.h"
#include "InstrumentWidgetTypes.h"
#include "MantidGLWidget.h"
#include "WidgetDllOption.h"
#include "MantidAPI/AlgorithmObserver.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/Workspace.h"
#include "MantidQtAPI/GraphOptions.h"
#include "MantidQtAPI/WorkspaceObserver.h"
#include "MantidAPI/AlgorithmObserver.h"
#include <boost/shared_ptr.hpp>
class InstrumentActor;
class OneCurvePlot;
......@@ -34,6 +37,8 @@ class QDropEvent;
class QStackedLayout;
class QSettings;
using namespace Mantid::API;
/**
\class InstrumentWidget
\brief This is the main window for the control of display on geometry
......@@ -41,133 +46,167 @@ class QSettings;
\date September 2008
\version 1.0
This is a QT widget for the controls and display of instrument geometry.
The user documentation can be found at http://www.mantidproject.org/MantidPlot:_Instrument_View
This is a QT widget for the controls and display of instrument geometry.
The user documentation can be found at
http://www.mantidproject.org/MantidPlot:_Instrument_View
and needs to be updated whenever the instrument view functionality changes.
*/
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentWidget : public QWidget, public MantidQt::API::WorkspaceObserver, public Mantid::API::AlgorithmObserver, public InstrumentWidgetTypes
{
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS InstrumentWidget
: public QWidget,
public MantidQt::API::WorkspaceObserver,
public Mantid::API::AlgorithmObserver,
public InstrumentWidgetTypes {
Q_OBJECT
public:
enum SurfaceType{ FULL3D = 0, CYLINDRICAL_X, CYLINDRICAL_Y, CYLINDRICAL_Z, SPHERICAL_X, SPHERICAL_Y, SPHERICAL_Z, SIDE_BY_SIDE, RENDERMODE_SIZE };
enum Tab{RENDER = 0, PICK, MASK, TREE};
enum SurfaceType {
FULL3D = 0,
CYLINDRICAL_X,
CYLINDRICAL_Y,
CYLINDRICAL_Z,
SPHERICAL_X,
SPHERICAL_Y,
SPHERICAL_Z,
SIDE_BY_SIDE,
RENDERMODE_SIZE
};
enum Tab { RENDER = 0, PICK, MASK, TREE };
explicit InstrumentWidget(const QString& wsName, QWidget *parent=nullptr);
explicit InstrumentWidget(const QString &wsName, QWidget *parent = nullptr,
bool resetGeometry = true, bool autoscaling = true,
double scaleMin = 0.0, double scaleMax = 0.0,
bool setDefaultView = true);
~InstrumentWidget();
void init(bool resetGeometry = true, bool autoscaling = true, double scaleMin = 0.0, double scaleMax = 0.0, bool setDefaultView = true);
QString getWorkspaceName() const { return m_workspaceName; }
void renameWorkspace(const QString & workspace) { m_workspaceName = workspace; }
std::string getWorkspaceNameStdString() const {
return m_workspaceName.toStdString();
}
void renameWorkspace(const std::string &workspace) {
m_workspaceName = QString::fromStdString(workspace);
}
SurfaceType getSurfaceType()const{return m_surfaceType;}
SurfaceType getSurfaceType() const { return m_surfaceType; }
/// Get pointer to the projection surface
boost::shared_ptr<ProjectionSurface> getSurface() const;
/// True if the GL instrument display is currently on
bool isGLEnabled() const;
/// Toggle between the GL and simple instrument display widgets
void enableOpenGL( bool on );
void enableOpenGL(bool on);
/// Redraw the instrument view
void updateInstrumentView(bool picking = true);
/// Recalculate the detector data and redraw the instrument view
void updateInstrumentDetectors();
/// Delete the peaks workspace.
void deletePeaksWorkspace(Mantid::API::IPeaksWorkspace_sptr pws);
/// Alter data from a script. These just foward calls to the 3D widget
void setColorMapMinValue(double minValue);
void setColorMapMaxValue(double maxValue);
void setColorMapRange(double minValue, double maxValue);
void selectComponent(const QString & name);
void selectComponent(const QString &name);
void setScaleType(GraphOptions::ScaleType type);
void setExponent(double nth_power);
void setViewType(const QString& type);
InstrumentActor* getInstrumentActor() const {return m_instrumentActor;}
void setViewType(const QString &type);
InstrumentActor *getInstrumentActor() const { return m_instrumentActor; }
void resetInstrument(bool resetGeometry);
void selectTab(int tab);
void selectTab(Tab tab){selectTab(int(tab));}
InstrumentWidgetTab *getTab(const QString & title="") const;
void selectTab(Tab tab) { selectTab(int(tab)); }
InstrumentWidgetTab *getTab(const QString &title = "") const;
InstrumentWidgetTab *getTab(const Tab tab) const;
/// Get a filename for saving
QString getSaveFileName(const QString& title, const QString& filters, QString* selectedFilter = NULL);
QString getSaveFileName(const QString &title, const QString &filters,
QString *selectedFilter = NULL);
/// Get a name for settings group
QString getSettingsGroupName() const;
/// Get a name for a instrument-specific settings group
QString getInstrumentSettingsGroupName() const;
bool hasWorkspace(const std::string &wsName) {
return wsName == getWorkspaceNameStdString();
}
void handleWorkspaceReplacement(const std::string &wsName,
const boost::shared_ptr<Workspace> workspace);
signals:
void enableLighting(bool);
void plot1D(const QString&,const std::set<int>&,bool);
void createDetectorTable(const QString&,const std::vector<int>&,bool);
void needSetIntegrationRange(double,double);
void plot1D(const QString &, const std::set<int> &, bool);
void createDetectorTable(const QString &, const std::vector<int> &, bool);
void needSetIntegrationRange(double, double);
void surfaceTypeChanged(int);
void colorMapChanged();
void colorMapMinValueChanged(double);
void colorMapMaxValueChanged(double);
void colorMapRangeChanged(double,double);
void colorMapRangeChanged(double, double);
void scaleTypeChanged(int);
void nthPowerChanged(double);
void integrationRangeChanged(double,double);
void integrationRangeChanged(double, double);
void glOptionChanged(bool);
void requestSelectComponent(const QString&);
void requestSelectComponent(const QString &);
protected:
/// Implements AlgorithmObserver's finish handler
void finishHandle(const Mantid::API::IAlgorithm* alg);
void dragEnterEvent( QDragEnterEvent* e );
void dropEvent( QDropEvent* e );
void finishHandle(const Mantid::API::IAlgorithm *alg);
void dragEnterEvent(QDragEnterEvent *e);
void dropEvent(QDropEvent *e);
bool eventFilter(QObject *obj, QEvent *ev);
public slots:
void tabChanged(int);
void componentSelected(Mantid::Geometry::ComponentID id);
void executeAlgorithm(const QString&, const QString&);
void executeAlgorithm(const QString &, const QString &);
void executeAlgorithm(Mantid::API::IAlgorithm_sptr);
void setupColorMap();
void changeColormap(const QString & filename = ""); // Deprecated
void changeScaleType(int);// Deprecated
void changeColormap(const QString &filename = ""); // Deprecated
void changeScaleType(int); // Deprecated
void changeNthPower(double);
void changeColorMapMinValue(double minValue); // Deprecated
void changeColorMapMaxValue(double maxValue); // Deprecated
void changeColorMapMinValue(double minValue); // Deprecated
void changeColorMapMaxValue(double maxValue); // Deprecated
void changeColorMapRange(double minValue, double maxValue); // Deprecated
void setIntegrationRange(double,double);
void setBinRange(double,double);
void setIntegrationRange(double, double);
void setBinRange(double, double);
void setColorMapAutoscaling(bool); // Deprecated
void setViewDirection(const QString&);
void setViewDirection(const QString &);
void pickBackgroundColor();
void saveImage(QString filename);
void setInfoText(const QString&);
void setInfoText(const QString &);
void set3DAxesState(bool);
void setSurfaceType(int);
void setWireframe(bool);
/// Overlay a workspace with the given name
bool overlay(const QString & wsName);
bool overlay(const QString &wsName);
void clearPeakOverlays();
void setPeakLabelPrecision(int n);
void setShowPeakRowFlag(bool on);
void setShowPeakLabelsFlag(bool on);
void setShowPeakRelativeIntensity(bool on);
/// Enable OpenGL. Slot called from render tab only - doesn't update the checkbox.
void enableGL( bool on );
/// Enable OpenGL. Slot called from render tab only - doesn't update the
/// checkbox.
void enableGL(bool on);
void updateInfoText();
private slots:
void helpClicked();
protected:
void init(bool resetGeometry, bool autoscaling, double scaleMin,
double scaleMax, bool setDefaultView);
/// Set newly created projection surface
void setSurface(ProjectionSurface* surface);
QWidget * createInstrumentTreeTab(QTabWidget* ControlsTab);
void createTabs(QSettings& settings);
void setSurface(ProjectionSurface *surface);
QWidget *createInstrumentTreeTab(QTabWidget *ControlsTab);
void createTabs(QSettings &settings);
void saveSettings();
QString asString(const std::vector<int>& numbers) const;
QString confirmDetectorOperation(const QString & opName, const QString & inputWS, int ndets);
QString asString(const std::vector<int> &numbers) const;
QString confirmDetectorOperation(const QString &opName,
const QString &inputWS, int ndets);
/// Set background color of the instrument display
void setBackgroundColor(const QColor& color);
void setBackgroundColor(const QColor &color);
/// Get the surface info string
QString getSurfaceInfoText() const;
/// Return the width of the instrunemt display
......@@ -177,54 +216,56 @@ protected:
/// Select the OpenGL or simple widget for instrument display
void selectOpenGLDisplay(bool yes);
/// Set the surface type.
void setSurfaceType(const QString& typeStr);
void setSurfaceType(const QString &typeStr);
/// Return a filename to save a grouping to
QString getSaveGroupingFilename();
// GUI elements
QLabel* mInteractionInfo;
QTabWidget* mControlsTab;
QLabel *mInteractionInfo;
QTabWidget *mControlsTab;
/// Control tabs
QList<InstrumentWidgetTab *> m_tabs;
InstrumentWidgetRenderTab *m_renderTab;
XIntegrationControl * m_xIntegration;
XIntegrationControl *m_xIntegration;
/// The OpenGL widget to display the instrument
MantidGLWidget* m_InstrumentDisplay;
MantidGLWidget *m_InstrumentDisplay;
/// The simple widget to display the instrument
SimpleWidget* m_simpleDisplay;
SimpleWidget *m_simpleDisplay;
// Context menu actions
QAction *m_clearPeakOverlays;
/// The name of workspace that this window is associated with. The InstrumentActor holds a pointer to the workspace itself.
/// The name of workspace that this window is associated with. The
/// InstrumentActor holds a pointer to the workspace itself.
QString m_workspaceName;
/// Instrument actor is an interface to the instrument
InstrumentActor* m_instrumentActor;
/// Option to use or not OpenGL display for "unwrapped" view, 3D is always in OpenGL
InstrumentActor *m_instrumentActor;
/// Option to use or not OpenGL display for "unwrapped" view, 3D is always in
/// OpenGL
bool m_useOpenGL;
/// 3D view or unwrapped
SurfaceType m_surfaceType;
SurfaceType m_surfaceType;
/// Stacked layout managing m_InstrumentDisplay and m_simpleDisplay
QStackedLayout* m_instrumentDisplayLayout;
QStackedLayout *m_instrumentDisplayLayout;
/// spectra index id
int mSpectraIDSelected;
int mSpectraIDSelected;
/// detector id
int mDetectorIDSelected;
int mDetectorIDSelected;
std::set<int> mSpectraIDSelectedList;
std::vector<int> mDetectorIDSelectedList;
/// The full path of the default color map
QString mDefaultColorMap;
QString mDefaultColorMap;
/// The last used dialog directory
QString m_savedialog_dir;
QString m_savedialog_dir;
/// stores whether the user changed the view (so don't automatically change it)
/// stores whether the user changed the view (so don't automatically change
/// it)
bool mViewChanged;
/// Set to true to block access to instrument during algorithm executions
bool m_blocked;
bool m_blocked;
QList<int> m_selectedDetectors;
bool m_instrumentDisplayContextMenuOn;
};
#endif /*INSTRUMENTWIDGET_H_*/
......@@ -5,6 +5,8 @@
#include "InstrumentWidgetPickTab.h"
#include "InstrumentWidgetRenderTab.h"
#include "InstrumentWidgetTreeTab.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/Workspace.h"
#include "PanelsSurface.h"
#include "Projection3D.h"
#include "SimpleWidget.h"
......@@ -12,8 +14,6 @@
#include "UnwrappedSphere.h"
#include "XIntegrationControl.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include <Poco/ActiveResult.h>
#include <QApplication>
......@@ -74,7 +74,10 @@ public:
/**
* Constructor.
*/
InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent)
InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent,
bool resetGeometry, bool autoscaling,
double scaleMin, double scaleMax,
bool setDefaultView)
: QWidget(parent), WorkspaceObserver(), m_InstrumentDisplay(nullptr),
m_simpleDisplay(nullptr), m_workspaceName(wsName),
m_instrumentActor(nullptr), m_surfaceType(FULL3D),
......@@ -173,6 +176,8 @@ InstrumentWidget::InstrumentWidget(const QString &wsName, QWidget *parent)
setAcceptDrops(true);
setWindowTitle(QString("Instrument - ") + m_workspaceName);
init(resetGeometry, autoscaling, scaleMin, scaleMax, setDefaultView);
}
/**
......@@ -1094,6 +1099,12 @@ void InstrumentWidget::updateInstrumentDetectors() {
QApplication::restoreOverrideCursor();
}
void InstrumentWidget::deletePeaksWorkspace(
Mantid::API::IPeaksWorkspace_sptr pws) {
this->getSurface()->deletePeaksWorkspace(pws);
updateInstrumentView();
}
/**
* Choose which widget to use.
* @param yes :: True to use the OpenGL one or false to use the Simple
......@@ -1179,3 +1190,34 @@ QString InstrumentWidget::getInstrumentSettingsGroupName() const {
QString::fromStdString(
getInstrumentActor()->getInstrument()->getName());
}
void InstrumentWidget::handleWorkspaceReplacement(
const std::string &wsName, const boost::shared_ptr<Workspace> workspace) {
// Replace current workspace
if (hasWorkspace(wsName)) {
if (m_instrumentActor) {
// Check if it's still the same workspace underneath (as well as having
// the same name)
auto matrixWS =
boost::dynamic_pointer_cast<const MatrixWorkspace>(workspace);
bool sameWS = false;
try {
sameWS = (matrixWS == m_instrumentActor->getWorkspace());
} catch (std::runtime_error &) {
// Carry on, sameWS should stay false
}
// try to detect if the instrument changes (unlikely if the workspace
// hasn't, but theoretically possible)
bool resetGeometry = matrixWS->getInstrument()->getNumberDetectors() !=
m_instrumentActor->ndetectors();
// if workspace and instrument don't change keep the scaling
if (sameWS && !resetGeometry) {
m_instrumentActor->updateColors();
} else {
resetInstrument(resetGeometry);
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment