00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "render_panel.h"
00031 #include "visualization_manager.h"
00032 #include "display.h"
00033 #include "tools/tool.h"
00034 #include "viewport_mouse_event.h"
00035 #include "view_controller.h"
00036
00037 #include <boost/bind.hpp>
00038
00039 #include <OGRE/OgreRoot.h>
00040 #include <OGRE/OgreViewport.h>
00041
00042 namespace rviz
00043 {
00044
00045 RenderPanel::RenderPanel( wxWindow* parent, bool create_render_window )
00046 : wxOgreRenderWindow( Ogre::Root::getSingletonPtr(), parent, wxID_ANY, wxDefaultPosition, wxSize(800, 600), wxSUNKEN_BORDER, wxDefaultValidator, create_render_window )
00047 , mouse_x_( 0 )
00048 , mouse_y_( 0 )
00049 , manager_(0)
00050 , scene_manager_(0)
00051 , camera_(0)
00052 , view_controller_(0)
00053 {
00054 SetFocus();
00055 Connect( wxEVT_CHAR, wxKeyEventHandler( RenderPanel::onChar ), NULL, this );
00056
00057 Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00058 Connect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00059 Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00060 Connect( wxEVT_MOTION, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00061 Connect( wxEVT_LEFT_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00062 Connect( wxEVT_MIDDLE_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00063 Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00064 Connect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00065 Connect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00066 }
00067
00068 RenderPanel::~RenderPanel()
00069 {
00070 delete view_controller_;
00071 scene_manager_->destroyCamera(camera_);
00072
00073 Disconnect( wxEVT_CHAR, wxKeyEventHandler( RenderPanel::onChar ), NULL, this );
00074 Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00075 Disconnect( wxEVT_MIDDLE_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00076 Disconnect( wxEVT_RIGHT_DOWN, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00077 Disconnect( wxEVT_MOTION, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00078 Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00079 Disconnect( wxEVT_MIDDLE_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00080 Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00081 Disconnect( wxEVT_MOUSEWHEEL, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00082 Disconnect( wxEVT_LEFT_DCLICK, wxMouseEventHandler( RenderPanel::onRenderWindowMouseEvents ), NULL, this );
00083 }
00084
00085 void RenderPanel::initialize(Ogre::SceneManager* scene_manager, VisualizationManager* manager)
00086 {
00087 manager_ = manager;
00088 scene_manager_ = scene_manager;
00089
00090 std::stringstream ss;
00091 static int count = 0;
00092 ss << "RenderPanelCamera" << count++;
00093 camera_ = scene_manager_->createCamera(ss.str());
00094
00095 wxOgreRenderWindow::setCamera(camera_);
00096 }
00097
00098 void RenderPanel::onRenderWindowMouseEvents( wxMouseEvent& event )
00099 {
00100 int last_x = mouse_x_;
00101 int last_y = mouse_y_;
00102
00103 mouse_x_ = event.GetX();
00104 mouse_y_ = event.GetY();
00105
00106 if (manager_)
00107 {
00108 SetFocus();
00109
00110 ViewportMouseEvent vme(this, getViewport(), event, last_x, last_y);
00111 manager_->handleMouseEvent(vme);
00112 }
00113 }
00114
00115 void RenderPanel::onChar( wxKeyEvent& event )
00116 {
00117 if (manager_)
00118 {
00119 manager_->handleChar( event );
00120 }
00121 }
00122
00123 void RenderPanel::setViewController(ViewController* controller)
00124 {
00125 if (view_controller_)
00126 {
00127 view_controller_->deactivate();
00128 }
00129
00130 delete view_controller_;
00131 view_controller_ = controller;
00132
00133 view_controller_->activate(camera_, manager_ ? manager_->getTargetFrame() : "");
00134 }
00135
00136 void RenderPanel::createRenderWindow()
00137 {
00138 wxOgreRenderWindow::createRenderWindow();
00139 wxOgreRenderWindow::setCamera(camera_);
00140 }
00141
00142 }