Search in sources :

Example 6 with IfcLocalPlacement

use of org.bimserver.models.ifc2x3tc1.IfcLocalPlacement 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(), 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) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)

Example 7 with IfcLocalPlacement

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

the class IfcUtils method getAbsolutePosition.

/**
 * Not finished, does not take into account the directions
 *
 * @param ifcObjectPlacement
 * @return
 * @throws PlacementNotImplementedException
 */
public static double[] getAbsolutePosition(IfcObjectPlacement ifcObjectPlacement) throws PlacementNotImplementedException {
    if (ifcObjectPlacement instanceof IfcGridPlacement) {
        throw new PlacementNotImplementedException("IfcGridPlacement has not been implemented");
    } else if (ifcObjectPlacement instanceof IfcLocalPlacement) {
        IfcLocalPlacement ifcLocalPlacement = (IfcLocalPlacement) ifcObjectPlacement;
        IfcAxis2Placement relativePlacement = ifcLocalPlacement.getRelativePlacement();
        if (relativePlacement instanceof IfcAxis2Placement2D) {
            throw new PlacementNotImplementedException("IfcAxis2Placement2D has not been implemented");
        } else if (relativePlacement instanceof IfcAxis2Placement3D) {
            IfcAxis2Placement3D ifcAxis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
            IfcObjectPlacement placementRelativeTo = ifcLocalPlacement.getPlacementRelTo();
            if (placementRelativeTo == null) {
                IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
                return new double[] { ifcCartesianPoint.getCoordinates().get(0), ifcCartesianPoint.getCoordinates().get(1), ifcCartesianPoint.getCoordinates().get(2) };
            } else {
                double[] relative = getAbsolutePosition(placementRelativeTo);
                IfcCartesianPoint ifcCartesianPoint = ifcAxis2Placement3D.getLocation();
                return new double[] { relative[0] + ifcCartesianPoint.getCoordinates().get(0), relative[1] + ifcCartesianPoint.getCoordinates().get(1), relative[2] + ifcCartesianPoint.getCoordinates().get(2) };
            }
        }
    }
    return new double[] { 0d, 0d, 0d };
}
Also used : IfcGridPlacement(org.bimserver.models.ifc2x3tc1.IfcGridPlacement) IfcAxis2Placement2D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement2D) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement)

Example 8 with IfcLocalPlacement

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

the class TestBigModelEmfRemote method createSpace.

private void createSpace(RichIfcModel richIfcModel, IfcRepresentationContext representationContext, IfcLocalPlacement storeyPlacement, IfcRelAggregates storeyAggregation, int x, int y, boolean doreuse) throws IfcModelInterfaceException {
    IfcSpace ifcSpace = richIfcModel.create(IfcSpace.class);
    ifcSpace.setName("Space " + ((y * 10) + x));
    ifcSpace.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcSpace.setInteriorOrExteriorSpace(IfcInternalOrExternalEnum.INTERNAL);
    IfcLocalPlacement spacePlacement = richIfcModel.create(IfcLocalPlacement.class);
    spacePlacement.setPlacementRelTo(storeyPlacement);
    spacePlacement.setRelativePlacement(richIfcModel.createBasicPosition(x * 6000, y * 6000, 0));
    ifcSpace.setObjectPlacement(spacePlacement);
    storeyAggregation.getRelatedObjects().add(ifcSpace);
    IfcProductRepresentation rep = null;
    if (doreuse) {
        if (this.spaceRep == null) {
            this.spaceRep = richIfcModel.createRectangularExtrusionProductRepresentation(5000, 5000, 2000);
        }
        rep = this.spaceRep;
    } else {
        rep = richIfcModel.createRectangularExtrusionProductRepresentation(5000, 5000, 2000);
    }
    ifcSpace.setRepresentation(rep);
    createFurnishing(richIfcModel, representationContext, y, ifcSpace, spacePlacement, doreuse);
}
Also used : IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcSpace(org.bimserver.models.ifc2x3tc1.IfcSpace) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)

Example 9 with IfcLocalPlacement

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

the class TestMoveObject method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Get the appropriate deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", newProject.getOid());
        // Checkin the file
        bimServerClient.checkinSync(newProject.getOid(), "test", deserializer.getOid(), false, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
            IfcObjectPlacement objectPlacement = ifcFurnishingElement.getObjectPlacement();
            if (objectPlacement != null && objectPlacement instanceof IfcLocalPlacement) {
                IfcLocalPlacement localPlacement = (IfcLocalPlacement) objectPlacement;
                IfcAxis2Placement relativePlacement = localPlacement.getRelativePlacement();
                if (relativePlacement != null) {
                    if (relativePlacement instanceof IfcAxis2Placement3D) {
                        IfcAxis2Placement3D axis2Placement3D = (IfcAxis2Placement3D) relativePlacement;
                        IfcCartesianPoint location = axis2Placement3D.getLocation();
                        double newValue = location.getCoordinates().get(2) + 50;
                        System.out.println("Changing z value of " + ifcFurnishingElement.getName() + " from " + location.getCoordinates().get(2) + " to " + newValue);
                        location.getCoordinates().set(2, newValue);
                    }
                }
            }
        }
        long newRoid = model.commit("Moved all furniture 50 meters up");
        SSerializerPluginConfiguration ifcSerializer = bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc");
        bimServerClient.download(newRoid, ifcSerializer.getOid(), Paths.get("movedf.ifc"));
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) SProject(org.bimserver.interfaces.objects.SProject) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) URL(java.net.URL) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) SSerializerPluginConfiguration(org.bimserver.interfaces.objects.SSerializerPluginConfiguration) IfcAxis2Placement(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement) Test(org.junit.Test)

Example 10 with IfcLocalPlacement

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

the class TestBigModelEmf method createSpace.

private void createSpace(RichIfcModel richIfcModel, IfcRepresentationContext representationContext, IfcLocalPlacement storeyPlacement, IfcRelAggregates storeyAggregation, int x, int y) throws IfcModelInterfaceException {
    IfcSpace ifcSpace = richIfcModel.create(IfcSpace.class);
    ifcSpace.setName("Space " + ((y * 10) + x));
    ifcSpace.setCompositionType(IfcElementCompositionEnum.ELEMENT);
    ifcSpace.setInteriorOrExteriorSpace(IfcInternalOrExternalEnum.INTERNAL);
    IfcLocalPlacement spacePlacement = richIfcModel.create(IfcLocalPlacement.class);
    spacePlacement.setPlacementRelTo(storeyPlacement);
    spacePlacement.setRelativePlacement(richIfcModel.createBasicPosition(x * 6000, y * 6000, 0));
    ifcSpace.setObjectPlacement(spacePlacement);
    storeyAggregation.getRelatedObjects().add(ifcSpace);
    ifcSpace.setRepresentation(richIfcModel.createRectangularExtrusionProductRepresentation(5000, 5000, 2000));
    createFurnishing(richIfcModel, representationContext, y, ifcSpace, spacePlacement);
}
Also used : IfcSpace(org.bimserver.models.ifc2x3tc1.IfcSpace) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)

Aggregations

IfcLocalPlacement (org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)10 IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)6 IfcModelInterface (org.bimserver.emf.IfcModelInterface)4 IfcFurnishingElement (org.bimserver.models.ifc2x3tc1.IfcFurnishingElement)4 SProject (org.bimserver.interfaces.objects.SProject)3 SSerializerPluginConfiguration (org.bimserver.interfaces.objects.SSerializerPluginConfiguration)3 IfcAxis2Placement (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement)3 IfcBuildingStorey (org.bimserver.models.ifc2x3tc1.IfcBuildingStorey)3 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)3 IfcObjectPlacement (org.bimserver.models.ifc2x3tc1.IfcObjectPlacement)3 IfcSpace (org.bimserver.models.ifc2x3tc1.IfcSpace)3 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)3 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)3 Test (org.junit.Test)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)2 IfcBuilding (org.bimserver.models.ifc2x3tc1.IfcBuilding)2 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)2 IfcRelAggregates (org.bimserver.models.ifc2x3tc1.IfcRelAggregates)2