43#include <Inventor/Qt/SoQt.h>
44#include <Inventor/SoDB.h>
45#include <Inventor/nodes/SoUnits.h>
57#include <SimoxUtility/math/convert/pos_rpy_to_mat4f.h>
58#include <VirtualRobot/Grasping/Grasp.h>
59#include <VirtualRobot/Grasping/GraspSet.h>
60#include <VirtualRobot/ManipulationObject.h>
61#include <VirtualRobot/MathTools.h>
62#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
63#include <VirtualRobot/XML/ObjectIO.h>
64#include <VirtualRobot/XML/RobotIO.h>
69#define DEFAULT_SETTINGS_SIMULATOR_PROXY_NAME "Simulator"
70#define DEFAULT_SETTINGS_SIMULATORVIEWER_PROXY_NAME "SimulatorViewer_SimulationWindow"
71#define DEFAULT_SETTINGS_TIMER_MS_UPDATE_SIM_INFO 500.0f
73static const int POLL_DELAY_MS = 1000;
85 ui.layerTable->setColumnWidth(0, 200);
86 ui.layerTable->setColumnWidth(1, 40);
87 ui.layerTable->setColumnWidth(2, 40);
88 ui.layerTable->setColumnWidth(3, 80);
89 ui.layerTable->setColumnWidth(4, 80);
90 ui.layerTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
91 ui.layerTable->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed);
92 ui.layerTable->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed);
93 ui.layerTable->horizontalHeader()->setResizeMode(3, QHeaderView::Fixed);
94 ui.layerTable->horizontalHeader()->setResizeMode(4, QHeaderView::Fixed);
95 for (
int i =
ui.layerTable->rowCount(); i; --i)
97 ui.layerTable->removeRow(0);
121 ARMARX_INFO <<
"Using simulator proxy: " << settings_simulatorPrxName <<
flush;
126 layerPollTimer.start(POLL_DELAY_MS);
134 layerPollTimer.stop();
164 customToolbar->setParent(parent);
168 customToolbar =
new QToolBar(parent);
169 customToolbar->addAction(
"Play / Stop",
this, SLOT(
playStopSim()));
170 customToolbar->addSeparator();
171 customToolbar->addAction(
"Reinit",
this, SLOT(
reInit()));
173 return customToolbar.data();
180 ui.cbWindow, SIGNAL(toggled(
bool)),
this, SLOT(
showSimWindow(
bool)), Qt::QueuedConnection);
181 connect(
ui.cbShowCoordSystem,
182 SIGNAL(toggled(
bool)),
185 Qt::QueuedConnection);
187 ui.cbContacts, SIGNAL(toggled(
bool)),
this, SLOT(
showContacts(
bool)), Qt::QueuedConnection);
188 connect(
ui.rbFull, SIGNAL(toggled(
bool)),
this, SLOT(
selectVisuType()), Qt::QueuedConnection);
189 connect(
ui.rbCol, SIGNAL(toggled(
bool)),
this, SLOT(
selectVisuType()), Qt::QueuedConnection);
191 ui.pushButtonPlayStop, SIGNAL(clicked()),
this, SLOT(
playStopSim()), Qt::QueuedConnection);
192 connect(
ui.pushButtonStep, SIGNAL(clicked()),
this, SLOT(
stepSim()), Qt::QueuedConnection);
193 connect(
ui.pushButtonReInit, SIGNAL(clicked()),
this, SLOT(
reInit()), Qt::QueuedConnection);
195 connect(
ui.spinBoxAntiAliasing,
196 SIGNAL(valueChanged(
int)),
199 Qt::QueuedConnection);
202 QObject::connect(&layerSignalMapperVisible,
203 SIGNAL(mapped(QString)),
207 &layerSignalMapperClear, SIGNAL(mapped(QString)),
this, SLOT(
layerClear(QString)));
209 &layerSignalMapperRemove, SIGNAL(mapped(QString)),
this, SLOT(
layerRemove(QString)));
211 QObject::connect(&layerPollTimer, SIGNAL(timeout()),
this, SLOT(
layerPoll()));
213 connect(
ui.pushButtonAddRobot, SIGNAL(clicked()),
this, SLOT(on_pushButtonAddRobot_clicked()));
214 connect(
ui.pushButtonManipRobotUpdate,
217 SLOT(on_pushButtonManipRobotUpdate_clicked()));
218 connect(
ui.pushButtonManipRobSetPose,
221 SLOT(on_pushButtonManipRobSetPose_clicked()));
223 ui.tableObjects->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
224 ui.layerTable->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
230 QString textSimTime(
"SimulationTime:");
231 QString textComTime(
"CommunicationTime:");
232 QString textRobots(
"Robots:");
233 QString textJoints(
"Actuated Joints:");
234 QString textObjects(
"Objects:");
235 QString textContacts(
"Contacts:");
236 QString textDraw(
"DrawTime:");
237 QString textSync(
"SyncTime:");
239 QString textCam(
"Camera ");
245 SimulatorInformation i =
simulatorPrx->getSimulatorInformation();
247 textSimTime += QString::number((
double)i.simTimeStepMeasuredMS,
'f', 2);
248 textSimTime += QString(
" ms (x ");
249 textSimTime += QString::number((
double)i.simTimeFactor,
'f', 2);
250 textSimTime += QString(
")");
252 textComTime += QString::number((
double)i.comTimeMS,
'f', 2);
253 textComTime += QString(
" ms");
255 textSync += QString::number((
double)i.syncEngineTimeMS,
'f', 2);
256 textSync += QString(
" ms");
258 textRobots += QString::number(i.nrRobots);
259 textJoints += QString::number(i.nrActuatedJoints);
260 textObjects += QString::number(i.nrObjects);
261 textContacts += QString::number(i.nrContacts);
262 curTime = QString::number(i.currentSimulatorTimeSec,
'f', 3);
266 ui.tableObjects->setRowCount(i.objects.size());
268 for (std::size_t ob = 0; ob < i.objects.size(); ++ob)
270 const auto& o = i.objects.at(ob);
271 QString name = QString::fromStdString(o.name);
273 PoseBasePtr pose = o.objectPoses.begin()->second;
274 Eigen::Matrix4f gp = PosePtr::dynamicCast(pose)->toEigen();
278 QString pos = QString::number(
x,
'f', 2) +
"," + QString::number(y,
'f', 2) +
"," +
279 QString::number(z,
'f', 2);
281 VirtualRobot::MathTools::eigen4f2rpy(gp, rpy);
282 QString ori = QString::number(rpy(0),
'f', 2) +
"," +
283 QString::number(rpy(1),
'f', 2) +
"," +
284 QString::number(rpy(2),
'f', 2);
298 ui.tableObjects->setItem(ob, 0,
new QTableWidgetItem{name});
299 ui.tableObjects->setItem(ob, 1,
new QTableWidgetItem{pos});
300 ui.tableObjects->setItem(ob, 2,
new QTableWidgetItem{ori});
301 ui.tableObjects->setItem(ob, 3,
new QTableWidgetItem{
status});
314 textDraw += QString::number((
double)i.drawTimeMS + (
double)i.comTimeMS,
'f', 2);
315 textDraw += QString(
" ms");
321 PosePtr p2 = PosePtr::dynamicCast(p);
322 Eigen::Matrix4f p3 = p2->toEigen();
324 MathTools::eigen4f2rpy(p3, rpy);
326 textCam += QString::number(p2->position->x * 1000.0f,
'f', 2);
328 textCam += QString::number(p2->position->y * 1000.0f,
'f', 2);
330 textCam += QString::number(p2->position->z * 1000.0f,
'f', 2);
332 textCam += QString::number(rpy(0),
'f', 2);
334 textCam += QString::number(rpy(1),
'f', 2);
336 textCam += QString::number(rpy(2),
'f', 2);
344 ui.lSimTime->setText(textSimTime);
345 ui.lComTime->setText(textComTime);
346 ui.lRobots->setText(textRobots);
347 ui.lJoints->setText(textJoints);
348 ui.lObjects->setText(textObjects);
349 ui.lContacts->setText(textContacts);
350 ui.lDrawTime->setText(textDraw);
351 ui.lSyncTime->setText(textSync);
352 ui.lcdNumberSimTime->setText(curTime);
354 ui.labelCamPose->setText(textCam);
423 bool fullModel =
ui.rbFull->isChecked();
452 ui.pushButtonStep->setEnabled(
true);
457 ui.pushButtonStep->setEnabled(
false);
537 std::string name = layerName.toStdString();
562 std::string name = layerName.toStdString();
587 auto name = layerName.toStdString();
589 if (layerVisibilityCheckBoxes.count(name))
591 const bool vis = layerVisibilityCheckBoxes.at(name).second->isChecked();
592 ARMARX_VERBOSE <<
"Toggling visibility from " << !vis <<
" to " << vis
593 <<
" for layer " << name <<
"...";
619 ui.layerTable->setRowCount(layerInfo.size());
620 LayerVisibilityCheckBoxesType newLayerVisibilityCheckBoxes;
622 const bool hideEmptyLayers =
ui.checkBoxHideEmptyLayers->isChecked();
624 for (
const auto& layer : layerInfo)
626 auto& layerEntry = newLayerVisibilityCheckBoxes[layer.layerName];
630 if (layerVisibilityCheckBoxes.count(layer.layerName))
633 layerEntry = layerVisibilityCheckBoxes.at(layer.layerName);
634 layerVisibilityCheckBoxes.erase(layer.layerName);
637 for (; tableIdx <
ui.layerTable->rowCount(); ++tableIdx)
639 const QTableWidgetItem* item =
ui.layerTable->item(tableIdx, 0);
642 found = (item->text() == QString::fromStdString(layer.layerName));
657 ui.layerTable->insertRow(0);
659 QString name = QString::fromStdString(layer.layerName);
662 ui.layerTable->setItem(0, 0,
new QTableWidgetItem{name});
665 QCheckBox* box{
new QCheckBox};
666 ui.layerTable->setCellWidget(0, 2, box);
667 layerEntry.second = box;
669 layerSignalMapperVisible.setMapping(box, name);
671 box, SIGNAL(stateChanged(
int)), &layerSignalMapperVisible, SLOT(map()));
674 QPushButton* clear{
new QPushButton{
"Clear"}};
675 ui.layerTable->setCellWidget(0, 3, clear);
676 layerSignalMapperClear.setMapping(clear, name);
678 clear, SIGNAL(clicked()), &layerSignalMapperClear, SLOT(map()));
681 QPushButton* remove{
new QPushButton{
"Remove"}};
682 ui.layerTable->setCellWidget(0, 4, remove);
683 layerSignalMapperRemove.setMapping(remove, name);
685 remove, SIGNAL(clicked()), &layerSignalMapperRemove, SLOT(map()));
691 QCheckBox* box = layerEntry.second;
693 ui.layerTable->setItem(
694 tableIdx, 1,
new QTableWidgetItem{QString::number(layer.elementCount)});
695 box->blockSignals(
true);
696 box->setChecked(layer.visible);
697 box->blockSignals(
false);
699 if (!layer.elementCount && hideEmptyLayers)
702 ui.layerTable->hideRow(tableIdx);
705 ui.layerTable->showRow(tableIdx);
708 for (
const auto& pair : layerVisibilityCheckBoxes)
710 ui.layerTable->removeRow(
ui.layerTable->row(pair.second.first));
712 for (
int i =
ui.layerTable->rowCount() - 1; i >= 0; --i)
714 const QTableWidgetItem* item =
ui.layerTable->item(i, 0);
717 if (layerVisibilityCheckBoxes.count(item->text().toStdString()))
719 ui.layerTable->removeRow(i);
724 ARMARX_WARNING <<
"layerPoll(delete old): item " << i <<
" is null";
727 layerVisibilityCheckBoxes = std::move(newLayerVisibilityCheckBoxes);
728 ui.layerTable->setRowCount(layerVisibilityCheckBoxes.size());
774armarx::SimulatorControlController::on_pushButtonAddRobot_clicked()
780 const auto result = simulatorPrx->addScaledRobot(ui.lineEditAddRobotXML->text().toStdString(),
781 ui.doubleSpinBoxAddRobotScale->value());
782 ui.labelAddRobotResult->setText(QString::fromStdString(result));
786armarx::SimulatorControlController::on_pushButtonManipRobotUpdate_clicked()
792 ui.comboBoxManipRobotName->clear();
793 for (
const auto& n : simulatorPrx->getRobotNames())
795 ui.comboBoxManipRobotName->addItem(QString::fromStdString(n));
800armarx::SimulatorControlController::on_pushButtonManipRobSetPose_clicked()
806 const Eigen::Matrix4f p = simox::math::pos_rpy_to_mat4f(ui.doubleSpinBoxManipRobTX->value(),
807 ui.doubleSpinBoxManipRobTY->value(),
808 ui.doubleSpinBoxManipRobTZ->value(),
810 ui.doubleSpinBoxManipRobRX->value(),
811 ui.doubleSpinBoxManipRobRY->value(),
812 ui.doubleSpinBoxManipRobRZ->value());
813 simulatorPrx->setRobotPose(ui.comboBoxManipRobotName->currentText().toStdString(),
new Pose{p});
#define DEFAULT_SETTINGS_SIMULATOR_PROXY_NAME
#define DEFAULT_SETTINGS_SIMULATORVIEWER_PROXY_NAME
#define DEFAULT_SETTINGS_TIMER_MS_UPDATE_SIM_INFO
std::enable_if<!HasGetWidgetName< ArmarXWidgetType >::value >::type addWidget()
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
void onInitComponent() override
Pure virtual hook for the subclass.
SimulatorViewerControlInterfacePrx simulatorViewerPrx
Ui::SimulatorControlGuiPlugin ui
SimulatorControlController()
QPointer< QWidget > getCustomTitlebarWidget(QWidget *parent) override
getTitleToolbar returns a pointer to the a toolbar widget of this controller.
void onDisconnectComponent() override
Hook for subclass.
void showContacts(bool enable)
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void antiAliasing(int steps)
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
SimulatorInterfacePrx simulatorPrx
void layerClear(QString layerName)
Clears a layer.
void layerPoll()
Requests the current layer information from simulatorPrx and updates the table.
void layerRemove(QString layerName)
Removes a layer.
void reInit()
reInit Re-loads all simulator content.
void timerEvent(QTimerEvent *) override
timerEvent
void onConnectComponent() override
Pure virtual hook for the subclass.
void showCoordSystem(bool enable)
void layerToggleVisibility(QString layerName)
Toggles a layer's visibility.
void onExitComponent() override
Hook for subclass.
void showSimWindow(bool enable)
SimulatorControlGuiPlugin()
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Pose > PosePtr
const LogSender::manipulator flush