-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGeneralInformationWidget.cpp
397 lines (296 loc) · 15.2 KB
/
GeneralInformationWidget.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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/* *****************************************************************************
Copyright (c) 2016-2017, The Regents of the University of California (Regents).
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
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.
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.
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.
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.
*************************************************************************** */
// Written by: Dr. Stevan Gavrilovic, UC Berkeley
#include "UIWidgets/GeneralInformationWidget.h"
#include "OpenSRAPreferences.h"
#include "sectiontitle.h"
#include "ClickableLabel.h"
#include <QGridLayout>
#include <QGroupBox>
#include <QFileDialog>
#include <QJsonArray>
#include <QPushButton>
#include <QRadioButton>
#include <QJsonObject>
#include <QComboBox>
#include <QDebug>
#include <QList>
#include <QLabel>
#include <QLineEdit>
#include <QMetaEnum>
#include <QStandardPaths>
#include <QApplication>
#include <QScrollArea>
GeneralInformationWidget::GeneralInformationWidget(QWidget *parent) : SimCenterAppWidget(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->setMargin(0);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(5,0,0,0);
QHBoxLayout *theHeaderLayout = new QHBoxLayout();
SectionTitle *label = new SectionTitle();
label->setText(QString("General Information"));
label->setMinimumWidth(150);
theHeaderLayout->addWidget(label);
QSpacerItem *spacer = new QSpacerItem(50,0);
theHeaderLayout->addItem(spacer);
theHeaderLayout->addStretch(1);
auto infoLayout = this->getInfoLayout();
infoLayout->setSpacing(3);
infoLayout->setContentsMargins(5,0,0,0);
auto infoWidget = new QWidget();
infoWidget->setLayout(infoLayout);
QScrollArea *scrollWidget = new QScrollArea();
scrollWidget->setWidgetResizable(true);
scrollWidget->setLineWidth(0);
scrollWidget->setWidget(infoWidget);
scrollWidget->setFrameShape(QFrame::NoFrame);
scrollWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainLayout->addLayout(theHeaderLayout);
mainLayout->addWidget(scrollWidget);
// mainLayout->addStretch();
this->setLayout(mainLayout);
}
GeneralInformationWidget::~GeneralInformationWidget()
{
}
bool GeneralInformationWidget::outputToJSON(QJsonObject &jsonObj)
{
QJsonObject outputObj;
QJsonObject directoryObj;
QDir workDir(workingDirectoryLineEdit->text());
directoryObj.insert("Working",workDir.absolutePath());
directoryObj.insert("OpenSRAData",OpenSRAPreferences::getInstance()->getAppDataDir());
directoryObj.insert("NDAData",OpenSRAPreferences::getInstance()->getNDADataDir());
outputObj.insert("AnalysisID",analysisLineEdit->text());
// outputObj.insert("UnitSystem",unitsCombo->currentText());
outputObj.insert("Directory", directoryObj);
// outputObj.insert("OutputFileType", "csv");
jsonObj.insert("General",outputObj);
return true;
}
bool GeneralInformationWidget::inputFromJSON(QJsonObject &jsonObject)
{
auto dirObj = jsonObject["Directory"].toObject();
auto workingDir = dirObj["Working"].toString();
if(!workingDir.isEmpty())
{
QDir workDir(workingDir);
if(workDir.exists())
{
workingDirectoryLineEdit->setText(workDir.absolutePath());
// Set the file path to the preferences
OpenSRAPreferences::getInstance()->setLocalWorkDir(workDir.absolutePath());
}
}
auto analysisID = jsonObject["AnalysisID"].toString();
analysisLineEdit->setText(analysisID);
// if(dirObj.contains("OpenSRAData"))
// {
// auto appDataDir = dirObj["OpenSRAData"].toString();
// if(!appDataDir.isEmpty())
// {
// QDir dataDir(appDataDir);
// if(dataDir.exists())
// {
// // Set the file path to the preferences
// OpenSRAPreferences::getInstance()->setAppDataDir(dataDir.absolutePath());
// }
// }
// }
// auto unitsSystem = jsonObject["UnitSystem"].toString();
// unitsCombo->setCurrentText(unitsSystem);
return true;
}
void GeneralInformationWidget::clear(void)
{
analysisLineEdit->clear();
auto loclWorkDir = OpenSRAPreferences::getInstance()->getLocalWorkDir();
workingDirectoryLineEdit->setText(loclWorkDir);
}
QVBoxLayout* GeneralInformationWidget::getInfoLayout(void)
{
// Get a rectangular message box on this window that could be help text box
auto analysisLabel = new QLabel("Analysis ID:");
analysisLineEdit = new QLineEdit();
analysisLineEdit->setText("Analysis_ID");
analysisLineEdit->setMaximumWidth(500);
auto unitSystemLabel = new QLabel("Unit System:");
unitsCombo = new QComboBox();
unitsCombo->addItem("SI (km)");
unitsCombo->setCurrentIndex(0);
unitsCombo->setMaximumWidth(500);
unitsCombo->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Maximum);
unitsCombo->setToolTip("Set the units here");
QPushButton *loadFileButton = new QPushButton();
loadFileButton->setText(tr("Browse"));
loadFileButton->setMaximumWidth(150);
auto workingDirectoryLabel = new QLabel("Working Directory:");
workingDirectoryLineEdit = new QLineEdit();
workingDirectoryLineEdit->setReadOnly(true);
workingDirectoryLineEdit->setMaximumWidth(400);
// Set the local work dir as default
auto loclWorkDir = OpenSRAPreferences::getInstance()->getLocalWorkDir();
workingDirectoryLineEdit->setText(loclWorkDir);
connect(loadFileButton,&QPushButton::clicked, this, &GeneralInformationWidget::chooseDirectoryDialog);
// overview
auto assessmentLabel = new QLabel("General Comments:");
assessmentLabel->setStyleSheet("font-weight: bold; color: black");
const char *assessmentDetailString =
"1. Refer back to this tab at any time for setup instructions.\n"
"2. Note that the first time you click \"PREPROCESS\" and \"PERFORM ANALYSIS\" after installation will take some time for OpenSRA to perform some behind-the-scene tasks.\n"
"3. If you are not familiar with OpenSRA, it is best to pick the example that best match your problem and adjust the analysis parameters from there (see \"Examples\" on the menu bar at the top).";
auto assessmentDetailLabel = new QLabel(assessmentDetailString);
// examples
auto exampleLabel = new QLabel("Instructions for Examples:");
exampleLabel->setStyleSheet("font-weight: bold; color: black");
const char *exampleDetailString =
"1. The built-in examples are separated by the currently available infrastructure types: (1) above ground components, (2) below ground pipeline, and (3) wells and caprocks.\n"
"\t- For below ground pipelines, the examples are further divided by the type of geohazard: (1) lateral spread, (2) liquefaction-induced settlement, (3) landslide, and (4) surface fault rupture.\n"
"2. To run an example:\n"
"\t- Select an example from the dropdown menu at the top of the screen\n"
"\t- Follow the pop-up prompts";
auto exampleDetailLabel = new QLabel(exampleDetailString);
// instructions
auto setupLabel = new QLabel("Program Overview and Setup Details:");
setupLabel->setStyleSheet("font-weight: bold; color: black");
const char *setupDetailString =
"1. \"General Information\":\n"
"\t- Define analysis ID (optional) and select the path for the working directory\n"
"2. \"Infrastructure\":\n"
"\t- Click on the button with the type of infrastructure to run\n"
"\t- From the dropdown menu, choose the file type to import\n"
"\t- Fill out the inputs as requested\n"
"\tNote: for \"Pipelines\", users can choose to use the prepackaged state pipeline network, which has been heavily preprocessed internally to reduce runtime; however, state-wide analysis can still take a long time to complete (over 1 hour)\n"
"3. \"Decision Variable\":\n"
"\t- Pick the decision metric to run from the secondary list of buttons\n"
"\t- From the dropdown menu, pick the method to run\n"
"\t- Review the descriptions of the outputs, inputs, and additional requirements from tabs on the left side-bar\n"
"\t- Click \"Add to list of methods to run\" to the include this method in the run\n"
"\tNote: The input parameters will be displayed under the \"Input Variables\" tab for users to edit\n"
"\tWarning: While you can use more than one method, we advise to use one method per run as combinations of methods may not be appropriate for the current implemention of Polynomial Chaos\n"
"4. \"Damage Measure\":\n"
"\t- Only required if requested by one of the methods under the \"Decision Variable\" tab\n"
"\t- Follow the same instructions as those under \"Decision Variable\"\n"
"5. \"Engineering Demand Parameters\":\n"
"\t- Only required if requested by one of the methods under the \"Decision Variable\" and/or the \"Damage Measure\" tab\n"
"\t- Follow the same instructions as those under \"Decision Variable\"\n"
"6. \"Intensity Measure\":\n"
"\t- From the dropdown menu, choose the type of seismic source to use\n"
"\t- Follow the on-screen instructions to fill out the inputs as requested\n"
"7. \"GIS and CPT Data\":\n"
"\t- \"User Provided GIS Data\"\n"\
"\t\t- Browse for folder with datasets - the menu on the right should populate with the GIS maps found in the folder\n"
"\t- \"Site Investigation Data (currently supporting CPTs only)\"\n"\
"\t\t- Follow the on-screen instructions to fill out the inputs as requested\n"
"\t\tNote: only used by below ground pipelines with lateral spread and settlement as geohazards\n"
"8. \"Input Variables\":\n"
"\t- This tab contains two tables:\n"
"\t\t- (a) random variables that can sampled for epistemic uncertainty\n"
"\t\t- (a) fixed variables that holds a singular value\n"
"\t- Follow the on-screen instructions to edit the tables\n"
"\nClick \"PREPROCESS\" once Steps 1 through 7 have been reviewed\n"
"When prompted, click \"PERFORM ANALYSIS\" to perform the analysis\n\n"
"\t- If the analysis is successful, a new layer named \"Results\" will be populated in the \"Visualization\" tab\n";
auto setupDetailLabel = new QLabel(setupDetailString);
// QRadioButton *button1 = new QRadioButton("Pre-configured setup for risk assessment (preferred)");
// QRadioButton *button2 = new QRadioButton("Allow for user customization (e.g., source models, evaluation methods to use)");
// button1->setChecked(true);
// auto warningLabel = new QLabel();
// warningLabel->setText("Warning: Only choose this option if you have read the user manual and are familiar with the program");
// warningLabel->setStyleSheet("color: red");
// Layout the UI components in a grid
QVBoxLayout* layout = new QVBoxLayout();
ClickableLabel* helpLabel1 = new ClickableLabel(" ?");
helpLabel1->setToolTip("Enter a unique analysis name.");
QHBoxLayout* analysisNameLayout = new QHBoxLayout();
analysisNameLayout->addWidget(analysisLabel);
analysisNameLayout->addWidget(analysisLineEdit);
analysisNameLayout->addWidget(helpLabel1);
analysisNameLayout->addStretch();
ClickableLabel* helpLabel2 = new ClickableLabel(" ?");
helpLabel2->setToolTip("Enter or select the path to the working directory, i.e., where OpenSRA will store the analysis inputs and results.");
QHBoxLayout* workingDirLayout = new QHBoxLayout();
workingDirLayout->addWidget(workingDirectoryLabel);
workingDirLayout->addWidget(workingDirectoryLineEdit);
workingDirLayout->addWidget(loadFileButton);
workingDirLayout->addWidget(helpLabel2);
workingDirLayout->addStretch();
ClickableLabel* helpLabel3 = new ClickableLabel(" ?");
helpLabel3->setToolTip("Select the analysis unit system.");
QHBoxLayout* unitsLayout = new QHBoxLayout();
unitsLayout->addWidget(unitSystemLabel);
unitsLayout->addWidget(unitsCombo);
unitsLayout->addWidget(helpLabel3);
unitsLayout->addStretch();
layout->addLayout(analysisNameLayout);
layout->addLayout(workingDirLayout);
layout->addLayout(unitsLayout);
// add spacer
QSpacerItem *vSpacer = new QSpacerItem(0,20);
layout->addItem(vSpacer);
// general comment text
layout->addWidget(assessmentLabel);
layout->addWidget(assessmentDetailLabel);
// example text
QSpacerItem *vSpacer2 = new QSpacerItem(0,20);
layout->addItem(vSpacer2);
layout->addWidget(exampleLabel);
layout->addWidget(exampleDetailLabel);
// setup text
QSpacerItem *vSpacer3 = new QSpacerItem(0,20);
layout->addItem(vSpacer3);
layout->addWidget(setupLabel);
layout->addWidget(setupDetailLabel);
layout->addStretch(1);
// layout->addWidget(button1);
// layout->addWidget(button2);
// layout->addWidget(warningLabel);
return layout;
}
void GeneralInformationWidget::chooseDirectoryDialog(void)
{
auto prefs = OpenSRAPreferences::getInstance();
auto pathToWorkingDirectoryFile = QFileDialog::getExistingDirectory(this,tr("Working Directory"), prefs->getLocalWorkDir());
if(pathToWorkingDirectoryFile.isEmpty())
return;
// Return if the user cancels
if(!QDir(pathToWorkingDirectoryFile).exists())
{
QString errMsg = "The given path " + pathToWorkingDirectoryFile + " is not a valid directory";
errorMessage(errMsg);
return;
}
// Set file name & entry in qLine edit
workingDirectoryLineEdit->setText(pathToWorkingDirectoryFile);
// Set the file path to the preferences
prefs->setLocalWorkDir(pathToWorkingDirectoryFile);
return;
}