diff --git a/src/bonsai/bonsai/bim/module/model/decorator.py b/src/bonsai/bonsai/bim/module/model/decorator.py index 7779bd067b..2a9fac1812 100644 --- a/src/bonsai/bonsai/bim/module/model/decorator.py +++ b/src/bonsai/bonsai/bim/module/model/decorator.py @@ -1211,3 +1211,63 @@ class WallAxisDecorator: self.draw_batch("LINES", verts, selected_elements_color, [(0, 1)]) verts = [tuple(list(v) + [0.0]) for v in axis["side"]] self.draw_batch("LINES", verts, unselected_elements_color, [(0, 1)]) + + +class SlabDirectionDecorator: + is_installed = False + handlers = [] + + @classmethod + def install(cls, context): + if cls.is_installed: + cls.uninstall() + handler = cls() + cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_wall_axis, (context,), "WINDOW", "POST_VIEW")) + cls.is_installed = True + + @classmethod + def uninstall(cls): + for handler in cls.handlers: + try: + SpaceView3D.draw_handler_remove(handler, "WINDOW") + except ValueError: + pass + cls.is_installed = False + + def draw_batch(self, shader_type, content_pos, color, indices=None): + shader = self.line_shader if shader_type == "LINES" else self.shader + batch = batch_for_shader(shader, shader_type, {"pos": content_pos}, indices=indices) + shader.uniform_float("color", color) + batch.draw(shader) + + def draw_wall_axis(self, context): + self.addon_prefs = tool.Blender.get_addon_preferences() + selected_elements_color = self.addon_prefs.decorator_color_selected + unselected_elements_color = self.addon_prefs.decorator_color_unselected + special_elements_color = self.addon_prefs.decorator_color_special + decorator_color_background = self.addon_prefs.decorator_color_background + + gpu.state.point_size_set(6) + gpu.state.blend_set("ALPHA") + + self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR") + self.line_shader.bind() # required to be able to change uniforms of the shader + self.line_shader.uniform_float("viewportSize", (context.region.width, context.region.height)) + self.shader = gpu.shader.from_builtin("UNIFORM_COLOR") + self.line_shader.uniform_float("lineWidth", 2.0) + dir = [(0, 0, 0), (0, 0.5, 0), (-0.25, 0.15, 0), (0.25, 0.15, 0)] + base = [(-2, 0, 0), (2, 0, 0)] + obj = context.active_object + if not obj: + return + element = tool.Ifc.get_entity(obj) + if (element + and ( + element.is_a("IfcSlab") + or element.is_a("IfcRoof") + ) + ): + dir = [obj.matrix_world @ Vector(d) for d in dir] + base = [obj.matrix_world @ Vector(d) for d in base] + self.draw_batch("LINES", dir, selected_elements_color, [(0, 1), (1, 2), (1, 3)]) + self.draw_batch("LINES", base, selected_elements_color, [(0, 1)])