mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
WIP: calculates x and y based on distance and angle. Accepts negative input
This commit is contained in:
committed by
Bruno Perdigão
parent
fcfc070825
commit
d995e010cf
@@ -343,16 +343,16 @@ class WallPolylineDecorator:
|
|||||||
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))
|
||||||
|
|
||||||
if is_input_on:
|
if is_input_on:
|
||||||
print("****", cls.input_panel)
|
|
||||||
snap_vector = Vector((float(cls.input_panel['X']), float(cls.input_panel['Y']), 0))
|
snap_vector = Vector((float(cls.input_panel['X']), float(cls.input_panel['Y']), 0))
|
||||||
else:
|
else:
|
||||||
snap_vector = Vector((snap_prop.x, snap_prop.y, 0))
|
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, )), Vector((1, 0, )))
|
||||||
current_axis = (last_point, snap_vector) # TODO get height from default container
|
current_axis = (Vector((last_point.x, last_point.y)), Vector((snap_vector.x, snap_vector.y))) # TODO get height from default container
|
||||||
if distance > 0:
|
if distance > 0:
|
||||||
angle = tool.Cad.angle_edges(x_axis_edge, current_axis, degrees=True)
|
angle = tool.Cad.angle_edges(x_axis_edge, current_axis, degrees=True, signed=True)
|
||||||
|
print("ANGLE", angle, radians(angle))
|
||||||
if cls.input_panel:
|
if cls.input_panel:
|
||||||
cls.input_panel['X'] = str(round(snap_vector.x, 4))
|
cls.input_panel['X'] = str(round(snap_vector.x, 4))
|
||||||
cls.input_panel['Y'] = str(round(snap_vector.y, 4))
|
cls.input_panel['Y'] = str(round(snap_vector.y, 4))
|
||||||
@@ -363,6 +363,31 @@ class WallPolylineDecorator:
|
|||||||
|
|
||||||
return cls.input_panel
|
return cls.input_panel
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def calculate_x_and_y(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))
|
||||||
|
distance = float(cls.input_panel['D'])
|
||||||
|
|
||||||
|
if distance < 0 or distance > 0:
|
||||||
|
angle_degrees = float(cls.input_panel['A'])
|
||||||
|
angle_radians = radians(360 - angle_degrees) # Substracting from 360 to make it clockwise
|
||||||
|
x = last_point[0] + distance * cos(angle_radians)
|
||||||
|
y = last_point[1] + distance * sin(angle_radians)
|
||||||
|
if cls.input_panel:
|
||||||
|
cls.input_panel['X'] = str(round(x, 4))
|
||||||
|
cls.input_panel['Y'] = str(round(y, 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
|
||||||
batch = batch_for_shader(shader, shader_type, {"pos": content_pos}, indices=indices)
|
batch = batch_for_shader(shader, shader_type, {"pos": content_pos}, indices=indices)
|
||||||
|
|||||||
@@ -304,6 +304,7 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
'4', '5', '6', '7', '8', '9', '.', '-'}
|
'4', '5', '6', '7', '8', '9', '.', '-'}
|
||||||
self.number_input = []
|
self.number_input = []
|
||||||
self.number_output = ''
|
self.number_output = ''
|
||||||
|
self.number_is_negative = False
|
||||||
self.is_input_on = False
|
self.is_input_on = False
|
||||||
self.input_options = {'X', 'Y', 'D', 'A'}
|
self.input_options = {'X', 'Y', 'D', 'A'}
|
||||||
self.input_type = ''
|
self.input_type = ''
|
||||||
@@ -551,19 +552,16 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
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))
|
||||||
|
|
||||||
if self.mousemove_count > 3:
|
if self.mousemove_count > 3:
|
||||||
start_time = time()
|
|
||||||
self.snaping_movement(context, event)
|
self.snaping_movement(context, event)
|
||||||
operator_time = time() - start_time
|
|
||||||
print(f"main function was finished in {operator_time:.2f} seconds")
|
|
||||||
print(len(bpy.context.scene.BIMModelProperties.polyline_point))
|
|
||||||
return {'RUNNING_MODAL'}
|
return {'RUNNING_MODAL'}
|
||||||
|
|
||||||
if event.value == 'RELEASE' and event.type == 'LEFTMOUSE':
|
if event.value == 'RELEASE' and event.type == 'LEFTMOUSE':
|
||||||
tool.Snaping.insert_polyline_point()
|
tool.Snaping.insert_polyline_point()
|
||||||
|
|
||||||
if event.value == 'RELEASE' and event.type == 'BACK_SPACE':
|
if self.is_input_on:
|
||||||
tool.Snaping.remove_last_polyline_point()
|
if event.value == 'RELEASE' and event.type == 'BACK_SPACE':
|
||||||
tool.Blender.update_viewport()
|
tool.Snaping.remove_last_polyline_point()
|
||||||
|
tool.Blender.update_viewport()
|
||||||
|
|
||||||
if event.value == 'PRESS' and event.type == 'I':
|
if event.value == 'PRESS' and event.type == 'I':
|
||||||
self.is_input_on = True
|
self.is_input_on = True
|
||||||
@@ -574,16 +572,37 @@ class DrawPolylineWall(bpy.types.Operator):
|
|||||||
self.number_input = []
|
self.number_input = []
|
||||||
self.number_output = ''
|
self.number_output = ''
|
||||||
|
|
||||||
|
if event.value == 'PRESS' and event.type in {'RIGHTMOUSE', 'ESC'}:
|
||||||
|
self.is_input_on = False
|
||||||
|
self.input_type = None
|
||||||
|
|
||||||
if self.input_type:
|
if self.input_type:
|
||||||
if event.ascii and event.ascii in self.number_options:
|
if event.ascii and event.ascii in self.number_options:
|
||||||
print(self.input_type)
|
if event.ascii == '-':
|
||||||
self.number_input.append(event.ascii)
|
print(self.number_is_negative)
|
||||||
self.number_output = ''.join(self.number_input)
|
if self.number_is_negative:
|
||||||
|
self.number_is_negative = False
|
||||||
|
else:
|
||||||
|
self.number_is_negative = True
|
||||||
|
else:
|
||||||
|
self.number_input.append(event.ascii)
|
||||||
|
self.number_output = ''.join(self.number_input)
|
||||||
|
|
||||||
|
|
||||||
|
if self.number_is_negative:
|
||||||
|
self.number_output = '-' + self.number_output
|
||||||
|
if not self.number_is_negative and self.number_output.startswith('-'):
|
||||||
|
self.number_output = self.number_output[1:]
|
||||||
|
|
||||||
|
print("NO", self.number_output)
|
||||||
self.input_panel[self.input_type] = self.number_output
|
self.input_panel[self.input_type] = self.number_output
|
||||||
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)
|
if self.input_type in {'X', 'Y'}:
|
||||||
|
self.input_panel = WallPolylineDecorator.calculate_distance_and_angle(context, self.is_input_on)
|
||||||
|
elif self.input_type in {'D', 'A'}:
|
||||||
|
self.input_panel = WallPolylineDecorator.calculate_x_and_y(context, self.is_input_on)
|
||||||
tool.Blender.update_viewport()
|
tool.Blender.update_viewport()
|
||||||
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'}:
|
||||||
tool.Snaping.insert_polyline_point(float(self.input_panel['X']), float(self.input_panel['Y']))
|
tool.Snaping.insert_polyline_point(float(self.input_panel['X']), float(self.input_panel['Y']))
|
||||||
|
|||||||
Reference in New Issue
Block a user