mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
New implementation for increment snap.
The first implementation was based directly on Blender increment snap. The new one works just by rounding distance and angle to a better number. The rounding is still contextual to the window zoom.
This commit is contained in:
@@ -347,7 +347,8 @@ class PolylineOperator:
|
|||||||
if self.mousemove_count > 3:
|
if self.mousemove_count > 3:
|
||||||
detected_snaps = tool.Snap.detect_snapping_points(context, event, self.objs_2d_bbox, self.tool_state)
|
detected_snaps = tool.Snap.detect_snapping_points(context, event, self.objs_2d_bbox, self.tool_state)
|
||||||
self.snapping_points = tool.Snap.select_snapping_points(context, event, self.tool_state, detected_snaps)
|
self.snapping_points = tool.Snap.select_snapping_points(context, event, self.tool_state, detected_snaps)
|
||||||
tool.Polyline.calculate_distance_and_angle(context, self.input_ui, self.tool_state)
|
tool.Polyline.calculate_distance_and_angle(context, self.input_ui, self.tool_state, should_round=True)
|
||||||
|
tool.Polyline.calculate_x_y_and_z(context, self.input_ui, self.tool_state)
|
||||||
tool.Blender.update_viewport()
|
tool.Blender.update_viewport()
|
||||||
return {"RUNNING_MODAL"}
|
return {"RUNNING_MODAL"}
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class Polyline(bonsai.core.tool.Polyline):
|
|||||||
return cls.ToolState()
|
return cls.ToolState()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def calculate_distance_and_angle(cls, context, input_ui, tool_state):
|
def calculate_distance_and_angle(cls, context, input_ui, tool_state, should_round=False):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
polyline_data = context.scene.BIMPolylineProperties.insertion_polyline[0]
|
polyline_data = context.scene.BIMPolylineProperties.insertion_polyline[0]
|
||||||
@@ -173,6 +173,11 @@ class Polyline(bonsai.core.tool.Polyline):
|
|||||||
angle = 0
|
angle = 0
|
||||||
orientation_angle = 0
|
orientation_angle = 0
|
||||||
if input_ui:
|
if input_ui:
|
||||||
|
if should_round:
|
||||||
|
angle = round(angle)
|
||||||
|
factor = tool.Snap.get_increment_snap_value(context)
|
||||||
|
print(factor)
|
||||||
|
distance = factor * round(distance / factor)
|
||||||
input_ui.set_value("X", snap_vector.x)
|
input_ui.set_value("X", snap_vector.x)
|
||||||
input_ui.set_value("Y", snap_vector.y)
|
input_ui.set_value("Y", snap_vector.y)
|
||||||
if input_ui.get_number_value("Z") is not None:
|
if input_ui.get_number_value("Z") is not None:
|
||||||
|
|||||||
@@ -41,6 +41,39 @@ class Snap(bonsai.core.tool.Snap):
|
|||||||
return
|
return
|
||||||
cls.snap_plane_method = value
|
cls.snap_plane_method = value
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_increment_snap_value(cls, context):
|
||||||
|
rv3d = context.region_data
|
||||||
|
|
||||||
|
factor = 1
|
||||||
|
fraction = 10
|
||||||
|
reference_value = -0.1
|
||||||
|
distance = 10
|
||||||
|
|
||||||
|
unit_system = tool.Drawing.get_unit_system()
|
||||||
|
if unit_system == "IMPERIAL":
|
||||||
|
factor = 3.28084
|
||||||
|
fraction = 12
|
||||||
|
reference_value = -0.4
|
||||||
|
distance = 5
|
||||||
|
|
||||||
|
increment = None
|
||||||
|
if rv3d.view_perspective == "PERSP":
|
||||||
|
if rv3d.view_distance < distance:
|
||||||
|
increment = (1 / fraction) / factor
|
||||||
|
else:
|
||||||
|
increment = 1 / factor
|
||||||
|
if rv3d.view_perspective == "ORTHO" or (
|
||||||
|
rv3d.view_perspective == "CAMERA" and context.scene.camera.data.type == "ORTHO"
|
||||||
|
):
|
||||||
|
window_scale = rv3d.window_matrix.to_scale()
|
||||||
|
if window_scale[0] < reference_value and window_scale[1] < reference_value:
|
||||||
|
increment = (1 / fraction) / factor
|
||||||
|
else:
|
||||||
|
increment = 1 / factor
|
||||||
|
|
||||||
|
return increment
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_snap_points_on_raycasted_face(cls, context, event, obj, face_index):
|
def get_snap_points_on_raycasted_face(cls, context, event, obj, face_index):
|
||||||
matrix = obj.matrix_world.copy()
|
matrix = obj.matrix_world.copy()
|
||||||
@@ -206,37 +239,9 @@ class Snap(bonsai.core.tool.Snap):
|
|||||||
(offset, -offset),
|
(offset, -offset),
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_increment_snap_value():
|
# TODO Snap like Blender snap increment. Enable this when we have a proper snap settings.
|
||||||
factor = 1
|
# Still need adjustments to improve the feel
|
||||||
fraction = 10
|
def round_vector_with_increment(intersection, relative_point):
|
||||||
reference_value = -0.1
|
|
||||||
distance = 10
|
|
||||||
|
|
||||||
unit_system = tool.Drawing.get_unit_system()
|
|
||||||
if unit_system == "IMPERIAL":
|
|
||||||
factor = 3.28084
|
|
||||||
fraction = 12
|
|
||||||
reference_value = -0.4
|
|
||||||
distance = 5
|
|
||||||
|
|
||||||
increment = None
|
|
||||||
if rv3d.view_perspective == "PERSP":
|
|
||||||
if rv3d.view_distance < distance:
|
|
||||||
increment = (1 / fraction) / factor
|
|
||||||
else:
|
|
||||||
increment = 1 / factor
|
|
||||||
if rv3d.view_perspective == "ORTHO" or (
|
|
||||||
rv3d.view_perspective == "CAMERA" and context.scene.camera.data.type == "ORTHO"
|
|
||||||
):
|
|
||||||
window_scale = rv3d.window_matrix.to_scale()
|
|
||||||
if window_scale[0] < reference_value and window_scale[1] < reference_value:
|
|
||||||
increment = (1 / fraction) / factor
|
|
||||||
else:
|
|
||||||
increment = 1 / factor
|
|
||||||
|
|
||||||
return increment
|
|
||||||
|
|
||||||
def round_vector_with_increment(intersection):
|
|
||||||
for i in range(len(intersection)):
|
for i in range(len(intersection)):
|
||||||
interval = round(abs(relative_point[i] % increment), 4)
|
interval = round(abs(relative_point[i] % increment), 4)
|
||||||
dist = round(abs(intersection[i] % increment), 4)
|
dist = round(abs(intersection[i] % increment), 4)
|
||||||
@@ -403,19 +408,7 @@ class Snap(bonsai.core.tool.Snap):
|
|||||||
intersection, tool_state, False
|
intersection, tool_state, False
|
||||||
)
|
)
|
||||||
|
|
||||||
# Increment Snap for Axis and Plane
|
|
||||||
increment = handle_increment_snap_value()
|
|
||||||
relative_point = (
|
|
||||||
Vector((polyline_points[-1].x, polyline_points[-1].y, polyline_points[-1].z))
|
|
||||||
if polyline_points
|
|
||||||
else Vector((0, 0, 0))
|
|
||||||
)
|
|
||||||
if increment:
|
|
||||||
round_vector_with_increment(intersection)
|
|
||||||
|
|
||||||
if rot_intersection and polyline_points:
|
if rot_intersection and polyline_points:
|
||||||
if tool_state.snap_angle == 90 or tool_state.snap_angle == 180 or tool_state.snap_angle == 0:
|
|
||||||
round_vector_with_increment(rot_intersection)
|
|
||||||
detected_snaps.append({"Axis": (rot_intersection, axis_start, axis_end)})
|
detected_snaps.append({"Axis": (rot_intersection, axis_start, axis_end)})
|
||||||
|
|
||||||
detected_snaps.append({"Plane": intersection})
|
detected_snaps.append({"Plane": intersection})
|
||||||
|
|||||||
Reference in New Issue
Block a user