mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 10:11:46 +00:00
#1674 use id to filter
This commit is contained in:
@@ -230,6 +230,32 @@ namespace IfcGeom {
|
|||||||
description = ss.str();
|
description = ss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct instance_id_filter : public filter {
|
||||||
|
std::set<int> instance_ids_;
|
||||||
|
|
||||||
|
instance_id_filter() {}
|
||||||
|
instance_id_filter(bool include, bool traverse, const std::set<int>& instance_ids)
|
||||||
|
: filter(include, traverse)
|
||||||
|
, instance_ids_(instance_ids) {}
|
||||||
|
|
||||||
|
bool match(IfcUtil::IfcBaseEntity* prod) const {
|
||||||
|
return instance_ids_.find(prod->data().id()) != instance_ids_.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator()(IfcUtil::IfcBaseEntity* prod) const {
|
||||||
|
return filter::match(prod, std::bind(&instance_id_filter::match, this, std::placeholders::_1));
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_description() {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << (traverse ? "traverse " : "") << (include ? "include" : "exclude") << " ids";
|
||||||
|
for (auto& id : instance_ids_) {
|
||||||
|
ss << " " << id;
|
||||||
|
}
|
||||||
|
description = ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -97,10 +97,9 @@ class iterator(ifcopenshell_wrapper.Iterator):
|
|||||||
if not all(inst.is_a("IfcProduct") for inst in include_or_exclude):
|
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")
|
raise ValueError("include and exclude need to be an aggregate of IfcProduct")
|
||||||
|
|
||||||
initializer = ifcopenshell_wrapper.construct_iterator_with_include_exclude_globalid
|
initializer = ifcopenshell_wrapper.construct_iterator_with_include_exclude_id
|
||||||
|
|
||||||
decode_unicode = lambda x: x.encode("ascii") if x.__class__.__name__ == "unicode" else x
|
include_or_exclude = [i.id() for i in include_or_exclude]
|
||||||
include_or_exclude = list(map(decode_unicode, map(operator.attrgetter("GlobalId"), include_or_exclude)))
|
|
||||||
else:
|
else:
|
||||||
initializer = ifcopenshell_wrapper.construct_iterator_with_include_exclude
|
initializer = ifcopenshell_wrapper.construct_iterator_with_include_exclude
|
||||||
|
|
||||||
|
|||||||
@@ -214,10 +214,17 @@ struct ShapeRTTI : public boost::static_visitor<PyObject*>
|
|||||||
af.include = include;
|
af.include = include;
|
||||||
return new IfcGeom::Iterator(settings, file, {af}, num_threads);
|
return new IfcGeom::Iterator(settings, file, {af}, num_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IfcGeom::Iterator* construct_iterator_with_include_exclude_id(IfcGeom::IteratorSettings settings, IfcParse::IfcFile* file, std::vector<int> elems, bool include, int num_threads) {
|
||||||
|
std::set<int> elems_set(elems.begin(), elems.end());
|
||||||
|
IfcGeom::instance_id_filter af(include, false, elems_set);
|
||||||
|
return new IfcGeom::Iterator(settings, file, {af}, num_threads);
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%newobject construct_iterator_with_include_exclude;
|
%newobject construct_iterator_with_include_exclude;
|
||||||
%newobject construct_iterator_with_include_exclude_globalid;
|
%newobject construct_iterator_with_include_exclude_globalid;
|
||||||
|
%newobject construct_iterator_with_include_exclude_id;
|
||||||
|
|
||||||
%extend IfcGeom::Representation::Triangulation {
|
%extend IfcGeom::Representation::Triangulation {
|
||||||
%pythoncode %{
|
%pythoncode %{
|
||||||
|
|||||||
Reference in New Issue
Block a user