forked from DrBenEvans/AerOptGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
204 lines (164 loc) · 7.02 KB
/
main.cpp
File metadata and controls
204 lines (164 loc) · 7.02 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
203
204
/*********************************************
**
** Created on: 28/12/2013 2013
** Author: matt - Matt Edmunds
** File: main.cpp
** This is the English version of this programme
**
**********************************************/
#include <iostream>
#include <QApplication>
#include <QDir>
#include <QDebug>
#include <QSettings>
#include <QSplashScreen>
#include <QMessageBox>
#include "DebugOutput.h"
#include "MainWindow.h"
#include "OptimisationModel.h"
#include "windowsizing.h"
void firstTimeSetup(QString AerOptWorkDir) {
QSettings settings;
settings.clear();
if(AerOptWorkDir.indexOf(' ') >= 0) {
QMessageBox::critical(nullptr, "Error", "Invalid Path: AerOpt executable path must not contains spaces.", QMessageBox::Ok);
exit(-1);
}
AerOptWorkDir = QDir::toNativeSeparators(AerOptWorkDir);
settings.setValue("AerOpt/workingDirectory", AerOptWorkDir);
QDir().mkdir(AerOptWorkDir);
settings.setValue("AerOpt/startLoadPath", AerOptWorkDir);
// setup executables
QString exeDir = QDir::toNativeSeparators(AerOptWorkDir + "Executables/");
QDir().mkdir(exeDir);
QString ext = ".exe";
QString targetext = ".exe";
#ifdef Q_OS_UNIX
ext = ".unix";
targetext = "";
#endif
#ifdef Q_OS_MACOS
ext = ".mac";
targetext = "";
#endif
bool copySuccess;
QString mesherExe = QDir::toNativeSeparators(exeDir + "MeshGenerator" + targetext);
copySuccess = QFile::copy(":/executables/MeshGenerator" + ext, mesherExe);
if(copySuccess) {
QFile(mesherExe).setPermissions(QFileDevice::ExeUser);
settings.setValue("mesher/exe", mesherExe);
} else {
qCritical() << "Mesher file copy failed";
}
QString aeroptExe = QDir::toNativeSeparators(exeDir + "AerOpt" + targetext);
copySuccess = QFile::copy(":/executables/AerOpt" + ext, aeroptExe);
if(copySuccess) {
QFile(aeroptExe).setPermissions(QFileDevice::ExeUser);
settings.setValue("AerOpt/executable", aeroptExe);
} else {
qCritical() << "AerOpt executable file copy failed";
}
QString exePath = QDir::toNativeSeparators(exeDir + "Delaunay_2D" + targetext);
QFile::copy(":/executables/Delaunay_2D" + ext, exePath);
QFile(exePath).setPermissions(QFileDevice::ExeUser);
exePath = QDir::toNativeSeparators(exeDir + "PrePro_2D" + targetext);
QFile::copy(":/executables/PrePro_2D" + ext, exePath);
QFile(exePath).setPermissions(QFileDevice::ExeUser);
exePath = QDir::toNativeSeparators(exeDir + "Solver_2D" + targetext);
QFile::copy(":/executables/Solver_2D" + ext, exePath);
QFile(exePath).setPermissions(QFileDevice::ExeUser);
qDebug() << "Working Directory:" << AerOptWorkDir;
qDebug() << "Mesher Exe Path" << mesherExe;
qDebug() << "AeroOpt Exe Path" << aeroptExe;
bool c = true;
QFileInfo checkMesher(mesherExe);
QFileInfo checkAerOpt(aeroptExe);
c &= checkMesher.exists();
c &= checkMesher.isFile();
c &= checkAerOpt.exists();
c &= checkAerOpt.isFile();
if (!c)
{
qCritical() << "Application executables not available!";
}
// setup default profiles
QString profileDir = QDir::toNativeSeparators(AerOptWorkDir + "profiles/");
QDir().mkdir(profileDir);
settings.setValue("AerOpt/profilesDefaultPath", profileDir);
settings.beginWriteArray("profiles");
settings.setArrayIndex(0);
QString profileFile = QDir::toNativeSeparators(profileDir + "NACA0024.prf");
copySuccess = QFile::copy(":/profiles/NACA0024.prf", profileFile);
if(copySuccess)
settings.setValue("filepath", profileFile);
settings.setArrayIndex(1);
profileFile = QDir::toNativeSeparators(profileDir + "NACA21120.prf");
copySuccess = QFile::copy(":/profiles/NACA21120.prf", profileFile);
if(copySuccess)
settings.setValue("filepath", profileFile);
settings.endArray();
// Input folder is read by AeroOpt executable
QString inFolder = AerOptWorkDir + "Input_Data/";
inFolder = QDir::toNativeSeparators(inFolder);
settings.setValue("AerOpt/inFolder", inFolder);
QString AerOptInFileName = "AerOpt_InputParameters.txt";
QString AerOptInFile = inFolder + AerOptInFileName;
AerOptInFile = QDir::toNativeSeparators(AerOptInFile);
settings.setValue("AerOpt/inputFile", AerOptInFile);
settings.setValue("AerOpt/inputFileName", AerOptInFileName);
QString AerOptNodeFile = inFolder + "Control_Nodes.txt";
AerOptNodeFile = QDir::toNativeSeparators(AerOptNodeFile);
settings.setValue("AerOpt/nodeFile", AerOptNodeFile);
QString AerOptBoundaryFile = inFolder + "Boundary_Points.txt";
AerOptBoundaryFile = QDir::toNativeSeparators(AerOptBoundaryFile);
settings.setValue("AerOpt/boundaryFile", AerOptBoundaryFile);
// mesh is created in a scratch directory
QString scratchPath = QDir::toNativeSeparators(AerOptWorkDir + "Scratch/");
settings.setValue("mesher/scratchDir", scratchPath);
QString initialMeshFile;
initialMeshFile = QDir(scratchPath + "Mesh.dat").absolutePath();
initialMeshFile = QDir::toNativeSeparators(initialMeshFile);
settings.setValue("mesher/initMeshFile", initialMeshFile);
settings.setValue("Cluster/Username", "");
settings.setValue("Cluster/Account", "scw1022");
settings.setValue("Cluster/Address", "sunbird.swansea.ac.uk");
}
void checkSettings()
{
//Setup up default settings
QCoreApplication::setOrganizationName("Swansea University (Engineering)");
QCoreApplication::setOrganizationDomain("engineering.swansea.ac.uk");
QCoreApplication::setApplicationName("AerOpt");
// get working directory
QString appPath = QDir::fromNativeSeparators(QCoreApplication::applicationFilePath());
QFileInfo appPathInfo(appPath);
QString AerOptWorkDir = appPathInfo.dir().absolutePath();
// macOS: remove part of path inside application bundle
AerOptWorkDir = AerOptWorkDir.remove(QRegExp("/AerOptGui.app/Contents.*"));
AerOptWorkDir = QDir::fromNativeSeparators(AerOptWorkDir + "/AerOptFiles/");
// if working directory exists, then no need for setup
if(!QDir(AerOptWorkDir).exists()) {
firstTimeSetup(AerOptWorkDir);
}
}
//Programme entry point.
int main(int argc, char *argv[])
{
//Initialises the QT library application event loops.
QApplication app(argc, argv);
app.setWindowIcon(QIcon(":/images/AerOpt.png"));
checkSettings();
//Application main interaction classes.
//DebugOutput::Instance();
qInfo() << " *** Welcome to AerOpt ***";
qInfo() << " *** Have a nice day ***";
// Setup optimisation model and selection model
OptimisationModel* optimisationModel = new OptimisationModel();
//Main window setup and show.
MainWindow w;
centerAndResizeWindow(&w);
w.setOptimisationModel(optimisationModel);
w.show();
w.setSplitterSizes();
return app.exec();
}