mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Cleaning up geom filters.
This commit is contained in:
committed by
Thomas Krijnen
parent
7101ac22c8
commit
d88c93a150
+132
-122
@@ -53,9 +53,6 @@
|
|||||||
const std::string DEFAULT_EXTENSION = "obj";
|
const std::string DEFAULT_EXTENSION = "obj";
|
||||||
const std::string TEMP_FILE_EXTENSION = ".tmp";
|
const std::string TEMP_FILE_EXTENSION = ".tmp";
|
||||||
|
|
||||||
const std::string NAME_ARG = "Name", GUID_ARG = "GlobalId", DESC_ARG = "Description", TAG_ARG = "Tag";
|
|
||||||
std::vector<std::string> supported_args;
|
|
||||||
|
|
||||||
namespace po = boost::program_options;
|
namespace po = boost::program_options;
|
||||||
|
|
||||||
void print_version()
|
void print_version()
|
||||||
@@ -119,6 +116,17 @@ bool rename_file(const std::string& old_filename, const std::string& new_filenam
|
|||||||
static std::stringstream log_stream;
|
static std::stringstream log_stream;
|
||||||
void write_log();
|
void write_log();
|
||||||
|
|
||||||
|
const std::string NAME_ARG = "Name", GUID_ARG = "GlobalId", DESC_ARG = "Description", TAG_ARG = "Tag";
|
||||||
|
std::vector<std::string> supported_args;
|
||||||
|
IfcGeom::entity_filter entity_filter; // Entity filter is used always by default.
|
||||||
|
IfcGeom::layer_filter layer_filter;
|
||||||
|
IfcGeom::string_arg_filter guid_filter(IfcSchema::Type::IfcRoot, 0); // IfcRoot.GlobalId
|
||||||
|
// Note: skipping IfcRoot OwnerHistory, argument index 1
|
||||||
|
IfcGeom::string_arg_filter name_filter(IfcSchema::Type::IfcRoot, 2); // IfcRoot.Name
|
||||||
|
IfcGeom::string_arg_filter desc_filter(IfcSchema::Type::IfcRoot, 3); // IfcRoot.Description
|
||||||
|
IfcGeom::string_arg_filter::arg_map_t tag_args; // IfcProxy.Tag & IfcElement.Tag
|
||||||
|
std::vector<IfcGeom::filter_t> filters;
|
||||||
|
|
||||||
struct geom_filter
|
struct geom_filter
|
||||||
{
|
{
|
||||||
geom_filter() : type(UNUSED) {}
|
geom_filter() : type(UNUSED) {}
|
||||||
@@ -132,6 +140,8 @@ struct geom_filter
|
|||||||
struct inclusion_filter : public IfcGeom::filter, public geom_filter { inclusion_filter() : filter(true, false) {} };
|
struct inclusion_filter : public IfcGeom::filter, public geom_filter { inclusion_filter() : filter(true, false) {} };
|
||||||
struct exclusion_filter : public IfcGeom::filter, public geom_filter { exclusion_filter() : filter(false, false) {} };
|
struct exclusion_filter : public IfcGeom::filter, public geom_filter { exclusion_filter() : filter(false, false) {} };
|
||||||
|
|
||||||
|
size_t setup_filters(const inclusion_filter&, const exclusion_filter&, const std::string&, bool);
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
po::options_description generic_options("Command line options");
|
po::options_description generic_options("Command line options");
|
||||||
@@ -280,13 +290,12 @@ int main(int argc, char** argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const po::error_with_option_name& e) {
|
} catch (const po::error_with_option_name& e) {
|
||||||
std::cerr << "[Error] Invalid usage of '" << e.get_option_name() << "': " << e.what() << "\n\n";
|
std::cerr << "[Error] Invalid usage of '" << e.get_option_name() << "': " << e.what() << "\n\n";
|
||||||
print_usage();
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "[Error] " << e.what() << "\n\n";
|
std::cerr << "[Error] " << e.what() << "\n\n";
|
||||||
print_usage();
|
print_usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} catch (...) { // other errors such as invalid command line syntax
|
} catch (...) {
|
||||||
print_usage();
|
print_usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
@@ -295,15 +304,15 @@ int main(int argc, char** argv)
|
|||||||
print_version();
|
print_version();
|
||||||
|
|
||||||
if (vmap.count("version")) {
|
if (vmap.count("version")) {
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
} else if (vmap.count("help")) {
|
} else if (vmap.count("help")) {
|
||||||
print_usage(false);
|
print_usage(false);
|
||||||
print_options(generic_options.add(geom_options).add(serializer_options));
|
print_options(generic_options.add(geom_options).add(serializer_options));
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
} else if (!vmap.count("input-file")) {
|
} else if (!vmap.count("input-file")) {
|
||||||
std::cerr << "[Error] Input file not specified" << std::endl;
|
std::cerr << "[Error] Input file not specified" << std::endl;
|
||||||
print_usage();
|
print_usage();
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
const bool verbose = vmap.count("verbose") != 0;
|
const bool verbose = vmap.count("verbose") != 0;
|
||||||
const bool weld_vertices = vmap.count("weld-vertices") != 0;
|
const bool weld_vertices = vmap.count("weld-vertices") != 0;
|
||||||
@@ -350,14 +359,14 @@ int main(int argc, char** argv)
|
|||||||
} else {
|
} else {
|
||||||
std::cerr << "[Error] Invalid use of --bounds" << std::endl;
|
std::cerr << "[Error] Invalid use of --bounds" << std::endl;
|
||||||
print_options(serializer_options);
|
print_options(serializer_options);
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string input_filename = vmap["input-file"].as<std::string>();
|
const std::string input_filename = vmap["input-file"].as<std::string>();
|
||||||
if (!file_exists(input_filename)) {
|
if (!file_exists(input_filename)) {
|
||||||
std::cerr << "[Error] Input file '" << input_filename << "' does not exist" << std::endl;
|
std::cerr << "[Error] Input file '" << input_filename << "' does not exist" << std::endl;
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no output filename is specified a Wavefront OBJ file will be output
|
// If no output filename is specified a Wavefront OBJ file will be output
|
||||||
@@ -369,7 +378,7 @@ int main(int argc, char** argv)
|
|||||||
if (output_filename.size() < 5) {
|
if (output_filename.size() < 5) {
|
||||||
std::cerr << "[Error] Invalid or unsupported output file '" << output_filename << "' given" << std::endl;
|
std::cerr << "[Error] Invalid or unsupported output file '" << output_filename << "' given" << std::endl;
|
||||||
print_usage();
|
print_usage();
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(output_filename) && !vmap.count("yes")) {
|
if (file_exists(output_filename) && !vmap.count("yes")) {
|
||||||
@@ -377,7 +386,7 @@ int main(int argc, char** argv)
|
|||||||
std::cout << "A file '" << output_filename << "' already exists. Overwrite the existing file?" << std::endl;
|
std::cout << "A file '" << output_filename << "' already exists. Overwrite the existing file?" << std::endl;
|
||||||
std::cin >> answer;
|
std::cin >> answer;
|
||||||
if (!boost::iequals(answer, "yes") && !boost::iequals(answer, "y")) {
|
if (!boost::iequals(answer, "yes") && !boost::iequals(answer, "y")) {
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,113 +396,8 @@ int main(int argc, char** argv)
|
|||||||
boost::to_lower(output_extension);
|
boost::to_lower(output_extension);
|
||||||
|
|
||||||
|
|
||||||
// Set up filters. Entity filter is used always by default.
|
if (!setup_filters(include_filter, exclude_filter, output_extension, traverse)) {
|
||||||
std::vector<IfcGeom::filter_t> filters;
|
return EXIT_FAILURE;
|
||||||
/// @todo Clean up this filter initialization code
|
|
||||||
IfcGeom::entity_filter entity_filter;
|
|
||||||
entity_filter.traverse = traverse;
|
|
||||||
try {
|
|
||||||
if (include_filter.type == geom_filter::ENTITY_TYPE) {
|
|
||||||
entity_filter.include = true;
|
|
||||||
entity_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.type == geom_filter::ENTITY_TYPE) {
|
|
||||||
entity_filter.include = false;
|
|
||||||
entity_filter.populate(exclude_filter.values);
|
|
||||||
}
|
|
||||||
// If no entity names are specified these are the defaults to skip from output
|
|
||||||
if (entity_filter.values.empty()) {
|
|
||||||
std::set<std::string> entities;
|
|
||||||
entities.insert("IfcSpace");
|
|
||||||
if (output_extension == ".svg") {
|
|
||||||
entity_filter.include = true;
|
|
||||||
} else {
|
|
||||||
entities.insert("IfcOpeningElement");
|
|
||||||
}
|
|
||||||
entity_filter.populate(entities);
|
|
||||||
|
|
||||||
Logger::Message(Logger::LOG_NOTICE, entity_filter.include ? "Including" : "Excluding" +
|
|
||||||
std::string(" by default entities ") + boost::algorithm::join(entities, ", "));
|
|
||||||
}
|
|
||||||
} catch (const IfcParse::IfcException& e) {
|
|
||||||
std::cout << "[Error] " << e.what() << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if (!entity_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(entity_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
IfcGeom::layer_filter layer_filter;
|
|
||||||
layer_filter.traverse = traverse;
|
|
||||||
if (include_filter.type == geom_filter::LAYER_NAME) {
|
|
||||||
layer_filter.include = true;
|
|
||||||
layer_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.type == geom_filter::LAYER_NAME) {
|
|
||||||
layer_filter.include = false;
|
|
||||||
layer_filter.populate(exclude_filter.values);
|
|
||||||
}
|
|
||||||
if (!layer_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(layer_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// IfcRoot.GlobalId
|
|
||||||
IfcGeom::string_arg_filter guid_filter(IfcSchema::Type::IfcRoot, 0);
|
|
||||||
guid_filter.traverse = traverse;
|
|
||||||
if (include_filter.arg == GUID_ARG) {
|
|
||||||
guid_filter.include = true;
|
|
||||||
guid_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.arg == GUID_ARG) {
|
|
||||||
guid_filter.include = false;
|
|
||||||
guid_filter.populate(include_filter.values);
|
|
||||||
}
|
|
||||||
if (!guid_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(guid_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note: skipping IfcRoot OwnerHistory, argument index 1
|
|
||||||
|
|
||||||
// IfcRoot.Name
|
|
||||||
IfcGeom::string_arg_filter name_filter(IfcSchema::Type::IfcRoot, 2);
|
|
||||||
name_filter.traverse = traverse;
|
|
||||||
if (include_filter.arg == NAME_ARG) {
|
|
||||||
name_filter.include = true;
|
|
||||||
name_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.arg == NAME_ARG) {
|
|
||||||
name_filter.include = false;
|
|
||||||
name_filter.populate(exclude_filter.values);
|
|
||||||
}
|
|
||||||
if (!name_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(name_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// IfcRoot.Description
|
|
||||||
IfcGeom::string_arg_filter desc_filter(IfcSchema::Type::IfcRoot, 3);
|
|
||||||
desc_filter.traverse = traverse;
|
|
||||||
if (include_filter.arg == DESC_ARG) {
|
|
||||||
desc_filter.include = true;
|
|
||||||
desc_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.arg == DESC_ARG) {
|
|
||||||
desc_filter.include = false;
|
|
||||||
desc_filter.populate(exclude_filter.values);
|
|
||||||
}
|
|
||||||
if (!desc_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(desc_filter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// IfcProxy.Tag & IfcElement.Tag
|
|
||||||
IfcGeom::string_arg_filter::arg_map_t tag_args;
|
|
||||||
tag_args[IfcSchema::Type::IfcProxy] = 8;
|
|
||||||
tag_args[IfcSchema::Type::IfcElement] = 7;
|
|
||||||
IfcGeom::string_arg_filter tag_filter(tag_args);
|
|
||||||
tag_filter.traverse = traverse;
|
|
||||||
if (include_filter.arg == TAG_ARG) {
|
|
||||||
tag_filter.include = true;
|
|
||||||
tag_filter.populate(include_filter.values);
|
|
||||||
} else if (exclude_filter.arg == TAG_ARG) {
|
|
||||||
tag_filter.include = false;
|
|
||||||
tag_filter.populate(exclude_filter.values);
|
|
||||||
}
|
|
||||||
if (!tag_filter.values.empty()) {
|
|
||||||
filters.push_back(boost::ref(tag_filter));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///@ todo Logger::Message(Logger::LOG_NOTICE, "Filtering by X, Y and Z.")
|
///@ todo Logger::Message(Logger::LOG_NOTICE, "Filtering by X, Y and Z.")
|
||||||
@@ -568,7 +472,7 @@ int main(int argc, char** argv)
|
|||||||
Logger::Message(Logger::LOG_ERROR, "Unknown output filename extension '" + output_extension + "'");
|
Logger::Message(Logger::LOG_ERROR, "Unknown output filename extension '" + output_extension + "'");
|
||||||
write_log();
|
write_log();
|
||||||
print_usage();
|
print_usage();
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool is_tesselated = serializer->isTesselated(); // isTesselated() doesn't change at run-time
|
const bool is_tesselated = serializer->isTesselated(); // isTesselated() doesn't change at run-time
|
||||||
@@ -588,7 +492,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
if (!serializer->ready()) {
|
if (!serializer->ready()) {
|
||||||
write_log();
|
write_log();
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t start,end;
|
time_t start,end;
|
||||||
@@ -600,7 +504,7 @@ int main(int argc, char** argv)
|
|||||||
/// the file and for a case where we found no entities that satisfy our filtering criteria.
|
/// the file and for a case where we found no entities that satisfy our filtering criteria.
|
||||||
Logger::Message(Logger::LOG_ERROR, "Unable to parse input file '" + input_filename + "' or no geometrical entities found");
|
Logger::Message(Logger::LOG_ERROR, "Unable to parse input file '" + input_filename + "' or no geometrical entities found");
|
||||||
write_log();
|
write_log();
|
||||||
return 1;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
serializer->setFile(context_iterator.getFile());
|
serializer->setFile(context_iterator.getFile());
|
||||||
@@ -743,3 +647,109 @@ void validate(boost::any& v, const std::vector<std::string>& values, exclusion_f
|
|||||||
parse_filter(filter, values);
|
parse_filter(filter, values);
|
||||||
v = filter;
|
v = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @todo Clean up this filter initialization code
|
||||||
|
/// @return The number of set up filters, if less than 1, an error occurred.
|
||||||
|
size_t setup_filters(
|
||||||
|
const inclusion_filter& include_filter,
|
||||||
|
const exclusion_filter& exclude_filter,
|
||||||
|
const std::string &output_extension,
|
||||||
|
bool traverse)
|
||||||
|
{
|
||||||
|
entity_filter.traverse = traverse;
|
||||||
|
try {
|
||||||
|
if (include_filter.type == geom_filter::ENTITY_TYPE) {
|
||||||
|
entity_filter.include = true;
|
||||||
|
entity_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.type == geom_filter::ENTITY_TYPE) {
|
||||||
|
entity_filter.include = false;
|
||||||
|
entity_filter.populate(exclude_filter.values);
|
||||||
|
}
|
||||||
|
// If no entity names are specified these are the defaults to skip from output
|
||||||
|
if (entity_filter.values.empty()) {
|
||||||
|
std::set<std::string> entities;
|
||||||
|
entities.insert("IfcSpace");
|
||||||
|
if (output_extension == ".svg") {
|
||||||
|
entity_filter.include = true;
|
||||||
|
} else {
|
||||||
|
entities.insert("IfcOpeningElement");
|
||||||
|
}
|
||||||
|
entity_filter.populate(entities);
|
||||||
|
|
||||||
|
Logger::Message(Logger::LOG_NOTICE, entity_filter.include ? "Including" : "Excluding" +
|
||||||
|
std::string(" by default entities ") + boost::algorithm::join(entities, ", "));
|
||||||
|
}
|
||||||
|
} catch (const IfcParse::IfcException& e) {
|
||||||
|
std::cout << "[Error] " << e.what() << std::endl;
|
||||||
|
return filters.size();
|
||||||
|
}
|
||||||
|
if (!entity_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(entity_filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
layer_filter.traverse = traverse;
|
||||||
|
if (include_filter.type == geom_filter::LAYER_NAME) {
|
||||||
|
layer_filter.include = true;
|
||||||
|
layer_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.type == geom_filter::LAYER_NAME) {
|
||||||
|
layer_filter.include = false;
|
||||||
|
layer_filter.populate(exclude_filter.values);
|
||||||
|
}
|
||||||
|
if (!layer_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(layer_filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
guid_filter.traverse = traverse;
|
||||||
|
if (include_filter.arg == GUID_ARG) {
|
||||||
|
guid_filter.include = true;
|
||||||
|
guid_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.arg == GUID_ARG) {
|
||||||
|
guid_filter.include = false;
|
||||||
|
guid_filter.populate(include_filter.values);
|
||||||
|
}
|
||||||
|
if (!guid_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(guid_filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
name_filter.traverse = traverse;
|
||||||
|
if (include_filter.arg == NAME_ARG) {
|
||||||
|
name_filter.include = true;
|
||||||
|
name_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.arg == NAME_ARG) {
|
||||||
|
name_filter.include = false;
|
||||||
|
name_filter.populate(exclude_filter.values);
|
||||||
|
}
|
||||||
|
if (!name_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(name_filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
desc_filter.traverse = traverse;
|
||||||
|
if (include_filter.arg == DESC_ARG) {
|
||||||
|
desc_filter.include = true;
|
||||||
|
desc_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.arg == DESC_ARG) {
|
||||||
|
desc_filter.include = false;
|
||||||
|
desc_filter.populate(exclude_filter.values);
|
||||||
|
}
|
||||||
|
if (!desc_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(desc_filter));
|
||||||
|
}
|
||||||
|
|
||||||
|
tag_args[IfcSchema::Type::IfcProxy] = 8;
|
||||||
|
tag_args[IfcSchema::Type::IfcElement] = 7;
|
||||||
|
IfcGeom::string_arg_filter tag_filter(tag_args);
|
||||||
|
tag_filter.traverse = traverse;
|
||||||
|
if (include_filter.arg == TAG_ARG) {
|
||||||
|
tag_filter.include = true;
|
||||||
|
tag_filter.populate(include_filter.values);
|
||||||
|
} else if (exclude_filter.arg == TAG_ARG) {
|
||||||
|
tag_filter.include = false;
|
||||||
|
tag_filter.populate(exclude_filter.values);
|
||||||
|
}
|
||||||
|
if (!tag_filter.values.empty()) {
|
||||||
|
filters.push_back(boost::ref(tag_filter));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return filters.size();
|
||||||
|
}
|
||||||
|
|||||||
+57
-54
@@ -24,6 +24,9 @@
|
|||||||
#define IFCGEOMFILTER_H
|
#define IFCGEOMFILTER_H
|
||||||
|
|
||||||
#include "IfcGeom.h"
|
#include "IfcGeom.h"
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#include "../ifcparse/IfcWritableEntity.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
#include <boost/regex.hpp>
|
#include <boost/regex.hpp>
|
||||||
@@ -44,18 +47,17 @@ 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;
|
||||||
|
|
||||||
//static bool traverse_match(IfcSchema::IfcProduct* prod, filter_t pred)
|
static bool traverse_match(IfcSchema::IfcProduct* prod, const filter_t& pred)
|
||||||
//{
|
{
|
||||||
// bool is_match = false;
|
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 = static_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
if (pred(parent)) {
|
||||||
// if (pred(parent)) {
|
return true;
|
||||||
// is_match = true;
|
}
|
||||||
// break;
|
current = parent;
|
||||||
// }
|
}
|
||||||
// current = parent;
|
return false;
|
||||||
// }
|
}
|
||||||
//}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wildcard_filter : public filter
|
struct wildcard_filter : public filter
|
||||||
@@ -109,8 +111,21 @@ namespace IfcGeom
|
|||||||
arg_map_t args;
|
arg_map_t args;
|
||||||
|
|
||||||
/// @todo Take only attribute name when IfcBaseClass and IfcLateBoundEntity are merged.
|
/// @todo Take only attribute name when IfcBaseClass and IfcLateBoundEntity are merged.
|
||||||
string_arg_filter(arg_map_t args) : args(args) {}
|
string_arg_filter(arg_map_t args) : args(args) { assert_arguments(); }
|
||||||
string_arg_filter(IfcSchema::Type::Enum type, unsigned short index) { args[type] = index; }
|
string_arg_filter(IfcSchema::Type::Enum type, unsigned short index) { args[type] = index; assert_arguments(); }
|
||||||
|
|
||||||
|
/// @todo this won't be needed when we have the generic argument name access
|
||||||
|
void assert_arguments()
|
||||||
|
{
|
||||||
|
#ifndef NDEBUG
|
||||||
|
for (arg_map_t::const_iterator it = args.begin(); it != args.end(); ++it) {
|
||||||
|
IfcWrite::IfcWritableEntity dummy(it->first);
|
||||||
|
IfcUtil::IfcBaseClass* base = IfcSchema::SchemaEntity(&dummy);
|
||||||
|
assert(it->second < base->getArgumentCount() && "Invalid argument index");
|
||||||
|
delete base;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
std::string value(IfcSchema::IfcProduct* prod) const
|
std::string value(IfcSchema::IfcProduct* prod) const
|
||||||
{
|
{
|
||||||
@@ -129,14 +144,7 @@ namespace IfcGeom
|
|||||||
{
|
{
|
||||||
bool is_match = match(value(prod));
|
bool is_match = match(value(prod));
|
||||||
if (is_match != include && traverse) {
|
if (is_match != include && traverse) {
|
||||||
IfcSchema::IfcProduct* parent, *current = prod;
|
is_match = traverse_match(prod, boost::ref(*this));
|
||||||
while ((parent = static_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
|
||||||
if (match(value(parent))) {
|
|
||||||
is_match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = parent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return is_match == include;
|
return is_match == include;
|
||||||
}
|
}
|
||||||
@@ -144,42 +152,44 @@ namespace IfcGeom
|
|||||||
|
|
||||||
struct layer_filter : public wildcard_filter
|
struct layer_filter : public wildcard_filter
|
||||||
{
|
{
|
||||||
|
typedef std::map<std::string, IfcSchema::IfcPresentationLayerAssignment*> layer_map_t;
|
||||||
|
|
||||||
layer_filter() {}
|
layer_filter() {}
|
||||||
layer_filter(bool include, bool traverse, const std::set<std::string>& patterns)
|
layer_filter(bool include, bool traverse, const std::set<std::string>& patterns)
|
||||||
: wildcard_filter(include, traverse, patterns)
|
: wildcard_filter(include, traverse, patterns)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool match(IfcSchema::IfcProduct* prod) const
|
||||||
|
{
|
||||||
|
layer_map_t layers = IfcGeom::Kernel::get_layers(prod);
|
||||||
|
return std::find_if(layers.begin(), layers.end(), wildcards_match(values)) != layers.end();
|
||||||
|
}
|
||||||
|
|
||||||
bool operator()(IfcSchema::IfcProduct* prod) const
|
bool operator()(IfcSchema::IfcProduct* prod) const
|
||||||
{
|
{
|
||||||
bool is_match = false;
|
bool is_match = match(prod);
|
||||||
std::map<std::string, IfcSchema::IfcPresentationLayerAssignment*> layers = IfcGeom::Kernel::get_layers(prod);
|
|
||||||
std::map<std::string, IfcSchema::IfcPresentationLayerAssignment*>::const_iterator lit;
|
|
||||||
for (lit = layers.begin(); lit != layers.end(); ++lit) {
|
|
||||||
if (match(lit->first)) {
|
|
||||||
is_match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_match != include && traverse) {
|
if (is_match != include && traverse) {
|
||||||
for (lit = layers.begin(); lit != layers.end(); ++lit) {
|
is_match = traverse_match(prod, boost::ref(*this));
|
||||||
IfcSchema::IfcProduct* parent, *current = prod;
|
|
||||||
while ((parent = static_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
|
||||||
if (match(lit->first)) {
|
|
||||||
is_match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = parent;
|
|
||||||
}
|
|
||||||
if (is_match) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return is_match == include;
|
return is_match == include;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wildcards_match
|
||||||
|
{
|
||||||
|
wildcards_match(const std::set<boost::regex>& patterns) : patterns(patterns) {}
|
||||||
|
bool operator()(const layer_map_t::value_type& layer_map_value) const
|
||||||
|
{
|
||||||
|
foreach(const boost::regex& r, patterns) {
|
||||||
|
if (boost::regex_match(layer_map_value.first, r)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<boost::regex> patterns;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct entity_filter : public filter
|
struct entity_filter : public filter
|
||||||
@@ -223,14 +233,7 @@ namespace IfcGeom
|
|||||||
{
|
{
|
||||||
bool is_match = match(prod);
|
bool is_match = match(prod);
|
||||||
if (is_match != include && traverse) {
|
if (is_match != include && traverse) {
|
||||||
IfcSchema::IfcProduct* parent, *current = prod;
|
is_match = traverse_match(prod, boost::ref(*this));
|
||||||
while ((parent = static_cast<IfcSchema::IfcProduct*>(IfcGeom::Kernel::get_decomposing_entity(current))) != 0) {
|
|
||||||
if (match(parent)) {
|
|
||||||
is_match = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
current = parent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return is_match == include;
|
return is_match == include;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user