-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
202 lines (152 loc) · 5.87 KB
/
Copy pathmain.cpp
File metadata and controls
202 lines (152 loc) · 5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Written: Stevan Gavrilovic
#include "MainWindowWorkflowApp.h"
#include "WorkflowAppOpenSRA.h"
#include "OpenSRAUserPass.h"
#include "OpenSRAPreferences.h"
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QThread>
#include <QObject>
#include <QCoreApplication>
#include <QApplication>
#include <QFile>
#include <QTime>
#include <QTextStream>
#include <QOpenGLWidget>
#include <QStandardPaths>
#include <QSettings>
#include <QDir>
#include <QStatusBar>
static bool logToFile = false;
#include "qgsapplication.h"
// customMessgaeOutput code taken from web:
// https://stackoverflow.com/questions/4954140/how-to-redirect-qdebug-qwarning-qcritical-etc-output
void customMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QHash<QtMsgType, QString> msgLevelHash({{QtDebugMsg, "Debug"}, {QtInfoMsg, "Info"}, {QtWarningMsg, "Warning"}, {QtCriticalMsg, "Critical"}, {QtFatalMsg, "Fatal"}});
QByteArray localMsg = msg.toLocal8Bit();
QTime time = QTime::currentTime();
QString formattedTime = time.toString("hh:mm:ss.zzz");
QByteArray formattedTimeMsg = formattedTime.toLocal8Bit();
QString logLevelName = msgLevelHash[type];
QByteArray logLevelMsg = logLevelName.toLocal8Bit();
if (logToFile) {
QString txt = QString("%1 %2: %3 (%4)").arg(formattedTime, logLevelName, msg, context.file);
QFile outFile(logFilePath);
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&outFile);
ts << txt << endl;
outFile.close();
} else {
fprintf(stderr, "%s %s: %s (%s:%u, %s)\n", formattedTimeMsg.constData(), logLevelMsg.constData(), localMsg.constData(), context.file, context.line, context.function);
fflush(stderr);
}
if (type == QtFatalMsg)
abort();
}
int main(int argc, char *argv[])
{
QString OpenSRAVersion = APP_VERSION;
// Setting Core Application Name, Organization, Version
QCoreApplication::setApplicationName("OpenSRA");
QCoreApplication::setOrganizationName("SimCenter");
QCoreApplication::setApplicationVersion(OpenSRAVersion);
#ifdef Q_OS_WIN
// QGuiApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#ifdef Q_OS_MACOS
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#ifdef Q_OS_LINUX
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
// Set up the application
// Start the Application
QgsApplication a( argc, argv, true );
auto prefs = OpenSRAPreferences::getInstance();
// Check if the app version has changed
QSettings settings("SimCenter", QCoreApplication::applicationName());
QVariant appVers = settings.value("AppVersion");
if (appVers.isValid())
{
auto prevAppVers = appVers.toString();
// If the app was updated, reset the preferences to pick up any potential updates
if(OpenSRAVersion != prevAppVers)
{
prefs->resetPreferences(true);
prefs->savePreferences(true);
settings.setValue("AppVersion", OpenSRAVersion);
}
}
else
{
// Set for the first time
settings.setValue("AppVersion", OpenSRAVersion);
}
// set up logging of output messages for user debugging
logFilePath = prefs->getLocalWorkDir();
// make sure tool dir exists in Documents folder
QDir dirWork(logFilePath);
if (!dirWork.exists())
if (!dirWork.mkpath(logFilePath)) {
qDebug() << QString("Could not create Working Dir: ") << logFilePath;
}
// full path to debug.log file
logFilePath = logFilePath + QDir::separator() + QString("debug.log");
// remove old log file
QFile debugFile(logFilePath);
debugFile.remove();
QByteArray envVar = qgetenv("QTDIR");
if (envVar.isEmpty())
logToFile = true;
qInstallMessageHandler(customMessageOutput);
// Set the key for the ArcGIS interface
// create the main window
WorkflowAppOpenSRA *theInputApp = new WorkflowAppOpenSRA();
MainWindowWorkflowApp mainWindowApp(QString("OpenSRA: Open-Source Seismic Risk Assessment Tool"), theInputApp, nullptr);
// Create the menu bar and actions to run the examples
theInputApp->initialize();
QString textAboutOpenSRA = "\
<p> \
This is the OpenSRA application. More to come here\
<p>\ ";
mainWindowApp.setAbout(textAboutOpenSRA);
// This is the title displayed in the on About dialog
QString aboutTitle = "About the OpenSRA Application";
QString aboutSource = "Open-source Seismic Risk Assessment (OpenSRA) Tool";
mainWindowApp.setAbout(aboutTitle, aboutSource);
QString version("Version "+ OpenSRAVersion);
mainWindowApp.setVersion(version);
QString citeText("OpenSRA");
mainWindowApp.setCite(citeText);
QString manualURL("https://docs.google.com/document/d/1zwgICunkn6PVedDiErWoyXhVvpM-vZqyZ7emsUKSxeQ/edit?usp=sharing");
mainWindowApp.setDocumentationURL(manualURL);
QString messageBoardURL("Link to message board");
mainWindowApp.setFeedbackURL(messageBoardURL);
//
// show the main window, set styles & start the event loop
//
mainWindowApp.setWindowState((mainWindowApp.windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen))| Qt::WindowMaximized);
mainWindowApp.show();
// mainWindowApp.activateWindow();
// mainWindowApp.statusBar()->showMessage("Ready", 5000);
#ifdef Q_OS_WIN
QFile file(":/styles/stylesheetWIN.qss");
#endif
#ifdef Q_OS_MACOS
QFile file(":/styles/stylesheetMAC.qss");
#endif
#ifdef Q_OS_LINUX
QFile file(":/styles/stylesheetMAC.qss");
#endif
if(file.open(QFile::ReadOnly)) {
a.setStyleSheet(file.readAll());
file.close();
} else {
qDebug() << "could not open stylesheet";
}
int res = a.exec();
return res;
}