Skip to content

Commit

Permalink
Fixed bugs that surfaced in GM widget with new implementations. Chang…
Browse files Browse the repository at this point in the history
…ed version number for new release.
sgavrilovic committed Jun 23, 2021
1 parent 25424d1 commit 6daefdf
Showing 10 changed files with 101 additions and 36 deletions.
67 changes: 52 additions & 15 deletions EVENTS/UI/GMWidget.cpp
Original file line number Diff line number Diff line change
@@ -212,7 +212,7 @@ void GMWidget::setupConnections()
}
else if(type == SiteConfig::SiteType::Scatter)
{
if(!m_siteConfigWidget->getSiteScatterWidget()->copySiteFile())
if(!m_siteConfigWidget->getSiteScatterWidget()->siteFileExists())
{
QString msg = "Please choose a site file before continuing";
this->statusMessage(msg);
@@ -241,7 +241,8 @@ void GMWidget::setupConnections()

connect(&peerClient, &PeerNgaWest2Client::recordsDownloaded, this, [this](QString zipFile)
{
this->parseDownloadedRecords(zipFile);
this->parseDownloadedRecords(zipFile);
this->getProgressDialog()->hideProgressBar();
});

}
@@ -449,6 +450,18 @@ void GMWidget::runHazardSimulation(void)
file.remove();
}

// Clean out any existing input files
auto pathToInputDir = m_appConfig->getInputDirectoryPath() + QDir::separator();

QStringList nameFilters = {"SiteFile.csv","OpenQuakeSiteModel.csv","sites_oq.csv","EQHazardConfiguration.json","oq_job.ini","rupture_model_example.xml"};

QDir dir(pathToInputDir);
dir.setNameFilters(nameFilters);
dir.setFilter(QDir::Files);
foreach(QString dirFile, dir.entryList())
{
dir.remove(dirFile);
}

// Remove the grid from the visualization screen
mapViewSubWidget->removeGridFromScene();
@@ -550,6 +563,8 @@ void GMWidget::runHazardSimulation(void)

gridData.push_back(headerRow);

bool writeSiteFile = true;

if(type == SiteConfig::SiteType::Single)
{
qDebug()<<"Single site selection not supported yet";
@@ -590,15 +605,20 @@ void GMWidget::runHazardSimulation(void)
gridData.push_back(stationRow);
}
}

bool writeSiteFile = true;
if(type == SiteConfig::SiteType::Scatter)
// site file has been copied to the input directory
else if(type == SiteConfig::SiteType::Scatter)
{
// Site file will be copied to the input directory
writeSiteFile = false;

if(!m_siteConfigWidget->getSiteScatterWidget()->copySiteFile(pathToInputDir))
{
this->errorMessage("Error copying site file to inputput directory");
}
}

if(writeSiteFile)
{
QString pathToSiteLocationFile = m_appConfig->getInputDirectoryPath() + QDir::separator() + "SiteFile.csv";
QString pathToSiteLocationFile = pathToInputDir + QDir::separator() + "SiteFile.csv";

CSVReaderWriter csvTool;

@@ -614,7 +634,7 @@ void GMWidget::runHazardSimulation(void)
QString strFromObj = QJsonDocument(configFile).toJson(QJsonDocument::Indented);

// Hazard sim
QString pathToConfigFile = m_appConfig->getInputDirectoryPath() + QDir::separator() + "EQHazardConfiguration.json";
QString pathToConfigFile = pathToInputDir + QDir::separator() + "EQHazardConfiguration.json";

QFile file(pathToConfigFile);

@@ -648,6 +668,8 @@ void GMWidget::runHazardSimulation(void)

qDebug()<<"Hazard Simulation Command:"<<args[0]<<" "<<args[1]<<" "<<args[2];

this->getProgressDialog()->showProgressBar();

process->start(pythonPath, args);
process->waitForStarted();
}
@@ -890,6 +912,18 @@ int GMWidget::processDownloadedRecords(QString& errorMessage)
// Set the scale at which the layer will become visible - if scale is too high, then the entire view will be filled with symbols
// gridLayer->setMinScale(80000);

auto headers = data.front();

auto indexFile = headers.indexOf("GP_file");
auto indexLon = headers.indexOf("Longitude");
auto indexLat = headers.indexOf("Latitude");

if(indexLon == -1 || indexLat == -1 || indexFile == -1)
{
errorMessage = "Error could not find latitude and longitude in headers";
return -1;
}

// Pop off the row that contains the header information
data.pop_front();

@@ -902,30 +936,30 @@ int GMWidget::processDownloadedRecords(QString& errorMessage)

auto vecValues = data.at(i);

if(vecValues.size() != 3)
if(vecValues.size() < 3)
{
qDebug()<<"Error in importing ground motions";
errorMessage = "Error in importing ground motions";
return -1;
}

bool ok;
auto lon = vecValues[1].toDouble(&ok);
auto lon = vecValues[indexLon].toDouble(&ok);

if(!ok)
{
errorMessage = "Error converting longitude object " + vecValues[1] + " to a double";
return -1;
}

auto lat = vecValues[2].toDouble(&ok);
auto lat = vecValues[indexLat].toDouble(&ok);

if(!ok)
{
errorMessage = "Error converting latitude object " + vecValues[2] + " to a double";
return -1;
}

auto stationName = vecValues[0];
auto stationName = vecValues[indexFile];

auto stationPath = inputFile.dir().absolutePath() + QDir::separator() + stationName;

@@ -1053,8 +1087,6 @@ int GMWidget::parseDownloadedRecords(QString zipFile)

this->statusMessage("Download and parsing of ground motion records complete.");

this->getProgressDialog()->hideProgressBar();

this->statusMessage("The folder containing the results: "+m_appConfig->getOutputDirectoryPath());

this->statusMessage("Earthquake hazard simulation complete.");
@@ -1069,6 +1101,11 @@ int GMWidget::parseDownloadedRecords(QString zipFile)
return 0;
}

GmAppConfig *GMWidget::appConfig() const
{
return m_appConfig;
}


void GMWidget::setCurrentlyViewable(bool status){

2 changes: 2 additions & 0 deletions EVENTS/UI/GMWidget.h
Original file line number Diff line number Diff line change
@@ -79,6 +79,8 @@ class GMWidget : public SimCenterAppWidget
void resetAppSettings(void);
void setCurrentlyViewable(bool status);

GmAppConfig *appConfig() const;

signals:
void locationsChanged(void);
void sceneViewChanged(void);
16 changes: 13 additions & 3 deletions EVENTS/UI/OpenQuakeScenario.cpp
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

#include "OpenQuakeScenario.h"
#include "SimCenterPreferences.h"
#include "GMWidget.h"
#include "GmAppConfig.h"

#include <QFile>
#include <QFileInfo>
@@ -48,7 +50,7 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
OpenQuakeScenario::OpenQuakeScenario(double rMesh, double aMesh, double maxDist, QString rFile, QWidget *parent) :
SimCenterWidget(parent), rupMesh(rMesh), areaMesh(aMesh), maxDistance(maxDist), rupFilename(rFile)
{

gmWidget = dynamic_cast<GMWidget*>(parent);
}


@@ -133,9 +135,17 @@ QJsonObject OpenQuakeScenario::getJson()

bool OpenQuakeScenario::copyRupFile()
{

if(gmWidget == nullptr)
{
QString errMsg = QString("Could not get the GMWidget.");
this->errorMessage(errMsg);
return false;
}

// Destination directory
QString destinationDir;
destinationDir = SimCenterPreferences::getInstance()->getLocalWorkDir() + "/HazardSimulation/Input/";
QString destinationDir = gmWidget->appConfig()->getInputDirectoryPath() + QDir::separator();

QDir dirInput(destinationDir);
if (!dirInput.exists())
if (!dirInput.mkpath(destinationDir))
4 changes: 4 additions & 0 deletions EVENTS/UI/OpenQuakeScenario.h
Original file line number Diff line number Diff line change
@@ -41,6 +41,8 @@ UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#include "JsonSerializable.h"
#include "SimCenterWidget.h"

class GMWidget;

class OpenQuakeScenario : public SimCenterWidget, JsonSerializable
{
Q_OBJECT
@@ -72,6 +74,8 @@ public slots:

bool copyRupFile();

GMWidget* gmWidget;

};

#endif // OpenQuakeScenario_H
2 changes: 1 addition & 1 deletion EVENTS/UI/OpenQuakeScenarioWidget.cpp
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ OpenQuakeScenarioWidget::OpenQuakeScenarioWidget(QWidget *parent) : SimCenterWid
this->setLayout(layout);

//We need to set initial values
m_eqRupture = new OpenQuakeScenario(1.0, 10.0, 500.0, "", this);
m_eqRupture = new OpenQuakeScenario(1.0, 10.0, 500.0, "", parent);

this->m_rupMeshBox->setValue(m_eqRupture->getRupMesh());
this->m_areaMeshBox->setValue(m_eqRupture->getAreaMesh());
2 changes: 1 addition & 1 deletion EVENTS/UI/PeerNgaWest2Client.cpp
Original file line number Diff line number Diff line change
@@ -532,7 +532,7 @@ void PeerNgaWest2Client::processDownloadRecordsReply()
file.write(downloadRecordsReply->readAll());
file.close();

emit statusUpdated("Ground Motions Downloaded Sucessfully");
emit statusUpdated("Ground Motions Downloaded Successfully");
emit recordsDownloaded(recordsPath);
}

6 changes: 3 additions & 3 deletions EVENTS/UI/RuptureWidget.cpp
Original file line number Diff line number Diff line change
@@ -54,11 +54,11 @@ RuptureWidget::RuptureWidget(QWidget *parent) : SimCenterAppWidget(parent)
theRootStackedWidget = new QStackedWidget(this);
theRootStackedWidget->setContentsMargins(0,0,0,0);

pointSourceWidget = new PointSourceRuptureWidget(this);
erfWidget = new EarthquakeRuptureForecastWidget(this);
pointSourceWidget = new PointSourceRuptureWidget(parent);
erfWidget = new EarthquakeRuptureForecastWidget(parent);
// add widgets connecting the OpenQuake-type hazard
// OpenQuake scenario-based
oqsbWidget = new OpenQuakeScenarioWidget(this);
oqsbWidget = new OpenQuakeScenarioWidget(parent);

theRootStackedWidget->addWidget(pointSourceWidget);
theRootStackedWidget->addWidget(erfWidget);
32 changes: 21 additions & 11 deletions EVENTS/UI/SiteScatterWidget.cpp
Original file line number Diff line number Diff line change
@@ -218,7 +218,7 @@ void SiteScatterWidget::loadSiteFile()
return;
}
else
this->errorMessage("Site file loaded.");
this->statusMessage("Site file loaded.");
}


@@ -494,34 +494,45 @@ bool SiteScatterWidget::getFileLoaded() const
}


bool SiteScatterWidget::copySiteFile()
bool SiteScatterWidget::siteFileExists()
{
// Destination directory
QString destinationDir;
destinationDir = SimCenterPreferences::getInstance()->getLocalWorkDir() + "/HazardSimulation/Input";
QString filename = this->siteFilePath;

QFile fileToCopy(filename);

if (! fileToCopy.exists())
return false;

return true;
}


bool SiteScatterWidget::copySiteFile(const QString& destinationDir)
{

QDir dirInput(destinationDir);
if (!dirInput.exists())
{
if (!dirInput.mkpath(destinationDir))
{
QString errMsg = QString("Could not make the input directory.");
qDebug() << errMsg;
this->errorMessage(errMsg);
return false;
}
}

QString filename = this->siteFilePath;

QFile fileToCopy(filename);

if (! fileToCopy.exists()) {
if(!this->siteFileExists())
{
QString errMsg = "Cannot find the site file." + QString(filename);
qDebug() << errMsg;
this->errorMessage(errMsg);
return false;
}

QFileInfo fileInfo(filename);
QString theFile = fileInfo.fileName();
QFile fileToCopy(filename);

// Overwriting check
QFile distFile(destinationDir + QDir::separator() + "SiteFile.csv");
@@ -535,7 +546,6 @@ bool SiteScatterWidget::copySiteFile()

// Copy
return fileToCopy.copy(destinationDir + QDir::separator() + "SiteFile.csv");

}


4 changes: 3 additions & 1 deletion EVENTS/UI/SiteScatterWidget.h
Original file line number Diff line number Diff line change
@@ -53,7 +53,9 @@ class SiteScatterWidget : public SimCenterWidget

bool getFileLoaded() const;

bool copySiteFile();
bool copySiteFile(const QString& destinationDir);

bool siteFileExists();

int getMinID();
int getMaxID();
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ int main(int argc, char *argv[])
// Setting Core Application Name, Organization, Version and Google Analytics Tracking Id
QCoreApplication::setApplicationName("R2D");
QCoreApplication::setOrganizationName("SimCenter");
QCoreApplication::setApplicationVersion("1.0.1");
QCoreApplication::setApplicationVersion("1.1.0");

//GoogleAnalytics::SetTrackingId("UA-186298856-1");
GoogleAnalytics::StartSession();

0 comments on commit 6daefdf

Please sign in to comment.