Remove SELECT from type browser

This commit is contained in:
Carlos Villagrasa
2022-08-01 20:55:52 +02:00
committed by Dion Moult
parent 5cc11a170b
commit c349523ea9
5 changed files with 54 additions and 116 deletions
@@ -23,7 +23,6 @@ classes = (
product.AddEmptyType,
product.AddConstrTypeInstance,
product.DisplayConstrTypes,
product.SelectConstructionType,
product.AlignProduct,
product.DynamicallyVoidProduct,
workspace.Hotkey,
@@ -42,7 +42,6 @@ class AuthoringData:
cls.props = bpy.context.scene.BIMModelProperties
cls.load_ifc_classes()
cls.load_relating_types()
cls.load_relating_types_browser()
cls.load_preview_constr_types()
@classmethod
@@ -53,10 +52,6 @@ class AuthoringData:
def load_relating_types(cls):
cls.data["relating_types_ids"] = cls.relating_types()
@classmethod
def load_relating_types_browser(cls):
cls.data["relating_types_ids_browser"] = cls.relating_types_browser()
@classmethod
def load_preview_constr_types(cls):
cls.data["preview_constr_types"] = preview_icon_ids
@@ -93,10 +88,6 @@ class AuthoringData:
def relating_types(cls, ifc_class=None):
return [(str(e.id()), e.Name, e.Description or "") for e in cls.constr_class_entities(ifc_class=ifc_class)]
@classmethod
def relating_types_browser(cls):
return cls.relating_types(ifc_class=cls.props.ifc_class_browser)
@staticmethod
def new_relating_type_info(ifc_class):
relating_type_info = bpy.context.scene.ConstrTypeInfo.add()
@@ -147,11 +138,11 @@ class AuthoringData:
@classmethod
def assetize_relating_type_from_selection(cls):
ifc_class_browser = cls.props.ifc_class_browser
relating_type_id_browser = cls.props.relating_type_id_browser
constr_class_occurrences = cls.constr_class_entities(ifc_class=ifc_class_browser)
ifc_class= cls.props.ifc_class
relating_type_id = cls.props.relating_type_id
constr_class_occurrences = cls.constr_class_entities(ifc_class=ifc_class)
constr_class_occurrences = [
entity for entity in constr_class_occurrences if entity.id() == int(relating_type_id_browser)
entity for entity in constr_class_occurrences if entity.id() == int(relating_type_id)
]
if len(constr_class_occurrences) == 0:
return False
@@ -159,7 +150,7 @@ class AuthoringData:
obj = tool.Ifc.get_object(constr_class_entity)
if obj is None:
return False
cls.assetize_object(obj, ifc_class_browser, constr_class_entity, from_selection=True)
cls.assetize_object(obj, ifc_class, constr_class_entity, from_selection=True)
return True
@staticmethod
@@ -171,11 +162,13 @@ class AuthoringData:
def new_relating_type(cls, ifc_class=None, relating_type_id=None):
if ifc_class is None:
bpy.ops.bim.add_constr_type_instance(
ifc_class=cls.props.ifc_class_browser, relating_type_id=int(cls.props.relating_type_id_browser)
ifc_class=cls.props.ifc_class, relating_type_id=int(cls.props.relating_type_id)
)
else:
cls.props.updating = True
cls.props.ifc_class = ifc_class
cls.props.relating_type_id = str(relating_type_id)
cls.props.updating = False
bpy.ops.bim.add_constr_type_instance()
return bpy.context.selected_objects[-1]
@@ -192,13 +185,3 @@ class AuthoringData:
def relating_type_id_by_name(cls, ifc_class, relating_type):
relating_types = [ct[0] for ct in cls.relating_types(ifc_class=ifc_class) if ct[1] == relating_type]
return None if len(relating_types) == 0 else relating_types[0]
@classmethod
def consolidate_relating_type(cls):
cls.props.ifc_class = cls.props.ifc_class_browser
cls.props.relating_type_id = cls.props.relating_type_id_browser
@classmethod
def setup_relating_type_browser(cls):
cls.props.ifc_class_browser = cls.props.ifc_class
cls.props.relating_type_id_browser = cls.props.relating_type_id
@@ -192,37 +192,18 @@ class DisplayConstrTypes(bpy.types.Operator):
def invoke(self, context, event):
if not AuthoringData.is_loaded:
AuthoringData.load()
AuthoringData.setup_relating_type_browser()
props = context.scene.BIMModelProperties
if props.unfold_relating_types:
ifc_class = props.ifc_class_browser
ifc_class = props.ifc_class
relating_type_info = AuthoringData.relating_type_info(ifc_class)
if relating_type_info is None or not relating_type_info.fully_loaded:
AuthoringData.assetize_constr_class(ifc_class)
else:
prop.update_relating_type_browser(props, context)
prop.update_relating_type(props, context)
bpy.ops.bim.display_constr_types_ui("INVOKE_DEFAULT")
return {"FINISHED"}
class SelectConstructionType(bpy.types.Operator):
bl_idname = "bim.select_construction_type"
bl_label = "Select"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Pick Type Instance as selection for subsequent operations"
ifc_class: bpy.props.StringProperty()
relating_type_id: bpy.props.StringProperty()
def execute(self, context):
props = context.scene.BIMModelProperties
if self.ifc_class != "":
props.ifc_class = self.ifc_class
AuthoringData.load_relating_types()
if self.relating_type_id != "":
props.relating_type_id = self.relating_type_id
return {"FINISHED"}
class AlignProduct(bpy.types.Operator):
bl_idname = "bim.align_product"
bl_label = "Align Product"
@@ -33,48 +33,37 @@ def get_relating_type(self, context):
return AuthoringData.data["relating_types_ids"]
def get_relating_type_browser(self, context):
if not AuthoringData.is_loaded:
AuthoringData.load()
return AuthoringData.data["relating_types_ids_browser"]
def update_icon_id(self, context):
ifc_class_browser = self.ifc_class_browser
relating_type_id_browser = self.relating_type_id_browser
relating_type_browser = AuthoringData.relating_type_name_by_id(ifc_class_browser, relating_type_id_browser)
ifc_class = self.ifc_class
relating_type_id = self.relating_type_id
relating_type = AuthoringData.relating_type_name_by_id(ifc_class, relating_type_id)
if (
ifc_class_browser not in AuthoringData.data["preview_constr_types"]
or relating_type_id_browser not in AuthoringData.data["preview_constr_types"][ifc_class_browser]
) and relating_type_browser is not None:
ifc_class not in AuthoringData.data["preview_constr_types"]
or relating_type_id not in AuthoringData.data["preview_constr_types"][ifc_class]
) and relating_type is not None:
if not AuthoringData.assetize_relating_type_from_selection():
return
self.icon_id = AuthoringData.data["preview_constr_types"][ifc_class_browser][relating_type_id_browser]["icon_id"]
self.icon_id = AuthoringData.data["preview_constr_types"][ifc_class][relating_type_id]["icon_id"]
def update_ifc_class(self, context):
AuthoringData.load_ifc_classes()
AuthoringData.load_relating_types()
self.relating_type_id = AuthoringData.data["relating_types_ids"][0][0]
def update_ifc_class_browser(self, context):
AuthoringData.load_ifc_classes()
AuthoringData.load_relating_types_browser()
props = context.scene.BIMModelProperties
if props.unfold_relating_types:
ifc_class_browser = props.ifc_class_browser
relating_type_info = AuthoringData.relating_type_info(ifc_class_browser)
if self.updating:
return
if self.unfold_relating_types:
ifc_class = self.ifc_class
relating_type_info = AuthoringData.relating_type_info(ifc_class)
if relating_type_info is None or not relating_type_info.fully_loaded:
curr_selection = props.ifc_class, props.relating_type_id
AuthoringData.assetize_constr_class(ifc_class_browser)
props.ifc_class, props.relating_type_id = curr_selection
AuthoringData.assetize_constr_class(ifc_class)
else:
self.relating_type_id_browser = AuthoringData.data["relating_types_ids_browser"][0][0]
self.relating_type_id = AuthoringData.data["relating_types_ids"][0][0]
def update_relating_type(self, context):
AuthoringData.load_relating_types()
if not self.updating:
update_icon_id(self, context)
def update_relating_type_by_name(self, context):
@@ -84,45 +73,31 @@ def update_relating_type_by_name(self, context):
self.relating_type_id = relating_type_id
def update_relating_type_browser_by_name(self, context):
AuthoringData.load_relating_types_browser()
relating_type_id_browser = AuthoringData.relating_type_id_by_name(
self.ifc_class_browser, self.relating_type_browser
)
if relating_type_id_browser is not None:
self.relating_type_id_browser = relating_type_id_browser
def update_relating_type_browser(self, context):
AuthoringData.load_relating_types_browser()
update_icon_id(self, context)
def update_unfold_relating_type(self, context):
update_ifc_class_browser(self, context)
if self.unfold_relating_types:
ifc_class = self.ifc_class
relating_type_info = AuthoringData.relating_type_info(ifc_class)
if relating_type_info is None or not relating_type_info.fully_loaded:
AuthoringData.assetize_constr_class(ifc_class)
else:
update_relating_type(self, context)
class BIMModelProperties(PropertyGroup):
ifc_class: bpy.props.EnumProperty(items=get_ifc_class, name="Construction Class", update=update_ifc_class)
ifc_class_browser: bpy.props.EnumProperty(
items=get_ifc_class, name="Construction Class", update=update_ifc_class_browser
)
relating_type: bpy.props.StringProperty(update=update_relating_type_by_name)
relating_type_id: bpy.props.EnumProperty(
items=get_relating_type, name="Construction Type", update=update_relating_type
)
relating_type_browser: bpy.props.StringProperty(update=update_relating_type_browser_by_name)
relating_type_id_browser: bpy.props.EnumProperty(
items=get_relating_type_browser, name="Construction Type", update=update_relating_type_browser
)
icon_id: bpy.props.IntProperty()
unfold_relating_types: bpy.props.BoolProperty(update=update_unfold_relating_type)
updating: bpy.props.BoolProperty(default=False)
occurrence_name_style: bpy.props.EnumProperty(
items=[("CLASS", "By Class", ""), ("TYPE", "By Type", ""), ("CUSTOM", "Custom", "")],
name="Occurrence Name Style",
)
occurrence_name_function: bpy.props.StringProperty(name="Occurrence Name Function")
getter_enum = {"ifc_class_browser": get_ifc_class, "relating_type_browser": get_relating_type_browser}
getter_enum = {"ifc_class": get_ifc_class, "relating_type": get_relating_type}
def get_relating_type_info(self, context):
@@ -80,7 +80,7 @@ class DisplayConstrTypesUI(Operator):
if AuthoringData.data["ifc_classes"]:
row = col1.row()
row.label(text="", icon="FILE_VOLUME")
prop_with_search(row, props, "ifc_class_browser", text="")
prop_with_search(row, props, "ifc_class", text="")
col1.row().separator()
else:
enabled = False
@@ -93,13 +93,13 @@ class DisplayConstrTypesUI(Operator):
def draw_by_ifc_class(self, props, header_data):
enabled, layout = [header_data[key] for key in ["enabled", "layout"]]
ifc_class_browser = props.ifc_class_browser
ifc_class = props.ifc_class
num_cols = 3
layout.row().separator(factor=0.25)
flow = layout.grid_flow(row_major=True, columns=num_cols, even_columns=True, even_rows=True, align=True)
relating_types_browser = AuthoringData.relating_types_browser()
num_types = len(relating_types_browser)
for idx, (relating_type_id_browser, name, desc) in enumerate(relating_types_browser):
relating_types = AuthoringData.relating_types()
num_types = len(relating_types)
for idx, (relating_type_id, name, desc) in enumerate(relating_types):
outer_col = flow.column()
box = outer_col.box()
row = box.row()
@@ -108,18 +108,18 @@ class DisplayConstrTypesUI(Operator):
row = box.row()
if enabled:
preview_constr_types = AuthoringData.data["preview_constr_types"]
if ifc_class_browser in preview_constr_types:
preview_ifc_class = preview_constr_types[ifc_class_browser]
if relating_type_id_browser in preview_ifc_class:
icon_id = preview_ifc_class[relating_type_id_browser]["icon_id"]
if ifc_class in preview_constr_types:
preview_ifc_class = preview_constr_types[ifc_class]
if relating_type_id in preview_ifc_class:
icon_id = preview_ifc_class[relating_type_id]["icon_id"]
row.template_icon(icon_value=icon_id, scale=6.0)
box.row().separator(factor=0.2)
row = box.row()
op = row.operator("bim.add_constr_type_instance", icon="ADD")
op.from_invoke = True
op.ifc_class = ifc_class_browser
if relating_type_id_browser.isnumeric():
op.relating_type_id = int(relating_type_id_browser)
op.ifc_class = ifc_class
if relating_type_id.isnumeric():
op.relating_type_id = int(relating_type_id)
factor = 2 if idx + 1 < math.ceil(num_types / num_cols) else 1.5
outer_col.row().separator(factor=factor)
last_row_cols = num_types % num_cols
@@ -129,12 +129,12 @@ class DisplayConstrTypesUI(Operator):
def draw_by_ifc_class_and_type(self, props, header_data):
enabled, col1, col2 = [header_data[key] for key in ["enabled", "col1", "col2"]]
ifc_class_browser = props.ifc_class_browser
relating_type_id_browser = props.relating_type_id_browser
if AuthoringData.data["relating_types_ids_browser"]:
ifc_class = props.ifc_class
relating_type_id = props.relating_type_id
if AuthoringData.data["relating_types_ids"]:
row = col1.row()
row.label(text="", icon="FILE_3D")
prop_with_search(row, props, "relating_type_id_browser", text="")
prop_with_search(row, props, "relating_type_id", text="")
col1.row().separator()
else:
enabled = False
@@ -144,9 +144,9 @@ class DisplayConstrTypesUI(Operator):
row.label(text="", icon="BLANK1")
op = row.operator("bim.add_constr_type_instance", icon="ADD")
op.from_invoke = True
op.ifc_class = ifc_class_browser
if relating_type_id_browser.isnumeric():
op.relating_type_id = int(relating_type_id_browser)
op.ifc_class = ifc_class
if relating_type_id.isnumeric():
op.relating_type_id = int(relating_type_id)
col2.row().separator(factor=1.25)
split = col2.split(factor=0.025)
col = [split.column() for _ in range(2)][-1]