24 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/view/dialogs/ui_EditStatechartGroupDialog.h>
26 #include <QFileDialog>
47 VariantInfoPtr variantInfo, QList<QString> selectedProxies,
bool generateContext,
48 const StatechartProfilesPtr& statechartProfiles,
const QMap<QString, QString>& statechartGroupConfigurations,
52 packageTool(packageTool),
54 statechartProfiles(statechartProfiles),
55 configurations(statechartGroupConfigurations),
56 variantInfo(variantInfo),
60 ui->btnShowPackageError->setVisible(
false);
62 ui->checkBoxGenerateContext->setChecked(generateContext);
68 setWindowTitle(
"Create new Statechart Group");
69 QRegExp rx(
"([a-zA-Z][a-zA-Z0-9]*)");
70 ui->editStatechartGroup->setValidator(
new QRegExpValidator(rx,
this));
72 connect(ui->btnSelectPackageFolder, SIGNAL(clicked()),
this, SLOT(
selectPackagePath()));
76 timer =
new QTimer(
this);
78 timer->setSingleShot(
true);
81 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
82 ui->tabWidget->setCurrentIndex(0);
86 setWindowTitle(groupName +
" - Properties");
87 ui->editStatechartGroup->setText(groupName);
88 ui->textEditGroupDescription->setPlainText(description);
89 ui->editPackagePath->setEnabled(
false);
90 ui->editStatechartGroup->setEnabled(
false);
91 ui->btnSelectPackageFolder->setEnabled(
false);
93 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
97 throw LocalException(
"Not supported enum value.");
100 QStringList properties;
101 QStandardItemModel* model =
new QStandardItemModel(ui->listProxies);
105 QString libName = QString::fromUtf8(lib->getName().c_str());
110 QString proxyHumanName = QString::fromUtf8(proxy->getHumanName().c_str());
111 QString proxyMemberName = QString::fromUtf8(proxy->getMemberName().c_str());
112 QString
display = QString(
"[%1] %3").arg(libName, proxyHumanName);
113 QStandardItem* listItem =
new QStandardItem(
display);
114 QString proxyId = QString(
"%1.%2").arg(libName, proxyMemberName);
115 listItem->setData(proxyId, Qt::UserRole);
116 listItem->setCheckable(
true);
117 listItem->setEditable(
false);
118 listItem->setCheckState(selectedProxies.contains(proxyId) ? Qt::Checked : Qt::Unchecked);
119 model->appendRow(listItem);
123 filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
124 filterModel->setSourceModel(model);
125 ui->listProxies->setModel(filterModel);
126 connect(ui->lineEditProxyFilter, SIGNAL(textChanged(QString)), filterModel, SLOT(setFilterFixedString(QString)));
129 std::list<StatechartProfilePtr> profileQueue;
130 profileQueue.push_back(statechartProfiles->getRootProfile());
133 while (!profileQueue.empty())
136 profileQueue.pop_front();
137 ui->comboBoxStatechartProfiles->addItem(QString(currentProfile->getNesting(),
'-') +
" " + QString::fromStdString(currentProfile->getName()),
138 QString::fromStdString(currentProfile->getName()));
139 for (
auto it = currentProfile->getChildren().rbegin(); it != currentProfile->getChildren().rend(); it++)
141 profileQueue.push_front(*it);
143 if (profileQueue.size() == 0)
147 if (configurations[QString::fromStdString(currentProfile->getName())].isEmpty())
149 configurations[QString::fromStdString(currentProfile->getName())] = properties.join(
"\n");
153 connect(ui->listProxies->model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SLOT(
updateDependencies(QModelIndex, QModelIndex)));
171 return ui->editStatechartGroup->text();
185 return QString::fromStdString(path.string());
192 <<
"Using legacy path for now.";
194 std::filesystem::path path = ui->editPackagePath->text().toUtf8().data();
197 path /=
"statecharts";
200 return QString::fromUtf8(path.c_str());
205 return ui->textEditGroupDescription->toPlainText();
210 const std::filesystem::path packagePath =
getPackagePath().toStdString();
214 for (
const std::string& package : packages)
219 return QString::fromStdString(package);
222 std::stringstream ss;
223 ss <<
"No CMake package found for path " << packagePath <<
".";
224 throw LocalException(ss.str());
232 std::filesystem::path path = ui->editPackagePath->text().toUtf8().data();
233 std::filesystem::path cleanPath = path;
237 cleanPath = std::filesystem::canonical(path);
243 if (*cleanPath.string().rbegin() ==
'/' || *cleanPath.string().rbegin() ==
'\\')
245 cleanPath = cleanPath.remove_filename();
249 return QString::fromUtf8(cleanPath.c_str());
254 QList<QString> proxies;
255 QSortFilterProxyModel* proxy = qobject_cast<QSortFilterProxyModel*>(ui->listProxies->model());
256 QStandardItemModel* model = qobject_cast<QStandardItemModel*>(proxy->sourceModel());
257 for (
int row = 0; row < model->rowCount(); row++)
259 auto item = model->item(row);
260 if (item && item->checkState() == Qt::Checked)
262 proxies.append(item->data(Qt::UserRole).toString());
271 return ui->checkBoxGenerateContext->isChecked();
276 return configurations;
287 QFileDialog selectFolder(
this,
"Select ArmarX Package Root Folder");
289 urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::HomeLocation))
290 << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::DesktopLocation));
297 selectFolder.setSidebarUrls(urls);
299 selectFolder.setOption(QFileDialog::ReadOnly,
true);
300 selectFolder.setOption(QFileDialog::HideNameFilterDetails,
false);
301 selectFolder.setFileMode(QFileDialog::Directory);
303 if (selectFolder.exec() == QDialog::Accepted)
305 ui->editPackagePath->setText(*selectFolder.selectedFiles().begin());
313 std::string cmdOutput;
314 if (packageTool->checkPackagePath(ui->editPackagePath->text().toStdString(), cmdOutput))
316 ui->labelPackageError->setText(
"Package path is valid.");
317 QPalette p(ui->labelPackageError->palette());
318 p.setColor(ui->labelPackageError->backgroundRole(), QColor::fromRgb(120, 255, 120));
320 ui->labelPackageError->setPalette(p);
322 if (!ui->editStatechartGroup->text().isEmpty())
324 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
328 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
330 ui->labelPackageError->setToolTip(
"");
331 ui->btnShowPackageError->setVisible(
false);
335 ui->labelPackageError->setText(
"Package path is not valid!");
336 ui->labelPackageError->setToolTip(QString::fromStdString(cmdOutput));
337 QPalette p(ui->labelPackageError->palette());
338 p.setColor(ui->labelPackageError->backgroundRole(), QColor::fromRgb(255, 120, 120));
339 ui->labelPackageError->setPalette(p);
340 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
341 ui->btnShowPackageError->setVisible(
true);
348 ui->listProxies->setEnabled(ui->checkBoxGenerateContext->isChecked());
353 int i = ui->comboBoxStatechartProfiles->findText(profileText);
358 auto profile = ui->comboBoxStatechartProfiles->itemData(i).toString();
359 ui->textEditParameters->setPlainText(configurations[profile]);
364 int i = ui->comboBoxStatechartProfiles->currentIndex();
365 auto profile = ui->comboBoxStatechartProfiles->itemData(i).toString();
366 configurations[profile] = ui->textEditParameters->toPlainText();
382 QString libName = QString::fromUtf8(lib->getName().c_str());
385 QString proxyMemberName = QString::fromUtf8(proxy->getMemberName().c_str());
386 QString proxyId = QString(
"%1.%2").arg(libName, proxyMemberName);
387 if (selectedProxies.contains(proxyId))
389 if (!libs.contains(libName))
400 Ice::StringSeq types;
403 for (
auto& param : state->getInputParameters())
405 vars.insert(param->type);
407 for (
auto& param : state->getLocalParameters())
409 vars.insert(param->type);
411 for (
auto& param : state->getOutputParameters())
413 vars.insert(param->type);
416 for (
auto& var : vars)
421 types.push_back(type);
424 for (std::string& lib : variantInfo->findLibNames(types))
426 auto libName = QString::fromStdString(lib);
427 if (!libs.contains(libName))
434 ui->editDependencies->setText(libs.join(
" "));
439 void armarx::EditStatechartGroupDialog::on_pushButton_clicked()
443 int i = ui->comboBoxStatechartProfiles->currentIndex();
448 auto profileName = ui->comboBoxStatechartProfiles->itemData(i).toString();
451 QString libName = QString::fromUtf8(lib->getName().c_str());
455 QString proxyMemberName = QString::fromUtf8(proxy->getMemberName().c_str());
456 QString proxyId = QString(
"%1.%2").arg(libName, proxyMemberName);
457 if (selectedProxies.contains(proxyId))
459 QString propName = QString(
"ArmarX.") + groupName +
"RemoteStateOfferer." + QString::fromUtf8(proxy->getPropertyName().c_str());
461 if (!configurations[profileName].
contains(propName))
464 if (!proxy->getPropertyIsOptional())
466 newProp +=
"# Required Property\n";
467 newProp +=
"#" + propName +
" = <set value and uncomment!>\n";
471 newProp +=
"#" + propName +
" = " + QString::fromUtf8(proxy->getPropertyDefaultValue().c_str()) +
"\n";
474 configurations[profileName] +=
"\n" + newProp;
482 void armarx::EditStatechartGroupDialog::on_btnShowPackageError_clicked()
484 QToolTip::showText(ui->btnShowPackageError->mapToGlobal(QPoint(10, 10)), ui->labelPackageError->toolTip());