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
+14 -13
View File
@@ -316,7 +316,9 @@ class PolylineDecorator:
cls.uninstall() cls.uninstall()
handler = cls() 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_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.draw_measurements, (context,), "WINDOW", "POST_PIXEL"))
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
@@ -463,7 +465,6 @@ class PolylineDecorator:
cls.input_panel["AREA"] = str(round(area, 4)) cls.input_panel["AREA"] = str(round(area, 4))
return cls.input_panel return cls.input_panel
@classmethod @classmethod
def calculate_x_y_and_z(cls, context): def calculate_x_y_and_z(cls, context):
try: try:
@@ -522,7 +523,7 @@ class PolylineDecorator:
batch.draw(shader) batch.draw(shader)
def draw_input_panel(self, context): 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() unit_system = tool.Drawing.get_unit_system()
if unit_system == "IMPERIAL": if unit_system == "IMPERIAL":
@@ -545,9 +546,11 @@ class PolylineDecorator:
if key != "A" and key != self.input_type: if key != "A" and key != self.input_type:
value = float(value) value = float(value)
if context.scene.unit_settings.length_unit == 'MILLIMETERS': if context.scene.unit_settings.length_unit == "MILLIMETERS":
value = value * 1000 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: else:
formatted_value = value formatted_value = value
@@ -565,7 +568,6 @@ class PolylineDecorator:
rv3d = region.data rv3d = region.data
measurement_prop = context.scene.BIMModelProperties.polyline_measurement measurement_prop = context.scene.BIMModelProperties.polyline_measurement
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
self.font_id = 1 self.font_id = 1
blf.size(self.font_id, 12) blf.size(self.font_id, 12)
@@ -573,12 +575,11 @@ class PolylineDecorator:
blf.shadow(self.font_id, 6, 0, 0, 0, 1) blf.shadow(self.font_id, 6, 0, 0, 0, 1)
color = self.addon_prefs.decorations_colour color = self.addon_prefs.decorations_colour
blf.color(self.font_id, *color) blf.color(self.font_id, *color)
for i in range(len(measurement_prop)): for i in range(len(measurement_prop)):
if i == 0: if i == 0:
continue 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) coords_dim = view3d_utils.location_3d_to_region_2d(region, rv3d, pos_dim)
unit_system = tool.Drawing.get_unit_system() unit_system = tool.Drawing.get_unit_system()
@@ -591,14 +592,16 @@ class PolylineDecorator:
value = measurement_prop[i].dim value = measurement_prop[i].dim
value = float(value) value = float(value)
if context.scene.unit_settings.length_unit == 'MILLIMETERS': if context.scene.unit_settings.length_unit == "MILLIMETERS":
value = value * 1000 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.position(self.font_id, coords_dim[0], coords_dim[1], 0)
blf.draw(self.font_id, "d: " + formatted_value) 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) 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.position(self.font_id, coords_angle[0], coords_angle[1], 0)
blf.draw(self.font_id, "a: " + measurement_prop[i].angle) 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.position(self.font_id, position, 30, 0)
blf.draw(self.font_id, self.snap_info) blf.draw(self.font_id, self.snap_info)
def __call__(self, context): def __call__(self, context):
self.addon_prefs = tool.Blender.get_addon_preferences() self.addon_prefs = tool.Blender.get_addon_preferences()
@@ -655,7 +657,6 @@ class PolylineDecorator:
except: except:
ref_point = None ref_point = None
default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z default_container_elevation = tool.Ifc.get_object(tool.Root.get_default_container()).location.z
projection_point = [] projection_point = []
if self.use_default_container: if self.use_default_container:
+3 -7
View File
@@ -106,7 +106,6 @@ class Raycast(bonsai.core.tool.Raycast):
else: else:
return None, None, None return None, None, None
@classmethod @classmethod
def ray_cast_by_proximity(cls, context, event, obj, face=None): def ray_cast_by_proximity(cls, context, event, obj, face=None):
region = context.region region = context.region
@@ -121,9 +120,9 @@ class Raycast(bonsai.core.tool.Raycast):
loc = Vector((0, 0, 0)) loc = Vector((0, 0, 0))
bm = bmesh.new() bm = bmesh.new()
if face is None: # Object with faces if face is None: # Object with faces
bm.from_mesh(obj.data) 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] verts = [bm.verts.new(obj.data.vertices[i].co) for i in face.vertices]
bm.faces.new(verts) bm.faces.new(verts)
@@ -139,7 +138,7 @@ class Raycast(bonsai.core.tool.Raycast):
v2 = edge.verts[1].co v2 = edge.verts[1].co
world_v1 = obj.matrix_world.copy() @ v1 world_v1 = obj.matrix_world.copy() @ v1
world_v2 = obj.matrix_world.copy() @ v2 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)) intersection = tool.Cad.point_on_edge(division_point, (ray_target, loc))
distance = (division_point - intersection).length distance = (division_point - intersection).length
@@ -153,11 +152,9 @@ class Raycast(bonsai.core.tool.Raycast):
if distance < 0.8: if distance < 0.8:
points.append((intersection[1], "Edge")) points.append((intersection[1], "Edge"))
bm.free() bm.free()
return points return points
@classmethod @classmethod
def ray_cast_to_polyline(cls, context, event): def ray_cast_to_polyline(cls, context, event):
region = context.region region = context.region
@@ -175,7 +172,6 @@ class Raycast(bonsai.core.tool.Raycast):
for point_data in polyline_data: for point_data in polyline_data:
point = Vector((point_data.x, point_data.y, point_data.z)) point = Vector((point_data.x, point_data.y, point_data.z))
intersection, _ = mathutils.geometry.intersect_point_line(point, ray_target, loc) intersection, _ = mathutils.geometry.intersect_point_line(point, ray_target, loc)
distance = (point - intersection).length distance = (point - intersection).length
if distance < 0.2: if distance < 0.2:
+1 -4
View File
@@ -289,7 +289,6 @@ class Snap(bonsai.core.tool.Snap):
if sorted_intersections[0]: if sorted_intersections[0]:
return sorted_intersections[0], "Mix" return sorted_intersections[0], "Mix"
@classmethod @classmethod
def detect_snapping_points(cls, context, event, objs_2d_bbox): def detect_snapping_points(cls, context, event, objs_2d_bbox):
region = context.region region = context.region
@@ -453,7 +452,6 @@ class Snap(bonsai.core.tool.Snap):
detected_snaps.append({"Plane": intersection}) detected_snaps.append({"Plane": intersection})
return detected_snaps return detected_snaps
@classmethod @classmethod
@@ -500,14 +498,13 @@ class Snap(bonsai.core.tool.Snap):
intersection = origin["Plane"] intersection = origin["Plane"]
snapping_points.append((intersection, "Plane")) snapping_points.append((intersection, "Plane"))
# Make Axis first priority # Make Axis first priority
if event.shift or cls.snap_axis_method in {"X", "Y", "Z"}: if event.shift or cls.snap_axis_method in {"X", "Y", "Z"}:
cls.update_snapping_ref(snapping_points[0][0], snapping_points[0][1]) cls.update_snapping_ref(snapping_points[0][0], snapping_points[0][1])
for point in snapping_points: for point in snapping_points:
if point[1] == "Axis": if point[1] == "Axis":
if snapping_points[0][1] not in {"Axis", "Plane"}: 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]) cls.update_snapping_point(mixed_snap[0], mixed_snap[1])
return snapping_points return snapping_points
cls.update_snapping_point(point[0], point[1]) cls.update_snapping_point(point[0], point[1])