| 1334 | } |
| 1335 | |
| 1336 | boost::optional<ComponentData> Model_Impl::insertComponent(const Component& component) { |
| 1337 | ComponentData newComponentData = component.componentData(); |
| 1338 | for (const ComponentWatcher& cw : m_componentWatchers) { |
| 1339 | ComponentData candidate = cw.componentData(); |
| 1340 | if (candidate.uuid() == newComponentData.uuid()) { |
| 1341 | if (candidate.versionUUID() != newComponentData.versionUUID()) { |
| 1342 | LOG(Warn, "Component '" << newComponentData.nameString() << "' to be inserted into Model is " |
| 1343 | << "already in Model as determined by UUID comparison, but has a different version. " |
| 1344 | << "Returning the version already in Model; if you would like to use both versions, " |
| 1345 | << "please create a new UUID for one of the Components."); |
| 1346 | } |
| 1347 | return candidate; |
| 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | // Start by deleting existing Unique ModelObject, without touching children/resources by calling WorkspaceObject::remove |
| 1352 | for (const WorkspaceObject& componentObject : component.objects()) { |
| 1353 | auto compIddObject = componentObject.iddObject(); |
| 1354 | if (compIddObject.properties().unique) { |
| 1355 | // Remove any existing objects (there should really be only one) |
| 1356 | for (WorkspaceObject& wo : model().getObjectsByType(compIddObject)) { |
| 1357 | LOG(Info, "Removing existing UniqueModelObject in the target model: " << wo.briefDescription()); |
| 1358 | wo.remove(); |
| 1359 | } |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | WorkspaceObjectVector resultingObjects = model().addObjects(component.objects()); |
| 1364 | if (resultingObjects.empty()) { |
| 1365 | return boost::none; |
| 1366 | } |
| 1367 | OS_ASSERT(resultingObjects.size() == component.numObjects()); |
| 1368 | for (const WorkspaceObject& wo : resultingObjects) { |
| 1369 | OptionalComponentData ocd = wo.optionalCast<ComponentData>(); |
| 1370 | if (ocd) { |
| 1371 | ComponentData componentDataObject = *ocd; |
| 1372 | mf_createComponentWatcher(componentDataObject); |
| 1373 | return componentDataObject; |
| 1374 | } |
| 1375 | } |
| 1376 | OS_ASSERT(false); |
| 1377 | return boost::none; |
| 1378 | } |
| 1379 | |
| 1380 | std::vector<openstudio::IdfObject> Model_Impl::purgeUnusedResourceObjects() { |
| 1381 | ResourceObjectVector resources = model().getModelObjects<ResourceObject>(); |