| 159 | } |
| 160 | |
| 161 | std::vector<ModelObject> getRecursiveChildrenAndResources(const ModelObject& object) { |
| 162 | std::set<Handle> resultSet; |
| 163 | std::pair<HandleSet::const_iterator, bool> insertResult; |
| 164 | std::vector<ModelObject> result; |
| 165 | resultSet.insert(object.handle()); |
| 166 | result.push_back(object); |
| 167 | |
| 168 | std::deque<ModelObject> objectQueue; |
| 169 | objectQueue.push_back(object); |
| 170 | |
| 171 | while (!objectQueue.empty()) { |
| 172 | ModelObject currentObject(objectQueue[0]); |
| 173 | objectQueue.pop_front(); |
| 174 | // resources |
| 175 | for (const ResourceObject& resource : currentObject.resources()) { |
| 176 | insertResult = resultSet.insert(resource.handle()); |
| 177 | if (insertResult.second) { |
| 178 | // new object |
| 179 | auto mo = resource.cast<ModelObject>(); |
| 180 | result.push_back(mo); |
| 181 | objectQueue.push_back(mo); |
| 182 | } |
| 183 | } |
| 184 | // children |
| 185 | OptionalParentObject opo = currentObject.optionalCast<ParentObject>(); |
| 186 | if (opo) { |
| 187 | ParentObject currentParent(*opo); |
| 188 | for (const ModelObject& child : currentParent.children()) { |
| 189 | insertResult = resultSet.insert(child.handle()); |
| 190 | if (insertResult.second) { |
| 191 | // new object |
| 192 | result.push_back(child); |
| 193 | objectQueue.push_back(child); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return result; |
| 200 | } |
| 201 | |
| 202 | } // namespace model |
| 203 | } // namespace openstudio |