27 #include <QFileDialog>
29 #include <QMessageBox>
31 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_TransitionDialog.h>
33 #include "../../../ObserverPropertiesPlugin/ObserverItemModel.h"
40 QStringList profileNames,
46 transition(transition),
49 variantInfo(variantInfo),
50 profileNames(profileNames)
64 return ui->inputTableMapping->getMapping();
70 return ui->parentLocalMapping->getMapping();
76 return ui->parentOutputMapping->getMapping();
83 const std::size_t len1 = s1.size(), len2 = s2.size();
84 std::vector<std::vector<unsigned int>> d(len1 + 1, std::vector<unsigned int>(len2 + 1));
87 for (
unsigned int i = 1; i <= len1; ++i)
91 for (
unsigned int i = 1; i <= len2; ++i)
96 for (
unsigned int i = 1; i <= len1; ++i)
97 for (
unsigned int j = 1; j <= len2; ++j)
100 d[i][j] =
std::min({d[i - 1][j] + 1,
102 d[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1)});
103 return d[len1][len2];
107 TransitionDialog::setup()
111 ui->labelEventName->setText(transition->eventName);
113 if (!transition->destinationState)
115 ui->labelDestinationState->setText(
"Transition is detached");
120 if (transition->sourceState)
122 ui->labelSourceState->setText(transition->sourceState->getInstanceName());
123 setWindowTitle(
"Edit Transition " + transition->eventName +
" [" +
124 transition->sourceState->getInstanceName() +
" -> " +
125 transition->destinationState->getInstanceName() +
"]");
129 ui->labelSourceState->setText(
"This is the initial transition to the start state");
130 setWindowTitle(
"Edit Initial Transition -> " +
131 transition->destinationState->getInstanceName());
134 ui->labelDestinationState->setText(transition->destinationState->getInstanceName());
139 if (transition->destinationState->getType() != eFinalState)
141 if (transition->destinationState->getStateClass())
143 destDict = transition->destinationState->getStateClass()->getInputParameters();
147 QMessageBox::warning(
this,
148 "Transition Editing Error",
149 "Transition editing not possible because destination state is "
150 "not loaded - load statechart group of destination state.");
156 destDict = transition->destinationState->getParent()->getOutputParameters();
159 ui->inputTableMapping->setup(destDict,
160 transition->mappingToNextStatesInput,
167 if (transition->sourceState)
169 ui->tabWidget->setTabEnabled(1,
true);
170 ui->tabWidget->setTabEnabled(2,
true);
173 ui->parentLocalMapping->setup(parentState->getLocalParameters(),
174 transition->mappingToParentStatesLocal,
180 ui->parentOutputMapping->setup(parentState->getOutputParameters(),
181 transition->mappingToParentStatesOutput,
190 ui->tabWidget->setTabEnabled(1,
false);
191 ui->tabWidget->setTabEnabled(2,
false);
199 armarx::TransitionDialog::on_btnAutoMap_clicked()
201 TransitionMappingTable* mapping;
202 if (ui->tabWidget->currentIndex() == 0)
204 mapping = ui->inputTableMapping;
206 else if (ui->tabWidget->currentIndex() == 1)
208 mapping = ui->parentLocalMapping;
212 mapping = ui->parentOutputMapping;
216 auto caseSensitive = [](QString s1, QString s2) {
return std::make_pair(s1 == s2, 0.0f); };
217 auto caseInsensitive = [](QString s1, QString s2)
218 {
return std::make_pair(s1.compare(s1, s2, Qt::CaseInsensitive) == 0, 0.0f); };
219 auto editDistance = [](QString s1, QString s2)
227 auto mappedRows = mapping->mapByCriteria(caseSensitive);
229 mappedRows.append(mapping->mapByCriteria(caseInsensitive));
231 mappedRows.append(mapping->mapByCriteria(editDistance));
233 QString foundMappingsString;
234 for (
auto& elem : mappedRows)
236 foundMappingsString += elem.first +
" from " + elem.second +
"\n";
238 if (!foundMappingsString.isEmpty())
240 foundMappingsString =
":\n" + foundMappingsString;
242 QMessageBox::information(
this,
243 "Auto Mapping Results",
244 "Mapped " + QString::number(mappedRows.size()) +
245 (mappedRows.size() == 1 ?
" entry" :
" entries") +
246 foundMappingsString);