mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Populate entity subtypes, get schema info in Python
This commit is contained in:
+102
-10
@@ -136,8 +136,8 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
}
|
||||
|
||||
{
|
||||
const std::vector<const IfcParse::entity::attribute*> attrs = $self->declaration().as_entity()->all_attributes();
|
||||
std::vector<const IfcParse::entity::attribute*>::const_iterator it = attrs.begin();
|
||||
const std::vector<const IfcParse::attribute*> attrs = $self->declaration().as_entity()->all_attributes();
|
||||
std::vector<const IfcParse::attribute*>::const_iterator it = attrs.begin();
|
||||
for (; it != attrs.end(); ++it) {
|
||||
if ((*it)->name() == name) {
|
||||
return 1;
|
||||
@@ -146,8 +146,8 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
}
|
||||
|
||||
{
|
||||
const std::vector<const IfcParse::entity::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
std::vector<const IfcParse::entity::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
const std::vector<const IfcParse::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
std::vector<const IfcParse::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
for (; it != attrs.end(); ++it) {
|
||||
if ((*it)->name() == name) {
|
||||
return 2;
|
||||
@@ -178,12 +178,12 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
return std::vector<std::string>(1, "wrappedValue");
|
||||
}
|
||||
|
||||
const std::vector<const IfcParse::entity::attribute*> attrs = $self->declaration().as_entity()->all_attributes();
|
||||
const std::vector<const IfcParse::attribute*> attrs = $self->declaration().as_entity()->all_attributes();
|
||||
|
||||
std::vector<std::string> attr_names;
|
||||
attr_names.reserve(attrs.size());
|
||||
|
||||
std::vector<const IfcParse::entity::attribute*>::const_iterator it = attrs.begin();
|
||||
std::vector<const IfcParse::attribute*>::const_iterator it = attrs.begin();
|
||||
for (; it != attrs.end(); ++it) {
|
||||
attr_names.push_back((*it)->name());
|
||||
}
|
||||
@@ -196,12 +196,12 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
return std::vector<std::string>(0);
|
||||
}
|
||||
|
||||
const std::vector<const IfcParse::entity::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
const std::vector<const IfcParse::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
|
||||
std::vector<std::string> attr_names;
|
||||
attr_names.reserve(attrs.size());
|
||||
|
||||
std::vector<const IfcParse::entity::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
std::vector<const IfcParse::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
for (; it != attrs.end(); ++it) {
|
||||
attr_names.push_back((*it)->name());
|
||||
}
|
||||
@@ -260,8 +260,8 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
}
|
||||
|
||||
IfcEntityList::ptr get_inverse(const std::string& a) {
|
||||
const std::vector<const IfcParse::entity::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
std::vector<const IfcParse::entity::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
const std::vector<const IfcParse::inverse_attribute*> attrs = $self->declaration().as_entity()->all_inverse_attributes();
|
||||
std::vector<const IfcParse::inverse_attribute*>::const_iterator it = attrs.begin();
|
||||
for (; it != attrs.end(); ++it) {
|
||||
if ((*it)->name() == a) {
|
||||
return self->data().getInverse(
|
||||
@@ -586,6 +586,98 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
||||
}
|
||||
%}
|
||||
|
||||
%extend IfcParse::named_type {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return repr(self.declared_type())
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::simple_type {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<%s>" % self.declared_type()
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::aggregation_type {
|
||||
std::string type_of_aggregation() const {
|
||||
static const char* const aggr_strings = ["array", "bag", "list", "set"];
|
||||
return aggr_strings[(int) type_of_aggregation_];
|
||||
}
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
format_bound = lambda i: "?" if i == -1 else str(i)
|
||||
return "<%s [%s:%s] of %r>" % (
|
||||
self.type_of_aggregation(),
|
||||
format_bound(self.bound1()),
|
||||
format_bound(self.bound2()),
|
||||
self.type_of_element()
|
||||
)
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::type_declaration {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<type %s: %r>" % (self.name(), self.declared_type())
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::select_type {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<select %s: (%s)>" % (self.name(), " | ".join(map(repr, self.select_list())))
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::enumeration_type {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<enumeration %s: (%s)>" % (self.name(), ", ".join(self.enumeration_items()))
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::attribute {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<attribute %s%s: %s>" % (self.name(), "?" if self.optional() else "", self.type_of_attribute())
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::inverse_attribute {
|
||||
std::string type_of_aggregation() const {
|
||||
static const char* const aggr_strings = ["bag", "set", ""];
|
||||
return aggr_strings[(int) type_of_aggregation_];
|
||||
}
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
format_bound = lambda i: "?" if i == -1 else str(i)
|
||||
return "<inverse %s: %s [%s:%s] of %r for %r>" % (
|
||||
self.name(),
|
||||
self.type_of_aggregation(),
|
||||
format_bound(self.bound1()),
|
||||
format_bound(self.bound2()),
|
||||
self.entity_reference(),
|
||||
self.attribute_reference()
|
||||
)
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::entity {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<entity %s>" % (self.name())
|
||||
%}
|
||||
}
|
||||
|
||||
%extend IfcParse::schema_definition {
|
||||
%pythoncode %{
|
||||
def __repr__(self):
|
||||
return "<schema %s>" % (self.name())
|
||||
%}
|
||||
}
|
||||
|
||||
%{
|
||||
static std::stringstream ifcopenshell_log_stream;
|
||||
%}
|
||||
|
||||
@@ -111,7 +111,10 @@
|
||||
PyObject* pythonize(const bool& t) { return PyBool_FromLong(t); }
|
||||
PyObject* pythonize(const double& t) { return PyFloat_FromDouble(t); }
|
||||
PyObject* pythonize(const std::string& t) { return PyUnicode_FromString(t.c_str()); }
|
||||
PyObject* pythonize(const IfcUtil::IfcBaseClass* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcUtil__IfcBaseClass, 0); }
|
||||
PyObject* pythonize(const IfcUtil::IfcBaseClass* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcUtil__IfcBaseClass, 0); }
|
||||
PyObject* pythonize(const IfcParse::attribute* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__attribute, 0); }
|
||||
PyObject* pythonize(const IfcParse::entity* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__entity, 0); }
|
||||
PyObject* pythonize(const IfcParse::declaration* t) { return SWIG_NewPointerObj(SWIG_as_voidptr(t), SWIGTYPE_p_IfcParse__declaration, 0); }
|
||||
// NB: This cannot be temporary as a Python object is constructed from a pointer to the address of this object
|
||||
PyObject* pythonize(const IfcGeom::Material& t) { return SWIG_NewPointerObj(SWIG_as_voidptr(&t), SWIGTYPE_p_IfcGeom__Material, 0); }
|
||||
|
||||
|
||||
@@ -10,6 +10,33 @@
|
||||
$result = SWIG_Python_str_FromChar(IfcUtil::ArgumentTypeToString($1));
|
||||
}
|
||||
|
||||
%typemap(out) IfcParse::declaration* {
|
||||
if ($1->as_entity()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_entity()), SWIGTYPE_p_IfcParse__entity, 0);
|
||||
} else if ($1->as_type_declaration()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_type_declaration()), SWIGTYPE_p_IfcParse__type_declaration, 0);
|
||||
} else if ($1->as_select_type()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_select_type()), SWIGTYPE_p_IfcParse__select_type, 0);
|
||||
} else if ($1->as_enumeration_type()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_enumeration_type()), SWIGTYPE_p_IfcParse__enumeration_type, 0);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) IfcParse::parameter_type* {
|
||||
if ($1->as_named_type()) {
|
||||
$result = SWIG_NewPointerObj(SWIG_as_voidptr($1->as_named_type()), SWIGTYPE_p_IfcParse__named_type, 0);
|
||||
} else if ($1->as_simple_type()) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) IfcParse::simple_type::data_type {
|
||||
static const char* const data_type_strings[] = {"binary", "boolean", "integer", "logical", "number", "real", "string"};
|
||||
$result = SWIG_Python_str_FromChar(data_type_strings[(int)$1]);
|
||||
}
|
||||
|
||||
%typemap(out) std::pair<IfcUtil::ArgumentType, Argument*> {
|
||||
// The SWIG %exception directive does not take care
|
||||
// of our typemap. So the attribute conversion block
|
||||
@@ -106,3 +133,6 @@ CREATE_VECTOR_TYPEMAP_OUT(unsigned int)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(double)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(std::string)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(IfcGeom::Material)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::attribute const *)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::entity const *)
|
||||
CREATE_VECTOR_TYPEMAP_OUT(IfcParse::declaration const *)
|
||||
|
||||
Reference in New Issue
Block a user