mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
len(get_inverse) -> get_total_inverses
This commit is contained in:
@@ -58,6 +58,6 @@ def edit_cost_value(
|
||||
value["ValueComponent"],
|
||||
)
|
||||
value = file.create_entity("IfcMeasureWithUnit", value_component, value["UnitComponent"])
|
||||
if old_unit_basis and len(file.get_inverse(old_unit_basis)) == 0:
|
||||
if old_unit_basis and file.get_total_inverses(old_unit_basis) == 0:
|
||||
ifcopenshell.util.element.remove_deep(file, old_unit_basis)
|
||||
setattr(cost_value, name, value)
|
||||
|
||||
@@ -43,7 +43,7 @@ def remove_cost_item_quantity(
|
||||
ifcopenshell.api.cost.remove_cost_item(model,
|
||||
cost_item=item, physical_quantity=quantity)
|
||||
"""
|
||||
if len(file.get_inverse(physical_quantity)) == 1:
|
||||
if file.get_total_inverses(physical_quantity) == 1:
|
||||
file.remove(physical_quantity)
|
||||
return
|
||||
quantities = list(cost_item.CostQuantities or [])
|
||||
|
||||
@@ -45,7 +45,7 @@ def remove_cost_value(
|
||||
|
||||
ifcopenshell.api.cost.remove_cost_value(model, parent=item, cost_value=value)
|
||||
"""
|
||||
if len(file.get_inverse(cost_value)) == 1:
|
||||
if file.get_total_inverses(cost_value) == 1:
|
||||
file.remove(cost_value)
|
||||
# TODO deep purge
|
||||
elif parent.is_a("IfcCostItem"):
|
||||
|
||||
@@ -43,7 +43,7 @@ def remove_georeferencing(file: ifcopenshell.file) -> None:
|
||||
ifcopenshell.api.pset.remove_pset(file, project, file.by_id(pset["id"]))
|
||||
return
|
||||
for projected_crs in file.by_type("IfcProjectedCRS"):
|
||||
if (unit := projected_crs.MapUnit) and len(file.get_inverse(unit)) == 1:
|
||||
if (unit := projected_crs.MapUnit) and file.get_total_inverses(unit) == 1:
|
||||
projected_crs.MapUnit = None
|
||||
ifcopenshell.util.element.remove_deep2(file, unit)
|
||||
file.remove(projected_crs)
|
||||
|
||||
@@ -42,7 +42,7 @@ def remove_grid_axis(file: ifcopenshell.file, axis: ifcopenshell.entity_instance
|
||||
ifcopenshell.api.grid.remove_grid_axis(model, axis=axis_2)
|
||||
"""
|
||||
axis_curve = axis.AxisCurve
|
||||
if len(file.get_inverse(axis_curve)) == 1:
|
||||
if file.get_total_inverses(axis_curve) == 1:
|
||||
ifcopenshell.util.element.remove_deep(file, axis_curve)
|
||||
file.remove(axis_curve)
|
||||
file.remove(axis)
|
||||
|
||||
@@ -117,7 +117,7 @@ class Usecase:
|
||||
for element in rel.RelatedObjects:
|
||||
self.change_profile(element, profile)
|
||||
|
||||
if old_profile and len(self.file.get_inverse(old_profile)) == 0:
|
||||
if old_profile and self.file.get_total_inverses(old_profile) == 0:
|
||||
# TODO: check remove deep
|
||||
self.file.remove(old_profile)
|
||||
|
||||
|
||||
@@ -38,10 +38,10 @@ def remove_organisation(file: ifcopenshell.file, organisation: ifcopenshell.enti
|
||||
ifcopenshell.api.owner.remove_organisation(model, organisation=organisation)
|
||||
"""
|
||||
for role in organisation.Roles or []:
|
||||
if len(file.get_inverse(role)) == 1:
|
||||
if (file.get_total_inverses(role)) == 1:
|
||||
ifcopenshell.api.owner.remove_role(file, role=role)
|
||||
for address in organisation.Addresses or []:
|
||||
if len(file.get_inverse(address)) == 1:
|
||||
if (file.get_total_inverses(address)) == 1:
|
||||
ifcopenshell.api.owner.remove_address(file, address=address)
|
||||
for inverse in file.get_inverse(organisation):
|
||||
if inverse.is_a("IfcOrganizationRelationship"):
|
||||
|
||||
@@ -41,10 +41,10 @@ def remove_person(file: ifcopenshell.file, person: ifcopenshell.entity_instance)
|
||||
"""
|
||||
|
||||
for role in person.Roles or []:
|
||||
if len(file.get_inverse(role)) == 1:
|
||||
if file.get_total_inverses(role) == 1:
|
||||
ifcopenshell.api.owner.remove_role(file, role=role)
|
||||
for address in person.Addresses or []:
|
||||
if len(file.get_inverse(address)) == 1:
|
||||
if file.get_total_inverses(address) == 1:
|
||||
ifcopenshell.api.owner.remove_address(file, address=address)
|
||||
for inverse in file.get_inverse(person):
|
||||
if inverse.is_a("IfcWorkControl"):
|
||||
|
||||
@@ -83,7 +83,7 @@ def assign_lag_time(
|
||||
duration = file.create_entity("IfcDuration", ifcopenshell.util.date.datetime2ifc(lag_value, "IfcDuration"))
|
||||
lag_time = file.create_entity("IfcLagTime", DurationType=duration_type, LagValue=duration)
|
||||
if rel_sequence.is_a("IfcRelSequence"):
|
||||
if rel_sequence.TimeLag and len(file.get_inverse(rel_sequence.TimeLag)) == 1:
|
||||
file.remove(rel_sequence.TimeLag)
|
||||
if (current_lag_time := rel_sequence.TimeLag) and file.get_total_inverses(current_lag_time) == 1:
|
||||
file.remove(current_lag_time)
|
||||
rel_sequence.TimeLag = lag_time
|
||||
return lag_time
|
||||
|
||||
@@ -108,11 +108,11 @@ def assign_recurrence_pattern(
|
||||
recurrence = file.create_entity("IfcRecurrencePattern", recurrence_type)
|
||||
|
||||
if parent.is_a("IfcWorkTime"):
|
||||
if parent.RecurrencePattern and len(file.get_inverse(parent.RecurrencePattern)) == 1:
|
||||
file.remove(parent.RecurrencePattern)
|
||||
if (old_recurrence := parent.RecurrencePattern) and file.get_total_inverses(old_recurrence) == 1:
|
||||
file.remove(old_recurrence)
|
||||
parent.RecurrencePattern = recurrence
|
||||
elif parent.is_a("IfcTaskTimeRecurring"):
|
||||
if (recurrence_old := parent.Recurrence) and len(file.get_inverse(recurrence_old)) == 1:
|
||||
if (recurrence_old := parent.Recurrence) and file.get_total_inverses(recurrence_old) == 1:
|
||||
file.remove(recurrence_old)
|
||||
parent.Recurrence = recurrence
|
||||
return recurrence
|
||||
|
||||
@@ -55,8 +55,8 @@ def unassign_lag_time(file: ifcopenshell.file, rel_sequence: ifcopenshell.entity
|
||||
# What if you didn't?
|
||||
ifcopenshell.api.sequence.unassign_lag_time(model, rel_sequence=sequence)
|
||||
"""
|
||||
if len(file.get_inverse(rel_sequence.TimeLag)) == 1:
|
||||
file.remove(rel_sequence.TimeLag)
|
||||
if file.get_total_inverses((current_lag_time := rel_sequence.TimeLag)) == 1:
|
||||
file.remove(current_lag_time)
|
||||
else:
|
||||
rel_sequence.TimeLag = None
|
||||
ifcopenshell.api.sequence.cascade_schedule(file, task=rel_sequence.RelatedProcess)
|
||||
|
||||
+3
-3
@@ -40,9 +40,9 @@ def edit_structural_connection_cs(
|
||||
structural_item.ConditionCoordinateSystem = ccs
|
||||
|
||||
ccs = structural_item.ConditionCoordinateSystem
|
||||
if ccs.Axis and len(file.get_inverse(ccs.Axis)) == 1:
|
||||
file.remove(ccs.Axis)
|
||||
if (current_axis := ccs.Axis) and file.get_total_inverses(current_axis) == 1:
|
||||
file.remove(current_axis)
|
||||
ccs.Axis = file.create_entity("IfcDirection", ifc_safe_vector_type(axis))
|
||||
if (prev_ref_direction := ccs.RefDirection) and len(file.get_inverse(prev_ref_direction)) == 1:
|
||||
if (prev_ref_direction := ccs.RefDirection) and file.get_total_inverses(prev_ref_direction) == 1:
|
||||
file.remove(prev_ref_direction)
|
||||
ccs.RefDirection = file.create_entity("IfcDirection", ifc_safe_vector_type(ref_direction))
|
||||
|
||||
@@ -31,6 +31,6 @@ def edit_structural_item_axis(
|
||||
Defaults to (0., 0., 1.).
|
||||
:return: None
|
||||
"""
|
||||
if len(file.get_inverse(axis_dir := structural_item.Axis)) == 1:
|
||||
if file.get_total_inverses(axis_dir := structural_item.Axis) == 1:
|
||||
file.remove(axis_dir)
|
||||
structural_item.Axis = file.create_entity("IfcDirection", ifc_safe_vector_type(axis))
|
||||
|
||||
@@ -174,7 +174,7 @@ class Usecase:
|
||||
new_items.append(self.create_styled_item(item_to_reuse))
|
||||
representation.Items = new_items
|
||||
for item in same_style_items:
|
||||
if len(self.file.get_inverse(item)) == 0:
|
||||
if self.file.get_total_inverses(item) == 0:
|
||||
self.file.remove(item)
|
||||
else:
|
||||
representations = list(definition_representation.Representations)
|
||||
|
||||
@@ -45,7 +45,7 @@ def edit_named_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance,
|
||||
for name, value in attributes.items():
|
||||
if name == "Dimensions":
|
||||
dimensions = unit.Dimensions
|
||||
if len(file.get_inverse(dimensions)) > 1:
|
||||
if file.get_total_inverses(dimensions) > 1:
|
||||
unit.Dimensions = file.createIfcDimensionalExponents(*value)
|
||||
else:
|
||||
for i, exponent in enumerate(value):
|
||||
|
||||
@@ -105,7 +105,7 @@ class TestAddBoolean(test.bootstrap.IFC4):
|
||||
assert len(booleans) == 1
|
||||
assert len(rep.Items) == 2
|
||||
|
||||
assert len(self.file.get_inverse(first1)) == 1
|
||||
assert self.file.get_total_inverses(first1) == 1
|
||||
result = list(self.file.get_inverse(first1))[0]
|
||||
assert result.FirstOperand == first1
|
||||
assert result.SecondOperand == second1
|
||||
@@ -114,7 +114,7 @@ class TestAddBoolean(test.bootstrap.IFC4):
|
||||
# Second2 is now used twice. Reusing is OK (albeit confusing), so long as things don't get recursive.
|
||||
assert result2.SecondOperand == second2
|
||||
|
||||
assert len(self.file.get_inverse(first2)) == 1
|
||||
assert self.file.get_total_inverses(first2) == 1
|
||||
result3 = list(self.file.get_inverse(first2))[0]
|
||||
assert result3.FirstOperand == first2
|
||||
assert result3.SecondOperand == second2
|
||||
|
||||
Reference in New Issue
Block a user