Search in sources :

Example 1 with IfcOwnerHistory

use of org.bimserver.models.ifc2x3tc1.IfcOwnerHistory in project BIMserver by opensourceBIM.

the class AddFurniture method main.

public static void main(String[] args) {
    try {
        PluginManager pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, Paths.get("../TestData/data/AC9R1-Haus-G-H-Ver2-2x3.ifc"));
        deserializer = deserializerPlugin.createDeserializer(null);
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface furnishingModel = DeserializerUtils.readFromFile(deserializer, Paths.get("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.getMetaDataManager().getPackageMetaData("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, true);
        SerializerUtils.writeToFile(serializer, Paths.get("withfurn.ifc"));
    } catch (PluginException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcObjectDefinition(org.bimserver.models.ifc2x3tc1.IfcObjectDefinition) IfcSpace(org.bimserver.models.ifc2x3tc1.IfcSpace) FileNotFoundException(java.io.FileNotFoundException) IfcOwnerHistory(org.bimserver.models.ifc2x3tc1.IfcOwnerHistory) PluginManager(org.bimserver.plugins.PluginManager) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductDefinitionShape(org.bimserver.models.ifc2x3tc1.IfcProductDefinitionShape) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) IfcBuildingStorey(org.bimserver.models.ifc2x3tc1.IfcBuildingStorey) Serializer(org.bimserver.plugins.serializers.Serializer) ModelHelper(org.bimserver.plugins.ModelHelper) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) IfcRelDecomposes(org.bimserver.models.ifc2x3tc1.IfcRelDecomposes) Deserializer(org.bimserver.plugins.deserializers.Deserializer) HideAllInversesObjectIDM(org.bimserver.plugins.objectidms.HideAllInversesObjectIDM) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)

Example 2 with IfcOwnerHistory

use of org.bimserver.models.ifc2x3tc1.IfcOwnerHistory in project BIMserver by opensourceBIM.

the class RichIfcModel method createDefaultProjectStructure.

public IfcBuilding createDefaultProjectStructure() throws IfcModelInterfaceException {
    IfcPerson person = create(IfcPerson.class);
    IfcOrganization organization = create(IfcOrganization.class);
    organization.setName("Required");
    IfcPersonAndOrganization owningUser = create(IfcPersonAndOrganization.class);
    owningUser.setTheOrganization(organization);
    owningUser.setThePerson(person);
    IfcOrganization developer = create(IfcOrganization.class);
    developer.setName("Required");
    IfcApplication application = create(IfcApplication.class);
    application.setApplicationDeveloper(developer);
    application.setApplicationFullName("Required");
    application.setApplicationIdentifier("Required");
    application.setVersion("1.0");
    IfcOwnerHistory ownerHistory = create(IfcOwnerHistory.class);
    ownerHistory.setChangeAction(IfcChangeActionEnum.ADDED);
    ownerHistory.setCreationDate(System.currentTimeMillis() / 1000);
    ownerHistory.setOwningApplication(application);
    ownerHistory.setOwningUser(owningUser);
    setDefaultOwnerHistory(ownerHistory);
    IfcAxis2Placement3D contextAxisPlacement = create(IfcAxis2Placement3D.class);
    contextAxisPlacement.setLocation(createIfcCartesianPoint(0, 0, 0));
    IfcGeometricRepresentationContext representationContext = create(IfcGeometricRepresentationContext.class);
    representationContext.setCoordinateSpaceDimension(3);
    representationContext.setPrecision(0.00001);
    representationContext.setWorldCoordinateSystem(contextAxisPlacement);
    representationContext.setContextType("Model");
    setDefaultRepresentationContext(representationContext);
    IfcUnitAssignment ifcUnitAssigment = create(IfcUnitAssignment.class);
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.LENGTHUNIT, IfcSIPrefix.MILLI, IfcSIUnitName.METRE));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.VOLUMEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.CUBIC_METRE));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.PLANEANGLEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.RADIAN));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.SOLIDANGLEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.STERADIAN));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.MASSUNIT, IfcSIPrefix.NULL, IfcSIUnitName.GRAM));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.TIMEUNIT, IfcSIPrefix.NULL, IfcSIUnitName.SECOND));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.THERMODYNAMICTEMPERATUREUNIT, IfcSIPrefix.NULL, IfcSIUnitName.DEGREE_CELSIUS));
    ifcUnitAssigment.getUnits().add(createIfcSiUnit(IfcUnitEnum.LUMINOUSINTENSITYUNIT, IfcSIPrefix.NULL, IfcSIUnitName.LUMEN));
    IfcProject ifcProject = create(IfcProject.class);
    ifcProject.getRepresentationContexts().add(representationContext);
    ifcProject.setUnitsInContext(ifcUnitAssigment);
    ifcProject.setName("Demo Project");
    IfcSite ifcSite = create(IfcSite.class);
    ifcSite.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcSite.setName("Default site");
    IfcBuilding ifcBuilding = create(IfcBuilding.class);
    ifcBuilding.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcBuilding.setName("Default building");
    addDecomposes(ifcProject, ifcSite);
    addDecomposes(ifcSite, ifcBuilding);
    return ifcBuilding;
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcOrganization(org.bimserver.models.ifc2x3tc1.IfcOrganization) IfcSite(org.bimserver.models.ifc2x3tc1.IfcSite) IfcUnitAssignment(org.bimserver.models.ifc2x3tc1.IfcUnitAssignment) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcGeometricRepresentationContext(org.bimserver.models.ifc2x3tc1.IfcGeometricRepresentationContext) IfcPerson(org.bimserver.models.ifc2x3tc1.IfcPerson) IfcApplication(org.bimserver.models.ifc2x3tc1.IfcApplication) IfcOwnerHistory(org.bimserver.models.ifc2x3tc1.IfcOwnerHistory) IfcPersonAndOrganization(org.bimserver.models.ifc2x3tc1.IfcPersonAndOrganization) IfcBuilding(org.bimserver.models.ifc2x3tc1.IfcBuilding)

Aggregations

IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)2 IfcOwnerHistory (org.bimserver.models.ifc2x3tc1.IfcOwnerHistory)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 IfcApplication (org.bimserver.models.ifc2x3tc1.IfcApplication)1 IfcBuilding (org.bimserver.models.ifc2x3tc1.IfcBuilding)1 IfcBuildingStorey (org.bimserver.models.ifc2x3tc1.IfcBuildingStorey)1 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)1 IfcFurnishingElement (org.bimserver.models.ifc2x3tc1.IfcFurnishingElement)1 IfcGeometricRepresentationContext (org.bimserver.models.ifc2x3tc1.IfcGeometricRepresentationContext)1 IfcLocalPlacement (org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)1 IfcObjectDefinition (org.bimserver.models.ifc2x3tc1.IfcObjectDefinition)1 IfcOrganization (org.bimserver.models.ifc2x3tc1.IfcOrganization)1 IfcPerson (org.bimserver.models.ifc2x3tc1.IfcPerson)1 IfcPersonAndOrganization (org.bimserver.models.ifc2x3tc1.IfcPersonAndOrganization)1 IfcProductDefinitionShape (org.bimserver.models.ifc2x3tc1.IfcProductDefinitionShape)1 IfcProject (org.bimserver.models.ifc2x3tc1.IfcProject)1 IfcRelContainedInSpatialStructure (org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)1