mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 17:57:02 +00:00
Handle references to missing instances gracefully
This commit is contained in:
+32
-32
@@ -1381,48 +1381,48 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
|
|||||||
|
|
||||||
delete tokens;
|
delete tokens;
|
||||||
|
|
||||||
|
auto resolve_instance = [this](auto inst, int ref, int refattr) {
|
||||||
|
IfcUtil::IfcBaseClass* ptr;
|
||||||
|
if constexpr (std::is_same_v<decltype(inst), int>) {
|
||||||
|
entity_by_id_t::const_iterator it = byid_.find(inst);
|
||||||
|
if (it == byid_.end()) {
|
||||||
|
Logger::Error("Instance reference #" + std::to_string(inst) + " used by instance #" + std::to_string(ref) + " at attribute index " + std::to_string(refattr) + " not found");
|
||||||
|
ptr = nullptr;
|
||||||
|
} else {
|
||||||
|
ptr = it->second;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ptr = inst;
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
};
|
||||||
|
|
||||||
for (auto& p : references_to_resolve) {
|
for (auto& p : references_to_resolve) {
|
||||||
boost::apply_visitor([this, &p](auto& v) {
|
boost::apply_visitor([this, &resolve_instance, &p](auto& v) {
|
||||||
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, reference_or_simple_type>) {
|
if constexpr (std::is_same_v<std::decay_t<decltype(v)>, reference_or_simple_type>) {
|
||||||
byid_[p.first.name_]->data().storage_.set(p.first.index_, boost::apply_visitor([this](auto inst) {
|
auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, v);
|
||||||
// @todo handle instance not found error
|
if (inst) {
|
||||||
IfcUtil::IfcBaseClass* ptr;
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, inst);
|
||||||
if constexpr (std::is_same_v<decltype(inst), int>) {
|
}
|
||||||
ptr = this->instance_by_id(inst);
|
|
||||||
} else {
|
|
||||||
ptr = inst;
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}, v));
|
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<reference_or_simple_type>>) {
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<reference_or_simple_type>>) {
|
||||||
aggregate_of_instance::ptr instances(new aggregate_of_instance);
|
aggregate_of_instance::ptr instances(new aggregate_of_instance);
|
||||||
instances->reserve(v.size());
|
instances->reserve(v.size());
|
||||||
for (auto& p : v) {
|
for (auto& vi : v) {
|
||||||
instances->push(boost::apply_visitor([this](auto inst) {
|
auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, vi);
|
||||||
IfcUtil::IfcBaseClass* ptr;
|
if (inst) {
|
||||||
if constexpr (std::is_same_v<decltype(inst), int>) {
|
instances->push(inst);
|
||||||
ptr = this->instance_by_id(inst);
|
}
|
||||||
} else {
|
|
||||||
ptr = inst;
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}, p));
|
|
||||||
}
|
}
|
||||||
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
byid_[p.first.name_]->data().storage_.set(p.first.index_, instances);
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<std::vector<reference_or_simple_type>>>) {
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(v)>, std::vector<std::vector<reference_or_simple_type>>>) {
|
||||||
aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance);
|
aggregate_of_aggregate_of_instance::ptr instances(new aggregate_of_aggregate_of_instance);
|
||||||
for (auto& ps : v) {
|
for (auto& vi : v) {
|
||||||
std::vector<IfcUtil::IfcBaseClass*> inner;
|
std::vector<IfcUtil::IfcBaseClass*> inner;
|
||||||
for (auto& p : ps) {
|
for (auto& vii : vi) {
|
||||||
inner.push_back(boost::apply_visitor([this](auto inst) {
|
auto inst = boost::apply_visitor([p, &resolve_instance](auto x) { return resolve_instance(x, p.first.name_, p.first.index_); }, vii);
|
||||||
IfcUtil::IfcBaseClass* ptr;
|
if (inst) {
|
||||||
if constexpr (std::is_same_v<decltype(inst), int>) {
|
inner.push_back(inst);
|
||||||
ptr = this->instance_by_id(inst);
|
}
|
||||||
} else {
|
|
||||||
ptr = inst;
|
|
||||||
}
|
|
||||||
return ptr;
|
|
||||||
}, p));
|
|
||||||
}
|
}
|
||||||
instances->push(inner);
|
instances->push(inner);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user