GCC Code Coverage Report


Directory: plugins/
File: plugins/hppwidgetsplugin/twojointsconstraint.cc
Date: 2024-12-13 15:51:58
Exec Total Coverage
Lines: 0 155 0.0%
Branches: 0 400 0.0%

Line Branch Exec Source
1 //
2 // Copyright (c) CNRS
3 // Authors: Joseph Mirabel
4 //
5
6 #include "twojointsconstraint.hh"
7
8 #include <gepetto/viewer/node.h>
9 #include <omniORB4/CORBA.h>
10
11 #include <QCheckBox>
12 #include <QComboBox>
13 #include <QFormLayout>
14 #include <QMessageBox>
15 #include <QString>
16 #include <QWidget>
17 #include <gepetto/gui/mainwindow.hh>
18
19 #include "hppwidgetsplugin/transformconstraintwidget.hh"
20
21 namespace hpp {
22 namespace gui {
23 ATwoJointConstraint::ATwoJointConstraint(HppWidgetsPlugin* plugin) {
24 plugin_ = plugin;
25 widget_ = new QWidget;
26 QFormLayout* layout = new QFormLayout(widget_);
27 firstJoint_ = new QComboBox(widget_);
28 secondJoint_ = new QComboBox(widget_);
29 globalFirst_ = new QCheckBox(widget_);
30 globalSecond_ = new QCheckBox(widget_);
31
32 layout->addRow(new QLabel("First Joint"), firstJoint_);
33 layout->addRow(NULL, globalFirst_);
34 layout->addRow(new QLabel("Second Joint"), secondJoint_);
35 layout->addRow(NULL, globalSecond_);
36
37 connect(firstJoint_, SIGNAL(currentIndexChanged(int)),
38 SLOT(firstJointSelect(int)));
39 connect(globalFirst_, SIGNAL(toggled(bool)), SLOT(globalSelected(bool)));
40 connect(globalFirst_, SIGNAL(toggled(bool)), firstJoint_,
41 SLOT(setDisabled(bool)));
42 connect(globalSecond_, SIGNAL(toggled(bool)), secondJoint_,
43 SLOT(setDisabled(bool)));
44 }
45
46 ATwoJointConstraint::~ATwoJointConstraint() { delete widget_; }
47
48 void ATwoJointConstraint::firstJointSelect(int index) {
49 secondJoint_->clear();
50 for (CORBA::ULong i = 0; i < joints_->length(); i++) {
51 if (int(i) != index) secondJoint_->addItem(joints_[i].in());
52 }
53 }
54
55 void ATwoJointConstraint::globalSelected(bool action) {
56 if (action) {
57 firstJointSelect(-1);
58 } else {
59 firstJointSelect(firstJoint_->currentIndex());
60 }
61 }
62
63 void ATwoJointConstraint::reload() {
64 joints_ = plugin_->client()->robot()->getAllJointNames();
65 firstJoint_->clear();
66 for (unsigned i = 0; i < joints_->length(); ++i) {
67 firstJoint_->addItem(joints_[i].in());
68 }
69 }
70
71 QWidget* ATwoJointConstraint::getWidget() const { return widget_; }
72
73 PositionConstraint::PositionConstraint(HppWidgetsPlugin* plugin)
74 : ATwoJointConstraint(plugin) {
75 plugin_ = plugin;
76 }
77
78 PositionConstraint::~PositionConstraint() {}
79
80 QString PositionConstraint::getName() const { return "Position"; }
81
82 void PositionConstraint::operator()(QString const& name) {
83 QString firstJoint =
84 (firstJoint_->isEnabled()) ? firstJoint_->currentText() : "";
85 QString secondJoint =
86 (secondJoint_->isEnabled()) ? secondJoint_->currentText() : "";
87
88 if (firstJoint == secondJoint) {
89 QMessageBox::information(NULL, "hpp-gui",
90 "You have to select two different joints");
91 return;
92 }
93 TransformConstraintWidget* tcw =
94 new TransformConstraintWidget(firstJoint, secondJoint, true, false, true);
95
96 connect(
97 tcw, SIGNAL(finished(std::pair<QVector<double>, QVector<bool> >)),
98 SLOT(getPositionConstraint(std::pair<QVector<double>, QVector<bool> >)));
99 tcw->show();
100 name_ = name;
101 firstJointName_ = firstJoint;
102 secondJointName_ = secondJoint;
103 }
104
105 void PositionConstraint::getPositionConstraint(
106 std::pair<QVector<double>, QVector<bool> > result) {
107 hpp::floatSeq_var first = new hpp::floatSeq;
108 hpp::floatSeq_var second = new hpp::floatSeq;
109 hpp::boolSeq_var boolSeq = new hpp::boolSeq;
110
111 first->length(3);
112 second->length(3);
113 boolSeq->length(3);
114 first[0] = result.first[0];
115 first[1] = result.first[1];
116 first[2] = result.first[2];
117 second[0] = result.first[3];
118 second[1] = result.first[4];
119 second[2] = result.first[5];
120 boolSeq[0] = result.second[0];
121 boolSeq[1] = result.second[1];
122 boolSeq[2] = result.second[2];
123
124 plugin_->client()->problem()->createPositionConstraint(
125 to_corba(name_), to_corba(firstJointName_), to_corba(secondJointName_),
126 first.in(), second.in(), boolSeq.in());
127 emit constraintCreated(name_);
128 emit finished();
129 }
130
131 OrientationConstraint::OrientationConstraint(HppWidgetsPlugin* plugin)
132 : ATwoJointConstraint(plugin) {
133 plugin_ = plugin;
134 }
135
136 OrientationConstraint::~OrientationConstraint() {}
137
138 QString OrientationConstraint::getName() const { return "Orientation"; }
139
140 void OrientationConstraint::getOrientationConstraint(
141 std::pair<QVector<double>, QVector<bool> > result) {
142 QVector3D vec3d((float)result.first[0], (float)result.first[1],
143 (float)result.first[2]);
144 QQuaternion qtQuat;
145 hpp::Quaternion__var quat = new hpp::Quaternion_;
146 hpp::boolSeq_var boolSeq = new hpp::boolSeq;
147
148 if (!vec3d.isNull()) {
149 qtQuat = QQuaternion::fromAxisAndAngle(vec3d.normalized(), vec3d.length());
150 const float theta = (float)vec3d.length();
151 qtQuat =
152 QQuaternion(std::cos(theta / 2), std::sin(theta / 2) * vec3d / theta);
153 }
154
155 boolSeq->length(3);
156 quat.inout()[0] = qtQuat.scalar();
157 quat.inout()[1] = qtQuat.x();
158 quat.inout()[2] = qtQuat.y();
159 quat.inout()[3] = qtQuat.z();
160 boolSeq[0] = result.second[0];
161 boolSeq[1] = result.second[1];
162 boolSeq[2] = result.second[2];
163
164 plugin_->client()->problem()->createOrientationConstraint(
165 to_corba(name_), to_corba(firstJoint_->currentText()),
166 to_corba(secondJoint_->currentText()), quat.in(), boolSeq.in());
167 emit constraintCreated(name_);
168 emit finished();
169 }
170
171 void OrientationConstraint::operator()(QString const& name) {
172 QString firstJoint =
173 (firstJoint_->isEnabled()) ? firstJoint_->currentText() : "";
174 QString secondJoint =
175 (secondJoint_->isEnabled()) ? secondJoint_->currentText() : "";
176
177 if (firstJoint == secondJoint) {
178 QMessageBox::information(NULL, "hpp-gui",
179 "You have to select two different joints");
180 return;
181 }
182
183 TransformConstraintWidget* tcw =
184 new TransformConstraintWidget(firstJoint, secondJoint, false, true);
185
186 connect(tcw, SIGNAL(finished(std::pair<QVector<double>, QVector<bool> >)),
187 SLOT(getOrientationConstraint(
188 std::pair<QVector<double>, QVector<bool> >)));
189 tcw->show();
190 name_ = name;
191 firstJointName_ = firstJoint;
192 secondJointName_ = secondJoint;
193 }
194
195 TransformConstraint::TransformConstraint(HppWidgetsPlugin* plugin)
196 : ATwoJointConstraint(plugin) {
197 plugin_ = plugin;
198 }
199
200 TransformConstraint::~TransformConstraint() {}
201
202 QString TransformConstraint::getName() const { return "Transformation"; }
203
204 void TransformConstraint::getTransformConstraint(
205 std::pair<QVector<double>, QVector<bool> > result) {
206 QVector3D vec3d((float)result.first[3], (float)result.first[4],
207 (float)result.first[5]);
208 QQuaternion qtQuat;
209 hpp::Transform__var trans = new hpp::Transform_;
210 hpp::boolSeq_var boolSeq = new hpp::boolSeq;
211
212 if (!vec3d.isNull()) {
213 qtQuat = QQuaternion::fromAxisAndAngle(vec3d.normalized(), vec3d.length());
214 const float theta = (float)vec3d.length();
215 qtQuat =
216 QQuaternion(std::cos(theta / 2), std::sin(theta / 2) * vec3d / theta);
217 }
218
219 boolSeq->length(6);
220 trans.inout()[0] = result.first[0];
221 trans.inout()[1] = result.first[1];
222 trans.inout()[2] = result.first[2];
223 trans.inout()[3] = qtQuat.scalar();
224 trans.inout()[4] = qtQuat.x();
225 trans.inout()[5] = qtQuat.y();
226 trans.inout()[6] = qtQuat.z();
227 boolSeq[0] = result.second[0];
228 boolSeq[1] = result.second[1];
229 boolSeq[2] = result.second[2];
230 boolSeq[3] = result.second[3];
231 boolSeq[4] = result.second[4];
232 boolSeq[5] = result.second[5];
233
234 plugin_->client()->problem()->createTransformationConstraint(
235 to_corba(name_), to_corba(firstJointName_), to_corba(secondJointName_),
236 trans.in(), boolSeq.in());
237 emit constraintCreated(name_);
238 emit finished();
239 }
240
241 void TransformConstraint::operator()(QString const& name) {
242 QString firstJoint =
243 (firstJoint_->isEnabled()) ? firstJoint_->currentText() : "";
244 QString secondJoint =
245 (secondJoint_->isEnabled()) ? secondJoint_->currentText() : "";
246
247 if (firstJoint == secondJoint) {
248 QMessageBox::information(NULL, "hpp-gui",
249 "You have to select two different joints");
250 return;
251 }
252
253 TransformConstraintWidget* tcw =
254 new TransformConstraintWidget(firstJoint, secondJoint, true, true);
255
256 connect(
257 tcw, SIGNAL(finished(std::pair<QVector<double>, QVector<bool> >)),
258 SLOT(getTransformConstraint(std::pair<QVector<double>, QVector<bool> >)));
259 tcw->show();
260 name_ = name;
261 firstJointName_ = firstJoint;
262 secondJointName_ = secondJoint;
263 }
264 } // namespace gui
265 } // namespace hpp
266