mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
Work on python wrapper
This commit is contained in:
+24
-3
@@ -79,6 +79,11 @@ if ( it != cache.T.end() ) { e = it->second; return true; }
|
|||||||
#define MAKE_TYPE_NAME_(a, b) MAKE_TYPE_NAME__(a, b)
|
#define MAKE_TYPE_NAME_(a, b) MAKE_TYPE_NAME__(a, b)
|
||||||
#define MAKE_TYPE_NAME(t) MAKE_TYPE_NAME_(t, IfcSchema)
|
#define MAKE_TYPE_NAME(t) MAKE_TYPE_NAME_(t, IfcSchema)
|
||||||
|
|
||||||
|
#define STRINGIFY_(x) #x
|
||||||
|
#define STRINGIFY(x) STRINGIFY_(x)
|
||||||
|
#define INCLUDE(x) STRINGIFY(../ifcparse/x.h)
|
||||||
|
#include INCLUDE(IfcSchema)
|
||||||
|
|
||||||
namespace IfcGeom {
|
namespace IfcGeom {
|
||||||
|
|
||||||
class IFC_GEOM_API MAKE_TYPE_NAME(Cache) {
|
class IFC_GEOM_API MAKE_TYPE_NAME(Cache) {
|
||||||
@@ -178,7 +183,6 @@ public:
|
|||||||
bool closest(const gp_Pnt&, const std::vector<gp_Pnt>&, gp_Pnt&);
|
bool closest(const gp_Pnt&, const std::vector<gp_Pnt>&, gp_Pnt&);
|
||||||
bool project(const Handle_Geom_Curve&, const gp_Pnt&, gp_Pnt& p, double& u, double& d);
|
bool project(const Handle_Geom_Curve&, const gp_Pnt&, gp_Pnt& p, double& u, double& d);
|
||||||
bool project(const Handle_Geom_Surface&, const TopoDS_Shape&, double& u1, double& v1, double& u2, double& v2, double widen=0.1);
|
bool project(const Handle_Geom_Surface&, const TopoDS_Shape&, double& u1, double& v1, double& u2, double& v2, double widen=0.1);
|
||||||
static int count(const TopoDS_Shape&, TopAbs_ShapeEnum);
|
|
||||||
|
|
||||||
bool find_wall_end_points(const IfcSchema::IfcWall*, gp_Pnt& start, gp_Pnt& end);
|
bool find_wall_end_points(const IfcSchema::IfcWall*, gp_Pnt& start, gp_Pnt& end);
|
||||||
|
|
||||||
@@ -194,8 +198,6 @@ public:
|
|||||||
const TopoDS_Shape& ensure_fit_for_subtraction(const TopoDS_Shape& shape, TopoDS_Shape& solid);
|
const TopoDS_Shape& ensure_fit_for_subtraction(const TopoDS_Shape& shape, TopoDS_Shape& solid);
|
||||||
bool profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Shape& face);
|
bool profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Shape& face);
|
||||||
void apply_tolerance(TopoDS_Shape& s, double t);
|
void apply_tolerance(TopoDS_Shape& s, double t);
|
||||||
void setValue(GeomValue var, double value);
|
|
||||||
double getValue(GeomValue var) const;
|
|
||||||
bool fill_nonmanifold_wires_with_planar_faces(TopoDS_Shape& shape);
|
bool fill_nonmanifold_wires_with_planar_faces(TopoDS_Shape& shape);
|
||||||
void remove_duplicate_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
void remove_duplicate_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
||||||
void remove_collinear_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
void remove_collinear_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
||||||
@@ -299,6 +301,25 @@ public:
|
|||||||
|
|
||||||
#include "IfcRegisterGeomHeader.h"
|
#include "IfcRegisterGeomHeader.h"
|
||||||
|
|
||||||
|
virtual void setValue(GeomValue var, double value);
|
||||||
|
virtual double getValue(GeomValue var) const;
|
||||||
|
|
||||||
|
virtual IfcGeom::BRepElement<double>* convert(
|
||||||
|
const IteratorSettings& settings, IfcUtil::IfcBaseClass* representation,
|
||||||
|
IfcUtil::IfcBaseClass* product)
|
||||||
|
{
|
||||||
|
return create_brep_for_representation_and_product<double>(settings, (IfcSchema::IfcRepresentation*) representation, (IfcSchema::IfcProduct*) product);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual IfcRepresentationShapeItems convert(IfcUtil::IfcBaseClass* item) {
|
||||||
|
IfcRepresentationShapeItems items;
|
||||||
|
bool success = convert_shapes(item, items);
|
||||||
|
if (!success) {
|
||||||
|
throw IfcParse::IfcException("Failed to process representation item");
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* tesselate(const TopoDS_Shape& shape, double deflection);
|
IFC_GEOM_API IfcSchema::IfcProductDefinitionShape* tesselate(const TopoDS_Shape& shape, double deflection);
|
||||||
|
|||||||
@@ -145,6 +145,68 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define MAKE_INIT_FN__(a, b) init_ ## a ## b
|
||||||
|
#define MAKE_INIT_FN_(a, b) MAKE_INIT_FN__(a, b)
|
||||||
|
#define MAKE_INIT_FN(t) MAKE_INIT_FN_(t, IfcSchema)
|
||||||
|
|
||||||
|
void MAKE_INIT_FN(Kernel)(IfcGeom::impl::KernelFactoryImplementation* mapping) {
|
||||||
|
static const std::string schema_name = STRINGIFY(IfcSchema);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
IfcGeom::Kernel* operator()(IfcParse::IfcFile* file) const {
|
||||||
|
IfcGeom::MAKE_TYPE_NAME(Kernel)* k = new IfcGeom::MAKE_TYPE_NAME(Kernel);
|
||||||
|
if (file) {
|
||||||
|
double unit_magnitude = 1.;
|
||||||
|
|
||||||
|
// Set unit information from file
|
||||||
|
|
||||||
|
IfcSchema::IfcProject::list::ptr projects = file->instances_by_type<IfcSchema::IfcProject>();
|
||||||
|
if (projects->size() == 1) {
|
||||||
|
IfcSchema::IfcProject* project = *projects->begin();
|
||||||
|
std::pair<std::string, double> unit_info = k->initializeUnits(project->UnitsInContext());
|
||||||
|
unit_magnitude = unit_info.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set precision from file
|
||||||
|
|
||||||
|
double lowest_precision_encountered = std::numeric_limits<double>::infinity();
|
||||||
|
bool any_precision_encountered = false;
|
||||||
|
|
||||||
|
IfcSchema::IfcGeometricRepresentationContext::list::it it;
|
||||||
|
IfcSchema::IfcGeometricRepresentationContext::list::ptr contexts =
|
||||||
|
file->instances_by_type<IfcSchema::IfcGeometricRepresentationContext>();
|
||||||
|
|
||||||
|
for (it = contexts->begin(); it != contexts->end(); ++it) {
|
||||||
|
IfcSchema::IfcGeometricRepresentationContext* context = *it;
|
||||||
|
if (context->hasPrecision() && context->Precision() < lowest_precision_encountered) {
|
||||||
|
// Some arbitrary factor that has proven to work better for the models in the set of test files.
|
||||||
|
lowest_precision_encountered = context->Precision() * unit_magnitude * 10.;
|
||||||
|
any_precision_encountered = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double precision_to_set = 1.e-5;
|
||||||
|
|
||||||
|
if (any_precision_encountered) {
|
||||||
|
if (lowest_precision_encountered < 1.e-7) {
|
||||||
|
Logger::Message(Logger::LOG_WARNING, "Precision lower than 0.0000001 meter not enforced");
|
||||||
|
precision_to_set = 1.e-7;
|
||||||
|
} else {
|
||||||
|
precision_to_set = lowest_precision_encountered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
k->setValue(IfcGeom::Kernel::GV_PRECISION, precision_to_set);
|
||||||
|
}
|
||||||
|
return k;
|
||||||
|
}
|
||||||
|
} factory;
|
||||||
|
|
||||||
|
mapping->bind(schema_name, factory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#define Kernel MAKE_TYPE_NAME(Kernel)
|
#define Kernel MAKE_TYPE_NAME(Kernel)
|
||||||
|
|
||||||
bool IfcGeom::Kernel::create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& shape) {
|
bool IfcGeom::Kernel::create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& shape) {
|
||||||
@@ -1785,15 +1847,6 @@ bool IfcGeom::Kernel::project(const Handle_Geom_Curve& crv, const gp_Pnt& pt, gp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IfcGeom::Kernel::find_wall_end_points(const IfcSchema::IfcWall* wall, gp_Pnt& start, gp_Pnt& end) {
|
bool IfcGeom::Kernel::find_wall_end_points(const IfcSchema::IfcWall* wall, gp_Pnt& start, gp_Pnt& end) {
|
||||||
IfcSchema::IfcRepresentation* axis_representation = find_representation(wall, "Axis");
|
IfcSchema::IfcRepresentation* axis_representation = find_representation(wall, "Axis");
|
||||||
if (!axis_representation) {
|
if (!axis_representation) {
|
||||||
|
|||||||
@@ -10,12 +10,9 @@ namespace IfcGeom {
|
|||||||
#define MAKE_INIT_FN_(a, b) MAKE_INIT_FN__(a, b)
|
#define MAKE_INIT_FN_(a, b) MAKE_INIT_FN__(a, b)
|
||||||
#define MAKE_INIT_FN(t) MAKE_INIT_FN_(t, IfcSchema)
|
#define MAKE_INIT_FN(t) MAKE_INIT_FN_(t, IfcSchema)
|
||||||
|
|
||||||
#define STRINGIFY(x) #x
|
|
||||||
#define TOSTRING(x) STRINGIFY(x)
|
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
void MAKE_INIT_FN(IteratorImplementation_)(IteratorFactoryImplementation<P>* mapping) {
|
void MAKE_INIT_FN(IteratorImplementation_)(IteratorFactoryImplementation<P>* mapping) {
|
||||||
static const std::string schema_name = TOSTRING(IfcSchema);
|
static const std::string schema_name = STRINGIFY(IfcSchema);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
IfcGeom::IteratorImplementation<P>* operator()(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file) const {
|
IfcGeom::IteratorImplementation<P>* operator()(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file) const {
|
||||||
|
|||||||
@@ -27,8 +27,9 @@
|
|||||||
#include <TColgp_Array1OfPnt.hxx>
|
#include <TColgp_Array1OfPnt.hxx>
|
||||||
#include <TColgp_Array1OfPnt2d.hxx>
|
#include <TColgp_Array1OfPnt2d.hxx>
|
||||||
|
|
||||||
#include <TopExp_Explorer.hxx>
|
#include <TopoDS.hxx>
|
||||||
#include <BRepTools.hxx>
|
#include <BRepTools.hxx>
|
||||||
|
#include <TopExp_Explorer.hxx>
|
||||||
|
|
||||||
#include <BRepAdaptor_Curve.hxx>
|
#include <BRepAdaptor_Curve.hxx>
|
||||||
#include <GCPnts_QuasiUniformDeflection.hxx>
|
#include <GCPnts_QuasiUniformDeflection.hxx>
|
||||||
@@ -203,13 +204,13 @@ namespace IfcGeom {
|
|||||||
gp_Vec normal_direction;
|
gp_Vec normal_direction;
|
||||||
prop.Normal(uv.X(),uv.Y(),p,normal_direction);
|
prop.Normal(uv.X(),uv.Y(),p,normal_direction);
|
||||||
gp_Vec normal(0., 0., 0.);
|
gp_Vec normal(0., 0., 0.);
|
||||||
if (normal_direction.Magnitude() > ALMOST_ZERO) {
|
if (normal_direction.Magnitude() > 1.e-9) {
|
||||||
normal = gp_Dir(normal_direction.XYZ() * rotation_matrix);
|
normal = gp_Dir(normal_direction.XYZ() * rotation_matrix);
|
||||||
} else {
|
} else {
|
||||||
Handle_Geom_Surface surf = BRep_Tool::Surface(face);
|
Handle_Geom_Surface surf = BRep_Tool::Surface(face);
|
||||||
// Special case the normal at the poles of a spherical surface
|
// Special case the normal at the poles of a spherical surface
|
||||||
if (surf->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) {
|
if (surf->DynamicType() == STANDARD_TYPE(Geom_SphericalSurface)) {
|
||||||
if (ALMOST_THE_SAME(fabs(uv.Y()), M_PI / 2.)) {
|
if (fabs(fabs(uv.Y()) - M_PI / 2.) < 1.e-9) {
|
||||||
const bool is_top = uv.Y() > 0;
|
const bool is_top = uv.Y() > 0;
|
||||||
const bool is_forward = face.Orientation() == TopAbs_FORWARD;
|
const bool is_forward = face.Orientation() == TopAbs_FORWARD;
|
||||||
const double z = (is_top == is_forward) ? 1. : -1.;
|
const double z = (is_top == is_forward) ? 1. : -1.;
|
||||||
|
|||||||
@@ -21,7 +21,9 @@
|
|||||||
#define IFCGEOMTREE_H
|
#define IFCGEOMTREE_H
|
||||||
|
|
||||||
#include "../ifcparse/IfcFile.h"
|
#include "../ifcparse/IfcFile.h"
|
||||||
#include "../ifcgeom/IfcGeomIterator.h"
|
#include "../ifcgeom/IfcGeomElement.h"
|
||||||
|
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
|
#include "../ifcgeom_schema_agnostic/Kernel.h"
|
||||||
|
|
||||||
#include <NCollection_UBTree.hxx>
|
#include <NCollection_UBTree.hxx>
|
||||||
#include <BRepBndLib.hxx>
|
#include <BRepBndLib.hxx>
|
||||||
@@ -243,7 +245,7 @@ namespace IfcGeom {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
class tree : public impl::tree<IfcSchema::IfcProduct*> {
|
class tree : public impl::tree<IfcUtil::IfcBaseEntity*> {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
tree() {};
|
tree() {};
|
||||||
@@ -267,7 +269,7 @@ namespace IfcGeom {
|
|||||||
if (it.initialize()) {
|
if (it.initialize()) {
|
||||||
do {
|
do {
|
||||||
IfcGeom::BRepElement<double>* elem = (IfcGeom::BRepElement<double>*)it.get();
|
IfcGeom::BRepElement<double>* elem = (IfcGeom::BRepElement<double>*)it.get();
|
||||||
add((IfcSchema::IfcProduct*)f.entityById(elem->id()), elem->geometry().as_compound());
|
add((IfcUtil::IfcBaseEntity*)f.instance_by_id(elem->id()), elem->geometry().as_compound());
|
||||||
} while (it.next());
|
} while (it.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,14 +47,6 @@ public:
|
|||||||
template <typename P>
|
template <typename P>
|
||||||
IteratorFactoryImplementation<P>& iterator_implementations();
|
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 {
|
namespace IfcGeom {
|
||||||
|
|
||||||
template <typename P>
|
template <typename P>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
@@ -1,8 +1,23 @@
|
|||||||
#ifndef ITERATOR_KERNEL_H
|
#ifndef ITERATOR_KERNEL_H
|
||||||
#define 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 {
|
namespace IfcGeom {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class BRepElement;
|
||||||
|
|
||||||
class Kernel {
|
class Kernel {
|
||||||
|
private:
|
||||||
|
Kernel* implementation_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Tolerances and settings for various geometrical operations:
|
// Tolerances and settings for various geometrical operations:
|
||||||
enum GeomValue {
|
enum GeomValue {
|
||||||
@@ -38,8 +53,44 @@ namespace IfcGeom {
|
|||||||
GV_DIMENSIONALITY
|
GV_DIMENSIONALITY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Kernel(IfcParse::IfcFile* file_ = 0);
|
||||||
|
|
||||||
virtual ~Kernel() {}
|
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
|
#endif
|
||||||
@@ -18,7 +18,9 @@
|
|||||||
********************************************************************************/
|
********************************************************************************/
|
||||||
|
|
||||||
#include "IfcLogger.h"
|
#include "IfcLogger.h"
|
||||||
|
|
||||||
#include "../ifcparse/IfcException.h"
|
#include "../ifcparse/IfcException.h"
|
||||||
|
#include "../ifcparse/Argument.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#ifndef IFCLOGGER_H
|
#ifndef IFCLOGGER_H
|
||||||
#define IFCLOGGER_H
|
#define IFCLOGGER_H
|
||||||
|
|
||||||
|
#include "../ifcparse/IfcBaseClass.h"
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -27,12 +29,6 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
#ifdef USE_IFC4
|
|
||||||
#include "../ifcparse/Ifc4.h"
|
|
||||||
#else
|
|
||||||
#include "../ifcparse/Ifc2x3.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
#include "ifc_parse_api.h"
|
#include "ifc_parse_api.h"
|
||||||
|
|||||||
@@ -47,12 +47,6 @@
|
|||||||
#include "../ifcparse/IfcLogger.h"
|
#include "../ifcparse/IfcLogger.h"
|
||||||
#include "../ifcparse/Argument.h"
|
#include "../ifcparse/Argument.h"
|
||||||
|
|
||||||
#ifdef USE_IFC4
|
|
||||||
#include "../ifcparse/Ifc4.h"
|
|
||||||
#else
|
|
||||||
#include "../ifcparse/Ifc2x3.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "../ifcparse/IfcSpfStream.h"
|
#include "../ifcparse/IfcSpfStream.h"
|
||||||
|
|
||||||
namespace IfcParse {
|
namespace IfcParse {
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ IfcParse::schema_definition::schema_definition(const std::string& name, const st
|
|||||||
, factory_(factory)
|
, factory_(factory)
|
||||||
{
|
{
|
||||||
std::sort(declarations_.begin(), declarations_.end(), declaration_by_index_sort());
|
std::sort(declarations_.begin(), declarations_.end(), declaration_by_index_sort());
|
||||||
for (std::vector<const declaration*>::const_iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
for (std::vector<const declaration*>::iterator it = declarations_.begin(); it != declarations_.end(); ++it) {
|
||||||
|
(**it).schema_ = this;
|
||||||
|
|
||||||
if ((**it).as_type_declaration()) type_declarations_.push_back((**it).as_type_declaration());
|
if ((**it).as_type_declaration()) type_declarations_.push_back((**it).as_type_declaration());
|
||||||
if ((**it).as_select_type()) select_types_.push_back((**it).as_select_type());
|
if ((**it).as_select_type()) select_types_.push_back((**it).as_select_type());
|
||||||
if ((**it).as_enumeration_type()) enumeration_types_.push_back((**it).as_enumeration_type());
|
if ((**it).as_enumeration_type()) enumeration_types_.push_back((**it).as_enumeration_type());
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ namespace IfcParse {
|
|||||||
class simple_type;
|
class simple_type;
|
||||||
class aggregation_type;
|
class aggregation_type;
|
||||||
|
|
||||||
|
class schema_definition;
|
||||||
|
|
||||||
class parameter_type {
|
class parameter_type {
|
||||||
public:
|
public:
|
||||||
virtual const named_type* as_named_type() const { return static_cast<named_type*>(0); }
|
virtual const named_type* as_named_type() const { return static_cast<named_type*>(0); }
|
||||||
@@ -118,19 +120,23 @@ namespace IfcParse {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class declaration {
|
class declaration {
|
||||||
|
friend class schema_definition;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::string name_, name_lower_;
|
std::string name_, name_lower_;
|
||||||
int index_in_schema_;
|
int index_in_schema_;
|
||||||
|
mutable const schema_definition* schema_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
declaration(const std::string& name, int index_in_schema)
|
declaration(const std::string& name, int index_in_schema)
|
||||||
: name_(name)
|
: name_(name)
|
||||||
, name_lower_(boost::to_lower_copy(name))
|
, name_lower_(boost::to_lower_copy(name))
|
||||||
, index_in_schema_(index_in_schema)
|
, index_in_schema_(index_in_schema)
|
||||||
|
, schema_(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
std::string name() const { return name_; }
|
const std::string& name() const { return name_; }
|
||||||
std::string name_lc() const { return name_lower_; }
|
const std::string& name_lc() const { return name_lower_; }
|
||||||
|
|
||||||
virtual const type_declaration* as_type_declaration() const { return static_cast<type_declaration*>(0); }
|
virtual const type_declaration* as_type_declaration() const { return static_cast<type_declaration*>(0); }
|
||||||
virtual const select_type* as_select_type() const { return static_cast<select_type*>(0); }
|
virtual const select_type* as_select_type() const { return static_cast<select_type*>(0); }
|
||||||
@@ -143,6 +149,8 @@ namespace IfcParse {
|
|||||||
int index_in_schema() const { return index_in_schema_; }
|
int index_in_schema() const { return index_in_schema_; }
|
||||||
|
|
||||||
int type() const { return index_in_schema_; }
|
int type() const { return index_in_schema_; }
|
||||||
|
|
||||||
|
const schema_definition* schema() const { return schema_; }
|
||||||
};
|
};
|
||||||
|
|
||||||
class type_declaration : public declaration {
|
class type_declaration : public declaration {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
%include "../ifcgeom/IfcGeomElement.h"
|
%include "../ifcgeom/IfcGeomElement.h"
|
||||||
%include "../ifcgeom/IfcGeomMaterial.h"
|
%include "../ifcgeom/IfcGeomMaterial.h"
|
||||||
%include "../ifcgeom/IfcGeomRepresentation.h"
|
%include "../ifcgeom/IfcGeomRepresentation.h"
|
||||||
%include "../ifcgeom/IfcGeomIterator.h"
|
%include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
|
|
||||||
// A Template instantantation should be defined before it is used as a base class.
|
// A Template instantantation should be defined before it is used as a base class.
|
||||||
// But frankly I don't care as most methods are subtlely different anyway.
|
// But frankly I don't care as most methods are subtlely different anyway.
|
||||||
@@ -51,42 +51,42 @@
|
|||||||
|
|
||||||
%extend IfcGeom::tree {
|
%extend IfcGeom::tree {
|
||||||
|
|
||||||
static IfcEntityList::ptr vector_to_list(const std::vector<IfcSchema::IfcProduct*>& ps) const {
|
static IfcEntityList::ptr vector_to_list(const std::vector<IfcUtil::IfcBaseEntity*>& ps) const {
|
||||||
IfcEntityList::ptr r(new IfcEntityList);
|
IfcEntityList::ptr r(new IfcEntityList);
|
||||||
for (std::vector<IfcSchema::IfcProduct*>::const_iterator it = ps.begin(); it != ps.end(); ++it) {
|
for (std::vector<IfcUtil::IfcBaseEntity*>::const_iterator it = ps.begin(); it != ps.end(); ++it) {
|
||||||
r->push(*it);
|
r->push(*it);
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcEntityList::ptr select_box(IfcUtil::IfcBaseClass* e, bool completely_within = false, double extend=-1.e-5) const {
|
IfcEntityList::ptr select_box(IfcUtil::IfcBaseClass* e, bool completely_within = false, double extend=-1.e-5) const {
|
||||||
if (!e->declaration().is(IfcSchema::Type::IfcProduct)) {
|
if (!e->declaration().is("IfcProduct")) {
|
||||||
throw IfcParse::IfcException("Instance should be an IfcProduct");
|
throw IfcParse::IfcException("Instance should be an IfcProduct");
|
||||||
}
|
}
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select_box((IfcSchema::IfcProduct*)e, completely_within, extend);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select_box((IfcUtil::IfcBaseEntity*)e, completely_within, extend);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcEntityList::ptr select_box(const gp_Pnt& p) const {
|
IfcEntityList::ptr select_box(const gp_Pnt& p) const {
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select_box(p);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select_box(p);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcEntityList::ptr select_box(const Bnd_Box& b, bool completely_within = false) const {
|
IfcEntityList::ptr select_box(const Bnd_Box& b, bool completely_within = false) const {
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select_box(b, completely_within);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select_box(b, completely_within);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcEntityList::ptr select(IfcUtil::IfcBaseClass* e, bool completely_within = false) const {
|
IfcEntityList::ptr select(IfcUtil::IfcBaseClass* e, bool completely_within = false) const {
|
||||||
if (!e->declaration().is(IfcSchema::Type::IfcProduct)) {
|
if (!e->declaration().is("IfcProduct")) {
|
||||||
throw IfcParse::IfcException("Instance should be an IfcProduct");
|
throw IfcParse::IfcException("Instance should be an IfcProduct");
|
||||||
}
|
}
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select((IfcSchema::IfcProduct*)e, completely_within);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select((IfcUtil::IfcBaseEntity*)e, completely_within);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcEntityList::ptr select(const gp_Pnt& p) const {
|
IfcEntityList::ptr select(const gp_Pnt& p) const {
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select(p);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select(p);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@
|
|||||||
shapes.Read(stream);
|
shapes.Read(stream);
|
||||||
const TopoDS_Shape& shp = shapes.Shape(shapes.NbShapes());
|
const TopoDS_Shape& shp = shapes.Shape(shapes.NbShapes());
|
||||||
|
|
||||||
std::vector<IfcSchema::IfcProduct*> ps = $self->select(shp);
|
std::vector<IfcUtil::IfcBaseEntity*> ps = $self->select(shp);
|
||||||
return IfcGeom_tree_vector_to_list(ps);
|
return IfcGeom_tree_vector_to_list(ps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,41 +299,36 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
%}
|
%}
|
||||||
};
|
};
|
||||||
|
|
||||||
%inline %{
|
%{
|
||||||
boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
|
template <typename Schema>
|
||||||
|
static boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> helper_fn_create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
|
||||||
IfcParse::IfcFile* file = instance->data().file;
|
IfcParse::IfcFile* file = instance->data().file;
|
||||||
IfcSchema::IfcProject::list::ptr projects = file->entitiesByType<IfcSchema::IfcProject>();
|
|
||||||
if (projects->size() != 1) {
|
|
||||||
throw IfcParse::IfcException("Not a single IfcProject instance");
|
|
||||||
}
|
|
||||||
IfcSchema::IfcProject* project = *projects->begin();
|
|
||||||
|
|
||||||
IfcGeom::Kernel kernel;
|
IfcGeom::Kernel kernel(file);
|
||||||
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.get(IfcGeom::IteratorSettings::SEW_SHELLS) ? 1000 : -1);
|
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.get(IfcGeom::IteratorSettings::SEW_SHELLS) ? 1000 : -1);
|
||||||
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.get(IfcGeom::IteratorSettings::INCLUDE_CURVES) ? (settings.get(IfcGeom::IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES) ? -1. : 0.) : +1.));
|
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.get(IfcGeom::IteratorSettings::INCLUDE_CURVES) ? (settings.get(IfcGeom::IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES) ? -1. : 0.) : +1.));
|
||||||
std::pair<std::string, double> length_unit = kernel.initializeUnits(project->UnitsInContext());
|
|
||||||
|
|
||||||
if (instance->declaration().is(IfcSchema::Type::IfcProduct)) {
|
if (instance->declaration().is(Schema::IfcProduct::Class())) {
|
||||||
if (representation) {
|
if (representation) {
|
||||||
if (!representation->declaration().is(IfcSchema::Type::IfcRepresentation)) {
|
if (!representation->declaration().is(Schema::IfcRepresentation::Class())) {
|
||||||
throw IfcParse::IfcException("Supplied representation not of type IfcRepresentation");
|
throw IfcParse::IfcException("Supplied representation not of type IfcRepresentation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcSchema::IfcProduct* product = (IfcSchema::IfcProduct*) instance;
|
typename Schema::IfcProduct* product = (typename Schema::IfcProduct*) instance;
|
||||||
|
|
||||||
if (!representation && !product->hasRepresentation()) {
|
if (!representation && !product->hasRepresentation()) {
|
||||||
throw IfcParse::IfcException("Representation is NULL");
|
throw IfcParse::IfcException("Representation is NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcSchema::IfcProductRepresentation* prodrep = product->Representation();
|
typename Schema::IfcProductRepresentation* prodrep = product->Representation();
|
||||||
IfcSchema::IfcRepresentation::list::ptr reps = prodrep->Representations();
|
typename Schema::IfcRepresentation::list::ptr reps = prodrep->Representations();
|
||||||
IfcSchema::IfcRepresentation* ifc_representation = (IfcSchema::IfcRepresentation*) representation;
|
typename Schema::IfcRepresentation* ifc_representation = (typename Schema::IfcRepresentation*) representation;
|
||||||
|
|
||||||
if (!ifc_representation) {
|
if (!ifc_representation) {
|
||||||
// First, try to find a representation based on the settings
|
// First, try to find a representation based on the settings
|
||||||
for (IfcSchema::IfcRepresentation::list::it it = reps->begin(); it != reps->end(); ++it) {
|
for (typename Schema::IfcRepresentation::list::it it = reps->begin(); it != reps->end(); ++it) {
|
||||||
IfcSchema::IfcRepresentation* rep = *it;
|
typename Schema::IfcRepresentation* rep = *it;
|
||||||
if (!rep->hasRepresentationIdentifier()) {
|
if (!rep->hasRepresentationIdentifier()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -354,9 +349,9 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
|
|
||||||
// Otherwise, find a representation within the 'Model' or 'Plan' context
|
// Otherwise, find a representation within the 'Model' or 'Plan' context
|
||||||
if (!ifc_representation) {
|
if (!ifc_representation) {
|
||||||
for (IfcSchema::IfcRepresentation::list::it it = reps->begin(); it != reps->end(); ++it) {
|
for (typename Schema::IfcRepresentation::list::it it = reps->begin(); it != reps->end(); ++it) {
|
||||||
IfcSchema::IfcRepresentation* rep = *it;
|
typename Schema::IfcRepresentation* rep = *it;
|
||||||
IfcSchema::IfcRepresentationContext* context = rep->ContextOfItems();
|
typename Schema::IfcRepresentationContext* context = rep->ContextOfItems();
|
||||||
|
|
||||||
// TODO: Remove redundancy with IfcGeomIterator.h
|
// TODO: Remove redundancy with IfcGeomIterator.h
|
||||||
if (context->hasContextType()) {
|
if (context->hasContextType()) {
|
||||||
@@ -391,28 +386,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcSchema::IfcRepresentationContext* ctx = ifc_representation->ContextOfItems();
|
IfcGeom::BRepElement<double>* brep = kernel.convert(settings, ifc_representation, product);
|
||||||
if (!ctx->declaration().is(IfcSchema::Type::IfcGeometricRepresentationContext)) {
|
|
||||||
throw IfcParse::IfcException("Context not of type IfcGeometricRepresentationContext");
|
|
||||||
}
|
|
||||||
IfcSchema::IfcGeometricRepresentationContext* context = (IfcSchema::IfcGeometricRepresentationContext*) ctx;
|
|
||||||
if (context->declaration().is(IfcSchema::Type::IfcGeometricRepresentationSubContext)) {
|
|
||||||
IfcSchema::IfcGeometricRepresentationSubContext* subcontext = (IfcSchema::IfcGeometricRepresentationSubContext*) context;
|
|
||||||
context = subcontext->ParentContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
double precision = 1.e-6;
|
|
||||||
if (context->hasPrecision()) {
|
|
||||||
precision = context->Precision();
|
|
||||||
}
|
|
||||||
precision *= length_unit.second;
|
|
||||||
|
|
||||||
// Some arbitrary factor that has proven to work better for the models in the set of test files.
|
|
||||||
precision *= 10.;
|
|
||||||
|
|
||||||
kernel.setValue(IfcGeom::Kernel::GV_PRECISION, precision);
|
|
||||||
|
|
||||||
IfcGeom::BRepElement<double>* brep = kernel.create_brep_for_representation_and_product<double>(settings, ifc_representation, product);
|
|
||||||
if (!brep) {
|
if (!brep) {
|
||||||
throw IfcParse::IfcException("Failed to process shape");
|
throw IfcParse::IfcException("Failed to process shape");
|
||||||
}
|
}
|
||||||
@@ -429,22 +403,19 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!representation) {
|
if (!representation) {
|
||||||
if (instance->declaration().is(IfcSchema::Type::IfcRepresentationItem) || instance->declaration().is(IfcSchema::Type::IfcRepresentation)) {
|
if (instance->declaration().is(Schema::IfcRepresentationItem::Class()) || instance->declaration().is(Schema::IfcRepresentation::Class())) {
|
||||||
IfcGeom::IfcRepresentationShapeItems shapes;
|
IfcGeom::IfcRepresentationShapeItems shapes = kernel.convert(instance);
|
||||||
if (kernel.convert_shapes(instance, shapes)) {
|
|
||||||
IfcGeom::ElementSettings element_settings(settings, kernel.getValue(IfcGeom::Kernel::GV_LENGTH_UNIT), IfcSchema::Type::ToString(instance->declaration().type()));
|
IfcGeom::ElementSettings element_settings(settings, kernel.getValue(IfcGeom::Kernel::GV_LENGTH_UNIT), instance->declaration().name());
|
||||||
IfcGeom::Representation::BRep brep(element_settings, boost::lexical_cast<std::string>(instance->data().id()), shapes);
|
IfcGeom::Representation::BRep brep(element_settings, boost::lexical_cast<std::string>(instance->data().id()), shapes);
|
||||||
try {
|
try {
|
||||||
if (settings.get(IfcGeom::IteratorSettings::USE_BREP_DATA)) {
|
if (settings.get(IfcGeom::IteratorSettings::USE_BREP_DATA)) {
|
||||||
return new IfcGeom::Representation::Serialization(brep);
|
return new IfcGeom::Representation::Serialization(brep);
|
||||||
} else if (!settings.get(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION)) {
|
} else if (!settings.get(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION)) {
|
||||||
return new IfcGeom::Representation::Triangulation<double>(brep);
|
return new IfcGeom::Representation::Triangulation<double>(brep);
|
||||||
}
|
|
||||||
} catch (...) {
|
|
||||||
throw IfcParse::IfcException("Error during shape serialization");
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (...) {
|
||||||
throw IfcParse::IfcException("Geometrical element not understood");
|
throw IfcParse::IfcException("Error during shape serialization");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -453,7 +424,23 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
}
|
}
|
||||||
return boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*>();
|
return boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*>();
|
||||||
}
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
static boost::variant<IfcGeom::Element<double>*, IfcGeom::Representation::Representation*> create_shape(IfcGeom::IteratorSettings& settings, IfcUtil::IfcBaseClass* instance, IfcUtil::IfcBaseClass* representation = 0) {
|
||||||
|
const std::string& schema_name = instance->declaration().schema()->name();
|
||||||
|
if (schema_name == "IFC2X3") {
|
||||||
|
return helper_fn_create_shape<Ifc2x3>(settings, instance, representation);
|
||||||
|
} else if (schema_name == "IFC4") {
|
||||||
|
return helper_fn_create_shape<Ifc4>(settings, instance, representation);
|
||||||
|
} else {
|
||||||
|
throw IfcParse::IfcException("No geometry support for " + schema_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
|
/*
|
||||||
|
%inline %{
|
||||||
IfcUtil::IfcBaseClass* serialise(const std::string& s, bool advanced=true) {
|
IfcUtil::IfcBaseClass* serialise(const std::string& s, bool advanced=true) {
|
||||||
std::stringstream stream(s);
|
std::stringstream stream(s);
|
||||||
BRepTools_ShapeSet shapes;
|
BRepTools_ShapeSet shapes;
|
||||||
@@ -472,6 +459,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
return IfcGeom::tesselate(shp, d);
|
return IfcGeom::tesselate(shp, d);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
*/
|
||||||
|
|
||||||
namespace IfcGeom {
|
namespace IfcGeom {
|
||||||
%template(iterator_single_precision) Iterator<float>;
|
%template(iterator_single_precision) Iterator<float>;
|
||||||
|
|||||||
@@ -58,12 +58,18 @@ private:
|
|||||||
%rename("add") addEntity;
|
%rename("add") addEntity;
|
||||||
%rename("remove") removeEntity;
|
%rename("remove") removeEntity;
|
||||||
|
|
||||||
|
%{
|
||||||
|
static const std::string& helper_fn_declaration_get_name(const IfcParse::declaration* decl) {
|
||||||
|
return decl->name();
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
|
||||||
%extend IfcParse::IfcFile {
|
%extend IfcParse::IfcFile {
|
||||||
IfcUtil::IfcBaseClass* by_guid(const std::string& guid) {
|
IfcUtil::IfcBaseClass* by_guid(const std::string& guid) {
|
||||||
return $self->entityByGuid(guid);
|
return $self->instance_by_guid(guid);
|
||||||
}
|
}
|
||||||
IfcEntityList::ptr get_inverse(IfcUtil::IfcBaseClass* e) {
|
IfcEntityList::ptr get_inverse(IfcUtil::IfcBaseClass* e) {
|
||||||
return $self->getInverse(e->data().id(), IfcSchema::Type::UNDEFINED, -1);
|
return $self->getInverse(e->data().id(), 0, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const std::string& fn) {
|
void write(const std::string& fn) {
|
||||||
@@ -84,7 +90,7 @@ private:
|
|||||||
const size_t n = std::distance($self->types_begin(), $self->types_end());
|
const size_t n = std::distance($self->types_begin(), $self->types_end());
|
||||||
std::vector<std::string> ts;
|
std::vector<std::string> ts;
|
||||||
ts.reserve(n);
|
ts.reserve(n);
|
||||||
std::transform($self->types_begin(), $self->types_end(), std::back_inserter(ts), IfcSchema::Type::ToString);
|
std::transform($self->types_begin(), $self->types_end(), std::back_inserter(ts), helper_fn_declaration_get_name);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +98,7 @@ private:
|
|||||||
const size_t n = std::distance($self->types_incl_super_begin(), $self->types_incl_super_end());
|
const size_t n = std::distance($self->types_incl_super_begin(), $self->types_incl_super_end());
|
||||||
std::vector<std::string> ts;
|
std::vector<std::string> ts;
|
||||||
ts.reserve(n);
|
ts.reserve(n);
|
||||||
std::transform($self->types_incl_super_begin(), $self->types_incl_super_end(), std::back_inserter(ts), IfcSchema::Type::ToString);
|
std::transform($self->types_incl_super_begin(), $self->types_incl_super_end(), std::back_inserter(ts), helper_fn_declaration_get_name);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +112,7 @@ private:
|
|||||||
%extend IfcUtil::IfcBaseClass {
|
%extend IfcUtil::IfcBaseClass {
|
||||||
|
|
||||||
int get_attribute_category(const std::string& name) const {
|
int get_attribute_category(const std::string& name) const {
|
||||||
if (IfcSchema::Type::IsSimple($self->declaration().type())) {
|
if (!$self->declaration().as_entity()) {
|
||||||
return name == "wrappedValue";
|
return name == "wrappedValue";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +183,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool is_a(const std::string& s) {
|
bool is_a(const std::string& s) {
|
||||||
return self->declaration().is(IfcSchema::Type::FromString(boost::to_upper_copy(s)));
|
return self->declaration().is(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string is_a() const {
|
std::string is_a() const {
|
||||||
@@ -197,7 +203,7 @@ private:
|
|||||||
if ($self == other) {
|
if ($self == other) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (IfcSchema::Type::IsSimple($self->declaration().type()) || IfcSchema::Type::IsSimple(other->declaration().type())) {
|
if (!$self->declaration().as_entity() || !other->declaration().as_entity()) {
|
||||||
/// @todo
|
/// @todo
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@@ -226,7 +232,7 @@ private:
|
|||||||
for (; it != attrs.end(); ++it) {
|
for (; it != attrs.end(); ++it) {
|
||||||
if ((*it)->name() == a) {
|
if ((*it)->name() == a) {
|
||||||
return self->data().getInverse(
|
return self->data().getInverse(
|
||||||
(*it)->entity_reference()->type(),
|
(*it)->entity_reference(),
|
||||||
(*it)->entity_reference()->attribute_index((*it)->attribute_reference()));
|
(*it)->entity_reference()->attribute_index((*it)->attribute_reference()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,7 +292,7 @@ private:
|
|||||||
arg->set(a);
|
arg->set(a);
|
||||||
self->data().setArgument(i, arg);
|
self->data().setArgument(i, arg);
|
||||||
} else if (arg_type == IfcUtil::Argument_ENUMERATION) {
|
} else if (arg_type == IfcUtil::Argument_ENUMERATION) {
|
||||||
const IfcParse::enumeration_type* enum_type = get_schema().declaration_by_name($self->declaration().type())->as_entity()->
|
const IfcParse::enumeration_type* enum_type = $self->declaration().schema()->declaration_by_name($self->declaration().type())->as_entity()->
|
||||||
attribute_by_index(i)->type_of_attribute()->as_named_type()->declared_type()->as_enumeration_type();
|
attribute_by_index(i)->type_of_attribute()->as_named_type()->declared_type()->as_enumeration_type();
|
||||||
|
|
||||||
std::vector<std::string>::const_iterator it = std::find(
|
std::vector<std::string>::const_iterator it = std::find(
|
||||||
@@ -489,48 +495,35 @@ private:
|
|||||||
|
|
||||||
%inline %{
|
%inline %{
|
||||||
IfcParse::IfcFile* open(const std::string& fn) {
|
IfcParse::IfcFile* open(const std::string& fn) {
|
||||||
IfcParse::IfcFile* f = new IfcParse::IfcFile();
|
IfcParse::IfcFile* f = new IfcParse::IfcFile(fn);
|
||||||
f->Init(fn);
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcParse::IfcFile* read(const std::string& data) {
|
IfcParse::IfcFile* read(const std::string& data) {
|
||||||
char* copiedData = new char[data.length()];
|
char* copiedData = new char[data.length()];
|
||||||
memcpy(copiedData, data.c_str(), data.length());
|
memcpy(copiedData, data.c_str(), data.length());
|
||||||
IfcParse::IfcFile* f = new IfcParse::IfcFile();
|
IfcParse::IfcFile* f = new IfcParse::IfcFile((void *)copiedData, data.length());
|
||||||
f->Init((void *)copiedData, data.length());
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
const char* schema_identifier() {
|
|
||||||
return IfcSchema::Identifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* version() {
|
const char* version() {
|
||||||
return IFCOPENSHELL_VERSION;
|
return IFCOPENSHELL_VERSION;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string get_supertype(std::string n) {
|
IfcUtil::IfcBaseClass* new_IfcBaseClass(const std::string& schema_identifier, const std::string& name) {
|
||||||
boost::to_upper(n);
|
const IfcParse::schema_definition* schema = IfcParse::schema_by_name(schema_identifier);
|
||||||
IfcSchema::Type::Enum t = IfcSchema::Type::FromString(n);
|
const IfcParse::declaration* decl = schema->declaration_by_name(name);
|
||||||
if (IfcSchema::Type::Parent(t)) {
|
IfcEntityInstanceData* data = new IfcEntityInstanceData(decl);
|
||||||
return IfcSchema::Type::ToString(*IfcSchema::Type::Parent(t));
|
|
||||||
} else {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IfcUtil::IfcBaseClass* new_IfcBaseClass(const std::string& s) {
|
|
||||||
IfcSchema::Type::Enum ty = IfcSchema::Type::FromString(boost::to_upper_copy(s));
|
|
||||||
IfcEntityInstanceData* data = new IfcEntityInstanceData(ty);
|
|
||||||
|
|
||||||
size_t attr_count = 1;
|
size_t attr_count = 1;
|
||||||
if (get_schema().declaration_by_name(ty)->as_entity()) {
|
if (decl->as_entity()) {
|
||||||
attr_count = get_schema().declaration_by_name(ty)->as_entity()->attribute_count();
|
attr_count = decl->as_entity()->attribute_count();
|
||||||
}
|
}
|
||||||
|
|
||||||
data->setArgument(attr_count - 1, new IfcWrite::IfcWriteArgument());
|
data->setArgument(attr_count - 1, new IfcWrite::IfcWriteArgument());
|
||||||
|
|
||||||
if (get_schema().declaration_by_name(ty)->as_entity()) {
|
if (decl->as_entity()) {
|
||||||
const std::vector<bool>& derived = get_schema().declaration_by_name(ty)->as_entity()->derived();
|
const std::vector<bool>& derived = decl->as_entity()->derived();
|
||||||
std::vector<bool>::const_iterator it = derived.begin();
|
std::vector<bool>::const_iterator it = derived.begin();
|
||||||
|
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
@@ -543,7 +536,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return IfcSchema::SchemaEntity(data);
|
return schema->instantiate(data);
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
%module ifcopenshell_wrapper %{
|
%module ifcopenshell_wrapper %{
|
||||||
#include "../ifcgeom/IfcGeom.h"
|
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
#include "../ifcgeom/IfcGeomIterator.h"
|
|
||||||
#include "../ifcgeom/IfcGeomTree.h"
|
#include "../ifcgeom/IfcGeomTree.h"
|
||||||
|
|
||||||
|
#include "../ifcparse/Ifc2x3.h"
|
||||||
|
#include "../ifcparse/Ifc4.h"
|
||||||
#include "../ifcparse/IfcBaseClass.h"
|
#include "../ifcparse/IfcBaseClass.h"
|
||||||
#include "../ifcparse/IfcFile.h"
|
#include "../ifcparse/IfcFile.h"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user