2013-11-02 01:48:30 +00:00
|
|
|
#ifndef OPENCS_VIEW_SCENEWIDGET_H
|
|
|
|
#define OPENCS_VIEW_SCENEWIDGET_H
|
|
|
|
|
2016-03-10 09:29:24 +00:00
|
|
|
#include <map>
|
2016-03-14 04:04:11 +00:00
|
|
|
#include <memory>
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2013-11-02 01:48:30 +00:00
|
|
|
#include <QWidget>
|
2015-03-19 22:27:14 +00:00
|
|
|
#include <QTimer>
|
2014-03-23 14:14:26 +00:00
|
|
|
|
2015-07-18 01:52:38 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
2014-03-26 16:47:56 +00:00
|
|
|
#include "lightingday.hpp"
|
2014-03-26 16:59:42 +00:00
|
|
|
#include "lightingnight.hpp"
|
2014-03-26 17:29:15 +00:00
|
|
|
#include "lightingbright.hpp"
|
2014-03-26 16:47:56 +00:00
|
|
|
|
2015-03-23 14:55:57 +00:00
|
|
|
#include <osgViewer/View>
|
|
|
|
#include <osgViewer/CompositeViewer>
|
2014-03-23 14:14:26 +00:00
|
|
|
|
2015-03-28 19:15:17 +00:00
|
|
|
namespace Resource
|
|
|
|
{
|
2015-07-18 01:52:38 +00:00
|
|
|
class ResourceSystem;
|
2015-03-28 19:15:17 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 23:39:24 +00:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Group;
|
2016-02-16 15:02:29 +00:00
|
|
|
class Camera;
|
2015-03-19 23:39:24 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 10:39:12 +00:00
|
|
|
namespace CSVWidget
|
2014-03-23 14:14:26 +00:00
|
|
|
{
|
|
|
|
class SceneToolMode;
|
|
|
|
class SceneToolbar;
|
2013-11-02 01:48:30 +00:00
|
|
|
}
|
|
|
|
|
2016-03-10 09:29:24 +00:00
|
|
|
namespace CSMPrefs
|
|
|
|
{
|
|
|
|
class Setting;
|
|
|
|
}
|
|
|
|
|
2013-11-02 01:48:30 +00:00
|
|
|
namespace CSVRender
|
|
|
|
{
|
2016-03-14 04:04:11 +00:00
|
|
|
class CameraController;
|
|
|
|
class FreeCameraController;
|
|
|
|
class OrbitCameraController;
|
2014-03-23 14:14:26 +00:00
|
|
|
class Lighting;
|
2014-02-27 14:23:14 +00:00
|
|
|
|
2015-03-28 19:15:17 +00:00
|
|
|
class RenderWidget : public QWidget
|
2013-11-02 01:48:30 +00:00
|
|
|
{
|
2016-03-14 04:14:28 +00:00
|
|
|
Q_OBJECT
|
2013-11-02 01:48:30 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
public:
|
|
|
|
RenderWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
|
|
|
virtual ~RenderWidget();
|
2014-10-05 21:20:09 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void flagAsModified();
|
2014-10-05 08:25:37 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void setVisibilityMask(int mask);
|
2015-03-25 23:27:39 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
osg::Camera *getCamera();
|
2016-02-16 15:02:29 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
protected:
|
2014-10-27 19:01:19 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
osg::ref_ptr<osgViewer::View> mView;
|
2015-03-23 14:55:57 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
osg::Group* mRootNode;
|
2015-03-19 23:39:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
QTimer mTimer;
|
2014-02-25 11:30:45 +00:00
|
|
|
};
|
2015-03-19 22:27:14 +00:00
|
|
|
|
2015-03-28 19:15:17 +00:00
|
|
|
// Extension of RenderWidget to support lighting mode selection & toolbar
|
|
|
|
class SceneWidget : public RenderWidget
|
|
|
|
{
|
2016-03-14 04:14:28 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent = 0,
|
|
|
|
Qt::WindowFlags f = 0, bool retrieveInput = true);
|
|
|
|
virtual ~SceneWidget();
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
CSVWidget::SceneToolMode *makeLightingSelector (CSVWidget::SceneToolbar *parent);
|
|
|
|
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
|
|
|
|
/// is the responsibility of the calling function.
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void setDefaultAmbient (const osg::Vec4f& colour);
|
|
|
|
///< \note The actual ambient colour may differ based on lighting settings.
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
protected:
|
|
|
|
void setLighting (Lighting *lighting);
|
|
|
|
///< \attention The ownership of \a lighting is not transferred to *this.
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void setAmbient(const osg::Vec4f& ambient);
|
2015-03-28 20:26:16 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
virtual void mousePressEvent (QMouseEvent *event);
|
|
|
|
virtual void mouseReleaseEvent (QMouseEvent *event);
|
|
|
|
virtual void mouseMoveEvent (QMouseEvent *event);
|
|
|
|
virtual void wheelEvent (QWheelEvent *event);
|
|
|
|
virtual void keyPressEvent (QKeyEvent *event);
|
|
|
|
virtual void keyReleaseEvent (QKeyEvent *event);
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
/// \return Is \a key a button mapping setting? (ignored otherwise)
|
|
|
|
virtual bool storeMappingSetting (const CSMPrefs::Setting *setting);
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
std::string mapButton (QMouseEvent *event);
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
boost::shared_ptr<Resource::ResourceSystem> mResourceSystem;
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
Lighting* mLighting;
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
osg::Vec4f mDefaultAmbient;
|
|
|
|
bool mHasDefaultAmbient;
|
|
|
|
LightingDay mLightingDay;
|
|
|
|
LightingNight mLightingNight;
|
|
|
|
LightingBright mLightingBright;
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
int mPrevMouseX, mPrevMouseY;
|
|
|
|
std::string mMouseMode;
|
|
|
|
std::auto_ptr<FreeCameraController> mFreeCamControl;
|
|
|
|
std::auto_ptr<OrbitCameraController> mOrbitCamControl;
|
|
|
|
CameraController* mCurrentCamControl;
|
2016-03-14 04:04:11 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
std::map<std::pair<Qt::MouseButton, bool>, std::string> mButtonMapping;
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-18 18:02:24 +00:00
|
|
|
private:
|
|
|
|
bool mCamPositionSet;
|
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
public slots:
|
|
|
|
void update(double dt);
|
2016-03-14 04:04:11 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
protected slots:
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
virtual void settingChanged (const CSMPrefs::Setting *setting);
|
2016-03-10 09:29:24 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void selectNavigationMode (const std::string& mode);
|
2016-03-10 21:56:14 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
private slots:
|
2015-03-28 19:15:17 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void selectLightingMode (const std::string& mode);
|
2015-09-17 10:41:56 +00:00
|
|
|
|
|
|
|
signals:
|
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
void focusToolbarRequest();
|
2015-03-28 19:15:17 +00:00
|
|
|
};
|
2015-03-23 14:55:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
// There are rendering glitches when using multiple Viewer instances, work around using CompositeViewer with multiple views
|
|
|
|
class CompositeViewer : public QObject, public osgViewer::CompositeViewer
|
|
|
|
{
|
2016-03-14 04:14:28 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
CompositeViewer();
|
2015-03-23 14:55:57 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
static CompositeViewer& get();
|
2015-03-23 14:55:57 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
QTimer mTimer;
|
2015-03-23 14:55:57 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
private:
|
|
|
|
osg::Timer mFrameTimer;
|
|
|
|
double mSimulationTime;
|
2015-06-14 17:19:23 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
public slots:
|
|
|
|
void update();
|
2016-03-14 04:04:11 +00:00
|
|
|
|
2016-03-14 04:14:28 +00:00
|
|
|
signals:
|
|
|
|
void simulationUpdated(double dt);
|
2015-03-23 14:55:57 +00:00
|
|
|
};
|
|
|
|
|
2013-11-02 01:48:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|