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 
26 #include <filesystem>
27 
28 #include <QComboBox>
29 #include <QDialogButtonBox>
30 #include <QFileDialog>
31 #include <QMessageBox>
32 #include <QPushButton>
33 
34 #include <IceUtil/UUID.h>
35 
37 
38 #include <MemoryX/gui-plugins/SceneEditor/ui_SceneEditorConfigDialog.h>
39 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
40 #include <MemoryX/interface/components/WorkingMemoryInterface.h>
41 
42 //#include <QtCore/qfsfileengine.h>
43 
44 
46  QDialog(parent), ui(new Ui::SceneEditorConfigDialog)
47 {
48  ui->setupUi(this);
49 
50  workingMemoryProxyFinder = new armarx::IceProxyFinder<memoryx::WorkingMemoryInterfacePrx>(this);
51  workingMemoryProxyFinder->setSearchMask("WorkingMemory");
52  workingMemoryProxyFinder->showSearchMaskField(true);
53  workingMemoryProxyFinder->showLabels(false);
54  ui->workingMemoryGridLayout->addWidget(workingMemoryProxyFinder, 0, 1, 1, 2);
55 
56  workingMemoryUpdatesTopicFinder = new armarx::IceTopicFinder(this);
57  workingMemoryUpdatesTopicFinder->setSearchMask("WorkingMemoryUpdates");
58  workingMemoryUpdatesTopicFinder->showSearchMaskField(false);
59  workingMemoryUpdatesTopicFinder->showLabels(false);
60  ui->workingMemoryGridLayout->addWidget(workingMemoryUpdatesTopicFinder, 1, 1, 1, 2);
61 
62  priorKnowledgeProxyFinder =
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(
75  QString::fromStdString((currentPath / defaultFile).string()));
76  connect(
77  ui->fileBrowserToolButton, SIGNAL(released()), this, SLOT(fileBrowserToolButtonReleased()));
78 }
79 
81 {
82  delete ui;
83 }
84 
85 std::string
87 {
88  return "SceneEditorConfigDialog" + IceUtil::generateUUID();
89 }
90 
91 void
93 {
94  workingMemoryProxyFinder->setIceManager(this->getIceManager());
95  workingMemoryUpdatesTopicFinder->setIceManager(this->getIceManager());
96  priorKnowledgeProxyFinder->setIceManager(this->getIceManager());
97 }
98 
99 void
101 {
102 }
103 
104 void
106 {
107  QObject::disconnect();
108 }
109 
110 void
112 {
113  this->setName(this->getDefaultName());
114 }
115 
116 std::string
118 {
119  return this->workingMemoryProxyFinder->getSelectedProxyName().toStdString();
120 }
121 
122 std::string
124 {
125  return this->workingMemoryUpdatesTopicFinder->getSelectedProxyName().toStdString();
126 }
127 
128 std::string
130 {
131  return this->priorKnowledgeProxyFinder->getSelectedProxyName().toStdString();
132 }
133 
134 void
135 gui::dialog::SceneEditorConfigDialog::verifyConfiguration()
136 {
137  if (this->getWorkingMemoryName().length() == 0)
138  {
139  QMessageBox::critical(
140  this, tr("Invalid Configuration"), tr("The WorkingMemory name must not be empty."));
141  }
142  else if (this->getWorkingMemoryUpdatesTopic().length() == 0)
143  {
144  QMessageBox::critical(this,
145  tr("Invalid Configuration"),
146  tr("The WorkingMemory updates topic name must not be empty."));
147  }
148  else if (!this->isTopicAvailable(this->getWorkingMemoryUpdatesTopic()))
149  {
150  QMessageBox::critical(
151  this,
152  tr("Invalid Configuration"),
153  tr("The WorkingMemory updates topic name does not name an avaiable topic."));
154  }
155  else if (this->getPriorMemoryName().length() == 0)
156  {
157  QMessageBox::critical(
158  this, tr("Invalid Configuration"), tr("The PriorMemory name must not be empty."));
159  }
160  else if (this->ui->settingsFileLineEdit->text().length() == 0)
161  {
162  QMessageBox::critical(this,
163  tr("Invalid Configuration"),
164  tr("The settings file path name must not be empty."));
165  }
166  else
167  {
168  this->accept();
169  }
170 }
171 
172 void
174 {
175  this->ui->retranslateUi(this);
176 }
177 
178 QString
180 {
181  return this->ui->settingsFileLineEdit->text();
182 }
183 
184 void
185 gui::dialog::SceneEditorConfigDialog::fileBrowserToolButtonReleased()
186 {
187  std::filesystem::path currentPath(this->ui->settingsFileLineEdit->text().toStdString());
188  QString filePath =
189  QFileDialog::getSaveFileName(this,
190  tr("Open settings file"),
191  QString::fromStdString(currentPath.remove_filename().string()),
192  tr("Settings (*.ini)"),
193  new QString(),
194  QFileDialog::DontConfirmOverwrite);
195 
196  if (!filePath.endsWith(".ini", Qt::CaseSensitivity::CaseInsensitive) && !filePath.isEmpty())
197  {
198  filePath.append(".ini");
199  }
200 
201  this->ui->settingsFileLineEdit->setText(filePath);
202 }
203 
204 bool
205 gui::dialog::SceneEditorConfigDialog::isTopicAvailable(std::string topicName)
206 {
207  return this->workingMemoryUpdatesTopicFinder->getProxyNameList("*").contains(
208  QString::fromStdString(topicName));
209 }
gui::dialog::SceneEditorConfigDialog::retranslate
void retranslate()
Translates all translatable strings in this dialog.
Definition: SceneEditorConfigDialog.cpp:173
gui::dialog::SceneEditorConfigDialog::getDefaultName
std::string getDefaultName() const override
Reimplemented armarx::ManagedIceObject:getDefaultName().
Definition: SceneEditorConfigDialog.cpp:86
gui::dialog::SceneEditorConfigDialog::getSettingsFilePath
QString getSettingsFilePath()
Returns the full path to the selected settings file.
Definition: SceneEditorConfigDialog.cpp:179
gui::dialog::SceneEditorConfigDialog::onConnectComponent
void onConnectComponent() override
Reimplemented armarx::ManagedIceObject:onConnectComponent().
Definition: SceneEditorConfigDialog.cpp:100
gui::dialog::SceneEditorConfigDialog::onInitComponent
void onInitComponent() override
Reimplemented armarx::ManagedIceObject:onInitComponent().
Definition: SceneEditorConfigDialog.cpp:92
gui::dialog::SceneEditorConfigDialog::~SceneEditorConfigDialog
~SceneEditorConfigDialog() override
Destructor.
Definition: SceneEditorConfigDialog.cpp:80
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:51
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
gui::dialog::SceneEditorConfigDialog::getPriorMemoryName
std::string getPriorMemoryName()
Returns selected PriorKnowledge name.
Definition: SceneEditorConfigDialog.cpp:129
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:49
gui::dialog::SceneEditorConfigDialog::setIceObjectName
void setIceObjectName()
Sets unic name for this widget.
Definition: SceneEditorConfigDialog.cpp:111
gui::dialog::SceneEditorConfigDialog::getWorkingMemoryUpdatesTopic
std::string getWorkingMemoryUpdatesTopic()
Returns selected WorkingMemory updates topic.
Definition: SceneEditorConfigDialog.cpp:123
gui::dialog::SceneEditorConfigDialog::onExitComponent
void onExitComponent() override
Reimplemented armarx::ManagedIceObject:onExitComponent().
Definition: SceneEditorConfigDialog.cpp:105
gui::dialog::SceneEditorConfigDialog::getWorkingMemoryName
std::string getWorkingMemoryName()
Returns selected WorkingMemory name.
Definition: SceneEditorConfigDialog.cpp:117