From 4e897a0c216799de5d9de9f448001bc8e62b1080 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sat, 13 Feb 2021 16:03:57 +0100 Subject: [PATCH] surface style ids on serialization --- src/ifcgeom/IfcGeomRepresentation.cpp | 7 +++++++ src/ifcgeom/IfcGeomRepresentation.h | 2 ++ src/ifcgeom_schema_agnostic/IfcGeomRenderStyles.h | 3 +++ src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py | 10 ++++++---- src/ifcwrap/IfcGeomWrapper.i | 1 + 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/ifcgeom/IfcGeomRepresentation.cpp b/src/ifcgeom/IfcGeomRepresentation.cpp index 0656899114..f148b97e8b 100644 --- a/src/ifcgeom/IfcGeomRepresentation.cpp +++ b/src/ifcgeom/IfcGeomRepresentation.cpp @@ -36,21 +36,28 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep) { TopoDS_Compound compound = brep.as_compound(); for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = brep.begin(); it != brep.end(); ++ it) { + int sid = -1; + if (it->hasStyle() && it->Style().Diffuse()) { const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse(); surface_styles_.push_back(clr.R()); surface_styles_.push_back(clr.G()); surface_styles_.push_back(clr.B()); + + sid = it->Style().Id().get_value_or(-1); } else { surface_styles_.push_back(-1.); surface_styles_.push_back(-1.); surface_styles_.push_back(-1.); } + if (it->hasStyle() && it->Style().Transparency()) { surface_styles_.push_back(1. - *it->Style().Transparency()); } else { surface_styles_.push_back(1.); } + + surface_style_ids_.push_back(sid); } std::stringstream sstream; BRepTools::Write(compound,sstream); diff --git a/src/ifcgeom/IfcGeomRepresentation.h b/src/ifcgeom/IfcGeomRepresentation.h index b20c646cf3..7e81c0f15f 100644 --- a/src/ifcgeom/IfcGeomRepresentation.h +++ b/src/ifcgeom/IfcGeomRepresentation.h @@ -87,9 +87,11 @@ namespace IfcGeom { std::string id_; std::string brep_data_; std::vector surface_styles_; + std::vector surface_style_ids_; public: const std::string& brep_data() const { return brep_data_; } const std::vector& surface_styles() const { return surface_styles_; } + const std::vector& surface_style_ids() const { return surface_style_ids_; } Serialization(const BRep& brep); virtual ~Serialization() {} const std::string& id() const { return id_; } diff --git a/src/ifcgeom_schema_agnostic/IfcGeomRenderStyles.h b/src/ifcgeom_schema_agnostic/IfcGeomRenderStyles.h index 33971f7182..4412e5d84d 100644 --- a/src/ifcgeom_schema_agnostic/IfcGeomRenderStyles.h +++ b/src/ifcgeom_schema_agnostic/IfcGeomRenderStyles.h @@ -90,10 +90,13 @@ namespace IfcGeom { const boost::optional& Specular() const { return specular; } const boost::optional& Transparency() const { return transparency; } const boost::optional& Specularity() const { return specularity; } + const boost::optional& Id() const { return id; } + boost::optional& Diffuse() { return diffuse; } boost::optional& Specular() { return specular; } boost::optional& Transparency() { return transparency; } boost::optional& Specularity() { return specularity; } + boost::optional& Id() { return id; } }; IFC_GEOM_API const SurfaceStyle* get_default_style(const std::string& ifc_type); diff --git a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py index 81e744cec4..e350bf9ad2 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py @@ -41,7 +41,7 @@ except ImportError: USE_OCCT_HANDLE = True -shape_tuple = namedtuple("shape_tuple", ("data", "geometry", "styles")) +shape_tuple = namedtuple("shape_tuple", ("data", "geometry", "styles", "style_ids")) handle, main_loop, add_menu, add_function_to_menu = None, None, None, None @@ -216,16 +216,18 @@ def serialize_shape(shape): def create_shape_from_serialization(brep_object): - brep_data, occ_shape, styles = None, None, () + brep_data, occ_shape, styles, style_ids = None, None, (), () is_product_shape = True try: brep_data = brep_object.geometry.brep_data styles = brep_object.geometry.surface_styles + style_ids = brep_object.geometry.surface_style_ids except BaseException: try: brep_data = brep_object.brep_data styles = brep_object.surface_styles + style_ids = brep_object.surface_style_ids is_product_shape = False except BaseException: pass @@ -233,7 +235,7 @@ def create_shape_from_serialization(brep_object): styles = tuple(styles[i : i + 4] for i in range(0, len(styles), 4)) if not brep_data: - return shape_tuple(brep_object, None, styles) + return shape_tuple(brep_object, None, styles, style_ids) try: ss = BRepTools.BRepTools_ShapeSet() @@ -243,6 +245,6 @@ def create_shape_from_serialization(brep_object): pass if is_product_shape: - return shape_tuple(brep_object, occ_shape, styles) + return shape_tuple(brep_object, occ_shape, styles, style_ids) else: return occ_shape diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 79249cddd1..957d37a3dd 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -269,6 +269,7 @@ struct ShapeRTTI : public boost::static_visitor id = property(id) brep_data = property(brep_data) surface_styles = property(surface_styles) + surface_style_ids = property(surface_style_ids) %} };