Skip to content

Commit

Permalink
Rename IDD Field, move path logic into model `openstudio::path Schedu…
Browse files Browse the repository at this point in the history
…leFile::translatedFilePath() const`
  • Loading branch information
jmarrec committed Oct 31, 2023
1 parent 30e34f1 commit 7683af4
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 58 deletions.
4 changes: 3 additions & 1 deletion resources/model/OpenStudio.idd
Original file line number Diff line number Diff line change
Expand Up @@ -5111,7 +5111,9 @@ OS:Schedule:File,
\key Yes
\key No
\default Yes
A8; \field Translate File Name
A8; \field Translate File With Relative Path
\note "No" means the absolute path of the ExternalFile is resolved and translated to IDF.
\note "Yes" means only the filename (relative) is translated
\type choice
\default No
\key Yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,8 @@ namespace energyplus {
idfObject.setString(openstudio::Schedule_FileFields::ScheduleTypeLimitsName, idfScheduleTypeLimits->name().get());
}
}

path fileName;
if (modelObject.translateFileName()) {
fileName = toPath(modelObject.externalFile().fileName());
} else {
fileName = modelObject.externalFile().filePath();
if (!exists(fileName)) {
LOG(Warn, "Cannot find file \"" << fileName << "\"");
} else {
// make the path correct for this system
fileName = system_complete(fileName);
}
}

// DLM: this path is going to be in the temp dir, might want to fix it up when saving model temp dir
idfObject.setString(openstudio::Schedule_FileFields::FileName, toString(fileName));
idfObject.setString(openstudio::Schedule_FileFields::FileName, toString(modelObject.translatedFilePath()));

idfObject.setInt(openstudio::Schedule_FileFields::ColumnNumber, modelObject.columnNumber());
idfObject.setInt(openstudio::Schedule_FileFields::RowstoSkipatTop, modelObject.rowstoSkipatTop());
Expand Down
16 changes: 8 additions & 8 deletions src/energyplus/Test/ScheduleInterval_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1869,8 +1869,8 @@ TEST_F(EnergyPlusFixture, ScheduleFileRelativePath) {
boost::optional<ExternalFile> external_file = ExternalFile::getExternalFile(model, openstudio::toString(p));
ASSERT_TRUE(external_file);
ScheduleFile schedule(*external_file);
EXPECT_TRUE(schedule.setTranslateFileName(true));
EXPECT_TRUE(schedule.translateFileName());
EXPECT_TRUE(schedule.setTranslateFileWithRelativePath(true));
EXPECT_TRUE(schedule.translateFileWithRelativePath());
EXPECT_EQ(1u, model.getConcreteModelObjects<ScheduleFile>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<ExternalFile>().size());
ExternalFile externalfile = schedule.externalFile();
Expand Down Expand Up @@ -1904,8 +1904,8 @@ TEST_F(EnergyPlusFixture, ScheduleFileRelativePath) {
boost::optional<ExternalFile> external_file = ExternalFile::getExternalFile(model, openstudio::toString(p));
ASSERT_TRUE(external_file);
ScheduleFile schedule(*external_file);
EXPECT_TRUE(schedule.setTranslateFileName(true));
EXPECT_TRUE(schedule.translateFileName());
EXPECT_TRUE(schedule.setTranslateFileWithRelativePath(true));
EXPECT_TRUE(schedule.translateFileWithRelativePath());
EXPECT_EQ(1u, model.getConcreteModelObjects<ScheduleFile>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<ExternalFile>().size());
ExternalFile externalfile = schedule.externalFile();
Expand Down Expand Up @@ -1937,8 +1937,8 @@ TEST_F(EnergyPlusFixture, ScheduleFileRelativePath) {
EXPECT_FALSE(p.is_relative());

ScheduleFile schedule(model, openstudio::toString(p));
EXPECT_TRUE(schedule.setTranslateFileName(true));
EXPECT_TRUE(schedule.translateFileName());
EXPECT_TRUE(schedule.setTranslateFileWithRelativePath(true));
EXPECT_TRUE(schedule.translateFileWithRelativePath());
EXPECT_EQ(1u, model.getConcreteModelObjects<ScheduleFile>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<ExternalFile>().size());
ExternalFile externalfile = schedule.externalFile();
Expand Down Expand Up @@ -1970,8 +1970,8 @@ TEST_F(EnergyPlusFixture, ScheduleFileRelativePath) {
EXPECT_TRUE(p.is_relative());

ScheduleFile schedule(model, openstudio::toString(p));
EXPECT_TRUE(schedule.setTranslateFileName(true));
EXPECT_TRUE(schedule.translateFileName());
EXPECT_TRUE(schedule.setTranslateFileWithRelativePath(true));
EXPECT_TRUE(schedule.translateFileWithRelativePath());
EXPECT_EQ(1u, model.getConcreteModelObjects<ScheduleFile>().size());
EXPECT_EQ(1u, model.getConcreteModelObjects<ExternalFile>().size());
ExternalFile externalfile = schedule.externalFile();
Expand Down
54 changes: 36 additions & 18 deletions src/model/ScheduleFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ namespace model {
return csvFile;
}

bool ScheduleFile_Impl::translateFileName() const {
boost::optional<std::string> value = getString(OS_Schedule_FileFields::TranslateFileName, true);
bool ScheduleFile_Impl::translateFileWithRelativePath() const {
boost::optional<std::string> value = getString(OS_Schedule_FileFields::TranslateFileWithRelativePath, true);
OS_ASSERT(value);
return openstudio::istringEqual(value.get(), "Yes");
}

bool ScheduleFile_Impl::isTranslateFileNameDefaulted() const {
return isEmpty(OS_Schedule_FileFields::TranslateFileName);
bool ScheduleFile_Impl::isTranslateFileWithRelativePathDefaulted() const {
return isEmpty(OS_Schedule_FileFields::TranslateFileWithRelativePath);
}

/* FIXME!
Expand Down Expand Up @@ -386,22 +386,36 @@ namespace model {
}*/
}

bool ScheduleFile_Impl::setTranslateFileName(bool translateFileName) {
bool ScheduleFile_Impl::setTranslateFileWithRelativePath(bool translateFileWithRelativePath) {
bool result = false;
if (translateFileName) {
result = setString(OS_Schedule_FileFields::TranslateFileName, "Yes");
if (translateFileWithRelativePath) {
result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, "Yes");
} else {
result = setString(OS_Schedule_FileFields::TranslateFileName, "No");
result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, "No");
}
OS_ASSERT(result);
return result;
}

void ScheduleFile_Impl::resetTranslateFileName() {
const bool result = setString(OS_Schedule_FileFields::TranslateFileName, "");
void ScheduleFile_Impl::resetTranslateFileWithRelativePath() {
const bool result = setString(OS_Schedule_FileFields::TranslateFileWithRelativePath, "");
OS_ASSERT(result);
}

openstudio::path ScheduleFile_Impl::translatedFilePath() const {
if (translateFileWithRelativePath()) {
return toPath(externalFile().fileName());
}
openstudio::path filePath = externalFile().filePath();
if (!exists(filePath)) {
LOG(Warn, "Cannot find file \"" << filePath << "\"");
} else {
// make the path correct for this system
filePath = system_complete(filePath);
}
return filePath;
}

} // namespace detail

ScheduleFile::ScheduleFile(const ExternalFile& externalfile, int column, int rowsToSkip)
Expand Down Expand Up @@ -503,12 +517,12 @@ namespace model {
return getImpl<detail::ScheduleFile_Impl>()->csvFile();
}

bool ScheduleFile::translateFileName() const {
return getImpl<detail::ScheduleFile_Impl>()->translateFileName();
bool ScheduleFile::translateFileWithRelativePath() const {
return getImpl<detail::ScheduleFile_Impl>()->translateFileWithRelativePath();
}

bool ScheduleFile::isTranslateFileNameDefaulted() const {
return getImpl<detail::ScheduleFile_Impl>()->isTranslateFileNameDefaulted();
bool ScheduleFile::isTranslateFileWithRelativePathDefaulted() const {
return getImpl<detail::ScheduleFile_Impl>()->isTranslateFileWithRelativePathDefaulted();
}

/* FIXME!
Expand Down Expand Up @@ -585,12 +599,16 @@ unsigned ScheduleFile::addTimeSeries(const openstudio::TimeSeries& timeSeries) {
getImpl<detail::ScheduleFile_Impl>()->resetAdjustScheduleforDaylightSavings();
}

bool ScheduleFile::setTranslateFileName(bool translateFileName) {
return getImpl<detail::ScheduleFile_Impl>()->setTranslateFileName(translateFileName);
bool ScheduleFile::setTranslateFileWithRelativePath(bool translateFileWithRelativePath) {
return getImpl<detail::ScheduleFile_Impl>()->setTranslateFileWithRelativePath(translateFileWithRelativePath);
}

void ScheduleFile::resetTranslateFileWithRelativePath() {
getImpl<detail::ScheduleFile_Impl>()->resetTranslateFileWithRelativePath();
}

void ScheduleFile::resetTranslateFileName() {
getImpl<detail::ScheduleFile_Impl>()->resetTranslateFileName();
openstudio::path ScheduleFile::translatedFilePath() {
getImpl<detail::ScheduleFile_Impl>()->translatedFilePath();
}

/// @cond
Expand Down
11 changes: 7 additions & 4 deletions src/model/ScheduleFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ namespace model {

boost::optional<CSVFile> csvFile() const;

bool translateFileName() const;
bool translateFileWithRelativePath() const;

bool isTranslateFileNameDefaulted() const;
bool isTranslateFileWithRelativePathDefaulted() const;

//@}
/** @name Setters */
Expand Down Expand Up @@ -124,14 +124,17 @@ namespace model {

/* FIXME! unsigned addTimeSeries(const openstudio::TimeSeries& timeSeries); */

bool setTranslateFileName(bool translateFileName);
bool setTranslateFileWithRelativePath(bool translateFileWithRelativePath);

void resetTranslateFileName();
void resetTranslateFileWithRelativePath();

//@}
/** @name Other */
//@{

// Depending on the value of 'Translate File With Relative Path', returns an absolute or a relative path
openstudio::path translatedFilePath() const;

//@}
protected:
/// @cond
Expand Down
10 changes: 6 additions & 4 deletions src/model/ScheduleFile_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ namespace model {

boost::optional<CSVFile> csvFile() const;

bool translateFileName() const;
bool translateFileWithRelativePath() const;

bool isTranslateFileNameDefaulted() const;
bool isTranslateFileWithRelativePathDefaulted() const;

//@}
/** @name Setters */
Expand Down Expand Up @@ -125,14 +125,16 @@ namespace model {
// ensure that this object does not contain the date 2/29
virtual void ensureNoLeapDays() override;

bool setTranslateFileName(bool translateFileName);
bool setTranslateFileWithRelativePath(bool translateFileWithRelativePath);

void resetTranslateFileName();
void resetTranslateFileWithRelativePath();

//@}
/** @name Other */
//@{

openstudio::path translatedFilePath() const;

//@}
protected:
private:
Expand Down
20 changes: 12 additions & 8 deletions src/model/test/ScheduleInterval_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,18 @@ TEST_F(ModelFixture, ScheduleFile) {
schedule3.resetAdjustScheduleforDaylightSavings();
EXPECT_TRUE(schedule3.isAdjustScheduleforDaylightSavingsDefaulted());

EXPECT_FALSE(schedule3.translateFileName());
EXPECT_TRUE(schedule3.isTranslateFileNameDefaulted());
EXPECT_TRUE(schedule3.setTranslateFileName(true));
EXPECT_TRUE(schedule3.translateFileName());
EXPECT_FALSE(schedule3.isTranslateFileNameDefaulted());
schedule3.resetTranslateFileName();
EXPECT_FALSE(schedule3.translateFileName());
EXPECT_TRUE(schedule3.isTranslateFileNameDefaulted());
EXPECT_FALSE(schedule3.translateFileWithRelativePath());
EXPECT_TRUE(schedule3.isTranslateFileWithRelativePathDefaulted());
EXPECT_EQ(externalfile->filePath(), schedule3.translatedFilePath());

EXPECT_TRUE(schedule3.setTranslateFileWithRelativePath(true));
EXPECT_TRUE(schedule3.translateFileWithRelativePath());
EXPECT_FALSE(schedule3.isTranslateFileWithRelativePathDefaulted());
EXPECT_EQ(toPath(externalfile->fileName()), schedule3.translatedFilePath());

schedule3.resetTranslateFileWithRelativePath();
EXPECT_FALSE(schedule3.translateFileWithRelativePath());
EXPECT_TRUE(schedule3.isTranslateFileWithRelativePathDefaulted());

// shouldn't create a new object
boost::optional<ExternalFile> externalfile2 = ExternalFile::getExternalFile(model, openstudio::toString(p));
Expand Down

0 comments on commit 7683af4

Please sign in to comment.