[Bf-extensions-cvs] [fccd99b8] blender-v2.82-release: PDT: Refactor codebase (stage 1 + 2)

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


Commit: fccd99b8324ca4b44eea964273b4f22c6d738690
Author: Alan Odom
Date:   Thu Jan 16 19:33:38 2020 +0000
Branches: blender-v2.82-release
https://developer.blender.org/rBAfccd99b8324ca4b44eea964273b4f22c6d738690

PDT: Refactor codebase (stage 1 + 2)

Moved all PDT Design Operations and Tools to Command Line file to de-dupe
code. All can now be called from the command line, e.g. a command of "otc" sets
the active objects Origin To Cursor, etc. Needs extensive further testing to see if all
Operations in all Modes still work exactly as before.
Tools menu split out from PDT Design so it can be minimised when not in use.

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

A	pdt_com_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_design.py
M	precision_drawing_tools/pdt_etof.py
M	precision_drawing_tools/pdt_functions.py
M	precision_drawing_tools/pdt_menus.py
M	precision_drawing_tools/pdt_msg_strings.py
M	precision_drawing_tools/pdt_pivot_point.py
M	precision_drawing_tools/pdt_view.py
M	precision_drawing_tools/pdt_xall.py

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

diff --git a/pdt_com_functions.py b/pdt_com_functions.py
new file mode 100644
index 00000000..7ae23293
--- /dev/null
+++ b/pdt_com_functions.py
@@ -0,0 +1,885 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+#
+# -----------------------------------------------------------------------
+# Author: Alan Odom (Clockmender), Rune Morling (ermo) Copyright (c) 2019
+# -----------------------------------------------------------------------
+#
+import bpy
+import bmesh
+import math
+from math import sqrt, tan, pi
+import numpy as np
+from mathutils import Vector
+from mathutils.geometry import intersect_point_line
+from .pdt_functions import (
+    set_mode,
+    oops,
+    get_percent,
+    dis_ang,
+    check_selection,
+    arc_centre,
+    intersection,
+    view_coords_i,
+    view_coords,
+    view_dir,
+    set_axis,
+)
+from .pdt_msg_strings import (
+    PDT_ERR_BAD3VALS,
+    PDT_ERR_BAD2VALS,
+    PDT_ERR_BAD1VALS,
+    PDT_ERR_CONNECTED,
+    PDT_ERR_SEL_2_VERTS,
+    PDT_ERR_EDOB_MODE,
+    PDT_ERR_NO_ACT_OBJ,
+    PDT_ERR_VERT_MODE,
+    PDT_ERR_SEL_3_VERTS,
+    PDT_ERR_SEL_3_OBJS,
+    PDT_ERR_EDIT_MODE,
+    PDT_ERR_NON_VALID,
+    PDT_LAB_NOR,
+    PDT_ERR_STRIGHT_LINE,
+    PDT_LAB_ARCCENTRE,
+    PDT_ERR_SEL_4_VERTS,
+    PDT_ERR_INT_NO_ALL,
+    PDT_LAB_INTERSECT,
+    PDT_ERR_SEL_4_OBJS,
+    PDT_INF_OBJ_MOVED,
+    PDT_ERR_SEL_2_VERTIO,
+    PDT_ERR_SEL_2_OBJS,
+    PDT_ERR_SEL_3_VERTIO,
+    PDT_ERR_TAPER_ANG,
+    PDT_ERR_TAPER_SEL,
+)
+
+
+def command_maths(self, context, pg, expression, output_target):
+    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(self, context, pg, obj, operation, values, num_values):
+    """Build Movement Vector from input Fields.
+
+    Args:
+        context: Blender bpy.context instance.
+        PDT parameter group as pg, object, operation,
+        command line values, required number of values.
+
+    Returns:
+        Vector to position, or offset items.
+    """
+
+    scene = context.scene
+    plane = pg.plane
+    flip_a = pg.flip_angle
+    flip_p = pg.flip_percent
+
+    if num_values == 3:
+        if len(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:
+            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:
+            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)
+
+
+def move_cursor_pivot(self, 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 = 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
+    return
+
+
+def placement_normal(self, context, operation):
+    """Manipulates Geometry, or Objects by Normal Intersection between 3 points.
+
+    -- set position of CUrsor       (CU)
+    -- set position of Pivot Point  (PP)
+    -- MoVe geometry/objects        (MV)
+    -- Extrude Vertices             (EV)
+    -- Split Edges                  (SE)
+    -- add a New Vertex             (NV)
+
+    Invalid Options result in "oops" Error.
+
+    Local vector variable 'vector_delta' used to reposition features.
+
+    Args:
+        context: Blender bpy.context instance.
+
+    Returns:
+        Status Set.
+    """
+
+    scene = context.scene
+    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":
+        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:
+                pg.error = PDT_ERR_VERT_MODE
+                context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+                return
+        else:
+            pg.error = f"{PDT_ERR_SEL_3_VERTS} {len(bm.select_history)})"
+            context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+            return
+    elif obj.mode == "OBJECT":
+        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")
+            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]
+    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":
+        if obj.mode == "EDIT":
+            pg.pivot_loc = obj_loc + vector_delta
+        elif obj.mode == "OBJECT":
+            pg.pivot_loc = vector_delta
+    elif operation == "G":
+        if obj.mode == "EDIT":
+            if ext_a:
+                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
+                )
+            else:
+                bm.select_history[-1].co = vector_delta
+                bm.select_history.clear()
+            bmesh.update_edit_mesh(obj.data)
+        elif obj.mode == "OBJECT":
+            context.view_layer.objects.active.location = vector_delta
+    elif operation == "N":
+        if obj.mode == "EDIT":
+            nVert = 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)
+        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.ve

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list