[Bf-extensions-cvs] [7597a8b6] blender-v2.82-release: Add System Input Rounding
Alan Odom
noreply at git.blender.org
Sat Feb 1 16:44:48 CET 2020
Commit: 7597a8b66d4562ef1bb8c8f648b692202ebffc30
Author: Alan Odom
Date: Tue Jan 28 11:05:27 2020 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBA7597a8b66d4562ef1bb8c8f648b692202ebffc30
Add System Input Rounding
Applies system rounding to inputs as defined in Add-on Preferences.
Default is 5 places of decimal, values taken from UI, or by calculation are
rounded before command is submitted.
===================================================================
M pdt_command_functions.py
M precision_drawing_tools/__init__.py
M precision_drawing_tools/pdt_command.py
M precision_drawing_tools/pdt_design.py
===================================================================
diff --git a/pdt_command_functions.py b/pdt_command_functions.py
index baf84c91..772f3fc0 100644
--- a/pdt_command_functions.py
+++ b/pdt_command_functions.py
@@ -620,18 +620,25 @@ def set_angle_distance_two(context):
v0 = np.array([vector_a[a1] + 1, vector_a[a2]]) - np.array([vector_a[a1], vector_a[a2]])
v1 = np.array([vector_b[a1], vector_b[a2]]) - np.array([vector_a[a1], vector_a[a2]])
ang = np.rad2deg(np.arctan2(np.linalg.det([v0, v1]), np.dot(v0, v1)))
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if flip_a:
if ang > 0:
- pg.angle = ang - 180
+ pg.angle = round(ang - 180, val_round)
else:
- pg.angle = ang + 180
+ pg.angle = round(ang - 180, val_round)
else:
- pg.angle = ang
+ pg.angle = round(ang, val_round)
if plane == "LO":
- pg.distance = sqrt((vector_a.x - vector_b.x) ** 2 + (vector_a.y - vector_b.y) ** 2)
+ pg.distance = round(sqrt(
+ (vector_a.x - vector_b.x) ** 2 +
+ (vector_a.y - vector_b.y) ** 2), val_round
+ )
else:
- pg.distance = sqrt((vector_a[a1] - vector_b[a1]) ** 2 + (vector_a[a2] - vector_b[a2]) ** 2)
- pg.cartesian_coords = vector_b - vector_a
+ pg.distance = round(sqrt(
+ (vector_a[a1] - vector_b[a1]) ** 2 +
+ (vector_a[a2] - vector_b[a2]) ** 2), val_round
+ )
+ pg.cartesian_coords = Vector(([round(i, val_round) for i in (vector_b - vector_a)]))
return
@@ -692,15 +699,16 @@ def set_angle_distance_three(context):
)
angle_cosine = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
ang = np.degrees(np.arccos(angle_cosine))
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if flip_a:
if ang > 0:
- pg.angle = ang - 180
+ pg.angle = round(ang - 180, val_round)
else:
- pg.angle = ang + 180
+ pg.angle = round(ang - 180, val_round)
else:
- pg.angle = ang
- pg.distance = (vector_a - vector_b).length
- pg.cartesian_coords = vector_b - vector_a
+ pg.angle = round(ang, val_round)
+ pg.distance = round((vector_a - vector_b).length, val_round)
+ pg.cartesian_coords = Vector(([round(i, val_round) for i in (vector_b - vector_a)]))
return
diff --git a/precision_drawing_tools/__init__.py b/precision_drawing_tools/__init__.py
index 1d2bb313..81ef97e4 100644
--- a/precision_drawing_tools/__init__.py
+++ b/precision_drawing_tools/__init__.py
@@ -448,15 +448,23 @@ class PDTPreferences(AddonPreferences):
description="Cutoff width for shrinking items per line in menus"
)
+ pdt_input_round : IntProperty(
+ name='Input Rounding',
+ default=5,
+ description='Rounding Factor for Inputs'
+ )
+
def draw(self, context):
layout = self.layout
box = layout.box()
row1 = box.row()
row2 = box.row()
+ row3 = box.row()
row1.prop(self, "debug")
- row1.prop(self, "pdt_ui_width")
- row2.prop(self, "pdt_library_path")
+ row2.prop(self, "pdt_ui_width")
+ row2.prop(self, "pdt_input_round")
+ row3.prop(self, "pdt_library_path")
# List of All Classes in the Add-on to register
diff --git a/precision_drawing_tools/pdt_command.py b/precision_drawing_tools/pdt_command.py
index ee1b3691..d941dc2a 100644
--- a/precision_drawing_tools/pdt_command.py
+++ b/precision_drawing_tools/pdt_command.py
@@ -376,21 +376,23 @@ def command_maths(context, mode, pg, expression, output_target):
pg.error = PDT_ERR_BADMATHS
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
raise PDT_MathsError
+
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if output_target == "x":
- pg.cartesian_coords.x = maths_result
+ pg.cartesian_coords.x = round(maths_result, val_round)
elif output_target == "y":
- pg.cartesian_coords.y = maths_result
+ pg.cartesian_coords.y = round(maths_result, val_round)
elif output_target == "z":
- pg.cartesian_coords.z = maths_result
+ pg.cartesian_coords.z = round(maths_result, val_round)
elif output_target == "d":
- pg.distance = maths_result
+ pg.distance = round(maths_result, val_round)
elif output_target == "a":
- pg.angle = maths_result
+ pg.angle = round(maths_result, val_round)
elif output_target == "p":
- pg.percent = maths_result
+ pg.percent = round(maths_result, val_round)
else:
# Mst be "o"
- pg.maths_output = maths_result
+ pg.maths_output = round(maths_result, val_round)
return
@@ -404,13 +406,17 @@ def command_parse(context):
mode_s = pg.select
obj = context.view_layer.objects.active
ind = 0
- for r in values:
+ for v in values:
try:
- _ = float(r)
+ _ = float(v)
good = True
except ValueError:
- values[ind] = "0"
+ values[ind] = "0.0"
ind = ind + 1
+ # Apply System Rounding
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
+ values_out = [str(round(float(v), val_round)) for v in values]
+
bm, good = obj_check(context, obj, scene, operation)
if good:
obj_loc = obj.matrix_world.decompose()[0]
@@ -432,10 +438,10 @@ def command_parse(context):
else:
verts = []
- debug(f"command: {command}")
+ debug(f"command: {operation}{mode}{values_out}")
debug(f"obj: {obj}, bm: {bm}, obj_loc: {obj_loc}")
- return pg, values, obj, obj_loc, bm, verts
+ return pg, values_out, obj, obj_loc, bm, verts
def move_cursor_pivot(context, pg, operation, mode, obj, verts, values):
@@ -845,7 +851,7 @@ def fillet_geometry(context, pg, mode, obj, bm, verts, values):
# Note that passing an empty parameter results in that parameter being seen as "0"
# _offset <= 0 is ignored since a bevel/fillet radius must be > 0 to make sense
_offset = float(values[0])
- _segments = int(values[1])
+ _segments = float(values[1])
if _segments < 1:
_segments = 1 # This is a single, flat segment (ignores profile)
_profile = float(values[2])
diff --git a/precision_drawing_tools/pdt_design.py b/precision_drawing_tools/pdt_design.py
index 51f60a93..20cb6ac3 100644
--- a/precision_drawing_tools/pdt_design.py
+++ b/precision_drawing_tools/pdt_design.py
@@ -56,7 +56,7 @@ from .pdt_msg_strings import (
PDT_LAB_DIR,
PDT_LAB_INTERSECT,
PDT_LAB_PERCENT,
- PDT_LAB_PLANE
+ PDT_LAB_PLANE,
)
@@ -90,31 +90,50 @@ class PDT_OT_PlacementAbs(Operator):
pg = context.scene.pdt_pg
operation = pg.operation
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if operation == "CU":
# Cursor
- pg.command = (f"ca{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"ca{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
elif operation == "PP":
# Pivot Point
- pg.command = (f"pa{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"pa{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
elif operation == "MV":
# Move Entities
- pg.command = (f"ga{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"ga{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
elif operation == "SE":
# Split Edges
- pg.command = (f"sa{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"sa{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
elif operation == "NV":
# New Vertex
- pg.command = (f"na{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"na{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
elif operation == "EV":
# Extrude Vertices
- pg.command = (f"va{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"va{str(round(pg.cartesian_coords.x, val_round))}"
+ f",{str(round(pg.cartesian_coords.y, val_round))}"
+ f",{str(round(pg.cartesian_coords.z, val_round))}"
+ )
else:
errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_ABS}"
self.report({"ERROR"}, errmsg)
@@ -153,39 +172,64 @@ class PDT_OT_PlacementDelta(Operator):
pg = context.scene.pdt_pg
operation = pg.operation
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if operation == "CU":
# Cursor
- pg.command = (f"cd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"cd{str(round(pg.cartesian_coords.x, val_round))
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list