| 178 | } |
| 179 | |
| 180 | bool addEnergyPlusOutputRequest(Workspace& workspace, IdfObject& idfObject) { |
| 181 | const auto iddObject = idfObject.iddObject(); |
| 182 | const bool is_unique = iddObject.properties().unique; |
| 183 | const auto iddObjectType = iddObject.type(); |
| 184 | |
| 185 | // If not marked safe, we Warn, but we let you do it anyways |
| 186 | if (isEnergyPlusOutputRequestPotentiallyUnsafe(iddObjectType)) { |
| 187 | LOG_FREE(Warn, "openstudio.worklow.Util", |
| 188 | "Requested to add an EnergyPlus Output Request of type '" |
| 189 | << iddObjectType.valueName() << "' which is not marked as safe: make sure you aren't going to modify the energy usage of the model."); |
| 190 | } |
| 191 | |
| 192 | if (!is_unique) { |
| 193 | |
| 194 | // If already present, don't do it |
| 195 | for (const auto& wo : workspace.getObjectsByType(iddObjectType)) { |
| 196 | if (idfObject.dataFieldsEqual(wo)) { |
| 197 | return false; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | workspace.addObject(idfObject); |
| 202 | |
| 203 | return true; |
| 204 | } else if (iddObjectType == IddObjectType::Output_Table_SummaryReports) { |
| 205 | auto summaryReports = workspace.getObjectsByType(iddObjectType); |
| 206 | if (summaryReports.empty()) { |
| 207 | workspace.addObject(idfObject); |
| 208 | return true; |
| 209 | } else { |
| 210 | return mergeOutputTableSummaryReports(summaryReports.front(), idfObject); |
| 211 | } |
| 212 | } else { |
| 213 | // It's a unique one, for which we didn't write a merge, so remove it first |
| 214 | auto existingUniqueObjects = workspace.getObjectsByType(iddObjectType); |
| 215 | if (!existingUniqueObjects.empty()) { |
| 216 | // Technically it should be size == 1 |
| 217 | if (std::ranges::any_of(existingUniqueObjects, [&idfObject](const auto& wo) { return idfObject.dataFieldsEqual(wo); })) { |
| 218 | return false; |
| 219 | } |
| 220 | for (auto& wo : existingUniqueObjects) { |
| 221 | wo.remove(); |
| 222 | } |
| 223 | } |
| 224 | workspace.addObject(idfObject); |
| 225 | return true; |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /***************************************************************************************************************************************************** |
| 230 | * O U T P U T A D A P T E R * |