25 #include <MemoryX/gui-plugins/SceneEditor/ui_SceneEditorConfigDialog.h>
30 #include <IceUtil/UUID.h>
33 #include <QMessageBox>
34 #include <QDialogButtonBox>
35 #include <QPushButton>
36 #include <QFileDialog>
40 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
41 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
52 workingMemoryProxyFinder->setSearchMask(
"WorkingMemory");
53 workingMemoryProxyFinder->showSearchMaskField(
true);
54 workingMemoryProxyFinder->showLabels(
false);
55 ui->workingMemoryGridLayout->addWidget(workingMemoryProxyFinder, 0, 1, 1, 2);
58 workingMemoryUpdatesTopicFinder->setSearchMask(
"WorkingMemoryUpdates");
59 workingMemoryUpdatesTopicFinder->showSearchMaskField(
false);
60 workingMemoryUpdatesTopicFinder->showLabels(
false);
61 ui->workingMemoryGridLayout->addWidget(workingMemoryUpdatesTopicFinder, 1, 1, 1, 2);
64 priorKnowledgeProxyFinder->setSearchMask(
"PriorKnowledge");
65 priorKnowledgeProxyFinder->showSearchMaskField(
true);
66 priorKnowledgeProxyFinder->showLabels(
false);
67 ui->priorKnowledgeGridLayout->addWidget(priorKnowledgeProxyFinder, 0, 1, 1, 2);
69 connect(ui->buttonBox, SIGNAL(accepted()),
this, SLOT(verifyConfiguration()));
70 ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(
false);
72 std::filesystem::path currentPath(std::filesystem::current_path());
73 std::filesystem::path defaultFile(
"SceneEditor.ini");
74 this->ui->settingsFileLineEdit->setText(QString::fromStdString((currentPath / defaultFile).
string()));
75 connect(ui->fileBrowserToolButton, SIGNAL(released()),
this, SLOT(fileBrowserToolButtonReleased()));
85 return "SceneEditorConfigDialog" + IceUtil::generateUUID();
90 workingMemoryProxyFinder->setIceManager(this->getIceManager());
91 workingMemoryUpdatesTopicFinder->setIceManager(this->getIceManager());
92 priorKnowledgeProxyFinder->setIceManager(this->getIceManager());
102 QObject::disconnect();
107 this->setName(this->getDefaultName());
112 return this->workingMemoryProxyFinder->getSelectedProxyName().toStdString();
117 return this->workingMemoryUpdatesTopicFinder->getSelectedProxyName().toStdString();
122 return this->priorKnowledgeProxyFinder->getSelectedProxyName().toStdString();
125 void gui::dialog::SceneEditorConfigDialog::verifyConfiguration()
127 if (this->getWorkingMemoryName().length() == 0)
129 QMessageBox::critical(
this, tr(
"Invalid Configuration"), tr(
"The WorkingMemory name must not be empty."));
131 else if (this->getWorkingMemoryUpdatesTopic().length() == 0)
133 QMessageBox::critical(
this, tr(
"Invalid Configuration"), tr(
"The WorkingMemory updates topic name must not be empty."));
135 else if (!this->isTopicAvailable(this->getWorkingMemoryUpdatesTopic()))
137 QMessageBox::critical(
this, tr(
"Invalid Configuration"), tr(
"The WorkingMemory updates topic name does not name an avaiable topic."));
139 else if (this->getPriorMemoryName().length() == 0)
141 QMessageBox::critical(
this, tr(
"Invalid Configuration"), tr(
"The PriorMemory name must not be empty."));
143 else if (this->ui->settingsFileLineEdit->text().length() == 0)
145 QMessageBox::critical(
this, tr(
"Invalid Configuration"), tr(
"The settings file path name must not be empty."));
155 this->ui->retranslateUi(
this);
160 return this->ui->settingsFileLineEdit->text();
163 void gui::dialog::SceneEditorConfigDialog::fileBrowserToolButtonReleased()
165 std::filesystem::path currentPath(this->ui->settingsFileLineEdit->text().toStdString());
166 QString filePath = QFileDialog::getSaveFileName(
this, tr(
"Open settings file"), QString::fromStdString(currentPath.remove_filename().string()), tr(
"Settings (*.ini)"),
new QString(), QFileDialog::DontConfirmOverwrite);
168 if (!filePath.endsWith(
".ini", Qt::CaseSensitivity::CaseInsensitive) && !filePath.isEmpty())
170 filePath.append(
".ini");
173 this->ui->settingsFileLineEdit->setText(filePath);
176 bool gui::dialog::SceneEditorConfigDialog::isTopicAvailable(std::string topicName)
178 return this->workingMemoryUpdatesTopicFinder->getProxyNameList(
"*").contains(QString::fromStdString(topicName));