black format

This commit is contained in:
Andrej730
2024-09-14 11:41:54 +05:00
parent aa3a362391
commit 6dbfb3afb3
5 changed files with 38 additions and 59 deletions
+19 -35
View File
@@ -312,7 +312,6 @@ class PolylineDecorator:
snap_info = None snap_info = None
tool_state = None tool_state = None
@classmethod @classmethod
def install(cls, context): def install(cls, context):
if cls.is_installed: if cls.is_installed:
@@ -321,11 +320,12 @@ class PolylineDecorator:
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_snap_point, (context,), "WINDOW", "POST_PIXEL")) cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_snap_point, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_measurements, (context,), "WINDOW", "POST_PIXEL")) cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_measurements, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_input_ui, (context,), "WINDOW", "POST_PIXEL")) cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_input_ui, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_product_preview, (context,), "WINDOW", "POST_VIEW")) cls.handlers.append(
SpaceView3D.draw_handler_add(handler.draw_product_preview, (context,), "WINDOW", "POST_VIEW")
)
cls.handlers.append(SpaceView3D.draw_handler_add(handler, (context,), "WINDOW", "POST_VIEW")) cls.handlers.append(SpaceView3D.draw_handler_add(handler, (context,), "WINDOW", "POST_VIEW"))
cls.is_installed = True cls.is_installed = True
@classmethod @classmethod
def uninstall(cls): def uninstall(cls):
for handler in cls.handlers: for handler in cls.handlers:
@@ -335,30 +335,25 @@ class PolylineDecorator:
pass pass
cls.is_installed = False cls.is_installed = False
@classmethod @classmethod
def update(cls, event, tool_state, input_ui, snapping_point): def update(cls, event, tool_state, input_ui, snapping_point):
cls.event = event cls.event = event
cls.tool_state = tool_state cls.tool_state = tool_state
cls.input_ui = input_ui cls.input_ui = input_ui
@classmethod @classmethod
def set_input_ui(cls, input_ui): def set_input_ui(cls, input_ui):
cls.input_ui = input_ui cls.input_ui = input_ui
@classmethod @classmethod
def set_angle_axis_line(cls, start, end): def set_angle_axis_line(cls, start, end):
cls.axis_start = start cls.axis_start = start
cls.axis_end = end cls.axis_end = end
# @classmethod # @classmethod
# def set_axis_rectangle(cls, corners): # def set_axis_rectangle(cls, corners):
# cls.axis_rectangle = [*corners] # cls.axis_rectangle = [*corners]
@classmethod @classmethod
def set_tool_state(cls, tool_state): def set_tool_state(cls, tool_state):
cls.tool_state = tool_state cls.tool_state = tool_state
@@ -376,24 +371,19 @@ class PolylineDecorator:
points = [] points = []
edges = [] edges = []
for i in range(len(prop)): for i in range(len(prop)):
points.append(Vector(( points.append(Vector((prop[i].x, prop[i].y, prop[i].z)))
prop[i].x,
prop[i].y,
prop[i].z
)))
n = len(points) // 2 n = len(points) // 2
bottom_loop = [[i, (i + 1) % (n)] for i in range(n)] bottom_loop = [[i, (i + 1) % (n)] for i in range(n)]
edges.extend(bottom_loop) edges.extend(bottom_loop)
upper_loop = [[i + n for i in edges] for edges in bottom_loop] upper_loop = [[i + n for i in edges] for edges in bottom_loop]
edges.extend(upper_loop) edges.extend(upper_loop)
connections = [[i, j] for i, j in zip(range(n), range(n, n*2))] connections = [[i, j] for i, j in zip(range(n), range(n, n * 2))]
edges.extend(connections) edges.extend(connections)
self.line_shader.uniform_float("lineWidth", 0.5) self.line_shader.uniform_float("lineWidth", 0.5)
if len(points) > 1: if len(points) > 1:
self.draw_batch("LINES", points, decorator_color, edges) self.draw_batch("LINES", points, decorator_color, edges)
def draw_input_ui(self, context): def draw_input_ui(self, context):
texts = { texts = {
"D": "Distance: ", "D": "Distance: ",
@@ -437,8 +427,8 @@ class PolylineDecorator:
def draw_text_background(self, context, coords_dim, text_dim): def draw_text_background(self, context, coords_dim, text_dim):
padding = 5 padding = 5
theme = context.preferences.themes.items()[0][1] theme = context.preferences.themes.items()[0][1]
color = (*theme.user_interface.wcol_menu_back.inner[:3], 0.5) #unwrap color values and adds alpha color = (*theme.user_interface.wcol_menu_back.inner[:3], 0.5) # unwrap color values and adds alpha
top_left = (coords_dim[0]- padding, coords_dim[1] + text_dim[1] + padding) top_left = (coords_dim[0] - padding, coords_dim[1] + text_dim[1] + padding)
bottom_left = (coords_dim[0] - padding, coords_dim[1] - padding) bottom_left = (coords_dim[0] - padding, coords_dim[1] - padding)
top_right = (coords_dim[0] + text_dim[0] + padding, coords_dim[1] + text_dim[1] + padding) top_right = (coords_dim[0] + text_dim[0] + padding, coords_dim[1] + text_dim[1] + padding)
bottom_right = (coords_dim[0] + text_dim[0] + padding, coords_dim[1] - padding) bottom_right = (coords_dim[0] + text_dim[0] + padding, coords_dim[1] - padding)
@@ -476,7 +466,6 @@ class PolylineDecorator:
self.draw_text_background(context, coords_dim, text_dim) self.draw_text_background(context, coords_dim, text_dim)
blf.draw(self.font_id, text) blf.draw(self.font_id, text)
if i == 1: if i == 1:
continue continue
pos_angle = measurement_prop[i - 1].position pos_angle = measurement_prop[i - 1].position
@@ -494,7 +483,7 @@ class PolylineDecorator:
self.shader = gpu.shader.from_builtin("UNIFORM_COLOR") self.shader = gpu.shader.from_builtin("UNIFORM_COLOR")
self.line_shader.uniform_float("lineWidth", 1.0) self.line_shader.uniform_float("lineWidth", 1.0)
theme = context.preferences.themes.items()[0][1] theme = context.preferences.themes.items()[0][1]
decorator_color_object_active = (*theme.view_3d.object_active, 1) #unwrap color values and adds alpha=1 decorator_color_object_active = (*theme.view_3d.object_active, 1) # unwrap color values and adds alpha=1
region = context.region region = context.region
rv3d = region.data rv3d = region.data
@@ -526,10 +515,8 @@ class PolylineDecorator:
draw_circle_2d(coords, decorator_color_object_active, padding) draw_circle_2d(coords, decorator_color_object_active, padding)
return return
self.draw_batch("LINES", verts, decorator_color_object_active, edges) self.draw_batch("LINES", verts, decorator_color_object_active, edges)
def __call__(self, context): def __call__(self, context):
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
@@ -540,12 +527,11 @@ class PolylineDecorator:
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
theme = context.preferences.themes.items()[0][1] theme = context.preferences.themes.items()[0][1]
decorator_color_object_active = (*theme.view_3d.object_active, 1) #unwrap color values and adds alpha=1 decorator_color_object_active = (*theme.view_3d.object_active, 1) # unwrap color values and adds alpha=1
decorator_color_x_axis = (*theme.user_interface.axis_x, 1) decorator_color_x_axis = (*theme.user_interface.axis_x, 1)
decorator_color_y_axis = (*theme.user_interface.axis_y, 1) decorator_color_y_axis = (*theme.user_interface.axis_y, 1)
decorator_color_z_axis = (*theme.user_interface.axis_z, 1) decorator_color_z_axis = (*theme.user_interface.axis_z, 1)
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
@@ -592,17 +578,17 @@ class PolylineDecorator:
# Line for angle axis snap # Line for angle axis snap
if snap_prop.snap_type == "Axis": if snap_prop.snap_type == "Axis":
axis_color = decorator_color axis_color = decorator_color
if (math.isclose(self.axis_start.y, self.axis_end.y, rel_tol=0.001) if math.isclose(self.axis_start.y, self.axis_end.y, rel_tol=0.001) and math.isclose(
and math.isclose(self.axis_start.z, self.axis_end.z, rel_tol=0.001) self.axis_start.z, self.axis_end.z, rel_tol=0.001
): ):
axis_color = decorator_color_x_axis axis_color = decorator_color_x_axis
if (math.isclose(self.axis_start.x, self.axis_end.x, rel_tol=0.001) if math.isclose(self.axis_start.x, self.axis_end.x, rel_tol=0.001) and math.isclose(
and math.isclose(self.axis_start.z, self.axis_end.z, rel_tol=0.001) self.axis_start.z, self.axis_end.z, rel_tol=0.001
): ):
axis_color = decorator_color_y_axis axis_color = decorator_color_y_axis
if (math.isclose(self.axis_start.x, self.axis_end.x, rel_tol=0.001) if math.isclose(self.axis_start.x, self.axis_end.x, rel_tol=0.001) and math.isclose(
and math.isclose(self.axis_start.y, self.axis_end.y, rel_tol=0.001) self.axis_start.y, self.axis_end.y, rel_tol=0.001
): ):
axis_color = decorator_color_z_axis axis_color = decorator_color_z_axis
self.line_shader.uniform_float("lineWidth", 0.75) self.line_shader.uniform_float("lineWidth", 0.75)
@@ -637,11 +623,9 @@ class PolylineDecorator:
self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color, edges) self.draw_batch("LINES", [polyline_points[-1]] + mouse_point, decorator_color, edges)
# Draw polyline with selected points # Draw polyline with selected points
print("EDGES",polyline_edges) print("EDGES", polyline_edges)
self.line_shader.uniform_float("lineWidth", 2.0) self.line_shader.uniform_float("lineWidth", 2.0)
print("VS", polyline_points) print("VS", polyline_points)
self.draw_batch("POINTS", polyline_points, decorator_color_special) self.draw_batch("POINTS", polyline_points, decorator_color_special)
if len(polyline_points) > 1: if len(polyline_points) > 1:
self.draw_batch("LINES", polyline_points, decorator_color_special, polyline_edges) self.draw_batch("LINES", polyline_points, decorator_color_special, polyline_edges)
@@ -332,14 +332,12 @@ class PolylineOperator:
tool.Snap.remove_last_polyline_point() tool.Snap.remove_last_polyline_point()
tool.Blender.update_viewport() tool.Blender.update_viewport()
def modal(self, context, event): def modal(self, context, event):
PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0]) PolylineDecorator.update(event, self.tool_state, self.input_ui, self.snapping_points[0])
tool.Blender.update_viewport() tool.Blender.update_viewport()
if event.type in {"MIDDLEMOUSE", "WHEELUPMOUSE", "WHEELDOWNMOUSE"}: if event.type in {"MIDDLEMOUSE", "WHEELUPMOUSE", "WHEELDOWNMOUSE"}:
return {"PASS_THROUGH"} return {"PASS_THROUGH"}
def invoke(self, context, event): def invoke(self, context, event):
PolylineDecorator.install(context) PolylineDecorator.install(context)
tool.Snap.clear_snapping_point() tool.Snap.clear_snapping_point()
@@ -192,7 +192,6 @@ class BIMModelProperties(PropertyGroup):
boundary_class: bpy.props.EnumProperty(items=get_boundary_class, name="Boundary Class") boundary_class: bpy.props.EnumProperty(items=get_boundary_class, name="Boundary Class")
class BIMArrayProperties(PropertyGroup): class BIMArrayProperties(PropertyGroup):
is_editing: bpy.props.IntProperty( is_editing: bpy.props.IntProperty(
default=-1, description="Currently edited array index. -1 if not in array editing mode." default=-1, description="Currently edited array index. -1 if not in array editing mode."
-1
View File
@@ -770,4 +770,3 @@ class Cad:
v1 = v2 v1 = v2
return new_verts return new_verts
+12 -13
View File
@@ -286,7 +286,9 @@ class Polyline(bonsai.core.tool.Polyline):
new_verts = [bm.verts.new(v) for v in base_vertices] new_verts = [bm.verts.new(v) for v in base_vertices]
if is_closed: if is_closed:
new_edges = [bm.edges.new((new_verts[i], new_verts[i + 1])) for i in range(len(new_verts) - 1)] new_edges = [bm.edges.new((new_verts[i], new_verts[i + 1])) for i in range(len(new_verts) - 1)]
new_edges.append(bm.edges.new((new_verts[-1], new_verts[0]))) # Add an edge between the last an first point to make it closed. new_edges.append(
bm.edges.new((new_verts[-1], new_verts[0]))
) # Add an edge between the last an first point to make it closed.
else: else:
new_edges = [bm.edges.new((new_verts[i], new_verts[i + 1])) for i in range(len(new_verts) - 1)] new_edges = [bm.edges.new((new_verts[i], new_verts[i + 1])) for i in range(len(new_verts) - 1)]
@@ -298,7 +300,7 @@ class Polyline(bonsai.core.tool.Polyline):
layers = tool.Model.get_material_layer_parameters(relating_type) layers = tool.Model.get_material_layer_parameters(relating_type)
if not layers["thickness"]: if not layers["thickness"]:
return return
thickness = layers['thickness'] thickness = layers["thickness"]
height = float(context.scene.BIMModelProperties.extrusion_depth) height = float(context.scene.BIMModelProperties.extrusion_depth)
rl = float(context.scene.BIMModelProperties.rl1) rl = float(context.scene.BIMModelProperties.rl1)
@@ -312,17 +314,16 @@ class Polyline(bonsai.core.tool.Polyline):
context.scene.BIMPolylineProperties.product_preview.clear() context.scene.BIMPolylineProperties.product_preview.clear()
return return
for point in polyline_data: for point in polyline_data:
base_vertices.append( base_vertices.append(Vector((point.x, point.y, point.z)))
Vector((point.x, point.y, point.z))
)
is_closed = False is_closed = False
if (base_vertices[0].x == base_vertices[-1].x and if (
base_vertices[0].y == base_vertices[-1].y and base_vertices[0].x == base_vertices[-1].x
base_vertices[0].z == base_vertices[-1].z): and base_vertices[0].y == base_vertices[-1].y
and base_vertices[0].z == base_vertices[-1].z
):
is_closed = True is_closed = True
base_vertices.pop(-1) # Remove the last point. The edges are going to inform that the shape is closed. base_vertices.pop(-1) # Remove the last point. The edges are going to inform that the shape is closed.
bm_base = create_bmesh_from_vertices(base_vertices) bm_base = create_bmesh_from_vertices(base_vertices)
bm_top = create_bmesh_from_vertices(base_vertices) bm_top = create_bmesh_from_vertices(base_vertices)
@@ -361,17 +362,15 @@ class Polyline(bonsai.core.tool.Polyline):
prop.z = new_v.z + rl + height prop.z = new_v.z + rl + height
for v in offset_top_verts[::-1]: for v in offset_top_verts[::-1]:
new_v = Vector((v.co.x, v.co.y, v.co.z))# + scaled_direction new_v = Vector((v.co.x, v.co.y, v.co.z)) # + scaled_direction
prop = context.scene.BIMPolylineProperties.product_preview.add() prop = context.scene.BIMPolylineProperties.product_preview.add()
prop.x = new_v.x prop.x = new_v.x
prop.y = new_v.y prop.y = new_v.y
prop.z = new_v.z + rl + height prop.z = new_v.z + rl + height
bm_base.free() bm_base.free()
bm_top.free() bm_top.free()
@classmethod @classmethod
def validate_input(cls, input_number, input_type): def validate_input(cls, input_number, input_type):