Work on python wrapper

This commit is contained in:
Thomas Krijnen
2017-12-22 13:51:11 +01:00
parent 4d325e026e
commit b3458c872f
16 changed files with 302 additions and 152 deletions
@@ -47,14 +47,6 @@ public:
template <typename P>
IteratorFactoryImplementation<P>& iterator_implementations();
template <class T>
class Registrar {
public:
Registrar(const std::string& schema_name, const typename get_factory_type<typename T::Precision>::type& fn) {
iterator_implementations<typename T::Precision>().bind(schema_name, fn);
}
};
namespace IfcGeom {
template <typename P>
+49
View File
@@ -0,0 +1,49 @@
#include "Kernel.h"
IfcGeom::Kernel::Kernel(IfcParse::IfcFile* file) {
if (file != 0) {
if (file->schema() == 0) {
throw IfcParse::IfcException("No schema associated with file");
}
const std::string& schema_name = file->schema()->name();
impl::kernel_implementations().construct(schema_name, file);
}
}
int IfcGeom::Kernel::count(const TopoDS_Shape& s, TopAbs_ShapeEnum t) {
int i = 0;
TopExp_Explorer exp(s, t);
for (; exp.More(); exp.Next()) {
++i;
}
return i;
}
IfcGeom::impl::KernelFactoryImplementation& IfcGeom::impl::kernel_implementations() {
static KernelFactoryImplementation impl;
return impl;
}
extern void init_KernelImplementation_Ifc2x3(IfcGeom::impl::KernelFactoryImplementation*);
extern void init_KernelImplementation_Ifc4(IfcGeom::impl::KernelFactoryImplementation*);
IfcGeom::impl::KernelFactoryImplementation::KernelFactoryImplementation() {
init_KernelImplementation_Ifc2x3(this);
init_KernelImplementation_Ifc4(this);
}
void IfcGeom::impl::KernelFactoryImplementation::bind(const std::string& schema_name, IfcGeom::impl::kernel_fn fn) {
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
this->insert(std::make_pair(schema_name_lower, fn));
}
IfcGeom::Kernel* IfcGeom::impl::KernelFactoryImplementation::construct(const std::string& schema_name, IfcParse::IfcFile* file) {
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
std::map<std::string, IfcGeom::impl::kernel_fn>::const_iterator it;
it = this->find(schema_name_lower);
if (it == end()) {
throw IfcParse::IfcException("No geometry kernel registered for " + schema_name);
}
return it->second(file);
}
+51
View File
@@ -1,8 +1,23 @@
#ifndef ITERATOR_KERNEL_H
#define ITERATOR_KERNEL_H
#include "../ifcparse/IfcFile.h"
#include "../ifcgeom/IfcGeomIteratorSettings.h"
#include "../ifcgeom/IfcRepresentationShapeItem.h"
#include <boost/function.hpp>
#include <TopExp_Explorer.hxx>
namespace IfcGeom {
template <typename T>
class BRepElement;
class Kernel {
private:
Kernel* implementation_;
public:
// Tolerances and settings for various geometrical operations:
enum GeomValue {
@@ -37,9 +52,45 @@ namespace IfcGeom {
// Whether to process shapes of type Face or higher (1) Wire or lower (-1) or all (0)
GV_DIMENSIONALITY
};
Kernel(IfcParse::IfcFile* file_ = 0);
virtual ~Kernel() {}
virtual void setValue(GeomValue var, double value) {
implementation_->setValue(var, value);
}
virtual double getValue(GeomValue var) const {
return implementation_->getValue(var);
}
virtual BRepElement<double>* convert(
const IteratorSettings& settings, IfcUtil::IfcBaseClass* representation,
IfcUtil::IfcBaseClass* product)
{
return implementation_->convert(settings, representation, product);
}
virtual IfcRepresentationShapeItems convert(IfcUtil::IfcBaseClass* item) {
return implementation_->convert(item);
}
static int count(const TopoDS_Shape&, TopAbs_ShapeEnum);
};
namespace impl {
typedef boost::function1<Kernel*, IfcParse::IfcFile*> kernel_fn;
class KernelFactoryImplementation : public std::map<std::string, kernel_fn> {
public:
KernelFactoryImplementation();
void bind(const std::string& schema_name, kernel_fn);
Kernel* construct(const std::string& schema_name, IfcParse::IfcFile*);
};
KernelFactoryImplementation& kernel_implementations();
}
}
#endif