diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp index 18280a90c58d..24ef57e91856 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.cpp @@ -55,6 +55,9 @@ using namespace Mantid::API; using namespace Mantid::Geometry; using namespace MantidQt::API; +// Name of the QSettings group to store the InstrumentWindw settings +const char* InstrumentWindowSettingsGroup = "Mantid/InstrumentWindow"; + /** * Constructor. */ @@ -1344,3 +1347,20 @@ void InstrumentWindow::createTabs(QSettings& settings) m_tabs << m_renderTab << pickTab << maskTab << treeTab; } + +/** + * Return a name for a group in QSettings to store InstrumentWindow configuration. + */ +QString InstrumentWindow::getSettingsGroupName() const +{ + return QString::fromAscii( InstrumentWindowSettingsGroup ); +} + +/** + * Construct a name for a group in QSettings to store instrument-specific configuration. + */ +QString InstrumentWindow::getInstrumentSettingsGroupName() const +{ + return QString::fromAscii( InstrumentWindowSettingsGroup ) + "/" + + QString::fromStdString( getInstrumentActor()->getInstrument()->getName() ); +} diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h index 87f8a823af98..a88d305b0031 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindow.h @@ -91,7 +91,7 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs void setViewType(const QString& type); /// for saving the instrument window to mantid project QString saveToString(const QString& geometry, bool saveAsTemplate= false); - InstrumentActor* getInstrumentActor(){return m_instrumentActor;} + InstrumentActor* getInstrumentActor() const {return m_instrumentActor;} bool blocked()const{return m_blocked;} void selectTab(int tab); void selectTab(Tab tab){selectTab(int(tab));} @@ -99,6 +99,10 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs InstrumentWindowTab *getTab(const Tab tab) const; /// Get a filename for saving 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; signals: void enableLighting(bool); diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.cpp index 2b6fbb146fa5..a170fd875bcd 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.cpp @@ -2,6 +2,7 @@ #include "ProjectionSurface.h" #include "UnwrappedSurface.h" #include "Projection3D.h" +#include "RotationSurface.h" #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include #include @@ -27,6 +29,8 @@ #include "BinDialog.h" #include "ColorMapWidget.h" +#include + InstrumentWindowRenderTab::InstrumentWindowRenderTab(InstrumentWindow* instrWindow): InstrumentWindowTab(instrWindow) @@ -128,6 +132,8 @@ InstrumentWindowTab(instrWindow) m_wireframe->setCheckable(true); m_wireframe->setChecked(false); connect(m_wireframe, SIGNAL(toggled(bool)), m_instrWindow, SLOT(setWireframe(bool))); + m_UCorrection = new QAction("U Correction",this); + connect(m_UCorrection, SIGNAL(triggered()),this,SLOT(setUCorrection())); // Create "Use OpenGL" action m_GLView = new QAction("Use OpenGL",this); @@ -147,6 +153,8 @@ InstrumentWindowTab(instrWindow) displaySettingsMenu->addAction(m_wireframe); displaySettingsMenu->addAction(m_lighting); displaySettingsMenu->addAction(m_GLView); + displaySettingsMenu->addAction(m_UCorrection); + displaySettings->setMenu(displaySettingsMenu); connect(displaySettingsMenu,SIGNAL(hovered(QAction*)),this,SLOT(showMenuToolTip(QAction*))); @@ -251,20 +259,47 @@ void InstrumentWindowRenderTab::enable3DSurface(bool on) } } +/** + * Surface-specific adjustments. + */ void InstrumentWindowRenderTab::initSurface() { setAxis(QString::fromStdString(m_instrWindow->getInstrumentActor()->getInstrument()->getDefaultAxis())); auto surface = getSurface(); + + // 3D axes switch needs to be shown for the 3D surface auto p3d = boost::dynamic_pointer_cast(surface); if ( p3d ) { p3d->set3DAxesState(areAxesOn()); } + bool detectorsOnly = !m_instrWindow->getInstrumentActor()->areGuidesShown(); m_displayDetectorsOnly->blockSignals(true); m_displayDetectorsOnly->setChecked(detectorsOnly); m_displayDetectorsOnly->blockSignals(false); setPrecisionMenuItemChecked(surface->getPeakLabelPrecision()); + + // enable u-correction for surfaces of rotation. correction applied in the last + // session is loaded and re-applied in the new session + auto rotSurface = boost::dynamic_pointer_cast(surface); + if ( rotSurface ) + { + m_UCorrection->setEnabled(true); + QString groupName = m_instrWindow->getInstrumentSettingsGroupName(); + QSettings settings; + settings.beginGroup( groupName ); + bool isManualUCorrection = settings.value("ManualUCorrection",false).asBool(); + if ( isManualUCorrection ) + { + double ucorr = settings.value("UCorrection",0.0).asDouble(); + rotSurface->setUCorrection( ucorr ); + } + } + else + { + m_UCorrection->setEnabled(false); + } } /** @@ -491,7 +526,7 @@ void InstrumentWindowRenderTab::setColorMapAutoscaling(bool on) QMenu* InstrumentWindowRenderTab::createPeaksMenu() { QSettings settings; - settings.beginGroup("Mantid/InstrumentWindow"); + settings.beginGroup( m_instrWindow->getSettingsGroupName() ); QMenu* menu = new QMenu(this); // show/hide peak hkl labels @@ -631,3 +666,46 @@ void InstrumentWindowRenderTab::showMenuToolTip(QAction *action) QToolTip::showText(QCursor::pos(),action->toolTip(),this); } +/** + * Set the offset in u-coordinate of a 2d (unwrapped) surface + * @param ucorr :: New value for the correction. + */ +void InstrumentWindowRenderTab::setUCorrection() +{ + auto surface = getSurface(); + auto rotSurface = boost::dynamic_pointer_cast(surface); + if ( rotSurface ) + { + bool ok; + double oldUCorr = rotSurface->getUCorrection(); + // ask the user to enter a number for the u-correction + double ucorr = QInputDialog::getDouble(this, "MantiPplot - Input", + "U Correction", oldUCorr, -std::numeric_limits::max(),std::numeric_limits::max(), 4, &ok); + // update the surface only if the correction changes + if (ok && ucorr != oldUCorr) + { + rotSurface->setUCorrection( ucorr ); // manually set the correction + rotSurface->requestRedraw(); // redraw the view + QSettings settings; + settings.beginGroup( m_instrWindow->getInstrumentSettingsGroupName() ); + settings.setValue("ManualUCorrection",true); + settings.setValue("UCorrection",ucorr); + } + } +} + +/** + * Get current value for the u-correction for a RotationSurface. + * Return 0 if it's not a RotationSurface. + */ +double InstrumentWindowRenderTab::getUCorrection() const +{ + auto surface = getSurface(); + auto rotSurface = boost::dynamic_pointer_cast(surface); + if ( rotSurface ) + { + return rotSurface->getUCorrection(); + } + return 0.0; +} + diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.h index 86a915619f10..ca8abe4a3b07 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowRenderTab.h @@ -16,6 +16,7 @@ class QCheckBox; class QAction; class QActionGroup; class QMenu; +class QLineEdit; /** * Implements the Render tab in InstrumentWindow. @@ -66,6 +67,7 @@ private slots: void scaleTypeChanged(int); void glOptionChanged(bool); void showMenuToolTip(QAction*); + void setUCorrection(); private: void showEvent (QShowEvent *); @@ -73,6 +75,7 @@ private slots: QFrame * setupAxisFrame(); void setPrecisionMenuItemChecked(int n); void enable3DSurface( bool on ); + double getUCorrection() const; QPushButton *m_surfaceTypeButton; QPushButton *mSaveImage; @@ -100,6 +103,7 @@ private slots: QAction *m_wireframe; QAction *m_lighting; QAction *m_GLView; ///< toggle between OpenGL and simple view + QAction *m_UCorrection; QActionGroup *m_precisionActionGroup; QList m_precisionActions; diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.cpp index de03e72b60e9..a4e5d0b918b0 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.cpp @@ -10,7 +10,8 @@ RotationSurface::RotationSurface(const InstrumentActor* rootActor,const Mantid:: UnwrappedSurface(rootActor), m_pos(origin), m_zaxis(axis), - m_u_correction(0) + m_u_correction(0), + m_manual_u_correction(false) { } @@ -22,7 +23,10 @@ void RotationSurface::init() // the actor calls this->callback for each detector m_unwrappedDetectors.clear(); m_assemblies.clear(); - m_u_correction = 0.0; + if ( !m_manual_u_correction ) + { + m_u_correction = 0.0; + } size_t ndet = m_instrActor->ndetectors(); m_unwrappedDetectors.resize(ndet); @@ -67,10 +71,13 @@ void RotationSurface::init() m_yaxis = m_zaxis.cross_prod(m_xaxis); } - // give some valid values to u bounds in case some code checks - // on u to be within them - m_u_min = -DBL_MAX; - m_u_max = DBL_MAX; + if ( !m_manual_u_correction ) + { + // give some valid values to u bounds in case some code checks + // on u to be within them + m_u_min = -DBL_MAX; + m_u_max = DBL_MAX; + } // For each detector in the order of actors // cppcheck-suppress syntaxError @@ -130,7 +137,10 @@ void RotationSurface::init() if (udet.v > m_v_max) m_v_max = udet.v; } - findAndCorrectUGap(); + if ( !m_manual_u_correction ) + { + findAndCorrectUGap(); + } double dU = fabs(m_u_max - m_u_min); double dV = fabs(m_v_max - m_v_min); @@ -156,7 +166,8 @@ void RotationSurface::init() m_u_max += du; m_v_min -= dv; m_v_max += dv; - m_viewRect = RectF( QPointF(m_u_min,m_v_min), QPointF(m_u_max,m_v_max) ); + + m_viewRect = RectF( QPointF(m_u_min,m_v_min), QPointF(m_u_max,m_v_max) ); } @@ -249,12 +260,24 @@ double RotationSurface::applyUCorrection(double u)const u += m_u_correction; if (u < m_u_min) { - u += period; + double periods = floor( (m_u_max - u) / period ) * period; + u += periods; } if (u > m_u_max) { - u -= period; + double periods = floor( (u - m_u_min) / period ) * period; + u -= periods; } return u; } +/** + * Set new value for the u-correction. + * Correct all uv corrdinates of detectors. + */ +void RotationSurface::setUCorrection(double ucorr) +{ + m_u_correction = ucorr; + m_manual_u_correction = true; + this->updateDetectors(); +} diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.h index b77748be4b32..2ab6ef2b31e6 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/RotationSurface.h @@ -12,6 +12,10 @@ class RotationSurface: public UnwrappedSurface public: RotationSurface(const InstrumentActor* rootActor,const Mantid::Kernel::V3D& origin,const Mantid::Kernel::V3D& axis); void init(); + // Get the value of the u-correction - a shift in the u-coord added to automatically determined uv coordinates + double getUCorrection() const {return m_u_correction;} + // Set new value for the u-correction + void setUCorrection(double ucorr); protected: @@ -32,7 +36,7 @@ class RotationSurface: public UnwrappedSurface Mantid::Kernel::V3D m_xaxis; ///< The x axis Mantid::Kernel::V3D m_yaxis; ///< The y axis double m_u_correction; ///< Correction to u calculated by project() after findAndCorrectUGap() - + bool m_manual_u_correction; ///< Flag set to prevent automatic FindAndCorrectUGap() }; #endif // ROTATIONSURFACE_H