mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 15:08:51 +00:00
Fix --traverse --exlucde=<entities|layers> + clean up duplicate code. filter::traverse_match: dynamic_cast instead of static_cast as the decomposing entity is not guaranteed to be IfcProduct
This commit is contained in:
committed by
Thomas Krijnen
parent
9074f25e93
commit
eade74c919
@@ -596,7 +596,7 @@ int main(int argc, char** argv)
|
|||||||
}
|
}
|
||||||
Logger::Status(msg.str());
|
Logger::Status(msg.str());
|
||||||
|
|
||||||
return successful ? 0 : 1;
|
return successful ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_log() {
|
void write_log() {
|
||||||
|
|||||||
+19
-26
@@ -52,10 +52,19 @@ namespace IfcGeom
|
|||||||
/// children of a storey named "Level 20", or children of entities that have no representation, e.g. IfcCurtainWall.
|
/// children of a storey named "Level 20", or children of entities that have no representation, e.g. IfcCurtainWall.
|
||||||
bool traverse;
|
bool traverse;
|
||||||
|
|
||||||
|
bool match(IfcSchema::IfcProduct* prod, const filter_t& pred) const
|
||||||
|
{
|
||||||
|
bool is_match = pred(prod);
|
||||||
|
if (!is_match && traverse) {
|
||||||
|
is_match = traverse_match(prod, pred);
|
||||||
|
}
|
||||||
|
return is_match == include;
|
||||||
|
}
|
||||||
|
|
||||||
static bool traverse_match(IfcSchema::IfcProduct* prod, const filter_t& pred)
|
static bool traverse_match(IfcSchema::IfcProduct* prod, const filter_t& pred)
|
||||||
{
|
{
|
||||||
IfcSchema::IfcProduct* parent, *current = prod;
|
IfcSchema::IfcProduct* parent, *current = prod;
|
||||||
while ((parent = static_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
while ((parent = dynamic_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
||||||
if (pred(parent)) {
|
if (pred(parent)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -84,7 +93,9 @@ namespace IfcGeom
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool match(const std::string &str) const
|
bool match(const std::string &str) const { return match_values(values, str); }
|
||||||
|
|
||||||
|
static bool match_values(const std::set<boost::regex>& values, const std::string &str)
|
||||||
{
|
{
|
||||||
foreach(const boost::regex& r, values) {
|
foreach(const boost::regex& r, values) {
|
||||||
if (boost::regex_match(str, r)) {
|
if (boost::regex_match(str, r)) {
|
||||||
@@ -157,13 +168,8 @@ namespace IfcGeom
|
|||||||
|
|
||||||
bool operator()(IfcSchema::IfcProduct* prod) const
|
bool operator()(IfcSchema::IfcProduct* prod) const
|
||||||
{
|
{
|
||||||
bool is_match = match(prod);
|
// @note bind1st() and mem_fun() deprecated in C++11, use bind() and mem_fn() when migrating to C++11.
|
||||||
if (!is_match && traverse) {
|
return filter::match(prod, std::bind1st(std::mem_fun(&string_arg_filter::match), this));
|
||||||
// @note bind1st() and mem_fun() deprecated in C++11, use bind() and mem_fn() when migrating to C++11.
|
|
||||||
filter_t pred = std::bind1st(std::mem_fun(&string_arg_filter::match), this);
|
|
||||||
is_match = traverse_match(prod, pred);
|
|
||||||
}
|
|
||||||
return is_match == include;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -185,11 +191,7 @@ namespace IfcGeom
|
|||||||
|
|
||||||
bool operator()(IfcSchema::IfcProduct* prod) const
|
bool operator()(IfcSchema::IfcProduct* prod) const
|
||||||
{
|
{
|
||||||
bool is_match = match(prod);
|
return filter::match(prod, std::bind1st(std::mem_fun(&layer_filter::match), this));
|
||||||
if (is_match != include && traverse) {
|
|
||||||
is_match = traverse_match(prod, boost::ref(*this));
|
|
||||||
}
|
|
||||||
return is_match == include;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wildcards_match
|
struct wildcards_match
|
||||||
@@ -197,12 +199,7 @@ namespace IfcGeom
|
|||||||
wildcards_match(const std::set<boost::regex>& patterns) : patterns(patterns) {}
|
wildcards_match(const std::set<boost::regex>& patterns) : patterns(patterns) {}
|
||||||
bool operator()(const layer_map_t::value_type& layer_map_value) const
|
bool operator()(const layer_map_t::value_type& layer_map_value) const
|
||||||
{
|
{
|
||||||
foreach(const boost::regex& r, patterns) {
|
return wildcard_filter::match_values(patterns, layer_map_value.first);
|
||||||
if (boost::regex_match(layer_map_value.first, r)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<boost::regex> patterns;
|
std::set<boost::regex> patterns;
|
||||||
@@ -231,7 +228,7 @@ namespace IfcGeom
|
|||||||
throw IfcParse::IfcException("'" + type + "' does not name a valid IFC entity");
|
throw IfcParse::IfcException("'" + type + "' does not name a valid IFC entity");
|
||||||
}
|
}
|
||||||
values.insert(ty);
|
values.insert(ty);
|
||||||
// TODO: Add child classes so that containment in set can be in O(log n)
|
/// @todo Add child classes so that containment in set can be in O(log n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,11 +245,7 @@ namespace IfcGeom
|
|||||||
|
|
||||||
bool operator()(IfcSchema::IfcProduct* prod) const
|
bool operator()(IfcSchema::IfcProduct* prod) const
|
||||||
{
|
{
|
||||||
bool is_match = match(prod);
|
return filter::match(prod, std::bind1st(std::mem_fun(&entity_filter::match), this));
|
||||||
if (is_match != include && traverse) {
|
|
||||||
is_match = traverse_match(prod, boost::ref(*this));
|
|
||||||
}
|
|
||||||
return is_match == include;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user