Search in sources :

Example 1 with IfcProductRepresentation

use of org.bimserver.models.ifc2x3tc1.IfcProductRepresentation 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)

Example 2 with IfcProductRepresentation

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

the class IfcTools2D method get2D.

public Area get2D(IfcProduct ifcProduct, double multiplierMillimeters) {
    IfcObjectPlacement objectPlacement = ifcProduct.getObjectPlacement();
    double[] productMatrix = placementToMatrix(objectPlacement);
    // Matrix.dump(productMatrix);
    IfcProductRepresentation representation = ifcProduct.getRepresentation();
    if (representation == null) {
        return null;
    }
    for (IfcRepresentation ifcRepresentation : representation.getRepresentations()) {
        if ("Curve2D".equals(ifcRepresentation.getRepresentationType())) {
        // Skip
        } else {
            if (ifcRepresentation instanceof IfcShapeRepresentation) {
                IfcShapeRepresentation ifcShapeRepresentation = (IfcShapeRepresentation) ifcRepresentation;
                for (IfcRepresentationItem ifcRepresentationItem : ifcShapeRepresentation.getItems()) {
                    Area area = getArea(multiplierMillimeters, productMatrix, ifcRepresentationItem);
                    if (area != null && area.getPathIterator(null).isDone()) {
                        return area;
                    }
                }
            }
        }
    }
    // Fall back to 3D geometry projected from the top
    GeometryInfo geometry = ifcProduct.getGeometry();
    if (geometry != null) {
        GeometryData geometryData = geometry.getData();
        if (geometryData != null) {
            int[] indices = GeometryUtils.toIntegerArray(geometryData.getIndices());
            float[] vertices = GeometryUtils.toFloatArray(geometryData.getVertices());
            float[] matrix = GeometryUtils.toFloatArray(GeometryUtils.toDoubleArray(geometry.getTransformation()));
            Area area = new Area();
            for (int i = 0; i < indices.length; i += 3) {
                int index1 = indices[i + 0];
                int index2 = indices[i + 1];
                int index3 = indices[i + 2];
                float[] a = new float[] { vertices[index1 * 3], vertices[index1 * 3 + 1], vertices[index1 * 3 + 2] };
                float[] b = new float[] { vertices[index2 * 3], vertices[index2 * 3 + 1], vertices[index2 * 3 + 2] };
                float[] c = new float[] { vertices[index3 * 3], vertices[index3 * 3 + 1], vertices[index3 * 3 + 2] };
                float[][] points = new float[][] { a, b, c };
                // if (similar(a[2], b[2], c[2])) {
                boolean first = true;
                Path2D.Float path = new Path2D.Float();
                for (int j = 0; j < 3; j++) {
                    float[] point = points[j];
                    float[] res = new float[4];
                    Matrix.multiplyMV(res, 0, matrix, 0, new float[] { point[0], point[1], point[2], 1 }, 0);
                    // * multiplierMillimeters
                    float x = (float) (res[0]);
                    // * multiplierMillimeters
                    float y = (float) (res[1]);
                    if (first) {
                        path.moveTo(x, y);
                        first = false;
                    } else {
                        path.lineTo(x, y);
                    }
                }
                path.closePath();
                area.add(new Area(path));
            // }
            }
            return area;
        }
    } else {
        LOGGER.info("No geometry generated for " + ifcProduct);
    }
    return null;
}
Also used : IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) Path2D(java.awt.geom.Path2D) GeometryData(org.bimserver.models.geometry.GeometryData) IfcObjectPlacement(org.bimserver.models.ifc2x3tc1.IfcObjectPlacement) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) Area(java.awt.geom.Area) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation)

Example 3 with IfcProductRepresentation

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

the class RichIfcModel method createRectangularExtrusionProductRepresentation.

public IfcProductRepresentation createRectangularExtrusionProductRepresentation(double width, double depth, double height) throws IfcModelInterfaceException {
    IfcPolyline ifcPolyline = create(IfcPolyline.class);
    EList<IfcCartesianPoint> points = ifcPolyline.getPoints();
    points.add(createIfcCartesianPoint(0, 0, 0));
    points.add(createIfcCartesianPoint(width, 0, 0));
    points.add(createIfcCartesianPoint(width, depth, 0));
    points.add(createIfcCartesianPoint(0, depth, 0));
    points.add(createIfcCartesianPoint(0, 0, 0));
    IfcArbitraryClosedProfileDef def = create(IfcArbitraryClosedProfileDef.class);
    def.setProfileType(IfcProfileTypeEnum.AREA);
    def.setOuterCurve(ifcPolyline);
    IfcExtrudedAreaSolid extrudedAreaSolid = create(IfcExtrudedAreaSolid.class);
    extrudedAreaSolid.setDepth(height);
    extrudedAreaSolid.setSweptArea(def);
    extrudedAreaSolid.setPosition(createBasicPosition(0, 0, 0));
    extrudedAreaSolid.setExtrudedDirection(createDirection(0, 0, 1));
    IfcProductRepresentation productRepresentation = create(IfcProductRepresentation.class);
    IfcShapeRepresentation shapeRepresentation = create(IfcShapeRepresentation.class);
    if (defaultRepresentationContext != null) {
        shapeRepresentation.setContextOfItems(defaultRepresentationContext);
    }
    shapeRepresentation.setRepresentationType("SweptSolid");
    shapeRepresentation.setRepresentationIdentifier("Body");
    shapeRepresentation.getItems().add(extrudedAreaSolid);
    productRepresentation.getRepresentations().add(shapeRepresentation);
    return productRepresentation;
}
Also used : IfcArbitraryClosedProfileDef(org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef) IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) IfcCartesianPoint(org.bimserver.models.ifc2x3tc1.IfcCartesianPoint) IfcShapeRepresentation(org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation) IfcExtrudedAreaSolid(org.bimserver.models.ifc2x3tc1.IfcExtrudedAreaSolid) IfcPolyline(org.bimserver.models.ifc2x3tc1.IfcPolyline)

Example 4 with IfcProductRepresentation

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

the class ModelColorizer method setColor.

public void setColor(IfcProduct product, double[] color, float transparency) throws IfcModelInterfaceException {
    if (!productToStyledItem.containsKey(product) || productToStyledItem.get(product).isEmpty()) {
        // There is no style, let's construct a path to a new one
        System.out.println("No style for " + product + " " + product.getGlobalId());
        IfcProductRepresentation productRepresentation = product.getRepresentation();
        if (product.getRepresentation() == null) {
            productRepresentation = model.create(IfcProductRepresentation.class);
            product.setRepresentation(productRepresentation);
        }
        IfcRepresentation representation = null;
        if (productRepresentation.getRepresentations().isEmpty()) {
            representation = model.create(IfcRepresentation.class);
            productRepresentation.getRepresentations().add(representation);
        } else {
            representation = productRepresentation.getRepresentations().get(0);
        }
        IfcRepresentationItem representationItem = null;
        if (representation.getItems().isEmpty()) {
            representationItem = model.create(IfcRepresentationItem.class);
            representation.getItems().add(representationItem);
        } else {
            representationItem = representation.getItems().get(0);
        }
        IfcStyledItem styledItem = model.create(IfcStyledItem.class);
        representationItem.getStyledByItem().clear();
        representationItem.getStyledByItem().add(styledItem);
        createStyle(color, transparency, styledItem);
    } else if (productToStyledItem.get(product).size() == 1) {
        // There is one style, we can work with that
        IfcStyledItem styledItem = productToStyledItem.get(product).iterator().next();
        Set<IfcProduct> products = styledItemToProduct.get(styledItem);
        if (products.isEmpty()) {
        // That's weird, inconsistent with other map
        } else if (products.size() == 1) {
            // That's probably us, we can alter the Style safely
            createStyle(color, transparency, styledItem);
        } else {
        // Multiple objects are using this style, we have to do some magic
        }
    } else {
        // There are multiple styles, that's a bit much...
        System.out.println(productToStyledItem.get(product).size() + " styles for " + product);
    }
}
Also used : IfcProductRepresentation(org.bimserver.models.ifc2x3tc1.IfcProductRepresentation) Set(java.util.Set) HashSet(java.util.HashSet) IfcRepresentationItem(org.bimserver.models.ifc2x3tc1.IfcRepresentationItem) IfcStyledItem(org.bimserver.models.ifc2x3tc1.IfcStyledItem) IfcRepresentation(org.bimserver.models.ifc2x3tc1.IfcRepresentation)

Aggregations

IfcProductRepresentation (org.bimserver.models.ifc2x3tc1.IfcProductRepresentation)4 IfcRepresentation (org.bimserver.models.ifc2x3tc1.IfcRepresentation)3 IfcRepresentationItem (org.bimserver.models.ifc2x3tc1.IfcRepresentationItem)3 HashSet (java.util.HashSet)2 IfcCartesianPoint (org.bimserver.models.ifc2x3tc1.IfcCartesianPoint)2 IfcShapeRepresentation (org.bimserver.models.ifc2x3tc1.IfcShapeRepresentation)2 IfcStyledItem (org.bimserver.models.ifc2x3tc1.IfcStyledItem)2 Area (java.awt.geom.Area)1 Path2D (java.awt.geom.Path2D)1 Set (java.util.Set)1 IdEObject (org.bimserver.emf.IdEObject)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 GeometryData (org.bimserver.models.geometry.GeometryData)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1 IfcArbitraryClosedProfileDef (org.bimserver.models.ifc2x3tc1.IfcArbitraryClosedProfileDef)1 IfcColourRgb (org.bimserver.models.ifc2x3tc1.IfcColourRgb)1 IfcExtrudedAreaSolid (org.bimserver.models.ifc2x3tc1.IfcExtrudedAreaSolid)1 IfcObjectPlacement (org.bimserver.models.ifc2x3tc1.IfcObjectPlacement)1 IfcPolyline (org.bimserver.models.ifc2x3tc1.IfcPolyline)1 IfcPresentationLayerAssignment (org.bimserver.models.ifc2x3tc1.IfcPresentationLayerAssignment)1