black format

This commit is contained in:
Bruno Perdigão
2024-08-27 18:22:43 -03:00
parent 0faacccf6d
commit 994c85a05a
4 changed files with 22 additions and 28 deletions
+17 -16
View File
@@ -309,14 +309,16 @@ class PolylineDecorator:
use_default_container = False
instructions = None
snap_info = None
@classmethod
def install(cls, context):
if cls.is_installed:
cls.uninstall()
handler = cls()
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_input_panel, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(SpaceView3D.draw_handler_add(handler.draw_on_screen_menu, (context,), "WINDOW", "POST_PIXEL"))
cls.handlers.append(
SpaceView3D.draw_handler_add(handler.draw_on_screen_menu, (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, (context,), "WINDOW", "POST_VIEW"))
cls.is_installed = True
@@ -463,7 +465,6 @@ class PolylineDecorator:
cls.input_panel["AREA"] = str(round(area, 4))
return cls.input_panel
@classmethod
def calculate_x_y_and_z(cls, context):
try:
@@ -522,7 +523,7 @@ class PolylineDecorator:
batch.draw(shader)
def draw_input_panel(self, context):
texts = {"D": "Distance:", "A": "Angle:", "X": "X coord:", "Y": "Y coord:", "Z": "Z coord:", "AREA": "Area:"}
texts = {"D": "Distance:", "A": "Angle:", "X": "X coord:", "Y": "Y coord:", "Z": "Z coord:", "AREA": "Area:"}
unit_system = tool.Drawing.get_unit_system()
if unit_system == "IMPERIAL":
@@ -545,9 +546,11 @@ class PolylineDecorator:
if key != "A" and key != self.input_type:
value = float(value)
if context.scene.unit_settings.length_unit == 'MILLIMETERS':
if context.scene.unit_settings.length_unit == "MILLIMETERS":
value = value * 1000
formatted_value = format_distance(value*factor, precision=precision, suppress_zero_inches=True, in_unit_length=True)
formatted_value = format_distance(
value * factor, precision=precision, suppress_zero_inches=True, in_unit_length=True
)
else:
formatted_value = value
@@ -565,7 +568,6 @@ class PolylineDecorator:
rv3d = region.data
measurement_prop = context.scene.BIMModelProperties.polyline_measurement
self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 1
blf.size(self.font_id, 12)
@@ -573,12 +575,11 @@ class PolylineDecorator:
blf.shadow(self.font_id, 6, 0, 0, 0, 1)
color = self.addon_prefs.decorations_colour
blf.color(self.font_id, *color)
for i in range(len(measurement_prop)):
if i == 0:
continue
pos_dim = (Vector(measurement_prop[i].position) + Vector(measurement_prop[i-1].position)) / 2
pos_dim = (Vector(measurement_prop[i].position) + Vector(measurement_prop[i - 1].position)) / 2
coords_dim = view3d_utils.location_3d_to_region_2d(region, rv3d, pos_dim)
unit_system = tool.Drawing.get_unit_system()
@@ -589,16 +590,18 @@ class PolylineDecorator:
precision = None
factor = 1
value = measurement_prop[i].dim
value = measurement_prop[i].dim
value = float(value)
if context.scene.unit_settings.length_unit == 'MILLIMETERS':
if context.scene.unit_settings.length_unit == "MILLIMETERS":
value = value * 1000
formatted_value = format_distance(value*factor, precision=precision, suppress_zero_inches=True, in_unit_length=True)
formatted_value = format_distance(
value * factor, precision=precision, suppress_zero_inches=True, in_unit_length=True
)
blf.position(self.font_id, coords_dim[0], coords_dim[1], 0)
blf.draw(self.font_id, "d: " + formatted_value)
pos_angle = measurement_prop[i-1].position
pos_angle = measurement_prop[i - 1].position
coords_angle = view3d_utils.location_3d_to_region_2d(region, rv3d, pos_angle)
blf.position(self.font_id, coords_angle[0], coords_angle[1], 0)
blf.draw(self.font_id, "a: " + measurement_prop[i].angle)
@@ -624,7 +627,6 @@ class PolylineDecorator:
blf.position(self.font_id, position, 30, 0)
blf.draw(self.font_id, self.snap_info)
def __call__(self, context):
self.addon_prefs = tool.Blender.get_addon_preferences()
@@ -655,7 +657,6 @@ class PolylineDecorator:
except:
ref_point = None
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
projection_point = []
if self.use_default_container:
@@ -2481,7 +2481,7 @@ class MeasureTool(bpy.types.Operator):
if event.value == "PRESS" and event.type == "M":
self.snapping_points = tool.Snap.modify_snapping_point_selection(self.snapping_points)
tool.Blender.update_viewport()
if event.shift and event.value == "PRESS" and event.type == "X":
tool.Snap.set_use_default_container(False)
PolylineDecorator.set_use_default_container(False)
+3 -7
View File
@@ -106,7 +106,6 @@ class Raycast(bonsai.core.tool.Raycast):
else:
return None, None, None
@classmethod
def ray_cast_by_proximity(cls, context, event, obj, face=None):
region = context.region
@@ -121,9 +120,9 @@ class Raycast(bonsai.core.tool.Raycast):
loc = Vector((0, 0, 0))
bm = bmesh.new()
if face is None: # Object with faces
if face is None: # Object with faces
bm.from_mesh(obj.data)
else: # Object without faces
else: # Object without faces
verts = [bm.verts.new(obj.data.vertices[i].co) for i in face.vertices]
bm.faces.new(verts)
@@ -139,7 +138,7 @@ class Raycast(bonsai.core.tool.Raycast):
v2 = edge.verts[1].co
world_v1 = obj.matrix_world.copy() @ v1
world_v2 = obj.matrix_world.copy() @ v2
division_point = (world_v1 + world_v2) / 2 # TODO Make it work for different divisions
division_point = (world_v1 + world_v2) / 2 # TODO Make it work for different divisions
intersection = tool.Cad.point_on_edge(division_point, (ray_target, loc))
distance = (division_point - intersection).length
@@ -153,11 +152,9 @@ class Raycast(bonsai.core.tool.Raycast):
if distance < 0.8:
points.append((intersection[1], "Edge"))
bm.free()
return points
@classmethod
def ray_cast_to_polyline(cls, context, event):
region = context.region
@@ -175,7 +172,6 @@ class Raycast(bonsai.core.tool.Raycast):
for point_data in polyline_data:
point = Vector((point_data.x, point_data.y, point_data.z))
intersection, _ = mathutils.geometry.intersect_point_line(point, ray_target, loc)
distance = (point - intersection).length
if distance < 0.2:
+1 -4
View File
@@ -289,7 +289,6 @@ class Snap(bonsai.core.tool.Snap):
if sorted_intersections[0]:
return sorted_intersections[0], "Mix"
@classmethod
def detect_snapping_points(cls, context, event, objs_2d_bbox):
region = context.region
@@ -453,7 +452,6 @@ class Snap(bonsai.core.tool.Snap):
detected_snaps.append({"Plane": intersection})
return detected_snaps
@classmethod
@@ -500,14 +498,13 @@ class Snap(bonsai.core.tool.Snap):
intersection = origin["Plane"]
snapping_points.append((intersection, "Plane"))
# Make Axis first priority
if event.shift or cls.snap_axis_method in {"X", "Y", "Z"}:
cls.update_snapping_ref(snapping_points[0][0], snapping_points[0][1])
for point in snapping_points:
if point[1] == "Axis":
if snapping_points[0][1] not in {"Axis", "Plane"}:
mixed_snap = cls.mix_snap_and_axis(snapping_points[0], axis_start, axis_end)
mixed_snap = cls.mix_snap_and_axis(snapping_points[0], axis_start, axis_end)
cls.update_snapping_point(mixed_snap[0], mixed_snap[1])
return snapping_points
cls.update_snapping_point(point[0], point[1])