Search in sources :

Example 1 with IfcSurfaceStyleElementSelect

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

the class GuidHighlighter method highlightGuids.

private void highlightGuids(IfcModelInterface model, Set<String> highlightedGuids) {
    Set<IdEObject> newObjects = new HashSet<IdEObject>();
    IfcColourRgb gray = Ifc2x3tc1Factory.eINSTANCE.createIfcColourRgb();
    newObjects.add(gray);
    gray.setRed(0.5f);
    gray.setGreen(0.5f);
    gray.setBlue(0.5f);
    Set<IdEObject> toDelete = new HashSet<IdEObject>();
    for (IdEObject object : model.getValues()) {
        if (object instanceof IfcPresentationLayerAssignment) {
            toDelete.add(object);
        }
    }
    IfcPresentationLayerAssignment notSelectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    notSelectedLayer.setName("Not Selected");
    notSelectedLayer.setIdentifier("Not Selected");
    newObjects.add(notSelectedLayer);
    IfcPresentationLayerAssignment selectedLayer = Ifc2x3tc1Factory.eINSTANCE.createIfcPresentationLayerAssignment();
    selectedLayer.setName("Selected");
    selectedLayer.setIdentifier("Selected");
    newObjects.add(selectedLayer);
    for (IdEObject idEObject : model.getValues()) {
        if (idEObject instanceof IfcProduct) {
            IfcProduct product = (IfcProduct) idEObject;
            String guid = product.getGlobalId();
            boolean hide = true;
            if (guid != null) {
                if (highlightedGuids.contains(guid)) {
                    hide = false;
                }
            }
            if (hide) {
                System.out.println("Hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        notSelectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            notSelectedLayer.getAssignedItems().add(ifcRepresentationItem);
                            for (IfcStyledItem ifcStyledItem : ifcRepresentationItem.getStyledByItem()) {
                                for (IfcPresentationStyleAssignment ifcPresentationStyleAssignment : ifcStyledItem.getStyles()) {
                                    for (IfcPresentationStyleSelect ifcPresentationStyleSelect : ifcPresentationStyleAssignment.getStyles()) {
                                        if (ifcPresentationStyleSelect instanceof IfcSurfaceStyle) {
                                            IfcSurfaceStyle ifcSurfaceStyle = (IfcSurfaceStyle) ifcPresentationStyleSelect;
                                            for (IfcSurfaceStyleElementSelect ifcSurfaceStyleElementSelect : ifcSurfaceStyle.getStyles()) {
                                                if (ifcSurfaceStyleElementSelect instanceof IfcSurfaceStyleRendering) {
                                                    IfcSurfaceStyleRendering ifcSurfaceStyleRendering = (IfcSurfaceStyleRendering) ifcSurfaceStyleElementSelect;
                                                    ifcSurfaceStyleRendering.setTransparency(0.98f);
                                                    ifcSurfaceStyleRendering.setDiffuseColour(gray);
                                                    ifcSurfaceStyleRendering.setReflectionColour(gray);
                                                    ifcSurfaceStyleRendering.setSpecularColour(gray);
                                                    ifcSurfaceStyleRendering.setSurfaceColour(gray);
                                                    ifcSurfaceStyleRendering.setTransmissionColour(gray);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else {
                System.out.println("Not hiding " + guid);
                IfcProductRepresentation representation = product.getRepresentation();
                if (representation != null) {
                    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
                        selectedLayer.getAssignedItems().add(ifcRepresentation);
                        for (IfcRepresentationItem ifcRepresentationItem : ifcRepresentation.getItems()) {
                            selectedLayer.getAssignedItems().add(ifcRepresentationItem);
                        }
                    }
                }
            }
        }
    }
    for (IdEObject toDeleteObject : toDelete) {
        model.remove(toDeleteObject);
    }
    for (IdEObject newObject : newObjects) {
        try {
            model.add(model.getHighestOid() + 1, newObject);
        } catch (IfcModelInterfaceException e) {
            e.printStackTrace();
        }
    }
}
Also used : IfcSurfaceStyle(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyle) IdEObject(org.bimserver.emf.IdEObject) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcPresentationLayerAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment) IfcColourRgb(org.bimserver.models.ifc2x3tc1.IfcColourRgb) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcSurfaceStyleElementSelect(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleElementSelect) IfcProduct(org.bimserver.models.ifc2x3tc1.IfcProduct) IfcPresentationStyleAssignment(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleAssignment) IfcPresentationStyleSelect(org.bimserver.models.ifc2x3tc1.IfcPresentationStyleSelect) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation) HashSet(java.util.HashSet) IfcSurfaceStyleRendering(org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleRendering)

Aggregations

HashSet (java.util.HashSet)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 IfcColourRgb (org.bimserver.models.ifc2x3tc1.IfcColourRgb)1 IfcPresentationLayerAssignment (org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment)1 IfcPresentationStyleAssignment (org.bimserver.models.ifc2x3tc1.IfcPresentationStyleAssignment)1 IfcPresentationStyleSelect (org.bimserver.models.ifc2x3tc1.IfcPresentationStyleSelect)1 IfcProduct (org.bimserver.models.ifc2x3tc1.IfcProduct)1 IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)1 IfcRepresentation (org.bimserver.models.ifc2x3tc1.IfcRepresentation)1 IfcRepresentationItem (org.bimserver.models.ifc2x3tc1.IfcRepresentationItem)1 IfcStyledItem (org.bimserver.models.ifc2x3tc1.IfcStyledItem)1 IfcSurfaceStyle (org.bimserver.models.ifc2x3tc1.IfcSurfaceStyle)1 IfcSurfaceStyleElementSelect (org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleElementSelect)1 IfcSurfaceStyleRendering (org.bimserver.models.ifc2x3tc1.IfcSurfaceStyleRendering)1