Skip to content

Commit

Permalink
Merge pull request #4892 from NREL/surf-prop-exp-method
Browse files Browse the repository at this point in the history
Add surface method for `SurfacePropertyExposedFoundationPerimeter`
  • Loading branch information
jmarrec committed Jun 5, 2023
2 parents 76940af + 6c84b6c commit 872300d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "../../model/Model.hpp"
#include "../../model/SurfacePropertyExposedFoundationPerimeter.hpp"
#include "../../model/SurfacePropertyExposedFoundationPerimeter_Impl.hpp"
#include "../../model/Surface.hpp"

#include <utilities/idd/SurfaceProperty_ExposedFoundationPerimeter_FieldEnums.hxx>
#include "../../utilities/idd/IddEnums.hpp"
Expand All @@ -51,7 +52,7 @@ namespace energyplus {

m_idfObjects.push_back(idfObject);

idfObject.setString(SurfaceProperty_ExposedFoundationPerimeterFields::SurfaceName, modelObject.surfaceName());
idfObject.setString(SurfaceProperty_ExposedFoundationPerimeterFields::SurfaceName, modelObject.surface().nameString());

idfObject.setString(SurfaceProperty_ExposedFoundationPerimeterFields::ExposedPerimeterCalculationMethod,
modelObject.exposedPerimeterCalculationMethod());
Expand Down
23 changes: 17 additions & 6 deletions src/model/SurfacePropertyExposedFoundationPerimeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ namespace model {
return SurfacePropertyExposedFoundationPerimeter::iddObjectType();
}

std::string SurfacePropertyExposedFoundationPerimeter_Impl::surfaceName() const {
boost::optional<Surface> surface =
getObject<ModelObject>().getModelObjectTarget<Surface>(OS_SurfaceProperty_ExposedFoundationPerimeterFields::SurfaceName);
OS_ASSERT(surface);
return surface.get().name().get();
Surface SurfacePropertyExposedFoundationPerimeter_Impl::surface() const {
boost::optional<Surface> value = optionalSurface();
if (!value) {
LOG_AND_THROW(briefDescription() << " does not have an Surface attached.");
}
return value.get();
}

boost::optional<Surface> SurfacePropertyExposedFoundationPerimeter_Impl::optionalSurface() const {
return getObject<ModelObject>().getModelObjectTarget<Surface>(OS_SurfaceProperty_ExposedFoundationPerimeterFields::SurfaceName);
}

std::string SurfacePropertyExposedFoundationPerimeter_Impl::exposedPerimeterCalculationMethod() const {
Expand Down Expand Up @@ -170,7 +175,13 @@ namespace model {
}

std::string SurfacePropertyExposedFoundationPerimeter::surfaceName() const {
return getImpl<detail::SurfacePropertyExposedFoundationPerimeter_Impl>()->surfaceName();
LOG(Warn, "As of 3.7.0, surfaceName is deprecated. Use surface.nameString instead. It will be "
"removed within three releases.");
return getImpl<detail::SurfacePropertyExposedFoundationPerimeter_Impl>()->surface().nameString();
}

Surface SurfacePropertyExposedFoundationPerimeter::surface() const {
return getImpl<detail::SurfacePropertyExposedFoundationPerimeter_Impl>()->surface();
}

std::string SurfacePropertyExposedFoundationPerimeter::exposedPerimeterCalculationMethod() const {
Expand Down
5 changes: 4 additions & 1 deletion src/model/SurfacePropertyExposedFoundationPerimeter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <vector>
#include "ModelAPI.hpp"
#include "ModelObject.hpp"
#include "../utilities/core/Deprecated.hpp"

namespace openstudio {
namespace model {
Expand Down Expand Up @@ -68,7 +69,9 @@ namespace model {
/** @name Getters */
//@{

std::string surfaceName() const;
OS_DEPRECATED std::string surfaceName() const;

Surface surface() const;

std::string exposedPerimeterCalculationMethod() const;

Expand Down
6 changes: 5 additions & 1 deletion src/model/SurfacePropertyExposedFoundationPerimeter_Impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
namespace openstudio {
namespace model {

class Surface;

namespace detail {

/** SurfacePropertyExposedFoundationPerimeter_Impl is a ModelObject_Impl that is the implementation class for SurfacePropertyExposedFoundationPerimeter.*/
Expand Down Expand Up @@ -67,7 +69,7 @@ namespace model {
/** @name Getters */
//@{

std::string surfaceName() const;
Surface surface() const;

std::string exposedPerimeterCalculationMethod() const;

Expand Down Expand Up @@ -101,6 +103,8 @@ namespace model {
protected:
private:
REGISTER_LOGGER("openstudio.model.SurfacePropertyExposedFoundationPerimeter");

boost::optional<Surface> optionalSurface() const;
};

} // namespace detail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,11 @@ TEST_F(ModelFixture, SurfacePropertyExposedFoundationPerimeter_SurfaceName) {
surface.createSurfacePropertyExposedFoundationPerimeter("TotalExposedPerimeter", 100);
auto prop = optprop.get();
EXPECT_EQ("Surface 1", prop.surfaceName());
EXPECT_EQ(surface.handle(), prop.surface().handle());
Surface surface2(points, model);
boost::optional<SurfacePropertyExposedFoundationPerimeter> optprop2 =
surface2.createSurfacePropertyExposedFoundationPerimeter("TotalExposedPerimeter", 100);
auto prop2 = optprop2.get();
EXPECT_EQ("Surface 2", prop2.surfaceName());
EXPECT_EQ(surface2.handle(), prop2.surface().handle());
}

0 comments on commit 872300d

Please sign in to comment.