Moving some code to tool.Geometry

This commit is contained in:
Andrej730
2023-09-29 16:22:27 +05:00
parent be928347c5
commit ca4d4e026c
5 changed files with 31 additions and 34 deletions
@@ -465,7 +465,7 @@ class CopyRepresentation(bpy.types.Operator, Operator):
if not element: if not element:
continue continue
bm.to_mesh(obj.data) bm.to_mesh(obj.data)
old_rep = self.get_representation_by_context(element, geometric_context) old_rep = tool.Geometry.get_representation_by_context(element, geometric_context)
if old_rep: if old_rep:
ifcopenshell.api.run( ifcopenshell.api.run(
"geometry.unassign_representation", tool.Ifc.get(), product=element, representation=old_rep "geometry.unassign_representation", tool.Ifc.get(), product=element, representation=old_rep
@@ -482,16 +482,6 @@ class CopyRepresentation(bpy.types.Operator, Operator):
profile_set_usage=None, profile_set_usage=None,
) )
def get_representation_by_context(self, element, context):
if element.is_a("IfcProduct") and element.Representation:
for r in element.Representation.Representations:
if r.ContextOfItems == context:
return r
elif element.is_a("IfcTypeProduct") and element.RepresentationMaps:
for r in element.RepresentationMaps:
if r.MappedRepresentation.ContextOfItems == context:
return r.MappedRepresentation
class OverrideDelete(bpy.types.Operator): class OverrideDelete(bpy.types.Operator):
bl_idname = "bim.override_object_delete" bl_idname = "bim.override_object_delete"
@@ -68,13 +68,7 @@ def update_door_modifier_representation(context, obj):
}, },
} }
def get_active_representation_context(obj): previously_active_context = tool.Geometry.get_active_representation_context(obj)
active_representation = tool.Geometry.get_active_representation(obj)
if active_representation:
return active_representation.ContextOfItems
return ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
previously_active_context = get_active_representation_context(obj)
# ELEVATION_VIEW representation # ELEVATION_VIEW representation
profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW") profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW")
@@ -124,7 +118,7 @@ def update_door_modifier_representation(context, obj):
# adding switch representation at the end instead of changing order of representations # adding switch representation at the end instead of changing order of representations
# to prevent #2744 # to prevent #2744
if get_active_representation_context(obj) != previously_active_context: if tool.Geometry.get_active_representation_context(obj) != previously_active_context:
previously_active_representation = ifcopenshell.util.representation.get_representation( previously_active_representation = ifcopenshell.util.representation.get_representation(
element, element,
previously_active_context.ContextType, previously_active_context.ContextType,
@@ -119,13 +119,7 @@ def update_window_modifier_representation(context, obj):
} }
representation_data["panel_properties"].append(panel_data) representation_data["panel_properties"].append(panel_data)
def get_active_representation_context(obj): previously_active_context = tool.Geometry.get_active_representation_context(obj)
active_representation = tool.Geometry.get_active_representation(obj)
if active_representation:
return active_representation.ContextOfItems
return ifcopenshell.util.representation.get_context(ifc_file, "Model", "Body", "MODEL_VIEW")
previously_active_context = get_active_representation_context(obj)
# ELEVATION_VIEW representation # ELEVATION_VIEW representation
profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW") profile = ifcopenshell.util.representation.get_context(ifc_file, "Model", "Profile", "ELEVATION_VIEW")
@@ -154,7 +148,7 @@ def update_window_modifier_representation(context, obj):
# adding switch representation at the end instead of changing order of representations # adding switch representation at the end instead of changing order of representations
# to prevent #2744 # to prevent #2744
if get_active_representation_context(obj) != previously_active_context: if tool.Geometry.get_active_representation_context(obj) != previously_active_context:
previously_active_representation = ifcopenshell.util.representation.get_representation( previously_active_representation = ifcopenshell.util.representation.get_representation(
element, element,
previously_active_context.ContextType, previously_active_context.ContextType,
+25 -3
View File
@@ -37,12 +37,16 @@ class Geometry(blenderbim.core.tool.Geometry):
@classmethod @classmethod
def change_object_data(cls, obj, data, is_global=False): def change_object_data(cls, obj, data, is_global=False):
if is_global: if is_global:
if obj.mode == "EDIT": cls.replace_object_data_globally(obj.data, data)
raise Exception("user_remap is not supported in EDIT mode")
obj.data.user_remap(data)
else: else:
obj.data = data obj.data = data
@classmethod
def replace_object_data_globally(cls, old_data, new_data):
if old_data.is_editmode:
raise Exception("user_remap is not supported for meshes in EDIT mode")
old_data.user_remap(new_data)
@classmethod @classmethod
def clear_cache(cls, element): def clear_cache(cls, element):
cache = IfcStore.get_cache() cache = IfcStore.get_cache()
@@ -297,6 +301,24 @@ class Geometry(blenderbim.core.tool.Geometry):
if obj.data and hasattr(obj.data, "BIMMeshProperties") and obj.data.BIMMeshProperties.ifc_definition_id: if obj.data and hasattr(obj.data, "BIMMeshProperties") and obj.data.BIMMeshProperties.ifc_definition_id:
return tool.Ifc.get().by_id(obj.data.BIMMeshProperties.ifc_definition_id) return tool.Ifc.get().by_id(obj.data.BIMMeshProperties.ifc_definition_id)
@classmethod
def get_active_representation_context(cls, obj):
active_representation = tool.Geometry.get_active_representation(obj)
if active_representation:
return active_representation.ContextOfItems
return ifcopenshell.util.representation.get_context(tool.Ifc.get(), "Model", "Body", "MODEL_VIEW")
@classmethod
def get_representation_by_context(cls, element, context):
if element.is_a("IfcProduct") and element.Representation:
for r in element.Representation.Representations:
if r.ContextOfItems == context:
return r
elif element.is_a("IfcTypeProduct") and element.RepresentationMaps:
for r in element.RepresentationMaps:
if r.MappedRepresentation.ContextOfItems == context:
return r.MappedRepresentation
@classmethod @classmethod
def get_cartesian_point_coordinate_offset(cls, obj): def get_cartesian_point_coordinate_offset(cls, obj):
props = bpy.context.scene.BIMGeoreferenceProperties props = bpy.context.scene.BIMGeoreferenceProperties
+1 -4
View File
@@ -27,10 +27,7 @@ import blenderbim.bim.helper
class Type(blenderbim.core.tool.Type): class Type(blenderbim.core.tool.Type):
@classmethod @classmethod
def change_object_data(cls, obj, data, is_global=False): def change_object_data(cls, obj, data, is_global=False):
if is_global: tool.Geometry.change_object_data(obj, data, is_global)
obj.data.user_remap(data)
else:
obj.data = data
@classmethod @classmethod
def disable_editing(cls, obj): def disable_editing(cls, obj):