From d212344c5448027f7bbc58da121889b4b76eb88b Mon Sep 17 00:00:00 2001 From: Massimo Fabbro Date: Sun, 14 Apr 2024 14:59:10 +0200 Subject: [PATCH] Covering tool more user friendly UI ... --- .../bim/module/covering/workspace.py | 147 +++++++++++------- .../blenderbim/bim/module/model/covering.py | 18 ++- src/blenderbim/blenderbim/core/covering.py | 9 +- 3 files changed, 106 insertions(+), 68 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/covering/workspace.py b/src/blenderbim/blenderbim/bim/module/covering/workspace.py index cf4218a40e..d71d04f3fb 100644 --- a/src/blenderbim/blenderbim/bim/module/covering/workspace.py +++ b/src/blenderbim/blenderbim/bim/module/covering/workspace.py @@ -107,59 +107,88 @@ class CoveringToolUI: # elif element and bpy.context.selected_objects and element.is_a("IfcSpace"): # op. = row.operator("bim.add_istance_flooring_from_spaces"): - if (type_material_usage == "IfcMaterialLayerSet" and - not bpy.context.selected_objects): - row = cls.layout.row(align=True) - row.label(text="", icon="EVENT_SHIFT") - row.label(text="", icon="EVENT_A") - if tool.Ifc.get_entity(collection_obj): - if AuthoringData.data["predefined_type"] == "FLOORING": - op = row.operator("bim.add_instance_flooring_covering_from_cursor") - elif AuthoringData.data["predefined_type"] == "CEILING": - op = row.operator("bim.add_instance_ceiling_covering_from_cursor") - else: - op = row.operator("bim.add_constr_type_instance", text="Add") - op.from_invoke = True - if cls.props.relating_type_id.isnumeric(): - op.relating_type_id = int(cls.props.relating_type_id) - - else: - op = row.operator("bim.add_constr_type_instance", text="Add") - op.from_invoke = True - if cls.props.relating_type_id.isnumeric(): - op.relating_type_id = int(cls.props.relating_type_id) - - elif (AuthoringData.data["predefined_type"] == "FLOORING" and - type_material_usage == "IfcMaterialLayerSet" and - element and - bpy.context.selected_objects and - element.is_a("IfcWall")): - row = cls.layout.row(align=True) - row.label(text="", icon="EVENT_SHIFT") - row.label(text="", icon="EVENT_A") - op = row.operator("bim.add_instance_flooring_coverings_from_walls") - - elif (AuthoringData.data["predefined_type"] == "CEILING" and - type_material_usage == "IfcMaterialLayerSet" and - element and - bpy.context.selected_objects and - element.is_a("IfcWall")): - row = cls.layout.row(align=True) - row.label(text="", icon="EVENT_SHIFT") - row.label(text="", icon="EVENT_A") - op = row.operator("bim.add_instance_ceiling_coverings_from_walls") - - elif (element and - bpy.context.selected_objects and - element.is_a("IfcCovering") and -# AuthoringData.data["predefined_type"] == "FLOORING" and - AuthoringData.data["active_material_usage"] == "LAYER3"): - row = cls.layout.row(align=True) - row.label(text="", icon="EVENT_SHIFT") - row.label(text="", icon="EVENT_G") - op = row.operator("bim.regen_selected_covering_object") +# if (type_material_usage == "IfcMaterialLayerSet" and +# not bpy.context.selected_objects): +# row = cls.layout.row(align=True) +# row.label(text="", icon="EVENT_SHIFT") +# row.label(text="", icon="EVENT_A") +# if tool.Ifc.get_entity(collection_obj): +# if AuthoringData.data["predefined_type"] == "FLOORING": +# op = row.operator("bim.add_instance_flooring_covering_from_cursor") +# elif AuthoringData.data["predefined_type"] == "CEILING": +# op = row.operator("bim.add_instance_ceiling_covering_from_cursor") +# else: +# op = row.operator("bim.add_constr_type_instance", text="Add") +# op.from_invoke = True +# if cls.props.relating_type_id.isnumeric(): +# op.relating_type_id = int(cls.props.relating_type_id) +# +# else: +# op = row.operator("bim.add_constr_type_instance", text="Add") +# op.from_invoke = True +# if cls.props.relating_type_id.isnumeric(): +# op.relating_type_id = int(cls.props.relating_type_id) +# +# elif (AuthoringData.data["predefined_type"] == "FLOORING" and +# type_material_usage == "IfcMaterialLayerSet" and +# element and +# bpy.context.selected_objects and +# element.is_a("IfcWall")): +# row = cls.layout.row(align=True) +# row.label(text="", icon="EVENT_SHIFT") +# row.label(text="", icon="EVENT_A") +# op = row.operator("bim.add_instance_flooring_coverings_from_walls") +# +# elif (AuthoringData.data["predefined_type"] == "CEILING" and +# type_material_usage == "IfcMaterialLayerSet" and +# element and +# bpy.context.selected_objects and +# element.is_a("IfcWall")): +# row = cls.layout.row(align=True) +# row.label(text="", icon="EVENT_SHIFT") +# row.label(text="", icon="EVENT_A") +# op = row.operator("bim.add_instance_ceiling_coverings_from_walls") +# +# elif (element and +# bpy.context.selected_objects and +# element.is_a("IfcCovering") and +## AuthoringData.data["predefined_type"] == "FLOORING" and +# AuthoringData.data["active_material_usage"] == "LAYER3"): +# row = cls.layout.row(align=True) +# row.label(text="", icon="EVENT_SHIFT") +# row.label(text="", icon="EVENT_G") +# op = row.operator("bim.regen_selected_covering_object") + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_A") + op = row.operator("bim.add_constr_type_instance", text="Add") + + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_A") + op = row.operator("bim.add_instance_flooring_covering_from_cursor") + + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_A") + op = row.operator("bim.add_instance_ceiling_covering_from_cursor") + + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_A") + op = row.operator("bim.add_instance_flooring_coverings_from_walls") + + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_A") + op = row.operator("bim.add_instance_ceiling_coverings_from_walls") + + row = cls.layout.row(align=True) + row.label(text="", icon="EVENT_SHIFT") + row.label(text="", icon="EVENT_G") + op = row.operator("bim.regen_selected_covering_object") # elif AuthoringData.data["predefined_type"] == "CEILING": # row = cls.layout.row(align=True) @@ -174,14 +203,14 @@ class CoveringToolUI: # op.from_invoke = True # if cls.props.relating_type_id.isnumeric(): # op.relating_type_id = int(cls.props.relating_type_id) - else: - row = cls.layout.row(align=True) - row.label(text="", icon="EVENT_SHIFT") - row.label(text="", icon="EVENT_A") - op = row.operator("bim.add_constr_type_instance", text="Add") - op.from_invoke = True - if cls.props.relating_type_id.isnumeric(): - op.relating_type_id = int(cls.props.relating_type_id) +# else: +# row = cls.layout.row(align=True) +# row.label(text="", icon="EVENT_SHIFT") +# row.label(text="", icon="EVENT_A") +# op = row.operator("bim.add_constr_type_instance", text="Add") +# op.from_invoke = True +# if cls.props.relating_type_id.isnumeric(): +# op.relating_type_id = int(cls.props.relating_type_id) @classmethod def draw_type_selection_interface(cls): diff --git a/src/blenderbim/blenderbim/bim/module/model/covering.py b/src/blenderbim/blenderbim/bim/module/model/covering.py index 9d9729be56..c5791e9c13 100644 --- a/src/blenderbim/blenderbim/bim/module/model/covering.py +++ b/src/blenderbim/blenderbim/bim/module/model/covering.py @@ -32,7 +32,9 @@ class AddInstanceFlooringCoveringFromCursor(bpy.types.Operator, tool.Ifc.Operato def poll(cls, context): collection = context.view_layer.active_layer_collection.collection collection_obj = collection.BIMCollectionProperties.obj - return tool.Ifc.get_entity(collection_obj) + relating_type_id = int(bpy.data.scenes["Scene"].BIMModelProperties.relating_type_id) + relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id)) + return tool.Ifc.get_entity(collection_obj) and relating_type == "FLOORING" def _execute(self, context): @@ -61,7 +63,9 @@ class AddInstanceCeilingCoveringFromCursor(bpy.types.Operator, tool.Ifc.Operator def poll(cls, context): collection = context.view_layer.active_layer_collection.collection collection_obj = collection.BIMCollectionProperties.obj - return tool.Ifc.get_entity(collection_obj) + relating_type_id = int(bpy.data.scenes["Scene"].BIMModelProperties.relating_type_id) + relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id)) + return tool.Ifc.get_entity(collection_obj) and relating_type == "CEILING" def _execute(self, context): @@ -116,9 +120,11 @@ class AddInstanceFlooringCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operato def poll(cls, context): active_obj = bpy.context.active_object element = tool.Ifc.get_entity(active_obj) + relating_type_id = int(bpy.data.scenes["Scene"].BIMModelProperties.relating_type_id) + relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id)) if element: if element.is_a("IfcWall") and tool.Model.get_usage_type(element) == "LAYER2": - return context.selected_objects + return context.selected_objects and relating_type == "FLOORING" def _execute(self, context): # This only works based on a 2D plan only considering the standard @@ -147,7 +153,7 @@ class AddInstanceFlooringCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operato class AddInstanceCeilingCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.add_instance_ceiling_coverings_from_walls" - bl_label = "Add Ceilings From Walls" + bl_label = "Add Ceiling From Walls" bl_options = {"REGISTER", "UNDO"} bl_description = "Add instance ceiling coverings from selected walls. The active object must be a wall and layered vertically" @@ -155,9 +161,11 @@ class AddInstanceCeilingCoveringsFromWalls(bpy.types.Operator, tool.Ifc.Operator def poll(cls, context): active_obj = bpy.context.active_object element = tool.Ifc.get_entity(active_obj) + relating_type_id = int(bpy.data.scenes["Scene"].BIMModelProperties.relating_type_id) + relating_type = ifcopenshell.util.element.get_predefined_type(tool.Ifc.get().by_id(relating_type_id)) if element: if element.is_a("IfcWall") and tool.Model.get_usage_type(element) == "LAYER2": - return context.selected_objects + return context.selected_objects and relating_type == "CEILING" def _execute(self, context): # This only works based on a 2D plan only considering the standard diff --git a/src/blenderbim/blenderbim/core/covering.py b/src/blenderbim/blenderbim/core/covering.py index f98cbe267a..a182ed57b9 100644 --- a/src/blenderbim/blenderbim/core/covering.py +++ b/src/blenderbim/blenderbim/core/covering.py @@ -46,7 +46,8 @@ def add_instance_flooring_covering_from_cursor(ifc, spatial, model, Type, geomet obj = spatial.get_named_obj_from_mesh(name, mesh) - spatial.set_obj_origin_to_cursor_position(obj) + spatial.set_obj_origin_to_cursor_position_and_zero_elevation(obj) + spatial.traslate_obj_to_z_location(obj, z) spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) points = spatial.get_scaled_2d_vertices(points) @@ -74,7 +75,7 @@ def add_instance_ceiling_covering_from_cursor(ifc, spatial, model, Type, geometr else: x, y, z, h, mat = spatial.get_x_y_z_h_mat_from_cursor() - z = covering.get_z_from_ceiling_height() + ceiling_height = covering.get_z_from_ceiling_height() space_polygon = spatial.get_space_polygon_from_context_visible_objects(x, y) @@ -87,8 +88,8 @@ def add_instance_ceiling_covering_from_cursor(ifc, spatial, model, Type, geometr obj = spatial.get_named_obj_from_mesh(name, mesh) - spatial.set_obj_origin_to_cursor_position(obj) - spatial.traslate_obj_to_z_location(obj, z) + spatial.set_obj_origin_to_cursor_position_and_zero_elevation(obj) + spatial.traslate_obj_to_z_location(obj, z+ceiling_height) spatial.link_obj_to_active_collection(obj) points = spatial.get_2d_vertices_from_obj(obj) points = spatial.get_scaled_2d_vertices(points)