DetailedApplicationController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-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 ArmarXCore::core
19  * @author Cedric Seehausen (usdnr at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
26 
27 #include <stdlib.h>
28 
29 #include <string>
30 
31 #include <QDesktopServices>
32 #include <QMessageBox>
33 #include <QUrl>
34 
40 
41 #include "ScenarioListController.h"
42 
43 
44 using namespace ScenarioManager;
45 using namespace Controller;
46 using namespace Exec;
47 using namespace Data_Structure;
48 
50  QObject* parent) :
51  QObject(parent), executor(executor), showingStartable(false)
52 {
53  QObject::connect(&propertyAdderView,
54  SIGNAL(create(std::string, std::string)),
55  this,
56  SLOT(setProperty(std::string, std::string)));
57 }
58 
60 {
61 }
62 
63 void
65 {
66  view = ptr;
67 }
68 
69 void
71  ScenarioItem* item)
72 {
73  if (application.get() == nullptr)
74  {
75  return;
76  }
77  showingStartable = true;
78  currentApplication = application;
79  currentScenario = ScenarioPtr();
80 
81  executor->loadAndSetCachedProperties(
82  application, Parser::IceParser::getCacheDir(), false, false);
83  application->load();
84  view->setVisible(true);
85  view->showApplicationInstance(application, item);
86 }
87 
88 void
91 {
92  if (application.get() == nullptr)
93  {
94  return;
95  }
96  showingStartable = false;
97  currentApplication = ApplicationInstancePtr();
98  currentScenario = ScenarioPtr();
101  executor->loadAndSetCachedProperties(app, Parser::IceParser::getCacheDir());
102 
103  view->setVisible(true);
104  view->showApplication(app);
105 }
106 
107 void
109 {
110  if (scenario.get() == nullptr)
111  {
112  return;
113  }
114  showingStartable = true;
115  currentApplication = ApplicationInstancePtr();
116  currentScenario = scenario;
117 
118  scenario->reloadGlobalConf();
119  view->setVisible(true);
120  view->showScenario(scenario);
121 }
122 
123 void
125 {
126  if (package.get() == nullptr)
127  {
128  return;
129  }
130  showingStartable = false;
131  currentApplication = ApplicationInstancePtr();
132  currentScenario = ScenarioPtr();
133  view->showPackage(package);
134 }
135 
136 void
138 {
139  if (showingStartable)
140  {
141  std::string url = "file://";
142  if (currentApplication.get() != nullptr)
143  {
144  url.append(currentApplication->getConfigPath());
145  }
146  else if (currentScenario.get() != nullptr)
147  {
148  url.append(currentScenario->getGlobalConfigPath());
149  }
150  QDesktopServices::openUrl(QUrl(url.c_str()));
151  }
152 }
153 
154 void
155 DetailedApplicationController::setProperty(std::string name, std::string value)
156 {
157  if (showingStartable)
158  {
159  if (currentApplication.get() != nullptr)
160  {
161  currentApplication->addProperty(name, value);
162  currentApplication->save();
163  showApplicationInstance(currentApplication, nullptr);
164  }
165  else if (currentScenario.get() != nullptr)
166  {
167  currentScenario->getGlobalConfig()->defineOptionalProperty<std::string>(
168  name, "::NOT_DEFINED::", "Custom Property");
169  currentScenario->getGlobalConfig()->getProperties()->setProperty(name, value);
170  currentScenario->save();
171  showScenario(currentScenario);
172  }
173  }
174 }
175 
176 void
178 {
179  if (showingStartable)
180  {
181  if (currentApplication.get() != nullptr)
182  {
183  executor->startApplication(currentApplication);
184  }
185  else if (currentScenario.get() != nullptr)
186  {
187  try
188  {
189  startScenario(currentScenario);
190  }
191  catch (IceGrid::ServerStartException& ex)
192  {
193  showWarningDialog("Ice had an launching error. Please make sure your remote launch "
194  "settings are correct");
195  }
196  }
197  }
198 }
199 
200 void
201 DetailedApplicationController::startScenario(ScenarioPtr scenario)
202 {
203 
204  StatusManager statusManager;
205  ScenarioListController::StartScenario(scenario, executor, iceAdmin);
206 
207  // StatusManager statusManager;
208  // StopStrategyFactory stopStrategyFactory;
209 
210  // if (scenario->getScenarioDeploymentType() == ScenarioDeploymentType::Local)
211  // {
212  // executor->setStarter(StarterFactory::getFactory()->getStarter(), scenario);
213  // executor->setStopStrategy(executor->getDefaultStopStrategy(), scenario);
214  // executor->startScenario(scenario);
215  // }
216  // else
217  // {
218  // executor->setStarter(StarterFactory::getFactory()->getIceStarter(iceAdmin), scenario);
219  // executor->setStopStrategy(stopStrategyFactory.getKillStrategy(StopperFactory::getFactory()->getIceStopper(iceAdmin)), scenario);
220  // if (executor->isScenarioDeployed(scenario))
221  // {
222  // try
223  // {
224  // executor->startScenario(scenario).get();
225  // }
226  // catch (IceGrid::ServerStartException& ex)
227  // {
228  // showWarningDialog("Ice had an launching error. Please make sure your remote launch settings are correct");
229  // }
230  // }
231  // else
232  // {
233  // try
234  // {
235  // executor->deployScenario(scenario).get();
236  // }
237  // catch (IceGrid::DeploymentException& ex)
238  // {
239  // showWarningDialog(QString::fromStdString(ex.reason));
240  // }
241  // }
242  // }
243 }
244 
245 void
247 {
248  if (showingStartable)
249  {
250  if (currentApplication.get() != nullptr)
251  {
252  executor->stopApplication(currentApplication);
253  }
254  else if (currentScenario.get() != nullptr)
255  {
256  executor->stopScenario(currentScenario);
257  }
258  }
259 }
260 
261 void
263 {
264  if (showingStartable)
265  {
266  if (currentApplication.get() != nullptr)
267  {
268  currentApplication->save();
269  executor->restartApplication(currentApplication);
270  }
271  else if (currentScenario.get() != nullptr)
272  {
273  currentScenario->save();
274  try
275  {
276  executor->restartScenario(currentScenario);
277  }
278  catch (IceGrid::ServerStartException& ex)
279  {
280  showWarningDialog("Ice had an launching error. Please make sure your remote launch "
281  "settings are correct");
282  }
283  }
284  }
285 }
286 
287 void
289 {
290 }
291 
292 void
294 {
295  propertyAdderView.exec();
296 }
297 
298 void
299 DetailedApplicationController::showWarningDialog(QString message)
300 {
301  QMessageBox box;
302  box.setText(message);
303  box.exec();
304 }
305 
306 void
308 {
309  this->iceAdmin = iceAdmin;
310 }
ScenarioItem
TreeItem representing data contained in a Scenario or an Application.
Definition: scenarioitem.h:38
ScenarioManager::Data_Structure::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Definition: Scenario.h:36
iceparser.h
Scenario.h
ScenarioManager::Controller::ScenarioListController::StartScenario
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
Definition: ScenarioListController.cpp:893
ScenarioManager::Controller::DetailedApplicationController::~DetailedApplicationController
~DetailedApplicationController() override
Destructor.
Definition: DetailedApplicationController.cpp:59
ScenarioManager::Data_Structure::ApplicationPtr
std::shared_ptr< Application > ApplicationPtr
Definition: Application.h:119
DetailedApplicationView::showApplication
void showApplication(ScenarioManager::Data_Structure::ApplicationPtr application)
Show an Application.
Definition: detailedapplicationview.cpp:140
StopperFactory.h
ScenarioManager::Controller::DetailedApplicationController::DetailedApplicationController
DetailedApplicationController(Exec::ExecutorPtr executor, QObject *parent=0)
Constructor that optionally sets the parent object.
Definition: DetailedApplicationController.cpp:49
message
message(STATUS "Boost-Library-Dir: " "${Boost_LIBRARY_DIRS}") message(STATUS "Boost-LIBRARIES
Definition: CMakeLists.txt:8
ScenarioManager::Exec::ExecutorPtr
std::shared_ptr< Executor > ExecutorPtr
Definition: Executor.h:164
ScenarioManager::Controller::DetailedApplicationController::save
void save()
Saves the configuration of the current ApplicationInstance to the config file.
Definition: DetailedApplicationController.cpp:262
ScenarioManager::Controller::DetailedApplicationController::setProperty
void setProperty(std::string name, std::string value)
Sets a property of the current ApplicationInstance.
Definition: DetailedApplicationController.cpp:155
ApplicationInstancePtr
std::shared_ptr< ScenarioManager::Data_Structure::ApplicationInstance > ApplicationInstancePtr
Definition: StopStrategy.h:7
ScenarioManager::Controller::DetailedApplicationController::showPackage
void showPackage(Data_Structure::PackagePtr package)
Shows a Package in the DetailedApplicationView.
Definition: DetailedApplicationController.cpp:124
ScenarioManager::Controller::DetailedApplicationController::showPropertyAddView
void showPropertyAddView()
Definition: DetailedApplicationController.cpp:293
ScenarioManager::Data_Structure::Application
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition: Application.h:45
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
ScenarioManager::Data_Structure::PackagePtr
std::shared_ptr< Package > PackagePtr
Definition: Package.h:121
ScenarioManager::Controller::DetailedApplicationController::deleteProperty
void deleteProperty(std::string name)
Deletes a property off the configuration file of the current ApplicationInstance.
Definition: DetailedApplicationController.cpp:288
ScenarioManager::Controller::DetailedApplicationController::setDetailedApplicationView
void setDetailedApplicationView(DetailedApplicationView *ptr)
Sets the view this controller manages.
Definition: DetailedApplicationController.cpp:64
ScenarioManager::Controller::DetailedApplicationController::showApplication
void showApplication(Data_Structure::ApplicationPtr application)
Shows an Application in the DetailedApplicationView.
Definition: DetailedApplicationController.cpp:89
ScenarioManager::Controller::DetailedApplicationController::setIceAdmin
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
Definition: DetailedApplicationController.cpp:307
DetailedApplicationView::showScenario
void showScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario)
Show a Scenario.
Definition: detailedapplicationview.cpp:473
ScenarioManager::StatusManager
Definition: StatusManager.h:7
ScenarioManager::Parser::IceParser::getCacheDir
static std::string getCacheDir()
Definition: iceparser.cpp:304
DetailedApplicationView::showApplicationInstance
void showApplicationInstance(ScenarioManager::Data_Structure::ApplicationInstancePtr appInstance, ScenarioItem *item)
Show an ApplicationInstance.
Definition: detailedapplicationview.cpp:238
ScenarioManager
Definition: Application.cpp:166
StopStrategyFactory.h
DetailedApplicationView::showPackage
void showPackage(ScenarioManager::Data_Structure::PackagePtr package)
Show a Package.
Definition: detailedapplicationview.cpp:664
ScenarioManager::Controller::DetailedApplicationController::showInStandardEditor
void showInStandardEditor()
Shows the configuration of the current ApplicationInstance in the standard editor.
Definition: DetailedApplicationController.cpp:137
ScenarioListController.h
ScenarioManager::Controller::DetailedApplicationController::stop
void stop()
Stops the current ApplicationInstance.
Definition: DetailedApplicationController.cpp:246
DetailedApplicationController.h
StarterFactory.h
DetailedApplicationView
View that shows detailed information about a Scenario, Package or Application. Shows status and param...
Definition: detailedapplicationview.h:52
ScenarioManager::Controller::DetailedApplicationController::start
void start()
Starts the current ApplicationInstance.
Definition: DetailedApplicationController.cpp:177
ScenarioManager::Controller::DetailedApplicationController::showScenario
void showScenario(Data_Structure::ScenarioPtr scenario)
Shows a Scenario in the DetailedApplicationView.
Definition: DetailedApplicationController.cpp:108
ScenarioManager::Controller::DetailedApplicationController::showApplicationInstance
void showApplicationInstance(Data_Structure::ApplicationInstancePtr application, ScenarioItem *item)
Shows an ApplicationInstance in the DetailedApplicationView.
Definition: DetailedApplicationController.cpp:70