SceneEditorConfigDialog.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
25 #include <MemoryX/gui-plugins/SceneEditor/ui_SceneEditorConfigDialog.h>
26 
27 #include <filesystem>
28 #include <filesystem>
29 
30 #include <IceUtil/UUID.h>
31 
32 #include <QComboBox>
33 #include <QMessageBox>
34 #include <QDialogButtonBox>
35 #include <QPushButton>
36 #include <QFileDialog>
37 
39 
40 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
41 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
42 //#include <QtCore/qfsfileengine.h>
43 
44 
46  QDialog(parent),
48 {
49  ui->setupUi(this);
50 
51  workingMemoryProxyFinder = new armarx::IceProxyFinder<memoryx::WorkingMemoryInterfacePrx>(this);
52  workingMemoryProxyFinder->setSearchMask("WorkingMemory");
53  workingMemoryProxyFinder->showSearchMaskField(true);
54  workingMemoryProxyFinder->showLabels(false);
55  ui->workingMemoryGridLayout->addWidget(workingMemoryProxyFinder, 0, 1, 1, 2);
56 
57  workingMemoryUpdatesTopicFinder = new armarx::IceTopicFinder(this);
58  workingMemoryUpdatesTopicFinder->setSearchMask("WorkingMemoryUpdates");
59  workingMemoryUpdatesTopicFinder->showSearchMaskField(false);
60  workingMemoryUpdatesTopicFinder->showLabels(false);
61  ui->workingMemoryGridLayout->addWidget(workingMemoryUpdatesTopicFinder, 1, 1, 1, 2);
62 
63  priorKnowledgeProxyFinder = new armarx::IceProxyFinder<memoryx::PriorKnowledgeInterfacePrx>(this);
64  priorKnowledgeProxyFinder->setSearchMask("PriorKnowledge");
65  priorKnowledgeProxyFinder->showSearchMaskField(true);
66  priorKnowledgeProxyFinder->showLabels(false);
67  ui->priorKnowledgeGridLayout->addWidget(priorKnowledgeProxyFinder, 0, 1, 1, 2);
68 
69  connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(verifyConfiguration()));
70  ui->buttonBox->button(QDialogButtonBox::Ok)->setDefault(false);
71 
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()));
76 }
77 
79 {
80  delete ui;
81 }
82 
84 {
85  return "SceneEditorConfigDialog" + IceUtil::generateUUID();
86 }
87 
89 {
90  workingMemoryProxyFinder->setIceManager(this->getIceManager());
91  workingMemoryUpdatesTopicFinder->setIceManager(this->getIceManager());
92  priorKnowledgeProxyFinder->setIceManager(this->getIceManager());
93 }
94 
96 {
97 
98 }
99 
101 {
102  QObject::disconnect();
103 }
104 
106 {
107  this->setName(this->getDefaultName());
108 }
109 
111 {
112  return this->workingMemoryProxyFinder->getSelectedProxyName().toStdString();
113 }
114 
116 {
117  return this->workingMemoryUpdatesTopicFinder->getSelectedProxyName().toStdString();
118 }
119 
121 {
122  return this->priorKnowledgeProxyFinder->getSelectedProxyName().toStdString();
123 }
124 
125 void gui::dialog::SceneEditorConfigDialog::verifyConfiguration()
126 {
127  if (this->getWorkingMemoryName().length() == 0)
128  {
129  QMessageBox::critical(this, tr("Invalid Configuration"), tr("The WorkingMemory name must not be empty."));
130  }
131  else if (this->getWorkingMemoryUpdatesTopic().length() == 0)
132  {
133  QMessageBox::critical(this, tr("Invalid Configuration"), tr("The WorkingMemory updates topic name must not be empty."));
134  }
135  else if (!this->isTopicAvailable(this->getWorkingMemoryUpdatesTopic()))
136  {
137  QMessageBox::critical(this, tr("Invalid Configuration"), tr("The WorkingMemory updates topic name does not name an avaiable topic."));
138  }
139  else if (this->getPriorMemoryName().length() == 0)
140  {
141  QMessageBox::critical(this, tr("Invalid Configuration"), tr("The PriorMemory name must not be empty."));
142  }
143  else if (this->ui->settingsFileLineEdit->text().length() == 0)
144  {
145  QMessageBox::critical(this, tr("Invalid Configuration"), tr("The settings file path name must not be empty."));
146  }
147  else
148  {
149  this->accept();
150  }
151 }
152 
154 {
155  this->ui->retranslateUi(this);
156 }
157 
159 {
160  return this->ui->settingsFileLineEdit->text();
161 }
162 
163 void gui::dialog::SceneEditorConfigDialog::fileBrowserToolButtonReleased()
164 {
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);
167 
168  if (!filePath.endsWith(".ini", Qt::CaseSensitivity::CaseInsensitive) && !filePath.isEmpty())
169  {
170  filePath.append(".ini");
171  }
172 
173  this->ui->settingsFileLineEdit->setText(filePath);
174 }
175 
176 bool gui::dialog::SceneEditorConfigDialog::isTopicAvailable(std::string topicName)
177 {
178  return this->workingMemoryUpdatesTopicFinder->getProxyNameList("*").contains(QString::fromStdString(topicName));
179 }
gui::dialog::SceneEditorConfigDialog::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: SceneEditorConfigDialog.cpp:153
gui::dialog::SceneEditorConfigDialog::getDefaultName
std::string getDefaultName() const override
Reimplemented armarx::ManagedIceObject:getDefaultName().
Definition: SceneEditorConfigDialog.cpp:83
gui::dialog::SceneEditorConfigDialog::getSettingsFilePath
QString getSettingsFilePath()
Returns the full path to the selected settings file.
Definition: SceneEditorConfigDialog.cpp:158
gui::dialog::SceneEditorConfigDialog::onConnectComponent
void onConnectComponent() override
Reimplemented armarx::ManagedIceObject:onConnectComponent().
Definition: SceneEditorConfigDialog.cpp:95
gui::dialog::SceneEditorConfigDialog::onInitComponent
void onInitComponent() override
Reimplemented armarx::ManagedIceObject:onInitComponent().
Definition: SceneEditorConfigDialog.cpp:88
gui::dialog::SceneEditorConfigDialog::~SceneEditorConfigDialog
~SceneEditorConfigDialog() override
Destructor.
Definition: SceneEditorConfigDialog.cpp:78
SceneEditorConfigDialog.h
gui::dialog::SceneEditorConfigDialog::SceneEditorConfigDialog
SceneEditorConfigDialog(QWidget *parent=0)
Constructor.
Definition: SceneEditorConfigDialog.cpp:45
gui::dialog::SceneEditorConfigDialog
This class provides a dialog derived from Qt::QDialog and armarx::ManagedIceObject.
Definition: SceneEditorConfigDialog.h:50
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
gui::dialog::SceneEditorConfigDialog::getPriorMemoryName
std::string getPriorMemoryName()
Returns selected PriorKnowledge name.
Definition: SceneEditorConfigDialog.cpp:120
IceProxyFinder.h
armarx::IceTopicFinder
The IceTopicFinder class queries and show all available topic registered with IceStorm.
Definition: IceProxyFinder.h:136
armarx::IceProxyFinder
Definition: StatechartViewerController.h:51
gui::dialog::SceneEditorConfigDialog::setIceObjectName
void setIceObjectName()
Sets unic name for this widget.
Definition: SceneEditorConfigDialog.cpp:105
gui::dialog::SceneEditorConfigDialog::getWorkingMemoryUpdatesTopic
std::string getWorkingMemoryUpdatesTopic()
Returns selected WorkingMemory updates topic.
Definition: SceneEditorConfigDialog.cpp:115
gui::dialog::SceneEditorConfigDialog::onExitComponent
void onExitComponent() override
Reimplemented armarx::ManagedIceObject:onExitComponent().
Definition: SceneEditorConfigDialog.cpp:100
gui::dialog::SceneEditorConfigDialog::getWorkingMemoryName
std::string getWorkingMemoryName()
Returns selected WorkingMemory name.
Definition: SceneEditorConfigDialog.cpp:110