VPTissue Reference Manual
sim_gui.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "sim_gui_mode.h"
21 
22 #include "common/InstallDirs.h"
23 #include "gui/AppCustomizer.h"
25 #include "session/SimSession.h"
28 
29 #include <QApplication>
30 #include <QMessageBox>
31 #include <QToolTip>
32 
33 #include <iostream>
34 #include <stdexcept>
35 
36 namespace Modes {
37 
38 using namespace std;
39 using namespace SimPT_Sim::ClockMan;
40 using namespace SimPT_Sim::Util;
41 using namespace SimPT_Shell;
42 using namespace SimShell::Gui::Controller;
43 
44 
45 int simPTGUIMode::operator()(int argc, char **argv)
46 {
47  int exit_status = EXIT_SUCCESS;
48 
49  // qApp: closing last window quits app and exits app process.
50  QApplication app(argc, argv, true);
51  qRegisterMetaType<std::string>("std::string");
52  QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
53 
54  try {
55  // Go ...
56  cout << "simPT_sim starting up in gui mode at: " << TimeStamp().ToString() << endl;
57  cout << "Executing " << argv[0]<< endl << endl;
58  cout << "Revision: " << RevisionInfo::CompoundId() << endl;
59 
60  // Set icon search path
61  QStringList search_paths = QIcon::themeSearchPaths();
62  search_paths.push_back(QString::fromStdString(SimShell::InstallDirs::GetDataDir() + "/icons"));
63  QIcon::setThemeSearchPaths(search_paths);
64  QIcon::setThemeName("Tango");
65 
66  // Preliminary graphics objects
67  QPalette tooltippalette = QToolTip::palette();
68  QColor transparentcolor = QColor(tooltippalette.brush(QPalette::Window).color());
69  tooltippalette.setBrush(QPalette::Window, QBrush(transparentcolor));
70  QToolTip::setPalette(tooltippalette);
71  qApp->setStyleSheet("QToolTip { color: red; border: 2px solid gray; }");
72 
73  // Main app components
74  auto factory = make_shared<Gui::AppCustomizer>();
75  AppController controller(factory);
76  controller.setVisible(true);
77 
78  // Execute the app
79  exit_status = app.exec();
80 
81  // Done ...
82  cout << endl << controller.GetTimings() << endl << endl;
83  cout << "simPT_sim exiting at: " << TimeStamp().ToString() << endl << endl;
84  }
85  catch (exception& e) {
86  cerr << e.what() << endl;
87  QString qmess = QString("Exception:\n%1\n").arg(e.what());
88  QMessageBox::critical(0, "Critical Error", qmess,
89  QMessageBox::Abort, QMessageBox::NoButton, QMessageBox::NoButton);
90  exit_status = EXIT_FAILURE;
91  }
92  catch (...) {
93  cerr << "Unknown exception." << endl;
94  QString qmess = QString("Unknown exception.");
95  QMessageBox::critical(0, "Critical Error", qmess);
96  exit_status = EXIT_FAILURE;
97  }
98 
99  return exit_status;
100 }
101 
102 } // namespace
103 
static std::string GetDataDir()
Utility method: get name of the directory for data files.
STL namespace.
Info on git revision and commit date.
AppController header.
Namespace for miscellaneous utilities.
Definition: PTreeFile.cpp:44
Namespace for SimPT shell package.
Definition: Client.cpp:50
Namespace for startup modes for simPT tools.
Definition: mode_manager.h:36
Interface/Implementation for the exec modes.
Interface for AppCustomizer.
TimeStamp class.
Interfaces for simulator session.
Provides wall-clock time stamp using the time call.
Definition: TimeStamp.h:37
std::string ToString() const
Returns string with the time stamp after eliminating newline.
Definition: TimeStamp.h:44
Interface for FileSys.
Namespace for controllers for App, Workspace, Project and Session.
Namespace for clock and timekeeping related classes.
Definition: ClockCLib.h:27