rviz.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Dorian Scholz, TU Darmstadt
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  *   * Redistributions of source code must retain the above copyright
00010  *     notice, this list of conditions and the following disclaimer.
00011  *   * Redistributions in binary form must reproduce the above
00012  *     copyright notice, this list of conditions and the following
00013  *     disclaimer in the documentation and/or other materials provided
00014  *     with the distribution.
00015  *   * Neither the name of the TU Darmstadt nor the names of its
00016  *     contributors may be used to endorse or promote products derived
00017  *     from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00022  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00023  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00024  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00025  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00027  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00028  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00029  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00030  * POSSIBILITY OF SUCH DAMAGE.
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   // prevent output of Ogre stuff to console
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   // create own menu bar to disable native menu bars on Unity and Mac
00077   QMenuBar* menu_bar = new QMenuBar();
00078   menu_bar->setNativeMenuBar(false);
00079   widget_->setMenuBar(menu_bar);
00080 
00081   widget_->initialize();
00082 
00083   // disable quit action in menu bar
00084   QMenu* menu = 0;
00085   {
00086     // find first menu in menu bar
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     // hide last action in menu
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   // trigger deleteLater for plugin when widget or frame is closed
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)


rqt_rviz
Author(s): Dorian Scholz
autogenerated on Fri Jan 3 2014 11:56:03