Skip to content

Commit

Permalink
Re #6161. Added property MantidOptions.InstrumentView.UseOpenGL
Browse files Browse the repository at this point in the history
If set to On the "unwrapped" instrument view will draw on to a OpenGL widget in MantidPlot. "Off" disables OpenGL. This option does not affect the 3D view.
(cherry picked from commit 451d339)
  • Loading branch information
mantid-roman authored and Michael Reuter committed Dec 10, 2012
1 parent e609a29 commit ba5602f
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 34 deletions.
5 changes: 4 additions & 1 deletion Code/Mantid/Framework/Properties/Mantid.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ curvefitting.findPeaksTolerance=4
# Do not show 'invisible' workspaces
MantidOptions.InvisibleWorkspaces=0

# This flag controls the way the "unwrapped" instrument view is rendered.
# Change to Off to disable OpenGL and use normal windows graphics.
MantidOptions.InstrumentView.UseOpenGL = On

#Uncommenting the line below will enable algorithm chain re-running whenever a
#workspace is replaced. Uncommenting and setting it to 0 will also turn it off
#enabling this is currently discouraged as it could cause race conditions with python scripts
Expand Down Expand Up @@ -193,4 +197,3 @@ loading.multifile=On
# set to a very high number to disbale
# however this limit is in place to protect you and your computer from simple formatting mistakes
loading.multifilelimit=100

21 changes: 21 additions & 0 deletions Code/Mantid/MantidPlot/src/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@ void ConfigDialog::initMantidOptionsTab()
if( apiVersion == 2 ) m_defaultToNewPython->setChecked(true);
else m_defaultToNewPython->setChecked(false);
grid->addWidget(m_defaultToNewPython, 2,0);

// create a checkbox for the instrument view OpenGL option
m_useOpenGL = new QCheckBox("Use OpenGL in Instrument View");
m_useOpenGL->setChecked(true);
grid->addWidget(m_useOpenGL,3,0);

setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().
getString("MantidOptions.InstrumentView.UseOpenGL")).toUpper();
if( setting == "ON")
{
m_useOpenGL->setChecked(true);
}
else
{
m_useOpenGL->setChecked(false);
}

}


Expand Down Expand Up @@ -2233,6 +2250,10 @@ void ConfigDialog::updateMantidOptionsTab()
}
mantid_config.setString("MantidOptions.InvisibleWorkspaces",showinvisible_ws.toStdString());

//OpenGL option
QString setting = m_useOpenGL->isChecked() ? "On" : "Off";
mantid_config.setString("MantidOptions.InstrumentView.UseOpenGL",setting.toStdString());

//Hidden categories
QString hiddenCategories = buildHiddenCategoryString().join(";");

Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/MantidPlot/src/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class ConfigDialog : public QDialog
QWidget* mantidOptionsPage;
QWidget* mantidSendToPage;
QCheckBox *m_invisibleWorkspaces;
QCheckBox *m_useOpenGL;
QCheckBox *m_sendToPrograms;
QTreeWidget *treeCategories;
QTreeWidget *treePrograms;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,15 @@ void InstrumentWindow::setSurfaceType(int type)
showPeakRow = settings.value("Mantid/InstrumentWindow/ShowPeakRows",true).toBool();
}

// which display to use?
bool useOpenGL = isGLEnabled();
if (m_surfaceType == FULL3D)
{
Projection3D* p3d = new Projection3D(m_instrumentActor,getInstrumentDisplayWidth(),getInstrumentDisplayHeight());
p3d->set3DAxesState(m_renderTab->areAxesOn());
surface = p3d;
// always OpenGL in 3D
useOpenGL = true;
}
else if (m_surfaceType <= CYLINDRICAL_Z)
{
Expand All @@ -414,7 +418,10 @@ void InstrumentWindow::setSurfaceType(int type)
}
surface->setPeakLabelPrecision(peakLabelPrecision);
surface->setShowPeakRowFlag(showPeakRow);
// set new surface
setSurface(surface);
// make sure to switch to the right instrument display
selectOpenGLDisplay( useOpenGL );
m_renderTab->init();
m_pickTab->init();
m_maskTab->init();
Expand Down Expand Up @@ -1471,22 +1478,47 @@ void InstrumentWindow::updateInstrumentDetectors()
}
}

/// Toggle between the GL and simple instrument display widgets
/**
* Choose which widget to use.
* @param yes :: True to use the OpenGL one or false to use the Simple
*/
void InstrumentWindow::selectOpenGLDisplay(bool yes)
{
int widgetIndex = yes ? 0 : 1;
const int oldIndex = m_instrumentDisplayLayout->currentIndex();
if ( oldIndex == widgetIndex ) return;
m_instrumentDisplayLayout->setCurrentIndex( widgetIndex );
ProjectionSurface* surface = getSurface();
if ( surface )
{
surface->updateView();
}
}

/// Public slot to toggle between the GL and simple instrument display widgets
void InstrumentWindow::enableOpenGL( bool on )
{
m_renderTab->m_GLView->setChecked( on );
}

/// Private slot to toggle between the GL and simple instrument display widgets
void InstrumentWindow::enableGL( bool on )
{
if ( on )
m_useOpenGL = on;
if ( m_surfaceType == FULL3D )
{
m_instrumentDisplayLayout->setCurrentIndex( 0 );
// always OpenGL in 3D
selectOpenGLDisplay( true );
}
else
{
m_instrumentDisplayLayout->setCurrentIndex( 1 );
// select the display
selectOpenGLDisplay( on );
}
getSurface()->updateView();
}

/// True if the GL instrument display is currently on
bool InstrumentWindow::isGLEnabled() const
{
return m_instrumentDisplayLayout->currentIndex() == 0;
return m_useOpenGL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class InstrumentWindow : public MdiSubWindow, public MantidQt::API::WorkspaceObs
void setSurface(ProjectionSurface* surface);
/// 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 );
/// Redraw the instrument view
void updateInstrumentView();
/// Recalculate the detector data and redraw the instrument view
Expand Down Expand Up @@ -159,7 +161,7 @@ public slots:
void clearPeakOverlays();
void setPeakLabelPrecision(int n);
void setShowPeakRowFlag(bool on);
/// Toggle between the GL and simple instrument display widgets
/// Enable OpenGL. Slot called from render tab only - doesn't update the checkbox.
void enableGL( bool on );

signals:
Expand Down Expand Up @@ -196,42 +198,59 @@ private slots:
QTabWidget* mControlsTab;
// Actions for the pick menu
QAction *mInfoAction, *mPlotAction, *mDetTableAction, *mGroupDetsAction, *mMaskDetsAction;
QAction *m_ExtractDetsToWorkspaceAction; ///< Extract selected detector ids to a new workspace
QAction *m_SumDetsToWorkspaceAction; ///< Sum selected detectors to a new workspace
QAction *m_createIncludeGroupingFileAction; ///< Create grouping xml file which includes selected detectors
QAction *m_createExcludeGroupingFileAction; ///< Create grouping xml file which excludes selected detectors
/// Extract selected detector ids to a new workspace
QAction *m_ExtractDetsToWorkspaceAction;
/// Sum selected detectors to a new workspace
QAction *m_SumDetsToWorkspaceAction;
/// Create grouping xml file which includes selected detectors
QAction *m_createIncludeGroupingFileAction;
/// Create grouping xml file which excludes selected detectors
QAction *m_createExcludeGroupingFileAction;
// 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.
const QString m_workspaceName;
/// The OpenGL widget to display the instrument
MantidGLWidget* m_InstrumentDisplay;
/// The simple widget to display the instrument
SimpleWidget* m_simpleDisplay;
/// Option to use or not OpenGL display for "unwrapped" view, 3D is always in OpenGL
bool m_useOpenGL;
/// Instrument actor
InstrumentActor* m_instrumentActor;
SurfaceType m_surfaceType; ///< 3D view or unwrapped
/// 3D view or unwrapped
SurfaceType m_surfaceType;
/// Stacked layout managing m_InstrumentDisplay and m_simpleDisplay
QStackedLayout* m_instrumentDisplayLayout;

int mSpectraIDSelected; ///< spectra index id
int mDetectorIDSelected; ///< detector id
/// spectra index id
int mSpectraIDSelected;
/// detector id
int mDetectorIDSelected;
std::set<int> mSpectraIDSelectedList;
std::vector<int> mDetectorIDSelectedList;
InstrumentTreeWidget* mInstrumentTree; ///< Widget to display instrument tree
/// Widget to display instrument tree
InstrumentTreeWidget* mInstrumentTree;

QString mDefaultColorMap; ///< The full path of the default color map
QString m_savedialog_dir; /// The last used dialog directory
/// The full path of the default color map
QString mDefaultColorMap;
/// The last used dialog directory
QString m_savedialog_dir;

InstrumentWindowRenderTab * m_renderTab;
InstrumentWindowPickTab * m_pickTab;
InstrumentWindowMaskTab * m_maskTab;
XIntegrationControl * m_xIntegration;

bool mViewChanged; ///< stores whether the user changed the view (so don't automatically change it)

bool m_blocked; ///< Set to true to block access to instrument during algorithm executions
/// 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;
QList<int> m_selectedDetectors;
bool m_instrumentDisplayContextMenuOn;

private:
/// ADS notification handlers
virtual void preDeleteHandle(const std::string & ws_name, const boost::shared_ptr<Mantid::API::Workspace> workspace_ptr);
virtual void afterReplaceHandle(const std::string& wsName,const boost::shared_ptr<Mantid::API::Workspace> workspace_ptr);
virtual void clearADSHandle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ QFrame(instrWindow),m_instrWindow(instrWindow)
m_wireframe->setCheckable(true);
m_wireframe->setChecked(false);
connect(m_wireframe, SIGNAL(toggled(bool)), m_instrWindow, SLOT(setWireframe(bool)));

// Create "Use OpenGL" action
m_GLView = new QAction("Use OpenGL",this);
m_GLView->setCheckable(true);
m_GLView->setChecked( m_instrWindow->isGLEnabled() );
QString setting = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().
getString("MantidOptions.InstrumentView.UseOpenGL")).toUpper();
bool useOpenGL = setting == "ON";
m_instrWindow->enableGL( useOpenGL );
m_GLView->setChecked( useOpenGL );
connect(m_GLView, SIGNAL( toggled(bool) ), m_instrWindow, SLOT( enableGL(bool) ));

displaySettingsMenu->addAction(m_colorMap);
displaySettingsMenu->addAction(m_backgroundColor);
displaySettingsMenu->addSeparator();
Expand Down Expand Up @@ -369,16 +376,6 @@ void InstrumentWindowRenderTab::displaySettingsAboutToshow()
*/
void InstrumentWindowRenderTab::setSurfaceType(int index)
{
// don't allow the simple viewer with 3D mode
if ( index == InstrumentWindow::FULL3D && !m_instrWindow->isGLEnabled() )
{
m_renderMode->blockSignals( true );
m_renderMode->setCurrentIndex( m_instrWindow->getSurfaceType() );
m_renderMode->blockSignals( false );
QMessageBox::warning(this,"MantidPlot - Warning","OpenGL must be enabled to view the instrument in 3D.\n"
"Check \"Use OpenGL\" in Display Settings.");
return;
}
m_instrWindow->setSurfaceType( index );
showResetView( index );
showFlipControl( index );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ private slots:
QAction *m_wireframe;
QAction *m_lighting;
QAction *m_GLView; ///< toggle between OpenGL and simple view

friend class InstrumentWindow;

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ void ProjectionSurface::clear()
m_zoomStack.clear();
}

/**
* Draw the surface on an OpenGL widget
* @param widget :: A widget to draw on.
*/
void ProjectionSurface::draw(MantidGLWidget *widget)const
{
if (getInteractionMode() == MoveMode)
Expand All @@ -106,14 +110,18 @@ void ProjectionSurface::draw(MantidGLWidget *widget)const
}
else
{
//std::cerr << "picking\n";
bool changed = m_viewChanged;
draw(widget,true);
m_viewChanged = changed;
draw(widget,false);
}
}

/**
* Draw the surface on an OpenGL widget.
* @param widget :: A widget to draw on.
* @param picking :: Picking / normal drawing switch.
*/
void ProjectionSurface::draw(MantidGLWidget *widget,bool picking)const
{
QImage **image = picking ? &m_pickImage : &m_viewImage;
Expand Down

0 comments on commit ba5602f

Please sign in to comment.