mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
typing
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import annotations
|
||||
import bpy
|
||||
import blf
|
||||
import bpy
|
||||
@@ -34,6 +35,7 @@ from gpu_extras.presets import draw_circle_2d
|
||||
from typing import Union
|
||||
from bonsai.bim.module.drawing.helper import format_distance
|
||||
from itertools import chain
|
||||
from typing import Union, Any
|
||||
|
||||
|
||||
def transparent_color(color, alpha=0.1):
|
||||
@@ -348,21 +350,28 @@ class PolylineDecorator:
|
||||
cls.is_installed = False
|
||||
|
||||
@classmethod
|
||||
def update(cls, event, tool_state, input_ui, snapping_point):
|
||||
def update(
|
||||
cls,
|
||||
event: bpy.types.Event,
|
||||
tool_state: tool.Polyline.ToolState,
|
||||
input_ui: tool.Polyline.PolylineUI,
|
||||
snapping_point: Vector,
|
||||
) -> None:
|
||||
cls.event = event
|
||||
cls.tool_state = tool_state
|
||||
cls.input_ui = input_ui
|
||||
|
||||
# TODO: unused?
|
||||
@classmethod
|
||||
def set_input_ui(cls, input_ui):
|
||||
def set_input_ui(cls, input_ui: tool.Polyline.PolylineUI) -> None:
|
||||
cls.input_ui = input_ui
|
||||
|
||||
@classmethod
|
||||
def set_angle_axis_line(cls, start, end):
|
||||
def set_angle_axis_line(cls, start: Vector, end: Vector) -> None:
|
||||
cls.axis_start = start
|
||||
cls.axis_end = end
|
||||
|
||||
def calculate_measurement_x_y_and_z(self, context):
|
||||
def calculate_measurement_x_y_and_z(self, context: bpy.types.Context) -> None:
|
||||
polyline_data = context.scene.BIMPolylineProperties.insertion_polyline
|
||||
polyline_points = polyline_data[0].polyline_points if polyline_data else []
|
||||
|
||||
@@ -385,7 +394,7 @@ class PolylineDecorator:
|
||||
return (x_axis, y_axis, z_axis), (x_middle, y_middle, z_middle)
|
||||
|
||||
@classmethod
|
||||
def calculate_polygon(self, points):
|
||||
def calculate_polygon(cls, points: list[Vector]) -> dict[str, Any]:
|
||||
bm = bmesh.new()
|
||||
|
||||
new_verts = [bm.verts.new(v) for v in points]
|
||||
@@ -414,7 +423,7 @@ class PolylineDecorator:
|
||||
shader.uniform_float("color", color)
|
||||
batch.draw(shader)
|
||||
|
||||
def draw_input_ui(self, context):
|
||||
def draw_input_ui(self, context: bpy.types.Context) -> None:
|
||||
texts = {
|
||||
"D": "Distance: ",
|
||||
"A": "Angle: ",
|
||||
@@ -424,6 +433,7 @@ class PolylineDecorator:
|
||||
"AREA": "Area:",
|
||||
}
|
||||
try:
|
||||
assert self.event
|
||||
mouse_pos = self.event.mouse_region_x, self.event.mouse_region_y
|
||||
except:
|
||||
mouse_pos = (None, None)
|
||||
@@ -726,8 +736,8 @@ class PolylineDecorator:
|
||||
polyline_points = polyline_data.polyline_points
|
||||
else:
|
||||
polyline_points = []
|
||||
polyline_verts = []
|
||||
polyline_edges = []
|
||||
polyline_verts: list[Vector] = []
|
||||
polyline_edges: list[list[int]] = []
|
||||
for point_prop in polyline_points:
|
||||
point = Vector((point_prop.x, point_prop.y, point_prop.z))
|
||||
polyline_verts.append(point)
|
||||
|
||||
@@ -550,6 +550,8 @@ class PolylineOperator:
|
||||
# TODO Fill doc strings
|
||||
""" """
|
||||
|
||||
objs_2d_bbox: list[tuple[bpy.types.Object, list[float]]]
|
||||
|
||||
@classmethod
|
||||
def poll(cls, context: bpy.types.Context) -> bool:
|
||||
return context.space_data.type == "VIEW_3D"
|
||||
|
||||
@@ -62,12 +62,18 @@ class Raycast(bonsai.core.tool.Raycast):
|
||||
return visible_objs
|
||||
|
||||
@classmethod
|
||||
def get_on_screen_2d_bounding_boxes(cls, context: bpy.types.Context, obj: bpy.types.Object):
|
||||
def get_on_screen_2d_bounding_boxes(
|
||||
cls, context: bpy.types.Context, obj: bpy.types.Object
|
||||
) -> Union[tuple[bpy.types.Object, list[float]], None]:
|
||||
obj_matrix = obj.matrix_world.copy()
|
||||
bbox = [obj_matrix @ Vector(v) for v in obj.bound_box]
|
||||
|
||||
transposed_bbox = []
|
||||
bbox_2d = []
|
||||
transposed_bbox: list[Vector] = []
|
||||
bbox_2d: list[float] = []
|
||||
|
||||
assert context.region
|
||||
assert isinstance(context.space_data, bpy.types.SpaceView3D)
|
||||
assert context.space_data.region_3d
|
||||
|
||||
for v in bbox:
|
||||
coord_2d = view3d_utils.location_3d_to_region_2d(context.region, context.space_data.region_3d, v)
|
||||
@@ -77,6 +83,7 @@ class Raycast(bonsai.core.tool.Raycast):
|
||||
region = context.region
|
||||
borders = (0, region.width, 0, region.height)
|
||||
for i, axis in enumerate(zip(*transposed_bbox)):
|
||||
axis: tuple[float, ...]
|
||||
min_point = min(axis)
|
||||
max_point = max(axis)
|
||||
bbox_2d.extend([min_point, max_point])
|
||||
@@ -93,7 +100,6 @@ class Raycast(bonsai.core.tool.Raycast):
|
||||
return (obj, bbox_2d)
|
||||
return None
|
||||
|
||||
|
||||
@classmethod
|
||||
def intersect_mouse_2d_bounding_box(cls, mouse_pos: tuple[int, int], bbox: list[float, float, float, float]):
|
||||
x, y = mouse_pos
|
||||
|
||||
@@ -25,7 +25,7 @@ import math
|
||||
import mathutils
|
||||
from mathutils import Matrix, Vector
|
||||
from lark import Lark, Transformer
|
||||
from typing import Union
|
||||
from typing import Union, Any
|
||||
|
||||
|
||||
class Snap(bonsai.core.tool.Snap):
|
||||
@@ -145,12 +145,12 @@ class Snap(bonsai.core.tool.Snap):
|
||||
|
||||
@classmethod
|
||||
def snap_on_axis(cls, intersection, tool_state):
|
||||
def create_axis_line_data(rot_mat, origin):
|
||||
def create_axis_line_data(rot_mat: Matrix, origin: Vector) -> tuple[Vector, Vector]:
|
||||
length = 1000
|
||||
direction = Vector((1, 0, 0))
|
||||
if tool_state.plane_method == "YZ" or (not tool_state.plane_method and tool_state.axis_method == "Z"):
|
||||
direction = Vector((0, 0, 1))
|
||||
rot_dir = rot_mat.inverted() @ direction
|
||||
rot_dir: Vector = rot_mat.inverted() @ direction
|
||||
start = origin + rot_dir * length
|
||||
end = origin - rot_dir * length
|
||||
|
||||
@@ -280,10 +280,16 @@ class Snap(bonsai.core.tool.Snap):
|
||||
return sorted_intersections
|
||||
|
||||
@classmethod
|
||||
def detect_snapping_points(cls, context: bpy.types.Context, event: bpy.types.Event, objs_2d_bbox, tool_state):
|
||||
def detect_snapping_points(
|
||||
cls,
|
||||
context: bpy.types.Context,
|
||||
event: bpy.types.Event,
|
||||
objs_2d_bbox: list[tuple[bpy.types.Object, list[float]]],
|
||||
tool_state: tool.Polyline.ToolState,
|
||||
) -> list[dict[str, Any]]:
|
||||
rv3d = context.region_data
|
||||
space = context.space_data
|
||||
detected_snaps = []
|
||||
detected_snaps: list[dict[str, Any]] = []
|
||||
|
||||
def select_plane_method():
|
||||
if not last_polyline_point:
|
||||
@@ -485,11 +491,11 @@ class Snap(bonsai.core.tool.Snap):
|
||||
for snap in snapping_points:
|
||||
zoom_factor = bpy.context.region_data.view_distance
|
||||
if snap["type"] == "Vertex":
|
||||
snap["distance"] *= (zoom_factor / 10)
|
||||
snap["distance"] *= zoom_factor / 10
|
||||
if snap["type"] == "Edge Center":
|
||||
snap["distance"] *= (zoom_factor / 8)
|
||||
snap["distance"] *= zoom_factor / 8
|
||||
if snap["type"] == "Edge Intersection":
|
||||
snap["distance"] *= (zoom_factor / 5)
|
||||
snap["distance"] *= zoom_factor / 5
|
||||
if snap["type"] == "Edge":
|
||||
snap["distance"] *= zoom_factor
|
||||
if snap["type"] in ["Plane", "Axis", "Face"]:
|
||||
|
||||
Reference in New Issue
Block a user