Search in sources :

Example 11 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class TestReadProperties method test.

@Test
public void test() {
    try {
        // New client
        BimServerClientInterface bimServerClient = getFactory().create(new UsernamePasswordAuthenticationInfo("admin@bimserver.org", "admin"));
        // Create a project
        SProject project = bimServerClient.getServiceInterface().addProject("test" + Math.random(), "ifc2x3tc1");
        // Look for a deserializer
        SDeserializerPluginConfiguration deserializer = bimServerClient.getServiceInterface().getSuggestedDeserializerForExtension("ifc", project.getOid());
        // Checkin file
        bimServerClient.checkin(project.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/AC11-Institute-Var-2-IFC.ifc"));
        // Refresh project
        project = bimServerClient.getServiceInterface().getProjectByPoid(project.getOid());
        // Load model without lazy loading (complete model at once)
        IfcModelInterface model = bimServerClient.getModel(project, project.getLastRevisionId(), true, false);
        // Iterate over all projects, there should be 1
        for (IfcProject ifcProject : model.getAllWithSubTypes(IfcProject.class)) {
            for (IfcRelDefines ifcRelDefines : ifcProject.getIsDefinedBy()) {
                if (ifcRelDefines instanceof IfcRelDefinesByProperties) {
                    IfcRelDefinesByProperties ifcRelDefinesByProperties = (IfcRelDefinesByProperties) ifcRelDefines;
                    IfcPropertySetDefinition relatingPropertyDefinition = ifcRelDefinesByProperties.getRelatingPropertyDefinition();
                    if (relatingPropertyDefinition instanceof IfcPropertySet) {
                        IfcPropertySet ifcPropertySet = (IfcPropertySet) relatingPropertyDefinition;
                        for (IfcProperty ifcProperty : ifcPropertySet.getHasProperties()) {
                            if (ifcProperty instanceof IfcPropertySingleValue) {
                                IfcPropertySingleValue ifcPropertySingleValue = (IfcPropertySingleValue) ifcProperty;
                                IfcValue nominalValue = ifcPropertySingleValue.getNominalValue();
                                String stringValue = "";
                                if (nominalValue instanceof IfcLabel) {
                                    stringValue = ((IfcLabel) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcIdentifier) {
                                    stringValue = ((IfcIdentifier) nominalValue).getWrappedValue();
                                } else if (nominalValue instanceof IfcAreaMeasure) {
                                    stringValue = "" + ((IfcAreaMeasure) nominalValue).getWrappedValue();
                                }
                                if (ifcPropertySingleValue.getName().equals("ConstructionMode")) {
                                    if (!stringValue.equals("Massivbau")) {
                                        fail("Massivbau expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("BuildingPermitId")) {
                                    if (!stringValue.equals("4711")) {
                                        fail("4711 expected");
                                    }
                                } else if (ifcPropertySingleValue.getName().equals("GrossAreaPlanned")) {
                                    if (stringValue == null || !stringValue.equals("1000.0")) {
                                        fail("1000. expected");
                                    }
                                }
                                System.out.println(ifcPropertySingleValue.getName() + ": " + stringValue);
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable e) {
        if (!(e instanceof AssertionError)) {
            fail(e.getMessage());
        }
    }
}
Also used : IfcProject(org.bimserver.models.ifc2x3tc1.IfcProject) IfcValue(org.bimserver.models.ifc2x3tc1.IfcValue) IfcProperty(org.bimserver.models.ifc2x3tc1.IfcProperty) IfcPropertySingleValue(org.bimserver.models.ifc2x3tc1.IfcPropertySingleValue) SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) IfcAreaMeasure(org.bimserver.models.ifc2x3tc1.IfcAreaMeasure) SProject(org.bimserver.interfaces.objects.SProject) IfcRelDefinesByProperties(org.bimserver.models.ifc2x3tc1.IfcRelDefinesByProperties) URL(java.net.URL) IfcRelDefines(org.bimserver.models.ifc2x3tc1.IfcRelDefines) IfcLabel(org.bimserver.models.ifc2x3tc1.IfcLabel) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcPropertySet(org.bimserver.models.ifc2x3tc1.IfcPropertySet) IfcPropertySetDefinition(org.bimserver.models.ifc2x3tc1.IfcPropertySetDefinition) IfcIdentifier(org.bimserver.models.ifc2x3tc1.IfcIdentifier) Test(org.junit.Test)

Example 12 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class TestReadTrim 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.checkin(newProject.getOid(), "test", deserializer.getOid(), false, Flow.SYNC, new URL("https://github.com/opensourceBIM/TestFiles/raw/master/TestData/data/TST.ifc"));
        // Refresh project info
        newProject = bimServerClient.getServiceInterface().getProjectByPoid(newProject.getOid());
        IfcModelInterface model = bimServerClient.getModel(newProject, newProject.getLastRevisionId(), true, false);
        for (IfcTrimmedCurve ifcTrimmedCurve : model.getAllWithSubTypes(IfcTrimmedCurve.class)) {
            for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim1()) {
                if (ifcTrimmingSelect instanceof IfcParameterValue) {
                    IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
                    System.out.println("Trim1: " + ifcParameterValue.getWrappedValue());
                }
            }
            for (IfcTrimmingSelect ifcTrimmingSelect : ifcTrimmedCurve.getTrim2()) {
                if (ifcTrimmingSelect instanceof IfcParameterValue) {
                    IfcParameterValue ifcParameterValue = (IfcParameterValue) ifcTrimmingSelect;
                    System.out.println("Trim2: " + ifcParameterValue.getWrappedValue());
                }
            }
        }
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcTrimmedCurve(org.bimserver.models.ifc2x3tc1.IfcTrimmedCurve) IfcTrimmingSelect(org.bimserver.models.ifc2x3tc1.IfcTrimmingSelect) IfcParameterValue(org.bimserver.models.ifc2x3tc1.IfcParameterValue) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) Test(org.junit.Test)

Example 13 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface 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 14 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class Visualise method main.

public static void main(String[] args) {
    PluginManager pluginManager;
    try {
        pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.requireDeserializer("application/ifc");
        Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        IfcModelInterface model1 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model1b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model2 = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        IfcModelInterface model2b = DeserializerUtils.readFromFile(deserializer, TestFile.EXPORT3.getFile());
        model1.setObjectOids();
        model1b.setObjectOids();
        model2.setObjectOids();
        model2b.setObjectOids();
        model1.indexGuids();
        model2.indexGuids();
        model2.fixOids(new IncrementingOidProvider(model1.getHighestOid() + 1));
        IfcModel merged = new RevisionMerger(model1, model2).merge();
        SerializerPlugin serializerPlugin = pluginManager.getSerializerPlugin("org.bimserver.ifc.step.serializer.IfcStepSerializerPlugin", true);
        Serializer serializer = serializerPlugin.createSerializer(new PluginConfiguration());
        serializer.init(merged, null, false);
        SerializerUtils.writeToFile(serializer, Paths.get("merged.ifc"));
        new Visualise().start(model1b, "Model 1");
        new Visualise().start(model2b, "Model 2");
        new Visualise().start(merged, "Merged");
    } catch (PluginException e1) {
        e1.printStackTrace();
    } catch (SerializerException e) {
        e.printStackTrace();
    } catch (DeserializeException e) {
        e.printStackTrace();
    } catch (IfcModelInterfaceException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RevisionMerger(org.bimserver.merging.RevisionMerger) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) FileNotFoundException(java.io.FileNotFoundException) SerializerPlugin(org.bimserver.plugins.serializers.SerializerPlugin) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) IOException(java.io.IOException) SerializerException(org.bimserver.plugins.serializers.SerializerException) PluginManager(org.bimserver.plugins.PluginManager) IfcModel(org.bimserver.ifc.IfcModel) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) Deserializer(org.bimserver.plugins.deserializers.Deserializer) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) IncrementingOidProvider(org.bimserver.shared.IncrementingOidProvider) Serializer(org.bimserver.plugins.serializers.Serializer)

Example 15 with IfcModelInterface

use of org.bimserver.emf.IfcModelInterface in project BIMserver by opensourceBIM.

the class GuidHighlighterTester method readModel.

public IfcModelInterface readModel(Path file) {
    PluginManager pluginManager;
    try {
        pluginManager = LocalDevPluginLoader.createPluginManager(Paths.get("home"));
        DeserializerPlugin deserializerPlugin = pluginManager.getFirstDeserializer("ifc", Schema.IFC2X3TC1, true);
        Deserializer deserializer = deserializerPlugin.createDeserializer(new PluginConfiguration());
        deserializer.init(pluginManager.getMetaDataManager().getPackageMetaData("ifc2x3tc1"));
        try {
            IfcModelInterface model = DeserializerUtils.readFromFile(deserializer, file);
            return model;
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (PluginException e1) {
        e1.printStackTrace();
    }
    return null;
}
Also used : PluginManager(org.bimserver.plugins.PluginManager) Deserializer(org.bimserver.plugins.deserializers.Deserializer) IfcModelInterface(org.bimserver.emf.IfcModelInterface) PluginException(org.bimserver.shared.exceptions.PluginException) DeserializerPlugin(org.bimserver.plugins.deserializers.DeserializerPlugin) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) PluginException(org.bimserver.shared.exceptions.PluginException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

IfcModelInterface (org.bimserver.emf.IfcModelInterface)58 SProject (org.bimserver.interfaces.objects.SProject)22 UserException (org.bimserver.shared.exceptions.UserException)21 BimServerClientInterface (org.bimserver.plugins.services.BimServerClientInterface)20 UsernamePasswordAuthenticationInfo (org.bimserver.shared.UsernamePasswordAuthenticationInfo)17 Test (org.junit.Test)17 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)16 PackageMetaData (org.bimserver.emf.PackageMetaData)15 URL (java.net.URL)14 Revision (org.bimserver.models.store.Revision)14 User (org.bimserver.models.store.User)14 ModelHelper (org.bimserver.plugins.ModelHelper)13 OldQuery (org.bimserver.database.OldQuery)12 Project (org.bimserver.models.store.Project)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IdEObject (org.bimserver.emf.IdEObject)11 DatabaseSession (org.bimserver.database.DatabaseSession)10 ConcreteRevision (org.bimserver.models.store.ConcreteRevision)10 IfcModelSet (org.bimserver.plugins.IfcModelSet)10