From 66139f393b0bab26084cf6cfe30abe14990610dd Mon Sep 17 00:00:00 2001 From: Elaine Hale Date: Mon, 25 Nov 2013 16:51:34 -0700 Subject: [PATCH] Preventing circular reference caused by opening OSP file associated with OSM and then setting that OSP's baseline to the OSM file that created it. Give user warning on opening the OSP, and then do not allow the setSeed operation to proceed. --- openstudiocore/src/analysisdriver/SimpleProject.cpp | 10 ++++++++++ openstudiocore/src/pat_app/PatApp.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/openstudiocore/src/analysisdriver/SimpleProject.cpp b/openstudiocore/src/analysisdriver/SimpleProject.cpp index c4745237aea..c8d1ae66191 100644 --- a/openstudiocore/src/analysisdriver/SimpleProject.cpp +++ b/openstudiocore/src/analysisdriver/SimpleProject.cpp @@ -561,6 +561,16 @@ namespace detail { return result; } + // is not osm that made this osp + openstudio::path osmForThisOsp = projectDir().parent_path() / toPath(projectDir().stem()); + osmForThisOsp = setFileExtension(osmForThisOsp,"osm"); + if (currentSeedLocation.path() == osmForThisOsp) { + LOG(Warn,"Cannot set seed to " << toString(currentSeedLocation.path()) << + ", because this OSP file was created by that OSM. Saving this project elsewhere " + << "before setting the baseline to that file will break the circular reference."); + return result; + } + // compatible with analysis? bool ok = analysis().setSeed(currentSeedLocation); if (!ok) { diff --git a/openstudiocore/src/pat_app/PatApp.cpp b/openstudiocore/src/pat_app/PatApp.cpp index 1c2fa385c54..a887122b4d4 100644 --- a/openstudiocore/src/pat_app/PatApp.cpp +++ b/openstudiocore/src/pat_app/PatApp.cpp @@ -66,6 +66,7 @@ #include #include #include +#include #include #include @@ -1208,6 +1209,15 @@ bool PatApp::openFile(const QString& fileName) } else { QTimer::singleShot(0, this, SLOT(markAsUnmodified())); } + openstudio::path osmForThisOsp = project->projectDir().parent_path() / toPath(project->projectDir().stem()); + osmForThisOsp = setFileExtension(osmForThisOsp,"osm"); + if (boost::filesystem::exists(osmForThisOsp)) { + QMessageBox::warning(mainWindow, + "PAT Project Associated with an OSM", + QString("This project appears to be associated with the OpenStudio Application file '") + + toQString(osmForThisOsp) + + QString("'. For best results, 'Save as ...' this project elsewhere before continuing your work.")); + } return true; } else { if (analysisdriver::OptionalSimpleProject plainProject = analysisdriver::SimpleProject::open(projectDir,options)) {