diff --git a/EE-UQ.pro b/EE-UQ.pro index 98b170c5..1d994a40 100644 --- a/EE-UQ.pro +++ b/EE-UQ.pro @@ -4,7 +4,10 @@ # #------------------------------------------------- -QT += core gui charts concurrent webenginewidgets network sql qml 3dcore 3drender 3dextras printsupport quick opengl +QT += core gui charts concurrent network sql qml 3dcore 3drender 3dextras printsupport quick opengl +QT += webengine webenginewidgets +QT += webenginecore +QT += webchannel greaterThan(QT_MAJOR_VERSION, 4): QT += widgets diff --git a/EVENTS/physicsBasedSimulation/IstanbulSingleSite.cpp b/EVENTS/physicsBasedSimulation/IstanbulSingleSite.cpp new file mode 100644 index 00000000..93ad9f14 --- /dev/null +++ b/EVENTS/physicsBasedSimulation/IstanbulSingleSite.cpp @@ -0,0 +1,373 @@ +/* ***************************************************************************** +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: fmckenna + +#include "IstanbulSingleSite.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +IstanbulSingleSite::IstanbulSingleSite(QWidget *parent) + :SimCenterAppWidget(parent), count(0), ok(false) +{ + + this->setWindowTitle("Splitting Widgets Example"); + this->setGeometry(100, 100, 600, 400); + QHBoxLayout *mainLayout = new QHBoxLayout(this); + QWidget *leftWidget = new QWidget(); + QGridLayout *leftLayout = new QGridLayout(leftWidget); + leftLayout->setAlignment(Qt::AlignTop); + // this->setLayout(theLayout); + QGroupBox *inputParameters = new QGroupBox("Input Parameters"); + + QGridLayout *theLayout = new QGridLayout(inputParameters); + this->setLayout(theLayout); + + theLayout->addWidget(new QLabel("grid type"),0,0); + QStringList listGrids; listGrids << "All"; + gridType = new SC_ComboBox("gridType",listGrids); + theLayout->addWidget(gridType, 0, 1); + + theLayout->addWidget(new QLabel("num Motions"),0,2); + numRealizations = new SC_IntLineEdit("numRealizations",1); + theLayout->addWidget(numRealizations,0,3); + + theLayout->addWidget(new QLabel("latitude"),2,0); + lat = new SC_DoubleLineEdit("latitude",40.9940); + theLayout->addWidget(lat,2,1); + theLayout->addWidget(new QLabel("longitude"),2,2); + lng = new SC_DoubleLineEdit("longitude",28.8990); + theLayout->addWidget(lng,2,3); + + + + + QString dirPath = SimCenterPreferences::getInstance()->getLocalWorkDir() + QDir::separator() + "Istanbul"; + theLayout->addWidget(new QLabel("tmp Directory"),3,0); + tmpLocation = new SC_DirEdit("tmpLocation"); + tmpLocation->setDirName(dirPath); + theLayout->addWidget(tmpLocation,3,1,1,2); + + QPushButton *getMotions = new QPushButton("Get Motions"); + theLayout->addWidget(getMotions, 4,1,1,3); + connect(getMotions, &QPushButton::clicked, this, [=](){ + this->downloadMotions(); + }); + QLabel *citation = new QLabel("Zhang, W., J. Crempien, K. Zhong, P. Chen, P. Arduino, E. Taciroglu. (2023), A suite of 57 broadband physics-based ground motion simulations for the Istanbul region, in Regional-scale physics-based ground motion simulation for Istanbul, Turkey. DesignSafe-CI."); + citation->setWordWrap(true); + theLayout->addWidget(citation,5,0,1,4); + theLayout->setRowStretch(6,1); + theLayout->setColumnStretch(1,1); + theLayout->setColumnStretch(3,1); + theLayout->setColumnStretch(4,1); + leftLayout->addWidget(inputParameters,0,0); + + QGroupBox *mapboxIstanbul = new QGroupBox("Grid Location"); + + // =========================================================== + // creating right widget + // =========================================================== + QWidget *rightWidget = new QWidget(); + + QGridLayout *rightLayout = new QGridLayout(rightWidget); + + QGroupBox *mapbox = new QGroupBox("Grid Map"); + QGridLayout *maplayout = new QGridLayout(mapbox); + + QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true); + QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true); + + // webView1->page()->setDevToolsPage(new QWebEnginePage()); + webView1 = new QWebEngineView(); + QString appDir = SimCenterPreferences::getInstance()->getAppDir(); + QString mappscript = appDir + QDir::separator() + "applications" + QDir::separator() + + "createEVENT" + QDir::separator() + "Istanbul" + QDir::separator(); + // webView1->setUrl(QUrl("https://www.google.com/maps")); + webView1->load(QUrl::fromLocalFile(mappscript+"Istanbul_AllSites_grid.html")); + webView1->show(); + maplayout->addWidget(webView1,0,0); + rightLayout->addWidget(mapbox,0,0); + + + + leftWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + rightWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + mainLayout->addWidget(leftWidget); + mainLayout->addWidget(rightWidget); + + + + mainLayout->addWidget(leftWidget); + mainLayout->addWidget(rightWidget); +} + +IstanbulSingleSite::~IstanbulSingleSite() +{ + + + + +} + +void +IstanbulSingleSite::downloadMotions(void) +{ + qDebug() << "IstanbulSingleSite::downloadMotions called"; + + // + // get tmp directory to store motions, if it exists remove + // + QString destDir = tmpLocation->getDirName(); + QDir destinationDirectory(destDir); + + if(destinationDirectory.exists()) { + destinationDirectory.removeRecursively(); + destinationDirectory.mkpath(destDir); + } else + destinationDirectory.mkpath(destDir); + + if (!destinationDirectory.exists()) { + errorMessage(QString("IstanbulSingleSite SHOULD NOT HAPPEN BUT NO ") + destDir); + return; + } + + // + // get all inputs + // + + double latitude = lat->getDouble(); + double longitude = lng->getDouble(); + QString currentGrid=gridType->currentText(); + int numMotion = numRealizations->getInt(); + + // + // now do python call + // + + QString appDir = SimCenterPreferences::getInstance()->getAppDir(); + QString IstanbulScript = appDir + QDir::separator() + "applications" + QDir::separator() + + "createEVENT" + QDir::separator() + "Istanbul" + QDir::separator() + "IstanbulRun.py"; + + QStringList args; args << QString("--lat") << QString::number(latitude) + << QString("--lng") << QString::number(longitude) + << QString("-g") << currentGrid + << QString("-n") << QString::number(numMotion) + << QString("-o") << destDir; + + /* + QJsonObject information; + information["LocationFlag"]=true; + information["APIFLAG"]=true; + information["latitude"]=latitude; + information["longitude"]=longitude; + information["grid_type"]=currentGrid; + information["number_of_realizations"]=numMotion; + information["directory"]=destDir; + + QJsonDocument jsonDoc(information); + + // Convert QJsonDocument to JSON string + QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Indented); + + // Write JSON data to a file + QString informationFile = destDir + QDir::separator() + "information.json"; + QFile outputFile(informationFile); + if(outputFile.open(QIODevice::WriteOnly)) { + outputFile.write(jsonData); + outputFile.close(); + } else { + QString msg("IstanbulSingleSite::Could not open file" + informationFile); + errorMessage(msg); + return; + } + QStringList args; args << informationFile; + */ + + ModularPython *thePythonApp = new ModularPython(tmpLocation->getDirName()); + errorMessage("Getting Motions from Designsafe repository. This may take a few minutes"); + errorMessage("STARTING PYTHON"); + thePythonApp->run(IstanbulScript,args); + errorMessage("PYTHON DONE"); + delete thePythonApp; +} + + +bool +IstanbulSingleSite::outputAppDataToJSON(QJsonObject &jsonObject) +{ + qDebug() << "IstanbulSingleSite::outputAppDataToJSON() - should not be called"; + Q_UNUSED(jsonObject); + return false; +} + +bool +IstanbulSingleSite::inputAppDataFromJSON(QJsonObject &jsonObject) +{ + qDebug() << "IstanbulSingleSite::inputAppDataFromJSON() - should not be called"; + Q_UNUSED(jsonObject); + return false; +} + +bool +IstanbulSingleSite::outputToJSON(QJsonObject &jsonObject) +{ + jsonObject["EventClassification"]="Earthquake"; + jsonObject["type"] = "PhysicsBasedMotion"; // for backend processing + jsonObject["sub_type"] = "Istanbul"; + QString downloadedDir = tmpLocation->getDirName(); + QDir downloadDirectory(downloadedDir); + QStringList motions = downloadDirectory.entryList(QStringList() << "*.json",QDir::Files); + QJsonArray motionList; + for (const QString& motion : motions) { + motionList.append(motion); + } + jsonObject["motions"]=motionList; + jsonObject["fileType"]="JSON"; + lat->outputToJSON(jsonObject); + lng->outputToJSON(jsonObject); + numRealizations->outputToJSON(jsonObject); + gridType->outputToJSON(jsonObject); + tmpLocation->outputToJSON(jsonObject); + + return true; +} + +bool +IstanbulSingleSite::inputFromJSON(QJsonObject &jsonObject) +{ + lat->inputFromJSON(jsonObject); + lng->inputFromJSON(jsonObject); + numRealizations->inputFromJSON(jsonObject); + gridType->inputFromJSON(jsonObject); + tmpLocation->inputFromJSON(jsonObject); + + return true; +} + + +bool +IstanbulSingleSite::copyFiles(QString &destDir) +{ + QString downloadedDir = tmpLocation->getDirName(); + QDir downloadDirectory(downloadedDir); + QStringList motions = downloadDirectory.entryList(QStringList() << "*.json",QDir::Files); + + // + // first check we have actual files to copy + // + if (motions.count() == 0) { + + statusMessage(QString("Istanbul no motions Downloaded")); + switch( QMessageBox::question( + this, + tr("Istanbul"), + tr("Istanbul has detected that no motions exist in the tmp folder. You may have requested too many motions or you did not run the 'Select Records' after entering your search criteria. If you trying to Run a Workflow, the workflow will FAIL to run or you will be presented with NANs (not a number) and zeroes. To select motions, return to the Istanbul EVENT and press the 'Download Records' Button. NOTE: The motions from present server take about 2min a record to download. Do you wish to continue anyway?"), + QMessageBox::Yes | + QMessageBox::No, + QMessageBox::Yes ) ) + { + case QMessageBox::Yes: + break; + case QMessageBox::No: + return false; + break; + default: + + break; + } + } + + // + // now copy files to input_data instead of dest_dir + // + + + // mkdir input_data, same level as dest_dir + + QDir destinationFolder(destDir); + destinationFolder.cdUp(); + QString inputDataDirPath = destinationFolder.absoluteFilePath("input_data"); + + if (destinationFolder.mkpath(inputDataDirPath) == false) { + this->errorMessage("Istanbul failed to create folder: "); + this->errorMessage(inputDataDirPath); + return false; + } + + // copyfiles + + SimCenterAppWidget::copyPath(downloadedDir, inputDataDirPath, false); + return true; +} + +void +IstanbulSingleSite::clear(void) +{ + +} + +bool +IstanbulSingleSite::outputCitation(QJsonObject &jsonObject) +{ + jsonObject.insert("citation", QString("Zhang, W., J. Crempien, K. Zhong, P. Chen, P. Arduino, E. Taciroglu. (2023) A suite of 57 broadband physics-based ground motion simulations for the Istanbul region, in Regional-scale physics-based ground motion simulation for Istanbul, Turkey. DesignSafe-CI. https://doi.org/10.17603/ds2-e7nq-8d52 v1")); + jsonObject.insert("description", QString("A suite of 57 broadband physics-based ground motion simulations for the Istanbul region")); + return true; +} + diff --git a/EVENTS/physicsBasedSimulation/IstanbulSingleSite.h b/EVENTS/physicsBasedSimulation/IstanbulSingleSite.h new file mode 100644 index 00000000..6437c80b --- /dev/null +++ b/EVENTS/physicsBasedSimulation/IstanbulSingleSite.h @@ -0,0 +1,89 @@ +#ifndef ISTANBUL_SINGLE_SITE_WIDGET_H +#define ISTANBUL_SINGLE_SITE_WIDGET_H + +/* ***************************************************************************** +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. + +*************************************************************************** */ + +/** + * @author fmckenna + * @date 03/2024 + * @version 1.0 + * + * @section DESCRIPTION + * + * The purpose of this class is to define interface for Istanbul ground motions + */ + +#include +#include +class SC_DoubleLineEdit; +class SC_IntLineEdit; +class SC_DirEdit; +class SC_ComboBox; + +class IstanbulSingleSite : public SimCenterAppWidget +{ + Q_OBJECT +public: + IstanbulSingleSite(QWidget *parent = 0); + virtual ~IstanbulSingleSite(); + bool outputToJSON(QJsonObject &jsonObject); + bool inputFromJSON(QJsonObject &jsonObject); + bool outputAppDataToJSON(QJsonObject &jsonObject); + bool inputAppDataFromJSON(QJsonObject &jsonObject); + bool copyFiles(QString &destDir); + virtual void clear(void); + + virtual bool outputCitation(QJsonObject &jsonObject); + +signals: + +public slots: + void downloadMotions(void); + +private: + SC_DoubleLineEdit *lat; + SC_DoubleLineEdit *lng; + SC_IntLineEdit *numRealizations; + SC_DirEdit *tmpLocation; + SC_ComboBox *gridType; + QWebEngineView *webView1; + int count; + bool ok; + +}; + +#endif // ISTANBUL_SINGLE_SITE_WIDGET_H diff --git a/EVENTS/physicsBasedSimulation/M9SingleSite.cpp b/EVENTS/physicsBasedSimulation/M9SingleSite.cpp index 6ae7240d..9ec17ba9 100644 --- a/EVENTS/physicsBasedSimulation/M9SingleSite.cpp +++ b/EVENTS/physicsBasedSimulation/M9SingleSite.cpp @@ -41,12 +41,17 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include #include #include +#include #include #include #include #include #include +#include +#include +#include +#include #include #include @@ -62,11 +67,21 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. M9SingleSite::M9SingleSite(QWidget *parent) :SimCenterAppWidget(parent), count(0), downloadedMotions(false), motionsDownloading(false) { - QGridLayout *theLayout = new QGridLayout(); - this->setLayout(theLayout); + this->setWindowTitle("Splitting Widgets Example"); + this->setGeometry(100, 100, 600, 400); + QHBoxLayout *mainLayout = new QHBoxLayout(this); + + QWidget *leftWidget = new QWidget(); + + QGridLayout *leftLayout = new QGridLayout(leftWidget); + leftLayout->setAlignment(Qt::AlignTop); + // this->setLayout(theLayout); + QGroupBox *inputParameters = new QGroupBox("Input Parameters"); + QGridLayout *theLayout = new QGridLayout(inputParameters); + theLayout->addWidget(new QLabel("Grid"),0,0); - QStringList listGrids; listGrids << "A" << "B" << "C" << "D" << "All"; + QStringList listGrids; listGrids << "All" << "A" << "B" << "C" << "D"; gridType = new SC_ComboBox("gridType",listGrids); theLayout->addWidget(gridType, 0, 1); @@ -87,9 +102,18 @@ M9SingleSite::M9SingleSite(QWidget *parent) tmpLocation->setDirName(dirPath); theLayout->addWidget(tmpLocation,3,1,1,3); + // Add a checkbox to allow the user to select if they want to use API or not + theLayout->addWidget(new QLabel("API"), 4, 0); // Column 4 + useAPI = new SC_CheckBox("useAPI", false); + theLayout->addWidget(useAPI, 4, 1); + // add the explanation for the API + QLabel *apiExplanation = new QLabel("Check this box if you want to use the API to get the motions. If you do not check this box, the motions will be Extracted from Designsafe repository."); + apiExplanation->setWordWrap(true); + theLayout->addWidget(apiExplanation, 4, 2, 1, 2); + getMotions = new QPushButton("Get Motions"); - theLayout->addWidget(getMotions, 4,1,1,3); + theLayout->addWidget(getMotions, 5,1,1,3); connect(getMotions, &QPushButton::clicked, this, [=](){ this->downloadMotions(); }); @@ -97,12 +121,61 @@ M9SingleSite::M9SingleSite(QWidget *parent) QLabel *citation = new QLabel("Frankel, A., Wirth, E., Marafi, N., Vidale, J., and Stephenson, W. (2018), Broadband Synthetic Seismograms for Magnitude 9 Earthquakes on the Cascadia Megathrust Based on 3D Simulations and Stochastic Synthetics, Part 1: Methodology and Overall Results. Bulletin of the Seismological Society of America, 108 (5A), 2347–2369. doi: https://doi.org/10.1785/0120180034"); citation->setWordWrap(true); - theLayout->addWidget(citation, 5,0,1,4); + theLayout->addWidget(citation, 6,0,1,4); - theLayout->setRowStretch(6,1); + theLayout->setRowStretch(7,1); theLayout->setColumnStretch(1,1); theLayout->setColumnStretch(3,1); - theLayout->setColumnStretch(4,1); + theLayout->setColumnStretch(4,1); + + leftLayout->addWidget(inputParameters,0,0); + + + QGroupBox *mapboxM9 = new QGroupBox("Grid Location"); + + // =========================================================== + // creating right widget + // =========================================================== + QWidget *rightWidget = new QWidget(); + + QGridLayout *rightLayout = new QGridLayout(rightWidget); + + QGroupBox *mapbox = new QGroupBox("Grid Maps"); + QGridLayout *maplayout = new QGridLayout(mapbox); + + QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true); + QWebEngineSettings::globalSettings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true); + + // webView1->page()->setDevToolsPage(new QWebEnginePage()); + webView1 = new QWebEngineView(); + QString appDir = SimCenterPreferences::getInstance()->getAppDir(); + QString mappscript = appDir + QDir::separator() + "applications" + QDir::separator() + + "createEVENT" + QDir::separator() + "M9" + QDir::separator(); + // webView1->setUrl(QUrl("https://www.google.com/maps")); + webView1->load(QUrl::fromLocalFile(mappscript+"All_grid.html")); + webView1->show(); + maplayout->addWidget(webView1,0,0); + rightLayout->addWidget(mapbox,0,0); + + + + leftWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + rightWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + mainLayout->addWidget(leftWidget); + mainLayout->addWidget(rightWidget); + + + + + + + + // create a signal if gridType changed to change the map + connect(gridType, &QComboBox::currentTextChanged, this, [=](){ + QString currentGrid=gridType->currentText(); + webView1->load(QUrl::fromLocalFile(mappscript+currentGrid+"_grid.html")); + }); } M9SingleSite::~M9SingleSite() @@ -150,13 +223,14 @@ M9SingleSite::downloadMotions(void) QString appDir = SimCenterPreferences::getInstance()->getAppDir(); QString m9Script = appDir + QDir::separator() + "applications" + QDir::separator() - + "createEVENT" + QDir::separator() + "M9" + QDir::separator() + "M9.py"; + + "createEVENT" + QDir::separator() + "M9" + QDir::separator() + "M9Run.py"; QStringList args; args << QString("--lat") << QString::number(latitude) << QString("--lng") << QString::number(longitude) << QString("-g") << currentGrid << QString("-n") << QString::number(numMotion) - << QString("-o") << destDir; + << QString("-o") << destDir + << QString("--API") << QString::number(useAPI->isChecked()); /* QJsonObject information; @@ -197,8 +271,13 @@ M9SingleSite::downloadMotions(void) // run the download in a Thread using RunPythinInThread // NOTE: do not invoke destructor .. class kills itself when python app finishes // - - errorMessage("M9 Downloading Motions .. this takes about 3 minutes per motion"); + // I useAPI is checked, then use the API print the message to the user + if (useAPI->isChecked()) { + errorMessage("M9 Downloading Motions using API .. this takes about 3 minutes per motion"); + + } else { + errorMessage("M9 running a app in Designsafe to download motions"); + } getMotions->setEnabled(false); downloadedMotions = false; motionsDownloading = true; @@ -251,6 +330,7 @@ M9SingleSite::outputToJSON(QJsonObject &jsonObject) numRealizations->outputToJSON(jsonObject); gridType->outputToJSON(jsonObject); tmpLocation->outputToJSON(jsonObject); + useAPI->outputToJSON(jsonObject); return true; } @@ -263,6 +343,7 @@ M9SingleSite::inputFromJSON(QJsonObject &jsonObject) numRealizations->inputFromJSON(jsonObject); gridType->inputFromJSON(jsonObject); tmpLocation->inputFromJSON(jsonObject); + useAPI->inputFromJSON(jsonObject); return true; } diff --git a/EVENTS/physicsBasedSimulation/M9SingleSite.h b/EVENTS/physicsBasedSimulation/M9SingleSite.h index edda5167..50c8b263 100644 --- a/EVENTS/physicsBasedSimulation/M9SingleSite.h +++ b/EVENTS/physicsBasedSimulation/M9SingleSite.h @@ -48,12 +48,13 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ #include - +#include class SC_DoubleLineEdit; class SC_IntLineEdit; class SC_DirEdit; class SC_ComboBox; class QPushButton; +class SC_CheckBox; class M9SingleSite : public SimCenterAppWidget { @@ -80,8 +81,11 @@ public slots: SC_DoubleLineEdit *lat; SC_DoubleLineEdit *lng; SC_IntLineEdit *numRealizations; - SC_DirEdit *tmpLocation; + SC_DirEdit *tmpLocation; SC_ComboBox *gridType; + SC_CheckBox *useAPI; + QWebEngineView *webView1; + QWebEngineView *webView2; int count; QPushButton *getMotions; diff --git a/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.cpp b/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.cpp index e2d478b7..890027e4 100644 --- a/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.cpp +++ b/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.cpp @@ -40,6 +40,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include "PhysicsBasedMotionSelection.h" #include "M9SingleSite.h" +#include "IstanbulSingleSite.h" #include #include @@ -79,12 +80,13 @@ PhysicsBasedMotionSelection::PhysicsBasedMotionSelection(GeneralInformationWidge QHBoxLayout *theSelectionLayout = new QHBoxLayout(); SectionTitle *label=new SectionTitle(); label->setMinimumWidth(250); - label->setText(QString("Simulated Motions Dataset")); + label->setText(QString("Physics Based Motion Type")); eventSelection = new QComboBox(); eventSelection->setObjectName("LoadingTypeCombox"); eventSelection->addItem(tr("M9")); + eventSelection->addItem(tr("Istanbul")); eventSelection->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); eventSelection->setMinimumWidth(250); @@ -107,10 +109,26 @@ PhysicsBasedMotionSelection::PhysicsBasedMotionSelection(GeneralInformationWidge theStackedWidget = new QStackedWidget(); layout->addWidget(theStackedWidget,2,1,6,1); + + + // Adding M9 theM9 = new M9SingleSite(); theStackedWidget->addWidget(theM9); + // Adding Istanbul + theIstanbul = new IstanbulSingleSite(); + theStackedWidget->addWidget(theIstanbul); + + // // check if is M9 or Istanbul + // if (eventSelection->currentText() == "M9") { + // theStackedWidget->setCurrentIndex(1); // Set index to M9 + // theCurrentEvent = theM9; // Set the current event to M9 + // } else if (eventSelection->currentText() == "Istanbul") { + // theStackedWidget->setCurrentIndex(0); // Set index to Istanbul + // theCurrentEvent = theIstanbul; // Set the current event to Istanbul + // } + QGroupBox *allWidgets = new QGroupBox(); allWidgets->setLayout(layout); @@ -196,7 +214,9 @@ void PhysicsBasedMotionSelection::eventSelectionChanged(const QString &arg1) theStackedWidget->setCurrentIndex(0); theCurrentEvent = theM9; currentEventType="M9"; - + } else if (arg1 == "Istanbul") { + theStackedWidget->setCurrentIndex(1); + theCurrentEvent = theIstanbul; } else { qDebug() << "ERROR .. PhysicsBasedMotionSelection selection .. type unknown: " << arg1; } @@ -272,9 +292,4 @@ PhysicsBasedMotionSelection::replyEventType(void) { // the Site Response and User-Defined Database are excluded emit typeEVT("None"); } -} - -bool -PhysicsBasedMotionSelection::outputCitation(QJsonObject &jsonObject) { - return theCurrentEvent->outputCitation(jsonObject); -} +} \ No newline at end of file diff --git a/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.h b/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.h index 946109c6..56108966 100644 --- a/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.h +++ b/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.h @@ -61,7 +61,6 @@ class PhysicsBasedMotionSelection : public SimCenterAppWidget bool outputAppDataToJSON(QJsonObject &rvObject); bool inputAppDataFromJSON(QJsonObject &rvObject); bool copyFiles(QString &destName); - bool outputCitation(QJsonObject &jsonObject); signals: void typeEVT(QString type); @@ -77,7 +76,8 @@ public slots: // SimCenterAppWidget *theSHA_MotionWidget; SimCenterAppWidget *theM9; + SimCenterAppWidget *theIstanbul; QString currentEventType; }; -#endif // PHYSICS_BASED_MOTION_SELECTION_H +#endif // PHYSICS_BASED_MOTION_SELECTION_H \ No newline at end of file diff --git a/EarthquakeEvents.pri b/EarthquakeEvents.pri index a3b9e5d0..38b044d6 100644 --- a/EarthquakeEvents.pri +++ b/EarthquakeEvents.pri @@ -32,6 +32,7 @@ SOURCES += \ $$PWD/EVENTS/peerNGA/surrogateGpParser.cpp \ $$PWD/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.cpp \ $$PWD/EVENTS/physicsBasedSimulation/M9SingleSite.cpp \ + $$PWD/EVENTS/physicsBasedSimulation/IstanbulSingleSite.cpp \ $$PWD/EVENTS/userDefinedDatabase/User_Defined_Database.cpp \ $$PWD/EVENTS/groundMotionModel/BakerJayaram2008.cpp @@ -58,7 +59,8 @@ HEADERS += \ $$PWD/EVENTS/peerNGA/UserSpectrumWidget.h \ $$PWD/EVENTS/peerNGA/surrogateGpParser.h \ $$PWD/EVENTS/physicsBasedSimulation/PhysicsBasedMotionSelection.h \ - $$PWD/EVENTS/physicsBasedSimulation/M9SingleSite.h \ + $$PWD/EVENTS/physicsBasedSimulation/M9SingleSite.h \ + $$PWD/EVENTS/physicsBasedSimulation/IstanbulSingleSite.h \ $$PWD/EVENTS/userDefinedDatabase/User_Defined_Database.h \ $$PWD/EVENTS/groundMotionModel/BakerJayaram2008.h