DebugDrawerGuiPluginWidgetController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * \package RobotAPI::gui-plugins::DebugDrawerGuiPluginWidgetController
17  * \author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * \date 2019
19  * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 #include <string>
26 
27 #include <Ice/UUID.h>
28 
29 #include <VirtualRobot/MathTools.h>
30 
32 
33 namespace armarx
34 {
36  _layerName{Ice::generateUUID()}, _debugDrawer{_layerName}
37  {
39  _ui.setupUi(getWidget());
40  connect(_ui.pushButtonLayerClear,
41  SIGNAL(clicked()),
42  this,
43  SLOT(on_pushButtonLayerClear_clicked()));
44  connect(_ui.pushButtonPoseDelete,
45  SIGNAL(clicked()),
46  this,
47  SLOT(on_pushButtonPoseDelete_clicked()));
48  connect(_ui.pushButtonArrowDelete,
49  SIGNAL(clicked()),
50  this,
51  SLOT(on_pushButtonArrowDelete_clicked()));
52 
53  connect(_ui.doubleSpinBoxPoseTX, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
54  connect(_ui.doubleSpinBoxPoseTY, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
55  connect(_ui.doubleSpinBoxPoseTZ, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
56  connect(_ui.doubleSpinBoxPoseRX, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
57  connect(_ui.doubleSpinBoxPoseRY, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
58  connect(_ui.doubleSpinBoxPoseRZ, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
59  connect(_ui.doubleSpinBoxPoseScale, SIGNAL(valueChanged(double)), this, SLOT(updatePose()));
60 
61  connect(_ui.doubleSpinBoxArrowFX, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
62  connect(_ui.doubleSpinBoxArrowFY, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
63  connect(_ui.doubleSpinBoxArrowFZ, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
64  connect(_ui.doubleSpinBoxArrowTX, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
65  connect(_ui.doubleSpinBoxArrowTY, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
66  connect(_ui.doubleSpinBoxArrowTZ, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
67  connect(
68  _ui.doubleSpinBoxArrowClrR, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
69  connect(
70  _ui.doubleSpinBoxArrowClrG, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
71  connect(
72  _ui.doubleSpinBoxArrowClrB, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
73  connect(
74  _ui.doubleSpinBoxArrowClrA, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
75  connect(
76  _ui.doubleSpinBoxArrowWidth, SIGNAL(valueChanged(double)), this, SLOT(updateArrow()));
77  }
78 
80  {
81  }
82 
83  void
85  {
86  }
87 
88  void
90  {
91  }
92 
93  void
95  {
97  offeringTopic(_debugDrawerTopicName);
98  }
99 
100  void
102  {
103  ARMARX_TRACE;
104  _debugDrawer.setDebugDrawer(getTopic<DebugDrawerInterfacePrx>(_debugDrawerTopicName));
105  }
106 
107  void
109  {
110  _debugDrawer.clearLayer();
111  }
112 
113  void
114  DebugDrawerGuiPluginWidgetController::on_pushButtonArrowDelete_clicked()
115  {
116  const auto name = _ui.lineEditArrowName->text().toStdString();
117  ARMARX_INFO << "Delete arrow " << name;
118  _debugDrawer.getDebugDrawer()->removePoseVisu(_layerName, name);
119  }
120 
121  void
122  DebugDrawerGuiPluginWidgetController::on_pushButtonPoseDelete_clicked()
123  {
124  const auto name = _ui.lineEditPoseName->text().toStdString();
125  ARMARX_INFO << "Delete pose " << name;
126  _debugDrawer.getDebugDrawer()->removePoseVisu(_layerName, name);
127  }
128 
129  void
130  DebugDrawerGuiPluginWidgetController::on_pushButtonLayerClear_clicked()
131  {
132  _debugDrawer.clearLayer();
133  }
134 
135  void
136  DebugDrawerGuiPluginWidgetController::updatePose()
137  {
138  const auto name = _ui.lineEditPoseName->text().toStdString();
139  ARMARX_INFO << "Updated pose " << name;
140 
141  const float deg2rad = M_PI / 360;
142 
143  _debugDrawer.drawPose(
144  name,
145  VirtualRobot::MathTools::posrpy2eigen4f(_ui.doubleSpinBoxPoseTX->value(),
146  _ui.doubleSpinBoxPoseTY->value(),
147  _ui.doubleSpinBoxPoseTZ->value(),
148  _ui.doubleSpinBoxPoseRX->value() * deg2rad,
149  _ui.doubleSpinBoxPoseRY->value() * deg2rad,
150  _ui.doubleSpinBoxPoseRZ->value() * deg2rad),
151  _ui.doubleSpinBoxPoseScale->value());
152  }
153 
154  void
155  DebugDrawerGuiPluginWidgetController::updateArrow()
156  {
157  const Eigen::Vector3f from{static_cast<float>(_ui.doubleSpinBoxArrowFX->value()),
158  static_cast<float>(_ui.doubleSpinBoxArrowFY->value()),
159  static_cast<float>(_ui.doubleSpinBoxArrowFZ->value())};
160 
161  const Eigen::Vector3f to{static_cast<float>(_ui.doubleSpinBoxArrowTX->value()),
162  static_cast<float>(_ui.doubleSpinBoxArrowTY->value()),
163  static_cast<float>(_ui.doubleSpinBoxArrowTZ->value())};
164 
165  const Eigen::Vector3f dir = to - from;
166 
167  const float len = dir.norm();
168 
169  const auto name = _ui.lineEditArrowName->text().toStdString();
170  ARMARX_INFO << "Updated arrow " << name;
171 
172  _debugDrawer.drawArrow(name,
173  from,
174  dir.normalized(),
175  {static_cast<float>(_ui.doubleSpinBoxArrowClrR->value()),
176  static_cast<float>(_ui.doubleSpinBoxArrowClrG->value()),
177  static_cast<float>(_ui.doubleSpinBoxArrowClrB->value()),
178  static_cast<float>(_ui.doubleSpinBoxArrowClrA->value())},
179  len,
180  static_cast<float>(_ui.doubleSpinBoxArrowWidth->value()));
181  }
182 } // namespace armarx
armarx::DebugDrawerGuiPluginWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: DebugDrawerGuiPluginWidgetController.cpp:108
armarx::DebugDrawerHelper::setDebugDrawer
void setDebugDrawer(const DebugDrawerInterfacePrx &drawer)
Definition: DebugDrawerHelper.cpp:479
armarx::DebugDrawerHelper::clearLayer
void clearLayer()
Definition: DebugDrawerHelper.cpp:390
trace.h
armarx::detail::DebugDrawerHelper::FrameView::drawPose
void drawPose(const std::string &name, const Eigen::Matrix4f &pose)
Definition: DebugDrawerHelper.cpp:114
armarx::DebugDrawerGuiPluginWidgetController::~DebugDrawerGuiPluginWidgetController
virtual ~DebugDrawerGuiPluginWidgetController()
Definition: DebugDrawerGuiPluginWidgetController.cpp:79
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
armarx::DebugDrawerGuiPluginWidgetController::onConnectComponent
void onConnectComponent() override
Pure virtual hook for the subclass.
Definition: DebugDrawerGuiPluginWidgetController.cpp:101
M_PI
#define M_PI
Definition: MathTools.h:17
DebugDrawerGuiPluginWidgetController.h
armarx::DebugDrawerGuiPluginWidgetController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: DebugDrawerGuiPluginWidgetController.cpp:94
armarx::DebugDrawerHelper::getDebugDrawer
const DebugDrawerInterfacePrx & getDebugDrawer() const
Definition: DebugDrawerHelper.cpp:473
armarx::DebugDrawerGuiPluginWidgetController::DebugDrawerGuiPluginWidgetController
DebugDrawerGuiPluginWidgetController()
Definition: DebugDrawerGuiPluginWidgetController.cpp:35
armarx::DebugDrawerGuiPluginWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: DebugDrawerGuiPluginWidgetController.cpp:84
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
armarx::detail::DebugDrawerHelper::FrameView::drawArrow
void drawArrow(const std::string &name, const Eigen::Vector3f &pos, const Eigen::Vector3f &direction, const DrawColor &color, float length, float width)
Definition: DebugDrawerHelper.cpp:169
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DebugDrawerGuiPluginWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: DebugDrawerGuiPluginWidgetController.cpp:89