mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Experimental get_inverse_cardinality proposal. See #1904.
This commit is contained in:
committed by
Thomas Krijnen
parent
d1caa3242f
commit
cef1c86f6d
@@ -391,6 +391,16 @@ class file(object):
|
|||||||
return inverses
|
return inverses
|
||||||
return set(inverses)
|
return set(inverses)
|
||||||
|
|
||||||
|
def get_inverse_cardinality(self, inst):
|
||||||
|
"""Returns the number of entities that reference this entity
|
||||||
|
|
||||||
|
:param inst: The entity instance to get inverse relationships
|
||||||
|
:type inst: ifcopenshell.entity_instance.entity_instance
|
||||||
|
:returns: 0 if no references, 1 if one reference, or 2 if more than one reference
|
||||||
|
:rtype: int
|
||||||
|
"""
|
||||||
|
return self.wrapped_data.get_inverse_cardinality(inst.wrapped_data)
|
||||||
|
|
||||||
def remove(self, inst):
|
def remove(self, inst):
|
||||||
"""Deletes an IFC object in the file.
|
"""Deletes an IFC object in the file.
|
||||||
|
|
||||||
|
|||||||
@@ -249,6 +249,7 @@ public:
|
|||||||
aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level=-1);
|
aggregate_of_instance::ptr traverse_breadth_first(IfcUtil::IfcBaseClass* instance, int max_level=-1);
|
||||||
|
|
||||||
aggregate_of_instance::ptr getInverse(int instance_id, const IfcParse::declaration* type, int attribute_index);
|
aggregate_of_instance::ptr getInverse(int instance_id, const IfcParse::declaration* type, int attribute_index);
|
||||||
|
int getInverseCardinality(int instance_id);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
typename T::list::ptr getInverse(int instance_id, int attribute_index) {
|
typename T::list::ptr getInverse(int instance_id, int attribute_index) {
|
||||||
|
|||||||
@@ -2387,6 +2387,25 @@ aggregate_of_instance::ptr IfcFile::getInverse(int instance_id, const IfcParse::
|
|||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int IfcFile::getInverseCardinality(int instance_id) {
|
||||||
|
auto lower = byref_excl.lower_bound({ instance_id,-1,-1 });
|
||||||
|
auto upper = byref_excl.upper_bound({ instance_id, std::numeric_limits<int>::max(), std::numeric_limits<int>::max() });
|
||||||
|
|
||||||
|
int total_references = 0;
|
||||||
|
for (auto it = lower; it != upper; it++) {
|
||||||
|
for (auto& i : it->second) {
|
||||||
|
total_references++;
|
||||||
|
if (total_references > 1) {
|
||||||
|
return total_references;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total_references;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void IfcFile::setDefaultHeaderValues() {
|
void IfcFile::setDefaultHeaderValues() {
|
||||||
const std::string empty_string = "";
|
const std::string empty_string = "";
|
||||||
std::vector<std::string> file_description, schema_identifiers, empty_vector;
|
std::vector<std::string> file_description, schema_identifiers, empty_vector;
|
||||||
|
|||||||
@@ -88,6 +88,9 @@ static IfcUtil::ArgumentType helper_fn_attribute_type(const IfcUtil::IfcBaseClas
|
|||||||
aggregate_of_instance::ptr get_inverse(IfcUtil::IfcBaseClass* e) {
|
aggregate_of_instance::ptr get_inverse(IfcUtil::IfcBaseClass* e) {
|
||||||
return $self->getInverse(e->data().id(), 0, -1);
|
return $self->getInverse(e->data().id(), 0, -1);
|
||||||
}
|
}
|
||||||
|
int get_inverse_cardinality(IfcUtil::IfcBaseClass* e) {
|
||||||
|
return $self->getInverseCardinality(e->data().id());
|
||||||
|
}
|
||||||
|
|
||||||
void write(const std::string& fn) {
|
void write(const std::string& fn) {
|
||||||
std::ofstream f(IfcUtil::path::from_utf8(fn).c_str());
|
std::ofstream f(IfcUtil::path::from_utf8(fn).c_str());
|
||||||
|
|||||||
Reference in New Issue
Block a user