Search in sources :

Example 1 with IfcMaterial

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

the class IfcUtils method getMaterial.

public static String getMaterial(IfcProduct ifcProduct) {
    Set<IfcMaterial> materials = new HashSet<>();
    for (IfcRelAssociates ifcRelAssociates : ifcProduct.getHasAssociations()) {
        if (ifcRelAssociates instanceof IfcRelAssociatesMaterial) {
            IfcRelAssociatesMaterial ifcRelAssociatesMaterial = (IfcRelAssociatesMaterial) ifcRelAssociates;
            IfcMaterialSelect relatingMaterial = ifcRelAssociatesMaterial.getRelatingMaterial();
            if (relatingMaterial instanceof IfcMaterial) {
                materials.add((IfcMaterial) relatingMaterial);
            } else if (relatingMaterial instanceof IfcMaterialLayerSetUsage) {
                IfcMaterialLayerSetUsage ifcMaterialLayerSetUsage = (IfcMaterialLayerSetUsage) relatingMaterial;
                IfcMaterialLayerSet forLayerSet = ifcMaterialLayerSetUsage.getForLayerSet();
                for (IfcMaterialLayer ifcMaterialLayer : forLayerSet.getMaterialLayers()) {
                    IfcMaterial material = ifcMaterialLayer.getMaterial();
                    materials.add(material);
                }
            } else if (relatingMaterial instanceof IfcMaterialList) {
                materials.addAll(((IfcMaterialList) relatingMaterial).getMaterials());
            } else if (relatingMaterial instanceof IfcMaterialLayerSet) {
                for (IfcMaterialLayer ifcMaterialLayer : ((IfcMaterialLayerSet) relatingMaterial).getMaterialLayers()) {
                    materials.add(ifcMaterialLayer.getMaterial());
                }
            } else {
                throw new UnsupportedOperationException(relatingMaterial.toString());
            }
        }
    }
    Iterator<IfcMaterial> iterator = materials.iterator();
    while (iterator.hasNext()) {
        IfcMaterial next = iterator.next();
        if (next == null || next.getName() == null) {
            iterator.remove();
        }
    }
    return Joiner.on(", ").join(materials.stream().map(new Function<IfcMaterial, String>() {

        @Override
        public String apply(IfcMaterial input) {
            return input.getName();
        }
    }).iterator());
}
Also used : IfcMaterialList(org.bimserver.models.ifc2x3tc1.IfcMaterialList) IfcRelAssociatesMaterial(org.bimserver.models.ifc2x3tc1.IfcRelAssociatesMaterial) IfcMaterialLayer(org.bimserver.models.ifc2x3tc1.IfcMaterialLayer) IfcMaterial(org.bimserver.models.ifc2x3tc1.IfcMaterial) IfcMaterialSelect(org.bimserver.models.ifc2x3tc1.IfcMaterialSelect) IfcMaterialLayerSet(org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSet) IfcMaterialLayerSetUsage(org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSetUsage) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IfcRelAssociates(org.bimserver.models.ifc2x3tc1.IfcRelAssociates)

Example 2 with IfcMaterial

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

the class TestGetMaterials method getMaterials.

public static Set<IfcMaterial> getMaterials(IfcProduct ifcProduct) {
    Set<IfcMaterial> materials = new HashSet<>();
    for (IfcRelAssociates ifcRelAssociates : ifcProduct.getHasAssociations()) {
        if (ifcRelAssociates instanceof IfcRelAssociatesMaterial) {
            IfcRelAssociatesMaterial ifcRelAssociatesMaterial = (IfcRelAssociatesMaterial) ifcRelAssociates;
            IfcMaterialSelect relatingMaterial = ifcRelAssociatesMaterial.getRelatingMaterial();
            // System.out.println(relatingMaterial);
            if (relatingMaterial instanceof IfcMaterial) {
                materials.add((IfcMaterial) relatingMaterial);
            } else if (relatingMaterial instanceof IfcMaterialLayerSetUsage) {
                IfcMaterialLayerSetUsage ifcMaterialLayerSetUsage = (IfcMaterialLayerSetUsage) relatingMaterial;
                IfcMaterialLayerSet forLayerSet = ifcMaterialLayerSetUsage.getForLayerSet();
                if (forLayerSet != null) {
                    for (IfcMaterialLayer ifcMaterialLayer : forLayerSet.getMaterialLayers()) {
                        IfcMaterial material = ifcMaterialLayer.getMaterial();
                        materials.add(material);
                    }
                }
            } else if (relatingMaterial instanceof IfcMaterialList) {
                materials.addAll(((IfcMaterialList) relatingMaterial).getMaterials());
            } else if (relatingMaterial instanceof IfcMaterialLayerSet) {
                for (IfcMaterialLayer ifcMaterialLayer : ((IfcMaterialLayerSet) relatingMaterial).getMaterialLayers()) {
                    materials.add(ifcMaterialLayer.getMaterial());
                }
            } else {
                throw new UnsupportedOperationException(relatingMaterial.toString());
            }
        }
    }
    Iterator<IfcMaterial> iterator = materials.iterator();
    while (iterator.hasNext()) {
        IfcMaterial next = iterator.next();
        if (next == null || next.getName() == null) {
            System.out.println(next.getOid());
            iterator.remove();
        }
    }
    if (materials.size() > 0) {
        System.out.println(ifcProduct.eClass().getName() + ": " + Joiner.on(", ").join(materials));
    }
    return new HashSet<>(materials);
}
Also used : IfcMaterialLayer(org.bimserver.models.ifc2x3tc1.IfcMaterialLayer) IfcMaterialList(org.bimserver.models.ifc2x3tc1.IfcMaterialList) IfcMaterial(org.bimserver.models.ifc2x3tc1.IfcMaterial) IfcMaterialSelect(org.bimserver.models.ifc2x3tc1.IfcMaterialSelect) IfcMaterialLayerSet(org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSet) IfcMaterialLayerSetUsage(org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSetUsage) HashSet(java.util.HashSet) IfcRelAssociates(org.bimserver.models.ifc2x3tc1.IfcRelAssociates) IfcRelAssociatesMaterial(org.bimserver.models.ifc2x3tc1.IfcRelAssociatesMaterial)

Example 3 with IfcMaterial

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

the class TestGetMaterials 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(), false, false);
        Query query = new Query(model.getPackageMetaData());
        query.setDoubleBuffer(true);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addType(new TypeDef(model.getPackageMetaData().getEClass("IfcProduct"), true));
        Include include = queryPart.createInclude();
        include.addType(model.getPackageMetaData().getEClass("IfcObjectDefinition"), true);
        include.addField("HasAssociations");
        include.addInclude("ifc2x3tc1-stdlib:IfcRelAssociatesMaterial");
        JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(model.getPackageMetaData());
        model.query(converter.toJson(query), true);
        int nrMaterialsWithName = 0;
        for (IfcProduct ifcProduct : model.getAllWithSubTypes(IfcProduct.class)) {
            Set<IfcMaterial> materials = getMaterials(ifcProduct);
            for (IfcMaterial ifcMaterial : materials) {
                if (ifcMaterial.getName() != null) {
                    System.out.println(ifcMaterial.getName());
                    nrMaterialsWithName++;
                }
            }
        }
        Assert.assertEquals(416, nrMaterialsWithName);
    } catch (Throwable e) {
        e.printStackTrace();
        if (e instanceof AssertionError) {
            throw (AssertionError) e;
        }
        fail(e.getMessage());
    }
}
Also used : SDeserializerPluginConfiguration(org.bimserver.interfaces.objects.SDeserializerPluginConfiguration) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) UsernamePasswordAuthenticationInfo(org.bimserver.shared.UsernamePasswordAuthenticationInfo) IfcModelInterface(org.bimserver.emf.IfcModelInterface) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) SProject(org.bimserver.interfaces.objects.SProject) URL(java.net.URL) IfcMaterial(org.bimserver.models.ifc2x3tc1.IfcMaterial) TypeDef(org.bimserver.database.queries.om.Include.TypeDef) BimServerClientInterface(org.bimserver.plugins.services.BimServerClientInterface) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) Test(org.junit.Test)

Aggregations

IfcMaterial (org.bimserver.models.ifc2x3tc1.IfcMaterial)3 HashSet (java.util.HashSet)2 IfcMaterialLayer (org.bimserver.models.ifc2x3tc1.IfcMaterialLayer)2 IfcMaterialLayerSet (org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSet)2 IfcMaterialLayerSetUsage (org.bimserver.models.ifc2x3tc1.IfcMaterialLayerSetUsage)2 IfcMaterialList (org.bimserver.models.ifc2x3tc1.IfcMaterialList)2 IfcMaterialSelect (org.bimserver.models.ifc2x3tc1.IfcMaterialSelect)2 IfcRelAssociates (org.bimserver.models.ifc2x3tc1.IfcRelAssociates)2 IfcRelAssociatesMaterial (org.bimserver.models.ifc2x3tc1.IfcRelAssociatesMaterial)2 URL (java.net.URL)1 LinkedHashSet (java.util.LinkedHashSet)1 Include (org.bimserver.database.queries.om.Include)1 TypeDef (org.bimserver.database.queries.om.Include.TypeDef)1 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)1 Query (org.bimserver.database.queries.om.Query)1 QueryPart (org.bimserver.database.queries.om.QueryPart)1 IfcModelInterface (org.bimserver.emf.IfcModelInterface)1 SDeserializerPluginConfiguration (org.bimserver.interfaces.objects.SDeserializerPluginConfiguration)1 SProject (org.bimserver.interfaces.objects.SProject)1 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)1