Commit 70f63a0e authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE #415] adapted WGEViewer for the use of WGEViewerMac

parent db9bf5bd
......@@ -6,7 +6,11 @@ ADD_SUBDIRECTORY( platformDependent )
FILE( GLOB GE_EXCEPTIONS_SRC "exceptions/*.cpp" "exceptions/*.h" )
FILE( GLOB GE_CALLBACKS_SRC "callbacks/*.cpp" "callbacks/*.h" )
FILE( GLOB GE_ALGORITHMS_SRC "algorithms/*.cpp" "algorithms/*.h" )
FILE( GLOB GE_PLATFORMDEPENDENT_SRC "platformDependent/WGEGraphicsWindowMac.cpp" "platformDependent/WGEGraphicsWindowMac.h" )
FILE( GLOB GE_PLATFORMDEPENDENT_SRC
"platformDependent/WGEViewerMac.cpp"
"platformDependent/WGEViewerMac.h"
"platformDependent/WGEGraphicsWindowMac.cpp"
"platformDependent/WGEGraphicsWindowMac.h" )
FILE( GLOB GE_SRC "*.cpp" "*.h" )
ADD_LIBRARY( OWge SHARED ${GE_SRC} ${GE_EXCEPTIONS_SRC} ${GE_CALLBACKS_SRC} ${GE_ALGORITHMS_SRC} ${GE_PLATFORMDEPENDENT_SRC} )
......
......@@ -22,160 +22,4 @@
//
//---------------------------------------------------------------------------
#include <string>
#include <iostream>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/UFOManipulator>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/StateSetManipulator>
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgViewer/ViewerEventHandlers>
#include <osgViewer/View>
#include <osgDB/ReadFile>
#include "exceptions/WGEInitFailed.h"
#include "WGE2DManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "WGEViewer.h"
WGEViewer::WGEViewer( std::string name, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
m_name( name )
{
try
{
m_View = osg::ref_ptr<osgViewer::Viewer>( new osgViewer::Viewer() );
m_View->setCamera( new WGECamera( width, height, projectionMode ) );
m_View->getCamera()->setGraphicsContext( m_GraphicsWindow.get() );
switch( projectionMode )
{
case( WGECamera::ORTHOGRAPHIC ):
m_pickHandler = new WPickHandler( name );
m_View->addEventHandler( m_pickHandler );
if ( name != std::string( "main" ) )
break;
case( WGECamera::PERSPECTIVE ):
// camera manipulator
m_View->setCameraManipulator( new WGEZoomTrackballManipulator() );
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
break;
case( WGECamera::TWO_D ):
// no manipulators nor gui handlers
break;
default:
throw WGEInitFailed( std::string( "Unknown projection mode" ) );
}
// add the stats handler
m_View->addEventHandler( new osgViewer::StatsHandler );
}
catch( ... )
{
throw WGEInitFailed( std::string( "Initialization of WGEViewer failed" ) );
}
}
WGEViewer::~WGEViewer()
{
// cleanup
close();
}
osg::ref_ptr<osgViewer::Viewer> WGEViewer::getView()
{
return m_View;
}
void WGEViewer::setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator )
{
m_View->setCameraManipulator( manipulator );
// redraw request?? no since it redraws permanently and uses the new settings
}
osg::ref_ptr<osgGA::MatrixManipulator> WGEViewer::getCameraManipulator()
{
return m_View->getCameraManipulator();
}
void WGEViewer::setCamera( osg::ref_ptr<osg::Camera> camera )
{
m_View->setCamera( camera );
// redraw request?? No since it redraws permanently and uses the new settings
}
osg::ref_ptr<osg::Camera> WGEViewer::getCamera()
{
return m_View->getCamera();
}
void WGEViewer::setScene( osg::ref_ptr< WGEGroupNode > node )
{
m_View->setSceneData( node );
m_scene = node;
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
{
return m_scene;
}
void WGEViewer::setBgColor( WColor bgColor )
{
m_View->getCamera()->setClearColor( osg::Vec4( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 1. ) );
}
void WGEViewer::paint()
{
m_View->frame();
}
void WGEViewer::resize( int width, int height )
{
m_View->getEventQueue()->windowResize( 0, 0, width, height );
WGEGraphicsWindow::resize( width, height );
// also update the camera
m_View->getCamera()->setViewport( 0, 0, width, height );
WGECamera* camera = dynamic_cast< WGECamera* >( m_View->getCamera() );
if( camera )
{
camera->resize();
}
}
void WGEViewer::close()
{
// forward close event
WGEGraphicsWindow::close();
}
std::string WGEViewer::getName() const
{
return m_name;
}
osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
{
return m_pickHandler;
}
void WGEViewer::reset()
{
m_View->home();
}
......@@ -25,173 +25,7 @@
#ifndef WGEVIEWER_H
#define WGEVIEWER_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <osg/Node>
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/UFOManipulator>
#include <osgViewer/View>
#include "../common/WThreadedRunner.h"
#include "../common/WColor.h"
#include "WGEGraphicsWindow.h"
#include "WGECamera.h"
#include "WPickHandler.h"
#include "WGEGroupNode.h"
#include "WExportWGE.h"
/**
* Class for managing one view to the scene. This includes viewport, camera and graphics context.
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
* \ingroup ge
*/
class WGE_EXPORT WGEViewer: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewer >
{
public:
/**
* Default constructor.
*
* \param name the name of the viewer
* \param x X coordinate of widget where to create the context.
* \param y Y coordinate of widget where to create the context.
* \param width Width of the widget.
* \param height Height of the Widget.
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( std::string name, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
*/
virtual ~WGEViewer();
/**
* Repaints the contents.
*/
virtual void paint();
/**
* Updates size information. Also updates camera.
*
* \param width new width.
* \param height new height.
*/
virtual void resize( int width, int height );
/**
* Close the viewer, but wait for the rendering thread to finish.
*/
virtual void close();
/**
* Getter for OpenSceneGraph View instance.
*
* \return the OSG Viewer instance.
*/
osg::ref_ptr<osgViewer::Viewer> getView();
/**
* Resets the view using the installed manipulator.
*/
void reset();
/**
* Sets the camera manipulator to use.
*
* \param manipulator the manipulator to use.
*/
void setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator );
/**
* Returns current active camera manipulator
*
* \return the active camera manipulator.
*/
osg::ref_ptr<osgGA::MatrixManipulator> getCameraManipulator();
/**
* Sets the current camera.
*
* \param camera the OSG camera instance.
*/
void setCamera( osg::ref_ptr<osg::Camera> camera );
/**
* Returns the camera currently in use.
*
* \return the camera currently in use.
*/
osg::ref_ptr<osg::Camera> getCamera();
/**
* Sets the scene graph node to be used for rendering.
*
* \param node part of the scene graph
*/
void setScene( osg::ref_ptr< WGEGroupNode > node );
/**
* Returns the currently set OSG node.
*
* \return the node.
*/
osg::ref_ptr< WGEGroupNode > getScene();
/**
* Returns the name of the viewer.
*
* \return the name
*/
std::string getName() const;
/**
* Determine the color of the viewer's background.
* \param bgColor the new background color
*/
void setBgColor( WColor bgColor );
/**
* Getter for the pick handler
*
* \return the pick handler
*/
osg::ref_ptr< WPickHandler > getPickHandler();
protected:
/**
* The OpenSceneGraph view used in this (Composite)Viewer.
*/
osg::ref_ptr< osgViewer::Viewer > m_View;
/**
* The name of the viewer.
*/
std::string m_name;
/**
* Pointer to the pick handler of the viewer.
*/
osg::ref_ptr<WPickHandler> m_pickHandler;
/**
* reference to the scene which is displayed by viewer
*/
osg::ref_ptr< WGEGroupNode > m_scene;
private:
};
#include "platformDependent/WGEViewerMac.h"
typedef WGEViewerMac WGEViewer;
#endif // WGEVIEWER_H
......@@ -40,17 +40,17 @@
#include <osgDB/ReadFile>
#include "exceptions/WGEInitFailed.h"
#include "WGE2DManipulator.h"
#include "WGEZoomTrackballManipulator.h"
#include "WPickHandler.h"
#include "../exceptions/WGEInitFailed.h"
#include "../WGE2DManipulator.h"
#include "../WGEZoomTrackballManipulator.h"
#include "../WPickHandler.h"
#include "WGEViewer.h"
#include "WGEViewerMac.h"
WGEViewer::WGEViewer( std::string name, int x, int y,
WGEViewerMac::WGEViewerMac( std::string name, int x, int y,
int width, int height, WGECamera::ProjectionMode projectionMode )
: WGEGraphicsWindow( x, y, width, height ),
boost::enable_shared_from_this< WGEViewer >(),
boost::enable_shared_from_this< WGEViewerMac >(),
m_name( name )
{
try
......@@ -85,65 +85,65 @@ WGEViewer::WGEViewer( std::string name, int x, int y,
}
catch( ... )
{
throw WGEInitFailed( std::string( "Initialization of WGEViewer failed" ) );
throw WGEInitFailed( std::string( "Initialization of WGEViewerMac failed" ) );
}
}
WGEViewer::~WGEViewer()
WGEViewerMac::~WGEViewerMac()
{
// cleanup
close();
}
osg::ref_ptr<osgViewer::Viewer> WGEViewer::getView()
osg::ref_ptr<osgViewer::Viewer> WGEViewerMac::getView()
{
return m_View;
}
void WGEViewer::setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator )
void WGEViewerMac::setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator )
{
m_View->setCameraManipulator( manipulator );
// redraw request?? no since it redraws permanently and uses the new settings
}
osg::ref_ptr<osgGA::MatrixManipulator> WGEViewer::getCameraManipulator()
osg::ref_ptr<osgGA::MatrixManipulator> WGEViewerMac::getCameraManipulator()
{
return m_View->getCameraManipulator();
}
void WGEViewer::setCamera( osg::ref_ptr<osg::Camera> camera )
void WGEViewerMac::setCamera( osg::ref_ptr<osg::Camera> camera )
{
m_View->setCamera( camera );
// redraw request?? No since it redraws permanently and uses the new settings
}
osg::ref_ptr<osg::Camera> WGEViewer::getCamera()
osg::ref_ptr<osg::Camera> WGEViewerMac::getCamera()
{
return m_View->getCamera();
}
void WGEViewer::setScene( osg::ref_ptr< WGEGroupNode > node )
void WGEViewerMac::setScene( osg::ref_ptr< WGEGroupNode > node )
{
m_View->setSceneData( node );
m_scene = node;
}
osg::ref_ptr< WGEGroupNode > WGEViewer::getScene()
osg::ref_ptr< WGEGroupNode > WGEViewerMac::getScene()
{
return m_scene;
}
void WGEViewer::setBgColor( WColor bgColor )
void WGEViewerMac::setBgColor( WColor bgColor )
{
m_View->getCamera()->setClearColor( osg::Vec4( bgColor.getRed(), bgColor.getGreen(), bgColor.getBlue(), 1. ) );
}
void WGEViewer::paint()
void WGEViewerMac::paint()
{
m_View->frame();
}
void WGEViewer::resize( int width, int height )
void WGEViewerMac::resize( int width, int height )
{
m_View->getEventQueue()->windowResize( 0, 0, width, height );
......@@ -158,23 +158,23 @@ void WGEViewer::resize( int width, int height )
}
}
void WGEViewer::close()
void WGEViewerMac::close()
{
// forward close event
WGEGraphicsWindow::close();
}
std::string WGEViewer::getName() const
std::string WGEViewerMac::getName() const
{
return m_name;
}
osg::ref_ptr< WPickHandler > WGEViewer::getPickHandler()
osg::ref_ptr< WPickHandler > WGEViewerMac::getPickHandler()
{
return m_pickHandler;
}
void WGEViewer::reset()
void WGEViewerMac::reset()
{
m_View->home();
}
......
......@@ -22,8 +22,8 @@
//
//---------------------------------------------------------------------------
#ifndef WGEVIEWER_H
#define WGEVIEWER_H
#ifndef WGEVIEWERMAC_H
#define WGEVIEWERMAC_H
#include <string>
......@@ -39,15 +39,15 @@
#include <osgViewer/View>
#include "../common/WThreadedRunner.h"
#include "../common/WColor.h"
#include "../../common/WThreadedRunner.h"
#include "../../common/WColor.h"
#include "WGEGraphicsWindow.h"
#include "WGECamera.h"
#include "WPickHandler.h"
#include "WGEGroupNode.h"
#include "../WGEGraphicsWindow.h"
#include "../WGECamera.h"
#include "../WPickHandler.h"
#include "../WGEGroupNode.h"
#include "WExportWGE.h"
#include "../WExportWGE.h"
/**
......@@ -55,8 +55,8 @@
* It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
* \ingroup ge
*/
class WGE_EXPORT WGEViewer: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewer >
class WGE_EXPORT WGEViewerMac: public WGEGraphicsWindow,
public boost::enable_shared_from_this< WGEViewerMac >
{
public:
/**
......@@ -70,13 +70,13 @@ public:
* \param projectionMode Projection mode of the viewer.
* \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
*/
WGEViewer( std::string name, int x, int y, int width, int height,
WGEViewerMac( std::string name, int x, int y, int width, int height,
WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
/**
* Destructor.
*/
virtual ~WGEViewer();
virtual ~WGEViewerMac();
/**
* Repaints the contents.
......@@ -194,4 +194,4 @@ protected:
private:
};
#endif // WGEVIEWER_H
#endif // WGEVIEWERMAC_H
......@@ -29,9 +29,8 @@
#include <osg/ref_ptr>
#include "../graphicsEngine/WGEViewer.h"
class WGEGroupNode;
class WGEViewer;
/**
* Custom widget which is created by a module to display custom information.
......
......@@ -35,8 +35,8 @@
#include <boost/signals2/signal.hpp>
#include "../../graphicsEngine/WGECamera.h"
#include "../../graphicsEngine/WGEViewer.h"
class WGEViewer;
class WColor;
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment