Skip to content

Commit

Permalink
Merge branch 'rewetResults'
Browse files Browse the repository at this point in the history
  • Loading branch information
fmckenna committed Oct 2, 2024
2 parents 3840f60 + 67be617 commit 912dd55
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 88 deletions.
6 changes: 5 additions & 1 deletion Tools/Pelicun3PostProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@ int Pelicun3PostProcessor::addResultSubtab(QString name, QWidget* existTab, QStr
SC_ResultsWidget* existingResult = dynamic_cast<SC_ResultsWidget*>(existTab);
if (existingResult){ // Make a subtab and add to existing result tab
// DL is always the first to be called, so no need to implement this
QWidget* subTab = new QWidget(this);
QWidget* subTab = new QDockWidget(this);
existingResult->addResultSubtab(QString("subTabName"), subTab, dirName);
}
else{ //Add the subtab to docklist
QDockWidget* subTabToAdd = dynamic_cast<QDockWidget*>(existTab);
if (!subTabToAdd){
qDebug() << "Adding a tab named " + name +" which is not a QDockWidget";
return -1;
}
dockList->append(subTabToAdd);
if (dockList->count()>1){
QDockWidget* base = dockList->at(0);
Expand Down
68 changes: 29 additions & 39 deletions assetWidgets/InpFileWaterInputWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ void InpFileWaterInputWidget::handleLayerCrsChanged(const QgsCoordinateReference

bool InpFileWaterInputWidget::copyFiles(QString &destDir)
{
qDebug()<<"--------------\n"<<"Sina in copyFiles\n";
// create dir and copy motion files
QDir destDIR(destDir);
if (!destDIR.exists()) {
Expand Down Expand Up @@ -198,28 +197,29 @@ bool InpFileWaterInputWidget::copyFiles(QString &destDir)
QJsonParseError jsonError;
QJsonDocument document = QJsonDocument::fromJson(bytes, &jsonError);
if(jsonError.error != QJsonParseError::NoError) {
qDebug() << "InpFileWater::copyFiles failed to open file to read: " << jsonError.errorString();
return false;
qDebug() << "InpFileWater::copyFiles failed to open file to read: " << jsonError.errorString();
return false;
}
if(document.isObject()) {
QJsonObject jsonObj = document.object();
jsonObj.remove(QString("crs"));
jsonObj.remove(QString("CRS"));
QJsonObject crsObject;
QJsonObject propertiesObject;
propertiesObject.insert(QString("name"), crsAuthID);
crsObject.insert(QString("type"), QString("name"));
crsObject.insert(QString("properties"), propertiesObject);
jsonObj.insert("crs", crsObject);
crsSelectorWidget->outputAppDataToJSON(crsObject);
document.setObject(jsonObj);
if(!fileJSON.open( QIODevice::WriteOnly)) {
qDebug() << "InpFileWaater::copyFILES failed to open file to write: " << jsonError.errorString();
return false;
}
fileJSON.write(document.toJson());
fileJSON.close();
}

QJsonObject jsonObj = document.object();
jsonObj.remove(QString("crs"));
jsonObj.remove(QString("CRS"));
QJsonObject crsObject;
QJsonObject propertiesObject;
propertiesObject.insert(QString("name"), crsAuthID);
crsObject.insert(QString("type"), QString("name"));
crsObject.insert(QString("properties"), propertiesObject);
jsonObj.insert("crs", crsObject);
crsSelectorWidget->outputAppDataToJSON(crsObject);
document.setObject(jsonObj);
if(!fileJSON.open( QIODevice::WriteOnly)) {
qDebug() << "InpFileWaater::copyFILES failed to open file to write: " << jsonError.errorString();
return false;
}
fileJSON.write(document.toJson());
fileJSON.close();
}
}
}

Expand All @@ -246,19 +246,20 @@ bool InpFileWaterInputWidget::outputAppDataToJSON(QJsonObject &jsonObject)
QJsonObject data;

QgsCoordinateReferenceSystem qgsCRS = QgsCoordinateReferenceSystem(defaultCRS);
if (!qgsCRS.isValid()){

if (qgsCRS.isValid()){
data.insert("Default_CRS", defaultCRS);
} else {
this->errorMessage("The CRS is not valid" + inpFileLineEdit->text());
return false;
this->errorMessage("The CRS is not valid " + inpFileLineEdit->text());
return false;
}

QFileInfo inpFile(inpFileLineEdit->text());
if (inpFile.exists()){
data.insert("inpFile", inpFile.absoluteFilePath());
} else {
this->errorMessage("Cannot find inp file" + inpFileLineEdit->text());
return false;
return false;
}

QFileInfo componentFile(geoJsonFileName);
Expand Down Expand Up @@ -321,8 +322,6 @@ bool InpFileWaterInputWidget::outputAppDataToJSON(QJsonObject &jsonObject)

bool InpFileWaterInputWidget::inputAppDataFromJSON(QJsonObject &jsonObject)
{
// Check the app type
qDebug() << "------------ sina -------------\n"<<jsonObject["Application"].toString() <<"\n";
if (jsonObject.contains("Application")) {
if ("INP_FILE" != jsonObject["Application"].toString()) {
this->errorMessage("InpFileWaterInputWidget::inputFRommJSON app name conflict");
Expand All @@ -339,20 +338,17 @@ bool InpFileWaterInputWidget::inputAppDataFromJSON(QJsonObject &jsonObject)

QJsonObject appData = jsonObject["ApplicationData"].toObject();

//qDebug() << "------------ alani -------------\n"<<jsonObject["ApplicationData"] <<"\n";
if (appData.contains("Default_CRS")){
defaultCRS = appData["Default_CRS"].toString();
}
else defaultCRS = "";

qDebug() << "Khodaaaaaa: "<<defaultCRS <<"\n";

QString fileName;

if (appData.contains("inpFile")){
fileName = appData["inpFile"].toString();
}
//qDebug() << "------------ alani -------------\n"<<fileName <<"\n";

QFileInfo fileInfo(fileName);

if (fileInfo.exists()) {
Expand Down Expand Up @@ -470,12 +466,7 @@ bool InpFileWaterInputWidget::loadAssetData()
geoJsonFileName = writableDir.filePath("sc_inpFileGeoJSON.json");
QString tmp1 = writableDir.filePath("SimCenter.thing1");
QString tmp2 = writableDir.filePath("SimCenter.thing2");

qDebug() << pathInpFileWater;
qDebug() << tmp1;
qDebug() << tmp2;
qDebug() << geoJsonFileName;


createJSON(pathInpFileWater.toStdString().c_str(),
tmp1.toStdString().c_str(),
tmp2.toStdString().c_str(),
Expand All @@ -497,6 +488,7 @@ bool InpFileWaterInputWidget::loadAssetData()
//QString crsString = crs["properties"].toObject()["name"].toString();
//QgsCoordinateReferenceSystem qgsCRS = QgsCoordinateReferenceSystem(inputCRS);
QgsCoordinateReferenceSystem qgsCRS = QgsCoordinateReferenceSystem(defaultCRS);

if (!qgsCRS.isValid()){
qgsCRS.createFromOgcWmsCrs(defaultCRS);
}
Expand Down Expand Up @@ -563,8 +555,6 @@ bool InpFileWaterInputWidget::loadAssetData()
tempFile.setFileTemplate(tempFile.fileTemplate() + "_" + assetType + ".geojson");
//QString outputFile = tempDir.absolutePath() + QDir::separator() + assetType + ".geojson";

//QFile file(outputFile);
qDebug() << "SINA: "<<tempFile<<"\n";
if (tempFile.open())
{

Expand Down
8 changes: 1 addition & 7 deletions systemPerformanceWidgets/RewetRecovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,6 @@ bool RewetRecovery::outputToJSON(QJsonObject &jsonObject)
nodeTimeBasedDiscoveryTable->outputToJSON(jsonObject);
tankTimeBasedDiscoveryTable->outputToJSON(jsonObject);
pumpTimeBasedDiscoveryTable->outputToJSON(jsonObject);


//solver->outputToJSON(jsonObject);
//policyDefinitionFile->outputToJSON(jsonObject);

// inputSettings->outputToJSON(jsonObject);

return true;
}
Expand Down Expand Up @@ -532,7 +526,7 @@ bool RewetRecovery::copyFiles(QString &destDir) {

bool RewetRecovery::outputCitation(QJsonObject &citation){
QString REWETCitationKey = "REWET";
QJsonValue REWETCitationValue( "\"citations\": [{\"citation\": \"Naeimi Dafchahi, Sina. 2023. “Post-Event Restoration Simulation of Water Distribution Systems: A Generally Applicable Approach.” ProQuest Dissertations Publishing. https://delcat.primo.exlibrisgroup.com/permalink/01UDEL_INST/1sm7l75/cdi_proquest_journals_2867955179\"},{\"citation\": \"Klise, K.A., Hart, D.B., Bynum, M., Hogge, J., Haxton, T., Murray, R., Burkhardt, J. (2020). Water Network Tool for Resilience (WNTR) User Manual: Version 0.2.3. U.S. EPA Office of Research and Development, Washington, DC, EPA/600/R-20/185, 82p.\"}, {\"Rossman, L., H. Woo, M. Tryby, F. Shang, R. Janke, AND T. Haxton. EPANET 2.2 User Manual. U.S. Environmental Protection Agency, Washington, DC, EPA/600/R-20/133, 2020.\"}]}");
QJsonValue REWETCitationValue( "\"citations\": [{\"citation\": \"Naeimi, Sina, and Rachel A. Davidson. “REWET: A Tool to Model System Functioning and Restoration of Damaged Water Supply Systems.” Journal of Infrastructure Systems 30.4 (2024): 04024024.},{\"citation\": \"Klise, K.A., Hart, D.B., Bynum, M., Hogge, J., Haxton, T., Murray, R., Burkhardt, J. (2020). Water Network Tool for Resilience (WNTR) User Manual: Version 0.2.3. U.S. EPA Office of Research and Development, Washington, DC, EPA/600/R-20/185, 82p.\"}, {\"Rossman, L., H. Woo, M. Tryby, F. Shang, R. Janke, AND T. Haxton. EPANET 2.2 User Manual. U.S. Environmental Protection Agency, Washington, DC, EPA/600/R-20/133, 2020.\"}]}");
citation.insert(REWETCitationKey, REWETCitationValue);

return true;
Expand Down
Loading

0 comments on commit 912dd55

Please sign in to comment.