fix error purging unused types in 75f8e75

This commit is contained in:
Andrej730
2024-07-30 19:08:52 +05:00
parent 51463ab674
commit de0374bdbd
6 changed files with 18 additions and 24 deletions
@@ -567,5 +567,5 @@ class PurgeUnusedTypes(bpy.types.Operator, tool.Ifc.Operator):
bl_options = {"REGISTER", "UNDO"}
def _execute(self, context):
purged_types = core.purge_unused_types(tool.Ifc, tool.Type)
purged_types = core.purge_unused_types(tool.Ifc, tool.Type, tool.Geometry)
self.report({"INFO"}, f"{purged_types} types were purged.")
+1 -1
View File
@@ -380,6 +380,7 @@ class Geometry:
def clear_modifiers(cls, obj): pass
def clear_scale(cls, obj): pass
def delete_data(cls, data): pass
def delete_ifc_object(cls, obj): pass
def does_representation_id_exist(cls, representation_id): pass
def duplicate_object_data(cls, obj): pass
def get_cartesian_point_coordinate_offset(cls, obj): pass
@@ -1007,7 +1008,6 @@ class Type:
def get_representation_context(cls, representation): pass
def get_type_occurrences(cls, element_type): pass
def has_material_usage(cls, element): pass
def remove_object(cls, obj): pass
def run_geometry_add_representation(cls, obj=None, context=None, ifc_representation_class=None, profile_set_usage=None): pass
def run_geometry_switch_representation(cls, obj=None, representation=None, should_reload=None, is_global=None): pass
+5 -5
View File
@@ -40,15 +40,15 @@ def assign_type(
type_tool.disable_editing(obj)
def purge_unused_types(ifc: tool.Ifc, type: tool.Type) -> int:
def purge_unused_types(ifc: tool.Ifc, type: tool.Type, geometry: tool.Geometry) -> int:
"""Remove all types without occurrences, return an amount of the removed types."""
purged_types = 0
for element_type in type.get_model_types():
if not type.get_type_occurrences(element_type):
obj = ifc.get_object(element_type)
ifc.run("root.remove_product", product=element_type)
purged_types += 1
if obj:
ifc.unlink(element=element_type)
type.remove_object(obj)
geometry.delete_ifc_object(obj)
else:
ifc.run("root.remove_product", product=element_type)
purged_types += 1
return purged_types
-4
View File
@@ -99,10 +99,6 @@ class Type(blenderbim.core.tool.Type):
return "Usage" in material.is_a()
return False
@classmethod
def remove_object(cls, obj: bpy.types.Object) -> None:
bpy.data.objects.remove(obj)
@classmethod
def run_geometry_add_representation(
cls,
+11 -6
View File
@@ -17,7 +17,7 @@
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import blenderbim.core.type as subject
from test.core.bootstrap import ifc, type
from test.core.bootstrap import ifc, type, geometry
class TestAssignType:
@@ -42,11 +42,16 @@ class TestAssignType:
class TestPurgeUnusedTypes:
def test_run(self, ifc, type):
def test_purge_types_obj_found(self, ifc, type, geometry):
type.get_model_types().should_be_called().will_return(["element_type"])
type.get_type_occurrences("element_type").should_be_called().will_return([])
ifc.run("root.remove_product", product="element_type").should_be_called()
ifc.get_object("element_type").should_be_called().will_return("obj")
ifc.unlink(element="element_type").should_be_called()
type.remove_object("obj").should_be_called()
subject.purge_unused_types(ifc, type)
geometry.delete_ifc_object("obj").should_be_called()
subject.purge_unused_types(ifc, type, geometry)
def test_purge_types_obj_not_found(self, ifc, type, geometry):
type.get_model_types().should_be_called().will_return(["element_type"])
type.get_type_occurrences("element_type").should_be_called().will_return([])
ifc.get_object("element_type").should_be_called().will_return(None)
ifc.run("root.remove_product", product="element_type").should_be_called()
subject.purge_unused_types(ifc, type, geometry)
-7
View File
@@ -168,13 +168,6 @@ class TestHasMaterialUsage(NewFile):
assert subject.has_material_usage(element) is True
class TestRemoveObject(NewFile):
def test_run(self):
obj = bpy.data.objects.new("Object", None)
subject.remove_object(obj)
assert not bpy.data.objects.get("Object")
class TestRunGeometryAddRepresentation(NewFile):
def test_nothing(self):
pass