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
42
43
44using namespace ScenarioManager;
45using namespace Controller;
46using namespace Exec;
47using 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
62
63void
68
69void
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
88void
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
107void
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
123void
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
136void
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
154void
155DetailedApplicationController::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
176void
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
200void
201DetailedApplicationController::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
245void
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
261void
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
287void
291
292void
294{
295 propertyAdderView.exec();
296}
297
298void
299DetailedApplicationController::showWarningDialog(QString message)
300{
301 QMessageBox box;
302 box.setText(message);
303 box.exec();
304}
305
306void
308{
309 this->iceAdmin = iceAdmin;
310}
View that shows detailed information about a Scenario, Package or Application.
TreeItem representing data contained in a Scenario or an Application.
void showApplication(Data_Structure::ApplicationPtr application)
Shows an Application in the DetailedApplicationView.
void showPackage(Data_Structure::PackagePtr package)
Shows a Package in the DetailedApplicationView.
void deleteProperty(std::string name)
Deletes a property off the configuration file of the current ApplicationInstance.
void setDetailedApplicationView(DetailedApplicationView *ptr)
Sets the view this controller manages.
DetailedApplicationController(Exec::ExecutorPtr executor, QObject *parent=0)
Constructor that optionally sets the parent object.
void setIceAdmin(IceGrid::AdminPrx iceAdmin)
Set an IceAdmin for the controller.
void showScenario(Data_Structure::ScenarioPtr scenario)
Shows a Scenario in the DetailedApplicationView.
void save()
Saves the configuration of the current ApplicationInstance to the config file.
void showInStandardEditor()
Shows the configuration of the current ApplicationInstance in the standard editor.
void setProperty(std::string name, std::string value)
Sets a property of the current ApplicationInstance.
void showApplicationInstance(Data_Structure::ApplicationInstancePtr application, ScenarioItem *item)
Shows an ApplicationInstance in the DetailedApplicationView.
static bool StartScenario(ScenarioManager::Data_Structure::ScenarioPtr scenario, Exec::ExecutorPtr executor, IceGrid::AdminPrx iceAdmin)
Class containing data about an application Provides methods to get and set the date contained in the ...
Definition Application.h:47
static std::string getCacheDir()
std::shared_ptr< Scenario > ScenarioPtr
Definition Scenario.h:35
std::shared_ptr< Application > ApplicationPtr
std::shared_ptr< Package > PackagePtr
Definition Package.h:122
std::shared_ptr< ApplicationInstance > ApplicationInstancePtr
std::shared_ptr< Executor > ExecutorPtr
Definition Executor.h:175