From fcfc070825054d66bcb4b8a8c1ae0971e7c3ceee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Perdig=C3=A3o?= Date: Fri, 2 Aug 2024 17:29:00 -0300 Subject: [PATCH] WIP: Input panel receives x and y inputs from the keyboard --- .../blenderbim/bim/module/model/decorator.py | 20 ++++++++++++---- .../blenderbim/bim/module/model/wall.py | 24 +++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/model/decorator.py b/src/blenderbim/blenderbim/bim/module/model/decorator.py index 55cc1bae56..d71f9a1692 100644 --- a/src/blenderbim/blenderbim/bim/module/model/decorator.py +++ b/src/blenderbim/blenderbim/bim/module/model/decorator.py @@ -332,15 +332,21 @@ class WallPolylineDecorator: cls.input_type = input_type @classmethod - def calculate_distance_and_angle(cls, context): + def calculate_distance_and_angle(cls, context, is_input_on): try: polyline_data = context.scene.BIMModelProperties.polyline_point snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0] last_point_data = polyline_data[len(polyline_data) - 1] except: return + last_point = Vector((last_point_data.x, last_point_data.y, last_point_data.z)) - snap_vector = Vector((snap_prop.x, snap_prop.y, 0)) + + if is_input_on: + print("****", cls.input_panel) + snap_vector = Vector((float(cls.input_panel['X']), float(cls.input_panel['Y']), 0)) + else: + snap_vector = Vector((snap_prop.x, snap_prop.y, 0)) distance = (snap_vector - last_point).length # TODO get height from default container x_axis_edge = (Vector((0, 0, 0,)), Vector((1, 0, 0,))) @@ -352,7 +358,10 @@ class WallPolylineDecorator: cls.input_panel['Y'] = str(round(snap_vector.y, 4)) cls.input_panel['D'] = str(round(distance, 4)) cls.input_panel['A'] = str(round(angle, 4)) + + return cls.input_panel + return cls.input_panel def draw_batch(self, shader_type, content_pos, color, indices=None): shader = self.line_shader if shader_type == "LINES" else self.shader @@ -410,7 +419,7 @@ class WallPolylineDecorator: # When a point is above the plane it projects the point # to the plane and creates a line if snap_prop.snap_type != "Plane" and snap_prop.z != 0: - self.line_shader.uniform_float("lineWidth", 0.5) + self.line_shader.uniform_float("lineWidth", 1.0) projection_point = [Vector((snap_prop.x, snap_prop.y, 0))] # TODO get height from default container self.draw_batch("POINTS", projection_point, decorator_color_unselected) edges = [[0, 1]] @@ -436,4 +445,7 @@ class WallPolylineDecorator: # Line between last polyline point and mouse edges = [[0, 1]] - self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color_unselected, edges) + if snap_prop.snap_type != "Plane" and snap_prop.z != 0: + self.draw_batch("LINES", [polyline_points[-1]] + projection_point, decorator_color_unselected, edges) + else: + self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color_unselected, edges) diff --git a/src/blenderbim/blenderbim/bim/module/model/wall.py b/src/blenderbim/blenderbim/bim/module/model/wall.py index ef193a6c14..ff6a3efe3c 100644 --- a/src/blenderbim/blenderbim/bim/module/model/wall.py +++ b/src/blenderbim/blenderbim/bim/module/model/wall.py @@ -535,15 +535,13 @@ class DrawPolylineWall(bpy.types.Operator): def modal(self, context, event): - # NOTE Blender seem to have a bug where some event types are triggered twice. - # The use of self.action_count is to prevent that. However, it's necessary to - # check if this behavior happens in every OS. Reference: https://blender.stackexchange.com/questions/30985/modal-operator-double-keytrigger-release-triggered-twice-on-ubuntu if event.type == 'MOUSEMOVE': self.mousemove_count += 1 tool.Blender.update_viewport() WallPolylineDecorator.set_mouse_position(context, event) - WallPolylineDecorator.calculate_distance_and_angle(context) + self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) + self.is_input_on = False else: self.mousemove_count = 0 @@ -568,7 +566,6 @@ class DrawPolylineWall(bpy.types.Operator): tool.Blender.update_viewport() if event.value == 'PRESS' and event.type == 'I': - self.input_panel = {'X': '', 'Y': '', 'D': '', 'A': ''} self.is_input_on = True if self.is_input_on: @@ -583,23 +580,15 @@ class DrawPolylineWall(bpy.types.Operator): self.number_input.append(event.ascii) self.number_output = ''.join(self.number_input) self.input_panel[self.input_type] = self.number_output - print("PANEL", self.input_panel) WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type) + self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on) tool.Blender.update_viewport() print(self.number_output) if event.value == 'PRESS' and event.type in {'RET', 'NUMPAD_ENTER'}: - if not None in self.input_value_xy: - tool.Snaping.insert_polyline_point(self.input_value_xy[0], self.input_value_xy[1]) - tool.Blender.update_viewport() - self.is_input_on = False - if self.number_output and self.input_type == 'X': - print("-> ", float(self.number_output)) - self.input_value_xy[0] = float(self.number_output) - if self.number_output and self.input_type == 'Y': - print("-> ", float(self.number_output)) - self.input_value_xy[1] = float(self.number_output) - + tool.Snaping.insert_polyline_point(float(self.input_panel['X']), float(self.input_panel['Y'])) + tool.Blender.update_viewport() + self.is_input_on = False if event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}: return {'PASS_THROUGH'} @@ -623,7 +612,6 @@ class DrawPolylineWall(bpy.types.Operator): self.visible_objs = self.get_visible_objects(context) for obj in self.visible_objs: # TODO check if matrix is needed here self.objs_2d_bbox.append(self.get_objects_2d_bounding_boxes(context, obj)) - # self.objs_bvhs.append(self.get_bvh_objects_bounding_boxes(obj)) context.window_manager.modal_handler_add(self) return {'RUNNING_MODAL'} else: