Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Odom <clockmender@icloud.com>2020-01-28 14:05:27 +0300
committerRune Morling <ermo.blender.org@spammesenseless.net>2020-02-01 18:42:03 +0300
commit7597a8b66d4562ef1bb8c8f648b692202ebffc30 (patch)
tree273e2810f77f70800905dfb41906e4b3fc623a39 /precision_drawing_tools
parent4d0298a3f9240cff351f7225819f55dbe29836a9 (diff)
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.
Diffstat (limited to 'precision_drawing_tools')
-rw-r--r--precision_drawing_tools/__init__.py12
-rw-r--r--precision_drawing_tools/pdt_command.py32
-rw-r--r--precision_drawing_tools/pdt_design.py180
3 files changed, 159 insertions, 65 deletions
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))}"
+ 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"pd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"pd{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"gd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"gd{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"sd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"sd{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"nd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"nd{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":
# Extrue Vertices
- pg.command = (f"vd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"vd{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 == "DG":
# Duplicate Entities
- pg.command = (f"dd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"dd{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 == "EG":
# Extrue Geometry
- pg.command = (f"ed{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
- f"{pg.cartesian_coords.z}")
+ pg.command = (
+ f"ed{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_DEL}"
self.report({"ERROR"}, errmsg)
@@ -224,30 +268,56 @@ class PDT_OT_PlacementDis(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"ci{pg.distance},{pg.angle}"
+ pg.command = (
+ f"ci{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "PP":
# Pivot Point
- pg.command = f"pi{pg.distance},{pg.angle}"
+ pg.command = (
+ f"pi{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "MV":
# Move Entities
- pg.command = f"gi{pg.distance},{pg.angle}"
+ pg.command = (
+ f"gi{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "SE":
# Split Edges
- pg.command = f"si{pg.distance},{pg.angle}"
+ pg.command = (
+ f"si{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "NV":
# New Vertex
- pg.command = f"ni{pg.distance},{pg.angle}"
+ pg.command = (
+ f"ni{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "EV":
# Extrude Vertices
- pg.command = f"vi{pg.distance},{pg.angle}"
+ pg.command = (
+ f"vi{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "DG":
# Duplicate Geometry
- pg.command = f"di{pg.distance},{pg.angle}"
+ pg.command = (
+ f"di{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
elif operation == "EG":
# Extrude Geometry
- pg.command = f"ei{pg.distance},{pg.angle}"
+ pg.command = (
+ f"ei{str(round(pg.distance, val_round))}"
+ f",{str(round(pg.angle, val_round))}"
+ )
else:
errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_DIR}"
self.report({"ERROR"}, errmsg)
@@ -261,7 +331,6 @@ class PDT_OT_PlacementPer(Operator):
bl_label = "Percentage Mode"
bl_options = {"REGISTER", "UNDO"}
-
def execute(self, context):
"""Manipulates Geometry, or Objects by Percentage between 2 points.
@@ -285,25 +354,26 @@ class PDT_OT_PlacementPer(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"cp{pg.percent}"
+ pg.command = f"cp{str(round(pg.percent, val_round))}"
elif operation == "PP":
# Pivot Point
- pg.command = f"pp{pg.percent}"
+ pg.command = f"pp{str(round(pg.percent, val_round))}"
elif operation == "MV":
# Move Entities
- pg.command = f"gp{pg.percent}"
+ pg.command = f"gp{str(round(pg.percent, val_round))}"
elif operation == "SE":
# Split Edges
- pg.command = f"sp{pg.percent}"
+ pg.command = f"sp{str(round(pg.percent, val_round))}"
elif operation == "NV":
# New Vertex
- pg.command = f"np{pg.percent}"
+ pg.command = f"np{str(round(pg.percent, val_round))}"
elif operation == "EV":
# Extrude Vertices
- pg.command = f"vp{pg.percent}"
+ pg.command = f"vp{str(round(pg.percent, val_round))}"
else:
errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_PERCENT}"
self.report({"ERROR"}, errmsg)
@@ -317,7 +387,6 @@ class PDT_OT_PlacementNormal(Operator):
bl_label = "Normal Mode"
bl_options = {"REGISTER", "UNDO"}
-
def execute(self, context):
"""Manipulates Geometry, or Objects by Normal Intersection between 3 points.
@@ -515,12 +584,25 @@ class PDT_OT_Fillet(Operator):
"""
pg = context.scene.pdt_pg
+ val_round = context.preferences.addons[__package__].preferences.pdt_input_round
if pg.fillet_intersect:
- pg.command = f"fi{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
+ pg.command = (
+ f"fi{str(round(pg.fillet_radius, val_round))}"
+ f",{str(round(pg.fillet_segments, val_round))}"
+ f",{str(round(pg.fillet_profile, val_round))}"
+ )
elif pg.fillet_vertices_only:
- pg.command = f"fv{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
+ pg.command = (
+ f"fv{str(round(pg.fillet_radius, val_round))}"
+ f",{str(round(pg.fillet_segments, val_round))}"
+ f",{str(round(pg.fillet_profile, val_round))}"
+ )
else:
- pg.command = f"fe{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
+ pg.command = (
+ f"fe{str(round(pg.fillet_radius, val_round))}"
+ f",{str(round(pg.fillet_segments, val_round))}"
+ f",{str(round(pg.fillet_profile, val_round))}"
+ )
return {"FINISHED"}
@@ -609,7 +691,6 @@ class PDT_OT_Taper(Operator):
bl_label = "Taper"
bl_options = {"REGISTER", "UNDO"}
-
@classmethod
def poll(cls, context):
ob = context.object
@@ -617,7 +698,6 @@ class PDT_OT_Taper(Operator):
return False
return all([bool(ob), ob.type == "MESH", ob.mode == "EDIT"])
-
def execute(self, context):
"""Taper Geometry along World Axes.