37 #include <QCloseEvent>
38 #include <QCoreApplication>
40 #include <QFileDialog>
41 #include <QHBoxLayout>
42 #include <QInputDialog>
44 #include <QMessageBox>
59 : m_client(nullptr), m_last_exploration(), m_settings(
"simPT Consortium",
"Parex Client")
62 QCoreApplication::setOrganizationName(
"SimPT Consortium");
63 QCoreApplication::setApplicationName(
"Parex Client");
65 setWindowTitle(
"Parameter Exploration - Client");
69 QHBoxLayout* layout =
new QHBoxLayout;
72 layout->addWidget(m_status);
75 action_connect =
new QAction(
"&Connect...",
this);
76 action_subscribe =
new QAction(
"&Subscribe",
this);
77 action_start_exploration =
new QAction(
"&Start Exploration...",
this);
78 action_delete_exploration =
new QAction(
"&Delete exploration...",
this);
79 action_download_exploration =
new QAction(
"&Download exploration...",
this);
80 action_workspace_wizard =
new QAction(
"&Workspace...",
this);
81 action_task_overview =
new QAction(
"&Task overview",
this);
83 action_subscribe->setDisabled(
true);
84 action_start_exploration->setDisabled(
true);
85 action_delete_exploration->setDisabled(
true);
86 action_download_exploration->setDisabled(
true);
87 action_task_overview->setDisabled(
true);
90 action_download_exploration->setVisible(
false);
92 action_connect->setShortcut(QKeySequence(
"Ctrl+C"));
93 action_subscribe->setShortcut(QKeySequence(
"Ctrl+U"));
94 action_start_exploration->setShortcut(QKeySequence(
"Ctrl+E"));
95 action_delete_exploration->setShortcut(QKeySequence(
"Ctrl+Shift+E"));
96 action_workspace_wizard->setShortcut(QKeySequence(
"Ctrl+W"));
97 action_task_overview->setShortcut(QKeySequence(
"Ctrl+T"));
102 QMenu* menu_server =
new QMenu(
"&Server", menu);
103 menu_server->addAction(action_connect);
104 menu_server->addSeparator();
105 menu_server->addAction(action_subscribe);
106 menu_server->addAction(action_task_overview);
107 menu->addMenu(menu_server);
109 QMenu* menu_exploration =
new QMenu(
"&Exploration", menu);
110 menu_exploration->addAction(action_start_exploration);
111 menu_exploration->addAction(action_delete_exploration);
112 menu_exploration->addAction(action_download_exploration);
113 menu->addMenu(menu_exploration);
115 QMenu* menu_workspace =
new QMenu(
"&Workspace", menu);
116 menu_workspace->addAction(action_workspace_wizard);
117 menu->addMenu(menu_workspace);
120 QToolBar* toolbar =
new QToolBar(
this);
121 toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
122 toolbar->setMovable(
false);
123 toolbar->addAction(action_connect);
124 toolbar->addAction(action_subscribe);
125 toolbar->addSeparator();
126 toolbar->addAction(action_start_exploration);
127 toolbar->addAction(action_delete_exploration);
128 toolbar->addAction(action_download_exploration);
129 toolbar->addSeparator();
130 toolbar->addAction(action_task_overview);
133 connect(action_connect, SIGNAL(triggered()),
this, SLOT(Connect()));
134 connect(action_subscribe, SIGNAL(triggered()),
this, SLOT(Subscribe()));
135 connect(action_start_exploration, SIGNAL(triggered()),
this, SLOT(StartExploration()));
136 connect(action_delete_exploration, SIGNAL(triggered()),
this, SLOT(DeleteExploration()));
137 connect(action_download_exploration, SIGNAL(triggered()),
this, SLOT(DownloadExploration()));
139 connect(action_workspace_wizard, SIGNAL(triggered()),
this, SLOT(SetWorkspace()));
140 connect(action_task_overview, SIGNAL(triggered()),
this, SLOT(ShowTaskOverview()));
143 m_statusbar =
new QStatusBar(
this);
144 m_statusbar->clearMessage();
146 m_connection_button =
new QPushButton(
"Not Connected");
147 m_connection_button->setFlat(
true);
148 connect(m_connection_button, SIGNAL(clicked()), action_connect, SLOT(trigger()));
149 m_statusbar->addPermanentWidget(m_connection_button);
150 setStatusBar(m_statusbar);
153 central->setLayout(layout);
154 setCentralWidget(central);
157 connect(m_task_view, SIGNAL(StopTask(
int)),
this, SLOT(StopTask(
int)));
158 connect(m_task_view, SIGNAL(StartTask(
int)),
this, SLOT(RestartTask(
int)));
161 if (m_settings.contains(
"workspace"))
162 m_workspace_path = m_settings.value(
"workspace").toString().toStdString();
172 void Client::InitWorkspace()
174 if (m_workspace_path ==
"" || !QDir(QString(m_workspace_path.c_str())).exists()) {
175 auto f = std::make_shared<SimPT_Shell::Ws::WorkspaceFactory>();
177 if (wizard.exec() == QDialog::Accepted)
178 m_workspace_path = wizard.GetWorkspaceDir();
184 void Client::Connect()
186 ServerDialog* dialog =
new ServerDialog(m_workspace_path);
187 if (dialog->exec() == QDialog::Accepted) {
188 auto server = dialog->GetServer();
189 m_client =
new ClientProtocol(server,
this);
191 QMessageBox::critical(
this,
"Connection Error",
"Could not connect to server.",
196 connect(m_client, SIGNAL(Ended()),
this, SLOT(Disconnected()));
197 connect(m_client, SIGNAL(ExplorationStatus(
const ExplorationProgress*)),
198 this, SLOT(UpdateStatus(
const ExplorationProgress*)));
199 connect(m_client, SIGNAL(ExplorationDeleted()),
this, SLOT(ExplorationDeleted()));
200 Connected(server->GetName().toStdString());
205 void Client::Disconnect()
207 assert(m_client !=
nullptr);
209 if (QMessageBox::question(
this,
"Disconnect",
"Are you sure you want to disconnect from the server?",
210 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
215 void Client::Subscribe()
217 assert(m_client !=
nullptr);
219 ExplorationSelection select_exploration(
true);
220 connect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
221 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
223 m_subscribed_exploration =
"";
225 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
230 if (select_exploration.exec() == QDialog::Accepted) {
231 if (select_exploration.Selected()) {
232 m_subscribed_exploration = select_exploration.GetSelection().at(0);
234 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
239 disconnect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
240 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
243 void Client::StartExploration()
245 assert(m_client !=
nullptr);
249 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
254 std::shared_ptr<const ParameterExploration> exploration
255 = std::dynamic_pointer_cast<
const ParameterExploration>(m_last_exploration);
256 ExplorationWizard wizard(
Ws::CliWorkspace(m_workspace_path).GetPreferences(), exploration,
this);
257 if (wizard.exec() == QDialog::Accepted) {
259 m_last_exploration = wizard.GetExploration();
261 QMessageBox::critical(
this,
"Connection Error",
262 "Not connected to server. Exploration will be saved.", QMessageBox::Abort);
264 QMessageBox::information(
this,
"Exploration sent",
265 "Exploration successfully sent.", QMessageBox::Ok);
270 void Client::DeleteExploration()
272 assert(m_client !=
nullptr);
274 ExplorationSelection select_exploration;
275 connect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
276 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
279 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
284 if (select_exploration.exec() == QDialog::Accepted) {
285 if (select_exploration.Selected()) {
286 if (QMessageBox::question(
this,
"Delete exploration",
287 "Are you sure you want to delete the exploration(s) from the server?",
288 QMessageBox::Yes | QMessageBox::No, QMessageBox::No) == QMessageBox::Yes) {
289 for (
auto exploration : select_exploration.GetSelection()) {
291 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
300 disconnect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
301 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
304 void Client::DownloadExploration()
306 assert(m_client !=
nullptr);
308 ExplorationSelection select_exploration;
309 connect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
310 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
313 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
318 if (select_exploration.exec() == QDialog::Accepted) {
319 if (select_exploration.Selected()) {
333 disconnect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
334 &select_exploration, SLOT(UpdateExplorations(std::vector<std::string>)));
337 void Client::StopTask(
int task)
339 assert(m_client !=
nullptr);
341 if (!m_client->
StopTask(m_subscribed_exploration, task))
342 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
346 void Client::RestartTask(
int task)
348 assert(m_client !=
nullptr);
350 if (!m_client->
RestartTask(m_subscribed_exploration, task))
351 QMessageBox::critical(
this,
"Connection Error",
"Not connected to server.",
352 QMessageBox::Abort);}
354 void Client::ShowTaskOverview()
359 void Client::SetWorkspace()
361 m_workspace_path =
"";
365 void Client::Connected(std::string name)
367 m_connection_button->setText(
"Connected with: " + QString(name.c_str()));
369 if (m_subscribed_exploration !=
"") {
370 connect(m_client, SIGNAL(ExplorationNames(std::vector<std::string>)),
371 this, SLOT(ConnectExplorationNames(std::vector<std::string>)));
375 action_connect->setText(
"&Disconnect...");
376 disconnect(action_connect, SIGNAL(triggered()),
this, SLOT(Connect()));
377 connect(action_connect, SIGNAL(triggered()),
this, SLOT(Disconnect()));
378 action_subscribe->setDisabled(
false);
379 action_start_exploration->setDisabled(
false);
380 action_delete_exploration->setDisabled(
false);
381 action_download_exploration->setDisabled(
false);
386 void Client::ConnectExplorationNames(
const std::vector<std::string> &names)
388 assert(m_client !=
nullptr);
390 for (
auto name : names) {
391 if (name == m_subscribed_exploration) {
397 UpdateStatus(
nullptr);
400 void Client::Disconnected()
405 m_connection_button->setText(
"Not Connected");
406 if (m_task_view->isVisible()) {
407 m_task_view->close();
410 action_connect->setText(
"&Connect...");
411 disconnect(action_connect, SIGNAL(triggered()),
this, SLOT(Disconnect()));
412 connect(action_connect, SIGNAL(triggered()),
this, SLOT(Connect()));
413 action_subscribe->setDisabled(
true);
414 action_start_exploration->setDisabled(
true);
415 action_delete_exploration->setDisabled(
true);
416 action_download_exploration->setDisabled(
true);
417 action_task_overview->setDisabled(
true);
422 void Client::UpdateStatus(
const ExplorationProgress *status)
424 std::shared_ptr<const ExplorationProgress> progress(status);
425 m_subscribed_exploration = progress->GetExploration().GetName();
428 action_task_overview->setDisabled(
false);
431 void Client::ExplorationDeleted()
433 assert(m_client !=
nullptr);
435 if (m_subscribed_exploration !=
"") {
438 m_subscribed_exploration =
"";
441 action_task_overview->setDisabled(
true);
Interface for WorkspaceWizard.
virtual ~Client()
Destructor.
Interface for ServerInfo.
see the online Qt documentation
bool RequestExplorationNames()
Request a list of current Explorations.
Interface for TaskOverview.
Interface for ExplorationWizard.
SimPT-specific implementation of workspace factory.
Namespace for SimPT shell package.
Interface for ExplorationSelection.
bool RestartTask(const std::string &name, int task)
Request to restart a task.
bool SubscribeUpdates(const std::string &explorationName)
Subscribe for regular updates.
see the online Qt documentation
A wizard that assists the user either specifying an existing workspace, or creating a new workspace...
void UpdateStatus(const std::shared_ptr< const ExplorationProgress > &progress)
Update the status of an exploration.
bool SendExploration(const Exploration *exploration)
Send exploration.
Interface for ClientProtocol.
void UpdateExploration(const std::shared_ptr< const ExplorationProgress > &explorationProgress)
Update the current exploration.
bool DeleteExploration(const std::string &name)
Request a stop and delete of the given exploration.
Cli Workspace for the command-line simulator.
see the online Qt documentation
Namespace for SimPT parameter explorer package.
Interface for ServerDialog.
bool UnsubscribeUpdates(const std::string &explorationName)
Unsubscribe for regular updates.
bool IsConnected()
Check if still connected.
bool StopTask(const std::string &name, int task)
Request to stop a task.
Widget to display status of subscribed exploration.
void Disconnected()
Set font to disconnected state.
Interface for ParameterExploration.
Interface for ExplorationProgress.
void Connected()
Set font to connected state.