From 94aa7dfab4f16395eafb9304ae3b7b2a7da429bb Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Sun, 18 Aug 2019 15:53:26 +0200 Subject: [PATCH] Close to working executable --- src/ifcgeom/kernel_agnostic/AbstractKernel.h | 2 ++ src/ifcgeom/schema/bind_convert_impl.i | 18 ++++++++++-------- src/ifcgeom/schema/mapping.cpp | 18 +++++++++++++++++- src/ifcgeom/schema/mapping.i | 2 +- src/ifcgeom/schema_agnostic/Converter.cpp | 5 +++++ src/ifcgeom/schema_agnostic/IfcGeomIterator.h | 1 + src/ifcgeom/taxonomy.h | 19 +++++++++++++------ 7 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/ifcgeom/kernel_agnostic/AbstractKernel.h b/src/ifcgeom/kernel_agnostic/AbstractKernel.h index 51673a6143..062b6d2a05 100644 --- a/src/ifcgeom/kernel_agnostic/AbstractKernel.h +++ b/src/ifcgeom/kernel_agnostic/AbstractKernel.h @@ -51,6 +51,8 @@ namespace ifcopenshell { namespace geometry { namespace kernels { virtual bool convert_impl(const taxonomy::face*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::extrusion*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } virtual bool convert_impl(const taxonomy::node*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } + virtual bool convert_impl(const taxonomy::colour*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } + virtual bool convert_impl(const taxonomy::collection*, ifcopenshell::geometry::ConversionResults&) { throw std::runtime_error("Not implemented"); } }; AbstractKernel* construct(const std::string& geometry_library, IfcParse::IfcFile*); diff --git a/src/ifcgeom/schema/bind_convert_impl.i b/src/ifcgeom/schema/bind_convert_impl.i index 89af251420..5914425f88 100644 --- a/src/ifcgeom/schema/bind_convert_impl.i +++ b/src/ifcgeom/schema/bind_convert_impl.i @@ -6,16 +6,18 @@ if (l->declaration().is(IfcSchema::T::Class())) { \ try { \ taxonomy::item* item = map((IfcSchema::T*)l); \ - item->instance = l; \ - try { \ - if (l->as()) { \ - auto style = find_style(l->as()); \ - if (style) { \ - ((taxonomy::geom_item*)item)->surface_style = as(map(style)); \ + if (item != nullptr) { \ + item->instance = l; \ + try { \ + if (l->as()) { \ + auto style = find_style(l->as()); \ + if (style) { \ + ((taxonomy::geom_item*)item)->surface_style = as(map(style)); \ + } \ } \ + } catch (const std::exception& e) { \ + Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l); \ } \ - } catch (const std::exception& e) { \ - Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l); \ } \ return item; \ } catch (const std::exception& e) { \ diff --git a/src/ifcgeom/schema/mapping.cpp b/src/ifcgeom/schema/mapping.cpp index a7b8a46871..d904f9e5d9 100644 --- a/src/ifcgeom/schema/mapping.cpp +++ b/src/ifcgeom/schema/mapping.cpp @@ -126,7 +126,6 @@ namespace { taxonomy::item* mapping::map(const IfcSchema::IfcExtrudedAreaSolid* inst) { // @todo length unit return new taxonomy::extrusion( - inst, as(map(inst->Position())), as(map(inst->SweptArea())), as(map(inst->ExtrudedDirection())), @@ -134,6 +133,23 @@ taxonomy::item* mapping::map(const IfcSchema::IfcExtrudedAreaSolid* inst) { ); } +taxonomy::item* mapping::map(const IfcSchema::IfcRepresentation* inst) { + auto c = new taxonomy::collection(); + IfcSchema::IfcRepresentationItem::list::ptr items = inst->Items(); + if (items->size()) { + for (IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) { + if (auto r = map(*it)) { + c->children.push_back(r); + } + } + } + if (c->children.empty()) { + delete c; + return nullptr; + } + return c; +} + taxonomy::item* mapping::map(const IfcSchema::IfcAxis2Placement3D* inst) { // @todo length unit return new taxonomy::matrix4(); diff --git a/src/ifcgeom/schema/mapping.i b/src/ifcgeom/schema/mapping.i index 2875100592..4fb8a158a7 100644 --- a/src/ifcgeom/schema/mapping.i +++ b/src/ifcgeom/schema/mapping.i @@ -26,7 +26,7 @@ // BIND(IfcShellBasedSurfaceModel); // BIND(IfcFaceBasedSurfaceModel); -// BIND(IfcRepresentation); +BIND(IfcRepresentation); // BIND(IfcMappedItem); // IfcFacetedBrep included // IfcAdvancedBrep included diff --git a/src/ifcgeom/schema_agnostic/Converter.cpp b/src/ifcgeom/schema_agnostic/Converter.cpp index 751b68ec8f..19843b11a8 100644 --- a/src/ifcgeom/schema_agnostic/Converter.cpp +++ b/src/ifcgeom/schema_agnostic/Converter.cpp @@ -35,6 +35,11 @@ ifcopenshell::geometry::NativeElement* ifcopenshell::geometry::Converter::create ifcopenshell::geometry::ConversionResults shapes; auto rep_item = mapping_->map(representation); + // @todo should map() throw an exception instead? + if (rep_item == nullptr) { + return nullptr; + } + // @todo decide how to get placement from product auto placement = (taxonomy::geom_item*) mapping_->map(product); kernel_->convert(rep_item, shapes); diff --git a/src/ifcgeom/schema_agnostic/IfcGeomIterator.h b/src/ifcgeom/schema_agnostic/IfcGeomIterator.h index c6febd30e1..cc6bc32823 100644 --- a/src/ifcgeom/schema_agnostic/IfcGeomIterator.h +++ b/src/ifcgeom/schema_agnostic/IfcGeomIterator.h @@ -209,6 +209,7 @@ namespace ifcopenshell { namespace geometry { const double unit_magnitude() const { return unit_magnitude_; } bool initialize() { + converter_ = new Converter(geometry_library_, ifc_file); converter_->mapping()->get_representations(tasks_, filters_, settings_); if (tasks_.size() == 0) { diff --git a/src/ifcgeom/taxonomy.h b/src/ifcgeom/taxonomy.h index 725ce46722..65bc958071 100644 --- a/src/ifcgeom/taxonomy.h +++ b/src/ifcgeom/taxonomy.h @@ -19,7 +19,7 @@ namespace geometry { namespace taxonomy { -enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE, EDGE, LOOP, FACE, EXTRUSION, NODE, COLOUR, STYLE }; +enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE, EDGE, LOOP, FACE, EXTRUSION, NODE, COLOUR, STYLE, COLLECTION }; struct item { const IfcUtil::IfcBaseClass* instance; @@ -83,6 +83,7 @@ struct geom_item : public item { geom_item(const IfcUtil::IfcBaseClass* instance = nullptr) : item(instance) {} geom_item(const IfcUtil::IfcBaseClass* instance, matrix4 m) : item(instance), matrix(m) {} + geom_item(matrix4 m) : matrix(m) {} }; template @@ -160,8 +161,8 @@ struct face : public geom_item { struct sweep : public geom_item { face basis; - sweep(const IfcUtil::IfcBaseClass* instance, face b) : geom_item(instance), basis(b) {} - sweep(const IfcUtil::IfcBaseClass* instance, matrix4 m, face b) : geom_item(instance, m), basis(b) {} + sweep(face b) : basis(b) {} + sweep(matrix4 m, face b) : geom_item(m), basis(b) {} }; struct extrusion : public sweep { @@ -171,7 +172,14 @@ struct extrusion : public sweep { virtual item* clone() const { return new extrusion(*this); } virtual kinds kind() const { return EXTRUSION; } - extrusion(const IfcUtil::IfcBaseClass* instance, matrix4 m, face basis, direction3 dir, double d) : sweep(instance, m, basis), direction(dir), depth(d) {} + extrusion(matrix4 m, face basis, direction3 dir, double d) : sweep(m, basis), direction(dir), depth(d) {} +}; + +struct collection : public geom_item { + std::vector children; + + virtual item* clone() const { return new collection(*this); } + virtual kinds kind() const { return COLLECTION; } }; struct node : public geom_item { @@ -185,8 +193,7 @@ struct node : public geom_item { }; namespace impl { - // enum kinds { MATRIX4, POINT3, DIRECTION3, LINE, CIRCLE, ELLIPSE, BSPLINE, EDGE, LOOP, FACE, EXTRUSION, NODE }; - typedef std::tuple KindsTuple; + typedef std::tuple KindsTuple; } struct type_by_kind {