30 #include <QListWidget>
31 #include <QMessageBox>
35 #include <SimoxUtility/algorithm/string.h>
36 #include <SimoxUtility/algorithm/string/string_tools.h>
49 defineOptionalProperty<std::string>(
50 "LoadPlugins",
"",
"List of paths to GuiPlugin-Libs (semi-colon seperated)");
51 defineOptionalProperty<std::string>(
52 "GuiConfigFile",
"",
"Path to config file, that should be loaded on startup");
53 defineOptionalProperty<bool>(
"DisablePreloading",
55 "Disables the preloading of widgets. Can be helpful if some "
56 "preloaded widget crashes the gui.");
60 qApplication(nullptr), argc(argc), argv(argv)
65 QTextCodec::setCodecForLocale(QTextCodec::codecForName(
"UTF-8"));
77 this->registry = registry;
85 if (QMessageBox::question(
nullptr,
86 "ArmarX is not running",
87 "ArmarX is not running - do you want me to start it now?",
91 int result = startArmarX();
111 SoQt::init(argc, argv,
"ArmarXGuiApp*1123");
114 (void)coin_setenv(
"COIN_SEPARATE_DIFFUSE_TRANSPARENCY_OVERRIDE",
"1", TRUE);
118 QString configToLoad;
119 if (getProperty<std::string>(
"GuiConfigFile").isSet())
122 QString::fromStdString(getProperty<std::string>(
"GuiConfigFile").getValue());
129 getProperty<bool>(
"DisablePreloading").getValue());
130 connect(mainWindow, SIGNAL(closeRequest()),
this, SLOT(closeRequest_sent()));
134 std::string
plugins = getProperty<std::string>(
"LoadPlugins").getValue();
135 std::vector<std::string> pluginList =
Split(
plugins,
",");
136 for (
auto iter = pluginList.begin(); iter != pluginList.end(); ++iter)
140 ARMARX_VERBOSE <<
"Loading plugin: " << iter->c_str() << std::endl;
145 std::cout <<
"Started ArmarXGui App" << std::endl;
148 this, &ArmarXGuiApp::runArmarXManager,
"ArmarXManagerWaitThread");
149 armarxManagerTask->start();
155 int result = qApplication->exec();
160 armarXManager->waitForShutdown();
163 qApplication->quit();
174 ArmarXGuiApp::closeRequest_sent()
179 ArmarXGuiApp::runArmarXManager()
185 qApplication->quit();
190 ArmarXGuiApp::startArmarX()
192 CMakePackageFinder armarx_core(
"ArmarXCore");
193 CMakePackageFinder armarx_memoryx(
"MemoryX");
196 if (armarx_core.packageFound())
199 std::string(armarx_core.getBinaryDir() + std::string(
"/armarx start")).c_str());
203 res = system(
"armarx start");
205 res = WEXITSTATUS(res);
206 if (res == EXIT_SUCCESS)
209 if (armarx_memoryx.packageFound())
211 if (armarx_core.packageFound())
213 res = system(std::string(armarx_core.getBinaryDir() +
214 std::string(
"/armarx memory start"))
219 res = system(
"armarx memory assureRunning");
221 res = WEXITSTATUS(res);
222 if (res == EXIT_FAILURE)
224 QMessageBox::warning(
nullptr,
226 "Could not start MongoDB! See terminal output for more "
227 "information. The GUI will now started anyway.");
234 QMessageBox::critical(
237 "Could not start ArmarX! See terminal output for more information.");
246 QString username = qgetenv(
"USER");
247 if (username.isEmpty())
249 username = qgetenv(
"USERNAME");
255 getUserNameAtHostName(
const QString& delimiter,
const QString& at)
257 const QString hostname = QHostInfo::localHostName();
258 QString user = getUserName();
265 return user + delimiter + at + delimiter + hostname;
270 ArmarXGuiApp::makeName()
272 std::vector<std::string> items{
"ArmarXGui"};
273 items.push_back(getUserNameAtHostName(
"-",
"at").toStdString());
276 std::string name = simox::alg::join(items,
"_");
286 return QApplication::notify(obj, ev);
288 catch (std::exception& e)
301 QStringList infos = exceptionReason.split(
"Backtrace:");
303 auto item =
new QListWidgetItem(
"[" + QTime::currentTime().
toString() +
"] " +
304 infos.first().trimmed());
305 item->setToolTip(exceptionReason);
307 list->scrollToBottom();
327 const auto guiWindowBaseName = QString{
"ArmarX"} +
" @ " + QHostInfo::localHostName();
328 setApplicationName(guiWindowBaseName);
331 const char* envArmarxWorkspace = std::getenv(
"ARMARX_WORKSPACE_NAME");
332 if (envArmarxWorkspace ==
nullptr)
334 envArmarxWorkspace = std::getenv(
"ARMARX_WORKSPACE");
337 QString applicationDisplayName;
338 if (envArmarxWorkspace !=
nullptr)
340 applicationDisplayName +=
"[▽" + QString(envArmarxWorkspace) +
"] ";
342 applicationDisplayName += getUserNameAtHostName(
" ",
"@");
343 setApplicationDisplayName(applicationDisplayName);
350 Qt::QueuedConnection);
357 Qt::QueuedConnection);