private void processStorey(Building building, IfcBuildingStorey ifcBuildingStorey) throws SerializerException { for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) { for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) { if (ifcObjectDefinition instanceof IfcSpace) { IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition; processSpace(building, ifcSpace); } } } for (IfcRelContainedInSpatialStructure ifcRelContainedInSpatialStructure : ifcBuildingStorey.getContainsElements()) { for (IfcProduct ifcProduct : ifcRelContainedInSpatialStructure.getRelatedElements()) { if (!convertedObjects.containsKey(ifcProduct)) { Room room = createFakeRoom(building); processBoundary(building, room, ifcProduct, null); if (ifcProduct instanceof IfcSpace) { IfcSpace ifcSpace = (IfcSpace) ifcProduct; processSpace(building, ifcSpace); } else if (ifcProduct instanceof IfcSlab) { convertSlab(building, room, (IfcSlab) ifcProduct); } } } } for (IfcRelContainedInSpatialStructure spatialStructure : ifcBuildingStorey.getContainsElements()) { for (IfcProduct ifcProduct : spatialStructure.getRelatedElements()) { if (ifcProduct instanceof IfcRoof) { RoofSurface roofSurface = new RoofSurface(); MultiSurfaceProperty roofMSP = new MultiSurfaceProperty(); MultiSurface roofMs = new MultiSurface(); roofMSP.setMultiSurface(roofMs); roofSurface.setLod4MultiSurface(roofMSP); setGeometry(roofMs, (IfcProduct) ifcProduct); BoundarySurfaceProperty boundarySurfaceProperty = new BoundarySurfaceProperty(); boundarySurfaceProperty.setObject(roofSurface); convertedObjects.put(ifcProduct, roofSurface); setName(roofSurface.getName(), ifcProduct.getName()); setGlobalId(roofSurface, ifcProduct); // IfcRoof ifcRoof = (IfcRoof) ifcProduct; // RoofTypeEnum roofTypeEnum = // RoofTypeEnum.valueOf(ifcRoof.getShapeType().getName()); // roofSurface.addGenericApplicationPropertyOfCityObject(roofTypeEnum); building.addBoundedBySurface(boundarySurfaceProperty); } else { List<Element> processProduct = processProduct(ifcProduct); if (processProduct != null) { for (Element element : processProduct) { building.addGenericADEComponent(new ADEComponent(element)); } } } } } }
public static void main(String[] args) { try { PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(new File("home")); DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true); Deserializer deserializer = deserializerPlugin.createDeserializer(null); deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")); IfcModelInterface model = deserializer.read(new File("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc")); deserializer = deserializerPlugin.createDeserializer(null); deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1")); IfcModelInterface furnishingModel = deserializer.read(new File("test.ifc")); model.fixOids(new IncrementingOidProvider()); long oid = model.getHighestOid(); IncrementingOidProvider oidProvider = new IncrementingOidProvider(oid + 1); IfcFurnishingElement picknick = (IfcFurnishingElement) furnishingModel.getByName( Ifc2x3tc1Package.eINSTANCE.getIfcFurnishingElement(), "Picknik Bank"); ModelHelper modelHelper = new ModelHelper( pluginManager.getMetaDataManager(), new HideAllInversesObjectIDM( CollectionUtils.singleSet(Ifc2x3tc1Package.eINSTANCE), pluginManager.requireSchemaDefinition("ifc2x3tc1")), model); IfcProductDefinitionShape representation = (IfcProductDefinitionShape) picknick.getRepresentation(); IfcRepresentation surfaceModel = null; IfcRepresentation boundingBox = null; for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) { IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation; if (ifcShapeRepresentation.getRepresentationType().equals("SurfaceModel")) { surfaceModel = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false); } else if (ifcShapeRepresentation.getRepresentationType().equals("BoundingBox")) { boundingBox = (IfcRepresentation) modelHelper.copy(ifcShapeRepresentation, false); } } IfcOwnerHistory ownerHistory = null; List<IfcOwnerHistory> all = model.getAll(IfcOwnerHistory.class); if (all.size() > 0) { ownerHistory = all.get(0); } for (IfcBuildingStorey ifcBuildingStorey : model.getAll(IfcBuildingStorey.class)) { for (IfcRelDecomposes ifcRelDecomposes : ifcBuildingStorey.getIsDecomposedBy()) { for (IfcObjectDefinition ifcObjectDefinition : ifcRelDecomposes.getRelatedObjects()) { if (ifcObjectDefinition instanceof IfcSpace) { IfcSpace ifcSpace = (IfcSpace) ifcObjectDefinition; // IfcProductDefinitionShape slabRepr = (IfcProductDefinitionShape) // ifcSpace.getRepresentation(); // IfcBoundingBox box = null; // for (IfcRepresentation representation2 : slabRepr.getRepresentations()) { // IfcShapeRepresentation shapeRepresentation = // (IfcShapeRepresentation)representation2; // if (shapeRepresentation.getRepresentationType().equals("BoundingBox")) { // for (IfcRepresentationItem i2 : shapeRepresentation.getItems()) { // box = (IfcBoundingBox)i2; // } // } // } IfcFurnishingElement newFurnishing = model.create(IfcFurnishingElement.class, oidProvider); IfcRelContainedInSpatialStructure containedInSpatialStructure2 = model.create(IfcRelContainedInSpatialStructure.class, oidProvider); containedInSpatialStructure2.setRelatingStructure(ifcBuildingStorey); containedInSpatialStructure2.getRelatedElements().add(newFurnishing); newFurnishing.setName("Generated"); newFurnishing.setGlobalId("TEST"); newFurnishing.setOwnerHistory(ownerHistory); IfcProductDefinitionShape definitionShape = model.create(IfcProductDefinitionShape.class, oidProvider); newFurnishing.setRepresentation(definitionShape); definitionShape.getRepresentations().add(boundingBox); definitionShape.getRepresentations().add(surfaceModel); IfcLocalPlacement localPlacement = model.create(IfcLocalPlacement.class, oidProvider); localPlacement.setPlacementRelTo(ifcSpace.getObjectPlacement()); IfcAxis2Placement3D axis2Placement3D = model.create(IfcAxis2Placement3D.class, oidProvider); localPlacement.setRelativePlacement(axis2Placement3D); IfcCartesianPoint pos = model.create(IfcCartesianPoint.class, oidProvider); pos.getCoordinates().add(-3d); pos.getCoordinates().add(+0.5d); pos.getCoordinates().add(0d); axis2Placement3D.setLocation(pos); newFurnishing.setObjectPlacement(localPlacement); } } } } model.resetExpressIds(); SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin( "org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true); Serializer serializer = serializerPlugin.createSerializer(null); serializer.init(model, null, pluginManager, null, null, true); serializer.writeToFile(new File("withfurn.ifc"), null); } catch (PluginException e) { e.printStackTrace(); } catch (DeserializeException e) { e.printStackTrace(); } catch (IfcModelInterfaceException e) { e.printStackTrace(); } catch (SerializerException e) { e.printStackTrace(); } }