mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +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))
|
||||
|
||||
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,)))
|
||||
current_axis = (last_point, snap_vector) # TODO get height from default container
|
||||
x_axis_edge = (Vector((0, 0, )), Vector((1, 0, )))
|
||||
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:
|
||||
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:
|
||||
cls.input_panel['X'] = str(round(snap_vector.x, 4))
|
||||
cls.input_panel['Y'] = str(round(snap_vector.y, 4))
|
||||
@@ -362,6 +362,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):
|
||||
shader = self.line_shader if shader_type == "LINES" else self.shader
|
||||
|
||||
@@ -304,6 +304,7 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
'4', '5', '6', '7', '8', '9', '.', '-'}
|
||||
self.number_input = []
|
||||
self.number_output = ''
|
||||
self.number_is_negative = False
|
||||
self.is_input_on = False
|
||||
self.input_options = {'X', 'Y', 'D', 'A'}
|
||||
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))
|
||||
|
||||
if self.mousemove_count > 3:
|
||||
start_time = time()
|
||||
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'}
|
||||
|
||||
if event.value == 'RELEASE' and event.type == 'LEFTMOUSE':
|
||||
tool.Snaping.insert_polyline_point()
|
||||
|
||||
if event.value == 'RELEASE' and event.type == 'BACK_SPACE':
|
||||
tool.Snaping.remove_last_polyline_point()
|
||||
tool.Blender.update_viewport()
|
||||
if self.is_input_on:
|
||||
if event.value == 'RELEASE' and event.type == 'BACK_SPACE':
|
||||
tool.Snaping.remove_last_polyline_point()
|
||||
tool.Blender.update_viewport()
|
||||
|
||||
if event.value == 'PRESS' and event.type == 'I':
|
||||
self.is_input_on = True
|
||||
@@ -574,16 +572,37 @@ class DrawPolylineWall(bpy.types.Operator):
|
||||
self.number_input = []
|
||||
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 event.ascii and event.ascii in self.number_options:
|
||||
print(self.input_type)
|
||||
self.number_input.append(event.ascii)
|
||||
self.number_output = ''.join(self.number_input)
|
||||
if event.ascii == '-':
|
||||
print(self.number_is_negative)
|
||||
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
|
||||
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()
|
||||
print(self.number_output)
|
||||
|
||||
|
||||
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']))
|
||||
|
||||
Reference in New Issue
Block a user