-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainWindow.cpp
executable file
·374 lines (311 loc) · 13.7 KB
/
MainWindow.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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
#include "MainWindow.h"
#include <RockOutcrop.h>
#include <QRect>
#include <QGuiApplication>
#include <QScreen>
#include <QVBoxLayout>
#include <HeaderWidget.h>
#include <FooterWidget.h>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
#include <QDesktopServices>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QRect rec = QGuiApplication::primaryScreen()->geometry();
int height = this->height()<int(0.35*rec.height())?int(0.35*rec.height()):this->height();
int width = this->width()<int(0.35*rec.width())?int(0.35*rec.width()):this->width();
this->resize(width, height);
QWidget *centralWidget = new QWidget();
QVBoxLayout *layout = new QVBoxLayout();
centralWidget->setLayout(layout);
//
// add SimCenter Header
//
//QString appName(QString("s") + QChar(0x00B3) + "hark");
QString appName = "<P><b><i><FONT COLOR='#000000' FONT SIZE = 4>";
appName.append(QString("S") + QChar(0x00B3) + "HARK 🦈");
appName.append("</i></b></P></br>");
HeaderWidget *header = new HeaderWidget();
header->setHeadingText(appName);
layout->addWidget(header);
theRockOutcropWidget = new RockOutcrop();
// this->setCentralWidget(theWidget);
layout->addWidget(theRockOutcropWidget);
//
// add SimCenter footer
//
FooterWidget *footer = new FooterWidget();
layout->addWidget(footer);
this->setCentralWidget(centralWidget);
this->createActions();
/*
// margins of centralWidget
centralWidget()->layout()->setContentsMargins(0, 0, 0, 0);
statusBar()->hide();
ui->mainToolBar->hide();
*/
}
MainWindow::~MainWindow()
{
}
void MainWindow::createActions() {
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
QAction *openAction = new QAction(tr("&Open"), this);
openAction->setShortcuts(QKeySequence::Open);
openAction->setStatusTip(tr("Open an existing file"));
connect(openAction, &QAction::triggered, this, &MainWindow::open);
fileMenu->addAction(openAction);
//fileToolBar->addAction(openAction);
QAction *saveAction = new QAction(tr("&Save"), this);
saveAction->setShortcuts(QKeySequence::Save);
saveAction->setStatusTip(tr("Save the document to disk"));
connect(saveAction, &QAction::triggered, this, &MainWindow::save);
fileMenu->addAction(saveAction);
QAction *saveAsAction = new QAction(tr("&Save As"), this);
saveAsAction->setStatusTip(tr("Save the document with new filename to disk"));
connect(saveAsAction, &QAction::triggered, this, &MainWindow::saveAs);
fileMenu->addAction(saveAsAction);
/*
thePreferences = SimCenterPreferences::getInstance(this);
QAction *preferenceAction = new QAction(tr("&Preferences"), this);
preferenceAction->setStatusTip(tr("Set application preferences"));
connect(preferenceAction, &QAction::triggered, this, &MainWindow::preferences);
fileMenu->addAction(preferenceAction);
*/
// strangely, this does not appear in menu (at least on a mac)!! ..
// does Qt not allow as in tool menu by default?
// check for yourself by changing Quit to drivel and it works
QAction *exitAction = new QAction(tr("&Quit"), this);
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
exitAction->setStatusTip(tr("Exit the application"));
fileMenu->addAction(exitAction);
QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
QAction *versionAct = helpMenu->addAction(tr("&Version"), this, &MainWindow::version);
QAction *aboutAct = helpMenu->addAction(tr("&About"), this, &MainWindow::about);
QAction *manualAct = helpMenu->addAction(tr("&Manual"), this, &MainWindow::manual);
QAction *submitAct = helpMenu->addAction(tr("&Provide Feedback"), this, &MainWindow::submitFeedback);
QAction *submitFeature = helpMenu->addAction(tr("&Submit Feature Request"), this, &MainWindow::submitFeatureRequest);
QAction *citeAct = helpMenu->addAction(tr("&How to Cite"), this, &MainWindow::cite);
QAction *copyrightAct = helpMenu->addAction(tr("&License"), this, &MainWindow::copyright);
}
bool MainWindow::save()
{
if (currentFile.isEmpty()) {
return saveAs();
} else {
return saveFile(currentFile);
}
}
bool MainWindow::saveAs()
{
//
// get filename
//
QFileDialog dialog(this);
dialog.setWindowModality(Qt::WindowModal);
dialog.setAcceptMode(QFileDialog::AcceptSave);
if (dialog.exec() != QDialog::Accepted)
return false;
// and save the file
return saveFile(dialog.selectedFiles().first());
}
void MainWindow::open()
{
QString fileName = QFileDialog::getOpenFileName(this);
if (!fileName.isEmpty())
loadFile(fileName);
}
void MainWindow::openFile(QString fileName)
{
if (!fileName.isEmpty())
loadFile(fileName);
}
void MainWindow::newFile()
{
// clear old
// inputWidget->clear();
// set currentFile blank
setCurrentFile(QString());
}
void MainWindow::setCurrentFile(const QString &fileName)
{
currentFile = fileName;
// setWindowModified(false);
QString shownName = currentFile;
if (currentFile.isEmpty())
shownName = "untitled.json";
setWindowFilePath(shownName);
}
bool MainWindow::saveFile(const QString &fileName)
{
//
// open file
//
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot write file %1:\n%2.")
.arg(QDir::toNativeSeparators(fileName),
file.errorString()));
return false;
}
//
// create a json object, fill it in & then use a QJsonDocument
// to write the contents of the object to the file in JSON format
//
QJsonObject json;
theRockOutcropWidget->outputToJSON(json);
QJsonDocument doc(json);
file.write(doc.toJson());
// close file
file.close();
// set current file
setCurrentFile(fileName);
return true;
}
void MainWindow::loadFile(const QString &fileName)
{
//
// open file
//
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {
QMessageBox::warning(this, tr("Application"),
tr("Cannot read file %1:\n%2.")
.arg(QDir::toNativeSeparators(fileName), file.errorString()));
return;
}
// validate the document
// JsonValidator class already takes a model type param, add additional model types as required
/*
JsonValidator *jval = new JsonValidator();
jval->validate(this, BIM, fileName);
*/
// place contents of file into json object
QString val;
val=file.readAll();
QJsonDocument doc = QJsonDocument::fromJson(val.toUtf8());
QJsonObject jsonObj = doc.object();
// close file
file.close();
// given the json object, create the C++ objects
if ( ! (currentFile.isNull() || currentFile.isEmpty()) ) {
// theRockOutcropWidget->clear(); no method
}
theRockOutcropWidget->inputFromJSON(jsonObj);
setCurrentFile(fileName);
}
void MainWindow::version()
{
QString versionText("Version 1.1.1");
QMessageBox msgBox;
QSpacerItem *theSpacer = new QSpacerItem(700, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setText(versionText);
QGridLayout *layout = (QGridLayout*)msgBox.layout();
layout->addItem(theSpacer, layout->rowCount(),0,1,layout->columnCount());
msgBox.exec();
}
void MainWindow::cite()
{
QString citeText("Charles Wang, Frank McKenna, Peter Mackenzie-Helnwein, Wael Elhaddad, Adam Zsarnoczay, Michael Gardner, & Pedro Arduino. (2019, September 27). NHERI-SimCenter/s3hark: Release v1.1.1 (Version v1.1.1). Zenodo. http://doi.org/10.5281/zenodo.3463594");
QMessageBox msgBox;
QSpacerItem *theSpacer = new QSpacerItem(700, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setText(citeText);
QGridLayout *layout = (QGridLayout*)msgBox.layout();
layout->addItem(theSpacer, layout->rowCount(),0,1,layout->columnCount());
msgBox.exec();
}
void MainWindow::about()
{
QString aboutText("A SimCenter Tool For Site Response Analysis");
QMessageBox msgBox;
QSpacerItem *theSpacer = new QSpacerItem(700, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setText(aboutText);
QGridLayout *layout = (QGridLayout*)msgBox.layout();
layout->addItem(theSpacer, layout->rowCount(),0,1,layout->columnCount());
msgBox.exec();
}
void MainWindow::submitFeedback()
{
QString feedbackURL("https://docs.google.com/forms/d/e/1FAIpQLSfh20kBxDmvmHgz9uFwhkospGLCeazZzL770A2GuYZ2KgBZBA/viewform");
QDesktopServices::openUrl(QUrl(feedbackURL, QUrl::TolerantMode));
//QDesktopServices::openUrl(QUrl("https://www.designsafe-ci.org/help/new-ticket/", QUrl::TolerantMode));
}
void MainWindow::manual()
{
QString manualURL("https://www.designsafe-ci.org/data/browser/public/designsafe.storage.community//SimCenter/Software/s3hark");
QDesktopServices::openUrl(QUrl(manualURL, QUrl::TolerantMode));
//QDesktopServices::openUrl(QUrl("https://www.designsafe-ci.org/help/new-ticket/", QUrl::TolerantMode));
}
void MainWindow::submitFeatureRequest()
{
QString featureRequestURL("https://docs.google.com/forms/d/e/1FAIpQLScTLkSwDjPNzH8wx8KxkyhoIT7AI9KZ16Wg9TuW1GOhSYFOag/viewform");
QDesktopServices::openUrl(QUrl(featureRequestURL, QUrl::TolerantMode));
//QDesktopServices::openUrl(QUrl("https://www.designsafe-ci.org/help/new-ticket/", QUrl::TolerantMode));
}
void MainWindow::copyright()
{
QMessageBox msgBox;
QString copyrightText = QString("\
<p>\
The source code is licensed under a BSD 2-Clause License:<p>\
\"Copyright (c) 2017-2019, The Regents of the University of California (Regents).\"\
All rights reserved.<p>\
<p>\
Redistribution and use in source and binary forms, with or without \
modification, are permitted provided that the following conditions are met:\
<p>\
1. Redistributions of source code must retain the above copyright notice, this\
list of conditions and the following disclaimer.\
\
\
2. Redistributions in binary form must reproduce the above copyright notice,\
this list of conditions and the following disclaimer in the documentation\
and/or other materials provided with the distribution.\
<p>\
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR\
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\
<p>\
The views and conclusions contained in the software and documentation are those\
of the authors and should not be interpreted as representing official policies,\
either expressed or implied, of the FreeBSD Project.\
<p>\
REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, \
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\
THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS \
PROVIDED \"AS IS\". REGENTS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,\
UPDATES, ENHANCEMENTS, OR MODIFICATIONS.\
<p>\
------------------------------------------------------------------------------------\
<p>\
The compiled binary form of this application is licensed under a GPL Version 3 license.\
The licenses are as published by the Free Software Foundation and appearing in the LICENSE file\
included in the packaging of this application. \
<p>\
------------------------------------------------------------------------------------\
<p>\
This software makes use of the QT packages (unmodified): core, gui, widgets and network\
<p>\
QT is copyright \"The Qt Company Ltd" and licensed under the GNU Lesser General \
Public License (version 3) which references the GNU General Public License (version 3)\
<p>\
The licenses are as published by the Free Software Foundation and appearing in the LICENSE file\
included in the packaging of this application. \
<p>\
");
QSpacerItem *theSpacer = new QSpacerItem(700, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
msgBox.setText(copyrightText);
QGridLayout *layout = (QGridLayout*)msgBox.layout();
layout->addItem(theSpacer, layout->rowCount(),0,1,layout->columnCount());
msgBox.exec();
}