mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-12 22:43:41 +00:00
WIP: Input panel receives x and y inputs from the keyboard
This commit is contained in:
committed by
Bruno Perdigão
parent
55552770a6
commit
fcfc070825
@@ -332,15 +332,21 @@ class WallPolylineDecorator:
|
|||||||
cls.input_type = input_type
|
cls.input_type = input_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def calculate_distance_and_angle(cls, context):
|
def calculate_distance_and_angle(cls, context, is_input_on):
|
||||||
try:
|
try:
|
||||||
polyline_data = context.scene.BIMModelProperties.polyline_point
|
polyline_data = context.scene.BIMModelProperties.polyline_point
|
||||||
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
snap_prop = context.scene.BIMModelProperties.snap_mouse_point[0]
|
||||||
last_point_data = polyline_data[len(polyline_data) - 1]
|
last_point_data = polyline_data[len(polyline_data) - 1]
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
last_point = Vector((last_point_data.x, last_point_data.y, last_point_data.z))
|
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
|
distance = (snap_vector - last_point).length # TODO get height from default container
|
||||||
x_axis_edge = (Vector((0, 0, 0,)), Vector((1, 0, 0,)))
|
x_axis_edge = (Vector((0, 0, 0,)), Vector((1, 0, 0,)))
|
||||||
@@ -353,6 +359,9 @@ class WallPolylineDecorator:
|
|||||||
cls.input_panel['D'] = str(round(distance, 4))
|
cls.input_panel['D'] = str(round(distance, 4))
|
||||||
cls.input_panel['A'] = str(round(angle, 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):
|
def draw_batch(self, shader_type, content_pos, color, indices=None):
|
||||||
shader = self.line_shader if shader_type == "LINES" else self.shader
|
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
|
# When a point is above the plane it projects the point
|
||||||
# to the plane and creates a line
|
# to the plane and creates a line
|
||||||
if snap_prop.snap_type != "Plane" and snap_prop.z != 0:
|
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
|
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)
|
self.draw_batch("POINTS", projection_point, decorator_color_unselected)
|
||||||
edges = [[0, 1]]
|
edges = [[0, 1]]
|
||||||
@@ -436,4 +445,7 @@ class WallPolylineDecorator:
|
|||||||
# Line between last polyline point and mouse
|
# Line between last polyline point and mouse
|
||||||
|
|
||||||
edges = [[0, 1]]
|
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)
|
||||||
|
|||||||
@@ -535,15 +535,13 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
|
|
||||||
|
|
||||||
def modal(self, context, event):
|
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':
|
if event.type == 'MOUSEMOVE':
|
||||||
self.mousemove_count += 1
|
self.mousemove_count += 1
|
||||||
tool.Blender.update_viewport()
|
tool.Blender.update_viewport()
|
||||||
WallPolylineDecorator.set_mouse_position(context, event)
|
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:
|
else:
|
||||||
self.mousemove_count = 0
|
self.mousemove_count = 0
|
||||||
|
|
||||||
@@ -568,7 +566,6 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
tool.Blender.update_viewport()
|
tool.Blender.update_viewport()
|
||||||
|
|
||||||
if event.value == 'PRESS' and event.type == 'I':
|
if event.value == 'PRESS' and event.type == 'I':
|
||||||
self.input_panel = {'X': '', 'Y': '', 'D': '', 'A': ''}
|
|
||||||
self.is_input_on = True
|
self.is_input_on = True
|
||||||
|
|
||||||
if self.is_input_on:
|
if self.is_input_on:
|
||||||
@@ -583,23 +580,15 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
self.number_input.append(event.ascii)
|
self.number_input.append(event.ascii)
|
||||||
self.number_output = ''.join(self.number_input)
|
self.number_output = ''.join(self.number_input)
|
||||||
self.input_panel[self.input_type] = self.number_output
|
self.input_panel[self.input_type] = self.number_output
|
||||||
print("PANEL", self.input_panel)
|
|
||||||
WallPolylineDecorator.set_input_panel(self.input_panel, self.input_type)
|
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()
|
tool.Blender.update_viewport()
|
||||||
print(self.number_output)
|
print(self.number_output)
|
||||||
|
|
||||||
if event.value == 'PRESS' and event.type in {'RET', 'NUMPAD_ENTER'}:
|
if event.value == 'PRESS' and event.type in {'RET', 'NUMPAD_ENTER'}:
|
||||||
if not None in self.input_value_xy:
|
tool.Snaping.insert_polyline_point(float(self.input_panel['X']), float(self.input_panel['Y']))
|
||||||
tool.Snaping.insert_polyline_point(self.input_value_xy[0], self.input_value_xy[1])
|
tool.Blender.update_viewport()
|
||||||
tool.Blender.update_viewport()
|
self.is_input_on = False
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
if event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}:
|
if event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}:
|
||||||
return {'PASS_THROUGH'}
|
return {'PASS_THROUGH'}
|
||||||
@@ -623,7 +612,6 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
self.visible_objs = self.get_visible_objects(context)
|
self.visible_objs = self.get_visible_objects(context)
|
||||||
for obj in self.visible_objs: # TODO check if matrix is needed here
|
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_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)
|
context.window_manager.modal_handler_add(self)
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user