| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGVIEWER_Viewer |
|---|
| 15 | #define OSGVIEWER_Viewer 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/ArgumentParser> |
|---|
| 18 | #include <osgGA/EventVisitor> |
|---|
| 19 | #include <osgUtil/UpdateVisitor> |
|---|
| 20 | #include <osgViewer/GraphicsWindow> |
|---|
| 21 | #include <osgViewer/View> |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | namespace osgViewer { |
|---|
| 25 | |
|---|
| 26 | /** Viewer holds a single view on to a single scene.*/ |
|---|
| 27 | class OSGVIEWER_EXPORT Viewer : public ViewerBase, public osgViewer::View |
|---|
| 28 | { |
|---|
| 29 | public: |
|---|
| 30 | |
|---|
| 31 | Viewer(); |
|---|
| 32 | |
|---|
| 33 | Viewer(osg::ArgumentParser& arguments); |
|---|
| 34 | |
|---|
| 35 | Viewer(const osgViewer::Viewer& viewer, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 36 | |
|---|
| 37 | virtual ~Viewer(); |
|---|
| 38 | |
|---|
| 39 | META_Object(osgViewer,Viewer); |
|---|
| 40 | |
|---|
| 41 | /** Take all the settings, Camera and Slaves from the passed in view(er), leaving it empty. */ |
|---|
| 42 | virtual void take(View& rhs); |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | /** Set the Stats object used for collect various frame related timing and scene graph stats.*/ |
|---|
| 46 | virtual void setViewerStats(osg::Stats* stats) { setStats(stats); } |
|---|
| 47 | |
|---|
| 48 | /** Get the Viewers Stats object.*/ |
|---|
| 49 | virtual osg::Stats* getViewerStats() { return getStats(); } |
|---|
| 50 | |
|---|
| 51 | /** Get the Viewers Stats object.*/ |
|---|
| 52 | virtual const osg::Stats* getViewerStats() const { return getStats(); } |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | /** read the viewer configuration from a configuration file.*/ |
|---|
| 56 | virtual bool readConfiguration(const std::string& filename); |
|---|
| 57 | |
|---|
| 58 | /** Get whether at least of one of this viewers windows are realized.*/ |
|---|
| 59 | virtual bool isRealized() const; |
|---|
| 60 | |
|---|
| 61 | /** set up windows and associated threads.*/ |
|---|
| 62 | virtual void realize(); |
|---|
| 63 | |
|---|
| 64 | virtual void setStartTick(osg::Timer_t tick); |
|---|
| 65 | void setReferenceTime(double time=0.0); |
|---|
| 66 | |
|---|
| 67 | /** Set the sene graph data that viewer with view.*/ |
|---|
| 68 | virtual void setSceneData(osg::Node* node); |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | /** Convenience method for setting up the viewer so it can be used embedded in an external managed window. |
|---|
| 72 | * Returns the GraphicsWindowEmbedded that can be used by applications to pass in events to the viewer. */ |
|---|
| 73 | virtual GraphicsWindowEmbedded* setUpViewerAsEmbeddedInWindow(int x, int y, int width, int height); |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | virtual double elapsedTime(); |
|---|
| 77 | |
|---|
| 78 | virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); } |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | /** Execute a main frame loop. |
|---|
| 82 | * Equivalent to while (!viewer.done()) viewer.frame(); |
|---|
| 83 | * Also calls realize() if the viewer is not already realized, |
|---|
| 84 | * and installs trackball manipulator if one is not already assigned. |
|---|
| 85 | */ |
|---|
| 86 | virtual int run(); |
|---|
| 87 | |
|---|
| 88 | virtual void advance(double simulationTime=USE_REFERENCE_TIME); |
|---|
| 89 | |
|---|
| 90 | virtual void eventTraversal(); |
|---|
| 91 | |
|---|
| 92 | virtual void updateTraversal(); |
|---|
| 93 | |
|---|
| 94 | void setCameraWithFocus(osg::Camera* camera) { _cameraWithFocus = camera; } |
|---|
| 95 | osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); } |
|---|
| 96 | const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); } |
|---|
| 97 | |
|---|
| 98 | virtual void getCameras(Cameras& cameras, bool onlyActive=true); |
|---|
| 99 | |
|---|
| 100 | virtual void getContexts(Contexts& contexts, bool onlyValid=true); |
|---|
| 101 | |
|---|
| 102 | virtual void getAllThreads(Threads& threads, bool onlyActive=true); |
|---|
| 103 | |
|---|
| 104 | virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true); |
|---|
| 105 | |
|---|
| 106 | virtual void getScenes(Scenes& scenes, bool onlyValid=true); |
|---|
| 107 | |
|---|
| 108 | virtual void getViews(Views& views, bool onlyValid=true); |
|---|
| 109 | |
|---|
| 110 | /** Get the keyboard and mouse usage of this viewer.*/ |
|---|
| 111 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | protected: |
|---|
| 115 | |
|---|
| 116 | void constructorInit(); |
|---|
| 117 | |
|---|
| 118 | virtual void viewerInit() { init(); } |
|---|
| 119 | |
|---|
| 120 | osg::observer_ptr<osg::Camera> _cameraWithFocus; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | #endif |
|---|