25 #include <QCoreApplication>
27 #include <QProgressDialog>
38 #include <SimoxUtility/algorithm/string/string_tools.h>
43 using namespace Controller;
44 using namespace Data_Structure;
45 using namespace Parser;
49 executor(new Executor(
50 stopStrategyFactory.getStopStrategy(StopperFactory::getFactory()->getPidStopper()),
51 StarterFactory::getFactory()->getStarter())),
52 applicationController(packages, executor),
53 detailedApplicationController(executor),
54 scenarioListController(packages, executor),
55 settingsController(packages, executor),
56 openScenarioController(packages, executor),
60 editModeAction =
new QAction(
"Edit Mode",
this);
62 QSettings q_settings(QString(settingsFile.c_str()), QSettings::NativeFormat);
63 bool editModeState = q_settings.value(
"editMode",
false).toBool();
71 bool ScenarioManagerWidgetController::isPackageAutoDiscoveryEnabled()
73 const std::string autodiscoverPropertyName =
"AutodiscoverPackages";
77 return getProperty<bool>(autodiscoverPropertyName).getValue();
80 ARMARX_INFO << autodiscoverPropertyName +
" property not found";
86 void ScenarioManagerWidgetController::autoDiscoverArmarXPackages()
88 QSettings autosettings(QString(settingsFile.c_str()), QSettings::NativeFormat);
92 std::sort(packagesStd.begin(), packagesStd.end(),
93 [](
const std::string& lhs,
const std::string& rhs) ->
bool {
94 return simox::alg::to_lower(lhs) < simox::alg::to_lower(rhs);
98 ARMARX_INFO <<
"Discovered the following ArmarX packages: ";
99 for(
const auto& pkg : packagesStd)
101 packages.push_back(QString::fromStdString(pkg));
105 autosettings.setValue(
"packages", packages);
110 QSettings autosettings(QString(settingsFile.c_str()), QSettings::NativeFormat);
111 QStringList scenarios = settings->value(
"scenarios", QStringList()).toStringList();
112 scenarios.removeDuplicates();
113 if (not scenarios.empty())
115 autosettings.setValue(
"scenarios", scenarios);
117 QStringList packages = settings->value(
"packages", QStringList()).toStringList();
118 packages.removeDuplicates();
119 if (not packages.empty())
121 autosettings.setValue(
"packages", packages);
128 QSettings autosettings(QString(settingsFile.c_str()), QSettings::NativeFormat);
129 auto scenarios = autosettings.value(
"scenarios", QStringList()).toStringList();
130 auto packages = autosettings.value(
"packages", QStringList()).toStringList();
131 scenarios.removeDuplicates();
132 packages.removeDuplicates();
133 settings->setValue(
"scenarios", scenarios);
134 settings->setValue(
"packages", packages);
140 QMetaObject::invokeMethod(
this,
"init", Qt::QueuedConnection);
144 ScenarioManagerWidgetController::init()
152 QObject::connect(widget.scenarioView,
153 SIGNAL(createScenario()),
154 &scenarioListController,
155 SLOT(createScenario()));
158 widget.scenarioView, SIGNAL(createScenario()), widget.applicationDatabase, SLOT(show()));
160 QObject::connect(widget.scenarioView,
161 SIGNAL(removeItem(QModelIndex)),
162 &scenarioListController,
163 SLOT(removeItem(QModelIndex)));
165 QObject::connect(widget.scenarioView,
166 SIGNAL(itemClicked(QModelIndex)),
167 &scenarioListController,
168 SLOT(showApplication(QModelIndex)));
170 QObject::connect(widget.scenarioView,
171 SIGNAL(startApplication(
int,
int, QModelIndex)),
172 &scenarioListController,
173 SLOT(start(
int,
int, QModelIndex)));
175 QObject::connect(widget.scenarioView,
176 SIGNAL(stopApplication(
int,
int, QModelIndex)),
177 &scenarioListController,
178 SLOT(stop(
int,
int, QModelIndex)));
180 QObject::connect(widget.scenarioView,
181 SIGNAL(restartApplication(
int,
int, QModelIndex)),
182 &scenarioListController,
183 SLOT(restart(
int,
int, QModelIndex)));
185 QObject::connect(&settingsController, SIGNAL(packageRemoved()),
this, SLOT(
updateModels()));
187 QObject::connect(&settingsController,
188 SIGNAL(packageAdded(std::string)),
192 QObject::connect(&scenarioListController, SIGNAL(updated()),
this, SLOT(
updateModels()));
195 &scenarioListController,
197 &detailedApplicationController,
200 QObject::connect(&scenarioListController,
202 &detailedApplicationController,
205 QObject::connect(&scenarioListController,
206 SIGNAL(statusUpdated()),
207 widget.detailedApplicationView,
208 SLOT(updateStatus()));
210 QObject::connect(widget.applicationDatabase,
211 SIGNAL(openSettings()),
213 SLOT(showSettings()));
215 QObject::connect(widget.applicationDatabase,
216 SIGNAL(itemClicked(QModelIndex)),
217 &applicationController,
218 SLOT(on_itemClicked(QModelIndex)));
220 QObject::connect(&applicationController,
222 &detailedApplicationController,
225 QObject::connect(&applicationController,
227 &detailedApplicationController,
230 QObject::connect(&openScenarioController, SIGNAL(updated()),
this, SLOT(
updateModels()));
232 QObject::connect(widget.scenarioView,
233 SIGNAL(showOpenDialog()),
234 &openScenarioController,
235 SLOT(showOpenScenarioView()));
237 QObject::connect(widget.detailedApplicationView,
238 SIGNAL(startButtonClicked()),
239 &detailedApplicationController,
242 QObject::connect(widget.detailedApplicationView,
243 SIGNAL(stopButtonClicked()),
244 &detailedApplicationController,
247 QObject::connect(widget.detailedApplicationView,
248 SIGNAL(restartButtonClicked()),
249 &detailedApplicationController,
252 QObject::connect(widget.detailedApplicationView,
253 SIGNAL(toolButtonClicked()),
254 &detailedApplicationController,
255 SLOT(showInStandardEditor()));
257 QObject::connect(widget.detailedApplicationView,
258 SIGNAL(addParameterButtonClicked()),
259 &detailedApplicationController,
260 SLOT(showPropertyAddView()));
262 QObject::connect(widget.detailedApplicationView,
263 SIGNAL(addIceEnvButtonClicked()),
264 &detailedApplicationController,
265 SLOT(showIceEnvVariableAddView()));
268 QObject::connect(widget.detailedApplicationView,
269 SIGNAL(applicationEnabledChange(
bool)),
270 &scenarioListController,
271 SLOT(updateModel()));
273 QObject::connect(&openScenarioController,
274 SIGNAL(showPackageDialog()),
276 SLOT(showPackageAdderView()));
278 QObject::connect(widget.detailedApplicationView,
280 &scenarioListController,
283 QObject::connect(&applicationController,
285 widget.applicationDatabase,
288 if(isPackageAutoDiscoveryEnabled())
291 autoDiscoverArmarXPackages();
294 widget.scenarioView->setModel(scenarioListController.
getTreeModel());
296 connect(editModeAction, SIGNAL(toggled(
bool)),
this, SLOT(
editMode(
bool)));
298 editModeAction->setCheckable(
true);
299 editModeAction->setToolTip(
300 "If toggled the application database and the application property view will be shown.");
302 QSettings settings(QString(settingsFile.c_str()), QSettings::NativeFormat);
303 QStringList packages = settings.value(
"packages").toStringList();
304 packages.removeDuplicates();
306 if (packages.empty())
309 if (application.get() !=
nullptr)
311 for (
const auto& package : application->getArmarXPackageNames())
313 packages << QString::fromStdString(package);
316 settings.setValue(
"packages", packages);
319 bool editModeState = settings.value(
"editMode",
false).toBool();
320 editModeAction->setChecked(editModeState);
323 settingsController.
init();
333 if (parent != customToolbar->parent())
335 customToolbar->setParent(parent);
338 return customToolbar.data();
341 customToolbar =
new QToolBar(parent);
342 customToolbar->setIconSize(QSize(16, 16));
343 customToolbar->addAction(
344 QIcon(
":/icons/configure-3.png"),
"Configure", &settingsController, SLOT(showSettings()));
345 QToolTip::showText(customToolbar->mapToGlobal(QPoint(0, 0)),
346 "Additional Packages can be opened in the settings");
347 customToolbar->addAction(editModeAction);
349 QAction* killallAction =
new QAction(
"Kill All",
this);
350 customToolbar->addAction(killallAction);
351 killallAction->setToolTip(
352 "Kill all armarx applications except guis on this pc (executes 'armarx killAll')");
353 connect(killallAction,
355 [] { [[maybe_unused]]
auto result = std::system(
"armarx killAll"); });
357 return customToolbar.data();
374 QSettings settings(QString(settingsFile.c_str()), QSettings::NativeFormat);
375 QStringList packages = settings.value(
"packages").toStringList();
376 packages.removeDuplicates();
378 QProgressDialog progress(
"Loading scenarios from " + QString::number(packages.size()) +
384 progress.setWindowModality(Qt::WindowModal);
387 bool didNotFindSomePackages =
false;
388 for (
int i = 0; i < packages.size(); i++)
390 std::string name = packages.at(i).toStdString();
391 progress.setLabelText(QString(
"Loading scenarios from package ") + name.c_str());
392 progress.setValue(i + 1);
393 qApp->processEvents();
395 QStringList openedScenarios = settings.value(
"scenarios").toStringList();
397 openedScenarios = openedScenarios.toSet().values();
400 for (
const QString& it : openedScenarios)
402 openedList.push_back(it.toStdString());
405 PackagePtr package = parser.parsePackage(name, openedList);
406 if (package ==
nullptr)
408 didNotFindSomePackages =
true;
412 this->packages->push_back(package);
415 if (didNotFindSomePackages)
417 std::stringstream ss;
418 ss <<
"To remove unavailable packages, "
419 <<
"open the configuration (wrench icon at the top of the ScenarioManager), "
420 <<
"switch to the 'Cache Settings' tab, "
421 <<
"and press 'Close unavailable packages'. Cheers!";
432 PackagePtr package = parser.parsePackage(name, StringList());
434 this->packages->push_back(package);
446 widget.detailedApplicationView->updateStatus();
455 QSettings settings(QString(settingsFile.c_str()), QSettings::NativeFormat);
456 settings.setValue(
"editMode", edit);
457 widget.detailedApplicationView->setVisible(edit);
458 widget.applicationDatabase->setVisible(edit);