Some more renaming/refactoring

This commit is contained in:
Carlos Villagrasa
2022-07-26 01:21:51 +02:00
parent 64752e52c9
commit cee48d7424
6 changed files with 44 additions and 57 deletions
@@ -21,10 +21,10 @@ from . import handler, prop, ui, grid, product, wall, slab, stair, opening, pie,
classes = (
product.AddEmptyType,
product.AddTypeInstance,
product.AddConstrType,
product.DisplayConstrTypes,
product.SelectConstructionType,
product.TypeInstanceHelp,
product.HelpConstrTypes,
product.AlignProduct,
product.DynamicallyVoidProduct,
workspace.Hotkey,
@@ -16,12 +16,14 @@
# You should have received a copy of the GNU General Public License
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
import functools
import bpy
import blenderbim.tool as tool
from blenderbim.bim.ifc import IfcStore
preview_icon_ids = {}
attempts = 0
def refresh():
@@ -37,6 +39,7 @@ class AuthoringData:
cls.is_loaded = True
if not hasattr(cls, "data"):
cls.data = {}
cls.props = bpy.context.scene.BIMModelProperties
cls.load_constr_classes()
cls.load_constr_types()
cls.load_constr_types_browser()
@@ -77,8 +80,7 @@ class AuthoringData:
return []
results = []
if constr_class is None:
props = bpy.context.scene.BIMModelProperties
constr_class = props.constr_class
constr_class = cls.props.constr_class
if not constr_class and constr_classes:
constr_class = constr_classes[0][0]
if constr_class:
@@ -95,8 +97,7 @@ class AuthoringData:
@classmethod
def constr_types_browser(cls):
props = bpy.context.scene.BIMModelProperties
return cls.constr_types(constr_class=props.constr_class_browser)
return cls.constr_types(constr_class=cls.props.constr_class_browser)
@staticmethod
def new_constr_type_info(constr_class):
@@ -107,8 +108,7 @@ class AuthoringData:
@classmethod
def assetize_constr_class(cls, constr_class=None):
if constr_class is None:
props = bpy.context.scene.BIMModelProperties
constr_class = props.constr_class
constr_class = cls.props.constr_class
constr_type_info = cls.constr_type_info(constr_class)
_ = cls.new_constr_type_info(constr_class) if constr_type_info is None else constr_type_info
constr_class_occurrences = cls.constr_class_entities(constr_class)
@@ -131,7 +131,7 @@ class AuthoringData:
kwargs = {}
if not from_selection:
kwargs.update({'constr_class': constr_class, 'constr_type_id': constr_type_id})
new_obj = cls.new_constr_type_instance(**kwargs)
new_obj = cls.new_constr_type(**kwargs)
if new_obj is not None:
to_be_deleted = True
obj = new_obj
@@ -147,9 +147,8 @@ class AuthoringData:
@classmethod
def assetize_constr_type_from_selection(cls):
props = bpy.context.scene.BIMModelProperties
constr_class_browser = props.constr_class_browser
constr_type_id_browser = props.constr_type_id_browser
constr_class_browser = cls.props.constr_class_browser
constr_type_id_browser = cls.props.constr_type_id_browser
constr_class_occurrences = cls.constr_class_entities(constr_class=constr_class_browser)
constr_class_occurrences = [
entity for entity in constr_class_occurrences if entity.id() == int(constr_type_id_browser)
@@ -169,16 +168,15 @@ class AuthoringData:
return None if len(constr_type_infos) == 0 else constr_type_infos[0]
@classmethod
def new_constr_type_instance(cls, constr_class=None, constr_type_id=None):
props = bpy.context.scene.BIMModelProperties
def new_constr_type(cls, constr_class=None, constr_type_id=None):
if constr_class is None:
bpy.ops.bim.add_type_instance(
constr_class=props.constr_class_browser, constr_type_id=int(props.constr_type_id_browser)
bpy.ops.bim.add_constr_type(
constr_class=cls.props.constr_class_browser, constr_type_id=int(cls.props.constr_type_id_browser)
)
else:
props.constr_class = constr_class
props.constr_type_id = str(constr_type_id)
bpy.ops.bim.add_type_instance()
cls.props.constr_class = constr_class
cls.props.constr_type_id = str(constr_type_id)
bpy.ops.bim.add_constr_type()
return bpy.context.selected_objects[-1]
@staticmethod
@@ -197,12 +195,10 @@ class AuthoringData:
@classmethod
def consolidate_constr_type(cls):
props = bpy.context.scene.BIMModelProperties
props.constr_class = props.constr_class_browser
props.constr_type_id = props.constr_type_id_browser
cls.props.constr_class = cls.props.constr_class_browser
cls.props.constr_type_id = cls.props.constr_type_id_browser
@classmethod
def setup_constr_type_browser(cls):
props = bpy.context.scene.BIMModelProperties
props.constr_class_browser = props.constr_class
props.constr_type_id_browser = props.constr_type_id
cls.props.constr_class_browser = cls.props.constr_class
cls.props.constr_type_id_browser = cls.props.constr_type_id
@@ -31,7 +31,7 @@ import blenderbim.core.geometry
from . import wall, slab, profile, mep
from blenderbim.bim.ifc import IfcStore
from blenderbim.bim.module.model.data import AuthoringData
from blenderbim.bim.helper import prop_with_search, layout_with_margins
from blenderbim.bim.helper import prop_with_search, layout_with_margins, close_operator_panel
from ifcopenshell.api.pset.data import Data as PsetData
from mathutils import Vector, Matrix
from bpy_extras.object_utils import AddObjectHelper
@@ -57,15 +57,8 @@ def add_empty_type_button(self, context):
self.layout.operator(AddEmptyType.bl_idname, icon="FILE_3D")
def close_operator_panel(event):
x, y = event.mouse_x, event.mouse_y
bpy.context.window.cursor_warp(10, 10)
move_back = lambda: bpy.context.window.cursor_warp(x, y)
bpy.app.timers.register(move_back, first_interval=0.001)
class AddTypeInstance(bpy.types.Operator):
bl_idname = "bim.add_type_instance"
class AddConstrType(bpy.types.Operator):
bl_idname = "bim.add_constr_type"
bl_label = "Add"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Add Type Instance to the model"
@@ -208,13 +201,13 @@ class DisplayConstrTypes(bpy.types.Operator):
AuthoringData.load()
AuthoringData.setup_constr_type_browser()
props = context.scene.BIMModelProperties
if props.unfold_relating_type:
if props.unfold_constr_types:
constr_class = props.constr_class_browser
constr_type_info = AuthoringData.constr_type_info(constr_class)
if constr_type_info is None or not constr_type_info.fully_loaded:
AuthoringData.assetize_constr_class(constr_class)
else:
prop.update_constr_type(props, context)
prop.update_constr_type_browser(props, context)
min_width = 250
width_scaling = 5 ** -1
width = max([min_width, int(width_scaling * context.region.width)])
@@ -222,10 +215,11 @@ class DisplayConstrTypes(bpy.types.Operator):
def draw(self, context):
props = context.scene.BIMModelProperties
if props.unfold_relating_type:
self.draw_by_constr_class(props)
header_data = self.draw_header(props)
if props.unfold_constr_types:
self.draw_by_constr_class(props, header_data)
else:
self.draw_by_constr_class_and_type(props)
self.draw_by_constr_class_and_type(props, header_data)
def draw_header(self, props):
layout = self.layout
@@ -234,7 +228,7 @@ class DisplayConstrTypes(bpy.types.Operator):
split = inner_layout.split(align=True, factor=2./3)
col1 = split.column(align=True)
row = col1.row()
row.prop(data=props, property="unfold_relating_type", text="Preview All Construction Types")
row.prop(data=props, property="unfold_constr_types", text="Preview All Construction Types")
col1.row().separator(factor=1)
row = col1.row()
row.label(text="Select Construction Type:")
@@ -250,12 +244,11 @@ class DisplayConstrTypes(bpy.types.Operator):
col2 = split.column(align=True)
subsplit = col2.split(factor=0.9)
subcol = [subsplit.column() for _ in range(2)][-1]
subcol.operator("bim.type_instance_help", text="", icon="QUESTION")
subcol.operator("bim.help_constr_types", text="", icon="QUESTION")
col2.row().separator(factor=1)
return {"enabled": enabled, "layout": inner_layout, "col1": col1, "col2": col2}
def draw_by_constr_class(self, props):
header_data = self.draw_header(props)
def draw_by_constr_class(self, props, header_data):
enabled, layout = [header_data[key] for key in ["enabled", "layout"]]
constr_class_browser = props.constr_class_browser
num_cols = 3
@@ -287,7 +280,7 @@ class DisplayConstrTypes(bpy.types.Operator):
op.constr_class = constr_class_browser
op.constr_type_id = constr_type_id_browser
col = split.column()
op = col.operator("bim.add_type_instance", icon="ADD")
op = col.operator("bim.add_constr_type", icon="ADD")
op.from_invoke = True
op.constr_class = constr_class_browser
if constr_type_id_browser.isnumeric():
@@ -299,8 +292,7 @@ class DisplayConstrTypes(bpy.types.Operator):
for _ in range(num_cols - last_row_cols):
flow.column()
def draw_by_constr_class_and_type(self, props):
header_data = self.draw_header(props)
def draw_by_constr_class_and_type(self, props, header_data):
enabled, col1, col2 = [header_data[key] for key in ["enabled", "col1", "col2"]]
constr_class_browser = props.constr_class_browser
constr_type_id_browser = props.constr_type_id_browser
@@ -317,7 +309,7 @@ class DisplayConstrTypes(bpy.types.Operator):
op = row.operator("bim.select_construction_type", icon="RIGHTARROW_THIN")
op.constr_class = constr_class_browser
op.constr_type_id = constr_type_id_browser
op = row.operator("bim.add_type_instance", icon="ADD")
op = row.operator("bim.add_constr_type", icon="ADD")
op.from_invoke = True
op.constr_class = constr_class_browser
if constr_type_id_browser.isnumeric():
@@ -353,8 +345,8 @@ class SelectConstructionType(bpy.types.Operator):
return {"FINISHED"}
class TypeInstanceHelp(bpy.types.Operator):
bl_idname = "bim.type_instance_help"
class HelpConstrTypes(bpy.types.Operator):
bl_idname = "bim.help_constr_types"
bl_label = "Construction Types Help"
bl_options = {"REGISTER", "UNDO"}
bl_description = "Click to read some contextual help"
@@ -48,8 +48,7 @@ def update_icon_id(self, context):
and constr_type_browser is not None):
if not AuthoringData.assetize_constr_type_from_selection():
return
props = bpy.context.scene.BIMModelProperties
props.icon_id = AuthoringData.data["preview_constr_types"][constr_class_browser][constr_type_id_browser]["icon_id"]
self.icon_id = AuthoringData.data["preview_constr_types"][constr_class_browser][constr_type_id_browser]["icon_id"]
def update_constr_class(self, context):
@@ -62,7 +61,7 @@ def update_constr_class_browser(self, context):
AuthoringData.load_constr_classes()
AuthoringData.load_constr_types_browser()
props = context.scene.BIMModelProperties
if props.unfold_relating_type:
if props.unfold_constr_types:
constr_class_browser = props.constr_class_browser
constr_type_info = AuthoringData.constr_type_info(constr_class_browser)
if constr_type_info is None or not constr_type_info.fully_loaded:
@@ -114,7 +113,7 @@ class BIMModelProperties(PropertyGroup):
items=get_constr_type_browser, name="Construction Type", update=update_constr_type_browser
)
icon_id: bpy.props.IntProperty()
unfold_relating_type: bpy.props.BoolProperty(update=update_unfold_constr_type)
unfold_constr_types: bpy.props.BoolProperty(update=update_unfold_constr_type)
occurrence_name_style: bpy.props.EnumProperty(
items=[("CLASS", "By Class", ""), ("TYPE", "By Type", ""), ("CUSTOM", "Custom", "")],
name="Occurrence Name Style",
@@ -66,7 +66,7 @@ class BimTool(WorkSpaceTool):
constr_types_ids = AuthoringData.data["constr_types_ids"]
if is_tool_header:
row.operator("bim.type_instance_help", text="", icon="QUESTION")
row.operator("bim.help_constr_types", text="", icon="QUESTION")
if constr_classes and is_tool_header:
row.label(text="", icon="BLANK1")
@@ -184,7 +184,7 @@ class Hotkey(bpy.types.Operator):
return {"FINISHED"}
def hotkey_S_A(self):
bpy.ops.bim.add_type_instance()
bpy.ops.bim.add_constr_type()
def hotkey_S_C(self):
if self.has_ifc_class and self.props.ifc_class == "IfcWallType":
@@ -88,4 +88,4 @@ class BIM_PT_type(Panel):
def add_object_button(self, context):
self.layout.operator("bim.add_type_instance", icon="PLUGIN")
self.layout.operator("bim.add_constr_type", icon="PLUGIN")