| 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_CompositeViewer |
|---|
| 15 | #define OSGVIEWER_CompositeViewer 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/ArgumentParser> |
|---|
| 18 | #include <osgUtil/UpdateVisitor> |
|---|
| 19 | #include <osgViewer/GraphicsWindow> |
|---|
| 20 | #include <osgViewer/View> |
|---|
| 21 | |
|---|
| 22 | namespace osgViewer { |
|---|
| 23 | |
|---|
| 24 | /** CompsiteViewer holds a or more views to a one more scenes.*/ |
|---|
| 25 | class OSGVIEWER_EXPORT CompositeViewer : public ViewerBase, public virtual osg::Object |
|---|
| 26 | { |
|---|
| 27 | public: |
|---|
| 28 | |
|---|
| 29 | CompositeViewer(); |
|---|
| 30 | |
|---|
| 31 | CompositeViewer(const CompositeViewer&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 32 | |
|---|
| 33 | CompositeViewer(osg::ArgumentParser& arguments); |
|---|
| 34 | |
|---|
| 35 | META_Object(osgViewer,CompositeViewer); |
|---|
| 36 | |
|---|
| 37 | virtual ~CompositeViewer(); |
|---|
| 38 | |
|---|
| 39 | /** read the viewer configuration from a configuration file.*/ |
|---|
| 40 | bool readConfiguration(const std::string& filename); |
|---|
| 41 | |
|---|
| 42 | void addView(osgViewer::View* view); |
|---|
| 43 | void removeView(osgViewer::View* view); |
|---|
| 44 | |
|---|
| 45 | osgViewer::View* getView(unsigned i) { return _views[i].get(); } |
|---|
| 46 | const osgViewer::View* getView(unsigned i) const { return _views[i].get(); } |
|---|
| 47 | |
|---|
| 48 | unsigned int getNumViews() const { return _views.size(); } |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | /** Get whether at least of one of this viewers windows are realized.*/ |
|---|
| 52 | virtual bool isRealized() const; |
|---|
| 53 | |
|---|
| 54 | /** set up windows and associated threads.*/ |
|---|
| 55 | virtual void realize(); |
|---|
| 56 | |
|---|
| 57 | virtual void setStartTick(osg::Timer_t tick); |
|---|
| 58 | |
|---|
| 59 | void setReferenceTime(double time=0.0); |
|---|
| 60 | |
|---|
| 61 | osg::FrameStamp* getFrameStamp() { return _frameStamp.get(); } |
|---|
| 62 | const osg::FrameStamp* getFrameStamp() const { return _frameStamp.get(); } |
|---|
| 63 | |
|---|
| 64 | virtual double elapsedTime(); |
|---|
| 65 | |
|---|
| 66 | virtual osg::FrameStamp* getViewerFrameStamp() { return getFrameStamp(); } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | /** Execute a main frame loop. |
|---|
| 70 | * Equivalent to while (!viewer.done()) viewer.frame(); |
|---|
| 71 | * Also calls realize() if the viewer is not already realized, |
|---|
| 72 | * and installs trackball manipulator if one is not already assigned. |
|---|
| 73 | */ |
|---|
| 74 | virtual int run(); |
|---|
| 75 | |
|---|
| 76 | virtual void advance(double simulationTime=USE_REFERENCE_TIME); |
|---|
| 77 | |
|---|
| 78 | virtual void eventTraversal(); |
|---|
| 79 | |
|---|
| 80 | virtual void updateTraversal(); |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | void setCameraWithFocus(osg::Camera* camera); |
|---|
| 84 | osg::Camera* getCameraWithFocus() { return _cameraWithFocus.get(); } |
|---|
| 85 | const osg::Camera* getCameraWithFocus() const { return _cameraWithFocus.get(); } |
|---|
| 86 | |
|---|
| 87 | osgViewer::View* getViewWithFocus() { return _viewWithFocus.get(); } |
|---|
| 88 | const osgViewer::View* getViewWithFocus() const { return _viewWithFocus.get(); } |
|---|
| 89 | |
|---|
| 90 | virtual void getCameras(Cameras& cameras, bool onlyActive=true); |
|---|
| 91 | |
|---|
| 92 | virtual void getContexts(Contexts& contexts, bool onlyValid=true); |
|---|
| 93 | |
|---|
| 94 | virtual void getAllThreads(Threads& threads, bool onlyActive=true); |
|---|
| 95 | |
|---|
| 96 | virtual void getOperationThreads(OperationThreads& threads, bool onlyActive=true); |
|---|
| 97 | |
|---|
| 98 | virtual void getScenes(Scenes& scenes, bool onlyValid=true); |
|---|
| 99 | |
|---|
| 100 | virtual void getViews(Views& views, bool onlyValid=true); |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | /** Get the keyboard and mouse usage of this viewer.*/ |
|---|
| 104 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 105 | |
|---|
| 106 | protected: |
|---|
| 107 | |
|---|
| 108 | void constructorInit(); |
|---|
| 109 | |
|---|
| 110 | virtual void viewerInit(); |
|---|
| 111 | |
|---|
| 112 | typedef std::vector< osg::ref_ptr<osgViewer::View> > RefViews; |
|---|
| 113 | RefViews _views; |
|---|
| 114 | |
|---|
| 115 | bool _firstFrame; |
|---|
| 116 | |
|---|
| 117 | osg::Timer_t _startTick; |
|---|
| 118 | osg::ref_ptr<osg::FrameStamp> _frameStamp; |
|---|
| 119 | |
|---|
| 120 | osg::observer_ptr<osg::Camera> _cameraWithFocus; |
|---|
| 121 | osg::observer_ptr<osgViewer::View> _viewWithFocus; |
|---|
| 122 | |
|---|
| 123 | }; |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | #endif |
|---|