mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-30 00:23:14 +00:00
Settings rework for plan/model/context and interfacing with python
This commit is contained in:
@@ -114,7 +114,13 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
|
||||
}
|
||||
void set_(const std::string& name, ifcopenshell::geometry::settings::IteratorOutputOptions val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
}
|
||||
void set_(const std::string& name, ifcopenshell::geometry::settings::PiecewiseStepMethod val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
void set_(const std::string& name, ifcopenshell::geometry::settings::OutputDimensionalityTypes val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
void set_(const std::string& name, double val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
@@ -124,6 +130,9 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
|
||||
void set_(const std::string& name, const std::set<int>& val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
void set_(const std::string& name, const std::set<std::string>& val) {
|
||||
return $self->set(name, val);
|
||||
}
|
||||
ifcopenshell::geometry::Settings::value_variant_t get_(const std::string& name) {
|
||||
return $self->get(name);
|
||||
}
|
||||
@@ -244,8 +253,8 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
|
||||
}
|
||||
|
||||
std::vector<clash> clash_intersection_many(const std::vector<IfcUtil::IfcBaseClass*>& set_a, const std::vector<IfcUtil::IfcBaseClass*>& set_b, double tolerance, bool check_all) const {
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
for (auto* e : set_a) {
|
||||
if (!e->declaration().is("IfcProduct")) {
|
||||
throw IfcParse::IfcException("All instances should be of type IfcProduct");
|
||||
@@ -262,8 +271,8 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
|
||||
}
|
||||
|
||||
std::vector<clash> clash_collision_many(const std::vector<IfcUtil::IfcBaseClass*>& set_a, const std::vector<IfcUtil::IfcBaseClass*>& set_b, bool allow_touching) const {
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
for (auto* e : set_a) {
|
||||
if (!e->declaration().is("IfcProduct")) {
|
||||
throw IfcParse::IfcException("All instances should be of type IfcProduct");
|
||||
@@ -280,8 +289,8 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
|
||||
}
|
||||
|
||||
std::vector<clash> clash_clearance_many(const std::vector<IfcUtil::IfcBaseClass*>& set_a, const std::vector<IfcUtil::IfcBaseClass*>& set_b, double clearance, bool check_all) const {
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_a_entities;
|
||||
std::vector<const IfcUtil::IfcBaseEntity*> set_b_entities;
|
||||
for (auto* e : set_a) {
|
||||
if (!e->declaration().is("IfcProduct")) {
|
||||
throw IfcParse::IfcException("All instances should be of type IfcProduct");
|
||||
@@ -597,13 +606,12 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
||||
if (!rep->RepresentationIdentifier()) {
|
||||
continue;
|
||||
}
|
||||
if (settings.get<ifcopenshell::geometry::settings::IncludeSurfaces>().get()) {
|
||||
if (*rep->RepresentationIdentifier() == "Body") {
|
||||
if (settings.get<ifcopenshell::geometry::settings::OutputDimensionality>().get() != ifcopenshell::geometry::settings::CURVES) {
|
||||
if (*rep->RepresentationIdentifier() == "Body" || *rep->RepresentationIdentifier() == "Facetation") {
|
||||
ifc_representation = rep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (settings.get<ifcopenshell::geometry::settings::IncludeCurves>().get()) {
|
||||
} else {
|
||||
if (*rep->RepresentationIdentifier() == "Plan" || *rep->RepresentationIdentifier() == "Axis") {
|
||||
ifc_representation = rep;
|
||||
break;
|
||||
@@ -621,13 +629,12 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
||||
// TODO: Remove redundancy with IfcGeomIterator.h
|
||||
if (context->ContextType()) {
|
||||
std::set<std::string> context_types;
|
||||
if (settings.get<ifcopenshell::geometry::settings::IncludeSurfaces>().get()) {
|
||||
if (settings.get<ifcopenshell::geometry::settings::OutputDimensionality>().get() != ifcopenshell::geometry::settings::CURVES) {
|
||||
context_types.insert("model");
|
||||
context_types.insert("design");
|
||||
context_types.insert("model view");
|
||||
context_types.insert("detail view");
|
||||
}
|
||||
if (settings.get<ifcopenshell::geometry::settings::IncludeCurves>().get()) {
|
||||
} else {
|
||||
context_types.insert("plan");
|
||||
}
|
||||
|
||||
|
||||
@@ -85,18 +85,40 @@
|
||||
return static_cast<IfcUtil::IfcBaseClass*>(SWIG_IsOK(res) ? arg : 0);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> python_sequence_as_vector(PyObject* aggregate) {
|
||||
std::vector<T> result_vector;
|
||||
result_vector.reserve(PySequence_Size(aggregate));
|
||||
template<typename T>
|
||||
void add_to_container(std::vector<T>& container, const T& element) {
|
||||
container.push_back(element);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void add_to_container(std::set<T>& container, const T& element) {
|
||||
container.insert(element);
|
||||
}
|
||||
|
||||
template <typename T, template<typename> typename U>
|
||||
U<T> python_sequence_as_cpp_container(PyObject* aggregate) {
|
||||
U<T> result_vector;
|
||||
if constexpr (std::is_same_v<U<T>, std::vector<T>>) {
|
||||
result_vector.reserve(PySequence_Size(aggregate));
|
||||
}
|
||||
for(Py_ssize_t i = 0; i < PySequence_Size(aggregate); ++i) {
|
||||
PyObject* element = PySequence_GetItem(aggregate, i);
|
||||
T t = cast_pyobject<T>(element);
|
||||
result_vector.push_back(t);
|
||||
add_to_container(result_vector, t);
|
||||
}
|
||||
return result_vector;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector<T> python_sequence_as_vector(PyObject* aggregate) {
|
||||
return python_sequence_as_cpp_container<T, std::vector>(aggregate);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::set<T> python_sequence_as_set(PyObject* aggregate) {
|
||||
return python_sequence_as_cpp_container<T, std::set>(aggregate);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::vector< std::vector<T> > python_sequence_as_vector_of_vector(PyObject* aggregate) {
|
||||
std::vector< std::vector<T> > result_vector;
|
||||
@@ -196,7 +218,10 @@
|
||||
if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::set<int>>) {
|
||||
std::vector<int> vs(t.begin(), t.end());
|
||||
return pythonize_vector(vs);
|
||||
} else {
|
||||
} else if constexpr (std::is_same_v<std::remove_cv_t<std::remove_reference_t<T>>, std::set<std::string>>) {
|
||||
std::vector<std::string> vs(t.begin(), t.end());
|
||||
return pythonize_vector(vs);
|
||||
} else {
|
||||
return pythonize(t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,3 +372,37 @@ CREATE_OPTIONAL_TYPEMAP_IN(std::string, string, str)
|
||||
%typemap(freearg) const std::vector<IfcGeom::OpaqueCoordinate<4>>& {
|
||||
delete $1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
%define CREATE_SET_TYPEMAP_IN(template_type)
|
||||
|
||||
%typemap(in) std::set<template_type> {
|
||||
if (!check_aggregate_of_type($input, get_python_type<template_type>())) {
|
||||
SWIG_exception(SWIG_TypeError, "Invalid");
|
||||
}
|
||||
$1 = python_sequence_as_set<template_type>($input);
|
||||
}
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) std::set<template_type> {
|
||||
$1 = check_aggregate_of_type($input, get_python_type<template_type>()) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_INTEGER) const std::set<template_type>& {
|
||||
$1 = check_aggregate_of_type($input, get_python_type<template_type>()) ? 1 : 0;
|
||||
}
|
||||
%typemap(arginit) const std::set<template_type>& {
|
||||
$1 = new std::set<template_type>();
|
||||
}
|
||||
%typemap(in) const std::set<template_type>& {
|
||||
if (!check_aggregate_of_type($input, get_python_type<template_type>())) {
|
||||
SWIG_exception(SWIG_TypeError, "Invalid");
|
||||
}
|
||||
*$1 = python_sequence_as_set<template_type>($input);
|
||||
}
|
||||
%typemap(freearg) const std::set<template_type>& {
|
||||
delete $1;
|
||||
}
|
||||
%enddef
|
||||
|
||||
CREATE_SET_TYPEMAP_IN(int)
|
||||
CREATE_SET_TYPEMAP_IN(std::string)
|
||||
|
||||
Reference in New Issue
Block a user