Complement changes from abd05e939a

This commit is contained in:
Bruno Perdigão
2025-01-18 11:48:37 -03:00
parent a57a0eb4eb
commit c07c2d7692
4 changed files with 48 additions and 33 deletions
+6 -2
View File
@@ -33,6 +33,7 @@ from bonsai.bim.module.model.workspace import LIST_OF_TOOLS, TOOLS_TO_CLASSES_MA
from bonsai.bim.module.aggregate.decorator import AggregateDecorator from bonsai.bim.module.aggregate.decorator import AggregateDecorator
from bonsai.bim.module.georeference.decorator import GeoreferenceDecorator from bonsai.bim.module.georeference.decorator import GeoreferenceDecorator
from bonsai.bim.module.model.decorator import WallAxisDecorator, SlabDirectionDecorator from bonsai.bim.module.model.decorator import WallAxisDecorator, SlabDirectionDecorator
from bonsai.bim.module.nest.decorator import NestDecorator
from mathutils import Vector from mathutils import Vector
from math import cos, degrees from math import cos, degrees
from typing import Union, Callable from typing import Union, Callable
@@ -323,11 +324,14 @@ def load_post(scene):
# Bonsai overlays # Bonsai overlays
georeference_props = bpy.context.scene.BIMGeoreferenceProperties georeference_props = bpy.context.scene.BIMGeoreferenceProperties
aggregate_props = bpy.context.scene.BIMAggregateProperties aggregate_props = bpy.context.scene.BIMAggregateProperties
nest_props = bpy.context.scene.BIMNestProperties
model_props = bpy.context.scene.BIMModelProperties model_props = bpy.context.scene.BIMModelProperties
if aggregate_props.aggregate_decorator:
AggregateDecorator.install(bpy.context)
if georeference_props.should_visualise: if georeference_props.should_visualise:
GeoreferenceDecorator.install(bpy.context) GeoreferenceDecorator.install(bpy.context)
if aggregate_props.aggregate_decorator:
AggregateDecorator.install(bpy.context)
if nest_props.nest_decorator:
NestDecorator.install(bpy.context)
if model_props.show_wall_axis: if model_props.show_wall_axis:
WallAxisDecorator.install(bpy.context) WallAxisDecorator.install(bpy.context)
if model_props.show_slab_direction: if model_props.show_slab_direction:
@@ -167,6 +167,8 @@ class AggregateDecorator:
theme = context.preferences.themes.items()[0][1] theme = context.preferences.themes.items()[0][1]
selected_object_color = (*theme.view_3d.object_active, 1) selected_object_color = (*theme.view_3d.object_active, 1)
self.shader = gpu.shader.from_builtin("UNIFORM_COLOR")
self.shader.bind()
self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR") self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR")
self.line_shader.bind() self.line_shader.bind()
# POLYLINE_UNIFORM_COLOR specific uniforms # POLYLINE_UNIFORM_COLOR specific uniforms
+32 -26
View File
@@ -86,7 +86,7 @@ class NestDecorator:
if cls.is_installed: if cls.is_installed:
cls.uninstall() cls.uninstall()
handler = cls() handler = cls()
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_aggregate, (context,), "WINDOW", "POST_VIEW")) cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_nest, (context,), "WINDOW", "POST_VIEW"))
cls.is_installed = True cls.is_installed = True
@classmethod @classmethod
@@ -153,8 +153,8 @@ class NestDecorator:
shader.uniform_float("color", color) shader.uniform_float("color", color)
batch.draw(shader) batch.draw(shader)
def draw_aggregate(self, context): def draw_nest(self, context):
if context.scene.BIMAggregateProperties.in_aggregate_mode: if context.scene.BIMNestProperties.in_nest_mode:
return return
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
decorator_color_special = self.addon_prefs.decorator_color_special decorator_color_special = self.addon_prefs.decorator_color_special
@@ -165,11 +165,13 @@ class NestDecorator:
theme = context.preferences.themes.items()[0][1] theme = context.preferences.themes.items()[0][1]
selected_object_color = (*theme.view_3d.object_active, 1) selected_object_color = (*theme.view_3d.object_active, 1)
self.shader = gpu.shader.from_builtin("UNIFORM_COLOR")
self.shader.bind()
self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR") self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR")
self.line_shader.bind() self.line_shader.bind()
# POLYLINE_UNIFORM_COLOR specific uniforms # POLYLINE_UNIFORM_COLOR specific uniforms
self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height)) self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height))
aggregates = [] nests = []
if not (selected_objects := context.selected_objects): if not (selected_objects := context.selected_objects):
return return
for obj in selected_objects: for obj in selected_objects:
@@ -177,35 +179,39 @@ class NestDecorator:
if not element or not element.is_a("IfcElement"): if not element or not element.is_a("IfcElement"):
return return
parts = ifcopenshell.util.element.get_parts(element) components = ifcopenshell.util.element.get_components(element)
if parts: if components:
aggregates.append(obj) nests.append(obj)
continue continue
aggregate = ifcopenshell.util.element.get_aggregate(element) nest = ifcopenshell.util.element.get_nest(element)
if aggregate: if nest:
aggregates.append(tool.Ifc.get_object(aggregate)) nests.append(tool.Ifc.get_object(nest))
aggregates = set(aggregates) nests = set(nests)
for aggregate in aggregates: for nest in nests:
self.line_shader.uniform_float("lineWidth", 1.0) self.line_shader.uniform_float("lineWidth", 1.0)
color = decorator_color_unselected color = decorator_color_unselected
if aggregate in selected_objects: if nest in selected_objects:
color = selected_object_color color = selected_object_color
size = aggregate.empty_display_size size = nest.empty_display_size
location = aggregate.location location = nest.location
line_x = (location - Vector((size, 0.0, 0.0)), location + Vector((size, 0.0, 0.0))) if nest.type == "EMPTY":
self.draw_batch("LINES", line_x, color, [(0, 1)]) line_x = (location - Vector((size, 0.0, 0.0)), location + Vector((size, 0.0, 0.0)))
line_y = (location - Vector((0.0, size, 0.0)), location + Vector((0.0, size, 0.0))) self.draw_batch("LINES", line_x, color, [(0, 1)])
self.draw_batch("LINES", line_y, color, [(0, 1)]) line_y = (location - Vector((0.0, size, 0.0)), location + Vector((0.0, size, 0.0)))
line_z = (location - Vector((0.0, 0.0, size)), location + Vector((0.0, 0.0, size))) self.draw_batch("LINES", line_y, color, [(0, 1)])
self.draw_batch("LINES", line_z, color, [(0, 1)]) line_z = (location - Vector((0.0, 0.0, size)), location + Vector((0.0, 0.0, size)))
if context.scene.BIMAggregateProperties.in_aggregate_mode: self.draw_batch("LINES", line_z, color, [(0, 1)])
return else:
parts = ifcopenshell.util.element.get_parts(tool.Ifc.get_entity(aggregate)) self.draw_batch("POINTS", [location], color)
parts_objs = [tool.Ifc.get_object(p) for p in parts] # if context.scene.BIMNestProperties.in_aggregate_mode:
# return
components = ifcopenshell.util.element.get_components(tool.Ifc.get_entity(nest))
components_objs = [tool.Ifc.get_object(p) for p in components]
components_objs.append(nest)
indices, edges = create_bounding_box(parts_objs) indices, edges = create_bounding_box(components_objs)
self.line_shader.uniform_float("lineWidth", 0.5) self.line_shader.uniform_float("lineWidth", 0.5)
self.draw_batch("LINES", indices, color, edges) self.draw_batch("LINES", indices, color, edges)
line = (Vector(indices[0]), location) line = (Vector(indices[0]), location)
+8 -5
View File
@@ -1209,8 +1209,9 @@ class BIM_PT_decorators_overlay(Panel):
view = context.space_data view = context.space_data
overlay = view.overlay overlay = view.overlay
geo_props = bpy.context.scene.BIMGeoreferenceProperties georeference_props = bpy.context.scene.BIMGeoreferenceProperties
agg_props = bpy.context.scene.BIMAggregateProperties aggregate_props = bpy.context.scene.BIMAggregateProperties
nest_props = bpy.context.scene.BIMNestProperties
model_props = bpy.context.scene.BIMModelProperties model_props = bpy.context.scene.BIMModelProperties
display_all = overlay.show_overlays display_all = overlay.show_overlays
@@ -1218,10 +1219,12 @@ class BIM_PT_decorators_overlay(Panel):
col.active = display_all col.active = display_all
row = col.row(align=True) row = col.row(align=True)
row.prop(geo_props, "should_visualise", text="Georeference") row.prop(georeference_props, "should_visualise", text="Georeference")
row.prop(geo_props, "visualization_scale", text="Size", slider=True) row.prop(georeference_props, "visualization_scale", text="Size", slider=True)
row = col.row(align=True) row = col.row(align=True)
row.prop(agg_props, "aggregate_decorator", text="Aggregate") row.prop(aggregate_props, "aggregate_decorator", text="Aggregate")
row = col.row(align=True)
row.prop(nest_props, "nest_decorator", text="Nest")
row = col.row(align=True) row = col.row(align=True)
row.prop(model_props, "show_wall_axis", text="Wall Axis") row.prop(model_props, "show_wall_axis", text="Wall Axis")
row = col.row(align=True) row = col.row(align=True)