forked from markgdawson/AerOpt-gui
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
270 lines (226 loc) · 9.96 KB
/
main.cpp
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*********************************************
**
** 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();
// Spaces in directory path mess with the MeshGenerator executable - have to exclude from AerOpt path.
if(AerOptWorkDir.indexOf(' ') >= 0) {
QMessageBox::critical(nullptr, "Error", "Invalid Path: AerOpt executables will not function properly if path contains spaces. Please move to a directory without spaces in the path.", 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;
bool exists = false;
QString mesherExe = QDir::toNativeSeparators(exeDir + "MeshGenerator" + targetext);
copySuccess = QFile::copy(":/executables/MeshGenerator" + ext, mesherExe);
settings.setValue("mesher/exe", mesherExe);
if(copySuccess) {
QFile(mesherExe).setPermissions(QFileDevice::ExeUser);
} else {
exists = QFile::exists(mesherExe);
if(!exists){
qCritical() << "Mesher file copy failed - check for presence of " << mesherExe;
}
else {
qInfo() << "MeshGenerator.exe already present in " << exeDir;
}
}
QString aeroptExe = QDir::toNativeSeparators(exeDir + "AerOpt" + targetext);
copySuccess = QFile::copy(":/executables/AerOpt" + ext, aeroptExe);
settings.setValue("AerOpt/Executable", aeroptExe);
if(copySuccess) {
QFile(aeroptExe).setPermissions(QFileDevice::ExeUser);
} else {
exists = QFile::exists(aeroptExe);
if(!exists){
qCritical() << "AerOpt executable file copy failed - check for presence of " << aeroptExe;
}
else {
qInfo() << "AerOpt.exe already present in " << exeDir;
}
}
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() << "AerOpt 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);
settings.setValue("filepath", profileFile);
if(!copySuccess) {
exists = QFile::exists(profileFile);
if(!exists){
qCritical() << "Copying of NACA0024.prf unsuccessful - check " << profileFile;
}
else {
qInfo() << "NACA0024.prf already present in " << profileDir;
}
}
settings.setArrayIndex(1);
profileFile = QDir::toNativeSeparators(profileDir + "NACA21120.prf");
copySuccess = QFile::copy(":/profiles/NACA21120.prf", profileFile);
settings.setValue("filepath", profileFile);
if(!copySuccess) {
exists = QFile::exists(profileFile);
if(!exists){
qCritical() << "Copying of NACA21120.prf unsuccessful - check " << profileFile;
}
else {
qInfo() << "NACA21120.prf already present in " << profileDir;
}
}
settings.endArray();
// Input folder is read by AerOpt 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);
// Initial cluster settings - assume AerOpt cluster directory is /AerOpt/
settings.setValue("Cluster/AerOptDir", "AerOpt/");
settings.setValue("Cluster/Username", "");
settings.setValue("Cluster/Account", "scw1022");
settings.setValue("Cluster/Address", "sunbird.swansea.ac.uk");
// Cluster interaction settings
settings.setValue("Cluster/WaitTime", "60");
settings.setValue("Cluster/UpdateTime", "10");
settings.setValue("Cluster/CheckTime", "60");
}
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);
}
QString targetext = ".exe";
#ifdef Q_OS_UNIX
ext = ".unix";
targetext = "";
#endif
#ifdef Q_OS_MACOS
ext = ".mac";
targetext = "";
#endif
// Write out expected directories for checking purposes
QString mesherExe = QDir::toNativeSeparators(AerOptWorkDir + "Executables/MeshGenerator" + targetext);
QString aeroptExe = QDir::toNativeSeparators(AerOptWorkDir + "Executables/AerOpt" + targetext);
QString inFolder = QDir::toNativeSeparators(AerOptWorkDir + "Input_Data/");
QString scratchPath = QDir::toNativeSeparators(AerOptWorkDir + "Scratch/");
// Check current logged settings. If any are blank, missing or incorrect, perform setup
QSettings settings;
bool settingcheck = true;
settingcheck &= (AerOptWorkDir==QDir::fromNativeSeparators(settings.value("AerOpt/workingDirectory").toString()));
settingcheck &= (mesherExe==QDir::fromNativeSeparators(settings.value("mesher/exe").toString()));
settingcheck &= (aeroptExe==QDir::fromNativeSeparators(settings.value("AerOpt/Executable").toString()));
settingcheck &= (inFolder==QDir::fromNativeSeparators(settings.value("AerOpt/inFolder").toString()));
settingcheck &= (scratchPath==QDir::fromNativeSeparators(settings.value("AerOpt/scratchDir").toString()));
settingcheck &= !(settings.value("Cluster/AerOptDir").toString().isEmpty());
if(!settingcheck) {
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();
}