23 #include "VirtualRobot/IK/IKSolver.h"
29 ARMARX_INFO <<
"RobotTrajectoryDesigner: WaypointController on init";
34 initValidator(-10000.000, 10000.000, 3);
37 this->guiWaypointTab->getWaypointTab()->waypointList->
38 setSelectionMode(QAbstractItemView::SingleSelection);
39 this->guiWaypointTab->getWaypointTab()->waypointList->clear();
44 ARMARX_INFO <<
"RobotTrajectoryDesigner: WaypointController on connect";
47 QObject::connect(guiWaypointTab->getWaypointTab()->waypointList,
48 SIGNAL(itemClicked(QListWidgetItem*)),
52 QObject::connect(guiWaypointTab->getWaypointTab()->xPositionLineEdit,
53 SIGNAL(editingFinished()),
54 this, SLOT(setXCoordinate()));
57 QObject::connect(guiWaypointTab->getWaypointTab()->yPositionLineEdit,
58 SIGNAL(editingFinished()),
59 this, SLOT(setYCoordinate()));
62 QObject::connect(guiWaypointTab->getWaypointTab()->zPositionLineEdit,
63 SIGNAL(editingFinished()),
64 this, SLOT(setZCoordinate()));
67 QObject::connect(guiWaypointTab->getWaypointTab()->eulerRLineEdit,
68 SIGNAL(editingFinished()),
69 this, SLOT(setEulerAngleR()));
72 QObject::connect(guiWaypointTab->getWaypointTab()->eulerPLineEdit,
73 SIGNAL(editingFinished()),
74 this, SLOT(setEulerAngleP()));
77 QObject::connect(guiWaypointTab->getWaypointTab()->eulerYLineEdit,
78 SIGNAL(editingFinished()),
79 this, SLOT(setEulerAngleY()));
82 QObject::connect(guiWaypointTab->getWaypointTab()->ikSelectionComboBox,
83 SIGNAL(activated(
int)),
84 this, SLOT(setCartesianSelection(
int)));
87 QObject::connect(guiWaypointTab->getWaypointTab()->isBreakpointCheckBox,
88 SIGNAL(clicked(
bool)),
89 this, SLOT(setBreakpoint(
bool)));
92 QObject::connect(guiWaypointTab->getWaypointTab()->insertButton,
97 QObject::connect(guiWaypointTab->getWaypointTab()->deleteButton,
104 ARMARX_INFO <<
"RobotTrajectoryDesigner: WaypointController on disconnect";
109 ARMARX_INFO <<
"RobotTrajectoryDesigner: WaypointController on exit";
113 guiWaypointTab(guiWaypointTab)
121 return this->guiWaypointTab;
126 if (guiWaypointTab != NULL)
128 this->guiWaypointTab = guiWaypointTab;
132 void WaypointController::addWaypoint(
134 std::vector<double>
values,
135 int cartesianSelection,
148 data.setValue(waypoint);
151 QListWidgetItem* item =
new QListWidgetItem(QString::fromStdString(
"Waypoint: " +
std::to_string(
index)));
152 item->setData(Qt::UserRole,
data);
153 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
155 waypoints->insertItem(
index, item);
159 if (waypoints->count() == 1)
164 changeTextListWidgetItems();
167 void WaypointController::removeWaypoint(
int index)
169 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
171 if (waypoints->count() >
index)
173 delete waypoints->takeItem(
index);
176 if (waypoints->count() == 0)
182 changeTextListWidgetItems();
190 updateWaypointElements(waypoint);
193 int row = guiWaypointTab->getWaypointTab()->waypointList->row(item);
194 guiWaypointTab->getWaypointTab()->waypointList->setCurrentRow(row);
202 QListWidgetItem* item = guiWaypointTab->getWaypointTab()->waypointList->item(
index);
206 updateWaypointElements(waypoint);
209 guiWaypointTab->getWaypointTab()->waypointList->setCurrentRow(
index);
214 void WaypointController::setXCoordinate()
217 if (guiWaypointTab->getWaypointTab()->xPositionLineEdit->hasAcceptableInput())
219 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
220 QListWidgetItem* item = waypoints->currentItem();
226 double x = guiWaypointTab->getWaypointTab()->
227 xPositionLineEdit->text().toDouble();
230 if ((waypoint.
values.size() == 6)
231 && (x != waypoint.
values[0]))
241 (
new QErrorMessage(0))->showMessage(
"Invalid input.");
245 void WaypointController::setYCoordinate()
248 if (guiWaypointTab->getWaypointTab()->yPositionLineEdit->hasAcceptableInput())
250 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
251 QListWidgetItem* item = waypoints->currentItem();
257 double y = guiWaypointTab->getWaypointTab()->
258 yPositionLineEdit->text().toDouble();
261 if ((waypoint.values.size() == 6)
262 && (y != waypoint.values[1]))
264 std::vector<double>
values = waypoint.values;
272 (
new QErrorMessage(0))->showMessage(
"Invalid input.");
276 void WaypointController::setZCoordinate()
279 if (guiWaypointTab->getWaypointTab()->zPositionLineEdit->hasAcceptableInput())
281 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
282 QListWidgetItem* item = waypoints->currentItem();
288 double z = guiWaypointTab->getWaypointTab()->
289 xPositionLineEdit->text().toDouble();
292 if ((waypoint.values.size() == 6)
293 && (z != waypoint.values[2]))
295 std::vector<double>
values = waypoint.values;
303 (
new QErrorMessage(0))->showMessage(
"Invalid Input.");
307 void WaypointController::setEulerAngleR()
310 if (guiWaypointTab->getWaypointTab()->eulerRLineEdit->hasAcceptableInput())
312 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
313 QListWidgetItem* item = waypoints->currentItem();
319 double r = guiWaypointTab->getWaypointTab()->
320 eulerRLineEdit->text().toDouble();
323 if ((waypoint.values.size() == 6)
324 && (r != waypoint.values[3]))
326 std::vector<double>
values = waypoint.values;
334 (
new QErrorMessage(0))->showMessage(
"Invalid Input.");
338 void WaypointController::setEulerAngleP()
341 if (guiWaypointTab->getWaypointTab()->eulerPLineEdit->hasAcceptableInput())
343 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
344 QListWidgetItem* item = waypoints->currentItem();
350 double p = guiWaypointTab->getWaypointTab()->
351 eulerPLineEdit->text().toDouble();
354 if ((waypoint.values.size() == 6)
355 && (p != waypoint.values[4]))
357 std::vector<double>
values = waypoint.values;
365 (
new QErrorMessage(0))->showMessage(
"Invalid Input.");
369 void WaypointController::setEulerAngleY()
372 if (guiWaypointTab->getWaypointTab()->eulerYLineEdit->hasAcceptableInput())
374 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
375 QListWidgetItem* item = waypoints->currentItem();
381 double y = guiWaypointTab->getWaypointTab()->
382 eulerYLineEdit->text().toDouble();
385 if ((waypoint.values.size() == 6)
386 && (y != waypoint.values[5]))
388 std::vector<double>
values = waypoint.values;
396 (
new QErrorMessage(0))->showMessage(
"Invalid Input.");
400 void WaypointController::setCartesianSelection(
int cs)
402 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
403 QListWidgetItem* item = waypoints->currentItem();
411 int cartesianSelection = guiWaypointTab->getWaypointTab()->
412 ikSelectionComboBox->itemData(cs, Qt::UserRole).toInt();
413 if (cartesianSelection != waypoint.cartesianSelection)
420 void WaypointController::setBreakpoint(
bool isBreakpoint)
422 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
423 QListWidgetItem* item = waypoints->currentItem();
431 if (isBreakpoint != waypoint.isBreakpoint)
440 std::vector<double>
values,
441 int cartesianSelection,
450 if (waypoint.
values.size() == 6)
454 data.setValue(waypoint);
456 QListWidget* waypoints = guiWaypointTab->getWaypointTab()->waypointList;
457 QListWidgetItem* item = waypoints->item(
index);
460 item->setData(Qt::UserRole,
data);
462 if (waypoints->currentRow() ==
index)
464 updateWaypointElements(waypoint);
470 void WaypointController::addWaypoint()
472 if (guiWaypointTab->getWaypointTab()->waypointList->count() == 0)
474 emit
addedWaypoint(guiWaypointTab->getWaypointTab()->waypointList->count(),
475 guiWaypointTab->getWaypointTab()->
476 insertAfterButton->isChecked());
478 else if (guiWaypointTab->getWaypointTab()->waypointList->currentRow() == -1)
480 emit
addedWaypoint(guiWaypointTab->getWaypointTab()->waypointList->count() - 1,
481 guiWaypointTab->getWaypointTab()->
482 insertAfterButton->isChecked());
487 waypointList->currentRow(),
488 guiWaypointTab->getWaypointTab()->
489 insertAfterButton->isChecked());
493 void WaypointController::removeWaypoint()
495 QListWidget* waypoints = this->guiWaypointTab->getWaypointTab()->waypointList;
496 if (waypoints->count() > 0)
498 int index = waypoints->currentRow();
511 this->guiWaypointTab->getWaypointTab()->waypointList->clear();
513 this->guiWaypointTab->getWaypointTab()->xPositionLineEdit->clear();
514 this->guiWaypointTab->getWaypointTab()->yPositionLineEdit->clear();
515 this->guiWaypointTab->getWaypointTab()->zPositionLineEdit->clear();
516 this->guiWaypointTab->getWaypointTab()->eulerRLineEdit->clear();
517 this->guiWaypointTab->getWaypointTab()->eulerPLineEdit->clear();
518 this->guiWaypointTab->getWaypointTab()->eulerYLineEdit->clear();
520 this->guiWaypointTab->getWaypointTab()->ikSelectionComboBox->setCurrentIndex(5);
522 this->guiWaypointTab->getWaypointTab()->isBreakpointCheckBox->setChecked(
false);
524 this->guiWaypointTab->getWaypointTab()->insertAfterButton->setChecked(
true);
525 this->guiWaypointTab->getWaypointTab()->insertBeforeButton->setChecked(
false);
532 guiWaypointTab->getWaypointTab()->deleteButton->setEnabled(enable);
533 guiWaypointTab->getWaypointTab()->ikSelectionComboBox->setEnabled(enable);
534 guiWaypointTab->getWaypointTab()->isBreakpointCheckBox->setEnabled(enable);
539 guiWaypointTab->getWaypointTab()->insertButton->setEnabled(enable);
540 guiWaypointTab->getWaypointTab()->insertAfterButton->setEnabled(enable);
541 guiWaypointTab->getWaypointTab()->insertBeforeButton->setEnabled(enable);
546 guiWaypointTab->getWaypointTab()->eulerPLineEdit->setEnabled(enable);
547 guiWaypointTab->getWaypointTab()->eulerRLineEdit->setEnabled(enable);
548 guiWaypointTab->getWaypointTab()->eulerYLineEdit->setEnabled(enable);
549 guiWaypointTab->getWaypointTab()->waypointList->setEnabled(enable);
550 guiWaypointTab->getWaypointTab()->xPositionLineEdit->setEnabled(enable);
551 guiWaypointTab->getWaypointTab()->yPositionLineEdit->setEnabled(enable);
552 guiWaypointTab->getWaypointTab()->zPositionLineEdit->setEnabled(enable);
558 void WaypointController::initCSComboBox()
560 QComboBox* cs = guiWaypointTab->getWaypointTab()->ikSelectionComboBox;
563 cs->setFocusPolicy(Qt::StrongFocus);
568 QVariant xpos(1), ypos(2), zpos(4), position(7), orientation(8),
all(15);
569 cs->addItem(QString::fromStdString(
"X Position"), xpos);
570 cs->addItem(QString::fromStdString(
"Y Position"), ypos);
571 cs->addItem(QString::fromStdString(
"Z Position"), zpos);
572 cs->addItem(QString::fromStdString(
"Position"), position);
573 cs->addItem(QString::fromStdString(
"Orientation"), orientation);
574 cs->addItem(QString::fromStdString(
"Position and Orientation"),
all);
575 cs->setEnabled(
true);
576 cs->setCurrentIndex(5);
579 void WaypointController::initValidator(
double bottom,
double top,
int decimals)
581 QDoubleValidator* validator =
new QDoubleValidator(bottom,
584 guiWaypointTab.get());
585 validator->setNotation(QDoubleValidator::StandardNotation);
587 this->guiWaypointTab->getWaypointTab()->xPositionLineEdit->
588 setValidator(validator);
589 this->guiWaypointTab->getWaypointTab()->yPositionLineEdit->
590 setValidator(validator);
591 this->guiWaypointTab->getWaypointTab()->zPositionLineEdit->
592 setValidator(validator);
593 this->guiWaypointTab->getWaypointTab()->eulerRLineEdit->setValidator(validator);
594 this->guiWaypointTab->getWaypointTab()->eulerPLineEdit->setValidator(validator);
595 this->guiWaypointTab->getWaypointTab()->eulerYLineEdit->setValidator(validator);
598 void WaypointController::updateWaypointElements(
GuiWaypoint waypoint)
600 if (waypoint.values.size() == 6)
603 guiWaypointTab->getWaypointTab()->xPositionLineEdit->
604 setText(QString::number(waypoint.values[0]));
606 guiWaypointTab->getWaypointTab()->yPositionLineEdit->
607 setText(QString::number(waypoint.values[1]));
609 guiWaypointTab->getWaypointTab()->zPositionLineEdit->
610 setText(QString::number(waypoint.values[2]));
612 guiWaypointTab->getWaypointTab()->eulerRLineEdit->
613 setText(QString::number(waypoint.values[3]));
615 guiWaypointTab->getWaypointTab()->eulerPLineEdit->
616 setText(QString::number(waypoint.values[4]));
618 guiWaypointTab->getWaypointTab()->eulerYLineEdit->
619 setText(QString::number(waypoint.values[5]));
621 guiWaypointTab->getWaypointTab()->ikSelectionComboBox->
622 setCurrentIndex(guiWaypointTab->getWaypointTab()->ikSelectionComboBox->
623 findData(QVariant(waypoint.cartesianSelection)));
625 guiWaypointTab->getWaypointTab()->isBreakpointCheckBox->
626 setChecked(waypoint.isBreakpoint);
630 void WaypointController::changeTextListWidgetItems()
632 QListWidget* waypoints = this->guiWaypointTab->getWaypointTab()->waypointList;
633 for (
int i = 0; i < waypoints->count(); i++)
635 waypoints->item(i)->setText(QString::fromStdString((
"Waypoint: " +
std::to_string(i))));