28 #include "../../../StatechartEventSenderPlugin/TreeBox.h"
29 #include "../../../ObserverPropertiesPlugin/ObserverItemModel.h"
31 #include <QHeaderView>
61 this->variantInfo = variantInfo;
62 destDict = targetDict;
63 this->transition = transition;
65 oldSourceMapping = sourceMapping;
66 this->profileNames = profileNames;
69 if (!transition->destinationState->getStateClass() && transition->destinationState->getType() != eFinalState)
74 setRowCount(destDict.size());
75 setHorizontalHeaderLabels(QString(
"Target parameter;Value Type;Mapping Required;Source Type;Source Parameter;").
split(
";"));
76 horizontalHeaderItem(
eMappingRequired)->setToolTip(
"Checked if this parameter has no default value and is not optional, so a mapping is required.");
82 horizontalHeader()->setStretchLastSection(
true);
84 QStringList mappingSources;
85 mappingSources <<
"Parent input";
86 mappingSources <<
"State output";
87 mappingSources <<
"Datafield" <<
"Event";
88 mappingSources <<
"Value";
91 statechartmodel::StateParameterMap::const_iterator it = destDict.begin();
93 for (; it != destDict.end(); it++)
95 QString keyInput = it.key();
104 QString typeInput = it.value()->type;
105 auto destKeyItem =
new QTableWidgetItem(keyInput);
106 setItem(row,
eDestKey, destKeyItem);
107 destKeyItem->setToolTip((it.value()->description.isEmpty() ?
"" :
"Description:\n") + it.value()->description);
108 item(row,
eDestKey)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
111 item(row,
eMappingRequired)->setCheckState(!it.value()->optional && !it.value()->getDefaultValue() ? Qt::Checked : Qt::Unchecked);
119 setCellWidget(row,
eSource, comboBoxMappingSource);
120 comboBoxMappingSource->addItems(mappingSources);
126 comboBoxMappingSource->setCurrentIndex(mapping->source);
131 int mappingSource = transition->sourceState ? 1 : 0;
132 comboBoxMappingSource->setCurrentIndex(mappingSource);
140 if (!transition->sourceState)
143 comboBoxMappingSource->setItemData(1, QVariant(0), Qt::UserRole - 1);
145 comboBoxMappingSource->setItemData(2, QVariant(0), Qt::UserRole - 1);
146 comboBoxMappingSource->setItemData(3, QVariant(0), Qt::UserRole - 1);
149 auto humanType = QString::fromUtf8(variantInfo->getNestedHumanNameFromBaseName(typeInput.toUtf8().data()).c_str());
150 setItem(row,
eDestType,
new QTableWidgetItem(humanType));
151 item(row,
eDestType)->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
152 item(row,
eDestType)->setToolTip(typeInput);
165 for (
int row = 0; row < rowCount(); row++)
168 mapping->destinationKey = item(row,
eDestKey)->text();
169 QComboBox* combo = qobject_cast<QComboBox*>(cellWidget(row,
eSource));
173 mapping->source = (MappingSource)combo->currentIndex();
176 QComboBox* sourceCombo = qobject_cast<QComboBox*>(cellWidget(row,
eSourceKey));
180 mapping->sourceKey = sourceCombo->currentText();
182 if (!mapping->sourceKey.isEmpty() && mapping->sourceKey !=
"none")
184 result.append(mapping);
191 mapping->profileValues = valueEdit->getJsonMap();
192 result.append(mapping);
203 QList<std::pair<QString, QString>> mappedRows;
204 for (
int row = 0; row < rowCount(); row++)
206 QComboBox* comboSourceType = qobject_cast<QComboBox*>(cellWidget(row,
eSource));
207 int oldIndex = comboSourceType->currentIndex();
209 for (
int type = 1; type >= 0; type--)
220 QComboBox* combo = qobject_cast<QComboBox*>(cellWidget(row,
eSourceKey));
222 if (combo && combo->currentIndex() > 0)
227 comboSourceType->setCurrentIndex(type);
228 if (comboSourceType->currentIndex() != type)
232 auto destinationKey = item(row,
eDestKey)->text();
235 combo = qobject_cast<QComboBox*>(cellWidget(row,
eSourceKey));
237 if (combo && combo->currentIndex() <= 0)
241 for (
int i = 0; i < combo->count(); i++)
243 ARMARX_DEBUG << combo->itemText(i) <<
" <-> " << destinationKey;
244 auto [
success, error] =
compare(combo->itemText(i), destinationKey);
245 if (
success && error < smallestError)
248 smallestError = error;
254 combo->setCurrentIndex(bestIndex);
255 ARMARX_DEBUG <<
" setting to " << bestIndex <<
" of source key " << combo->itemText(bestIndex);
257 mappedRows.push_back(std::make_pair(destinationKey, comboSourceType->currentText() +
"." + combo->itemText(bestIndex)));
264 comboSourceType->setCurrentIndex(oldIndex);
273 statechartmodel::StateParameterMap::const_iterator it = destDict.begin();
277 QWidget* wid = qobject_cast<QWidget*>(sender());
281 throw LocalException(
"Could not get row of table");
284 QModelIndex mIndex = indexAt(wid->pos());
285 tableRow = mIndex.row();
288 for (
int i = 0; i < tableRow; ++i, it++)
297 auto selection = getFilteredParams(parentState->getInputAndLocalParameters(), *it.value());
299 for (
auto it = selection.begin(); it != selection.end(); ++it, i++)
301 parentInput->addItem(it->first);
302 parentInput->setItemData(i, it->second.isEmpty() ?
"" :
"Description:\n" + it->second, Qt::ToolTipRole);
304 if (initialValue.length() > 0)
306 parentInput->setCurrentIndex(parentInput->findText(initialValue));
309 setCellWidget(tableRow,
eSourceKey, parentInput);
313 if (transition->sourceState)
315 QComboBox* box = getFilteredOutputItems(it.key(), transition);
317 if (initialValue.length() > 0)
319 box->setCurrentIndex(box->findText(initialValue));
326 setCellWidget(tableRow,
eSourceKey,
new QWidget());
329 else if (
index == 4 && ic)
331 auto destType = getInputTypeString(tableRow);
337 if (m->destinationKey == it.key())
343 QMap<QString, QString>
values;
344 if (i < oldSourceMapping.size())
349 values = mappingEntry->profileValues;
362 setCellWidget(tableRow,
eSourceKey,
new QLineEdit(initialValue));
369 QList<QPair<QString, QString>> items;
371 statechartmodel::StateParameterMap::const_iterator it =
source.begin();
373 for (; it !=
source.end(); it++)
375 if (it.value()->type == argumentToMatch.
type)
377 items.append(qMakePair(it.key(), it.value()->description));
384 items.insert(0, qMakePair(tr(
"none"), QString(
"")));
389 QString TransitionMappingTable::getInputTypeString(
int row)
391 statechartmodel::StateParameterMap::const_iterator it = destDict.begin();
395 QWidget* wid = qobject_cast<QWidget*>(sender());
399 throw LocalException(
"Could not get row of table");
402 QModelIndex mIndex = indexAt(wid->pos());
406 for (
int i = 0; i < row; ++i, it++)
409 if (it != destDict.end())
411 return it.value()->type;
421 QList<QString> items;
425 if (!transition->sourceState)
427 ARMARX_ERROR_S << (
"The sourceState of the transition with event ") << transition->eventName <<
" is NULL - output parameters are not loaded" ;
431 if (!transition->sourceState->getStateClass())
433 ARMARX_ERROR_S << (
"The stateClass pointer of the sourceState named '") << transition->sourceState->getInstanceName() <<
"' of the transition is NULL - output parameters of state '" << transition->sourceState->getInstanceName() <<
"' are not loaded";
440 statechartmodel::StateParameterMap::const_iterator it =
source.begin();
450 items.insert(0, tr(
"none"));
453 for (; it !=
source.end(); it++)
455 if (it.value()->type == param->type)
457 items.append(it.key());
466 cbo->addItems(items);