This commit is contained in:
Andrej730
2026-03-09 19:34:38 +05:00
parent 4b12b6dacd
commit 15ea092ac4
23 changed files with 124 additions and 66 deletions
+2 -1
View File
@@ -1020,7 +1020,8 @@ class IfcImporter:
obj.hide_select = True obj.hide_select = True
obj.hide_viewport = True obj.hide_viewport = True
self.project["blender"].objects.link(obj) self.project["blender"].objects.link(obj)
self.project["blender"].BIMCollectionProperties.obj = obj collection_props = tool.Blender.get_collection_props(self.project["blender"])
collection_props.obj = obj
props = tool.Blender.get_object_bim_props(obj) props = tool.Blender.get_object_bim_props(obj)
props.collection = self.collections[project.GlobalId] = self.project["blender"] props.collection = self.collections[project.GlobalId] = self.project["blender"]
+2 -2
View File
@@ -1253,8 +1253,8 @@ class ActivateBcfViewpoint(bpy.types.Operator):
else: else:
obj.data.show_background_images = False obj.data.show_background_images = False
area = next(area for area in context.screen.areas if area.type == "VIEW_3D") assert (space := tool.Blender.get_view3d_space())
area.spaces[0].region_3d.view_perspective = "CAMERA" space.region_3d.view_perspective = "CAMERA"
if self.file: if self.file:
self.set_viewpoint_components(viewpoint, context) self.set_viewpoint_components(viewpoint, context)
+1 -1
View File
@@ -398,8 +398,8 @@ class BIM_PT_cost_item_types(Panel):
op = row2.operator("bim.calculate_cost_item_resource_value", text="", icon="DISC") op = row2.operator("bim.calculate_cost_item_resource_value", text="", icon="DISC")
op.cost_item = cost_item.ifc_definition_id op.cost_item = cost_item.ifc_definition_id
rtprops = context.scene.BIMResourceTreeProperties
rprops = tool.Resource.get_resource_props() rprops = tool.Resource.get_resource_props()
rtprops = rprops.tree
if rtprops.resources and rprops.active_resource_index < len(rtprops.resources): if rtprops.resources and rprops.active_resource_index < len(rtprops.resources):
if has_quantity_names: if has_quantity_names:
op = row2.operator("bim.assign_cost_item_quantity", text="", icon="PROPERTIES") op = row2.operator("bim.assign_cost_item_quantity", text="", icon="PROPERTIES")
@@ -98,8 +98,8 @@ class VisualiseDiff(bpy.types.Operator):
obj.color = (0.0, 1.0, 0.0, 1.0) obj.color = (0.0, 1.0, 0.0, 1.0)
elif global_id in diff["changed"]: elif global_id in diff["changed"]:
obj.color = (0.0, 0.0, 1.0, 1.0) obj.color = (0.0, 0.0, 1.0, 1.0)
area = next(area for area in context.screen.areas if area.type == "VIEW_3D") assert (space := tool.Blender.get_view3d_space())
area.spaces[0].shading.color_type = "OBJECT" space.shading.color_type = "OBJECT"
return {"FINISHED"} return {"FINISHED"}
+3 -3
View File
@@ -515,6 +515,8 @@ class BIM_PT_derived_coordinates(Panel):
return context.active_object is not None return context.active_object is not None
def draw(self, context): def draw(self, context):
assert context.active_object
props = tool.Model.get_model_props()
if not DerivedCoordinatesData.is_loaded: if not DerivedCoordinatesData.is_loaded:
DerivedCoordinatesData.load() DerivedCoordinatesData.load()
@@ -529,10 +531,8 @@ class BIM_PT_derived_coordinates(Panel):
row = self.layout.row(align=True) row = self.layout.row(align=True)
row.enabled = False row.enabled = False
area_3d = next((area for area in context.screen.areas if area.type == "VIEW_3D"), None)
space_3d = next((space for space in area_3d.spaces if space.type == "VIEW_3D"), None)
if bpy.context.scene.BIMModelProperties.show_bounding_box: if props.show_bounding_box:
for axis, icon, idx in [("X", "STRIP_COLOR_01", 0), ("Y", "STRIP_COLOR_04", 1), ("Z", "STRIP_COLOR_05", 2)]: for axis, icon, idx in [("X", "STRIP_COLOR_01", 0), ("Y", "STRIP_COLOR_04", 1), ("Z", "STRIP_COLOR_05", 2)]:
row.label(text="", icon=icon) row.label(text="", icon=icon)
row.prop(context.active_object, "dimensions", text=axis, index=idx) row.prop(context.active_object, "dimensions", text=axis, index=idx)
@@ -41,10 +41,11 @@ class SetOverrideColour(bpy.types.Operator):
return context.selected_objects return context.selected_objects
def execute(self, context): def execute(self, context):
props = tool.Misc.get_misc_props()
for obj in context.selected_objects: for obj in context.selected_objects:
obj.color = context.scene.BIMMiscProperties.override_colour obj.color = props.override_colour
area = next(area for area in context.screen.areas if area.type == "VIEW_3D") assert (space := tool.Blender.get_view3d_space())
area.spaces[0].shading.color_type = "OBJECT" space.shading.color_type = "OBJECT"
return {"FINISHED"} return {"FINISHED"}
@@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>. # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from typing import TYPE_CHECKING
from bpy.props import ( from bpy.props import (
FloatVectorProperty, FloatVectorProperty,
IntProperty, IntProperty,
@@ -32,3 +34,7 @@ class BIMMiscProperties(PropertyGroup):
override_colour: FloatVectorProperty( override_colour: FloatVectorProperty(
name="Override Colour", subtype="COLOR", default=(1, 0, 0, 1), min=0.0, max=1.0, size=4 name="Override Colour", subtype="COLOR", default=(1, 0, 0, 1), min=0.0, max=1.0, size=4
) )
if TYPE_CHECKING:
total_storeys: int
override_colour: tuple[float, float, float, float]
+3 -1
View File
@@ -18,6 +18,8 @@
import bpy import bpy
import bonsai.tool as tool
class BIM_PT_misc_utilities(bpy.types.Panel): class BIM_PT_misc_utilities(bpy.types.Panel):
bl_idname = "BIM_PT_misc_utilities" bl_idname = "BIM_PT_misc_utilities"
@@ -30,7 +32,7 @@ class BIM_PT_misc_utilities(bpy.types.Panel):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
props = context.scene.BIMMiscProperties props = tool.Misc.get_misc_props()
row = layout.split(factor=0.2, align=True) row = layout.split(factor=0.2, align=True)
row.prop(props, "override_colour", text="") row.prop(props, "override_colour", text="")
row.operator("bim.set_override_colour") row.operator("bim.set_override_colour")
@@ -31,7 +31,7 @@ import bonsai.tool as tool
def update_sverchok_modifier(context): def update_sverchok_modifier(context):
obj = context.active_object obj = context.active_object
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
psets = ifcopenshell.util.element.get_psets(element) psets = ifcopenshell.util.element.get_psets(element)
pset = psets.get("BBIM_Sverchok", None) pset = psets.get("BBIM_Sverchok", None)
@@ -72,7 +72,7 @@ class CreateNewSverchokGraph(bpy.types.Operator, tool.Ifc.Operator):
import sverchok import sverchok
obj = context.active_object obj = context.active_object
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
node_group = bpy.data.node_groups.new("IfcNodeTree", type="SverchCustomTreeType") node_group = bpy.data.node_groups.new("IfcNodeTree", type="SverchCustomTreeType")
plane = node_group.nodes.new(type="SvPlaneNodeMk3") plane = node_group.nodes.new(type="SvPlaneNodeMk3")
@@ -96,7 +96,7 @@ class DeleteSverchokGraph(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
obj = context.active_object obj = context.active_object
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
bpy.data.node_groups.remove(props.node_group) bpy.data.node_groups.remove(props.node_group)
return {"FINISHED"} return {"FINISHED"}
@@ -113,7 +113,8 @@ class UpdateDataFromSverchok(bpy.types.Operator, tool.Ifc.Operator):
bl_options = {"REGISTER"} bl_options = {"REGISTER"}
def invoke(self, context, event): def invoke(self, context, event):
if not context.active_object.BIMSverchokProperties.node_group: props = tool.Model.get_sverchok_props(context.active_object)
if not props.node_group:
return context.window_manager.invoke_props_dialog(self) return context.window_manager.invoke_props_dialog(self)
return self._execute(context) return self._execute(context)
@@ -124,7 +125,7 @@ class UpdateDataFromSverchok(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context): def _execute(self, context):
obj = context.active_object obj = context.active_object
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
node_group = props.node_group node_group = props.node_group
if node_group: if node_group:
@@ -196,7 +197,7 @@ class ImportSverchokGraph(bpy.types.Operator, tool.Ifc.Operator, ImportHelper):
importer = sverchok.utils.sv_json_import.JSONImporter.init_from_path(self.filepath) importer = sverchok.utils.sv_json_import.JSONImporter.init_from_path(self.filepath)
obj = context.active_object obj = context.active_object
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
node_group = context.scene.io_panel_properties.import_tree node_group = context.scene.io_panel_properties.import_tree
if not node_group: if not node_group:
@@ -234,7 +235,7 @@ class ExportSverchokGraph(bpy.types.Operator, tool.Ifc.Operator, ExportHelper):
import sverchok import sverchok
obj = context.active_object obj = context.active_object
props = obj.BIMSverchokProperties props = tool.Model.get_sverchok_props(obj)
ng = props.node_group ng = props.node_group
destination_path = self.filepath destination_path = self.filepath
if not destination_path.lower().endswith(".json"): if not destination_path.lower().endswith(".json"):
@@ -273,7 +274,8 @@ class ExportSverchokGraph(bpy.types.Operator, tool.Ifc.Operator, ExportHelper):
return {"FINISHED"} return {"FINISHED"}
def draw(self, context): def draw(self, context):
graph_name = context.active_object.BIMSverchokProperties.node_group.name props = tool.Model.get_sverchok_props(context.active_object)
graph_name = props.node_group.name
self.layout.label(text=f'Save node tree "{graph_name}" into json:') self.layout.label(text=f'Save node tree "{graph_name}" into json:')
col = self.layout.column(heading="Options") # new syntax in >= 2.90 col = self.layout.column(heading="Options") # new syntax in >= 2.90
+1 -1
View File
@@ -360,7 +360,7 @@ class BIM_PT_sverchok(bpy.types.Panel):
self.layout.label(text="Requires Sverchok Add-on", icon="ERROR") self.layout.label(text="Requires Sverchok Add-on", icon="ERROR")
return return
props = context.active_object.BIMSverchokProperties props = tool.Model.get_sverchok_props(context.active_object)
self.layout.prop_search(props, "node_group", bpy.data, "node_groups") self.layout.prop_search(props, "node_group", bpy.data, "node_groups")
self.layout.operator("bim.create_new_sverchok_graph", icon="ADD") self.layout.operator("bim.create_new_sverchok_graph", icon="ADD")
@@ -215,8 +215,6 @@ class NestDecorator:
self.draw_batch("LINES", line_z, color, [(0, 1)]) self.draw_batch("LINES", line_z, color, [(0, 1)])
else: else:
self.draw_batch("POINTS", [location], color) self.draw_batch("POINTS", [location], color)
# if context.scene.BIMNestProperties.in_aggregate_mode:
# return
components = ifcopenshell.util.element.get_components(tool.Ifc.get_entity(nest)) components = ifcopenshell.util.element.get_components(tool.Ifc.get_entity(nest))
components_objs = [tool.Ifc.get_object(p) for p in components] components_objs = [tool.Ifc.get_object(p) for p in components]
components_objs.append(nest) components_objs.append(nest)
@@ -188,7 +188,7 @@ class BIMResourceProperties(PropertyGroup):
@property @property
def productivity(self) -> "BIMResourceProductivity": def productivity(self) -> "BIMResourceProductivity":
assert bpy.context.scene assert bpy.context.scene
productivity = bpy.context.scene.BIMResourceProductivity productivity = bpy.context.scene.BIMResourceProductivity # pyright: ignore[reportAttributeAccessIssue]
assert isinstance(productivity, BIMResourceProductivity) assert isinstance(productivity, BIMResourceProductivity)
return productivity return productivity
@@ -1053,8 +1053,8 @@ class ColourByProperty(Operator):
colourscheme[str(values[index])]["total"] += 1 colourscheme[str(values[index])]["total"] += 1
obj.color = (*tool.Search.get_quantitative_palette(palette, value, min_value, max_value), 1) obj.color = (*tool.Search.get_quantitative_palette(palette, value, min_value, max_value), 1)
if areas := [a for a in context.screen.areas if a.type == "VIEW_3D"]: assert (space := tool.Blender.get_view3d_space())
areas[0].spaces[0].shading.color_type = "OBJECT" space.shading.color_type = "OBJECT"
props.colourscheme.clear() props.colourscheme.clear()
@@ -1078,16 +1078,18 @@ class ColourByProperty(Operator):
return (1, value) return (1, value)
def store_state(self, context): def store_state(self, context):
if areas := [a for a in context.screen.areas if a.type == "VIEW_3D"]: if space := tool.Blender.get_view3d_space():
self.transaction_data = {"area": areas[0], "color_type": areas[0].spaces[0].shading.color_type} self.transaction_data = {"color_type": space.shading.color_type}
def rollback(self, data): def rollback(self, data):
if data: if data:
data["area"].spaces[0].shading.color_type = data["color_type"] assert (space := tool.Blender.get_view3d_space())
space.shading.color_type = data["color_type"]
def commit(self, data): def commit(self, data):
if data: if data:
data["area"].spaces[0].shading.color_type = "OBJECT" assert (space := tool.Blender.get_view3d_space())
space.shading.color_type = "OBJECT"
class SelectByProperty(Operator): class SelectByProperty(Operator):
@@ -512,7 +512,7 @@ class SetContainerVisibility(bpy.types.Operator):
containers -= set(tool.Ifc.get().by_type("IfcSpatialZone")) containers -= set(tool.Ifc.get().by_type("IfcSpatialZone"))
for container in containers: for container in containers:
if obj := tool.Ifc.get_object(container): if obj := tool.Ifc.get_object(container):
if collection := obj.BIMObjectProperties.collection: if collection := tool.Blender.get_object_bim_props(obj).collection:
collection.hide_viewport = True collection.hide_viewport = True
should_hide = False should_hide = False
else: else:
@@ -523,7 +523,7 @@ class SetContainerVisibility(bpy.types.Operator):
while queue: while queue:
container = queue.pop() container = queue.pop()
if obj := tool.Ifc.get_object(container): if obj := tool.Ifc.get_object(container):
if collection := obj.BIMObjectProperties.collection: if collection := tool.Blender.get_object_bim_props(obj).collection:
collection.hide_viewport = should_hide collection.hide_viewport = should_hide
if self.should_include_children: if self.should_include_children:
queue.extend(ifcopenshell.util.element.get_parts(container)) queue.extend(ifcopenshell.util.element.get_parts(container))
+4 -1
View File
@@ -102,7 +102,10 @@ def update_shading_styles(self: "BIMStylesProperties", context: bpy.types.Contex
def update_shader_graph(self: Union["Texture", "BIMStylesProperties"], context: bpy.types.Context) -> None: def update_shader_graph(self: Union["Texture", "BIMStylesProperties"], context: bpy.types.Context) -> None:
props = self.id_data.BIMStylesProperties if isinstance(self, Texture) else self if isinstance(self, Texture):
props = tool.Style.get_style_props()
else:
props = self
if not props.update_graph: if not props.update_graph:
return return
+2 -2
View File
@@ -70,7 +70,7 @@ class SetTab(bpy.types.Operator):
if context.area.spaces.active.search_filter: if context.area.spaces.active.search_filter:
return {"FINISHED"} return {"FINISHED"}
tool.Blender.setup_tabs() tool.Blender.setup_tabs()
aprops = tool.Blender.get_area_props(context) aprops = tool.Blender.get_active_area_props(context)
aprops.tab = self.tab aprops.tab = self.tab
return {"FINISHED"} return {"FINISHED"}
@@ -85,7 +85,7 @@ class SwitchTab(bpy.types.Operator):
if context.area.spaces.active.search_filter: if context.area.spaces.active.search_filter:
return {"FINISHED"} return {"FINISHED"}
tool.Blender.setup_tabs() tool.Blender.setup_tabs()
aprops = tool.Blender.get_area_props(context) aprops = tool.Blender.get_active_area_props(context)
aprops.tab = aprops.alt_tab aprops.tab = aprops.alt_tab
return {"FINISHED"} return {"FINISHED"}
+2 -1
View File
@@ -59,7 +59,8 @@ def update_is_visible(self: "BIMTabVisibility", context: bpy.types.Context) -> N
def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> None: def update_global_tab(self: "BIMTabProperties", context: bpy.types.Context) -> None:
tool.Blender.setup_tabs() tool.Blender.setup_tabs()
screen = context.id_data screen = context.id_data
aprops = screen.BIMAreaProperties[screen.areas[:].index(context.area)] assert isinstance(screen, bpy.types.Screen)
aprops = tool.Blender.get_area_props(screen)[screen.areas[:].index(context.area)]
aprops.tab = self.tab aprops.tab = self.tab
+1 -1
View File
@@ -1031,7 +1031,7 @@ class BIM_PT_tabs(Panel):
def draw(self, context): def draw(self, context):
if not UIData.is_loaded: if not UIData.is_loaded:
UIData.load() UIData.load()
aprops = tool.Blender.get_area_props(context) aprops = tool.Blender.get_active_area_props(context)
addon_prefs = tool.Blender.get_addon_preferences() addon_prefs = tool.Blender.get_addon_preferences()
row = self.layout.row() row = self.layout.row()
+47 -19
View File
@@ -74,7 +74,13 @@ if TYPE_CHECKING:
BIMSolarProperties, BIMSolarProperties,
RadianceExporterProperties, RadianceExporterProperties,
) )
from bonsai.bim.prop import BIMObjectProperties, BIMProperties from bonsai.bim.prop import (
BIMAreaProperties,
BIMCollectionProperties,
BIMObjectProperties,
BIMProperties,
BIMTabProperties,
)
T = TypeVar("T") T = TypeVar("T")
@@ -138,17 +144,20 @@ class Blender(bonsai.core.tool.Blender):
space.region_3d.view_perspective = "CAMERA" space.region_3d.view_perspective = "CAMERA"
@classmethod @classmethod
def get_area_props(cls, context: bpy.types.Context) -> bpy.types.PropertyGroup: def get_active_area_props(cls, context: bpy.types.Context) -> BIMAreaProperties | BIMTabProperties:
FULLSCREEN_SUFFIX = "-nonnormal" # Ctrl-space temporary fullscreen
assert (screen := context.screen)
try: try:
if context.screen.name.endswith("-nonnormal"): # Ctrl-space temporary fullscreen if screen.name.endswith(FULLSCREEN_SUFFIX):
screen = bpy.data.screens[context.screen.name.removesuffix("-nonnormal")] screen = bpy.data.screens[screen.name.removesuffix(FULLSCREEN_SUFFIX)]
# The original area object has its type changed to "EMPTY" apparently # The original area object has its type changed to "EMPTY" apparently
index = [a.type for a in screen.areas].index("EMPTY") index = [a.type for a in screen.areas].index("EMPTY")
return screen.BIMAreaProperties[index] return cls.get_area_props(screen)[index]
return context.screen.BIMAreaProperties[context.screen.areas[:].index(context.area)] assert (area := context.area)
return cls.get_area_props(screen)[screen.areas[:].index(area)]
except IndexError: except IndexError:
# Fallback in case areas aren't setup yet. # Fallback in case areas aren't setup yet.
return context.screen.BIMTabProperties return cls.get_tab_props(screen)
@classmethod @classmethod
def set_active_object(cls, obj: bpy.types.Object) -> None: def set_active_object(cls, obj: bpy.types.Object) -> None:
@@ -165,15 +174,16 @@ class Blender(bonsai.core.tool.Blender):
def setup_tabs(cls) -> None: def setup_tabs(cls) -> None:
# https://blender.stackexchange.com/questions/140644/how-can-make-the-state-of-a-boolean-property-relative-to-the-3d-view-area # https://blender.stackexchange.com/questions/140644/how-can-make-the-state-of-a-boolean-property-relative-to-the-3d-view-area
for screen in bpy.data.screens: for screen in bpy.data.screens:
if len(screen.BIMAreaProperties) == 20: area_props = cls.get_area_props(screen)
if len(area_props) == 20:
continue continue
screen.BIMAreaProperties.clear() area_props.clear()
for i in range(20): # 20 is an arbitrary value of split areas for i in range(20): # 20 is an arbitrary value of split areas
screen.BIMAreaProperties.add() area_props.add()
@classmethod @classmethod
def should_show_panel(cls, context: bpy.types.Context, tab: str, panel: str) -> bool: def should_show_panel(cls, context: bpy.types.Context, tab: str, panel: str) -> bool:
aprops = cls.get_area_props(context) aprops = cls.get_active_area_props(context)
if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter: if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter:
return True return True
if (is_bookmark_tab := aprops.tab == "BOOKMARK") or aprops.tab == tab: if (is_bookmark_tab := aprops.tab == "BOOKMARK") or aprops.tab == tab:
@@ -185,6 +195,7 @@ class Blender(bonsai.core.tool.Blender):
return True return True
elif panel_visibility.is_visible: elif panel_visibility.is_visible:
return True return True
return False
@classmethod @classmethod
def is_default_scene(cls) -> bool: def is_default_scene(cls) -> bool:
@@ -330,7 +341,8 @@ class Blender(bonsai.core.tool.Blender):
@classmethod @classmethod
def get_view3d_area(cls) -> Union[bpy.types.Area, None]: def get_view3d_area(cls) -> Union[bpy.types.Area, None]:
for window in bpy.context.window_manager.windows: assert (wm := bpy.context.window_manager)
for window in wm.windows:
for area in window.screen.areas: for area in window.screen.areas:
if area.type == "VIEW_3D": if area.type == "VIEW_3D":
return area return area
@@ -338,7 +350,9 @@ class Blender(bonsai.core.tool.Blender):
@classmethod @classmethod
def get_view3d_space(cls) -> Union[bpy.types.SpaceView3D, None]: def get_view3d_space(cls) -> Union[bpy.types.SpaceView3D, None]:
if area := cls.get_view3d_area(): if area := cls.get_view3d_area():
return area.spaces.active space = area.spaces.active
assert isinstance(space, bpy.types.SpaceView3D)
return space
@classmethod @classmethod
def get_blender_prop_default_value(cls, props: bpy.types.bpy_struct, prop_name: str) -> Any: def get_blender_prop_default_value(cls, props: bpy.types.bpy_struct, prop_name: str) -> Any:
@@ -1489,7 +1503,7 @@ class Blender(bonsai.core.tool.Blender):
def override_scene_panel(cls, original_panel: bpy.types.Panel) -> None: def override_scene_panel(cls, original_panel: bpy.types.Panel) -> None:
@classmethod @classmethod
def poll_check_blender_tab(cls, context): def poll_check_blender_tab(cls, context):
aprops = tool.Blender.get_area_props(context) aprops = tool.Blender.get_active_area_props(context)
if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter: if aprops.path_from_id() == "BIMAreaProperties" and context.area.spaces.active.search_filter:
return True return True
return aprops.tab == "BLENDER" return aprops.tab == "BLENDER"
@@ -1829,6 +1843,18 @@ class Blender(bonsai.core.tool.Blender):
assert (scene := bpy.context.scene) assert (scene := bpy.context.scene)
return scene.BIMProperties # pyright: ignore[reportAttributeAccessIssue] return scene.BIMProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod
def get_area_props(cls, screen: bpy.types.Screen) -> bpy.types.bpy_prop_collection_idprop[BIMAreaProperties]:
return screen.BIMAreaProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod
def get_tab_props(cls, screen: bpy.types.Screen) -> BIMTabProperties:
return screen.BIMTabProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod
def get_collection_props(cls, collection: bpy.types.Collection) -> BIMCollectionProperties:
return collection.BIMCollectionProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_object_bim_props(cls, obj: bpy.types.Object) -> BIMObjectProperties: def get_object_bim_props(cls, obj: bpy.types.Object) -> BIMObjectProperties:
return obj.BIMObjectProperties # pyright: ignore[reportAttributeAccessIssue] return obj.BIMObjectProperties # pyright: ignore[reportAttributeAccessIssue]
@@ -1882,19 +1908,21 @@ class Blender(bonsai.core.tool.Blender):
@classmethod @classmethod
def clear_undo_history(cls) -> None: def clear_undo_history(cls) -> None:
"""Clears the Blender history, Bonsai history, and IfcOpenShell history""" """Clears the Blender history, Bonsai history, and IfcOpenShell history"""
old_undo_steps = bpy.context.preferences.edit.undo_steps assert (preferences := bpy.context.preferences)
bpy.context.preferences.edit.undo_steps = 2 old_undo_steps = preferences.edit.undo_steps
preferences.edit.undo_steps = 2
for i in range(3): for i in range(3):
bpy.ops.ed.undo_push(message="Undo history cleared") bpy.ops.ed.undo_push(message="Undo history cleared")
bpy.context.preferences.edit.undo_steps = old_undo_steps preferences.edit.undo_steps = old_undo_steps
tool.Ifc.clear_history() tool.Ifc.clear_history()
old_history_size = tool.Ifc.get().history_size old_history_size = tool.Ifc.get().history_size
tool.Ifc.get().set_history_size(0) tool.Ifc.get().set_history_size(0)
tool.Ifc.get().set_history_size(old_history_size) tool.Ifc.get().set_history_size(old_history_size)
@classmethod @classmethod
def get_unit_scale(cls): def get_unit_scale(cls) -> float:
unit_length = bpy.context.scene.unit_settings.length_unit assert (scene := bpy.context.scene)
unit_length = scene.unit_settings.length_unit
unit_scale = 1.0 unit_scale = 1.0
if unit_length == "CENTIMETERS": if unit_length == "CENTIMETERS":
unit_scale = 0.01 unit_scale = 0.01
+2 -1
View File
@@ -157,7 +157,8 @@ class Collector(bonsai.core.tool.Collector):
return return
collection = bpy.data.collections.new(obj.name) collection = bpy.data.collections.new(obj.name)
props.collection = collection props.collection = collection
collection.BIMCollectionProperties.obj = obj collection_props = tool.Blender.get_collection_props(collection)
collection_props.obj = obj
return collection return collection
@classmethod @classmethod
+10 -1
View File
@@ -16,7 +16,9 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>. # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from typing import Union from __future__ import annotations
from typing import TYPE_CHECKING, Union
import bmesh import bmesh
import bpy import bpy
@@ -30,8 +32,15 @@ import bonsai.core.root
import bonsai.core.tool import bonsai.core.tool
import bonsai.tool as tool import bonsai.tool as tool
if TYPE_CHECKING:
from bonsai.bim.module.misc.prop import BIMMiscProperties
class Misc(bonsai.core.tool.Misc): class Misc(bonsai.core.tool.Misc):
@classmethod
def get_misc_props(cls) -> BIMMiscProperties:
return bpy.context.scene.BIMMiscProperties
@classmethod @classmethod
def get_object_storey(cls, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]: def get_object_storey(cls, obj: bpy.types.Object) -> Union[ifcopenshell.entity_instance, None]:
element = tool.Ifc.get_entity(obj) element = tool.Ifc.get_entity(obj)
+10 -5
View File
@@ -76,6 +76,7 @@ if TYPE_CHECKING:
BIMRailingProperties, BIMRailingProperties,
BIMRoofProperties, BIMRoofProperties,
BIMStairProperties, BIMStairProperties,
BIMSverchokProperties,
BIMWindowProperties, BIMWindowProperties,
) )
@@ -87,23 +88,27 @@ class Model(bonsai.core.tool.Model):
@classmethod @classmethod
def get_door_props(cls, obj: bpy.types.Object) -> BIMDoorProperties: def get_door_props(cls, obj: bpy.types.Object) -> BIMDoorProperties:
return obj.BIMDoorProperties return obj.BIMDoorProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_window_props(cls, obj: bpy.types.Object) -> BIMWindowProperties: def get_window_props(cls, obj: bpy.types.Object) -> BIMWindowProperties:
return obj.BIMWindowProperties return obj.BIMWindowProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_stair_props(cls, obj: bpy.types.Object) -> BIMStairProperties: def get_stair_props(cls, obj: bpy.types.Object) -> BIMStairProperties:
return obj.BIMStairProperties return obj.BIMStairProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_roof_props(cls, obj: bpy.types.Object) -> BIMRoofProperties: def get_roof_props(cls, obj: bpy.types.Object) -> BIMRoofProperties:
return obj.BIMRoofProperties return obj.BIMRoofProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_railing_props(cls, obj: bpy.types.Object) -> BIMRailingProperties: def get_railing_props(cls, obj: bpy.types.Object) -> BIMRailingProperties:
return obj.BIMRailingProperties return obj.BIMRailingProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod
def get_sverchok_props(cls, obj: bpy.types.Object) -> BIMSverchokProperties:
return obj.BIMSverchokProperties # pyright: ignore[reportAttributeAccessIssue]
@classmethod @classmethod
def get_array_props(cls, obj: bpy.types.Object) -> BIMArrayProperties: def get_array_props(cls, obj: bpy.types.Object) -> BIMArrayProperties:
+1 -2
View File
@@ -124,8 +124,7 @@ class Nest(bonsai.core.tool.Nest):
@classmethod @classmethod
def disable_nest_mode(cls): def disable_nest_mode(cls):
context = bpy.context props = cls.get_nest_props()
props = context.scene.BIMNestProperties
for obj_prop in props.not_editing_objects: for obj_prop in props.not_editing_objects:
obj = obj_prop.obj obj = obj_prop.obj
obj.original.display_type = obj_prop.previous_display_type obj.original.display_type = obj_prop.previous_display_type