From 8f7949808a026df56ad927ba250f39c2904e1b5b Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 17 Sep 2024 18:25:41 +0500 Subject: [PATCH] Move id to IfcGeom::Representation::Representation and document it as it's a common attribute for all 3 Representation subclasses we have --- src/ifcgeom/IfcGeomRepresentation.cpp | 6 ++---- src/ifcgeom/IfcGeomRepresentation.h | 27 +++++++++++++-------------- src/ifcwrap/IfcGeomWrapper.i | 9 +++++++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/ifcgeom/IfcGeomRepresentation.cpp b/src/ifcgeom/IfcGeomRepresentation.cpp index 9f8d10bd58..24b1c7f319 100644 --- a/src/ifcgeom/IfcGeomRepresentation.cpp +++ b/src/ifcgeom/IfcGeomRepresentation.cpp @@ -142,8 +142,7 @@ namespace { #endif IfcGeom::Representation::Serialization::Serialization(const BRep& brep) - : Representation(brep.settings(), brep.entity()) - , id_(brep.id()) + : Representation(brep.settings(), brep.entity(), brep.id()) { for (auto it = brep.begin(); it != brep.end(); ++it) { int sid = -1; @@ -323,8 +322,7 @@ bool IfcGeom::Representation::BRep::calculate_projected_surface_area(const ifcop } IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model) - : Representation(shape_model.settings(), shape_model.entity()) - , id_(shape_model.id()) + : Representation(shape_model.settings(), shape_model.entity(), shape_model.id()) , weld_offset_(0) { for (IfcGeom::ConversionResults::const_iterator iit = shape_model.begin(); iit != shape_model.end(); ++iit) { diff --git a/src/ifcgeom/IfcGeomRepresentation.h b/src/ifcgeom/IfcGeomRepresentation.h index a52953d602..8efc98f659 100644 --- a/src/ifcgeom/IfcGeomRepresentation.h +++ b/src/ifcgeom/IfcGeomRepresentation.h @@ -35,35 +35,39 @@ namespace IfcGeom { protected: const ifcopenshell::geometry::Settings settings_; const std::string entity_; + std::string id_; public: - explicit Representation(const ifcopenshell::geometry::Settings& settings, const std::string& entity) + explicit Representation(const ifcopenshell::geometry::Settings& settings, const std::string& entity, const std::string& id) : settings_(settings) , entity_(entity) + , id_(id) {} const ifcopenshell::geometry::Settings& settings() const { return settings_; } const std::string& entity() const { return entity_; } + // id starts with representation id and then it may have the following dash separated elements: + // - layerset-layerset_id + // - material-material_id + // - openings-opening0_id-...-openingN_id + const std::string& id() const { return id_; } virtual ~Representation() {} }; class IFC_GEOM_API BRep : public Representation { private: - std::string id_; const IfcGeom::ConversionResults shapes_; BRep(const BRep& other); BRep& operator=(const BRep& other); public: BRep(const ifcopenshell::geometry::Settings& settings, const std::string& entity, const std::string& id, const IfcGeom::ConversionResults& shapes) - : Representation(settings, entity) - , id_(id) + : Representation(settings, entity, id) , shapes_(shapes) {} virtual ~BRep() {} IfcGeom::ConversionResults::const_iterator begin() const { return shapes_.begin(); } IfcGeom::ConversionResults::const_iterator end() const { return shapes_.end(); } const IfcGeom::ConversionResults& shapes() const { return shapes_; } - const std::string& id() const { return id_; } IfcGeom::ConversionResultShape* as_compound(bool force_meters = false) const; bool calculate_volume(double&) const; @@ -77,7 +81,6 @@ namespace IfcGeom { class IFC_GEOM_API Serialization : public Representation { private: - std::string id_; std::string brep_data_; std::vector surface_styles_; std::vector surface_style_ids_; @@ -87,7 +90,6 @@ namespace IfcGeom { const std::vector& surface_style_ids() const { return surface_style_ids_; } Serialization(const BRep& brep); virtual ~Serialization() {} - const std::string& id() const { return id_; } private: Serialization(); Serialization(const Serialization&); @@ -101,7 +103,6 @@ namespace IfcGeom { typedef std::map VertexKeyMap; typedef std::pair Edge; - std::string id_; std::vector _verts; std::vector _faces; std::vector _edges; @@ -113,13 +114,12 @@ namespace IfcGeom { size_t weld_offset_; VertexKeyMap welds; - Triangulation(const ifcopenshell::geometry::Settings& settings, const std::string& entity) - : Representation(settings, entity) + Triangulation(const ifcopenshell::geometry::Settings& settings, const std::string& entity, const std::string& id) + : Representation(settings, entity, id) , weld_offset_(0) {} public: - const std::string& id() const { return id_; } const std::vector& verts() const { return _verts; } const std::vector& faces() const { return _faces; } const std::vector& edges() const { return _edges; } @@ -145,8 +145,7 @@ namespace IfcGeom { const std::vector& materials, const std::vector& item_ids ) - : Representation(settings, entity) - , id_(id) + : Representation(settings, entity, id) , _verts(verts) , _faces(faces) , _edges(edges) @@ -163,7 +162,7 @@ namespace IfcGeom { /// @todo Very simple impl. Assumes that input vertices and normals match 1:1. static std::vector box_project_uvs(const std::vector &vertices, const std::vector &normals); - static Triangulation* empty(const ifcopenshell::geometry::Settings& settings) { return new Triangulation(settings, ""); } + static Triangulation* empty(const ifcopenshell::geometry::Settings& settings) { return new Triangulation(settings, "", ""); } /// Welds vertices that belong to different faces int addVertex(int item_index, int material_index, double X, double Y, double Z); diff --git a/src/ifcwrap/IfcGeomWrapper.i b/src/ifcwrap/IfcGeomWrapper.i index 03adf23494..dbf9451a7c 100644 --- a/src/ifcwrap/IfcGeomWrapper.i +++ b/src/ifcwrap/IfcGeomWrapper.i @@ -681,7 +681,6 @@ struct ShapeRTTI : public boost::static_visitor %pythoncode %{ # Hide the getters with read-only property implementations - id = property(id) faces = property(faces) edges = property(edges) material_ids = property(material_ids) @@ -700,10 +699,16 @@ struct ShapeRTTI : public boost::static_visitor %} }; -%extend IfcGeom::Representation::Serialization { +%extend IfcGeom::Representation::Representation { %pythoncode %{ # Hide the getters with read-only property implementations id = property(id) + %} +}; + +%extend IfcGeom::Representation::Serialization { + %pythoncode %{ + # Hide the getters with read-only property implementations brep_data = property(brep_data) surface_styles = property(surface_styles) surface_style_ids = property(surface_style_ids)