ClusterLabelPanel.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Robot Operating System code by the University of Osnabrück
5  * Copyright (c) 2015, University of Osnabrück
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the following
14  * disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  *
21  * 3. Neither the name of the copyright holder nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
33  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
34  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
36  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  *
39  *
40  * ClusterLabelPanel.cpp
41  *
42  *
43  * authors:
44  *
45  * Kristin Schmidt <krschmidt@uni-osnabrueck.de>
46  * Jan Philipp Vogtherr <jvogtherr@uni-osnabrueck.de>
47  */
48 
49 #include <ClusterLabelPanel.hpp>
50 
51 #include <QPainter>
52 #include <QLineEdit>
53 #include <QVBoxLayout>
54 #include <QHBoxLayout>
55 #include <QLabel>
56 #include <QTimer>
57 #include <QPushButton>
58 
59 #include <rviz/tool_manager.h>
60 
61 namespace rviz_map_plugin
62 {
63 ClusterLabelPanel::ClusterLabelPanel(QWidget* parent) : rviz::Panel(parent)
64 {
65  QHBoxLayout* clusterNameLayout = new QHBoxLayout();
66  clusterNameLayout->addWidget(new QLabel("Cluster Name:"));
67  m_clusterNameEditor = new QLineEdit();
68  clusterNameLayout->addWidget(m_clusterNameEditor);
69 
70  m_createClusterButton = new QPushButton("Label Cluster");
71 
72  m_resetFacesButton = new QPushButton("Reset Faces");
73 
74  QVBoxLayout* layout = new QVBoxLayout();
75  layout->addLayout(clusterNameLayout);
76  layout->addWidget(m_createClusterButton);
77  layout->addWidget(m_resetFacesButton);
78  setLayout(layout);
79 
80  // Make signal/slot connections
81  connect(m_clusterNameEditor, SIGNAL(editingFinished()), this, SLOT(updateClusterName()));
82 
83  connect(m_createClusterButton, SIGNAL(released()), this, SLOT(publish()));
84  connect(m_resetFacesButton, SIGNAL(released()), this, SLOT(resetFaces()));
85 }
86 
88 {
89  // Check if the cluster label tool is already opened
91  QStringList toolClasses = toolManager->getToolClasses();
92  bool foundTool = false;
93  for (int i = 0; i < toolClasses.size(); i++)
94  {
95  if (toolClasses.at(i).contains("ClusterLabel"))
96  {
97  m_tool = static_cast<ClusterLabelTool*>(toolManager->getTool(i));
98  foundTool = true;
99  break;
100  }
101  }
102 
103  if (!foundTool)
104  {
105  m_tool = static_cast<ClusterLabelTool*>(vis_manager_->getToolManager()->addTool("rviz_map_plugin/ClusterLabel"));
106  }
107 }
108 
109 void ClusterLabelPanel::setClusterName(const QString& clusterName)
110 {
111  m_clusterName = clusterName;
112  Q_EMIT configChanged();
113 
114  // Gray out the create cluster button when the cluster name is empty
115  m_createClusterButton->setEnabled(m_clusterName != "");
116 }
117 
119 {
121 }
122 
124 {
125  ROS_INFO("Label Panel: Publish");
126  m_tool->publishLabel(m_clusterName.toStdString());
127 }
128 
130 {
131  ROS_INFO("Label panel: Reset");
132  m_tool->resetFaces();
133 }
134 
136 {
138  config.mapSetValue("ClusterName", m_clusterName);
139 }
140 
142 {
144  QString clusterName;
145  if (config.mapGetString("ClusterName", &clusterName))
146  ;
147  {
148  m_clusterNameEditor->setText(clusterName);
150  }
151 }
152 
153 } // End namespace rviz_map_plugin
154 
rviz::ToolManager::getToolClasses
QStringList getToolClasses()
rviz::Panel::configChanged
void configChanged()
rviz_map_plugin::ClusterLabelTool
Tool for selecting faces.
Definition: ClusterLabelTool.hpp:125
rviz::ToolManager
rviz::Panel
rviz_map_plugin::ClusterLabelPanel::m_clusterNameEditor
QLineEdit * m_clusterNameEditor
Input for entering the cluster name.
Definition: ClusterLabelPanel.hpp:128
rviz_map_plugin::ClusterLabelTool::publishLabel
void publishLabel(std::string name)
Publish a label with a given namen.
Definition: ClusterLabelTool.cpp:636
rviz_map_plugin::ClusterLabelPanel::load
virtual void load(const rviz::Config &config)
Load a configuration @input config The configuration.
Definition: ClusterLabelPanel.cpp:141
rviz_map_plugin::ClusterLabelPanel::publish
void publish()
Publishes the current cluster.
Definition: ClusterLabelPanel.cpp:123
rviz_map_plugin::ClusterLabelPanel::updateClusterName
void updateClusterName()
Updates the current cluster name.
Definition: ClusterLabelPanel.cpp:118
rviz_map_plugin::ClusterLabelPanel::save
virtual void save(rviz::Config config) const
Save a configuration @input config The configuration.
Definition: ClusterLabelPanel.cpp:135
rviz::VisualizationManager::getToolManager
ToolManager * getToolManager() const override
tool_manager.h
class_list_macros.h
rviz::ToolManager::getTool
Tool * getTool(int index)
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
rviz
rviz_map_plugin::ClusterLabelTool::resetFaces
void resetFaces()
Resets the list of selected faces.
Definition: ClusterLabelTool.cpp:723
rviz_map_plugin::ClusterLabelPanel::ClusterLabelPanel
ClusterLabelPanel(QWidget *parent=0)
Constructor.
Definition: ClusterLabelPanel.cpp:63
rviz_map_plugin::ClusterLabelPanel::m_clusterName
QString m_clusterName
Name of the cluster.
Definition: ClusterLabelPanel.hpp:133
rviz_map_plugin::ClusterLabelPanel::resetFaces
void resetFaces()
Resets the current face selection state.
Definition: ClusterLabelPanel.cpp:129
ClusterLabelPanel.hpp
rviz::ToolManager::addTool
Tool * addTool(const QString &tool_class_lookup_name)
rviz_map_plugin::ClusterLabelPanel::onInitialize
void onInitialize()
RViz callback on inizialize.
Definition: ClusterLabelPanel.cpp:87
rviz::Panel::load
virtual void load(const Config &config)
rviz_map_plugin::ClusterLabelPanel::m_createClusterButton
QPushButton * m_createClusterButton
Button for creating and publishing the cluster.
Definition: ClusterLabelPanel.hpp:136
rviz_map_plugin::ClusterLabelPanel
Panel for interacting with the label tool.
Definition: ClusterLabelPanel.hpp:75
rviz::Panel::save
virtual void save(Config config) const
rviz_map_plugin
Definition: ClusterLabelDisplay.hpp:120
rviz_map_plugin::ClusterLabelPanel::setClusterName
void setClusterName(const QString &clusterName)
Set the name under which the current cluster will be saved.
Definition: ClusterLabelPanel.cpp:109
rviz_map_plugin::ClusterLabelPanel::m_tool
ClusterLabelTool * m_tool
Instance of the label tool from this package.
Definition: ClusterLabelPanel.hpp:141
ROS_INFO
#define ROS_INFO(...)
rviz_map_plugin::ClusterLabelPanel::m_resetFacesButton
QPushButton * m_resetFacesButton
Button for resetting the current faces in cluster.
Definition: ClusterLabelPanel.hpp:138
config
config
rviz::Config
rviz::Panel::vis_manager_
VisualizationManager * vis_manager_


rviz_map_plugin
Author(s): Sebastian Pütz , Kristin Schmidt , Jan Philipp Vogtherr , Malte kleine Piening
autogenerated on Sun Jan 21 2024 04:06:25