diff options
author | Alan Odom <clockmender@icloud.com> | 2020-01-20 23:48:53 +0300 |
---|---|---|
committer | Rune Morling <ermo.blender.org@spammesenseless.net> | 2020-02-01 18:40:43 +0300 |
commit | 0e62a382183b02799dda7e48d5a3f97dd2321be9 (patch) | |
tree | 00c3da979cc19f05ed7ca7f0aa0ebd5d6a1c0582 /precision_drawing_tools | |
parent | fccd99b8324ca4b44eea964273b4f22c6d738690 (diff) |
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.
Diffstat (limited to 'precision_drawing_tools')
-rw-r--r-- | precision_drawing_tools/__init__.py | 2 | ||||
-rw-r--r-- | precision_drawing_tools/pdt_bix.py | 8 | ||||
-rw-r--r-- | precision_drawing_tools/pdt_command.py | 114 | ||||
-rw-r--r-- | precision_drawing_tools/pdt_etof.py | 2 | ||||
-rw-r--r-- | precision_drawing_tools/pdt_functions.py | 108 | ||||
-rw-r--r-- | precision_drawing_tools/pdt_xall.py | 2 |
6 files changed, 136 insertions, 100 deletions
diff --git a/precision_drawing_tools/__init__.py b/precision_drawing_tools/__init__.py index 37f83ef2..1d2bb313 100644 --- a/precision_drawing_tools/__init__.py +++ b/precision_drawing_tools/__init__.py @@ -29,7 +29,7 @@ bl_info = { "name": "Precision Drawing Tools (PDT)", "author": "Alan Odom (Clockmender), Rune Morling (ermo)", - "version": (1, 1, 8), + "version": (1, 2, 0), "blender": (2, 80, 0), "location": "View3D > UI > PDT", "description": "Precision Drawing Tools for Acccurate Modelling", diff --git a/precision_drawing_tools/pdt_bix.py b/precision_drawing_tools/pdt_bix.py index adf4d335..0da468cb 100644 --- a/precision_drawing_tools/pdt_bix.py +++ b/precision_drawing_tools/pdt_bix.py @@ -34,7 +34,7 @@ from .pdt_msg_strings import ( ) from .pdt_functions import debug, oops -def add_line_to_bisection(self, context): +def add_line_to_bisection(context): """Computes Bisector of 2 Co-Planar Edges. Args: @@ -46,7 +46,7 @@ def add_line_to_bisection(self, context): obj = context.object if all([bool(obj), obj.type == "MESH", obj.mode == "EDIT"]): - pg = scene.pdt_pg + pg = context.scene.pdt_pg me = obj.data bm = bmesh.from_edit_mesh(me) @@ -70,8 +70,8 @@ def add_line_to_bisection(self, context): edge2 = (v3, v4) if not cm.test_coplanar(edge1, edge2): - msg = PDT_ERR_NCEDGES - self.report({"ERROR"}, msg) + pg.error = PDT_ERR_NCEDGES + context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return # get pt and pick farthest vertex from (projected) intersections diff --git a/precision_drawing_tools/pdt_command.py b/precision_drawing_tools/pdt_command.py index 8013a38a..5b6b1b51 100644 --- a/precision_drawing_tools/pdt_command.py +++ b/precision_drawing_tools/pdt_command.py @@ -32,7 +32,7 @@ from .pdt_functions import ( oops, update_sel, ) -from .pdt_com_functions import ( +from .pdt_command_functions import ( command_maths, vector_build, move_cursor_pivot, @@ -194,37 +194,37 @@ def command_run(self, context): elif command == "": return elif command.upper() == "J2V": - join_two_vertices(self, context) + join_two_vertices(context) return elif command.upper() == "AD2": - set_angle_distance_two(self, context) + set_angle_distance_two(context) return elif command.upper() == "AD3": - set_angle_distance_three(self, context) + set_angle_distance_three(context) return elif command.upper() == "OTC": - origin_to_cursor(self, context) + origin_to_cursor(context) return elif command.upper() == "TAP": taper(self, context) return elif command.upper() == "BIS": - add_line_to_bisection(self, context) + add_line_to_bisection(context) return elif command.upper() == "ETF": extend_vertex(self, context) return elif command.upper() == "INTALL": - intersect_all(self, context) + intersect_all(context) return elif command.upper()[1:4] == "NML": - placement_normal(self, context, command.upper()[0]) + placement_normal(context, command.upper()[0]) return elif command.upper()[1:4] == "CEN": - placement_centre(self, context, command.upper()[0]) + placement_centre(context, command.upper()[0]) return elif command.upper()[1:4] == "INT": - placement_intersect(self, context, command.upper()[0]) + placement_intersect(context, command.upper()[0]) return elif len(command) < 3: pg.error = PDT_ERR_CHARS_NUM @@ -262,7 +262,7 @@ def command_run(self, context): # -------------- # Maths Operation if operation == "M": - command_maths(self, context, pg, command[2:], mode) + command_maths(context, mode, pg, command[2:], mode) return # ----------------------------------------------------- @@ -309,16 +309,16 @@ def command_run(self, context): if operation in {"C", "P"}: # Absolute/Global Coordinates, or Delta/Relative Coordinates if mode in {"a", "d"}: - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) # Direction/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) # Percent Options elif mode == "p": - vector_delta = vector_build(self, context, pg, obj, operation, values, 1) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 1) - if vector_delta is not None: - move_cursor_pivot(self, context, pg, obj, verts, operation, + if valid_result: + move_cursor_pivot(context, pg, obj, verts, operation, mode, vector_delta) return @@ -332,7 +332,9 @@ def command_run(self, context): return # Absolute/Global Coordinates if mode == "a": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return if obj.mode == "EDIT": for v in verts: v.co = vector_delta - obj_loc @@ -346,10 +348,14 @@ def command_run(self, context): elif mode in {"d", "i"}: if mode == "d": # Delta/Relative Coordinates - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return else: # Direction/Polar Coordinates - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) + if not valid_result: + return if vector_delta is not None: if obj.mode == "EDIT": bmesh.ops.translate( @@ -360,7 +366,9 @@ def command_run(self, context): ob.location = obj_loc + vector_delta # Percent Options elif mode == "p": - vector_delta = vector_build(self, context, pg, obj, operation, values, 1) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 1) + if not valid_result: + return if vector_delta is not None: if obj.mode == 'EDIT': verts[-1].co = vector_delta @@ -380,19 +388,27 @@ def command_run(self, context): return # Absolute/Global Coordinates if mode == "a": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return new_vertex = bm.verts.new(vector_delta - obj_loc) # Delta/Relative Coordinates elif mode == "d": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return new_vertex = bm.verts.new(verts[-1].co + vector_delta) # Direction/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) + if not valid_result: + return new_vertex = bm.verts.new(verts[-1].co + vector_delta) # Percent Options elif mode == "p": - vector_delta = vector_build(self, context, pg, obj, operation, values, 1) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 1) + if not valid_result: + return new_vertex = bm.verts.new(vector_delta) for v in [v for v in bm.verts if v.select]: @@ -411,7 +427,9 @@ def command_run(self, context): return # Absolute/Global Coordinates if mode == "a": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return edges = [e for e in bm.edges if e.select] if len(edges) != 1: pg.error = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})" @@ -423,7 +441,9 @@ def command_run(self, context): new_vertex.co = vector_delta - obj_loc # Delta/Relative Coordinates elif mode == "d": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return edges = [e for e in bm.edges if e.select] faces = [f for f in bm.faces if f.select] if len(faces) != 0: @@ -439,7 +459,9 @@ def command_run(self, context): bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta) # Directional/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) + if not valid_result: + return edges = [e for e in bm.edges if e.select] faces = [f for f in bm.faces if f.select] if len(faces) != 0: @@ -455,8 +477,8 @@ def command_run(self, context): bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta) # Percent Options elif mode == "p": - vector_delta = vector_build(self, context, pg, obj, operation, values, 1) - if vector_delta is None: + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 1) + if not valid_result: return edges = [e for e in bm.edges if e.select] faces = [f for f in bm.faces if f.select] @@ -464,7 +486,7 @@ def command_run(self, context): pg.error = PDT_ERR_FACE_SEL context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return - if len(edges) < 1: + if len(edges) != 1: pg.error = f"{PDT_ERR_SEL_1_EDGEM} {len(edges)})" context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return @@ -490,7 +512,9 @@ def command_run(self, context): return # Absolute/Global Coordinates if mode == "a": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return new_vertex = bm.verts.new(vector_delta - obj_loc) for v in verts: bm.edges.new([v, new_vertex]) @@ -501,7 +525,9 @@ def command_run(self, context): ) # Delta/Relative Coordinates elif mode == "d": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return for v in verts: new_vertex = bm.verts.new(v.co) new_vertex.co = new_vertex.co + vector_delta @@ -510,7 +536,9 @@ def command_run(self, context): new_vertex.select_set(True) # Direction/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) + if not valid_result: + return for v in verts: new_vertex = bm.verts.new(v.co) new_vertex.co = new_vertex.co + vector_delta @@ -519,7 +547,9 @@ def command_run(self, context): new_vertex.select_set(True) # Percent Options elif mode == "p": - vector_delta = vector_build(self, context, pg, obj, operation, values, 1) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 1) + if not valid_result: + return verts = [v for v in bm.verts if v.select].copy() if len(verts) == 0: pg.error = PDT_ERR_NO_SEL_GEOM @@ -547,10 +577,14 @@ def command_run(self, context): return # Delta/Relative Coordinates if mode == "d": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return # Direction/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, values, 2) + if not valid_result: + return ret = bmesh.ops.extrude_face_region( bm, @@ -581,10 +615,14 @@ def command_run(self, context): return # Delta/Relative Coordinates if mode == "d": - vector_delta = vector_build(self, context, pg, obj, operation, values, 3) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 3) + if not valid_result: + return # Direction/Polar Coordinates elif mode == "i": - vector_delta = vector_build(self, context, pg, obj, operation, values, 2) + valid_result, vector_delta = vector_build(context, pg, obj, operation, values, 2) + if not valid_result: + return ret = bmesh.ops.duplicate( bm, diff --git a/precision_drawing_tools/pdt_etof.py b/precision_drawing_tools/pdt_etof.py index e1b65f6f..385c12f4 100644 --- a/precision_drawing_tools/pdt_etof.py +++ b/precision_drawing_tools/pdt_etof.py @@ -49,7 +49,7 @@ def failure_message_on_plane(self, context): context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return -def extend_vertex(self, context): +def extend_vertex(context): """Computes Edge Extension to Face. Args: diff --git a/precision_drawing_tools/pdt_functions.py b/precision_drawing_tools/pdt_functions.py index cc800d61..d6462852 100644 --- a/precision_drawing_tools/pdt_functions.py +++ b/precision_drawing_tools/pdt_functions.py @@ -166,21 +166,21 @@ def check_selection(num, bm, obj): else: actE = bm.select_history[-1] if isinstance(actE, bmesh.types.BMVert): - actV = actE.co + vector_a = actE.co if num == 1: - return actV + return vector_a elif num == 2: - othV = bm.select_history[-2].co - return actV, othV + vector_b = bm.select_history[-2].co + return vector_a, vector_b elif num == 3: - othV = bm.select_history[-2].co - lstV = bm.select_history[-3].co - return actV, othV, lstV + vector_b = bm.select_history[-2].co + vector_c = bm.select_history[-3].co + return vector_a, vector_b, vector_d elif num == 4: - othV = bm.select_history[-2].co - lstV = bm.select_history[-3].co - fstV = bm.select_history[-4].co - return actV, othV, lstV, fstV + vector_b = bm.select_history[-2].co + vector_c = bm.select_history[-3].co + vector_d = bm.select_history[-4].co + return vector_a, vector_b, vector_d, vector_c else: for f in bm.faces: f.select_set(False) @@ -271,7 +271,7 @@ def view_dir(dis_v, ang_v): """Converts Distance and Angle to View Oriented Vector. Converts View Transformation Matrix to Rotational Matrix (3x3) - Angles are converted to Radians from degrees. + Angles are Converts to Radians from degrees. Args: dis_v: Scene distance @@ -319,21 +319,21 @@ def euler_to_quaternion(roll, pitch, yaw): return Quaternion((qw, qx, qy, qz)) -def arc_centre(actV, othV, lstV): +def arc_centre(vector_a, vector_b, vector_d): """Calculates Centre of Arc from 3 Vector Locations using standard Numpy routine Args: - actV: Active vector location - othV: Other vector location - lstV: Last vector location + vector_a: Active vector location + vector_b: Other vector location + vector_d: Last vector location Returns: Vector representing Arc Centre and Float representing Arc Radius. """ - A = np.array([actV.x, actV.y, actV.z]) - B = np.array([othV.x, othV.y, othV.z]) - C = np.array([lstV.x, lstV.y, lstV.z]) + A = np.array([vector_a.x, vector_a.y, vector_a.z]) + B = np.array([vector_b.x, vector_b.y, vector_b.z]) + C = np.array([vector_d.x, vector_d.y, vector_d.z]) a = np.linalg.norm(C - B) b = np.linalg.norm(C - A) c = np.linalg.norm(B - A) @@ -349,41 +349,38 @@ def arc_centre(actV, othV, lstV): return Vector((P[0], P[1], P[2])), R -def intersection(actV, othV, lstV, fstV, plane): +def intersection(vertex_a, vertex_b, vertex_c, vertex_d, plane): """Calculates Intersection Point of 2 Imagined Lines from 4 Vectors. - Calculates Converging Intersect Location and indication of whether the lines are convergent using standard Numpy Routines - Args: - actV: Active vector location of first line - othV: Other vector location of first line - lstV: Last vector location of 2nd line - fstV: First vector location of 2nd line + vertex_a: Active vector location of first line + vertex_b: Other vector location of first line + vertex_d: Last vector location of 2nd line + vertex_c: First vector location of 2nd line plane: Working Plane 4 Vector Locations representing 2 lines and Working Plane - Returns: Intersection Vector and Boolean for convergent state. """ if plane == "LO": - disV = othV - actV - othV = view_coords_i(disV.x, disV.y, disV.z) - disV = lstV - actV - lstV = view_coords_i(disV.x, disV.y, disV.z) - disV = fstV - actV - fstV = view_coords_i(disV.x, disV.y, disV.z) + vertex_offset = vertex_b - vertex_a + vertex_b = view_coords_i(vertex_offset.x, vertex_offset.y, vertex_offset.z) + vertex_offset = vertex_d - vertex_a + vertex_d = view_coords_i(vertex_offset.x, vertex_offset.y, vertex_offset.z) + vertex_offset = vertex_c - vertex_a + vertex_c = view_coords_i(vertex_offset.x, vertex_offset.y, vertex_offset.z) refV = Vector((0, 0, 0)) - ap1 = (fstV.x, fstV.y) - ap2 = (lstV.x, lstV.y) - bp1 = (othV.x, othV.y) + ap1 = (vertex_c.x, vertex_c.y) + ap2 = (vertex_d.x, vertex_d.y) + bp1 = (vertex_b.x, vertex_b.y) bp2 = (refV.x, refV.y) else: a1, a2, a3 = set_mode(plane) - ap1 = (fstV[a1], fstV[a2]) - ap2 = (lstV[a1], lstV[a2]) - bp1 = (othV[a1], othV[a2]) - bp2 = (actV[a1], actV[a2]) + ap1 = (vertex_c[a1], vertex_c[a2]) + ap2 = (vertex_d[a1], vertex_d[a2]) + bp1 = (vertex_a[a1], vertex_a[a2]) + bp2 = (vertex_b[a1], vertex_b[a2]) s = np.vstack([ap1, ap2, bp1, bp2]) h = np.hstack((s, np.ones((4, 1)))) l1 = np.cross(h[0], h[1]) @@ -396,7 +393,7 @@ def intersection(actV, othV, lstV, fstV, plane): if plane == "LO": ly = 0 else: - ly = actV[a3] + ly = vertex_a[a3] # Order Vector Delta if plane == "XZ": vector_delta = Vector((nx, ly, nz)) @@ -405,7 +402,7 @@ def intersection(actV, othV, lstV, fstV, plane): elif plane == "YZ": vector_delta = Vector((ly, nx, nz)) elif plane == "LO": - vector_delta = viewCoords(nx, nz, ly) + actV + vector_delta = view_coords(nx, nz, ly) + vertex_a return vector_delta, True @@ -435,9 +432,9 @@ def get_percent(obj, flip_p, per_v, data, scene): bm = bmesh.from_edit_mesh(obj.data) verts = [v for v in bm.verts if v.select] if len(verts) == 2: - actV = verts[0].co - othV = verts[1].co - if actV is None: + vector_a = verts[0].co + vector_b = verts[1].co + if vector_a is None: pg.error = PDT_ERR_VERT_MODE bpy.context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return None @@ -445,8 +442,8 @@ def get_percent(obj, flip_p, per_v, data, scene): pg.error = PDT_ERR_SEL_2_V_1_E + str(len(verts)) + " Vertices" bpy.context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return None - p1 = np.array([actV.x, actV.y, actV.z]) - p2 = np.array([othV.x, othV.y, othV.z]) + p1 = np.array([vector_a.x, vector_a.y, vector_a.z]) + p2 = np.array([vector_b.x, vector_b.y, vector_b.z]) if obj.mode == "OBJECT": objs = bpy.context.view_layer.objects.selected if len(objs) != 2: @@ -506,14 +503,14 @@ def obj_check(obj, scene, operator): return bm, True if len(bm.select_history) >= 1: if _operator not in {"D", "E", "F", "G", "N", "S"}: - actV = check_selection(1, bm, obj) + vector_a = check_selection(1, bm, obj) else: verts = [v for v in bm.verts if v.select] if len(verts) > 0: - actV = verts[0] + vector_a = verts[0] else: - actV = None - if actV is None: + vector_a = None + if vector_a is None: pg.error = PDT_ERR_VERT_MODE bpy.context.window_manager.popup_menu(oops, title="Error", icon="ERROR") return None, False @@ -614,10 +611,11 @@ def drawCallback3D(self, context): if len(areas) > 0: sf = abs(areas[0].spaces.active.region_3d.window_matrix.decompose()[2][1]) # Check for orhtographic view and resize - if areas[0].spaces.active.region_3d.is_orthographic_side_view: - a = w / sf / 60000 * pg.pivot_size - else: - a = w / sf / 5000 * pg.pivot_size + #if areas[0].spaces.active.region_3d.is_orthographic_side_view: + # a = w / sf / 60000 * pg.pivot_size + #else: + # a = w / sf / 5000 * pg.pivot_size + a = w / sf / 50000 * pg.pivot_size b = a * 0.65 c = a * 0.05 + (pg.pivot_width * a * 0.02) o = c / 3 diff --git a/precision_drawing_tools/pdt_xall.py b/precision_drawing_tools/pdt_xall.py index 0c01b5d8..1c283cb6 100644 --- a/precision_drawing_tools/pdt_xall.py +++ b/precision_drawing_tools/pdt_xall.py @@ -146,7 +146,7 @@ def unselect_nonintersecting(bm, d_edges, edge_indices): bm.edges[edge].select = False -def intersect_all(self, context): +def intersect_all(context): """Computes All intersections with Crossing Geometry. Deletes original edges and replaces with new intersected edges |