mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-09 21:53:40 +00:00
Consistency of get_inverse calls
This commit is contained in:
@@ -806,11 +806,11 @@ class file_mixin:
|
|||||||
if with_attribute_indices and not allow_duplicate:
|
if with_attribute_indices and not allow_duplicate:
|
||||||
raise ValueError("with_attribute_indices requires allow_duplicate to be True")
|
raise ValueError("with_attribute_indices requires allow_duplicate to be True")
|
||||||
|
|
||||||
inverses = self.get_inverse(inst)
|
inverses = self._get_inverse(inst)
|
||||||
|
|
||||||
if allow_duplicate:
|
if allow_duplicate:
|
||||||
if with_attribute_indices:
|
if with_attribute_indices:
|
||||||
idxs = self.get_inverse_indices(inst)
|
idxs = self._get_inverse_indices(inst)
|
||||||
# TODO: include in typing.
|
# TODO: include in typing.
|
||||||
return list(zip(inverses, idxs))
|
return list(zip(inverses, idxs))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2489,22 +2489,24 @@ std::vector<express::Entity> IfcFile::getInverse(int instance_id, const IfcParse
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t IfcFile::getTotalInverses(int instance_id) {
|
size_t IfcFile::getTotalInverses(int instance_id) {
|
||||||
size_t n = 0;
|
std::set<uint32_t> counted_ids;
|
||||||
|
|
||||||
std::visit([&n, instance_id](const auto& x) {
|
std::visit([&counted_ids, instance_id](const auto& x) {
|
||||||
if constexpr (std::is_same_v<std::decay_t<decltype(x)>, std::monostate>) {
|
if constexpr (std::is_same_v<std::decay_t<decltype(x)>, std::monostate>) {
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(x)>, impl::in_memory_file_storage>) {
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(x)>, impl::in_memory_file_storage>) {
|
||||||
auto lower = x.byref_excl_.lower_bound({ instance_id, -1, -1 });
|
auto lower = x.byref_excl_.lower_bound({ instance_id, -1, -1 });
|
||||||
auto upper = x.byref_excl_.upper_bound({ instance_id, std::numeric_limits<short>::max(), std::numeric_limits<short>::max() });
|
auto upper = x.byref_excl_.upper_bound({ instance_id, std::numeric_limits<short>::max(), std::numeric_limits<short>::max() });
|
||||||
for (auto it = lower; it != upper; ++it) {
|
for (auto it = lower; it != upper; ++it) {
|
||||||
n += it->second.size();
|
for (auto& i : it->second) {
|
||||||
|
counted_ids.insert(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if constexpr (std::is_same_v<std::decay_t<decltype(x)>, impl::rocks_db_file_storage>) {
|
} else if constexpr (std::is_same_v<std::decay_t<decltype(x)>, impl::rocks_db_file_storage>) {
|
||||||
// @todo
|
// @todo
|
||||||
}
|
}
|
||||||
}, storage_);
|
}, storage_);
|
||||||
|
|
||||||
return n;
|
return counted_ids.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void IfcFile::setDefaultHeaderValues() {
|
void IfcFile::setDefaultHeaderValues() {
|
||||||
|
|||||||
@@ -199,35 +199,18 @@ private:
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
IfcFile(const std::string& schema = "IFC4") {
|
IfcFile(const std::string& schema) {
|
||||||
auto resolved_schema = schema;
|
return new IfcParse::IfcFile(IfcParse::schema_by_name(schema));
|
||||||
if (resolved_schema == "IFC4X3") {
|
|
||||||
resolved_schema = "IFC4X3_ADD2";
|
|
||||||
}
|
|
||||||
return new IfcParse::IfcFile(IfcParse::schema_by_name(resolved_schema));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IfcFile(const std::vector<int>& schema_version) {
|
std::vector<express::Base> _get_inverse(const express::Base& e) {
|
||||||
static const char* prefixes[] = { "IFC", "X", "_ADD", "_TC" };
|
|
||||||
|
|
||||||
std::string resolved_schema;
|
|
||||||
for (size_t i = 0; i < schema_version.size() && i < 4; ++i) {
|
|
||||||
if (schema_version[i] != 0) {
|
|
||||||
resolved_schema += prefixes[i];
|
|
||||||
resolved_schema += std::to_string(schema_version[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new IfcParse::IfcFile(IfcParse::schema_by_name(resolved_schema));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<express::Base> get_inverse(const express::Base& e) {
|
|
||||||
if (auto e_ = e.as<express::Entity>()) {
|
if (auto e_ = e.as<express::Entity>()) {
|
||||||
return cast_vector<express::Base>($self->getInverse(e_.id(), 0, -1));
|
return cast_vector<express::Base>($self->getInverse(e_.id(), 0, -1));
|
||||||
}
|
}
|
||||||
throw IfcParse::IfcException("Only entities with ids are supported for get_inverse. Provided entity: '" + e.declaration().name() + "'.");
|
throw IfcParse::IfcException("Only entities with ids are supported for get_inverse. Provided entity: '" + e.declaration().name() + "'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> get_inverse_indices(const express::Base& e) {
|
std::vector<int> _get_inverse_indices(const express::Base& e) {
|
||||||
if (auto e_ = e.as<express::Entity>()) {
|
if (auto e_ = e.as<express::Entity>()) {
|
||||||
return $self->get_inverse_indices(e_.id());
|
return $self->get_inverse_indices(e_.id());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user