ArmarXGuiApp.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::Component::ArmarXGui
17 * @author David Ruscheweyh (david.ruscheweyh at student.kit dot edu)
18 * @author Kai Welke (welke at kit dot edu)
19 * @copyright 2011 Humanoids Group, HIS, KITh
20 * @license http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23 
24 #include "ArmarXGuiApp.h"
25 
26 #include <QListWidget>
27 #include <QMessageBox>
28 #include <QTime>
29 #include <QTextCodec>
30 #include <iostream>
31 
34 
35 #include <IceUtil/UUID.h>
36 
37 
38 namespace armarx
39 {
41 
42 
43  ArmarXGuiApp::ArmarXGuiApp(int& argc, char** argv) :
44  qApplication(nullptr)
45  {
46  this->argc = 0;
47  this->argv = 0;
48  qApplication = new ArmarXQApplication(argc, argv);
49 
50  // Set text encoding to UTF-8 (otherwise, umlauts display wrongly in, e.g., the log viewer)
51  QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
52  }
53 
55  {
56  // std::cout << "FINISH" << std::endl;
57  }
58 
60  {
61  this->registry = registry;
62  }
63 
64  int ArmarXGuiApp::run(int argc, char* argv[])
65  {
66  if (!ArmarXManager::CheckIceConnection(communicator(), false))
67  {
68  if (QMessageBox::question(nullptr, "ArmarX is not running", "ArmarX is not running - do you want me to start it now?", QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
69  {
70  int result = startArmarX();
71  if (result != 0)
72  {
73  return result;
74  }
75  }
76  else
77  {
78  return 1;
79  }
80  }
81  setName("ArmarXGui-" + std::to_string(IceUtil::Time::now().toMilliSeconds()));
82  return armarx::Application::run(argc, argv);
83  }
84 
85 
86  int ArmarXGuiApp::exec(const ArmarXManagerPtr& armarXManager)
87  {
88  // init SoDB and Qt, SoQt::init also creates an application object
89  SoDB::init();
90  SoQt::init(argc, argv, "ArmarXGuiApp");
91 
92  // enable Coin3D extension: transparent settings without color
93  (void)coin_setenv("COIN_SEPARATE_DIFFUSE_TRANSPARENCY_OVERRIDE", "1", TRUE);
94 
95  {
96  std::vector<std::string> packageNames = getDefaultPackageNames();
97  QString configToLoad;
98  if (getProperty<std::string>("GuiConfigFile").isSet())
99  {
100  configToLoad = QString::fromStdString(getProperty<std::string>("GuiConfigFile").getValue());
101  }
102 
103  // create top-level widget
104  mainWindow = new ArmarXMainWindow(registry, packageNames, configToLoad, getProperty<bool>("DisablePreloading").getValue());
105  connect(mainWindow, SIGNAL(closeRequest()), this, SLOT(closeRequest_sent()));
106  }
107  {
108  // parse properties
109  std::string plugins = getProperty<std::string>("LoadPlugins").getValue();
110  std::vector<std::string> pluginList = Split(plugins, ",");
111  for (auto iter = pluginList.begin(); iter != pluginList.end(); ++iter)
112  {
113  if (!iter->empty())
114  {
115  std::cout << "Loading plugin: " << iter->c_str() << std::endl;
116  mainWindow->loadPlugin(iter->c_str());
117  }
118  }
119  }
120  std::cout << "Started ArmarXGui App" << std::endl;
121 
122  armarxManagerTask = new RunningTask<ArmarXGuiApp>(this, &ArmarXGuiApp::runArmarXManager, "ArmarXManagerWaitThread");
123  armarxManagerTask->start();
124 
125  mainWindow->show();
126  mainWindow->appendFileToWindowTitle();
127 
128  ARMARX_INFO << "Now showing main window";
129  int result = qApplication->exec();
130 
131  // exit SoQt and Qt
132  interruptCallback(0); // signal to the application it should terminate the ice connection
133 
134  armarXManager->waitForShutdown();
135 
136  // Shutdown.
137  qApplication->quit();
138  delete mainWindow;
139 
140  SoQt::done();
141  delete qApplication;
142  qApplication = 0;
143 
144  return result;
145  }
146 
147  void ArmarXGuiApp::closeRequest_sent()
148  {
149  }
150 
151  void ArmarXGuiApp::runArmarXManager()
152  {
153  getArmarXManager()->waitForShutdown();
154 
155  if (qApplication)
156  {
157  qApplication->quit();
158  }
159  }
160 
161  int ArmarXGuiApp::startArmarX()
162  {
163  CMakePackageFinder finder("ArmarXCore");
164 
165  int res;
166  if (finder.packageFound())
167  {
168  res = system(std::string(finder.getBinaryDir() + std::string("/armarx start")).c_str());
169  }
170  else
171  {
172  res = system("armarx start");
173  }
174  res = WEXITSTATUS(res);
175  if (res == EXIT_SUCCESS)
176  {
177  ARMARX_INFO_S << "Started ArmarX successfully!";
178  if (finder.packageFound())
179  {
180  res = system(std::string(finder.getBinaryDir() + std::string("/armarx memory start")).c_str());
181  }
182  else
183  {
184  res = system("armarx memory assureRunning");
185  }
186  res = WEXITSTATUS(res);
187  if (res == EXIT_FAILURE)
188  {
189  QMessageBox::warning(nullptr, "ArmarX Error", "Could not start MongoDB! See terminal output for more information. The GUI will now started anyway.");
190  return 0;
191  }
192  }
193  else
194  {
195  QMessageBox::critical(nullptr, "ArmarX Error", "Could not start ArmarX! See terminal output for more information.");
196  return 1;
197  }
198  return 0;
199  }
200 
201 
202 
203  bool ArmarXQApplication::notify(QObject* obj, QEvent* ev)
204  {
205  try
206  {
207  return QApplication::notify(obj, ev);
208  }
209  catch (std::exception& e)
210  {
211  ARMARX_ERROR_S << "Exception caught:\n" << armarx::GetHandledExceptionString();
212  emit exceptionCaught(QString::fromStdString(armarx::GetHandledExceptionString()));
214  }
215 
216  return false;
217  }
218 
219  void ArmarXQApplication::showException(QString exceptionReason)
220  {
221  QStringList infos = exceptionReason.split("Backtrace:");
222  QListWidget* list = exceptionDialogHandler.listWidgetExceptions;
223  auto item = new QListWidgetItem("[" + QTime::currentTime().toString() + "] " + infos.first().trimmed());
224  item->setToolTip(exceptionReason);
225  list->addItem(item);
226  list->scrollToBottom();
227 
228  if (!exceptionDialogHandler.checkBoxDoNotShowAgain->isChecked())
229  {
230  exceptionDialog.show();
231  }
232  /*
233  QStringList infos = exceptionReason.split("Backtrace:");
234  QMessageBox box;
235  box.setIcon(QMessageBox::Warning);
236  box.setWindowTitle("An exception occured!");
237  box.setText("An exception was caught!\n" + infos.first());
238  if(infos.size() > 1)
239  box.setDetailedText(infos.last());
240  box.exec();
241  */
242  }
243 
244 
245  ArmarXQApplication::ArmarXQApplication(int& argc, char** argv) :
246  QApplication(argc, argv)
247  {
248  connect(this, SIGNAL(exceptionCaught(QString)), this, SLOT(showException(QString)), Qt::QueuedConnection);
249 
251  QListWidget* list = exceptionDialogHandler.listWidgetExceptions;
252  connect(exceptionDialogHandler.pushButtonClearHistory, SIGNAL(clicked()), list, SLOT(clear()), Qt::QueuedConnection);
253  }
254 
256  {
257  }
258 }
armarx::ArmarXGuiApp::exec
int exec(const ArmarXManagerPtr &armarXManager) override
Runs the Qt Event Loop.
Definition: ArmarXGuiApp.cpp:86
armarx::Application::run
int run(int argc, char *argv[]) override
Ice::Application replacement for the main function.
Definition: Application.cpp:362
armarx::ArmarXQApplication::ArmarXQApplication
ArmarXQApplication(int &argc, char **argv)
Definition: ArmarXGuiApp.cpp:245
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::Application::getDefaultPackageNames
std::vector< std::string > getDefaultPackageNames()
getDefaultPackageNames returns the value of the ArmarX.DefaultPackages property It splits the string ...
Definition: Application.cpp:656
armarx::ArmarXManager::CheckIceConnection
static bool CheckIceConnection(const Ice::CommunicatorPtr &communicator, bool printHint)
Definition: ArmarXManager.cpp:129
armarx::Split
std::vector< std::string > Split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelperTemplates.h:35
armarx::ArmarXGuiApp::setup
void setup(const ManagedIceObjectRegistryInterfacePtr &registry, Ice::PropertiesPtr properties) override
Configures the app, sets Qt up.
Definition: ArmarXGuiApp.cpp:59
armarx::ArmarXMainWindow
The ArmarXMainWindow class.
Definition: ArmarXMainWindow.h:80
trace.h
armarx::ArmarXMainWindow::appendFileToWindowTitle
void appendFileToWindowTitle(const QString &filepath="")
Definition: ArmarXMainWindow.cpp:824
armarx::Application::getArmarXManager
ArmarXManagerPtr getArmarXManager()
Definition: Application.cpp:728
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
plugins
StringHelpers.h
armarx::ArmarXMainWindow::loadPlugin
void loadPlugin(QString filePath)
loads a plugin with the given file path
Definition: ArmarXMainWindow.cpp:497
ArmarXGuiApp.h
IceInternal::Handle< ::Ice::Properties >
armarx::GetHandledExceptionString
std::string GetHandledExceptionString()
Definition: Exception.cpp:148
armarx::ArmarXQApplication::exceptionCaught
void exceptionCaught(QString exceptionReason)
armarx::ArmarXGuiApp::ArmarXGuiApp
ArmarXGuiApp(int &argc=ArmarXGuiApp::globalargc, char **argv=NULL)
Constructs and initialized an ArmarXGuiApp.
Definition: ArmarXGuiApp.cpp:43
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:209
armarx::ArmarXQApplication::~ArmarXQApplication
~ArmarXQApplication() override
Definition: ArmarXGuiApp.cpp:255
armarx::ArmarXQApplication::notify
bool notify(QObject *obj, QEvent *ev) override
Definition: ArmarXGuiApp.cpp:203
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::ArmarXGuiApp::~ArmarXGuiApp
~ArmarXGuiApp() override
Definition: ArmarXGuiApp.cpp:54
armarx::ArmarXQApplication
Definition: ArmarXGuiApp.h:64
No
Introduction Thank you for taking interest in our work and downloading this software This library implements the algorithm described in the paper R R R Klein Efficient RANSAC for Point Cloud Shape in Computer Graphics No
Definition: ReadMe.txt:21
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
IceUtil::Handle< ManagedIceObjectRegistryInterface >
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:27
armarx::ArmarXGuiApp::globalargc
static int globalargc
Definition: ArmarXGuiApp.h:101
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
armarx::ArmarXQApplication::showException
void showException(QString exceptionReason)
Definition: ArmarXGuiApp.cpp:219
armarx::detail::Trace::ClearExceptionBacktrace
static void ClearExceptionBacktrace()
Definition: trace.cpp:90
armarx::Application::interruptCallback
void interruptCallback(int signal) override
Cleans up connections with IceStorm before terminating the app.
Definition: Application.cpp:619
armarx::ArmarXQApplication::exceptionDialog
QDialog exceptionDialog
Definition: ArmarXGuiApp.h:79
armarx::ArmarXQApplication::exceptionDialogHandler
Ui_ExceptionDialog exceptionDialogHandler
Definition: ArmarXGuiApp.h:80
armarx::Application::setName
void setName(const std::string &name)
Set name of the application.
Definition: Application.cpp:607
armarx::ArmarXGuiApp::run
int run(int argc, char *argv[]) override
Definition: ArmarXGuiApp.cpp:64
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
GfxTL::Yes
OnOff< true > Yes
Definition: OnOff.h:12