Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[internal] Schedule:File relative paths mod #5010

Merged
merged 2 commits into from Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion resources/model/OpenStudio.idd
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this name more clear.

\note "No" means the absolute path of the ExternalFile is resolved and translated to IDF.
\note "Yes" means only the filename (relative) is translated
Comment on lines +5115 to +5116
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

\type choice
\default No
\key Yes
Expand Down
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
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
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;
}
Comment on lines +405 to +417
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


} // 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() const {
return getImpl<detail::ScheduleFile_Impl>()->translatedFilePath();
}

/// @cond
Expand Down
11 changes: 7 additions & 4 deletions src/model/ScheduleFile.hpp
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
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
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