25 #include <ArmarXGui/gui-plugins/StatechartEventSenderPlugin/ui_EventSenderConfig.h>
38 #include <IceUtil/IceUtil.h>
44 #include <QScrollArea>
45 #include <QPushButton>
46 #include <QTableWidget>
47 #include <QTableWidgetItem>
49 #include <QFileDialog>
50 #include <QMessageBox>
51 #include <QTableWidgetItem>
81 settings->setValue(
"eventName",
event->eventName.c_str());
82 settings->setValue(
"eventReceiverName",
event->eventReceiverName.c_str());
83 settings->beginWriteArray(
"parameters");
84 StringVariantContainerBaseMap::const_iterator it =
event->properties.begin();
87 for (; it !=
event->properties.end(); ++it, i++)
90 settings->setArrayIndex(i);
91 settings->setValue(
"key", it->first.c_str());
92 settings->setValue(
"VariantTypeId", sVar->get()->getType());
93 settings->setValue(
"value", sVar->get()->getOutputValueOnly().c_str());
104 description = settings->value(
"description").toString();
106 event =
new Event(settings->value(
"eventReceiverName").toString().toStdString(),
107 settings->value(
"eventName").toString().toStdString());
109 int size = settings->beginReadArray(
"parameters");
111 for (
int i = 0; i < size; ++i)
113 settings->setArrayIndex(i);
116 var->setType(settings->value(
"VariantTypeId").toInt());
117 QVariant
data = settings->value(
"value");
122 var->setString(
data.toString().toStdString());
126 var->setInt(
data.toInt());
130 var->setLong(
data.toLongLong());
134 var->setFloat(
data.toFloat());
138 var->setDouble(
data.toDouble());
142 var->setBool(
data.toBool());
149 sVar->setVariant(var);
150 std::string key = settings->value(
"key").toString().toStdString();
151 event->properties[key] = sVar;
155 settings->endArray();
191 throw NotImplementedYetException(
"Sending event");
218 QString currentEventString =
ui->CBEvent->currentText();
220 event->properties =
ui->paramEditor->getStringValueMap();
299 QModelIndex oldIndex = treeBox->rootModelIndex();
300 treeBox->setRootModelIndex(
index.parent());
301 treeBox->setCurrentIndex(
index.row());
302 treeBox->setRootModelIndex(oldIndex);
303 treeBox->view()->setCurrentIndex(
index);
308 ui->CBEvent->setCurrentIndex(
ui->CBEvent->findText(config.
event->eventName.c_str()));
312 ui->paramEditor->setRowCount(0);
313 StringVariantContainerBaseMap::const_iterator it = config.
event->properties.begin();
315 for (; it != config.
event->properties.end(); ++it)
319 , sVar->get()->getOutputValueOnly().c_str());
327 QStandardItem* item = model->invisibleRootItem();
328 return getRowOfItem(item, searchString, userDataRole, userData);
333 if (userDataRole == 0 && searchString.length() == 0)
335 throw LocalException(
"Either searchString or userDataRole must be given!");
339 QStandardItem* child;
341 while (i++, child = item->child(i), child != NULL)
348 if ((searchString.length() == 0 || child->text() == searchString)
349 && (userDataRole == 0 || child->data(userDataRole) == userData))
351 return child->index();
354 QModelIndex result =
getRowOfItem(child, searchString, userDataRole, userData);
356 if (result.isValid())
363 return QModelIndex();
370 this->iceManager = iceManager;
374 ui->paramEditor->setCommunicator(iceManager->getCommunicator());
382 for (
unsigned int i = 0; i < state->transitions.size(); i++)
384 TransitionIceBase& t = state->transitions[i];
386 if (!events.contains(QString(t.evt->eventName.c_str())))
388 events.push_back(QString(t.evt->eventName.c_str()));
397 QSettings settings(first, second);
404 int rows = settings.beginReadArray(
"TableWidget");
405 ui->paramEditor->setRowCount(rows);
407 for (
int i = 0; i < rows; i++)
409 settings.setArrayIndex(i);
410 int columns = settings.beginReadArray(
"Column");
411 ui->paramEditor->setColumnCount(columns);
413 for (
int j = 0; j < columns; j++)
415 settings.setArrayIndex(j);
419 ui->paramEditor->item(i, j)->setText(settings.value(
"Cell").toString());
424 QComboBox* tempBox =
new QComboBox;
425 int comboLength = settings.beginReadArray(
"ComboBox");
431 tempBox->insertItem(
index, settings.value(cell).toString());
434 ui->paramEditor->setCellWidget(i, j, tempBox);
445 QLineEdit* tempEdit =
new QLineEdit;
446 tempEdit->setText(settings.value(
"Cell").toString());
447 ui->paramEditor->setCellWidget(i, j, tempEdit);
461 QSettings settings(
"armarx",
"eventSender");
463 settings.beginWriteArray(
"ComboBox");
469 settings.beginWriteArray(
"TableWidget");
471 for (
int i = 0; i <
ui->paramEditor->rowCount(); i++)
473 settings.setArrayIndex(i);
474 settings.beginWriteArray(
"Column");
476 for (
int j = 0; j <
ui->paramEditor->columnCount(); j++)
478 settings.setArrayIndex(j);
482 settings.setValue(
"Cell",
ui->paramEditor->item(i, j)->text());
487 QComboBox* tempBox = qobject_cast<QComboBox*>(
ui->paramEditor->cellWidget(i, j));
488 settings.beginWriteArray(
"ComboBox");
492 settings.setArrayIndex(
index);
495 settings.setValue(cell, tempBox->itemText(
index));
503 QLineEdit* tempEdit = qobject_cast<QLineEdit*>(
ui->paramEditor->cellWidget(i, j));
504 settings.setValue(
"Cell", tempEdit->text());
518 std::vector<StateIceBasePtr> baseStateList;
519 std::vector<StateIceBasePtr> instanceStateList;
520 std::string stateSearchMask =
ui->edtStateSearchMask->text().toStdString();
521 std::vector<std::string> remoteStateOffererList = iceManager->getIceGridSession()->getRegisteredObjectNames<RemoteStateOffererInterfacePrx>(stateSearchMask);
523 QStringList componentNames;
525 for (
unsigned int i = 0; i < remoteStateOffererList.size(); ++i)
527 componentNames << QString::fromStdString(remoteStateOffererList.at(i));
530 if (componentNames.size() == 0)
536 foreach (QString componentNameQStr, componentNames)
538 std::string componentName = componentNameQStr.trimmed().toStdString();
543 model->
updateModel(componentName, baseStateList, instanceStateList);
545 catch (Ice::NotRegisteredException& e)
547 ARMARX_WARNING <<
"The entered component with name '" << componentName <<
"' was not found - maybe you forgot to start it?" <<
flush;
549 catch (IceUtil::NullHandleException& e)
551 ARMARX_ERROR <<
"IceUtil::NullHandleException: " << e.what() <<
"\nFile: " << e. ice_file() << e.ice_line() <<
"\nBacktrace:\n" << e.ice_stackTrace() <<
flush;
553 catch (armarx::UserException& e)
555 ARMARX_WARNING <<
"Found component but cannot communicate with component - probably it is a component of another type\nreason: " << e.reason <<
flush;
565 RemoteStateOffererInterfacePrx statePrx;
566 statePrx = iceManager->getProxy< armarx::RemoteStateOffererInterfacePrx >(componentName);
574 Ice::StringSeq availableStates = statePrx->getAvailableStates();
575 baseStateList.clear();
577 for (
unsigned int i = 0; i < availableStates.size(); ++i)
579 baseStateList.push_back(statePrx->getStatechart(availableStates[i]));
582 StateIdNameMap availableStateInstances = statePrx->getAvailableStateInstances();
583 instanceStateList.clear();
584 StateIdNameMap::iterator it = availableStateInstances.begin();
586 for (; it != availableStateInstances.end(); ++it)
588 instanceStateList.push_back(statePrx->getStatechartInstance(it->first));
596 QModelIndex modelIndex = treeBox->view()->currentIndex();
598 std::string globalStateId = treeBox->model()->itemData(modelIndex)[
STATE_GLOBALSTATEID].toString().toStdString();
599 std::string componentName = treeBox->model()->itemData(modelIndex)[
STATE_COMPONENT_NAME].toString().toStdString();
604 ui->CBEvent->clear();
605 ui->edtSelectedState->setText(
"");
609 StateIceBasePtr statePtr = model->
getState(componentName, globalStateId);
613 ARMARX_WARNING <<
"Could not find state with id " << globalStateId <<
" of component '" << componentName <<
"'" <<
flush;
617 ui->edtSelectedState->setText(globalStateId.c_str());
618 ui->CBEvent->clear();
620 ui->CBEvent->addItems(eventList);
627 QObject::connect(
ui->buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
628 QObject::connect(
ui->buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
631 treeBox =
new TreeBox(model,
true,
this);
632 ui->gridLayout->addWidget(treeBox, 3, 4, 1, 1);
635 ui->paramEditor->setDefaultValueState(Qt::Checked);
658 connect(
ui->addRowButton, SIGNAL(clicked()),
ui->paramEditor, SLOT(addParameterRow()));
659 connect(
ui->sendButton, SIGNAL(clicked()),
this, SLOT(
send()));
663 connect(treeBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
stateSelected(
int)));
664 ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(
true);
670 QModelIndex
index = treeBox->view()->currentIndex();
676 QModelIndex
index = treeBox->view()->currentIndex();