private void step1() { List<IfcDistributionPort> ports = model.getAll(IfcDistributionPort.class); for (IfcDistributionPort port : ports) { if (port.getConnectedTo().size() == 0 && port.getConnectedFrom().size() == 0) { out.println("Step 1: DistributionPort = " + port.getName()); step2(port); } } }
@SuppressWarnings("unchecked") @Override public Set<T> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException { Map<Long, Revision> oidToRoidMap = new HashMap<Long, Revision>(); // Look in the cache Set<EidClash> clashDetections = bimServer.getClashDetectionCache().getClashDetection(clashDetectionSettings); if (clashDetections != null) { return (Set<T>) clashDetections; } Project project = null; IfcModelSet ifcModelSet = new IfcModelSet(); for (Revision revision : clashDetectionSettings.getRevisions()) { project = revision.getProject(); for (ConcreteRevision concreteRevision : revision.getConcreteRevisions()) { IfcModel source = new IfcModel(); getDatabaseSession() .getMap( source, concreteRevision.getProject().getId(), concreteRevision.getId(), true, null); source.setDate(concreteRevision.getDate()); ifcModelSet.add(source); for (Long oid : source.keySet()) { oidToRoidMap.put(oid, revision); } } } IfcModelInterface ifcModel = bimServer.getMergerFactory().createMerger().merge(project, ifcModelSet, false); IfcModel newModel = new IfcModel(); Map<IdEObject, IdEObject> converted = new HashMap<IdEObject, IdEObject>(); for (IdEObject idEObject : ifcModel.getValues()) { if (!clashDetectionSettings.getIgnoredClasses().contains(idEObject.eClass().getName())) { cleanupModel(idEObject.eClass(), idEObject, newModel, ifcModel, converted); } } Collection<SerializerPlugin> allSerializerPlugins = bimServer.getPluginManager().getAllSerializerPlugins("application/ifc", true); if (!allSerializerPlugins.isEmpty()) { SerializerPlugin serializerPlugin = allSerializerPlugins.iterator().next(); EmfSerializer ifcSerializer = serializerPlugin.createSerializer(); try { try { ifcSerializer.init( newModel, null, bimServer.getPluginManager(), bimServer.getPluginManager().requireIfcEngine().createIfcEngine()); byte[] bytes = ifcSerializer.getBytes(); Plugin plugin = bimServer .getPluginManager() .getPlugin("org.bimserver.ifcengine.TNOIfcEnginePlugin", true); if (plugin != null && plugin instanceof IfcEnginePlugin) { IfcEnginePlugin ifcEnginePlugin = (IfcEnginePlugin) plugin; IfcEngine ifcEngine = ifcEnginePlugin.createIfcEngine(); ifcEngine.init(); IfcEngineModel ifcEngineModel = ifcEngine.openModel(bytes); try { Set<IfcEngineClash> clashes = ifcEngineModel.findClashesWithEids(clashDetectionSettings.getMargin()); Set<EidClash> eidClashes = new HashSet<EidClash>(); for (IfcEngineClash clash : clashes) { EidClash eidClash = StoreFactory.eINSTANCE.createEidClash(); eidClash.setEid1(clash.getEid1()); eidClash.setEid2(clash.getEid2()); eidClash.setName1(clash.getName1()); eidClash.setName2(clash.getName2()); eidClash.setType1(clash.getType1()); eidClash.setType2(clash.getType2()); eidClashes.add(eidClash); } // Store in cache bimServer .getClashDetectionCache() .storeClashDetection(clashDetectionSettings, eidClashes); for (EidClash clash : eidClashes) { IfcRoot object1 = (IfcRoot) newModel.get(clash.getEid1()); clash.setName1(object1.getName()); clash.setType1(object1.eClass().getName()); clash.setRevision1(oidToRoidMap.get(clash.getEid1())); IfcRoot object2 = (IfcRoot) newModel.get(clash.getEid2()); clash.setName2(object2.getName()); clash.setType2(object2.eClass().getName()); clash.setRevision2(oidToRoidMap.get(clash.getEid2())); } return (Set<T>) eidClashes; } finally { ifcEngineModel.close(); ifcEngine.close(); } } } catch (PluginException e) { LOGGER.error("", e); } } catch (SerializerException e) { LOGGER.error("", e); } } return null; }
@SuppressWarnings("unchecked") private IdEObject cleanupModel( EClass originalEClass, IdEObject original, IfcModelInterface newModel, IfcModelInterface ifcModel, Map<IdEObject, IdEObject> converted) throws UserException { if (converted.containsKey(original)) { return converted.get(original); } IdEObject newObject = (IdEObject) original.eClass().getEPackage().getEFactoryInstance().create(original.eClass()); ((IdEObjectImpl) newObject).setOid(original.getOid()); converted.put(original, newObject); if (!(newObject instanceof WrappedValue) && !(newObject instanceof IfcGloballyUniqueId)) { newModel.add(newObject.getOid(), newObject); } ObjectIDM objectIDM; try { objectIDM = bimServer.getPluginManager().requireObjectIDM(); } catch (ObjectIDMException e) { throw new UserException(e); } for (EStructuralFeature eStructuralFeature : original.eClass().getEAllStructuralFeatures()) { if (objectIDM.shouldFollowReference(originalEClass, original.eClass(), eStructuralFeature)) { Object get = original.eGet(eStructuralFeature); if (eStructuralFeature instanceof EAttribute) { if (get instanceof Double) { EStructuralFeature doubleStringFeature = original.eClass().getEStructuralFeature("wrappedValueAsString"); if (doubleStringFeature != null) { Object doubleString = original.eGet(doubleStringFeature); newObject.eSet(doubleStringFeature, doubleString); } else { newObject.eSet(eStructuralFeature, get); } } else { newObject.eSet(eStructuralFeature, get); } } else if (eStructuralFeature instanceof EReference) { if (get == null) { } else { if (eStructuralFeature.isMany()) { BasicEList<EObject> list = (BasicEList<EObject>) get; BasicEList<EObject> toList = (BasicEList<EObject>) newObject.eGet(eStructuralFeature); for (Object o : list) { if (converted.containsKey(o)) { toList.addUnique(converted.get(o)); } else { IdEObject result = cleanupModel(originalEClass, (IdEObject) o, newModel, ifcModel, converted); if (result != null) { toList.addUnique(result); } } } } else { if (converted.containsKey(get)) { newObject.eSet(eStructuralFeature, converted.get(get)); } else { newObject.eSet( eStructuralFeature, cleanupModel(originalEClass, (IdEObject) get, newModel, ifcModel, converted)); } } } } } } return newObject; }