Search in sources :

Example 1 with IfcFurnishingElement

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

the class TestRemoveReferenceList method test.

// This test makes no sense, since getContainedInStructure is a Set (unordered)
@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the service interface
        bimServerClient.getSettingsInterface().setGenerateGeometryOnCheckin(false);
        // Create a new project
        SProject newProject = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        IfcModelInterface model = bimServerClient.newModel(newProject, true);
        IfcFurnishingElement furnishingElement = model.create(IfcFurnishingElement.class);
        furnishingElement.setName("Furnishing 1");
        IfcRelContainedInSpatialStructure link1 = model.create(IfcRelContainedInSpatialStructure.class);
        link1.setName("link1");
        IfcRelContainedInSpatialStructure link2 = model.create(IfcRelContainedInSpatialStructure.class);
        link2.setName("link2");
        IfcRelContainedInSpatialStructure link3 = model.create(IfcRelContainedInSpatialStructure.class);
        link3.setName("link3");
        link1.getRelatedElements().add(furnishingElement);
        link2.getRelatedElements().add(furnishingElement);
        link3.getRelatedElements().add(furnishingElement);
        model.commit("initial");
        // refresh
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        bimServerClient.download(newProject.getLastRevisionId(), bimServerClient.getServiceInterface().getSerializerByContentType("application/ifc").getOid(), Paths.get("testX.ifc"));
        model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, true);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
            if (ifcFurnishingElement.getContainedInStructure().size() != 3) {
                fail("Size should be 3, is " + ifcFurnishingElement.getContainedInStructure().size());
            }
            // Remove the middle one
            IfcRelContainedInSpatialStructure middleOne = null;
            for (IfcRelContainedInSpatialStructure rel : ifcFurnishingElement.getContainedInStructure()) {
                if (rel.getName().equals("link2")) {
                    middleOne = rel;
                    break;
                }
            }
            ifcFurnishingElement.getContainedInStructure().remove(middleOne);
        }
        model.commit("removed middle link");
        // refresh
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAll(IfcFurnishingElement.class)) {
            assertTrue("Size should be 2, is " + ifcFurnishingElement.getContainedInStructure().size(), ifcFurnishingElement.getContainedInStructure().size() == 2);
            assertEquals("link", "link1", ifcFurnishingElement.getContainedInStructure().get(0).getName());
            assertEquals("link", "link3", ifcFurnishingElement.getContainedInStructure().get(1).getName());
        }
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure) SProject(org.bimserver.interfaces.objects.SProject) Test(org.junit.Test)

Example 2 with IfcFurnishingElement

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

the class TestBigModelEmfRemote method createFurnishing.

private void createFurnishing(RichIfcModel richIfcModel, IfcRepresentationContext representationContext, int number, IfcSpace ifcSpace, IfcLocalPlacement spacePlacement, boolean doreuse) throws IfcModelInterfaceException {
    IfcFurnishingElement furnishing = richIfcModel.create(IfcFurnishingElement.class);
    furnishing.setName("Furnishing " + number);
    IfcLocalPlacement furnishingPlacement = richIfcModel.create(IfcLocalPlacement.class);
    furnishingPlacement.setPlacementRelTo(spacePlacement);
    IfcAxis2Placement3D furnitureAxisPlacement = richIfcModel.create(IfcAxis2Placement3D.class);
    furnitureAxisPlacement.setLocation(richIfcModel.createIfcCartesianPoint(500, 500, 2));
    furnishingPlacement.setRelativePlacement(furnitureAxisPlacement);
    furnishing.setObjectPlacement(furnishingPlacement);
    IfcProductRepresentation rep = null;
    if (doreuse) {
        if (this.furnishingRep == null) {
            this.furnishingRep = richIfcModel.createRectangularExtrusionProductRepresentation(4000, 4000, 1200);
        }
        rep = this.furnishingRep;
    } else {
        rep = richIfcModel.createRectangularExtrusionProductRepresentation(4000, 4000, 1200);
    }
    furnishing.setRepresentation(rep);
    richIfcModel.addContains(ifcSpace, furnishing);
}
Also used : IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)

Example 3 with IfcFurnishingElement

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

the class TestBigModelEmf method createFurnishing.

private void createFurnishing(RichIfcModel richIfcModel, IfcRepresentationContext representationContext, int number, IfcSpace ifcSpace, IfcLocalPlacement spacePlacement) throws IfcModelInterfaceException {
    IfcFurnishingElement furnishing = richIfcModel.create(IfcFurnishingElement.class);
    furnishing.setName("Furnishing " + number);
    IfcLocalPlacement furnishingPlacement = richIfcModel.create(IfcLocalPlacement.class);
    furnishingPlacement.setPlacementRelTo(spacePlacement);
    IfcAxis2Placement3D furnitureAxisPlacement = richIfcModel.create(IfcAxis2Placement3D.class);
    furnitureAxisPlacement.setLocation(richIfcModel.createIfcCartesianPoint(500, 500, 2));
    furnishingPlacement.setRelativePlacement(furnitureAxisPlacement);
    furnishing.setObjectPlacement(furnishingPlacement);
    furnishing.setRepresentation(richIfcModel.createRectangularExtrusionProductRepresentation(4000, 4000, 1200));
    richIfcModel.addContains(ifcSpace, furnishing);
}
Also used : IfcFurnishingElement(org.bimserver.models.ifc2x3tc1.IfcFurnishingElement) IfcAxis2Placement3D(org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D) IfcLocalPlacement(org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)

Example 4 with IfcFurnishingElement

use of org.bimserver.models.ifc2x3tc1.IfcFurnishingElement 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 5 with IfcFurnishingElement

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

the class TestContainedInStructure method test.

@Test
public void test() {
    try {
        // Create a new BimServerClient with authentication
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Get the service interface
        bimServerClient.getSettingsInterface().setGenerateGeometryOnCheckin(false);
        // 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, false);
        for (IfcFurnishingElement ifcFurnishingElement : model.getAllWithSubTypes(IfcFurnishingElement.class)) {
            System.out.println(ifcFurnishingElement);
            for (IfcRelContainedInSpatialStructure ifcRelContainedInSpatialStructure : ifcFurnishingElement.getContainedInStructure()) {
                System.out.println(ifcRelContainedInSpatialStructure.getRelatingStructure());
            }
        }
    } 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) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcRelContainedInSpatialStructure(org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Aggregations

IfcFurnishingElement (org.bimserver.models.ifc2x3tc1.IfcFurnishingElement)8 IfcModelInterface (org.bimserver.emf.IfcModelInterface)6 SProject (org.bimserver.interfaces.objects.SProject)4 IfcAxis2Placement3D (org.bimserver.models.ifc2x3tc1.IfcAxis2Placement3D)4 IfcLocalPlacement (org.bimserver.models.ifc2x3tc1.IfcLocalPlacement)4 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)4 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)4 Test (org.junit.Test)4 IfcRelContainedInSpatialStructure (org.bimserver.models.ifc2x3tc1.IfcRelContainedInSpatialStructure)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 URL (java.net.URL)2 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)2 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)2 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)2 ModelHelper (org.bimserver.plugins.ModelHelper)2 PluginManager (org.bimserver.plugins.PluginManager)2 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)2 Deserializer (org.bimserver.plugins.deserializers.Deserializer)2 DeserializerPlugin (org.bimserver.plugins.deserializers.DeserializerPlugin)2