36 #include <VirtualRobot/XML/RobotIO.h>
37 #include <VirtualRobot/CollisionDetection/CollisionModel.h>
42 #include <QPushButton>
47 #include <Inventor/SoDB.h>
48 #include <Inventor/Qt/SoQt.h>
63 #define ROBOTSTATE_NAME_DEFAULT "RobotStateComponent"
80 "Joint Configuration",
81 "Framed Position (TCP)",
82 "Framed Orientation (TCP)",
88 addWidget<RobotViewerWidgetController>();
95 , timerSensor(nullptr)
96 , debugLayerVisu(nullptr)
101 QComboBox* outputTypes =
ui.outputTypeComboBox;
105 outputTypes->addItem(typeName);
107 outputTypes->setCurrentIndex(0);
113 bool createDebugDrawer =
true;
126 if (createDebugDrawer)
128 std::string debugDrawerComponentName =
"RobotViewerGUIDebugDrawer_" +
getName();
129 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
146 std::unique_lock lock(*
mutex3D);
169 Ice::StringSeq includePaths;
179 for (
const std::string& projectName : packages)
181 if (projectName.empty())
187 auto pathsString =
project.getDataDir();
188 ARMARX_VERBOSE <<
"Data paths of ArmarX package " << projectName <<
": " << pathsString;
189 Ice::StringSeq projectIncludePaths =
Split(pathsString,
";,",
true,
true);
190 ARMARX_VERBOSE <<
"Result: Data paths of ArmarX package " << projectName <<
": " << projectIncludePaths;
191 includePaths.insert(includePaths.end(), projectIncludePaths.begin(), projectIncludePaths.end());
207 ARMARX_INFO <<
"Loading robot from file " << rfile;
208 robot = loadRobotFile(rfile);
224 std::cout <<
"returning" << std::endl;
232 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
241 ui.kinematicChainComboBox->addItem(
"<All Nodes>");
245 ui.kinematicChainComboBox->addItem(QString::fromStdString(nodeSetName));
247 ui.kinematicChainComboBox->setCurrentIndex(0);
248 ui.tcpComboBox->addItem(
"<default>");
249 for (
auto& node : sharedRobot->getRobotNodes())
251 ui.tcpComboBox->addItem(QString::fromStdString(node));
253 ui.tcpComboBox->setCurrentIndex(0);
255 ui.frameComboBox->addItem(
"<Global>");
259 ui.frameComboBox->addItem(QString::fromStdString(nodeName));
261 ui.frameComboBox->setCurrentIndex(0);
276 SoSensorManager* sensor_mgr = SoDB::getSensorManager();
280 ARMARX_INFO <<
"Disconnecting component: timer stopped";
285 std::unique_lock lock(*
mutex3D);
289 ARMARX_INFO <<
"Disconnecting component: removing visu";
295 ARMARX_INFO <<
"Disconnecting component: finished";
304 std::unique_lock lock(*
mutex3D);
345 return qobject_cast<SimpleConfigDialog*>(dialog);
360 bool showRob = settings->value(
"showRobot", QVariant(
true)).toBool();
361 bool fullMod = settings->value(
"fullModel", QVariant(
true)).toBool();
362 ui.cbRobot->setChecked(showRob);
363 ui.radioButtonFull->setChecked(fullMod);
364 ui.radioButtonCol->setChecked(!fullMod);
370 settings->setValue(
"showRobot",
ui.cbRobot->isChecked());
371 settings->setValue(
"fullModel",
ui.radioButtonFull->isChecked());
383 std::unique_lock lock(*
mutex3D);
385 VirtualRobot::SceneObject::VisualizationType
v = VirtualRobot::SceneObject::Full;
389 v = VirtualRobot::SceneObject::Collision;
394 if (robotViewerVisualization)
396 robotVisu->addChild(robotViewerVisualization->getCoinVisualization());
426 std::string poseName(
"root");
447 std::unique_lock lock(*
mutex3D);
480 connect(
ui.cbDebugLayer, SIGNAL(toggled(
bool)),
this, SLOT(
showVisuLayers(
bool)), Qt::QueuedConnection);
481 connect(
ui.cbRoot, SIGNAL(toggled(
bool)),
this, SLOT(
showRoot(
bool)), Qt::QueuedConnection);
482 connect(
ui.cbRobot, SIGNAL(toggled(
bool)),
this, SLOT(
showRobot(
bool)), Qt::QueuedConnection);
483 connect(
ui.radioButtonCol, SIGNAL(toggled(
bool)),
this, SLOT(
colModel(
bool)), Qt::QueuedConnection);
484 connect(
ui.radioButtonFull, SIGNAL(toggled(
bool)),
this, SLOT(
colModel(
bool)), Qt::QueuedConnection);
485 connect(
ui.horizontalSliderCollisionModelInflation, SIGNAL(sliderMoved(
int)),
this, SLOT(
inflateCollisionModel(
int)), Qt::QueuedConnection);
488 connect(
ui.kinematicChainComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
updateStateSettings(
int)));
490 connect(
ui.outputTypeComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
updateStateSettings(
int)));
491 connect(
ui.copyToClipboardButton, SIGNAL(clicked()),
this, SLOT(
copyToClipboard()));
504 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
507 robot = RobotIO::loadRobot(fileName);
511 ARMARX_INFO <<
"Could not find Robot XML file with name " << fileName;
522 if (
ui.radioButtonCol->isChecked())
526 ui.horizontalSliderCollisionModelInflation->setEnabled(
ui.radioButtonCol->isChecked());
538 QClipboard* clipboard = QApplication::clipboard();
541 QString currentText =
ui.previewTextBox->document()->toPlainText();
542 clipboard->setText(currentText);
551 VirtualRobot::RobotNodeSetPtr
const& robotNodeSet)
555 writer.startObject();
559 for (RobotNodePtr
const& node : *robotNodeSet)
561 writer.writeKey(node->getName());
562 writer.writeRawValue(
to_string(node->getJointValue()));
567 for (RobotNodePtr
const& node : robot.getRobotNodes())
569 if (node->isRotationalJoint() || node->isTranslationalJoint())
571 writer.writeKey(node->getName());
572 writer.writeRawValue(
to_string(node->getJointValue()));
578 return writer.toString();
581 template <
typename FrameType>
582 static std::string writeFramedTCP(
VirtualRobot::RobotPtr const& robot, VirtualRobot::RobotNodeSetPtr
const& nodeSet, std::string
const& frameName,
const std::string& tcpName)
586 auto tcp = tcpName.empty() ? nodeSet->getTCP() : robot->getRobotNode(tcpName);
589 position->changeFrame(robot, frameName);
593 return object->asString(
true);
608 std::string kinematicChainName =
ui.kinematicChainComboBox->currentText().toStdString();
609 VirtualRobot::RobotNodeSetPtr robotNodeSet;
610 if (
ui.kinematicChainComboBox->currentIndex() > 0)
612 robotNodeSet =
robot->getRobotNodeSet(kinematicChainName);
615 std::string frameName =
ui.frameComboBox->currentText().toStdString();
616 if (
ui.frameComboBox->currentIndex() <= 0)
618 frameName =
"Global";
621 int selectedOutputType =
ui.outputTypeComboBox->currentIndex();
629 const char* oldLocale = std::setlocale(LC_ALL,
"en_US.UTF-8");
630 std::string tcpName =
ui.tcpComboBox->currentIndex() == 0 ?
"" :
ui.tcpComboBox->currentText().toStdString();
635 output = writeJointConfigurationToJson(*
robot, robotNodeSet);
639 output = writeFramedTCP<FramedPosition>(
robot, robotNodeSet, frameName, tcpName);
643 output = writeFramedTCP<FramedOrientation>(
robot, robotNodeSet, frameName, tcpName);
647 output = writeFramedTCP<FramedPose>(
robot, robotNodeSet, frameName, tcpName);
651 ARMARX_ERROR <<
"Output type not supported: " << outputType;
655 QString jsonOutput = QString::fromStdString(output);
656 QPlainTextEdit* previewTextBox =
ui.previewTextBox;
657 QTextDocument* document = previewTextBox->document();
658 if (document->toPlainText() != jsonOutput)
660 QScrollBar* scrollBar = previewTextBox->verticalScrollBar();
661 int oldScrollValue = scrollBar->value();
663 document->setPlainText(jsonOutput);
665 int newScrollValue =
std::min(oldScrollValue, scrollBar->maximum());
666 scrollBar->setValue(newScrollValue);
669 std::setlocale(LC_ALL, oldLocale);
674 if (
ui.autoUpdateCheckBox->isChecked())
682 std::unique_lock lock(*
mutex3D);
700 QString roboInfo(
"Robot Pose (global): pos: ");
701 roboInfo += QString::number(gp(0, 3),
'f', 2);
702 roboInfo += QString(
", ");
703 roboInfo += QString::number(gp(1, 3),
'f', 2);
704 roboInfo += QString(
", ");
705 roboInfo += QString::number(gp(2, 3),
'f', 2);
706 roboInfo += QString(
", rot:");
708 VirtualRobot::MathTools::eigen4f2rpy(gp, rpy);
709 roboInfo += QString::number(rpy(0),
'f', 2);
710 roboInfo += QString(
", ");
711 roboInfo += QString::number(rpy(1),
'f', 2);
712 roboInfo += QString(
", ");
713 roboInfo += QString::number(rpy(2),
'f', 2);
714 ui.leRobotInfo->setText(roboInfo);
721 std::unique_lock lock(*
mutex3D);
723 for (
auto& model :
robot->getCollisionModels())
725 model->inflateModel(inflationValueMM);
727 ui.label_collisionModelInflationValue->setText(QString::number(inflationValueMM) +
" mm");
744 std::unique_lock lock(*mutex3D);
745 if (!robotStateComponentPrx || !robot)
751 if (!robot->getGlobalPose().isApprox(newPose))
753 robot->setGlobalPose(newPose);
759 std::unique_lock lock(*mutex3D);
761 if (!robotStateComponentPrx || !robot || !aValueChanged)