From b86b359563768e957afcdfc65393e9d48af88599 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 4 Mar 2018 10:44:09 +0100 Subject: [PATCH] Schema independent layer and transformation conv functions --- src/ifcgeom/IfcGeom.h | 6 ++-- src/ifcgeom/IfcGeomFunctions.cpp | 30 -------------------- src/ifcgeom/IfcGeomRenderStyles.cpp | 12 +++++--- src/ifcgeom_schema_agnostic/Kernel.h | 42 ++++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 38 deletions(-) diff --git a/src/ifcgeom/IfcGeom.h b/src/ifcgeom/IfcGeom.h index ee89a08a94..8e61220064 100644 --- a/src/ifcgeom/IfcGeom.h +++ b/src/ifcgeom/IfcGeom.h @@ -110,7 +110,7 @@ private: std::map style_cache; - const SurfaceStyle* internalize_surface_style(const std::pair& shading_style); + const SurfaceStyle* internalize_surface_style(const std::pair& shading_style); // For stopping PlacementRelTo recursion in convert(const IfcSchema::IfcObjectPlacement* l, gp_Trsf& trsf) const IfcParse::declaration* placement_rel_to; @@ -224,9 +224,7 @@ public: static IfcSchema::IfcObjectDefinition* get_decomposing_entity(IfcSchema::IfcProduct*); - static std::map get_layers(IfcSchema::IfcProduct* prod); - - template + template IfcGeom::BRepElement

* create_brep_for_representation_and_product( const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*); diff --git a/src/ifcgeom/IfcGeomFunctions.cpp b/src/ifcgeom/IfcGeomFunctions.cpp index 1fc1bc18f0..bcff087646 100644 --- a/src/ifcgeom/IfcGeomFunctions.cpp +++ b/src/ifcgeom/IfcGeomFunctions.cpp @@ -1545,36 +1545,6 @@ IfcSchema::IfcObjectDefinition* IfcGeom::Kernel::get_decomposing_entity(IfcSchem return parent; } -std::map IfcGeom::Kernel::get_layers(IfcSchema::IfcProduct* prod) -{ - std::map layers; - if (prod->hasRepresentation()) { - IfcEntityList::ptr r = IfcParse::traverse(prod->Representation()); - IfcSchema::IfcRepresentation::list::ptr representations = r->as(); - for (IfcSchema::IfcRepresentation::list::it it = representations->begin(); it != representations->end(); ++it) { - IfcSchema::IfcPresentationLayerAssignment::list::ptr a = (*it)->LayerAssignments(); - for (IfcSchema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { - layers[(*jt)->Name()] = *jt; - } - } - - IfcSchema::IfcRepresentationItem::list::ptr items = r->as(); - for (IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) { - IfcSchema::IfcPresentationLayerAssignment::list::ptr a = (*it)-> - // LayerAssignments renamed from plural to singular, LayerAssignment, so work around that -#ifdef USE_IFC4 - LayerAssignment(); -#else - LayerAssignments(); -#endif - for (IfcSchema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { - layers[(*jt)->Name()] = *jt; - } - } - } - return layers; -} - template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product( const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product); template IFC_GEOM_API IfcGeom::BRepElement* IfcGeom::Kernel::create_brep_for_representation_and_product( diff --git a/src/ifcgeom/IfcGeomRenderStyles.cpp b/src/ifcgeom/IfcGeomRenderStyles.cpp index dfe6e87131..7d6921c684 100644 --- a/src/ifcgeom/IfcGeomRenderStyles.cpp +++ b/src/ifcgeom/IfcGeomRenderStyles.cpp @@ -56,7 +56,7 @@ namespace { #define Kernel MAKE_TYPE_NAME(Kernel) -const IfcGeom::SurfaceStyle* IfcGeom::Kernel::internalize_surface_style(const std::pair& shading_styles) { +const IfcGeom::SurfaceStyle* IfcGeom::Kernel::internalize_surface_style(const std::pair& shading_styles) { if (shading_styles.second == 0) { return 0; } @@ -66,13 +66,17 @@ const IfcGeom::SurfaceStyle* IfcGeom::Kernel::internalize_surface_style(const st return &(it->second); } SurfaceStyle surface_style; - if (shading_styles.first->hasName()) { - surface_style = SurfaceStyle(surface_style_id, shading_styles.first->Name()); + + IfcSchema::IfcSurfaceStyle* style = shading_styles.first->as(); + IfcSchema::IfcSurfaceStyleShading* shading = shading_styles.second->as(); + + if (style->hasName()) { + surface_style = SurfaceStyle(surface_style_id, style->Name()); } else { surface_style = SurfaceStyle(surface_style_id); } double rgb[3]; - if (process_colour(shading_styles.second->SurfaceColour(), rgb)) { + if (process_colour(shading->SurfaceColour(), rgb)) { surface_style.Diffuse().reset(SurfaceStyle::ColorComponent(rgb[0], rgb[1], rgb[2])); } if (shading_styles.second->declaration().is(IfcSchema::IfcSurfaceStyleRendering::Class())) { diff --git a/src/ifcgeom_schema_agnostic/Kernel.h b/src/ifcgeom_schema_agnostic/Kernel.h index a9632ea7de..8bec392b33 100644 --- a/src/ifcgeom_schema_agnostic/Kernel.h +++ b/src/ifcgeom_schema_agnostic/Kernel.h @@ -5,12 +5,25 @@ #include "../ifcgeom/IfcGeomIteratorSettings.h" #include "../ifcgeom/IfcRepresentationShapeItem.h" +#include "../ifcparse/Ifc2x3.h" +#include "../ifcparse/Ifc4.h" + #include #include namespace IfcGeom { + namespace impl { + // LayerAssignments renamed from plural to singular, LayerAssignment, so work around that + IfcEntityList::ptr getLayerAssignments(Ifc2x3::IfcRepresentationItem* item) { + return item->LayerAssignments()->generalize(); + } + IfcEntityList::ptr getLayerAssignments(Ifc4::IfcRepresentationItem* item) { + return item->LayerAssignment()->generalize(); + } + } + template class BRepElement; @@ -76,7 +89,36 @@ namespace IfcGeom { return implementation_->convert(item); } + virtual bool convert(IfcUtil::IfcBaseClass* item, gp_Trsf& trsf) { + return implementation_->convert(item, trsf); + } + static int count(const TopoDS_Shape&, TopAbs_ShapeEnum); + + template + static std::map get_layers(typename Schema::IfcProduct* prod) { + std::map layers; + if (prod->hasRepresentation()) { + IfcEntityList::ptr r = IfcParse::traverse(prod->Representation()); + Schema::IfcRepresentation::list::ptr representations = r->as(); + for (Schema::IfcRepresentation::list::it it = representations->begin(); it != representations->end(); ++it) { + Schema::IfcPresentationLayerAssignment::list::ptr a = (*it)->LayerAssignments(); + for (Schema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { + layers[(*jt)->Name()] = *jt; + } + } + + Schema::IfcRepresentationItem::list::ptr items = r->as(); + for (Schema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) { + Schema::IfcPresentationLayerAssignment::list::ptr a = impl::getLayerAssignments(*it)->as(); + for (Schema::IfcPresentationLayerAssignment::list::it jt = a->begin(); jt != a->end(); ++jt) { + layers[(*jt)->Name()] = *jt; + } + } + } + return layers; + } + }; namespace impl {