mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
fix error purging unused types in 75f8e75
This commit is contained in:
@@ -567,5 +567,5 @@ class PurgeUnusedTypes(bpy.types.Operator, tool.Ifc.Operator):
|
|||||||
bl_options = {"REGISTER", "UNDO"}
|
bl_options = {"REGISTER", "UNDO"}
|
||||||
|
|
||||||
def _execute(self, context):
|
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.")
|
self.report({"INFO"}, f"{purged_types} types were purged.")
|
||||||
|
|||||||
@@ -380,6 +380,7 @@ class Geometry:
|
|||||||
def clear_modifiers(cls, obj): pass
|
def clear_modifiers(cls, obj): pass
|
||||||
def clear_scale(cls, obj): pass
|
def clear_scale(cls, obj): pass
|
||||||
def delete_data(cls, data): pass
|
def delete_data(cls, data): pass
|
||||||
|
def delete_ifc_object(cls, obj): pass
|
||||||
def does_representation_id_exist(cls, representation_id): pass
|
def does_representation_id_exist(cls, representation_id): pass
|
||||||
def duplicate_object_data(cls, obj): pass
|
def duplicate_object_data(cls, obj): pass
|
||||||
def get_cartesian_point_coordinate_offset(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_representation_context(cls, representation): pass
|
||||||
def get_type_occurrences(cls, element_type): pass
|
def get_type_occurrences(cls, element_type): pass
|
||||||
def has_material_usage(cls, element): 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_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
|
def run_geometry_switch_representation(cls, obj=None, representation=None, should_reload=None, is_global=None): pass
|
||||||
|
|
||||||
|
|||||||
@@ -40,15 +40,15 @@ def assign_type(
|
|||||||
type_tool.disable_editing(obj)
|
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."""
|
"""Remove all types without occurrences, return an amount of the removed types."""
|
||||||
purged_types = 0
|
purged_types = 0
|
||||||
for element_type in type.get_model_types():
|
for element_type in type.get_model_types():
|
||||||
if not type.get_type_occurrences(element_type):
|
if not type.get_type_occurrences(element_type):
|
||||||
obj = ifc.get_object(element_type)
|
obj = ifc.get_object(element_type)
|
||||||
ifc.run("root.remove_product", product=element_type)
|
|
||||||
purged_types += 1
|
|
||||||
if obj:
|
if obj:
|
||||||
ifc.unlink(element=element_type)
|
geometry.delete_ifc_object(obj)
|
||||||
type.remove_object(obj)
|
else:
|
||||||
|
ifc.run("root.remove_product", product=element_type)
|
||||||
|
purged_types += 1
|
||||||
return purged_types
|
return purged_types
|
||||||
|
|||||||
@@ -99,10 +99,6 @@ class Type(blenderbim.core.tool.Type):
|
|||||||
return "Usage" in material.is_a()
|
return "Usage" in material.is_a()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def remove_object(cls, obj: bpy.types.Object) -> None:
|
|
||||||
bpy.data.objects.remove(obj)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def run_geometry_add_representation(
|
def run_geometry_add_representation(
|
||||||
cls,
|
cls,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import blenderbim.core.type as subject
|
import blenderbim.core.type as subject
|
||||||
from test.core.bootstrap import ifc, type
|
from test.core.bootstrap import ifc, type, geometry
|
||||||
|
|
||||||
|
|
||||||
class TestAssignType:
|
class TestAssignType:
|
||||||
@@ -42,11 +42,16 @@ class TestAssignType:
|
|||||||
|
|
||||||
|
|
||||||
class TestPurgeUnusedTypes:
|
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_model_types().should_be_called().will_return(["element_type"])
|
||||||
type.get_type_occurrences("element_type").should_be_called().will_return([])
|
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.get_object("element_type").should_be_called().will_return("obj")
|
||||||
ifc.unlink(element="element_type").should_be_called()
|
geometry.delete_ifc_object("obj").should_be_called()
|
||||||
type.remove_object("obj").should_be_called()
|
subject.purge_unused_types(ifc, type, geometry)
|
||||||
subject.purge_unused_types(ifc, type)
|
|
||||||
|
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)
|
||||||
|
|||||||
@@ -168,13 +168,6 @@ class TestHasMaterialUsage(NewFile):
|
|||||||
assert subject.has_material_usage(element) is True
|
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):
|
class TestRunGeometryAddRepresentation(NewFile):
|
||||||
def test_nothing(self):
|
def test_nothing(self):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user