25 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_TransitionDialog.h>
27 #include "../../../ObserverPropertiesPlugin/ObserverItemModel.h"
30 #include <QFileDialog>
32 #include <QMessageBox>
41 transition(transition),
44 variantInfo(variantInfo),
45 profileNames(profileNames)
58 return ui->inputTableMapping->getMapping();
63 return ui->parentLocalMapping->getMapping();
68 return ui->parentOutputMapping->getMapping();
74 const std::size_t len1 = s1.size(), len2 = s2.size();
75 std::vector<std::vector<unsigned int>> d(len1 + 1, std::vector<unsigned int>(len2 + 1));
78 for (
unsigned int i = 1; i <= len1; ++i)
82 for (
unsigned int i = 1; i <= len2; ++i)
87 for (
unsigned int i = 1; i <= len1; ++i)
88 for (
unsigned int j = 1; j <= len2; ++j)
91 d[i][j] =
std::min({ d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + (s1[i - 1] == s2[j - 1] ? 0 : 1) });
96 void TransitionDialog::setup()
100 ui->labelEventName->setText(transition->eventName);
102 if (!transition->destinationState)
104 ui->labelDestinationState->setText(
"Transition is detached");
109 if (transition->sourceState)
111 ui->labelSourceState->setText(transition->sourceState->getInstanceName());
112 setWindowTitle(
"Edit Transition " + transition->eventName +
" [" + transition->sourceState->getInstanceName() +
" -> " + transition->destinationState->getInstanceName() +
"]");
116 ui->labelSourceState->setText(
"This is the initial transition to the start state");
117 setWindowTitle(
"Edit Initial Transition -> " + transition->destinationState->getInstanceName());
120 ui->labelDestinationState->setText(transition->destinationState->getInstanceName());
125 if (transition->destinationState->getType() != eFinalState)
127 if (transition->destinationState->getStateClass())
129 destDict = transition->destinationState->getStateClass()->getInputParameters();
133 QMessageBox::warning(
this,
"Transition Editing Error",
"Transition editing not possible because destination state is not loaded - load statechart group of destination state.");
139 destDict = transition->destinationState->getParent()->getOutputParameters();
142 ui->inputTableMapping->setup(destDict, transition->mappingToNextStatesInput, transition, parentState, profileNames, ic, variantInfo);
144 if (transition->sourceState)
146 ui->tabWidget->setTabEnabled(1,
true);
147 ui->tabWidget->setTabEnabled(2,
true);
150 ui->parentLocalMapping->setup(parentState->getLocalParameters(), transition->mappingToParentStatesLocal, transition, parentState, profileNames, ic, variantInfo);
151 ui->parentOutputMapping->setup(parentState->getOutputParameters(), transition->mappingToParentStatesOutput, transition, parentState, profileNames, ic, variantInfo);
155 ui->tabWidget->setTabEnabled(1,
false);
156 ui->tabWidget->setTabEnabled(2,
false);
167 void armarx::TransitionDialog::on_btnAutoMap_clicked()
169 TransitionMappingTable* mapping;
170 if (ui->tabWidget->currentIndex() == 0)
172 mapping = ui->inputTableMapping;
174 else if (ui->tabWidget->currentIndex() == 1)
176 mapping = ui->parentLocalMapping;
180 mapping = ui->parentOutputMapping;
184 auto caseSensitive = [](QString s1, QString s2)
186 return std::make_pair(s1 == s2, 0.0f);
188 auto caseInsensitive = [](QString s1, QString s2)
190 return std::make_pair(s1.compare(s1, s2, Qt::CaseInsensitive) == 0, 0.0f);
192 auto editDistance = [](QString s1, QString s2)
199 auto mappedRows = mapping->mapByCriteria(caseSensitive);
201 mappedRows.append(mapping->mapByCriteria(caseInsensitive));
203 mappedRows.append(mapping->mapByCriteria(editDistance));
205 QString foundMappingsString;
206 for (
auto& elem : mappedRows)
208 foundMappingsString += elem.first +
" from " + elem.second +
"\n";
210 if (!foundMappingsString.isEmpty())
212 foundMappingsString =
":\n" + foundMappingsString;
214 QMessageBox::information(
this,
"Auto Mapping Results",
"Mapped " + QString::number(mappedRows.size()) + (mappedRows.size() == 1 ?
" entry" :
" entries") + foundMappingsString);