black format

This commit is contained in:
Bruno Perdigão
2024-08-05 21:03:48 -03:00
committed by Bruno Perdigão
parent 5e2cefee12
commit f637ef8016
2 changed files with 67 additions and 56 deletions
@@ -304,7 +304,6 @@ class WallPolylineDecorator:
angle_snap_mat = None angle_snap_mat = None
angle_snap_loc = None angle_snap_loc = None
@classmethod @classmethod
def install(cls, context): def install(cls, context):
if cls.is_installed: if cls.is_installed:
@@ -323,7 +322,6 @@ class WallPolylineDecorator:
pass pass
cls.is_installed = False cls.is_installed = False
@classmethod @classmethod
def set_mouse_position(cls, context, event): def set_mouse_position(cls, context, event):
cls.mouse_pos = event.mouse_region_x, event.mouse_region_y cls.mouse_pos = event.mouse_region_x, event.mouse_region_y
@@ -351,23 +349,45 @@ class WallPolylineDecorator:
if last_point_data: if last_point_data:
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))
else: else:
last_point = Vector((0, 0, 0,)) last_point = Vector(
(
0,
0,
0,
)
)
if is_input_on: if is_input_on:
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, )), Vector((1, 0, ))) x_axis_edge = (
current_axis = (Vector((last_point.x, last_point.y)), Vector((snap_vector.x, snap_vector.y))) # TODO get height from default container 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: if distance > 0:
angle = tool.Cad.angle_edges(x_axis_edge, current_axis, degrees=True, signed=True) angle = tool.Cad.angle_edges(x_axis_edge, current_axis, degrees=True, signed=True)
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))
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
@@ -383,16 +403,16 @@ class WallPolylineDecorator:
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))
distance = float(cls.input_panel['D']) distance = float(cls.input_panel["D"])
if distance < 0 or distance > 0: if distance < 0 or distance > 0:
angle_degrees = float(cls.input_panel['A']) angle_degrees = float(cls.input_panel["A"])
angle_radians = radians(360 - angle_degrees) # Substracting from 360 to make it clockwise angle_radians = radians(360 - angle_degrees) # Substracting from 360 to make it clockwise
x = last_point[0] + distance * cos(angle_radians) x = last_point[0] + distance * cos(angle_radians)
y = last_point[1] + distance * sin(angle_radians) y = last_point[1] + distance * sin(angle_radians)
if cls.input_panel: if cls.input_panel:
cls.input_panel['X'] = str(round(x, 4)) cls.input_panel["X"] = str(round(x, 4))
cls.input_panel['Y'] = str(round(y, 4)) cls.input_panel["Y"] = str(round(y, 4))
return cls.input_panel return cls.input_panel
@@ -404,9 +424,8 @@ class WallPolylineDecorator:
shader.uniform_float("color", color) shader.uniform_float("color", color)
batch.draw(shader) batch.draw(shader)
def draw_text(self, context): def draw_text(self, context):
texts = ['X coord:', 'Y coord:', 'Distance:', 'Angle:'] texts = ["X coord:", "Y coord:", "Distance:", "Angle:"]
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 0 self.font_id = 0
blf.size(self.font_id, 12) blf.size(self.font_id, 12)
@@ -423,7 +442,6 @@ class WallPolylineDecorator:
blf.position(self.font_id, self.mouse_pos[0] + offset, self.mouse_pos[1] + offset - (new_line * i), 0) blf.position(self.font_id, self.mouse_pos[0] + offset, self.mouse_pos[1] + offset - (new_line * i), 0)
blf.draw(self.font_id, text + self.input_panel[keys[i]]) blf.draw(self.font_id, text + self.input_panel[keys[i]])
def __call__(self, context): def __call__(self, context):
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
@@ -434,7 +452,6 @@ class WallPolylineDecorator:
decorator_color_unselected = self.addon_prefs.decorator_color_unselected decorator_color_unselected = self.addon_prefs.decorator_color_unselected
decorator_color_background = self.addon_prefs.decorator_color_background decorator_color_background = self.addon_prefs.decorator_color_background
gpu.state.blend_set("ALPHA") gpu.state.blend_set("ALPHA")
self.line_shader = gpu.shader.from_builtin("POLYLINE_UNIFORM_COLOR") 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.bind() # required to be able to change uniforms of the shader
@@ -454,12 +471,11 @@ class WallPolylineDecorator:
else: else:
self.draw_batch("POINTS", mouse_point, (1.0, 0.6, 0.0, 1.0)) self.draw_batch("POINTS", mouse_point, (1.0, 0.6, 0.0, 1.0))
# 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", 1.0) 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]]
self.draw_batch("LINES", mouse_point + projection_point, (1.0, 0.6, 0.0, 1.0), edges) self.draw_batch("LINES", mouse_point + projection_point, (1.0, 0.6, 0.0, 1.0), edges)
@@ -473,14 +489,13 @@ class WallPolylineDecorator:
polyline_points.append(point) polyline_points.append(point)
for i in range(len(polyline_points) - 1): for i in range(len(polyline_points) - 1):
polyline_edges.append([i, i+1]) polyline_edges.append([i, i + 1])
self.line_shader.uniform_float("lineWidth", 2.0) self.line_shader.uniform_float("lineWidth", 2.0)
self.draw_batch("POINTS", polyline_points, decorator_color_selected) self.draw_batch("POINTS", polyline_points, decorator_color_selected)
if len(polyline_points) > 1: if len(polyline_points) > 1:
self.draw_batch("LINES", polyline_points, decorator_color_selected, polyline_edges) self.draw_batch("LINES", polyline_points, decorator_color_selected, polyline_edges)
# Line between last polyline point and mouse # Line between last polyline point and mouse
edges = [[0, 1]] edges = [[0, 1]]
if snap_prop.snap_type != "Plane" and snap_prop.z != 0: if snap_prop.snap_type != "Plane" and snap_prop.z != 0:
@@ -489,12 +504,11 @@ class WallPolylineDecorator:
self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color_unselected, edges) self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color_unselected, edges)
# Line for angle axis snap # Line for angle axis snap
if snap_prop.snap_type == 'Axis': if snap_prop.snap_type == "Axis":
length = 1000 length = 1000
direction = Vector((1, 0, 0)) direction = Vector((1, 0, 0))
rot_dir = self.angle_snap_mat.inverted() @ direction rot_dir = self.angle_snap_mat.inverted() @ direction
start = self.angle_snap_loc + rot_dir * length start = self.angle_snap_loc + rot_dir * length
end = self.angle_snap_loc - rot_dir * length end = self.angle_snap_loc - rot_dir * length
self.line_shader.uniform_float("lineWidth", 0.75) self.line_shader.uniform_float("lineWidth", 0.75)
self.draw_batch("LINES", [start, end], decorator_color_unselected, [(0,1)]) self.draw_batch("LINES", [start, end], decorator_color_unselected, [(0, 1)])
+6 -9
View File
@@ -36,7 +36,7 @@ class Snaping(blenderbim.core.tool.Snaping):
edges_center = [] edges_center = []
for v1, v2 in zip(vertices, vertices[1:] + [vertices[0]]): for v1, v2 in zip(vertices, vertices[1:] + [vertices[0]]):
middle_dist = (v2-v1) / 2 middle_dist = (v2 - v1) / 2
edges_center.append(v1 + middle_dist) edges_center.append(v1 + middle_dist)
snap_points.update({tuple(vertex): "Vertices" for vertex in vertices}) snap_points.update({tuple(vertex): "Vertices" for vertex in vertices})
@@ -44,7 +44,6 @@ class Snaping(blenderbim.core.tool.Snaping):
return snap_points return snap_points
@classmethod @classmethod
def get_snap_points_on_polyline(cls): def get_snap_points_on_polyline(cls):
snap_points = {} snap_points = {}
@@ -57,7 +56,6 @@ class Snaping(blenderbim.core.tool.Snaping):
return snap_points return snap_points
@classmethod @classmethod
def select_snap_point(cls, snap_points, hit, threshold): def select_snap_point(cls, snap_points, hit, threshold):
shortest_distance = None shortest_distance = None
@@ -100,11 +98,11 @@ class Snaping(blenderbim.core.tool.Snaping):
if x is not None and y is not None: if x is not None and y is not None:
polyline_point.x = x polyline_point.x = x
polyline_point.y = y polyline_point.y = y
polyline_point.z = 0 # TODO Update to the the default container height polyline_point.z = 0 # TODO Update to the the default container height
else: else:
polyline_point.x = snap_vertex.x polyline_point.x = snap_vertex.x
polyline_point.y = snap_vertex.y polyline_point.y = snap_vertex.y
polyline_point.z = 0 # TODO Update to the the default container height polyline_point.z = 0 # TODO Update to the the default container height
@classmethod @classmethod
def clear_polyline(cls): def clear_polyline(cls):
@@ -118,7 +116,7 @@ class Snaping(blenderbim.core.tool.Snaping):
def snap_on_axis(intersection): def snap_on_axis(intersection):
polyline_data = bpy.context.scene.BIMModelProperties.polyline_point polyline_data = bpy.context.scene.BIMModelProperties.polyline_point
if polyline_data: if polyline_data:
last_point_data =polyline_data[-1] last_point_data = polyline_data[-1]
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))
else: else:
last_point = Vector((0, 0, 0)) last_point = Vector((0, 0, 0))
@@ -127,7 +125,7 @@ class Snaping(blenderbim.core.tool.Snaping):
translated_intersection = intersection - last_point translated_intersection = intersection - last_point
for i in range(12): for i in range(12):
angle = 30 * i angle = 30 * i
rot_mat = Matrix.Rotation(math.radians(360 - angle), 3, 'Z') rot_mat = Matrix.Rotation(math.radians(360 - angle), 3, "Z")
WallPolylineDecorator.set_angle_axis_line(rot_mat, last_point) WallPolylineDecorator.set_angle_axis_line(rot_mat, last_point)
rot_intersection = rot_mat @ translated_intersection rot_intersection = rot_mat @ translated_intersection
is_on_rot_axis = abs(rot_intersection.y) <= 0.60 is_on_rot_axis = abs(rot_intersection.y) <= 0.60
@@ -135,8 +133,7 @@ class Snaping(blenderbim.core.tool.Snaping):
# snap to axis # snap to axis
rot_intersection = Vector((rot_intersection.x, 0, rot_intersection.z)) rot_intersection = Vector((rot_intersection.x, 0, rot_intersection.z))
# convert it back # convert it back
snap_intersection = rot_mat.inverted() @ rot_intersection + last_point snap_intersection = rot_mat.inverted() @ rot_intersection + last_point
return snap_intersection return snap_intersection
return None return None