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 
00031 
00032 
00033 #include "rviz.h"
00034 
00035 #include <pluginlib/class_list_macros.h>
00036 #include <OGRE/OgreLogManager.h>
00037 
00038 #include <QCloseEvent>
00039 #include <QMenuBar>
00040 
00041 namespace rqt_rviz {
00042 
00043 RViz::RViz()
00044   : rqt_gui_cpp::Plugin()
00045   , context_(0)
00046   , widget_(0)
00047   , log_(0)
00048 {
00049   setObjectName("RViz");
00050 }
00051 
00052 RViz::~RViz()
00053 {
00054   Ogre::LogManager* log_manager = Ogre::LogManager::getSingletonPtr();
00055   if (log_manager && log_)
00056   {
00057     log_manager->destroyLog(log_);
00058   }
00059 }
00060 
00061 void RViz::initPlugin(qt_gui_cpp::PluginContext& context)
00062 {
00063   context_ = &context;
00064 
00065   
00066   Ogre::LogManager* log_manager = Ogre::LogManager::getSingletonPtr();
00067   if (!log_manager)
00068   {
00069     log_manager = new Ogre::LogManager();
00070   }
00071   QString filename = QString("rqt_rviz_ogre") + (context.serialNumber() > 1 ? QString::number(context.serialNumber()) : QString("")) + QString(".log");
00072   log_ = log_manager->createLog(filename.toStdString().c_str(), false, false);
00073 
00074   widget_ = new rviz::VisualizationFrame();
00075 
00076   
00077   QMenuBar* menu_bar = new QMenuBar();
00078   menu_bar->setNativeMenuBar(false);
00079   widget_->setMenuBar(menu_bar);
00080 
00081   widget_->initialize();
00082 
00083   
00084   QMenu* menu = 0;
00085   {
00086     
00087     const QObjectList& children = menu_bar->children();
00088     for (QObjectList::const_iterator it = children.begin(); !menu && it != children.end(); it++)
00089     {
00090       menu = dynamic_cast<QMenu*>(*it);
00091     }
00092   }
00093   if (menu)
00094   {
00095     
00096     const QObjectList& children = menu->children();
00097     if (!children.empty())
00098     {
00099       QAction* action = dynamic_cast<QAction*>(children.last());
00100       if (action)
00101       {
00102         action->setVisible(false);
00103       }
00104     }
00105   }
00106 
00107   widget_->setWindowTitle("RViz[*]");
00108   if (context.serialNumber() != 1)
00109   {
00110     widget_->setWindowTitle(widget_->windowTitle() + " (" + QString::number(context.serialNumber()) + ")");
00111   }
00112   context.addWidget(widget_);
00113 
00114   
00115   widget_->installEventFilter(this);
00116 }
00117 
00118 bool RViz::eventFilter(QObject* watched, QEvent* event)
00119 {
00120   if (watched == widget_ && event->type() == QEvent::Close)
00121   {
00122     event->ignore();
00123     context_->closePlugin();
00124     return true;
00125   }
00126 
00127   return QObject::eventFilter(watched, event);
00128 }
00129 
00130 }
00131 
00132 PLUGINLIB_DECLARE_CLASS(rqt_rviz, RViz, rqt_rviz::RViz, rqt_gui_cpp::Plugin)