SettingController.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 RobotTrajectoryDesigner::gui-plugins::Controller::SettingController
17* \author Max Beddies
18* \date 2018
19* \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22#include "SettingController.h"
23
24#include <QFileDialog>
25
26#include <VirtualRobot/XML/RobotIO.h>
27
28#include "../KinematicSolver.h"
29
30namespace armarx
31{
32 void
34 {
35 ARMARX_INFO << "RobotTrajectoryDesigner: SettingController on init";
36
37 // Disable collision model combo box and list, import and export button
38 enableWidgets(true);
41 }
42
43 void
45 {
46 ARMARX_INFO << "RobotTrajectoryDesigner: SettingController on connect";
47
48 // Robot selection button: clicked
49 QObject::connect(guiSettingTab->getSettingTab()->robotSelectionButton,
50 SIGNAL(clicked()),
51 this,
52 SLOT(openRobotSelectionDialog()));
53
54 // Shortcut button: clicked
55 QObject::connect(guiSettingTab->getSettingTab()->shortcutButton,
56 SIGNAL(clicked()),
57 this,
58 SLOT(openShortcutDialog()));
59
60 // TCP combo box: index changed
61 QObject::connect(guiSettingTab->getSettingTab()->tcpComboBox,
62 SIGNAL(activated(int)),
63 this,
64 SLOT(selectTCP(int)));
65
66 // New IK solution button: clicked
67 QObject::connect(guiSettingTab->getSettingTab()->newIKSolutionButton,
68 SIGNAL(clicked()),
69 this,
70 SLOT(newIKSolution()));
71
72 // Active collision model changed
73 QObject::connect(guiSettingTab->getSettingTab()->collisionModelComboBox,
74 SIGNAL(activated(int)),
75 this,
76 SLOT(selectActiveCM(int)));
77
78 // Other used collision models changed
79 QObject::connect(guiSettingTab->getSettingTab()->collisionModelList,
80 SIGNAL(itemChanged(QListWidgetItem*)),
81 this,
82 SLOT(setCollisionModelList(QListWidgetItem*)));
83
84 // Export
85 QObject::connect(guiSettingTab->getSettingTab()->convertToMMMButton,
86 SIGNAL(clicked()),
87 this,
88 SLOT(convertToMMMSlot()));
89
90 // Import
91 QObject::connect(guiSettingTab->getSettingTab()->importButton,
92 SIGNAL(clicked()),
93 this,
94 SLOT(openImportDialog()));
95 }
96
97 void
99 {
100 ARMARX_INFO << "RobotTrajectoryDesigner: SettingController on disconnect";
101 }
102
103 void
105 {
106 ARMARX_INFO << "RobotTrajectoryDesigner: SettingController on exit";
107 }
108
109 SettingController::SettingController(SettingTabPtr settingTab) : guiSettingTab(settingTab)
110 {
113 }
114
117 {
118 return this->guiSettingTab;
119 }
120
121 void
123 {
124 if (guiSettingTab != NULL)
125 {
126 this->guiSettingTab = guiSettingTab;
127 }
128 }
129
130 void
131 SettingController::openRobotSelectionDialog()
132 {
133 emit openRobotSelection();
134 }
135
136 void
137 SettingController::openShortcutDialog()
138 {
139 emit openShortcut();
140 }
141
142 void
144 {
145 /*
146 * If index is valid kinematic chain, enable widgets and send signal,
147 * else disable widgets
148 */
149 if (index > 0)
150 {
151 enableWidgets(true);
152 emit changedTCP(this->guiSettingTab->getSettingTab()->tcpComboBox->currentText());
153 }
154 else
155 {
156 enableWidgets(false);
157 }
158 }
159
160 void
162 {
163 QComboBox* combobox = guiSettingTab->getSettingTab()->tcpComboBox;
164 int index = combobox->findText(tcp);
165
166 // Check if tcp is valid kinematic chain
167 if (index > 0)
168 {
169 combobox->setCurrentIndex(index);
170 }
171 }
172
173 void
174 SettingController::selectActiveCM(int index)
175 {
176 QListWidget* cmList = this->guiSettingTab->getSettingTab()->collisionModelList;
177 if (index > 0)
178 {
179 // Enable all collision model items but active collision model item
180 for (int i = 0; i < cmList->count(); i++)
181 {
182 QListWidgetItem* item = cmList->item(i);
183 if (i == (index - 1))
184 {
185 item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
186 }
187 else
188 {
189 item->setFlags(item->flags() | Qt::ItemIsEnabled);
190 }
191 }
192 cmList->setEnabled(true);
193 }
194 else
195 {
196 cmList->setEnabled(false);
197 }
199 guiSettingTab->getSettingTab()->collisionModelComboBox->itemText(index));
200 }
201
202 void
203 SettingController::setCollisionModelList(QListWidgetItem* item)
204 {
205 if (item != NULL)
206 {
207 QComboBox* tcp = guiSettingTab->getSettingTab()->tcpComboBox;
208 QComboBox* cm = guiSettingTab->getSettingTab()->collisionModelComboBox;
209
210 // Check if tcp is selected and active collision model is selected
211 if ((tcp->currentIndex() > 0) && (cm->currentIndex() > 0))
212 {
213 QListWidget* models = guiSettingTab->getSettingTab()->collisionModelList;
214 QStringList bodyCollisionModels;
215
216 // Add each checked collision model as robot node set pointer to vector
217 for (int i = 0; i < models->count(); i++)
218 {
219 if (models->item(i)->checkState() == Qt::Checked)
220 {
221 bodyCollisionModels.push_back(models->item(i)->text());
222 }
223 }
224 emit setBodyColModelsNames(bodyCollisionModels);
225 }
226 }
227 }
228
229 void
230 SettingController::exportTrajectorySlot()
231 {
232 emit exportTrajectory();
233 }
234
235 void
236 SettingController::convertToMMMSlot()
237 {
238 emit convertToMMM();
239 }
240
241 void
242 SettingController::openImportDialog()
243 {
244 emit openImport();
245 }
246
247 void
248 SettingController::setLanguage(int index)
249 {
250 /*
251 QVariant language = guiSettingTab->getSettingTab()->languageComboBox->
252 itemData(index, Qt::UserRole);
253 if (language.isValid())
254 {
255 emit changedLanguage(language.toString());
256 }
257 */
258 }
259
260 void
262 {
263 this->guiSettingTab->getSettingTab()->newIKSolutionButton->setEnabled(enable);
264 }
265
266 void
268 {
269 this->guiSettingTab->getSettingTab()->convertToMMMButton->setEnabled(enable);
270 //this->guiSettingTab->getSettingTab()->exportTrajectoryButton->setEnabled(enable);
271 }
272
273 void
275 {
276 this->guiSettingTab->getSettingTab()->collisionModelComboBox->setEnabled(enable);
277 this->guiSettingTab->getSettingTab()->collisionModelList->setEnabled(enable);
278 this->guiSettingTab->getSettingTab()->tcpComboBox->setEnabled(enable);
279 this->guiSettingTab->getSettingTab()->importButton->setEnabled(enable);
280 }
281
282 void
283 SettingController::newIKSolution()
284 {
285 VirtualRobot::RobotPtr robot = environment->getRobot();
287 VirtualRobot::RobotNodeSetPtr activeKinematicChain = robot->getRobotNodeSet(
288 guiSettingTab->getSettingTab()->tcpComboBox->currentText().toStdString());
289 std::vector<double> newJA =
290 kc->solveIK(activeKinematicChain,
291 PoseBasePtr(new Pose(activeKinematicChain->getTCP()->getGlobalPose())),
292 VirtualRobot::IKSolver::CartesianSelection::All,
293 50);
294 if (newJA.size() != 0)
295 {
296 activeKinematicChain->setJointValues(std::vector<float>(newJA.begin(), newJA.end()));
297 }
298 }
299
300 void
302 {
303 throw("not yet implemented");
304 }
305
306 void
308 {
309 guiSettingTab->getSettingTab()->robotSelectionButton->setEnabled(enable);
310 }
311
312 void
314 {
315 guiSettingTab->getSettingTab()->tcpComboBox->clear();
316 guiSettingTab->getSettingTab()->collisionModelComboBox->clear();
317 guiSettingTab->getSettingTab()->collisionModelList->clear();
318 this->environment = environment;
319 // Get robot and initialize child widgets
320 VirtualRobot::RobotPtr robot = environment->getRobot();
321 initTCPComboBox(robot);
322 initCMComboBox(robot);
323 initCMList(robot);
324 }
325
326 /************************************************************************************/
327 /* Private functions */
328 /************************************************************************************/
329 void
330 SettingController::enableWidgets(bool enable)
331 {
332 this->guiSettingTab->getSettingTab()->collisionModelComboBox->setEnabled(enable);
333 this->guiSettingTab->getSettingTab()->collisionModelList->setEnabled(enable);
334 //Man kann auch importieren ohne einen TCP ausgewählt zu haben.
335 //this->guiSettingTab->getSettingTab()->importButton->setEnabled(enable);
336 }
337
338 void
339 SettingController::initTCPComboBox(VirtualRobot::RobotPtr robot)
340 {
341 QComboBox* tcpComboBox = this->guiSettingTab->getSettingTab()->tcpComboBox;
342
343 // Set strong focus and add wheel event filter
344 tcpComboBox->setFocusPolicy(Qt::StrongFocus);
345 tcpComboBox->installEventFilter(new WheelEventFilter(this));
346
347 if (robot)
348 {
349 tcpComboBox->clear();
350
351 // Combo box item at first index is no rns
352 tcpComboBox->insertItem(0, QString::fromStdString("- select -"));
353
354 auto robotNodeSets = robot->getRobotNodeSets();
355
356 // Add combo box item for each robot node set
357 for (VirtualRobot::RobotNodeSetPtr s : robotNodeSets)
358 {
359 if ((s->isKinematicChain()) && (s->getTCP() != NULL))
360 {
361 ARMARX_DEBUG << "Add item " << s->getName() << " to tcp combo box";
362 tcpComboBox->addItem(QString::fromStdString(s->getName()));
363 }
364 }
365 tcpComboBox->setEnabled(true);
366 tcpComboBox->setCurrentIndex(0);
367 }
368 else
369 {
370 // Error message? Or just label in red etc?
371 tcpComboBox->setEnabled(false);
372 }
373 }
374
375 void
376 SettingController::initCMComboBox(VirtualRobot::RobotPtr robot)
377 {
378 QComboBox* cmComboBox = this->guiSettingTab->getSettingTab()->collisionModelComboBox;
379
380 // Set strong focus and add wheel event filter
381 cmComboBox->setFocusPolicy(Qt::StrongFocus);
382 cmComboBox->installEventFilter(new WheelEventFilter(this));
383
384 if (robot)
385 {
386 cmComboBox->clear();
387
388 // Combo box item at first index is no collision model
389 cmComboBox->insertItem(0, QString::fromStdString("- select -"));
390
391 auto robotNodeSets = robot->getRobotNodeSets();
392
393 // Add combo box item for each robot node set (collision model)
394 for (VirtualRobot::RobotNodeSetPtr s : robotNodeSets)
395 {
396 if (s->isKinematicChain())
397 {
398 ARMARX_DEBUG << "Add item " << s->getName() << " to collision model combo box";
399 cmComboBox->addItem(QString::fromStdString(s->getName()));
400 }
401 }
402 cmComboBox->setCurrentIndex(0);
403 }
404 else
405 {
406 // Error message? Or just label in red etc?
407 cmComboBox->setEnabled(false);
408 }
409 }
410
411 void
412 SettingController::initCMList(VirtualRobot::RobotPtr robot)
413 {
414 QListWidget* cmList = this->guiSettingTab->getSettingTab()->collisionModelList;
415 if (robot)
416 {
417 cmList->clear();
418
419 auto robotNodeSets = robot->getRobotNodeSets();
420
421 for (VirtualRobot::RobotNodeSetPtr s : robotNodeSets)
422 {
423 if (s->isKinematicChain())
424 {
425 QListWidgetItem* item =
426 new QListWidgetItem(QString::fromStdString(s->getName()));
427 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
428 item->setCheckState(Qt::Unchecked);
429 ARMARX_DEBUG << "Add item " << s->getName() << " to collision model list";
430 cmList->addItem(item);
431 }
432 }
433 }
434 else
435 {
436 // Error message? Or just label in red etc?
437 cmList->setEnabled(false);
438 }
439 }
440
441} // namespace armarx
uint8_t index
std::shared_ptr< SettingTab > SettingTabPtr
Definition SettingTab.h:54
static std::shared_ptr< KinematicSolver > getInstance(VirtualRobot::ScenePtr scenario, VirtualRobot::RobotPtr robot)
SINGLETON-FEATURES///////////////////////////////////////////////////////////////////////////////////...
The Pose class.
Definition Pose.h:243
void environmentChanged(EnvironmentPtr environment)
Set the enviroment.
void setActiveColModelName(QString activeColModelName)
Sets the active collision model name.
void enableIKSolutionButton(bool enable)
Enables or disables the new IK solution button.
void enableImportTCPCollision(bool enable)
Enables or disables the import, tcp and collision buttons.
void retranslateGui()
Retranslates the guiSettingTab.
void changedTCP(QString tcp)
Notifies other controllers about a change of the current TCP.
void onDisconnectComponent() override
void enableExportButtons(bool enable)
Enables or disables the export buttons.
void openImport()
Notifies other controllers to open an import dialog.
void convertToMMM()
Notifies other controllers to convert all trajectories to MMM.
void exportTrajectory()
Notifies other controllers to export all trajectories to Trajectory.
SettingTabPtr getGuiSettingTab()
Getter for the SettingTab pointer to guiSettingTab.
void enableSelectRobotButton(bool enable)
SettingController(SettingTabPtr guiSettingTab)
Creates a new SettingController and assigns a SettingTab to handle.
void setBodyColModelsNames(QStringList bodyColModelsNames)
Sets the body collision models names.
void setGuiSettingTab(SettingTabPtr guiSettingTab)
Setter for the SettingTab pointer to guiSettingTab.
void openRobotSelection()
Notifies other controllers to open a robot selection dialog.
void openShortcut()
Notifies other controllers to open a shortcut dialog.
void selectTCP(int index)
Changes the currently selected TCP.
#define ARMARX_INFO
The normal logging level.
Definition Logging.h:181
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
double s(double t, double s0, double v0, double a0, double j)
Definition CtrlUtil.h:33
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< KinematicSolver > KinematicSolverPtr
std::shared_ptr< Environment > EnvironmentPtr
Definition Environment.h:29