Go to the documentation of this file.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 <QApplication>
00031 #include <QMenu>
00032
00033 #include "render_panel.h"
00034 #include "visualization_manager.h"
00035 #include "display.h"
00036 #include "display_wrapper.h"
00037 #include "tools/tool.h"
00038 #include "viewport_mouse_event.h"
00039 #include "view_controller.h"
00040
00041 #include <OGRE/OgreRoot.h>
00042 #include <OGRE/OgreViewport.h>
00043
00044 namespace rviz
00045 {
00046
00047 RenderPanel::RenderPanel( ogre_tools::RenderSystem* render_system, Display* display, QWidget* parent )
00048 : QtOgreRenderWindow( render_system, parent )
00049 , mouse_x_( 0 )
00050 , mouse_y_( 0 )
00051 , manager_( 0 )
00052 , scene_manager_( 0 )
00053 , camera_( 0 )
00054 , view_controller_( 0 )
00055 , display_( display )
00056 {
00057 setFocus( Qt::OtherFocusReason );
00058 }
00059
00060 RenderPanel::~RenderPanel()
00061 {
00062 delete view_controller_;
00063 scene_manager_->destroyCamera(camera_);
00064 }
00065
00066 void RenderPanel::initialize(Ogre::SceneManager* scene_manager, VisualizationManager* manager)
00067 {
00068 manager_ = manager;
00069 scene_manager_ = scene_manager;
00070
00071 std::stringstream ss;
00072 static int count = 0;
00073 ss << "RenderPanelCamera" << count++;
00074 camera_ = scene_manager_->createCamera(ss.str());
00075
00076 setCamera( camera_ );
00077 }
00078
00079 void RenderPanel::onRenderWindowMouseEvents( QMouseEvent* event )
00080 {
00081 int last_x = mouse_x_;
00082 int last_y = mouse_y_;
00083
00084 mouse_x_ = event->x();
00085 mouse_y_ = event->y();
00086
00087 if (manager_)
00088 {
00089 setFocus( Qt::MouseFocusReason );
00090
00091 ViewportMouseEvent vme(this, getViewport(), event, last_x, last_y);
00092 manager_->handleMouseEvent(vme);
00093 event->accept();
00094 }
00095 }
00096
00097 void RenderPanel::wheelEvent( QWheelEvent* event )
00098 {
00099 int last_x = mouse_x_;
00100 int last_y = mouse_y_;
00101
00102 mouse_x_ = event->x();
00103 mouse_y_ = event->y();
00104
00105 if (manager_)
00106 {
00107 setFocus( Qt::MouseFocusReason );
00108
00109 ViewportMouseEvent vme(this, getViewport(), event, last_x, last_y);
00110 manager_->handleMouseEvent(vme);
00111 event->accept();
00112 }
00113 }
00114
00115 void RenderPanel::keyPressEvent( QKeyEvent* 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::showContextMenu( boost::shared_ptr<QMenu> menu )
00137 {
00138 boost::mutex::scoped_lock lock(context_menu_mutex_);
00139 context_menu_ = menu;
00140
00141 QApplication::postEvent( this, new QContextMenuEvent( QContextMenuEvent::Mouse, QPoint() ));
00142 }
00143
00144 void RenderPanel::contextMenuEvent( QContextMenuEvent* event )
00145 {
00146 boost::shared_ptr<QMenu> context_menu;
00147 {
00148 boost::mutex::scoped_lock lock(context_menu_mutex_);
00149 context_menu.swap(context_menu_);
00150 }
00151
00152 if ( context_menu )
00153 {
00154 context_menu->exec( QCursor::pos() );
00155 }
00156 }
00157
00158 }