From dedbf7014ad23295e160317903630ea2cc99a2d6 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 16 Jul 2024 13:55:25 +0500 Subject: [PATCH] fill context attribute of the shape elements (similar to v0.7.0) #4832 --- src/ifcgeom/Converter.cpp | 33 ++++++++++++++------------------- src/ifcgeom/IfcGeomElement.h | 1 + 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/ifcgeom/Converter.cpp b/src/ifcgeom/Converter.cpp index b0e0d79d02..20809f5a7f 100644 --- a/src/ifcgeom/Converter.cpp +++ b/src/ifcgeom/Converter.cpp @@ -233,14 +233,19 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_represe std::string context_string = ""; - /* - // @todo - if (representation->RepresentationIdentifier()) { - context_string = *representation->RepresentationIdentifier(); - } else if (representation->ContextOfItems()->ContextType()) { - context_string = *representation->ContextOfItems()->ContextType(); + // IfcShapeRepresentation. + const IfcUtil::IfcBaseEntity *representation = representation_node->instance->as(); + auto representation_identifier = representation->get("RepresentationIdentifier"); + if (!representation_identifier->isNull()) { + context_string = *representation_identifier; + } + else { + IfcUtil::IfcBaseClass *context = (IfcUtil::IfcBaseClass *) *representation->get("ContextOfItems"); + auto context_type = context->as()->get("ContextType"); + if (!context_type->isNull()) { + context_string = *context_type; + } } - */ auto elem = new IfcGeom::BRepElement( product->data().id(), @@ -343,17 +348,8 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process const std::string guid = product->get_value("GlobalId"); const std::string name = product->get_value("Name", ""); - - /* - std::string context_string = ""; - if (representation->hasRepresentationIdentifier()) { - context_string = representation->RepresentationIdentifier(); - } else if (representation->ContextOfItems()->hasContextType()) { - context_string = representation->ContextOfItems()->ContextType(); - } - */ - const std::string product_type = product->declaration().name(); + const std::string context_string = brep->context(); return new IfcGeom::BRepElement( product->data().id(), @@ -361,8 +357,7 @@ IfcGeom::BRepElement* ifcopenshell::geometry::Converter::create_brep_for_process name, product_type, guid, - // @todo - "", + context_string, place, brep->geometry_pointer(), product diff --git a/src/ifcgeom/IfcGeomElement.h b/src/ifcgeom/IfcGeomElement.h index da2236be26..e17d0e39b5 100644 --- a/src/ifcgeom/IfcGeomElement.h +++ b/src/ifcgeom/IfcGeomElement.h @@ -92,6 +92,7 @@ namespace IfcGeom { const std::string& name() const { return _name; } const std::string& type() const { return _type; } const std::string& guid() const { return _guid; } + // Return the representation's identifier (e.g. "Body") if present, or it's context type (e.g. "Model"). const std::string& context() const { return _context; } const std::string& unique_id() const { return _unique_id; } const Transformation& transformation() const { return _transformation; }