mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
cpp changes for latebound schema manipulation from Python
This commit is contained in:
@@ -74,6 +74,18 @@ namespace IfcUtil {
|
||||
}
|
||||
};
|
||||
|
||||
class IFC_PARSE_API IfcLateBoundEntity : public IfcBaseClass {
|
||||
private:
|
||||
const IfcParse::declaration* decl_;
|
||||
|
||||
public:
|
||||
IfcLateBoundEntity(const IfcParse::declaration* decl, IfcEntityInstanceData* data) : IfcBaseClass(data), decl_(decl) {}
|
||||
|
||||
virtual const IfcParse::declaration& declaration() const {
|
||||
return *decl_;
|
||||
}
|
||||
};
|
||||
|
||||
class IFC_PARSE_API IfcBaseEntity : public IfcBaseClass {
|
||||
public:
|
||||
IfcBaseEntity() : IfcBaseClass() {}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "IfcSchema.h"
|
||||
#include "../ifcparse/IfcBaseClass.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
@@ -62,6 +63,19 @@ IfcParse::schema_definition::~schema_definition() {
|
||||
}
|
||||
}
|
||||
|
||||
IfcUtil::IfcBaseClass* IfcParse::schema_definition::instantiate(IfcEntityInstanceData * data) const {
|
||||
if (factory_) {
|
||||
return (*factory_)(data);
|
||||
} else {
|
||||
return new IfcUtil::IfcLateBoundEntity(data->type(), data);
|
||||
}
|
||||
}
|
||||
|
||||
void IfcParse::register_schema(schema_definition* s) {
|
||||
schemas.insert({ s->name(), s });
|
||||
}
|
||||
|
||||
|
||||
#include "../ifcparse/Ifc2x3.h"
|
||||
#include "../ifcparse/Ifc4.h"
|
||||
#include "../ifcparse/Ifc4x1.h"
|
||||
|
||||
@@ -443,10 +443,12 @@ namespace IfcParse {
|
||||
|
||||
const std::string& name() const { return name_; }
|
||||
|
||||
IfcUtil::IfcBaseClass* instantiate(IfcEntityInstanceData* data) const { return (*factory_)(data); }
|
||||
IfcUtil::IfcBaseClass* instantiate(IfcEntityInstanceData* data) const;
|
||||
};
|
||||
|
||||
const schema_definition* schema_by_name(const std::string&);
|
||||
|
||||
void register_schema(schema_definition*);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -115,6 +115,8 @@
|
||||
return SWIGTYPE_p_IfcParse__select_type;
|
||||
} else if (t->as_enumeration_type()) {
|
||||
return SWIGTYPE_p_IfcParse__enumeration_type;
|
||||
} else {
|
||||
throw std::runtime_error("Unexpected declaration type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,96 @@ CREATE_VECTOR_TYPEMAP_IN(int, INTEGER, int)
|
||||
CREATE_VECTOR_TYPEMAP_IN(double, REAL, float)
|
||||
CREATE_VECTOR_TYPEMAP_IN(std::string, STRING, str)
|
||||
|
||||
// @todo use macros.
|
||||
|
||||
%typemap(in) const std::vector<const IfcParse::declaration*>& {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = new std::vector<const IfcParse::declaration*>;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
||||
PyObject* element = PySequence_GetItem($input, i);
|
||||
void *arg = 0;
|
||||
int res = SWIG_ConvertPtr(element, &arg, SWIGTYPE_p_IfcParse__declaration, 0);
|
||||
auto decl = static_cast<const IfcParse::declaration*>(SWIG_IsOK(res) ? arg : 0);
|
||||
if (decl) {
|
||||
$1->push_back(decl);
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected a schema declaration");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected an sequence type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const std::vector<const IfcParse::entity*>& {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = new std::vector<const IfcParse::entity*>;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
||||
PyObject* element = PySequence_GetItem($input, i);
|
||||
void *arg = 0;
|
||||
int res = SWIG_ConvertPtr(element, &arg, SWIGTYPE_p_IfcParse__entity, 0);
|
||||
auto decl = static_cast<const IfcParse::entity*>(SWIG_IsOK(res) ? arg : 0);
|
||||
if (decl) {
|
||||
$1->push_back(decl);
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected a schema entity");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected an sequence type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const std::vector<const IfcParse::attribute*>& {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = new std::vector<const IfcParse::attribute*>;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
||||
PyObject* element = PySequence_GetItem($input, i);
|
||||
void *arg = 0;
|
||||
int res = SWIG_ConvertPtr(element, &arg, SWIGTYPE_p_IfcParse__attribute, 0);
|
||||
auto decl = static_cast<const IfcParse::attribute*>(SWIG_IsOK(res) ? arg : 0);
|
||||
if (decl) {
|
||||
$1->push_back(decl);
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected a schema attribute");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected an sequence type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const std::vector<const IfcParse::inverse_attribute*>& {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = new std::vector<const IfcParse::inverse_attribute*>;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
||||
PyObject* element = PySequence_GetItem($input, i);
|
||||
void *arg = 0;
|
||||
int res = SWIG_ConvertPtr(element, &arg, SWIGTYPE_p_IfcParse__inverse_attribute, 0);
|
||||
auto decl = static_cast<const IfcParse::inverse_attribute*>(SWIG_IsOK(res) ? arg : 0);
|
||||
if (decl) {
|
||||
$1->push_back(decl);
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected a schema inverse attribute");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected an sequence type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const std::vector<bool>& {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = new std::vector<bool>;
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
|
||||
PyObject* element = PySequence_GetItem($input, i);
|
||||
$1->push_back(PyObject_IsTrue(element));
|
||||
}
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "Expected an sequence type");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) IfcEntityList::ptr {
|
||||
if (PySequence_Check($input)) {
|
||||
$1 = IfcEntityList::ptr(new IfcEntityList());
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_simple_type()), SWIGTYPE_p_IfcParse__simple_type, 0);
|
||||
} else if ($1->as_aggregation_type()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_aggregation_type()), SWIGTYPE_p_IfcParse__aggregation_type, 0);
|
||||
} else {
|
||||
throw std::runtime_error("unexpected parameter type");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user