src/model/ModelObject_Impl.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef MODEL_MODELOBJECT_IMPL_HPP | ||
| 7 | #define MODEL_MODELOBJECT_IMPL_HPP | ||
| 8 | |||
| 9 | #include "ModelAPI.hpp" | ||
| 10 | #include "../utilities/idf/WorkspaceObject_Impl.hpp" | ||
| 11 | |||
| 12 | #include "../nano/nano_signal_slot.hpp" // Signal-Slot replacement | ||
| 13 | |||
| 14 | #include "../utilities/core/Optional.hpp" | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | class TimeSeries; | ||
| 19 | |||
| 20 | namespace model { | ||
| 21 | |||
| 22 | class Model; | ||
| 23 | class ModelObject; | ||
| 24 | |||
| 25 | class Component; | ||
| 26 | class LifeCycleCost; | ||
| 27 | |||
| 28 | class FieldViewer; | ||
| 29 | |||
| 30 | class ParentObject; | ||
| 31 | class ResourceObject; | ||
| 32 | |||
| 33 | class Schedule; | ||
| 34 | |||
| 35 | class OutputVariable; | ||
| 36 | class Meter; | ||
| 37 | class Connection; | ||
| 38 | |||
| 39 | class EMSActuatorNames; | ||
| 40 | |||
| 41 | class AdditionalProperties; | ||
| 42 | |||
| 43 | class ScheduleTypeKey; | ||
| 44 | |||
| 45 | namespace detail { | ||
| 46 | |||
| 47 | class Model_Impl; | ||
| 48 | |||
| 49 | /** Implementation class for ModelObject. Each class deriving from ModelObject | ||
| 50 | * should provide an implementation class that derives from ModelObject_Impl. */ | ||
| 51 | class MODEL_API ModelObject_Impl : public openstudio::detail::WorkspaceObject_Impl | ||
| 52 | { | ||
| 53 | |||
| 54 | public: | ||
| 55 | /** @name Constructors and Destructors */ | ||
| 56 | //@{ | ||
| 57 | |||
| 58 | /** Copy constructor for use by Model::Model(const Workspace&). Clones all | ||
| 59 | * WorkspaceObject_Impl data and hooks new ModelObject_Impl up to model. */ | ||
| 60 | ModelObject_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle); | ||
| 61 | |||
| 62 | /** Copy constructor. Assigns new handle, keeps same workspace pointer. Workspace should know | ||
| 63 | * whether copy is to live in original workspace, or in cloned workspace. If the latter, | ||
| 64 | * Workspace will need to update the workspace pointer, and any source and target pointer | ||
| 65 | * handles. */ | ||
| 66 | ModelObject_Impl(const ModelObject_Impl& other, Model_Impl* model, bool keepHandle); | ||
| 67 | |||
| 68 | /** Creates a new ModelObject whose underlying data is identical to *this, except that a | ||
| 69 | * new handle is assigned, and it is placed in model. */ | ||
| 70 | virtual ModelObject clone(Model model) const; | ||
| 71 | |||
| 72 | 412865 | virtual ~ModelObject_Impl() override = default; | |
| 73 | |||
| 74 | /// remove the object from the model, also removes any cost objects associated with this object | ||
| 75 | /// return std::vector<IdfObject> containing any removed object(s) | ||
| 76 | virtual std::vector<IdfObject> remove() override; | ||
| 77 | |||
| 78 | //@} | ||
| 79 | /** @name Components | ||
| 80 | * | ||
| 81 | * Once a Component has been created, it can be saved to a ProjectDatabase for local storing | ||
| 82 | * and sharing, and can be uploaded to the online Building Component Library for web-enabled | ||
| 83 | * storing and sharing. Components are the preferred method for specifying | ||
| 84 | * and inserting alternative pieces of a model (constructions, schedules, etc.) in higher-level | ||
| 85 | * libraries such as standardsinterface and analysis. */ | ||
| 86 | //@{ | ||
| 87 | |||
| 88 | /** Method with virtual implementation for creating sharable Model snippets. Creates a component | ||
| 89 | * with this ModelObject as the primary object. Clones all data. */ | ||
| 90 | virtual Component createComponent() const; | ||
| 91 | |||
| 92 | //@} | ||
| 93 | /** @name Getters */ | ||
| 94 | //@{ | ||
| 95 | |||
| 96 | /** Returns the Model that contains this object. */ | ||
| 97 | Model model() const; | ||
| 98 | |||
| 99 | /// return the parent object in the hierarchy | ||
| 100 | virtual boost::optional<ParentObject> parent() const; | ||
| 101 | |||
| 102 | /** Get the resources directly used by this ModelObject. */ | ||
| 103 | virtual std::vector<ResourceObject> resources() const; | ||
| 104 | |||
| 105 | /** Get all output variables names that could be associated with this object. These variables | ||
| 106 | * may or may not be available for each simulation, need to check report variable dictionary | ||
| 107 | * to see if the variable is available. Each concrete class should override this method.*/ | ||
| 108 | virtual const std::vector<std::string>& outputVariableNames() const = 0; | ||
| 109 | |||
| 110 | /** Get all output variables associated with this object, must run simulation to generate data. */ | ||
| 111 | virtual std::vector<OutputVariable> outputVariables() const; | ||
| 112 | |||
| 113 | /** Get data associated with this output variable and this object. */ | ||
| 114 | virtual boost::optional<openstudio::TimeSeries> getData(const OutputVariable& variable, const std::string& envPeriod) const; | ||
| 115 | |||
| 116 | std::vector<LifeCycleCost> lifeCycleCosts() const; | ||
| 117 | |||
| 118 | std::vector<IdfObject> removeLifeCycleCosts(); | ||
| 119 | |||
| 120 | /// REIMPLEMENT IN ALL CONCRETE MODEL OBJECTS (AND NOT IN ABSTRACT BASE CLASSES). | ||
| 121 | virtual IddObjectType iddObjectType() const = 0; | ||
| 122 | |||
| 123 | /** Returns this object's additional properties, constructing a new object if necessary. */ | ||
| 124 | AdditionalProperties additionalProperties() const; | ||
| 125 | |||
| 126 | bool hasAdditionalProperties() const; | ||
| 127 | |||
| 128 | /** Removes all additional properties that refer to this object. Returns removed objects. */ | ||
| 129 | std::vector<IdfObject> removeAdditionalProperties(); | ||
| 130 | |||
| 131 | boost::optional<std::string> cadObjectId() const; | ||
| 132 | |||
| 133 | bool setCADObjectId(const std::string& cadObjectId); | ||
| 134 | |||
| 135 | boost::optional<std::string> gbXMLId() const; | ||
| 136 | |||
| 137 | bool setGBXMLId(const std::string& gbXMLId); | ||
| 138 | |||
| 139 | boost::optional<std::string> displayName() const; | ||
| 140 | |||
| 141 | bool setDisplayName(const std::string& displayName); | ||
| 142 | |||
| 143 | //@} | ||
| 144 | /** @name Setters */ | ||
| 145 | //@{ | ||
| 146 | |||
| 147 | /// set the parent, child may have to call non-const methods on the parent | ||
| 148 | virtual bool setParent(ParentObject& newParent); | ||
| 149 | |||
| 150 | //@} | ||
| 151 | /** @name Queries */ | ||
| 152 | //@{ | ||
| 153 | |||
| 154 | /** Return the ScheduleTypeKeys indicating how schedule is used in this object. If schedule is not directly | ||
| 155 | * used by this object, return value will be .empty(). | ||
| 156 | * | ||
| 157 | * REIMPLEMENT IN ALL CONCRETE MODELOBJECTS THAT CAN POINT TO SCHEDULES. */ | ||
| 158 | virtual std::vector<ScheduleTypeKey> getScheduleTypeKeys(const Schedule& schedule) const; | ||
| 159 | |||
| 160 | virtual std::vector<EMSActuatorNames> emsActuatorNames() const; | ||
| 161 | |||
| 162 | virtual std::vector<std::string> emsInternalVariableNames() const; | ||
| 163 | |||
| 164 | //@} | ||
| 165 | /** @name HVAC System Connections */ | ||
| 166 | //@{ | ||
| 167 | |||
| 168 | boost::optional<ModelObject> connectedObject(unsigned port) const; | ||
| 169 | |||
| 170 | boost::optional<unsigned> connectedObjectPort(unsigned port) const; | ||
| 171 | |||
| 172 | //@} | ||
| 173 | /** @name Nano Signals */ | ||
| 174 | //@{ | ||
| 175 | |||
| 176 | //@} | ||
| 177 | |||
| 178 | /** Gets the autosized component value from the sql file **/ | ||
| 179 | boost::optional<double> getAutosizedValue(const std::string& valueName, const std::string& units, std::string overrideCompType = "") const; | ||
| 180 | |||
| 181 | protected: | ||
| 182 | ModelObject_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle); | ||
| 183 | |||
| 184 | ModelObject_Impl(IddObjectType type, Model_Impl* model); | ||
| 185 | |||
| 186 | /** Returns a bool for field index. Throws if unable to deduce a value. Should only | ||
| 187 | * be used for defaulted or required boolean fields. */ | ||
| 188 | bool getBooleanFieldValue(unsigned index) const; | ||
| 189 | |||
| 190 | /** Set a bool for field index. Throws if unsuccessful (and returns false). Should only be used for defaulted | ||
| 191 | * or required boolean fields. */ | ||
| 192 | bool setBooleanFieldValue(unsigned index, bool value); | ||
| 193 | |||
| 194 | /** This is solely to prevent implicit conversion of types to bool. This will cause a link time | ||
| 195 | * error if anything other than a bool is used for value. This has no implementation. */ | ||
| 196 | template <class T> | ||
| 197 | bool setBooleanFieldValue(unsigned index, const T& value); | ||
| 198 | |||
| 199 | /** Sets index to point to schedule if schedule's ScheduleTypeLimits are compatible with the | ||
| 200 | * ScheduleType in the ScheduleTypeRegistry for (className,scheduleDisplayName), or if | ||
| 201 | * schedule's ScheduleTypeLimits have not yet been set (in which case the ScheduleTypeRegistry | ||
| 202 | * is used to retrieve or create an appropriate one). */ | ||
| 203 | bool setSchedule(unsigned index, const std::string& className, const std::string& scheduleDisplayName, Schedule& schedule); | ||
| 204 | |||
| 205 | /** For stuff that's plain missing from ComponentSizes table in E+, so getAutosizedValue can't work. | ||
| 206 | * This method is slower as it executes a lot more queries (an average of 10, versus 1 for getAutosizedValue) */ | ||
| 207 | boost::optional<double> getAutosizedValueFromInitializationSummary(const std::string& valueName, const std::string& units) const; | ||
| 208 | |||
| 209 | private: | ||
| 210 | − | REGISTER_LOGGER("openstudio.model.ModelObject"); | |
| 211 | |||
| 212 | // vector of connections to other ModelObject "ports" | ||
| 213 | std::vector<std::shared_ptr<Connection>> m_connectionVector; | ||
| 214 | |||
| 215 | boost::optional<ModelObject> parentAsModelObject() const; | ||
| 216 | |||
| 217 | std::vector<ModelObject> resourcesAsModelObjects() const; | ||
| 218 | |||
| 219 | bool setParentAsModelObject(boost::optional<ModelObject> modelObject); | ||
| 220 | |||
| 221 | // set name from optional string for name property | ||
| 222 | bool mf_setName(const boost::optional<std::string>& name); | ||
| 223 | |||
| 224 | // get specific key value from optional key value which might be '*' | ||
| 225 | boost::optional<std::string> getSpecificKeyValue(OptionalString keyValue) const; | ||
| 226 | }; | ||
| 227 | |||
| 228 | using ModelObject_ImplPtr = std::shared_ptr<ModelObject_Impl>; | ||
| 229 | |||
| 230 | } // namespace detail | ||
| 231 | } // namespace model | ||
| 232 | } // namespace openstudio | ||
| 233 | |||
| 234 | #endif | ||
| 235 |