Implement mapping of IfcExtrudedAreaSolid

This commit is contained in:
Thomas Krijnen
2019-08-04 11:27:10 +02:00
parent 467ebb68a3
commit dae35f59ce
4 changed files with 97 additions and 16 deletions
+55 -1
View File
@@ -22,9 +22,63 @@
#include "../../ifcparse/IfcLogger.h"
using namespace IfcUtil;
using namespace ifcopenshell::geometry;
ifcopenshell::geometry::taxonomy::item* ifcopenshell::geometry::POSTFIX_SCHEMA(mapping)::map(const IfcBaseClass* l) {
#define mapping POSTFIX_SCHEMA(mapping)
taxonomy::item* mapping::map(const IfcBaseClass* l) {
#include "bind_convert_impl.i"
Logger::Message(Logger::LOG_ERROR, "No operation defined for:", l);
return nullptr;
}
namespace {
// A RAII-based mechanism to cast the conversion results
// from map() into the right type expected by the higher
// level typology items. An exception is thrown if the
// types do not match or the result was nullptr. A copy
// will be assigned to the higher level topology member
// and the original pointer will be deleted.
// This class is also able to uplift some topology items
// to higher level types, such as a loop to a face, which
// is why the cast operator does not return a reference.
template <typename T>
class as {
private:
taxonomy::item* item_;
public:
as(taxonomy::item* item) : item_(item) {}
operator T() const {
if (!item_) {
throw taxonomy::topology_error;
}
T* t = dynamic_cast<T*>(item_);
if (t) {
return *t;
} else {
if constexpr (std::is_same<T, topology::face>::value) {
topology::loop* loop = dynamic_cast<T*>(item_);
if (loop) {
return topology::face(loop.id, loop.matrix, *loop);
}
}
throw taxonomy::topology_error;
}
}
~as() {
delete item;
}
};
};
taxonomy::item* mapping::map(const IfcSchema::IfcExtrudedAreaSolid* inst) {
return new taxonomy::extrusion(
inst->data().id(),
as<taxonomy::matrix4>(map(inst->Position())),
as<taxonomy::face>(map(inst->SweptArea())),
as<taxonomy::direction3>(map(inst->ExtrudedDirection())),
inst->Depth()
);
}