Move macro logic into template function; mark failures as intended #4915

This commit is contained in:
Thomas Krijnen
2024-07-01 20:34:51 +02:00
parent 0357d15ce4
commit 675e1982ee
6 changed files with 78 additions and 76 deletions
+40
View File
@@ -31,6 +31,46 @@ namespace geometry {
void initialize_units_();
void addRepresentationsFromContextIds(IfcSchema::IfcRepresentation::list::ptr&);
void addRepresentationsFromDefaultContexts(IfcSchema::IfcRepresentation::list::ptr&);
// Set of instances to mark failures that are intended, such as representations not
// resulting in any items due to dimensionality filters.
std::set<const IfcUtil::IfcBaseInterface*> failed_on_purpose_;
template <typename T>
void process_mapping(bool& matched, taxonomy::ptr& item, IfcUtil::IfcBaseInterface const * inst) {
if (!item && inst->as<T>()) {
matched = true;
try {
item = map_impl(inst->as<T>());
if (item != nullptr) {
if (item->instance == nullptr) {
item->instance = inst;
}
try {
if (inst->as<IfcSchema::IfcRepresentationItem>() && !inst->as<IfcSchema::IfcStyledItem>() &&
/* @todo */
(item->kind() == taxonomy::SOLID || item->kind() == taxonomy::SHELL || item->kind() == taxonomy::COLLECTION || item->kind() == taxonomy::EXTRUSION)
) {
auto style = find_style(inst->as<IfcSchema::IfcRepresentationItem>());
if (style) {
auto mstyle = map(style);
if (mstyle) {
taxonomy::cast<taxonomy::geom_item>(item)->surface_style = taxonomy::cast<taxonomy::style>(mstyle);
}
}
}
} catch (const std::exception& e) {
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst);
}
} else if (failed_on_purpose_.find(inst) == failed_on_purpose_.end()) {
Logger::Message(Logger::LOG_ERROR, "Failed to convert:", inst);
}
} catch (const std::exception& e) {
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", inst);
}
}
}
const IfcSchema::IfcStyledItem* find_style(const IfcSchema::IfcRepresentationItem*);
public:
POSTFIX_SCHEMA(mapping)(IfcParse::IfcFile* file, Settings& settings) : abstract_mapping(settings), file_(file), placement_rel_to_type_(0), placement_rel_to_instance_(0) {
initialize_units_();