mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Moving some code to tool.Geometry
This commit is contained in:
@@ -465,7 +465,7 @@ class CopyRepresentation(bpy.types.Operator, Operator):
|
||||
if not element:
|
||||
continue
|
||||
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:
|
||||
ifcopenshell.api.run(
|
||||
"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,
|
||||
)
|
||||
|
||||
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):
|
||||
bl_idname = "bim.override_object_delete"
|
||||
|
||||
@@ -68,13 +68,7 @@ def update_door_modifier_representation(context, obj):
|
||||
},
|
||||
}
|
||||
|
||||
def 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)
|
||||
previously_active_context = tool.Geometry.get_active_representation_context(obj)
|
||||
|
||||
# ELEVATION_VIEW representation
|
||||
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
|
||||
# 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(
|
||||
element,
|
||||
previously_active_context.ContextType,
|
||||
|
||||
@@ -119,13 +119,7 @@ def update_window_modifier_representation(context, obj):
|
||||
}
|
||||
representation_data["panel_properties"].append(panel_data)
|
||||
|
||||
def 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)
|
||||
previously_active_context = tool.Geometry.get_active_representation_context(obj)
|
||||
|
||||
# ELEVATION_VIEW representation
|
||||
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
|
||||
# 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(
|
||||
element,
|
||||
previously_active_context.ContextType,
|
||||
|
||||
@@ -37,12 +37,16 @@ class Geometry(blenderbim.core.tool.Geometry):
|
||||
@classmethod
|
||||
def change_object_data(cls, obj, data, is_global=False):
|
||||
if is_global:
|
||||
if obj.mode == "EDIT":
|
||||
raise Exception("user_remap is not supported in EDIT mode")
|
||||
obj.data.user_remap(data)
|
||||
cls.replace_object_data_globally(obj.data, data)
|
||||
else:
|
||||
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
|
||||
def clear_cache(cls, element):
|
||||
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:
|
||||
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
|
||||
def get_cartesian_point_coordinate_offset(cls, obj):
|
||||
props = bpy.context.scene.BIMGeoreferenceProperties
|
||||
|
||||
@@ -27,10 +27,7 @@ import blenderbim.bim.helper
|
||||
class Type(blenderbim.core.tool.Type):
|
||||
@classmethod
|
||||
def change_object_data(cls, obj, data, is_global=False):
|
||||
if is_global:
|
||||
obj.data.user_remap(data)
|
||||
else:
|
||||
obj.data = data
|
||||
tool.Geometry.change_object_data(obj, data, is_global)
|
||||
|
||||
@classmethod
|
||||
def disable_editing(cls, obj):
|
||||
|
||||
Reference in New Issue
Block a user