mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix bug where removing a drawing didn't remove its references.
This commit is contained in:
@@ -181,12 +181,18 @@ def duplicate_drawing(ifc, drawing_tool, drawing=None):
|
||||
|
||||
|
||||
def remove_drawing(ifc, drawing_tool, drawing=None):
|
||||
collection = drawing_tool.get_drawing_collection(drawing)
|
||||
group = drawing_tool.get_drawing_group(drawing)
|
||||
if group:
|
||||
drawing_tool.delete_drawing_elements(drawing_tool.get_group_elements(group))
|
||||
ifc.run("group.remove_group", group=group)
|
||||
drawing_tool.delete_collection(collection)
|
||||
collection = drawing_tool.get_drawing_collection(drawing)
|
||||
if collection:
|
||||
drawing_tool.delete_collection(collection)
|
||||
for reference in drawing_tool.get_drawing_references(drawing):
|
||||
reference_obj = ifc.get_object(reference)
|
||||
if reference_obj:
|
||||
drawing_tool.delete_object(reference_obj)
|
||||
ifc.run("root.remove_product", product=reference)
|
||||
ifc.run("root.remove_product", product=drawing)
|
||||
drawing_tool.import_drawings()
|
||||
|
||||
|
||||
@@ -186,6 +186,7 @@ class Drawing:
|
||||
def get_document_uri(cls, document): pass
|
||||
def get_drawing_collection(cls, drawing): pass
|
||||
def get_drawing_group(cls, drawing): pass
|
||||
def get_drawing_references(cls, drawing): pass
|
||||
def get_drawing_target_view(cls, drawing): pass
|
||||
def get_group_elements(cls, group): pass
|
||||
def get_ifc_representation_class(cls, object_type): pass
|
||||
|
||||
@@ -215,6 +215,14 @@ class Drawing(blenderbim.core.tool.Drawing):
|
||||
if rel.is_a("IfcRelAssignsToGroup"):
|
||||
return rel.RelatingGroup
|
||||
|
||||
@classmethod
|
||||
def get_drawing_references(cls, drawing):
|
||||
results = set()
|
||||
for inverse in tool.Ifc.get().get_inverse(drawing):
|
||||
if inverse.is_a("IfcRelAssignsToProduct") and inverse.RelatingProduct == drawing:
|
||||
results.update(inverse.RelatedObjects)
|
||||
return results
|
||||
|
||||
@classmethod
|
||||
def get_drawing_target_view(cls, drawing):
|
||||
return ifcopenshell.util.element.get_psets(drawing)["EPset_Drawing"].get("TargetView", "MODEL_VIEW")
|
||||
|
||||
@@ -269,6 +269,10 @@ class TestRemoveDrawing:
|
||||
drawing.delete_drawing_elements("elements").should_be_called()
|
||||
ifc.run("group.remove_group", group="group").should_be_called()
|
||||
drawing.delete_collection("collection").should_be_called()
|
||||
drawing.get_drawing_references("drawing").should_be_called().will_return(["reference"])
|
||||
ifc.get_object("reference").should_be_called().will_return("reference_obj")
|
||||
drawing.delete_object("reference_obj").should_be_called()
|
||||
ifc.run("root.remove_product", product="reference").should_be_called()
|
||||
ifc.run("root.remove_product", product="drawing").should_be_called()
|
||||
drawing.import_drawings().should_be_called()
|
||||
subject.remove_drawing(ifc, drawing, drawing="drawing")
|
||||
|
||||
Reference in New Issue
Block a user