[Bf-extensions-cvs] [0e62a382] blender-v2.82-release: PDT: Refactor - Stage 3 (Pylint & Black runs)

Alan Odom noreply at git.blender.org
Sat Feb 1 16:44:48 CET 2020


Commit: 0e62a382183b02799dda7e48d5a3f97dd2321be9
Author: Alan Odom
Date:   Mon Jan 20 20:48:53 2020 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBA0e62a382183b02799dda7e48d5a3f97dd2321be9

PDT: Refactor - Stage 3 (Pylint & Black runs)

Most of the recommendations from pylint are now done, I have not changed variables
like v in expression [v for v in... as I consider these to be normal coding practice.

Rename pdt_com_functions.py to pdt_command_functions.py

Fix error in Intersect operation if selected vertices resulted in more than
2 edges being selected. Priority is given to two edges as a selection, then to
4 vertices, if the four vertices represent two edges, the intersection point is
at the intersection of the two edges, which might not be the four vertices, if
one of the vertices forms part of two edges that are also selected.

Priority is 2 edges, then 4 vertices selected individually with the mouse.

===================================================================

R069	pdt_com_functions.py	pdt_command_functions.py
M	precision_drawing_tools/__init__.py
M	precision_drawing_tools/pdt_bix.py
M	precision_drawing_tools/pdt_command.py
M	precision_drawing_tools/pdt_etof.py
M	precision_drawing_tools/pdt_functions.py
M	precision_drawing_tools/pdt_xall.py

===================================================================

diff --git a/pdt_com_functions.py b/pdt_command_functions.py
similarity index 69%
rename from pdt_com_functions.py
rename to pdt_command_functions.py
index 7ae23293..b7653229 100644
--- a/pdt_com_functions.py
+++ b/pdt_command_functions.py
@@ -67,10 +67,22 @@ 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(self, context, pg, expression, output_target):
+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")
@@ -99,7 +111,8 @@ def command_maths(self, context, pg, expression, output_target):
         pg.maths_output = maths_result
     return
 
-def vector_build(self, context, pg, obj, operation, values, num_values):
+
+def vector_build(context, pg, obj, operation, values, num_values):
     """Build Movement Vector from input Fields.
 
     Args:
@@ -116,28 +129,25 @@ def vector_build(self, context, pg, obj, operation, values, num_values):
     flip_a = pg.flip_angle
     flip_p = pg.flip_percent
 
-    if num_values == 3:
-        if len(values) != 3:
+    if num_values == 3 and len(values) == 3:
+        output_vector = Vector((float(values[0]), float(values[1]), float(values[2])))
+    elif num_values == 2 and len(values) == 2:
+        output_vector = dis_ang(values, flip_a, plane, scene)
+    elif num_values == 1 and len(values) == 1:
+        output_vector = get_percent(obj, flip_p, float(values[0]), operation, scene)
+    else:
+        if num_values == 3:
             pg.error = PDT_ERR_BAD3VALS
-            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
-            return None
-        return Vector((float(values[0]), float(values[1]), float(values[2])))
-    elif num_values == 2:
-        if len(values) != 2:
+        elif num_values == 2:
             pg.error = PDT_ERR_BAD2VALS
-            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
-            return
-        return dis_ang(values, flip_a, plane, scene)
-    elif num_values == 1:
-        if len(values) != 1:
+        else:
             pg.error = PDT_ERR_BAD1VALS
-            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
-            return
-        return get_percent(obj, flip_p, float(values[0]), operation, scene)
+        context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+        return False, Vector((0, 0, 0))
+    return True, output_vector
 
 
-def move_cursor_pivot(self, context, pg, obj, sel_verts, operation,
-        mode_op, vector_delta):
+def move_cursor_pivot(context, pg, obj, sel_verts, operation, mode_op, vector_delta):
     """Move Cursor or Pivot Point.
 
     Args:
@@ -157,7 +167,7 @@ def move_cursor_pivot(self, context, pg, obj, sel_verts, operation,
             scene.cursor.location = vector_delta
         elif operation == "P":
             pg.pivot_loc = vector_delta
-    elif mode_op in {"d","i"}:
+    elif mode_op in {"d", "i"}:
         if mode_sel == "REL":
             if operation == "C":
                 scene.cursor.location = scene.cursor.location + vector_delta
@@ -166,11 +176,9 @@ def move_cursor_pivot(self, context, pg, obj, sel_verts, operation,
         elif mode_sel == "SEL":
             if obj.mode == "EDIT":
                 if operation == "C":
-                    scene.cursor.location = (
-                        sel_verts[-1].co + obj_loc + vector_delta
-                    )
+                    scene.cursor.location = sel_verts[-1].co + obj_loc + vector_delta
                 else:
-                    pg.pivot_loc = verts[-1].co + obj_loc + vector_delta
+                    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
@@ -187,10 +195,9 @@ def move_cursor_pivot(self, context, pg, obj, sel_verts, operation,
                 scene.cursor.location = vector_delta
             else:
                 pg.pivot_loc = vector_delta
-    return
 
 
-def placement_normal(self, context, operation):
+def placement_normal(context, operation):
     """Manipulates Geometry, or Objects by Normal Intersection between 3 points.
 
     -- set position of CUrsor       (CU)
@@ -215,16 +222,17 @@ def placement_normal(self, context, operation):
     pg = scene.pdt_pg
     ext_a = pg.extend
     obj = context.view_layer.objects.active
-    if obj is None:
-        pg.error = PDT_ERR_NO_ACT_OBJ
-        context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
-        return
-    obj_loc = obj.matrix_world.decompose()[0]
+
     if obj.mode == "EDIT":
+        if obj is None:
+            pg.error = PDT_ERR_NO_ACT_OBJ
+            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+            return
+        obj_loc = obj.matrix_world.decompose()[0]
         bm = bmesh.from_edit_mesh(obj.data)
         if len(bm.select_history) == 3:
-            actV, othV, lstV = check_selection(3, bm, obj)
-            if actV is None:
+            vector_a, vector_b, vector_c = check_selection(3, bm, obj)
+            if vector_a is None:
                 pg.error = PDT_ERR_VERT_MODE
                 context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
                 return
@@ -236,20 +244,19 @@ def placement_normal(self, context, operation):
         objs = context.view_layer.objects.selected
         if len(objs) != 3:
             pg.error = f"{PDT_ERR_SEL_3_OBJS} {len(objs)})"
-            scontext.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
             return
-        else:
-            objs_s = [ob for ob in objs if ob.name != obj.name]
-            actV = obj.matrix_world.decompose()[0]
-            othV = objs_s[-1].matrix_world.decompose()[0]
-            lstV = objs_s[-2].matrix_world.decompose()[0]
-    vector_delta = intersect_point_line(actV, othV, lstV)[0]
+        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]
+        vector_c = objs_s[-2].matrix_world.decompose()[0]
+    vector_delta = intersect_point_line(vector_a, vector_b, vector_c)[0]
     if operation == "C":
         if obj.mode == "EDIT":
             scene.cursor.location = obj_loc + vector_delta
         elif obj.mode == "OBJECT":
             scene.cursor.location = vector_delta
-    elif operation.upper == "P":
+    elif operation == "P":
         if obj.mode == "EDIT":
             pg.pivot_loc = obj_loc + vector_delta
         elif obj.mode == "OBJECT":
@@ -260,9 +267,7 @@ def placement_normal(self, context, operation):
                 for v in [v for v in bm.verts if v.select]:
                     v.co = vector_delta
                 bm.select_history.clear()
-                bmesh.ops.remove_doubles(
-                    bm, verts=[v for v in bm.verts if v.select], dist=0.0001
-                )
+                bmesh.ops.remove_doubles(bm, verts=[v for v in bm.verts if v.select], dist=0.0001)
             else:
                 bm.select_history[-1].co = vector_delta
                 bm.select_history.clear()
@@ -271,27 +276,27 @@ def placement_normal(self, context, operation):
             context.view_layer.objects.active.location = vector_delta
     elif operation == "N":
         if obj.mode == "EDIT":
-            nVert = bm.verts.new(vector_delta)
+            vertex_new = bm.verts.new(vector_delta)
             bmesh.update_edit_mesh(obj.data)
             bm.select_history.clear()
             for v in [v for v in bm.verts if v.select]:
                 v.select_set(False)
-            nVert.select_set(True)
+            vertex_new.select_set(True)
         else:
             pg.error = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
             context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
             return
     elif operation == "V" and obj.mode == "EDIT":
-        vNew = vector_delta
-        nVert = bm.verts.new(vNew)
+        vector_new = vector_delta
+        vertex_new = bm.verts.new(vector_new)
         if ext_a:
             for v in [v for v in bm.verts if v.select]:
-                bm.edges.new([v, nVert])
+                bm.edges.new([v, vertex_new])
         else:
-            bm.edges.new([bm.select_history[-1], nVert])
+            bm.edges.new([bm.select_history[-1], vertex_new])
         for v in [v for v in bm.verts if v.select]:
             v.select_set(False)
-        nVert.select_set(True)
+        vertex_new.select_set(True)
         bmesh.update_edit_mesh(obj.data)
         bm.select_history.clear()
     else:
@@ -299,7 +304,8 @@ def placement_normal(self, context, operation):
         context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
     return
 
-def placement_centre(self, context, operation):
+
+def placement_centre(context, operation):
     """Manipulates Geometry, or Objects to an Arc Centre defined by 3 points on an Imaginary Arc.
 
     -- set position of CUrsor       (CU)
@@ -308,7 +314,7 @@ def placement_centre(self, context, operation):
     -- Extrude Vertices             (EV)
     -- add a New vertex             (NV)
 
-    Invalid Options result in self.report Error.
+    Invalid Options result in "oops" Error.
 
     Local vector variable 'vector_delta' used to reposition features.
 
@@ -324,24 +330,23 @@ def placement_centre(self, context, operation):
     ext_a = pg.extend
     obj = context.view_layer.objects.active
 
-    if obj is None:
-        pg.error = PDT_ERR_NO_ACT_OBJ
-        context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
-        return
    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list