[Bf-extensions-cvs] [4d0298a3] blender-v2.82-release: PDT: Refactor - Stage 4
Alan Odom
noreply at git.blender.org
Sat Feb 1 16:44:48 CET 2020
Commit: 4d0298a3f9240cff351f7225819f55dbe29836a9
Author: Alan Odom
Date: Sun Jan 26 10:52:00 2020 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBA4d0298a3f9240cff351f7225819f55dbe29836a9
PDT: Refactor - Stage 4
- Check Object Mode is either EDIT or OBJECT as appropriate.
- Change If loop to check command values - error if D, E, For M commands.
- Remove surplus command check in command_maths function.
- Added import of exceptions file.
- Check for Mesh Objects in Object or Edit Mode first and exit with error
message if not.
- Some minor changes for obscure failures in unusual circumstances.
- Fixes and changes to code to correct minor errors and remove unnecessary
checks.
- Refactored Command File structure.
- Add more checks to Fillet Operation to check selection and make sure
current selected vertices/edges are always used. Previous version could
use wrong selection if Bmesh SelectHistory was in place for Faces, or Edges.
===================================================================
M pdt_command_functions.py
A pdt_exception.py
M precision_drawing_tools/pdt_command.py
M precision_drawing_tools/pdt_functions.py
M precision_drawing_tools/pdt_msg_strings.py
===================================================================
diff --git a/pdt_command_functions.py b/pdt_command_functions.py
index b7653229..baf84c91 100644
--- a/pdt_command_functions.py
+++ b/pdt_command_functions.py
@@ -41,6 +41,18 @@ from .pdt_functions import (
view_dir,
set_axis,
)
+
+from . import pdt_exception
+PDT_SelectionError = pdt_exception.SelectionError
+PDT_InvalidVector = pdt_exception.InvalidVector
+PDT_ObjectMode = pdt_exception.ObjectMode
+PDT_InfRadius = pdt_exception.InfRadius
+PDT_NoObjectError = pdt_exception.NoObjectError
+PDT_IntersectionError = pdt_exception.IntersectionError
+PDT_InvalidOperation = pdt_exception.InvalidOperation
+PDT_VerticesConnected = pdt_exception.VerticesConnected
+PDT_InvalidAngle = pdt_exception.InvalidAngle
+
from .pdt_msg_strings import (
PDT_ERR_BAD3VALS,
PDT_ERR_BAD2VALS,
@@ -67,51 +79,11 @@ from .pdt_msg_strings import (
PDT_ERR_SEL_3_VERTIO,
PDT_ERR_TAPER_ANG,
PDT_ERR_TAPER_SEL,
- PDT_ERR_BADMATHS,
PDT_ERR_INT_LINES,
PDT_LAB_PLANE,
)
-def command_maths(context, mode, pg, expression, output_target):
- """Evaluates Maths Input.
-
- Args:
- context: Blender bpy.context instance.
- mode, pg, expression, output_target
-
- Returns:
- Nothing.
- """
- if output_target not in {"x", "y", "z", "d", "a", "p", "o"}:
- pg.error = f"{mode} {PDT_ERR_NON_VALID} Maths)"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- namespace = {}
- namespace.update(vars(math))
- try:
- maths_result = eval(expression, namespace, namespace)
- except ValueError:
- pg.error = PDT_ERR_BADMATHS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- if output_target == "x":
- pg.cartesian_coords.x = maths_result
- elif output_target == "y":
- pg.cartesian_coords.y = maths_result
- elif output_target == "z":
- pg.cartesian_coords.z = maths_result
- elif output_target == "d":
- pg.distance = maths_result
- elif output_target == "a":
- pg.angle = maths_result
- elif output_target == "p":
- pg.percent = maths_result
- elif output_target == "o":
- pg.maths_output = maths_result
- return
-
-
def vector_build(context, pg, obj, operation, values, num_values):
"""Build Movement Vector from input Fields.
@@ -143,58 +115,8 @@ def vector_build(context, pg, obj, operation, values, num_values):
else:
pg.error = PDT_ERR_BAD1VALS
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return False, Vector((0, 0, 0))
- return True, output_vector
-
-
-def move_cursor_pivot(context, pg, obj, sel_verts, operation, mode_op, vector_delta):
- """Move Cursor or Pivot Point.
-
- Args:
- context: Blender bpy.context instance.
- PDT parameter group as pg, active object, selected vertices,
- operation, operational mode as mode_op, movement vector.
-
- Returns:
- Nothing.
- """
- scene = context.scene
- mode_sel = pg.select
- obj_loc = obj.matrix_world.decompose()[0]
-
- if mode_op == "a":
- if operation == "C":
- scene.cursor.location = vector_delta
- elif operation == "P":
- pg.pivot_loc = vector_delta
- elif mode_op in {"d", "i"}:
- if mode_sel == "REL":
- if operation == "C":
- scene.cursor.location = scene.cursor.location + vector_delta
- else:
- pg.pivot_loc = pg.pivot_loc + vector_delta
- elif mode_sel == "SEL":
- if obj.mode == "EDIT":
- if operation == "C":
- scene.cursor.location = sel_verts[-1].co + obj_loc + vector_delta
- else:
- pg.pivot_loc = sel_verts[-1].co + obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- if operation == "C":
- scene.cursor.location = obj_loc + vector_delta
- else:
- pg.pivot_loc = obj_loc + vector_delta
- elif mode_op == "p":
- if obj.mode == "EDIT":
- if operation == "C":
- scene.cursor.location = obj_loc + vector_delta
- else:
- pg.pivot_loc = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- if operation == "C":
- scene.cursor.location = vector_delta
- else:
- pg.pivot_loc = vector_delta
+ raise pdt_InvalidVector
+ return output_vector
def placement_normal(context, operation):
@@ -227,7 +149,7 @@ def placement_normal(context, operation):
if obj is None:
pg.error = PDT_ERR_NO_ACT_OBJ
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_ObjectMode
obj_loc = obj.matrix_world.decompose()[0]
bm = bmesh.from_edit_mesh(obj.data)
if len(bm.select_history) == 3:
@@ -235,17 +157,17 @@ def placement_normal(context, operation):
if vector_a is None:
pg.error = PDT_ERR_VERT_MODE
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_InvalidVector
else:
- pg.error = f"{PDT_ERR_SEL_3_VERTS} {len(bm.select_history)})"
+ pg.error = f"{PDT_ERR_SEL_3_VERTIO} {len(bm.select_history)})"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
elif obj.mode == "OBJECT":
objs = context.view_layer.objects.selected
if len(objs) != 3:
pg.error = f"{PDT_ERR_SEL_3_OBJS} {len(objs)})"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
objs_s = [ob for ob in objs if ob.name != obj.name]
vector_a = obj.matrix_world.decompose()[0]
vector_b = objs_s[-1].matrix_world.decompose()[0]
@@ -334,7 +256,7 @@ def placement_centre(context, operation):
if obj is None:
pg.error = PDT_ERR_NO_ACT_OBJ
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_ObjectMode
obj = context.view_layer.objects.active
obj_loc = obj.matrix_world.decompose()[0]
bm = bmesh.from_edit_mesh(obj.data)
@@ -342,7 +264,7 @@ def placement_centre(context, operation):
if len(verts) != 3:
pg.error = f"{PDT_ERR_SEL_3_VERTS} {len(verts)})"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
vector_a = verts[0].co
vector_b = verts[1].co
vector_c = verts[2].co
@@ -350,7 +272,7 @@ def placement_centre(context, operation):
if str(radius) == "inf":
pg.error = PDT_ERR_STRIGHT_LINE
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_InfRadius
pg.distance = radius
if operation == "C":
scene.cursor.location = obj_loc + vector_delta
@@ -396,7 +318,7 @@ def placement_centre(context, operation):
if len(context.view_layer.objects.selected) != 3:
pg.error = f"{PDT_ERR_SEL_3_OBJS} {len(context.view_layer.objects.selected)})"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
vector_a = context.view_layer.objects.selected[0].matrix_world.decompose()[0]
vector_b = context.view_layer.objects.selected[1].matrix_world.decompose()[0]
vector_c = context.view_layer.objects.selected[2].matrix_world.decompose()[0]
@@ -443,7 +365,7 @@ def placement_intersect(context, operation):
if obj is None:
pg.error = PDT_ERR_NO_ACT_OBJ
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_NoObjectError
obj_loc = obj.matrix_world.decompose()[0]
bm = bmesh.from_edit_mesh(obj.data)
edges = [e for e in bm.edges if e.select]
@@ -464,7 +386,7 @@ def placement_intersect(context, operation):
+ " Edges)"
)
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
vertex_a = bm.select_history[-1]
vertex_b = bm.select_history[-2]
vertex_c = bm.select_history[-3]
@@ -474,7 +396,7 @@ def placement_intersect(context, operation):
if not done:
pg.error = f"{PDT_ERR_INT_LINES} {plane} {PDT_LAB_PLANE}"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_IntersectionError
if operation == "C":
scene.cursor.location = obj_loc + vector_delta
@@ -551,17 +473,17 @@ def placement_intersect(context, operation):
else:
pg.error = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_InvalidOperation
elif obj.mode == "OBJECT":
if len(context.view_layer.objects.selected) != 4:
pg.error = f"{PDT_ERR_SEL_4_OBJS} {len(context.view_layer.objects.selected)})"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ raise PDT_SelectionError
order = pg.object_order.split(",")
objs = sorted(context.view_layer.objects.selected, key=lambda x: x.name)
pg.error = (
- "Original Object Order was: "
+ "Original Object Order (1,2,3,4) was: "
+ objs[0].name
+ ", "
+ objs[1].name
@@ -580,7 +502,7 @@ def placement_intersect(context, operation):
if not done:
pg.error = f"{PDT_ERR_INT_LINES} {plane} {PD
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list