2013-11-02 01:48:30 +00:00
# include "scenewidget.hpp"
# include <QEvent>
# include <QResizeEvent>
2014-02-25 12:09:37 +00:00
# include <QTimer>
2014-07-14 09:19:59 +00:00
# include <QShortcut>
2015-03-19 22:27:14 +00:00
# include <QLayout>
2013-11-02 01:48:30 +00:00
2014-07-08 10:39:12 +00:00
# include "../widget/scenetoolmode.hpp"
2014-09-23 12:33:49 +00:00
# include "../../model/settings/usersettings.hpp"
2014-03-23 14:14:26 +00:00
2014-02-27 14:23:14 +00:00
# include "navigation.hpp"
2014-03-23 14:14:26 +00:00
# include "lighting.hpp"
2014-02-27 14:23:14 +00:00
2015-03-19 22:27:14 +00:00
# include <osgQt/GraphicsWindowQt>
# include <osg/GraphicsContext>
2014-10-13 04:57:01 +00:00
2015-03-19 23:39:24 +00:00
# include <osgViewer/ViewerEventHandlers>
2014-10-13 04:57:01 +00:00
2015-03-19 22:27:14 +00:00
namespace CSVRender
{
2013-11-02 01:48:30 +00:00
2015-03-19 22:27:14 +00:00
SceneWidget : : SceneWidget ( QWidget * parent , Qt : : WindowFlags f )
: QWidget ( parent , f )
2015-03-19 23:39:24 +00:00
, mRootNode ( 0 )
2015-03-19 22:27:14 +00:00
{
2013-11-02 01:48:30 +00:00
2015-03-19 22:27:14 +00:00
# if QT_VERSION >= 0x050000
// Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4
osgViewer : : ViewerBase : : ThreadingModel threadingModel = osgViewer : : ViewerBase : : SingleThreaded ;
2013-11-02 01:48:30 +00:00
# else
2015-03-19 22:27:14 +00:00
osgViewer : : ViewerBase : : ThreadingModel threadingModel = osgViewer : : ViewerBase : : CullDrawThreadPerContext ;
2013-11-02 01:48:30 +00:00
# endif
2015-03-19 22:27:14 +00:00
setThreadingModel ( threadingModel ) ;
2014-02-27 14:23:14 +00:00
2015-03-19 22:27:14 +00:00
// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone ( 0 ) ;
2014-02-27 14:23:14 +00:00
2015-03-19 22:27:14 +00:00
osg : : DisplaySettings * ds = osg : : DisplaySettings : : instance ( ) . get ( ) ;
2015-03-19 23:39:24 +00:00
//ds->setNumMultiSamples(8);
2015-03-19 22:27:14 +00:00
osg : : ref_ptr < osg : : GraphicsContext : : Traits > traits = new osg : : GraphicsContext : : Traits ;
traits - > windowName = " " ;
traits - > windowDecoration = true ;
traits - > x = 0 ;
traits - > y = 0 ;
traits - > width = width ( ) ;
traits - > height = height ( ) ;
traits - > doubleBuffer = true ;
traits - > alpha = ds - > getMinimumNumAlphaBits ( ) ;
traits - > stencil = ds - > getMinimumNumStencilBits ( ) ;
traits - > sampleBuffers = ds - > getMultiSamples ( ) ;
traits - > samples = ds - > getNumMultiSamples ( ) ;
2015-03-19 23:39:24 +00:00
// Doesn't make much sense as we're running on demand updates, and there seems to be a bug with the refresh rate when running multiple QGLWidgets
traits - > vsync = false ;
2014-02-25 12:09:37 +00:00
2015-03-19 22:27:14 +00:00
osgQt : : GraphicsWindowQt * window = new osgQt : : GraphicsWindowQt ( traits . get ( ) ) ;
QLayout * layout = new QHBoxLayout ( this ) ;
layout - > addWidget ( window - > getGLWidget ( ) ) ;
setLayout ( layout ) ;
2014-02-25 12:39:49 +00:00
2015-03-19 22:27:14 +00:00
getCamera ( ) - > setGraphicsContext ( window ) ;
2014-02-25 13:09:07 +00:00
2015-03-19 22:27:14 +00:00
getCamera ( ) - > setClearColor ( osg : : Vec4 ( 0.2 , 0.2 , 0.6 , 1.0 ) ) ;
getCamera ( ) - > setViewport ( new osg : : Viewport ( 0 , 0 , traits - > width , traits - > height ) ) ;
2015-03-19 23:39:24 +00:00
getCamera ( ) - > setProjectionMatrixAsPerspective ( 30.0f , static_cast < double > ( traits - > width ) / static_cast < double > ( traits - > height ) , 1.0f , 10000.0f ) ;
2014-02-25 13:09:07 +00:00
2015-03-19 23:39:24 +00:00
mRootNode = new osg : : Group ;
setSceneData ( mRootNode ) ;
// Press S to reveal profiling stats
addEventHandler ( new osgViewer : : StatsHandler ) ;
2014-02-25 13:09:07 +00:00
2015-03-19 22:27:14 +00:00
// Only render when the camera position changed, or content flagged dirty
//setRunFrameScheme(osgViewer::ViewerBase::ON_DEMAND);
2015-03-19 23:39:24 +00:00
setRunFrameScheme ( osgViewer : : ViewerBase : : CONTINUOUS ) ;
2014-02-25 12:09:37 +00:00
2015-03-21 22:10:52 +00:00
getCamera ( ) - > setCullMask ( ~ ( 0x1 ) ) ;
2015-03-19 22:27:14 +00:00
connect ( & mTimer , SIGNAL ( timeout ( ) ) , this , SLOT ( update ( ) ) ) ;
mTimer . start ( 10 ) ;
2015-03-21 22:10:52 +00:00
realize ( ) ;
2015-03-19 22:27:14 +00:00
}
2014-09-28 04:08:14 +00:00
2015-03-19 22:27:14 +00:00
void SceneWidget : : paintEvent ( QPaintEvent * event )
{
frame ( ) ;
}
2014-09-28 05:43:33 +00:00
2015-03-19 22:27:14 +00:00
void SceneWidget : : flagAsModified ( )
{
_requestRedraw = true ;
}
2014-09-28 20:27:54 +00:00
2013-11-02 01:48:30 +00:00
}