mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 14:56:25 +00:00
Iterator include/exclude of entity_instance in Python
This commit is contained in:
@@ -23,6 +23,7 @@ from __future__ import print_function
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import operator
|
||||||
|
|
||||||
from .. import ifcopenshell_wrapper
|
from .. import ifcopenshell_wrapper
|
||||||
from ..file import file
|
from ..file import file
|
||||||
@@ -86,12 +87,30 @@ class iterator(_iterator):
|
|||||||
# Couldn't get the typemaps properly applied using %extend so we
|
# Couldn't get the typemaps properly applied using %extend so we
|
||||||
# replicate the SWIG-generated __init__ call on the output of a
|
# replicate the SWIG-generated __init__ call on the output of a
|
||||||
# free function.
|
# free function.
|
||||||
# @todo verify this works with SWIG 4
|
# @todo verify this works with SWIG 4
|
||||||
self.this = ifcopenshell_wrapper.\
|
|
||||||
construct_iterator_double_precision_with_include_exclude(
|
include_or_exclude = include if exclude is None else exclude
|
||||||
|
include_or_exclude_type = set(x.__class__.__name__ for x in include_or_exclude)
|
||||||
|
print(include_or_exclude_type)
|
||||||
|
|
||||||
|
if include_or_exclude_type == {"entity_instance"}:
|
||||||
|
if not all(inst.is_a("IfcProduct") for inst in include_or_exclude):
|
||||||
|
raise ValueError("include and exclude need to be an aggregate of IfcProduct")
|
||||||
|
|
||||||
|
initializer = ifcopenshell_wrapper.\
|
||||||
|
construct_iterator_double_precision_with_include_exclude_globalid
|
||||||
|
|
||||||
|
decode_unicode = lambda x: x.encode('ascii') if x.__class__.__name__ == "unicode" else x
|
||||||
|
include_or_exclude = list(map(decode_unicode, map(operator.attrgetter('GlobalId'), include_or_exclude)))
|
||||||
|
else:
|
||||||
|
initializer = ifcopenshell_wrapper.\
|
||||||
|
construct_iterator_double_precision_with_include_exclude
|
||||||
|
|
||||||
|
import pdb; pdb.set_trace()
|
||||||
|
self.this = initializer(
|
||||||
self.settings,
|
self.settings,
|
||||||
file_or_filename,
|
file_or_filename,
|
||||||
include if exclude is None else exclude,
|
include_or_exclude,
|
||||||
include is not None,
|
include is not None,
|
||||||
num_threads)
|
num_threads)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -171,6 +171,16 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
return new IfcGeom::Iterator<T>(settings, file, {ef}, num_threads);
|
return new IfcGeom::Iterator<T>(settings, file, {ef}, num_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
IfcGeom::Iterator<T>* construct_iterator_with_include_exclude_globalid_(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
||||||
|
std::set<std::string> elems_set(elems.begin(), elems.end());
|
||||||
|
IfcGeom::attribute_filter af;
|
||||||
|
af.attribute_name = "GlobalId";
|
||||||
|
af.populate(elems_set);
|
||||||
|
af.include = include;
|
||||||
|
return new IfcGeom::Iterator<T>(settings, file, {af}, num_threads);
|
||||||
|
}
|
||||||
|
|
||||||
IfcGeom::Iterator<float>* construct_iterator_single_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
IfcGeom::Iterator<float>* construct_iterator_single_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
||||||
return construct_iterator_with_include_exclude_<float>(settings, file, elems, include, num_threads);
|
return construct_iterator_with_include_exclude_<float>(settings, file, elems, include, num_threads);
|
||||||
}
|
}
|
||||||
@@ -178,11 +188,21 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
IfcGeom::Iterator<double>* construct_iterator_double_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
IfcGeom::Iterator<double>* construct_iterator_double_precision_with_include_exclude(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
||||||
return construct_iterator_with_include_exclude_<double>(settings, file, elems, include, num_threads);
|
return construct_iterator_with_include_exclude_<double>(settings, file, elems, include, num_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IfcGeom::Iterator<float>* construct_iterator_single_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
||||||
|
return construct_iterator_with_include_exclude_globalid_<float>(settings, file, elems, include, num_threads);
|
||||||
|
}
|
||||||
|
|
||||||
|
IfcGeom::Iterator<double>* construct_iterator_double_precision_with_include_exclude_globalid(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<std::string> elems, bool include, int num_threads) {
|
||||||
|
return construct_iterator_with_include_exclude_globalid_<double>(settings, file, elems, include, num_threads);
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%ignore construct_iterator_with_include_exclude_;
|
%ignore construct_iterator_with_include_exclude_;
|
||||||
%newobject construct_iterator_single_precision_with_include_exclude;
|
%newobject construct_iterator_single_precision_with_include_exclude;
|
||||||
%newobject construct_iterator_double_precision_with_include_exclude;
|
%newobject construct_iterator_double_precision_with_include_exclude;
|
||||||
|
%newobject construct_iterator_single_precision_with_include_exclude_globalid;
|
||||||
|
%newobject construct_iterator_double_precision_with_include_exclude_globalid;
|
||||||
|
|
||||||
%extend IfcGeom::Iterator<float> {
|
%extend IfcGeom::Iterator<float> {
|
||||||
static int mantissa_size() {
|
static int mantissa_size() {
|
||||||
|
|||||||
Reference in New Issue
Block a user