ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version | answered 2015-03-13 15:28:52 -0500 Anonymous |
@inflo :
Okay, so here's my final package. I organized it this way :
plugin_panel/
|__ CMakeLists.txt
|__ package.xml
|__ plugin_description.xml
|__ include/
|__ plugin_panel.h
|__ src/
|__ plugin_panel.cpp
The plugin displays a simple dockable panel with two QPushButton
.
- CMakeLists.txt
:
cmake_minimum_required(VERSION 2.8.11)
project(plugin_panel)
find_package(catkin REQUIRED)
find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui)
include(${QT_USE_FILE})
include_directories(include/)
qt4_wrap_cpp(QT_MOC include/plugin_panel.h)
set(SOURCES src/plugin_panel.cpp ${QT_MOC})
add_library(${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES} ${catkin_LIBRARIES})
- package.xml
:
<?xml version="1.0"?>
<package>
<name>plugin_panel</name>
<version>1.0.0</version>
<description>
An additional panel in RViz.
</description>
<maintainer email="none@none.none">Matthieu</maintainer>
<license>BSD</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>rviz</build_depend>
<run_depend>rviz</run_depend>
<export>
<rviz plugin="${prefix}/plugin_description.xml"/>
</export>
</package>
- plugin_description.xml
:
<library path="lib/libplugin_panel">
<class name="plugin_panel/HelloWorld"
type="PluginPanel"
base_class_type="rviz::Panel">
<description>
An empty panel.
</description>
</class>
</library>
- include/plugin_panel.h
:
#include <QtGui>
#include <rviz/panel.h>
class PluginPanel: public rviz::Panel
{
Q_OBJECT
public:
PluginPanel(QWidget* parent = 0);
protected:
QVBoxLayout* _vbox;
QPushButton* _button1;
QPushButton* _button2;
};
- src/plugin_panel.cpp
:
#include <pluginlib/class_list_macros.h>
#include "plugin_panel.h"
PluginPanel::PluginPanel(QWidget* parent):
rviz::Panel(parent)
{
_vbox = new QVBoxLayout();
_button1 = new QPushButton(tr("Button 1"));
_button2 = new QPushButton(tr("Button 2"));
_button1->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_button2->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
_vbox->addWidget(_button1);
_vbox->addWidget(_button2);
setLayout(_vbox);
}
PLUGINLIB_EXPORT_CLASS(PluginPanel, rviz::Panel)
That's it!
That's the minimum code I found after many iterations, each time trying to remove as much thing as possible from any files.