Rework iterator constructor #7291

This commit is contained in:
Thomas Krijnen
2025-10-26 13:21:06 +01:00
parent b1c44d42e3
commit b10415b1b3
2 changed files with 8 additions and 6 deletions
@@ -22,7 +22,7 @@ import os
import sys
import operator
from .. import ifcopenshell_wrapper
from .. import open, ifcopenshell_wrapper
from ..file import file
from ..entity_instance import entity_instance
@@ -307,10 +307,7 @@ class iterator(ifcopenshell_wrapper.Iterator):
self.file = file
file_or_filename = file_or_filename.wrapped_data
else:
# @todo?
self.file = None
# Makes sure people are able to use python's platform agnostic paths
file_or_filename = os.path.abspath(file_or_filename)
file_or_filename = self.file = open(file_or_filename)
if include is not None and exclude is not None:
raise ValueError("include and exclude cannot be specified simultaneously")
@@ -342,7 +339,7 @@ class iterator(ifcopenshell_wrapper.Iterator):
geometry_library, self.settings, file_or_filename, include_or_exclude, include is not None, num_threads
)
else:
ifcopenshell_wrapper.Iterator.__init__(self, geometry_library, settings, file_or_filename, num_threads)
self.this = ifcopenshell_wrapper.construct_iterator(geometry_library, self.settings, file_or_filename, num_threads)
if has_occ:
+5
View File
@@ -628,6 +628,7 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
$result = boost::apply_visitor(ShapeRTTI(), (boost::variant<IfcGeom::Element*, IfcGeom::Representation::Representation*, IfcGeom::Transformation*>) $1);
}
%newobject construct_iterator;
%newobject construct_iterator_with_include_exclude;
%newobject construct_iterator_with_include_exclude_globalid;
%newobject construct_iterator_with_include_exclude_id;
@@ -635,6 +636,10 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
// I couldn't get the vector<string> typemap to be applied when %extending Iterator constructor.
// anyway it does not matter as SWIG generates C code without actual constructors
%inline %{
IfcGeom::Iterator* construct_iterator(const std::string& geometry_library, ifcopenshell::geometry::Settings settings, IfcParse::IfcFile* file, int num_threads) {
return new IfcGeom::Iterator(ifcopenshell::geometry::kernels::construct(file, geometry_library, settings), settings, file, num_threads);
}
IfcGeom::Iterator* construct_iterator_with_include_exclude(const std::string& geometry_library, ifcopenshell::geometry::Settings 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::entity_filter ef{ include, false, elems_set };