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-16 22:33:38 +0300
committerRune Morling <ermo.blender.org@spammesenseless.net>2020-02-01 18:40:29 +0300
commitfccd99b8324ca4b44eea964273b4f22c6d738690 (patch)
tree64579493ce4b735b560971dbf5a859a664751ff7 /precision_drawing_tools
parentc8846a9e1a07b356523cc5e36227d469706fdc08 (diff)
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.
Diffstat (limited to 'precision_drawing_tools')
-rw-r--r--precision_drawing_tools/__init__.py5
-rw-r--r--precision_drawing_tools/pdt_bix.py107
-rw-r--r--precision_drawing_tools/pdt_command.py774
-rw-r--r--precision_drawing_tools/pdt_design.py1289
-rw-r--r--precision_drawing_tools/pdt_etof.py98
-rw-r--r--precision_drawing_tools/pdt_functions.py51
-rw-r--r--precision_drawing_tools/pdt_menus.py36
-rw-r--r--precision_drawing_tools/pdt_msg_strings.py7
-rw-r--r--precision_drawing_tools/pdt_pivot_point.py4
-rw-r--r--precision_drawing_tools/pdt_view.py90
-rw-r--r--precision_drawing_tools/pdt_xall.py63
11 files changed, 702 insertions, 1822 deletions
diff --git a/precision_drawing_tools/__init__.py b/precision_drawing_tools/__init__.py
index 35e55158..37f83ef2 100644
--- a/precision_drawing_tools/__init__.py
+++ b/precision_drawing_tools/__init__.py
@@ -272,7 +272,7 @@ class PDTSceneProperties(PropertyGroup):
items=(
("CU", "Move Cursor", "This function will Move the Cursor"),
("PP", "Move Pivot Point", "This function will Move the Pivot Point"),
- ("MV", "Move (per Move Mode)", "This function will Move selected Vertices or Objects"),
+ ("MV", "Move Entities", "This function will Move selected Vertices or Objects"),
("NV", "Add New Vertex", "This function will Add a New Vertex"),
("EV", "Extrude Vertex/Vertices", "This function will Extrude Vertex/Vertices Only in EDIT Mode"),
("SE", "Split Edges", "This function will Split Edges Only in EDIT Mode"),
@@ -420,7 +420,7 @@ class PDTSceneProperties(PropertyGroup):
default=True,
description=PDT_DES_FILLETVERTS,
)
- fillet_int : BoolProperty(
+ fillet_intersect : BoolProperty(
name="Intersect",
default=False,
description=PDT_DES_FILLINT,
@@ -487,6 +487,7 @@ classes = (
pdt_library.PDT_OT_Link,
pdt_library.PDT_OT_LibShow,
pdt_menus.PDT_PT_PanelDesign,
+ pdt_menus.PDT_PT_PanelTools,
pdt_menus.PDT_PT_PanelCommandLine,
pdt_menus.PDT_PT_PanelViewControl,
pdt_menus.PDT_PT_PanelPivotPoint,
diff --git a/precision_drawing_tools/pdt_bix.py b/precision_drawing_tools/pdt_bix.py
index e59c1e08..adf4d335 100644
--- a/precision_drawing_tools/pdt_bix.py
+++ b/precision_drawing_tools/pdt_bix.py
@@ -27,8 +27,12 @@
import bpy
import bmesh
from . import pdt_cad_module as cm
-from .pdt_msg_strings import PDT_ERR_2CPNPE, PDT_ERR_NCEDGES
-from .pdt_functions import debug
+from .pdt_msg_strings import (
+ PDT_ERR_2CPNPE,
+ PDT_ERR_NCEDGES,
+ PDT_ERR_EDOB_MODE,
+)
+from .pdt_functions import debug, oops
def add_line_to_bisection(self, context):
"""Computes Bisector of 2 Co-Planar Edges.
@@ -41,53 +45,59 @@ def add_line_to_bisection(self, context):
"""
obj = context.object
- me = obj.data
- bm = bmesh.from_edit_mesh(me)
-
- bm.verts.ensure_lookup_table()
- bm.edges.ensure_lookup_table()
-
- edges = [e for e in bm.edges if e.select and not e.hide]
-
- if not len(edges) == 2:
- msg = PDT_ERR_2CPNPE
- self.report({"ERROR"}, msg)
- return
-
- [[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges]
- debug(f"vectors found:\n {v1}\n {v2}\n {v3}\n {v4}")
-
- dist1 = (v1 - v2).length
- dist2 = (v3 - v4).length
- bdist = min([dist1, dist2])
- edge1 = (v1, v2)
- edge2 = (v3, v4)
-
- if not cm.test_coplanar(edge1, edge2):
- msg = PDT_ERR_NCEDGES
- self.report({"ERROR"}, msg)
+ if all([bool(obj), obj.type == "MESH", obj.mode == "EDIT"]):
+ pg = scene.pdt_pg
+ me = obj.data
+ bm = bmesh.from_edit_mesh(me)
+
+ bm.verts.ensure_lookup_table()
+ bm.edges.ensure_lookup_table()
+
+ edges = [e for e in bm.edges if e.select and not e.hide]
+
+ if not len(edges) == 2:
+ pg.error = f"{PDT_ERR_2CPNPE}"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
+
+ [[v1, v2], [v3, v4]] = [[v.co for v in e.verts] for e in edges]
+ debug(f"vectors found:\n {v1}\n {v2}\n {v3}\n {v4}")
+
+ dist1 = (v1 - v2).length
+ dist2 = (v3 - v4).length
+ bdist = min([dist1, dist2])
+ edge1 = (v1, v2)
+ edge2 = (v3, v4)
+
+ if not cm.test_coplanar(edge1, edge2):
+ msg = PDT_ERR_NCEDGES
+ self.report({"ERROR"}, msg)
+ return
+
+ # get pt and pick farthest vertex from (projected) intersections
+ pt = cm.get_intersection(edge1, edge2)
+ far1 = v2 if (v1 - pt).length < (v2 - pt).length else v1
+ far2 = v4 if (v3 - pt).length < (v4 - pt).length else v3
+
+ dex1 = far1 - pt
+ dex2 = far2 - pt
+ dex1 = dex1 * (bdist / dex1.length)
+ dex2 = dex2 * (bdist / dex2.length)
+ pt2 = pt + (dex1).lerp(dex2, 0.5)
+ pt3 = pt2.lerp(pt, 2.0)
+
+ vec1 = bm.verts.new(pt2)
+ vec2 = bm.verts.new(pt)
+ vec3 = bm.verts.new(pt3)
+ bm.edges.new((vec1, vec2))
+ bm.edges.new((vec2, vec3))
+ bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
+ bmesh.update_edit_mesh(me)
+ else:
+ pg.error = f"{PDT_ERR_EDOB_MODE},{obj.mode})"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- # get pt and pick farthest vertex from (projected) intersections
- pt = cm.get_intersection(edge1, edge2)
- far1 = v2 if (v1 - pt).length < (v2 - pt).length else v1
- far2 = v4 if (v3 - pt).length < (v4 - pt).length else v3
-
- dex1 = far1 - pt
- dex2 = far2 - pt
- dex1 = dex1 * (bdist / dex1.length)
- dex2 = dex2 * (bdist / dex2.length)
- pt2 = pt + (dex1).lerp(dex2, 0.5)
- pt3 = pt2.lerp(pt, 2.0)
-
- vec1 = bm.verts.new(pt2)
- vec2 = bm.verts.new(pt)
- vec3 = bm.verts.new(pt3)
- bm.edges.new((vec1, vec2))
- bm.edges.new((vec2, vec3))
- bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
- bmesh.update_edit_mesh(me)
-
class PDT_OT_LineOnBisection(bpy.types.Operator):
"""Create Bisector between 2 Selected Edges."""
@@ -114,5 +124,6 @@ class PDT_OT_LineOnBisection(bpy.types.Operator):
Status Set.
"""
- add_line_to_bisection(self, context)
+ pg = context.scene.pdt_pg
+ pg.command = f"bis"
return {"FINISHED"}
diff --git a/precision_drawing_tools/pdt_command.py b/precision_drawing_tools/pdt_command.py
index 6b433fcc..8013a38a 100644
--- a/precision_drawing_tools/pdt_command.py
+++ b/precision_drawing_tools/pdt_command.py
@@ -25,31 +25,35 @@ import bpy
import bmesh
from bpy.types import Operator
from mathutils import Vector
-import math
from .pdt_functions import (
debug,
- disAng,
- getPercent,
intersection,
- objCheck,
+ obj_check,
oops,
- updateSel,
+ update_sel,
+)
+from .pdt_com_functions import (
+ command_maths,
+ vector_build,
+ move_cursor_pivot,
+ join_two_vertices,
+ set_angle_distance_two,
+ set_angle_distance_three,
+ origin_to_cursor,
+ taper,
+ placement_normal,
+ placement_centre,
+ placement_intersect,
)
from .pdt_msg_strings import (
PDT_ERR_ADDVEDIT,
- PDT_ERR_BAD1VALS,
- PDT_ERR_BAD2VALS,
PDT_ERR_BAD3VALS,
- PDT_ERR_BADCOORDL,
PDT_ERR_BADFLETTER,
- PDT_ERR_BADMATHS,
- PDT_ERR_BADSLETTER,
PDT_ERR_CHARS_NUM,
PDT_ERR_DUPEDIT,
PDT_ERR_EXTEDIT,
PDT_ERR_FACE_SEL,
PDT_ERR_FILEDIT,
- PDT_ERR_NOCOMMAS,
PDT_ERR_NON_VALID,
PDT_ERR_NO_ACT_OBJ,
PDT_ERR_NO_SEL_GEOM,
@@ -58,6 +62,9 @@ from .pdt_msg_strings import (
PDT_ERR_SEL_1_VERT,
PDT_ERR_SPLITEDIT
)
+from .pdt_bix import add_line_to_bisection
+from .pdt_etof import extend_vertex
+from .pdt_xall import intersect_all
def pdt_help(self, context):
@@ -106,6 +113,7 @@ def pdt_help(self, context):
label(text="'- Segments: 4 (int) -- choosing an even amount of segments gives better geometry")
label(text="'- Profile: 0.5 (float[0.0;1.0]) -- 0.5 (default) yields a circular, convex shape")
+
class PDT_OT_CommandReRun(Operator):
"""Repeat Current Displayed Command."""
@@ -144,7 +152,7 @@ def command_run(self, context):
Example; SP35 - Splits active Edge at 35% of separation between edge's vertices
- Valid First Letters (as 'oper' - pg.command[0])
+ Valid First Letters (as 'operation' - pg.command[0])
C = Cursor, G = Grab(move), N = New Vertex, V = Extrude Vertices Only,
E = Extrude geometry, P = Move Pivot Point, D = Duplicate geometry, S = Split Edges
@@ -175,78 +183,98 @@ def command_run(self, context):
scene = context.scene
pg = scene.pdt_pg
- cmd = pg.command.strip()
+ command = pg.command.strip()
- if cmd == "?" or cmd.lower() == "help":
+ # Check First Letter.
+ if command == "?" or command.lower() == "help":
# fmt: off
context.window_manager.popup_menu(pdt_help, title="PDT Command Line Help", icon="INFO")
# fmt: on
return
- elif cmd == "":
+ elif command == "":
+ return
+ elif command.upper() == "J2V":
+ join_two_vertices(self, context)
+ return
+ elif command.upper() == "AD2":
+ set_angle_distance_two(self, context)
+ return
+ elif command.upper() == "AD3":
+ set_angle_distance_three(self, context)
+ return
+ elif command.upper() == "OTC":
+ origin_to_cursor(self, context)
+ return
+ elif command.upper() == "TAP":
+ taper(self, context)
return
- elif len(cmd) < 3:
+ elif command.upper() == "BIS":
+ add_line_to_bisection(self, context)
+ return
+ elif command.upper() == "ETF":
+ extend_vertex(self, context)
+ return
+ elif command.upper() == "INTALL":
+ intersect_all(self, context)
+ return
+ elif command.upper()[1:4] == "NML":
+ placement_normal(self, context, command.upper()[0])
+ return
+ elif command.upper()[1:4] == "CEN":
+ placement_centre(self, context, command.upper()[0])
+ return
+ elif command.upper()[1:4] == "INT":
+ placement_intersect(self, context, command.upper()[0])
+ return
+ elif len(command) < 3:
pg.error = PDT_ERR_CHARS_NUM
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- oper = cmd[0].upper()
- if oper not in {"C", "D", "E", "F", "G", "N", "M", "P", "V", "S"}:
+ operation = command[0].upper()
+ if operation not in {"C", "D", "E", "F", "G", "N", "M", "P", "V", "S"}:
pg.error = PDT_ERR_BADFLETTER
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- mode = cmd[1].lower()
- if mode not in {"a", "d", "e", "g", "i", "o", "p", "v", "x", "y", "z"}:
- pg.error = PDT_ERR_BADSLETTER
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ mode = command[1].lower()
- # --------------
- # Math Operation
- if oper == "M":
- if mode not in {"x", "y", "z", "d", "a", "p", "o"}:
- pg.error = f"{mode} {PDT_ERR_NON_VALID} Maths)"
+ # Check Second Letter.
+ if operation == "F":
+ if mode not in {"v", "e", "i"}:
+ pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{operation}'"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- exp = cmd[2:]
- namespace = {}
- namespace.update(vars(math))
- try:
- num = eval(exp, namespace, namespace)
- except ValueError:
- pg.error = PDT_ERR_BADMATHS
+ elif operation in {"D", "E"}:
+ if mode not in {"d", "i"}:
+ pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{operation}'"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- if mode == "x":
- pg.cartesian_coords.x = num
- elif mode == "y":
- pg.cartesian_coords.y = num
- elif mode == "z":
- pg.cartesian_coords.z = num
- elif mode == "d":
- pg.distance = num
- elif mode == "a":
- pg.angle = num
- elif mode == "p":
- pg.percent = num
- elif mode == "o":
- pg.maths_output = num
- return
- # "o"/"x"/"y"/"z" modes are only legal for Math Operation
- else:
- if mode in {"o", "x", "y", "z"}:
- pg.error = PDT_ERR_BADCOORDL
+ elif operation == "M":
+ if mode not in {"a", "d", "i", "p", "o", "x", "y", "z"}:
+ pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{operation}'"
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
+ else:
+ if mode not in {"a", "d", "i", "p"}:
+ pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{operation}'"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
+
+ # --------------
+ # Maths Operation
+ if operation == "M":
+ command_maths(self, context, pg, command[2:], mode)
+ return
# -----------------------------------------------------
- # Not a Math Operation, so let's parse the command line
- vals = cmd[2:].split(",")
+ # Not a Maths Operation, so let's parse the command line
+ values = command[2:].split(",")
ind = 0
- for r in vals:
+ for r in values:
try:
_ = float(r)
good = True
except ValueError:
- vals[ind] = "0"
+ values[ind] = "0"
ind = ind + 1
mode_s = pg.select
flip_a = pg.flip_angle
@@ -254,293 +282,136 @@ def command_run(self, context):
ext_a = pg.extend
plane = pg.plane
obj = context.view_layer.objects.active
- #FIXME: What does call this imply in terms of invariants?
- # There's a lot of places in the code where we rely on bm not being None...
- bm, good = objCheck(obj, scene, oper)
- obj_loc = None
+ bm, good = obj_check(obj, scene, operation)
if good:
obj_loc = obj.matrix_world.decompose()[0]
- debug(f"cmd: {cmd}")
- debug(f"obj: {obj}, bm: {bm}, obj_loc: {obj_loc}")
-
- # static set variable for use in recurring comparisons
- adip = {"a", "d", "i", "p"}
+ else:
+ obj_loc = None
- # ---------------------
- # Cursor or Pivot Point
- if oper in {"C", "P"}:
- if mode not in adip:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- if mode in {"d","i"}:
- if len(bm.select_history) == 0:
- if len(bm.verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- else:
- verts = bm.verts
- else:
- verts = bm.select_history
- # Absolute/Global Coordinates
- if mode == "a":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
+ if mode_s == 'SEL' and bm is not None and mode not in {"a"}:
+ if len(bm.select_history) == 0:
+ if len([v for v in bm.verts if v.select]) == 0:
+ pg.error = PDT_ERR_NO_SEL_GEOM
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- if oper == "C":
- scene.cursor.location = vector_delta
else:
- pg.pivot_loc = vector_delta
- # Delta/Relative Coordinates
- elif mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- if mode_s == "REL":
- if oper == "C":
- scene.cursor.location = scene.cursor.location + vector_delta
- else:
- pg.pivot_loc = pg.pivot_loc + vector_delta
- elif mode_s == "SEL":
- if obj.mode == "EDIT":
- if oper == "C":
- scene.cursor.location = (
- verts[-1].co + obj_loc + vector_delta
- )
- else:
- pg.pivot_loc = verts[-1].co + obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- if oper == "C":
- scene.cursor.location = obj_loc + vector_delta
- else:
- pg.pivot_loc = obj_loc + vector_delta
+ verts = [v for v in bm.verts if v.select]
+ else:
+ verts = bm.select_history
+ else:
+ verts = []
+
+ debug(f"command: {command}")
+ debug(f"obj: {obj}, bm: {bm}, obj_loc: {obj_loc}")
+
+ # ---------------------
+ # Cursor or Pivot Point
+ 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)
# Direction/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- if mode_s == "REL":
- if oper == "C":
- scene.cursor.location = scene.cursor.location + vector_delta
- else:
- pg.pivot_loc = pg.pivot_loc + vector_delta
- elif mode_s == "SEL":
- if obj.mode == "EDIT":
- if oper == "C":
- scene.cursor.location = (
- verts[-1].co + obj_loc + vector_delta
- )
- else:
- pg.pivot_loc = verts[-1].co + obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- if oper == "C":
- scene.cursor.location = obj_loc + vector_delta
- else:
- pg.pivot_loc = obj_loc + vector_delta
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
# Percent Options
elif mode == "p":
- if len(vals) != 1:
- pg.error = PDT_ERR_BAD1VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = getPercent(obj, flip_p, float(vals[0]), oper, scene)
- if vector_delta is None:
- return
- if obj.mode == "EDIT":
- if oper == "C":
- scene.cursor.location = obj_loc + vector_delta
- else:
- pg.pivot_loc = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- if oper == "C":
- scene.cursor.location = vector_delta
- else:
- pg.pivot_loc = vector_delta
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 1)
+
+ if vector_delta is not None:
+ move_cursor_pivot(self, context, pg, obj, verts, operation,
+ mode, vector_delta)
return
# ------------------------
# Move Vertices or Objects
- elif oper == "G":
- if mode not in adip:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- # Absolute/Global Coordinates
- if mode == "a":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
+ elif operation == "G":
+ if obj.mode == "EDIT":
+ if len(verts) == 0:
+ pg.error = PDT_ERR_NO_SEL_GEOM
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
+ # Absolute/Global Coordinates
+ if mode == "a":
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
if obj.mode == "EDIT":
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
for v in verts:
v.co = vector_delta - obj_loc
bmesh.ops.remove_doubles(
bm, verts=[v for v in bm.verts if v.select], dist=0.0001
)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
elif obj.mode == "OBJECT":
for ob in context.view_layer.objects.selected:
ob.location = vector_delta
- # Delta/Relative Coordinates
- elif mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- if obj.mode == "EDIT":
- # FIXME: Show error popup if nothing is selected?
- bmesh.ops.translate(
- bm, verts=[v for v in bm.verts if v.select], vec=vector_delta
- )
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- for ob in context.view_layer.objects.selected:
- ob.location = obj_loc + vector_delta
- # Direction/Polar Coordinates
- elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- if obj.mode == "EDIT":
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- bmesh.ops.translate(bm, verts=verts, vec=vector_delta)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- for ob in context.view_layer.objects.selected:
- ob.location = ob.location + vector_delta
+
+ elif mode in {"d", "i"}:
+ if mode == "d":
+ # Delta/Relative Coordinates
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
+ else:
+ # Direction/Polar Coordinates
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
+ if vector_delta is not None:
+ if obj.mode == "EDIT":
+ bmesh.ops.translate(
+ bm, verts=[v for v in bm.verts if v.select], vec=vector_delta
+ )
+ elif obj.mode == "OBJECT":
+ for ob in context.view_layer.objects.selected:
+ ob.location = obj_loc + vector_delta
# Percent Options
elif mode == "p":
- if obj.mode == "OBJECT":
- if len(vals) != 1:
- pg.error = PDT_ERR_BAD1VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = getPercent(obj, flip_p, float(vals[0]), oper, scene)
- if vector_delta is None:
- return
- ob.location = vector_delta
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 1)
+ if vector_delta is not None:
+ if obj.mode == 'EDIT':
+ verts[-1].co = vector_delta
+ elif obj.mode == "OBJECT":
+ obj.location = vector_delta
+ if obj.mode == 'EDIT':
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# --------------
# Add New Vertex
- elif oper == "N":
- if mode not in adip:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "N":
if not obj.mode == "EDIT":
pg.error = PDT_ERR_ADDVEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- if mode in {"d","i"}:
- if len(bm.select_history) == 0:
- if len(bm.verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- else:
- verts = bm.verts
- else:
- verts = bm.select_history
# Absolute/Global Coordinates
if mode == "a":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- vNew = vector_delta - obj_loc
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
+ new_vertex = bm.verts.new(vector_delta - obj_loc)
# Delta/Relative Coordinates
elif mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- vNew = verts[-1].co + vector_delta
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
+ new_vertex = bm.verts.new(verts[-1].co + vector_delta)
# Direction/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- vNew = verts[-1].co + vector_delta
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
+ new_vertex = bm.verts.new(verts[-1].co + vector_delta)
# Percent Options
elif mode == "p":
- if len(vals) != 1:
- pg.error = PDT_ERR_BAD1VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = getPercent(obj, flip_p, float(vals[0]), oper, scene)
- vNew = vector_delta
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 1)
+ new_vertex = bm.verts.new(vector_delta)
+
+ for v in [v for v in bm.verts if v.select]:
+ v.select_set(False)
+ new_vertex.select_set(True)
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# -----------
# Split Edges
- elif oper == "S":
- if mode not in adip:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "S":
if not obj.mode == "EDIT":
pg.error = PDT_ERR_SPLITEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
# Absolute/Global Coordinates
if mode == "a":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
edges = [e for e in bm.edges if e.select]
if len(edges) != 1:
pg.error = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})"
@@ -548,20 +419,11 @@ def command_run(self, context):
return
geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- nVert = new_verts[0]
- nVert.co = vector_delta - obj_loc
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ new_vertex = new_verts[0]
+ new_vertex.co = vector_delta - obj_loc
# Delta/Relative Coordinates
elif mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
edges = [e for e in bm.edges if e.select]
faces = [f for f in bm.faces if f.select]
if len(faces) != 0:
@@ -574,24 +436,10 @@ def command_run(self, context):
return
geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- for v in new_verts:
- v.select_set(False)
bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- for v in new_verts:
- v.select_set(False)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
# Directional/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
edges = [e for e in bm.edges if e.select]
faces = [f for f in bm.faces if f.select]
if len(faces) != 0:
@@ -605,19 +453,9 @@ def command_run(self, context):
geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- for v in new_verts:
- v.select_set(False)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
# Percent Options
elif mode == "p":
- if len(vals) != 1:
- pg.error = PDT_ERR_BAD1VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = getPercent(obj, flip_p, float(vals[0]), oper, scene)
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 1)
if vector_delta is None:
return
edges = [e for e in bm.edges if e.select]
@@ -632,257 +470,145 @@ def command_run(self, context):
return
geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- nVert = new_verts[0]
- nVert.co = vector_delta
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ new_vertex = new_verts[0]
+ new_vertex.co = vector_delta
+
+ for v in [v for v in bm.verts if v.select]:
+ v.select_set(False)
+ for v in new_verts:
+ v.select_set(False)
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# ----------------
# Extrude Vertices
- elif oper == "V":
- if mode not in adip:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "V":
if not obj.mode == "EDIT":
pg.error = PDT_ERR_EXTEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
# Absolute/Global Coordinates
if mode == "a":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- vNew = vector_delta - obj_loc
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
+ new_vertex = bm.verts.new(vector_delta - obj_loc)
+ for v in verts:
+ bm.edges.new([v, new_vertex])
v.select_set(False)
- nVert.select_set(True)
+ new_vertex.select_set(True)
bmesh.ops.remove_doubles(
bm, verts=[v for v in bm.verts if v.select], dist=0.0001
)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
# Delta/Relative Coordinates
elif mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
for v in verts:
- nVert = bm.verts.new(v.co)
- nVert.co = nVert.co + vector_delta
- bm.edges.new([v, nVert])
+ new_vertex = bm.verts.new(v.co)
+ new_vertex.co = new_vertex.co + vector_delta
+ bm.edges.new([v, new_vertex])
v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ new_vertex.select_set(True)
# Direction/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
for v in verts:
- nVert = bm.verts.new(v.co)
- nVert.co = nVert.co + vector_delta
- bm.edges.new([v, nVert])
+ new_vertex = bm.verts.new(v.co)
+ new_vertex.co = new_vertex.co + vector_delta
+ bm.edges.new([v, new_vertex])
v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ new_vertex.select_set(True)
# Percent Options
elif mode == "p":
- vector_delta = getPercent(obj, flip_p, float(vals[0]), oper, scene)
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 1)
verts = [v for v in bm.verts if v.select].copy()
if len(verts) == 0:
pg.error = PDT_ERR_NO_SEL_GEOM
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- nVert = bm.verts.new(vector_delta)
+ new_vertex = bm.verts.new(vector_delta)
if ext_a:
for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
+ bm.edges.new([v, new_vertex])
v.select_set(False)
else:
- bm.edges.new([verts[-1], nVert])
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ bm.edges.new([verts[-1], new_vertex])
+ new_vertex.select_set(True)
+
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# ----------------
# Extrude Geometry
- elif oper == "E":
- if mode not in {"d", "i"}:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "E":
if not obj.mode == "EDIT":
pg.error = PDT_ERR_EXTEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
# Delta/Relative Coordinates
if mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- ret = bmesh.ops.extrude_face_region(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_extr = ret["geom"]
- verts_extr = [v for v in geom_extr if isinstance(v, bmesh.types.BMVert)]
- edges_extr = [e for e in geom_extr if isinstance(e, bmesh.types.BMEdge)]
- faces_extr = [f for f in geom_extr if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_extr, vec=vector_delta)
- updateSel(bm, verts_extr, edges_extr, faces_extr)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
# Direction/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- ret = bmesh.ops.extrude_face_region(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_extr = ret["geom"]
- verts_extr = [v for v in geom_extr if isinstance(v, bmesh.types.BMVert)]
- edges_extr = [e for e in geom_extr if isinstance(e, bmesh.types.BMEdge)]
- faces_extr = [f for f in geom_extr if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_extr, vec=vector_delta)
- updateSel(bm, verts_extr, edges_extr, faces_extr)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
+
+ ret = bmesh.ops.extrude_face_region(
+ bm,
+ geom=(
+ [f for f in bm.faces if f.select]
+ + [e for e in bm.edges if e.select]
+ + [v for v in bm.verts if v.select]
+ ),
+ use_select_history=True,
+ )
+ geom_extr = ret["geom"]
+ verts_extr = [v for v in geom_extr if isinstance(v, bmesh.types.BMVert)]
+ edges_extr = [e for e in geom_extr if isinstance(e, bmesh.types.BMEdge)]
+ faces_extr = [f for f in geom_extr if isinstance(f, bmesh.types.BMFace)]
+ del ret
+ bmesh.ops.translate(bm, verts=verts_extr, vec=vector_delta)
+ update_sel(bm, verts_extr, edges_extr, faces_extr)
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# ------------------
# Duplicate Geometry
- elif oper == "D":
- if mode not in {"d", "i"}:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "D":
if not obj.mode == "EDIT":
pg.error = PDT_ERR_DUPEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
# Delta/Relative Coordinates
if mode == "d":
- if len(vals) != 3:
- pg.error = PDT_ERR_BAD3VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = Vector((float(vals[0]), float(vals[1]), float(vals[2])))
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- ret = bmesh.ops.duplicate(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_dupe = ret["geom"]
- verts_dupe = [v for v in geom_dupe if isinstance(v, bmesh.types.BMVert)]
- edges_dupe = [e for e in geom_dupe if isinstance(e, bmesh.types.BMEdge)]
- faces_dupe = [f for f in geom_dupe if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_dupe, vec=vector_delta)
- updateSel(bm, verts_dupe, edges_dupe, faces_dupe)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 3)
# Direction/Polar Coordinates
elif mode == "i":
- if len(vals) != 2:
- pg.error = PDT_ERR_BAD2VALS
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- vector_delta = disAng(vals, flip_a, plane, scene)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- pg.error = PDT_ERR_NO_SEL_GEOM
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
- ret = bmesh.ops.duplicate(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_dupe = ret["geom"]
- verts_dupe = [v for v in geom_dupe if isinstance(v, bmesh.types.BMVert)]
- edges_dupe = [e for e in geom_dupe if isinstance(e, bmesh.types.BMEdge)]
- faces_dupe = [f for f in geom_dupe if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_dupe, vec=vector_delta)
- updateSel(bm, verts_dupe, edges_dupe, faces_dupe)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ vector_delta = vector_build(self, context, pg, obj, operation, values, 2)
+
+ ret = bmesh.ops.duplicate(
+ bm,
+ geom=(
+ [f for f in bm.faces if f.select]
+ + [e for e in bm.edges if e.select]
+ + [v for v in bm.verts if v.select]
+ ),
+ use_select_history=True,
+ )
+ geom_dupe = ret["geom"]
+ verts_dupe = [v for v in geom_dupe if isinstance(v, bmesh.types.BMVert)]
+ edges_dupe = [e for e in geom_dupe if isinstance(e, bmesh.types.BMEdge)]
+ faces_dupe = [f for f in geom_dupe if isinstance(f, bmesh.types.BMFace)]
+ del ret
+ bmesh.ops.translate(bm, verts=verts_dupe, vec=vector_delta)
+ update_sel(bm, verts_dupe, edges_dupe, faces_dupe)
+ bmesh.update_edit_mesh(obj.data)
+ bm.select_history.clear()
return
# ---------------
# Fillet Geometry
- elif oper == "F":
- if mode not in {"v", "e", "i"}:
- pg.error = f"'{mode}' {PDT_ERR_NON_VALID} '{oper}'"
- context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
- return
+ elif operation == "F":
if obj is None:
pg.error = PDT_ERR_NO_ACT_OBJ
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
@@ -891,7 +617,7 @@ def command_run(self, context):
pg.error = PDT_ERR_FILEDIT
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
- if len(vals) != 3:
+ if len(values) != 3:
pg.error = PDT_ERR_BAD3VALS
context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
return
@@ -906,11 +632,11 @@ def command_run(self, context):
return
# 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(vals[0])
- _segments = int(vals[1])
+ _offset = float(values[0])
+ _segments = int(values[1])
if _segments < 1:
_segments = 1 # This is a single, flat segment (ignores profile)
- _profile = float(vals[2])
+ _profile = float(values[2])
if _profile < 0.0 or _profile > 1.0:
_profile = 0.5 # This is a circular profile
if mode == "i":
diff --git a/precision_drawing_tools/pdt_design.py b/precision_drawing_tools/pdt_design.py
index f0943ce6..51f60a93 100644
--- a/precision_drawing_tools/pdt_design.py
+++ b/precision_drawing_tools/pdt_design.py
@@ -29,50 +29,32 @@ from mathutils import Vector
from mathutils.geometry import intersect_point_line
from math import sin, cos, tan, pi, sqrt
from .pdt_functions import (
- setMode,
- checkSelection,
- setAxis,
- updateSel,
- viewCoords,
- viewCoordsI,
- viewDir,
- arcCentre,
+ check_selection,
+ set_axis,
+ view_coords,
+ view_coords_i,
intersection,
- getPercent,
)
from .pdt_msg_strings import (
- PDT_ERR_CONNECTED,
- PDT_ERR_EDIT_MODE,
PDT_ERR_EDOB_MODE,
- PDT_ERR_FACE_SEL,
PDT_ERR_INT_LINES,
PDT_ERR_INT_NO_ALL,
PDT_ERR_NON_VALID,
PDT_ERR_NO_ACT_OBJ,
- PDT_ERR_NO_ACT_VERTS,
- PDT_ERR_SEL_1_EDGE,
- PDT_ERR_SEL_1_VERT,
- PDT_ERR_SEL_1_VERTI,
PDT_ERR_SEL_2_OBJS,
PDT_ERR_SEL_2_VERTIO,
- PDT_ERR_SEL_2_VERTS,
- PDT_ERR_SEL_2_EDGES,
PDT_ERR_SEL_3_OBJS,
PDT_ERR_SEL_3_VERTIO,
- PDT_ERR_SEL_3_VERTS,
PDT_ERR_SEL_4_OBJS,
PDT_ERR_SEL_4_VERTS,
- PDT_ERR_STRIGHT_LINE,
PDT_ERR_TAPER_ANG,
PDT_ERR_TAPER_SEL,
PDT_ERR_VERT_MODE,
PDT_INF_OBJ_MOVED,
PDT_LAB_ABS,
- PDT_LAB_ARCCENTRE,
PDT_LAB_DEL,
PDT_LAB_DIR,
PDT_LAB_INTERSECT,
- PDT_LAB_NOR,
PDT_LAB_PERCENT,
PDT_LAB_PLANE
)
@@ -88,7 +70,7 @@ class PDT_OT_PlacementAbs(Operator):
def execute(self, context):
"""Manipulates Geometry, or Objects by Absolute (World) Coordinates.
- - Reads pg.operate from Operation Mode Selector as 'data'
+ - Reads pg.operate from Operation Mode Selector as 'operation'
- Reads pg.cartesian_coords scene variables to:
-- set position of CUrsor (CU)
-- set postion of Pivot Point (PP)
@@ -99,8 +81,6 @@ class PDT_OT_PlacementAbs(Operator):
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' is used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -108,84 +88,35 @@ class PDT_OT_PlacementAbs(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- oper = pg.operation
-
- vector_delta = pg.cartesian_coords
- if oper not in {"CU", "PP", "NV"}:
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- obj_loc = obj.matrix_world.decompose()[0]
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- errmsg = PDT_ERR_NO_ACT_VERTS
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper == "CU":
- scene.cursor.location = vector_delta
- scene.cursor.rotation_euler = (0, 0, 0)
- elif oper == "PP":
- pg.pivot_loc = vector_delta
- elif oper == "MV":
- if obj.mode == "EDIT":
- for v in verts:
- v.co = vector_delta - obj_loc
- bm.select_history.clear()
- bmesh.ops.remove_doubles(bm, verts=[v for v in bm.verts if v.select], dist=0.0001)
- bmesh.update_edit_mesh(obj.data)
- elif obj.mode == "OBJECT":
- for ob in context.view_layer.objects.selected:
- ob.location = vector_delta
- elif oper == "SE" and obj.mode == "EDIT":
- edges = [e for e in bm.edges if e.select]
- if len(edges) != 1:
- errmsg = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
- new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- nVert = new_verts[0]
- nVert.co = vector_delta - obj_loc
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "NV":
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- vNew = vector_delta - obj.location
- nVert = bm.verts.new(vNew)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- nVert.select_set(True)
- else:
- errmsg = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif oper == "EV" and obj.mode == "EDIT":
- vNew = vector_delta - obj_loc
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
- v.select_set(False)
- nVert.select_set(True)
- bm.select_history.clear()
- bmesh.ops.remove_doubles(bm, verts=[v for v in bm.verts if v.select], dist=0.0001)
- bmesh.update_edit_mesh(obj.data)
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+
+ if operation == "CU":
+ # Cursor
+ pg.command = (f"ca{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "PP":
+ # Pivot Point
+ pg.command = (f"pa{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "MV":
+ # Move Entities
+ pg.command = (f"ga{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "SE":
+ # Split Edges
+ pg.command = (f"sa{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "NV":
+ # New Vertex
+ pg.command = (f"na{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "EV":
+ # Extrude Vertices
+ pg.command = (f"va{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_ABS}"
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_ABS}"
self.report({"ERROR"}, errmsg)
return {"FINISHED"}
@@ -200,7 +131,7 @@ class PDT_OT_PlacementDelta(Operator):
def execute(self, context):
"""Manipulates Geometry, or Objects by Delta Offset (Increment).
- - Reads pg.operation from Operation Mode Selector as 'oper'
+ - Reads pg.operation from Operation Mode Selector as 'operation'
- Reads pg.select, pg.plane, pg.cartesian_coords scene variables to:
-- set position of CUrsor (CU)
-- set position of Pivot Point (PP)
@@ -213,8 +144,6 @@ class PDT_OT_PlacementDelta(Operator):
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -222,147 +151,44 @@ class PDT_OT_PlacementDelta(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- x_loc = pg.cartesian_coords.x
- y_loc = pg.cartesian_coords.y
- z_loc = pg.cartesian_coords.z
- mode_s = pg.select
- oper = pg.operation
-
- if pg.plane == "LO":
- vector_delta = viewCoords(x_loc, y_loc, z_loc)
- else:
- vector_delta = Vector((x_loc, y_loc, z_loc))
- if mode_s == "REL" and oper == "CU":
- scene.cursor.location = scene.cursor.location + vector_delta
- elif mode_s == "REL" and oper == "PP":
- pg.pivot_loc = pg.pivot_loc + vector_delta
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+
+ if operation == "CU":
+ # Cursor
+ pg.command = (f"cd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "PP":
+ # Pivot Point
+ pg.command = (f"pd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "MV":
+ # Move Entities
+ pg.command = (f"gd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "SE":
+ # Split Edges
+ pg.command = (f"sd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "NV":
+ # New Vertex
+ pg.command = (f"nd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "EV":
+ # Extrue Vertices
+ pg.command = (f"vd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "DG":
+ # Duplicate Entities
+ pg.command = (f"dd{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
+ elif operation == "EG":
+ # Extrue Geometry
+ pg.command = (f"ed{pg.cartesian_coords.x},{pg.cartesian_coords.y},"\
+ f"{pg.cartesian_coords.z}")
else:
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- obj_loc = obj.matrix_world.decompose()[0]
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- if oper not in {"MV", "SE", "EV", "DG", "EG"}:
- if len(bm.select_history) >= 1:
- actV = checkSelection(1, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_1_VERTI} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper not in {"CU", "PP", "NV"} and obj.mode == "EDIT":
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- errmsg = PDT_ERR_NO_ACT_VERTS
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper == "CU":
- if obj.mode == "EDIT":
- scene.cursor.location = obj_loc + actV + vector_delta
- elif obj.mode == "OBJECT":
- scene.cursor.location = obj_loc + vector_delta
- elif oper == "PP":
- if obj.mode == "EDIT":
- pg.pivot_loc = obj_loc + actV + vector_delta
- elif obj.mode == "OBJECT":
- pg.pivot_loc = obj_loc + vector_delta
- elif oper == "MV":
- if obj.mode == "EDIT":
- bmesh.ops.translate(bm, verts=verts, vec=vector_delta)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- for ob in context.view_layer.objects.selected:
- ob.location = ob.location + vector_delta
- elif oper == "SE" and obj.mode == "EDIT":
- edges = [e for e in bm.edges if e.select]
- faces = [f for f in bm.faces if f.select]
- if len(faces) != 0:
- errmsg = PDT_ERR_FACE_SEL
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if len(edges) < 1:
- errmsg = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
- new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "NV":
- if obj.mode == "EDIT":
- vNew = actV + vector_delta
- nVert = bm.verts.new(vNew)
- 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:
- errmsg = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif oper == "EV" and obj.mode == "EDIT":
- for v in [v for v in bm.verts if v.select]:
- nVert = bm.verts.new(v.co)
- nVert.co = nVert.co + vector_delta
- bm.edges.new([v, nVert])
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "DG" and obj.mode == "EDIT":
- ret = bmesh.ops.duplicate(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_dupe = ret["geom"]
- verts_dupe = [v for v in geom_dupe if isinstance(v, bmesh.types.BMVert)]
- edges_dupe = [e for e in geom_dupe if isinstance(e, bmesh.types.BMEdge)]
- faces_dupe = [f for f in geom_dupe if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_dupe, vec=vector_delta)
- updateSel(bm, verts_dupe, edges_dupe, faces_dupe)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "EG" and obj.mode == "EDIT":
- ret = bmesh.ops.extrude_face_region(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_extr = ret["geom"]
- verts_extr = [v for v in geom_extr if isinstance(v, bmesh.types.BMVert)]
- edges_extr = [e for e in geom_extr if isinstance(e, bmesh.types.BMEdge)]
- faces_extr = [f for f in geom_extr if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_extr, vec=vector_delta)
- updateSel(bm, verts_extr, edges_extr, faces_extr)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_DEL}"
- self.report({"ERROR"}, errmsg)
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_DEL}"
+ self.report({"ERROR"}, errmsg)
return {"FINISHED"}
@@ -376,7 +202,7 @@ class PDT_OT_PlacementDis(Operator):
def execute(self, context):
"""Manipulates Geometry, or Objects by Distance at Angle (Direction).
- - Reads pg.operation from Operation Mode Selector as 'oper'
+ - Reads pg.operation from Operation Mode Selector as 'operation'
- Reads pg.select, pg.distance, pg.angle, pg.plane & pg.flip_angle scene variables to:
-- set position of CUrsor (CU)
-- set position of Pivot Point (PP)
@@ -389,8 +215,6 @@ class PDT_OT_PlacementDis(Operator):
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -398,156 +222,35 @@ class PDT_OT_PlacementDis(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- dis_v = pg.distance
- ang_v = pg.angle
- plane = pg.plane
- mode_s = pg.select
- oper = pg.operation
- flip_a = pg.flip_angle
- if flip_a:
- if ang_v > 0:
- ang_v = ang_v - 180
- else:
- ang_v = ang_v + 180
- pg.angle = ang_v
- if plane == "LO":
- vector_delta = viewDir(dis_v, ang_v)
- else:
- a1, a2, _ = setMode(plane)
- vector_delta = Vector((0, 0, 0))
- vector_delta[a1] = vector_delta[a1] + (dis_v * cos(ang_v * pi / 180))
- vector_delta[a2] = vector_delta[a2] + (dis_v * sin(ang_v * pi / 180))
- if mode_s == "REL" and oper == "CU":
- scene.cursor.location = scene.cursor.location + vector_delta
- elif mode_s == "REL" and oper == "PP":
- pg.pivot_loc = pg.pivot_loc + vector_delta
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+ if operation == "CU":
+ # Cursor
+ pg.command = f"ci{pg.distance},{pg.angle}"
+ elif operation == "PP":
+ # Pivot Point
+ pg.command = f"pi{pg.distance},{pg.angle}"
+ elif operation == "MV":
+ # Move Entities
+ pg.command = f"gi{pg.distance},{pg.angle}"
+ elif operation == "SE":
+ # Split Edges
+ pg.command = f"si{pg.distance},{pg.angle}"
+ elif operation == "NV":
+ # New Vertex
+ pg.command = f"ni{pg.distance},{pg.angle}"
+ elif operation == "EV":
+ # Extrude Vertices
+ pg.command = f"vi{pg.distance},{pg.angle}"
+ elif operation == "DG":
+ # Duplicate Geometry
+ pg.command = f"di{pg.distance},{pg.angle}"
+ elif operation == "EG":
+ # Extrude Geometry
+ pg.command = f"ei{pg.distance},{pg.angle}"
else:
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- obj_loc = obj.matrix_world.decompose()[0]
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- if oper not in {"MV", "SE", "EV", "DG", "EG"}:
- if len(bm.select_history) >= 1:
- actV = checkSelection(1, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_1_VERTI} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper not in {"CU", "PP", "NV"} and obj.mode == "EDIT":
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 0:
- errmsg = PDT_ERR_NO_ACT_VERTS
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper == "CU":
- if obj.mode == "EDIT":
- scene.cursor.location = obj_loc + actV + vector_delta
- elif obj.mode == "OBJECT":
- scene.cursor.location = obj_loc + vector_delta
- elif oper == "PP":
- if obj.mode == "EDIT":
- pg.pivot_loc = obj_loc + actV + vector_delta
- elif obj.mode == "OBJECT":
- pg.pivot_loc = obj_loc + vector_delta
- elif oper == "MV":
- if obj.mode == "EDIT":
- bmesh.ops.translate(bm, verts=verts, vec=vector_delta)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- for ob in context.view_layer.objects.selected:
- ob.location = ob.location + vector_delta
- elif oper == "SE" and obj.mode == "EDIT":
- edges = [e for e in bm.edges if e.select]
- faces = [f for f in bm.faces if f.select]
- if len(faces) != 0:
- errmsg = PDT_ERR_FACE_SEL
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if len(edges) < 1:
- errmsg = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
- new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- bmesh.ops.translate(bm, verts=new_verts, vec=vector_delta)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "NV":
- if obj.mode == "EDIT":
- vNew = actV + vector_delta
- nVert = bm.verts.new(vNew)
- 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:
- errmsg = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif oper == "EV" and obj.mode == "EDIT":
- for v in [v for v in bm.verts if v.select]:
- nVert = bm.verts.new(v.co)
- nVert.co = nVert.co + vector_delta
- bm.edges.new([v, nVert])
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "DG" and obj.mode == "EDIT":
- ret = bmesh.ops.duplicate(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_dupe = ret["geom"]
- verts_dupe = [v for v in geom_dupe if isinstance(v, bmesh.types.BMVert)]
- edges_dupe = [e for e in geom_dupe if isinstance(e, bmesh.types.BMEdge)]
- faces_dupe = [f for f in geom_dupe if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_dupe, vec=vector_delta)
- updateSel(bm, verts_dupe, edges_dupe, faces_dupe)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "EG" and obj.mode == "EDIT":
- ret = bmesh.ops.extrude_face_region(
- bm,
- geom=(
- [f for f in bm.faces if f.select]
- + [e for e in bm.edges if e.select]
- + [v for v in bm.verts if v.select]
- ),
- use_select_history=True,
- )
- geom_extr = ret["geom"]
- verts_extr = [v for v in geom_extr if isinstance(v, bmesh.types.BMVert)]
- edges_extr = [e for e in geom_extr if isinstance(e, bmesh.types.BMEdge)]
- faces_extr = [f for f in geom_extr if isinstance(f, bmesh.types.BMFace)]
- del ret
- bmesh.ops.translate(bm, verts=verts_extr, vec=vector_delta)
- updateSel(bm, verts_extr, edges_extr, faces_extr)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_DIR}"
- self.report({"ERROR"}, errmsg)
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_DIR}"
+ self.report({"ERROR"}, errmsg)
return {"FINISHED"}
@@ -562,19 +265,17 @@ class PDT_OT_PlacementPer(Operator):
def execute(self, context):
"""Manipulates Geometry, or Objects by Percentage between 2 points.
- - Reads pg.operation from Operation Mode Selector as 'oper'
+ - Reads pg.operation from Operation Mode Selector as 'operation'
- Reads pg.percent, pg.extend & pg.flip_percent scene variables to:
-- 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)
+ -- Split Edges (SE)
+ -- add a New Vertex (NV)
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -582,81 +283,29 @@ class PDT_OT_PlacementPer(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- per_v = pg.percent
- oper = pg.operation
- ext_a = pg.extend
- flip_p = pg.flip_percent
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- obj_loc = obj.matrix_world.decompose()[0]
- vector_delta = getPercent(obj, flip_p, per_v, oper, scene)
- if vector_delta is None:
- return {"FINISHED"}
-
- if oper == "CU":
- if obj.mode == "EDIT":
- scene.cursor.location = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- scene.cursor.location = vector_delta
- elif oper == "PP":
- if obj.mode == "EDIT":
- pg.pivot_loc = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- pg.pivot_loc = vector_delta
- elif oper == "MV":
- if obj.mode == "EDIT":
- bm.select_history[-1].co = vector_delta
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- obj.location = vector_delta
- elif oper == "SE" and obj.mode == "EDIT":
- edges = [e for e in bm.edges if e.select]
- if len(edges) != 1:
- errmsg = f"{PDT_ERR_SEL_1_EDGE} {len(edges)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- geom = bmesh.ops.subdivide_edges(bm, edges=edges, cuts=1)
- new_verts = [v for v in geom["geom_split"] if isinstance(v, bmesh.types.BMVert)]
- nVert = new_verts[0]
- nVert.co = vector_delta
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper == "NV":
- 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:
- errmsg = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif oper == "EV" and obj.mode == "EDIT":
- nVert = bm.verts.new(vector_delta)
- if ext_a:
- for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
- v.select_set(False)
- else:
- bm.edges.new([bm.select_history[-1], nVert])
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+
+ if operation == "CU":
+ # Cursor
+ pg.command = f"cp{pg.percent}"
+ elif operation == "PP":
+ # Pivot Point
+ pg.command = f"pp{pg.percent}"
+ elif operation == "MV":
+ # Move Entities
+ pg.command = f"gp{pg.percent}"
+ elif operation == "SE":
+ # Split Edges
+ pg.command = f"sp{pg.percent}"
+ elif operation == "NV":
+ # New Vertex
+ pg.command = f"np{pg.percent}"
+ elif operation == "EV":
+ # Extrude Vertices
+ pg.command = f"vp{pg.percent}"
else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_PERCENT}"
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_PERCENT}"
self.report({"ERROR"}, errmsg)
return {"FINISHED"}
@@ -672,7 +321,7 @@ class PDT_OT_PlacementNormal(Operator):
def execute(self, context):
"""Manipulates Geometry, or Objects by Normal Intersection between 3 points.
- - Reads pg.operation from Operation Mode Selector as 'oper'
+ - Reads pg.operation from Operation Mode Selector as 'operation'
- Reads pg.extend scene variable to:
-- set position of CUrsor (CU)
-- set position of Pivot Point (PP)
@@ -683,8 +332,6 @@ class PDT_OT_PlacementNormal(Operator):
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -692,108 +339,37 @@ class PDT_OT_PlacementNormal(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- oper = pg.operation
- ext_a = pg.extend
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- 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 = checkSelection(3, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_3_VERTS} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif obj.mode == "OBJECT":
- objs = context.view_layer.objects.selected
- if len(objs) != 3:
- errmsg = f"{PDT_ERR_SEL_3_OBJS} {len(objs)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- 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 oper == "CU":
- if obj.mode == "EDIT":
- scene.cursor.location = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- scene.cursor.location = vector_delta
- elif oper == "PP":
- if obj.mode == "EDIT":
- pg.pivot_loc = obj_loc + vector_delta
- elif obj.mode == "OBJECT":
- pg.pivot_loc = vector_delta
- elif oper == "MV":
- 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 oper == "NV":
- 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:
- errmsg = f"{PDT_ERR_EDIT_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif oper == "EV" and obj.mode == "EDIT":
- vNew = vector_delta
- nVert = bm.verts.new(vNew)
- if ext_a:
- for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
- else:
- bm.edges.new([bm.select_history[-1], nVert])
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+ if operation == "CU":
+ pg.command = f"cnml"
+ elif operation == "PP":
+ pg.command = f"pnml"
+ elif operation == "MV":
+ pg.command = f"gnml"
+ elif operation == "EV":
+ pg.command = f"vnml"
+ elif operation == "SE":
+ pg.command = f"snml"
+ elif operation == "NV":
+ pg.command = f"nnml"
else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_NOR}"
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
self.report({"ERROR"}, errmsg)
return {"FINISHED"}
-class PDT_OT_PlacementInt(Operator):
- """Use Intersection, or Convergence Placement."""
+class PDT_OT_PlacementCen(Operator):
+ """Use Placement at Arc Centre."""
- bl_idname = "pdt.intersect"
- bl_label = "Intersect Mode"
+ bl_idname = "pdt.centre"
+ bl_label = "Centre Mode"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
- """Manipulates Geometry, or Objects by Convergance Intersection between 4 points, or 2 Edges.
+ """Manipulates Geometry, or Objects to an Arc Centre defined by 3 points on an Imaginary Arc.
- - Reads pg.operation from Operation Mode Selector as 'oper'
- - Reads pg.plane scene variable and operates in Working Plane to:
+ - Reads pg.operation from Operation Mode Selector as 'operation'
-- set position of CUrsor (CU)
-- set position of Pivot Point (PP)
-- MoVe geometry/objects (MV)
@@ -802,8 +378,6 @@ class PDT_OT_PlacementInt(Operator):
Invalid Options result in self.report Error.
- Local vector variable 'vector_delta' used to reposition features.
-
Args:
context: Blender bpy.context instance.
@@ -811,193 +385,43 @@ class PDT_OT_PlacementInt(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- oper = pg.operation
- plane = pg.plane
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+ if operation == "CU":
+ pg.command = f"ccen"
+ elif operation == "PP":
+ pg.command = f"pcen"
+ elif operation == "MV":
+ pg.command = f"gcen"
+ elif operation == "EV":
+ pg.command = f"vcen"
+ elif operation == "NV":
+ pg.command = f"ncen"
+ else:
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- obj_loc = obj.matrix_world.decompose()[0]
- bm = bmesh.from_edit_mesh(obj.data)
- edges = [e for e in bm.edges if e.select]
- if len(bm.select_history) == 4:
- ext_a = pg.extend
- v_active = bm.select_history[-1]
- v_other = bm.select_history[-2]
- v_last = bm.select_history[-3]
- v_first = bm.select_history[-4]
- actV, othV, lstV, fstV = checkSelection(4, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif len(edges) == 2:
- ext_a = pg.extend
- v_active = edges[0].verts[0]
- v_other = edges[0].verts[1]
- v_last = edges[1].verts[0]
- v_first = edges[1].verts[1]
- else:
- errmsg = (
- PDT_ERR_SEL_4_VERTS
- + str(len(bm.select_history))
- + " Vertices/"
- + str(len(edges))
- + " Edges)"
- )
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- vector_delta, done = intersection(v_active.co,
- v_other.co,
- v_last.co,
- v_first.co,
- plane
- )
- if not done:
- errmsg = f"{PDT_ERR_INT_LINES} {plane} {PDT_LAB_PLANE}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
-
- if oper == "CU":
- scene.cursor.location = obj_loc + vector_delta
- elif oper == "PP":
- pg.pivot_loc = obj_loc + vector_delta
- elif oper == "NV":
- vNew = vector_delta
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- for f in bm.faces:
- f.select_set(False)
- for e in bm.edges:
- e.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif oper in {"MV", "EV"}:
- nVert = None
- proc = False
-
- if (v_active.co - vector_delta).length < (v_other.co - vector_delta).length:
- if oper == "MV":
- v_active.co = vector_delta
- proc = True
- elif oper == "EV":
- nVert = bm.verts.new(vector_delta)
- bm.edges.new([va, nVert])
- proc = True
- else:
- if oper == "MV" and ext_a:
- v_other.co = vector_delta
- elif oper == "EV" and ext_a:
- nVert = bm.verts.new(vector_delta)
- bm.edges.new([vo, nVert])
-
- if (v_last.co - vector_delta).length < (v_first.co - vector_delta).length:
- if oper == "MV" and ext_a:
- v_last.co = vector_delta
- elif oper == "EV" and ext_a:
- bm.edges.new([vl, nVert])
- else:
- if oper == "MV" and ext_a:
- v_first.co = vector_delta
- elif oper == "EV" and ext_a:
- bm.edges.new([vf, nVert])
- bm.select_history.clear()
- bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
-
- if not proc and not ext_a:
- errmsg = PDT_ERR_INT_NO_ALL
- self.report({"ERROR"}, errmsg)
- bmesh.update_edit_mesh(obj.data)
- return {"FINISHED"}
- else:
- for v in bm.verts:
- v.select_set(False)
- for f in bm.faces:
- f.select_set(False)
- for e in bm.edges:
- e.select_set(False)
-
- if nVert is not None:
- nVert.select_set(True)
- for v in bm.select_history:
- if v is not None:
- v.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif obj.mode == "OBJECT":
- if len(context.view_layer.objects.selected) != 4:
- errmsg = f"{PDT_ERR_SEL_4_OBJS} {len(context.view_layer.objects.selected)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- order = pg.object_order.split(",")
- objs = sorted(
- [ob for ob in context.view_layer.objects.selected], key=lambda x: x.name
- )
- message = (
- "Original Object Order was: "
- + objs[0].name
- + ", "
- + objs[1].name
- + ", "
- + objs[2].name
- + ", "
- + objs[3].name
- )
- self.report({"INFO"}, message)
-
- actV = objs[int(order[0]) - 1].matrix_world.decompose()[0]
- othV = objs[int(order[1]) - 1].matrix_world.decompose()[0]
- lstV = objs[int(order[2]) - 1].matrix_world.decompose()[0]
- fstV = objs[int(order[3]) - 1].matrix_world.decompose()[0]
- vector_delta, done = intersection(actV, othV, lstV, fstV, plane)
- if not done:
- errmsg = f"{PDT_ERR_INT_LINES} {plane} {PDT_LAB_PLANE}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if oper == "CU":
- scene.cursor.location = vector_delta
- elif oper == "PP":
- pg.pivot_loc = vector_delta
- elif oper == "MV":
- context.view_layer.objects.active.location = vector_delta
- infmsg = PDT_INF_OBJ_MOVED + message
- self.report({"INFO"}, infmsg)
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
+ return {"FINISHED"}
-class PDT_OT_PlacementCen(Operator):
- """Use Placement at Arc Centre."""
+class PDT_OT_PlacementInt(Operator):
+ """Use Intersection, or Convergence Placement."""
- bl_idname = "pdt.centre"
- bl_label = "Centre Mode"
+ bl_idname = "pdt.intersect"
+ bl_label = "Intersect Mode"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
- """Manipulates Geometry, or Objects to an Arc Centre defined by 3 points on an Imaginary Arc.
+ """Manipulates Geometry, or Objects by Convergance Intersection between 4 points, or 2 Edges.
- Valid Options for pg.operation; CU PP MV NV EV
- - Reads pg.operation from Operation Mode Selector as 'oper'
- - Reads pg.extend scene variable to:
+ - Reads pg.operation from Operation Mode Selector as 'operation'
+ - Reads pg.plane scene variable and operates in Working Plane to:
-- set position of CUrsor (CU)
-- set position of Pivot Point (PP)
-- MoVe geometry/objects (MV)
-- Extrude Vertices (EV)
-- add a New vertex (NV)
- Invalid Options result in self.report Error.
+ Invalid Options result in "self.report" Error.
Local vector variable 'vector_delta' used to reposition features.
@@ -1008,104 +432,22 @@ class PDT_OT_PlacementCen(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- oper = pg.operation
- ext_a = pg.extend
- obj = context.view_layer.objects.active
-
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
+ pg = context.scene.pdt_pg
+ operation = pg.operation
+ if operation == "CU":
+ pg.command = f"cint"
+ elif operation == "PP":
+ pg.command = f"pint"
+ elif operation == "MV":
+ pg.command = f"gint"
+ elif operation == "EV":
+ pg.command = f"vint"
+ elif operation == "NV":
+ pg.command = f"nint"
+ else:
+ errmsg = f"{operation} {PDT_ERR_NON_VALID} {PDT_LAB_INTERSECT}"
self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- obj = context.view_layer.objects.active
- obj_loc = obj.matrix_world.decompose()[0]
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 3:
- actV = verts[0].co
- othV = verts[1].co
- lstV = verts[2].co
- else:
- errmsg = f"{PDT_ERR_SEL_3_VERTS} {len(verts)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- vector_delta, radius = arcCentre(actV, othV, lstV)
- if str(radius) == "inf":
- errmsg = PDT_ERR_STRIGHT_LINE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- pg.distance = radius
- if oper == "CU":
- scene.cursor.location = obj_loc + vector_delta
- elif oper == "PP":
- pg.pivot_loc = obj_loc + vector_delta
- elif oper == "NV":
- vNew = vector_delta
- nVert = bm.verts.new(vNew)
- for v in [v for v in bm.verts if v.select]:
- v.select_set(False)
- nVert.select_set(True)
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- nVert.select_set(True)
- elif oper == "MV":
- 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 oper == "EV":
- nVert = bm.verts.new(vector_delta)
- if ext_a:
- for v in [v for v in bm.verts if v.select]:
- bm.edges.new([v, nVert])
- v.select_set(False)
- nVert.select_set(True)
- bm.select_history.clear()
- bmesh.ops.remove_doubles(
- bm, verts=[v for v in bm.verts if v.select], dist=0.0001
- )
- bmesh.update_edit_mesh(obj.data)
- else:
- bm.edges.new([bm.select_history[-1], nVert])
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_ARCCENTRE}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif obj.mode == "OBJECT":
- if len(context.view_layer.objects.selected) != 3:
- errmsg = f"{PDT_ERR_SEL_3_OBJS} {len(context.view_layer.objects.selected)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- actV = context.view_layer.objects.selected[0].matrix_world.decompose()[0]
- othV = context.view_layer.objects.selected[1].matrix_world.decompose()[0]
- lstV = context.view_layer.objects.selected[2].matrix_world.decompose()[0]
- vector_delta, radius = arcCentre(actV, othV, lstV)
- pg.distance = radius
- if oper == "CU":
- scene.cursor.location = vector_delta
- elif oper == "PP":
- pg.pivot_loc = vector_delta
- elif oper == "MV":
- context.view_layer.objects.active.location = vector_delta
- else:
- errmsg = f"{oper} {PDT_ERR_NON_VALID} {PDT_LAB_ARCCENTRE}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
+ return {"FINISHED"}
class PDT_OT_JoinVerts(Operator):
@@ -1136,23 +478,9 @@ class PDT_OT_JoinVerts(Operator):
Status Set.
"""
- obj = context.view_layer.objects.active
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 2:
- try:
- bm.edges.new([verts[-1], verts[-2]])
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- return {"FINISHED"}
- except ValueError:
- errmsg = PDT_ERR_CONNECTED
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_2_VERTS} {len(verts)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
+ pg = context.scene.pdt_pg
+ pg.command = f"j2v"
+ return {"FINISHED"}
class PDT_OT_Fillet(Operator):
@@ -1186,70 +514,14 @@ class PDT_OT_Fillet(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- plane = pg.plane
- obj = context.view_layer.objects.active
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if pg.fillet_int:
- # Fillet & Intersect Two Edges
- edges = [e for e in bm.edges if e.select]
- if len(edges) == 2 and len(verts) == 4:
- v_active = edges[0].verts[0]
- v_other = edges[0].verts[1]
- v_last = edges[1].verts[0]
- v_first = edges[1].verts[1]
- vector_delta, done = intersection(v_active.co,
- v_other.co,
- v_last.co,
- v_first.co,
- plane
- )
- if not done:
- errmsg = f"{PDT_ERR_INT_LINES} {plane} {PDT_LAB_PLANE}"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if (v_active.co - vector_delta).length < (v_other.co - vector_delta).length:
- v_active.co = vector_delta
- vo.select_set(False)
- else:
- v_other.co = vector_delta
- v_active.select_set(False)
- if (v_last.co - vector_delta).length < (v_first.co - vector_delta).length:
- v_last.co = vector_delta
- v_first.select_set(False)
- else:
- v_first.co = vector_delta
- v_last.select_set(False)
- bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
- bpy.ops.mesh.bevel(
- offset_type="OFFSET",
- offset=pg.fillet_radius,
- segments=pg.fillet_segments,
- profile=pg.fillet_profile,
- vertex_only=True,
- )
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_2_EDGES} {len(edges)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
+ pg = context.scene.pdt_pg
+ if pg.fillet_intersect:
+ pg.command = f"fi{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
+ elif pg.fillet_vertices_only:
+ pg.command = f"fv{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
else:
- if len(verts) == 0:
- errmsg = PDT_ERR_SEL_1_VERT
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- # Intersct Edges
- bpy.ops.mesh.bevel(
- offset_type="OFFSET",
- offset=pg.fillet_radius,
- segments=pg.fillet_segments,
- profile=pg.fillet_profile,
- vertex_only=pg.fillet_vertices_only,
- )
- return {"FINISHED"}
+ pg.command = f"fe{pg.fillet_radius},{pg.fillet_segments},{pg.fillet_profile}"
+ return {"FINISHED"}
class PDT_OT_Angle2(Operator):
@@ -1273,65 +545,8 @@ class PDT_OT_Angle2(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- plane = pg.plane
- flip_a = pg.flip_angle
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 2:
- if len(bm.select_history) == 2:
- actV, othV = checkSelection(2, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_2_VERTIO} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_2_VERTIO} {len(verts)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif obj.mode == "OBJECT":
- objs = context.view_layer.objects.selected
- if len(objs) < 2:
- errmsg = f"{PDT_ERR_SEL_2_OBJS} {len(objs)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- 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]
- if plane == "LO":
- disV = othV - actV
- othV = viewCoordsI(disV.x, disV.y, disV.z)
- actV = Vector((0, 0, 0))
- v0 = np.array([actV.x + 1, actV.y]) - np.array([actV.x, actV.y])
- v1 = np.array([othV.x, othV.y]) - np.array([actV.x, actV.y])
- else:
- a1, a2, _ = setMode(plane)
- v0 = np.array([actV[a1] + 1, actV[a2]]) - np.array([actV[a1], actV[a2]])
- v1 = np.array([othV[a1], othV[a2]]) - np.array([actV[a1], actV[a2]])
- ang = np.rad2deg(np.arctan2(np.linalg.det([v0, v1]), np.dot(v0, v1)))
- if flip_a:
- if ang > 0:
- pg.angle = ang - 180
- else:
- pg.angle = ang + 180
- else:
- pg.angle = ang
- if plane == "LO":
- pg.distance = sqrt((actV.x - othV.x) ** 2 + (actV.y - othV.y) ** 2)
- else:
- pg.distance = sqrt((actV[a1] - othV[a1]) ** 2 + (actV[a2] - othV[a2]) ** 2)
- pg.cartesian_coords = othV - actV
+ pg = context.scene.pdt_pg
+ pg.command = f"ad2"
return {"FINISHED"}
@@ -1357,53 +572,7 @@ class PDT_OT_Angle3(Operator):
"""
pg = context.scene.pdt_pg
- flip_a = pg.flip_angle
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- verts = [v for v in bm.verts if v.select]
- if len(verts) == 3:
- if len(bm.select_history) == 3:
- actV, othV, lstV = checkSelection(3, bm, obj)
- if actV is None:
- errmsg = PDT_ERR_VERT_MODE
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_3_VERTIO} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- else:
- errmsg = f"{PDT_ERR_SEL_3_VERTIO} {len(verts)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- elif obj.mode == "OBJECT":
- objs = context.view_layer.objects.selected
- if len(objs) < 3:
- errmsg = PDT_ERR_SEL_3_OBJS + str(len(objs))
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- 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]
- ba = np.array([othV.x, othV.y, othV.z]) - np.array([actV.x, actV.y, actV.z])
- bc = np.array([lstV.x, lstV.y, lstV.z]) - np.array([actV.x, actV.y, actV.z])
- cosA = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
- ang = np.degrees(np.arccos(cosA))
- if flip_a:
- if ang > 0:
- pg.angle = ang - 180
- else:
- pg.angle = ang + 180
- else:
- pg.angle = ang
- pg.distance = (actV - othV).length
- pg.cartesian_coords = othV - actV
+ pg.command = f"ad3"
return {"FINISHED"}
@@ -1428,30 +597,8 @@ class PDT_OT_Origin(Operator):
Status Set.
"""
- scene = context.scene
- obj = context.view_layer.objects.active
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- obj_loc = obj.matrix_world.decompose()[0]
- cur_loc = scene.cursor.location
- diff_v = obj_loc - cur_loc
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
- for v in bm.verts:
- v.co = v.co + diff_v
- obj.location = cur_loc
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
- elif obj.mode == "OBJECT":
- for v in obj.data.vertices:
- v.co = v.co + diff_v
- obj.location = cur_loc
- else:
- errmsg = f"{PDT_ERR_EDOB_MODE} {obj.mode})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
+ pg = context.scene.pdt_pg
+ pg.command = f"otc"
return {"FINISHED"}
@@ -1489,38 +636,6 @@ class PDT_OT_Taper(Operator):
Status Set.
"""
- scene = context.scene
- pg = scene.pdt_pg
- tap_ax = pg.taper
- ang_v = pg.angle
- obj = context.view_layer.objects.active
- if ang_v > 80 or ang_v < -80:
- errmsg = f"{PDT_ERR_TAPER_ANG} {ang_v})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- if obj is None:
- errmsg = PDT_ERR_NO_ACT_OBJ
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- _, a2, a3 = setAxis(tap_ax)
- bm = bmesh.from_edit_mesh(obj.data)
- if len(bm.select_history) >= 1:
- rotV = bm.select_history[-1]
- viewV = viewCoords(rotV.co.x, rotV.co.y, rotV.co.z)
- else:
- errmsg = f"{PDT_ERR_TAPER_SEL} {len(bm.select_history)})"
- self.report({"ERROR"}, errmsg)
- return {"FINISHED"}
- for v in [v for v in bm.verts if v.select]:
- if pg.plane == "LO":
- v_loc = viewCoords(v.co.x, v.co.y, v.co.z)
- dis_v = sqrt((viewV.x - v_loc.x) ** 2 + (viewV.y - v_loc.y) ** 2)
- x_loc = dis_v * tan(ang_v * pi / 180)
- vm = viewDir(x_loc, 0)
- v.co = v.co - vm
- else:
- dis_v = sqrt((rotV.co[a3] - v.co[a3]) ** 2 + (rotV.co[a2] - v.co[a2]) ** 2)
- v.co[a2] = v.co[a2] - (dis_v * tan(ang_v * pi / 180))
- bmesh.update_edit_mesh(obj.data)
- bm.select_history.clear()
+ pg = context.scene.pdt_pg
+ pg.command = f"tap"
return {"FINISHED"}
diff --git a/precision_drawing_tools/pdt_etof.py b/precision_drawing_tools/pdt_etof.py
index 5c2fbc43..e1b65f6f 100644
--- a/precision_drawing_tools/pdt_etof.py
+++ b/precision_drawing_tools/pdt_etof.py
@@ -31,27 +31,25 @@ from .pdt_msg_strings import (
PDT_ERR_NOINT,
PDT_ERR_SEL_1_E_1_F
)
+from .pdt_functions import oops
-def failure_message(self):
+def failure_message(self, context):
"""Warn to the user to select 1 edge and 1 face."""
- self.report({"WARNING"}, PDT_ERR_SEL_1_E_1_F)
+ pg = context.scene.pdt_pg
+ pg.error = f"Select One Face and One Edge"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
-def failure_message_on_plane(self):
+def failure_message_on_plane(self, context):
"""Report an informative error message in a popup."""
- msg2 = """\
-Edge2Face expects the edge to intersect at one point on the plane of the selected face. You're
-seeing this warning because mathutils.geometry.intersect_line_plane is being called on an edge/face
-combination that has no clear intersection point ( both points of the edge either touch the same
-plane as the face or they lie in a plane that is offset along the face's normal )"""
- lines = msg2.split("\n")
- for line in lines:
- self.report({"INFO"}, line)
- self.report({"ERROR"}, PDT_ERR_NOINT)
-
-
-def extend_vertex(self):
+ pg = context.scene.pdt_pg
+ pg.error = f"{PDT_ERR_NOINT}"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
+
+def extend_vertex(self, context):
"""Computes Edge Extension to Face.
Args:
@@ -61,47 +59,52 @@ def extend_vertex(self):
Nothing."""
obj = bpy.context.edit_object
- me = obj.data
- bm = bmesh.from_edit_mesh(me)
- verts = bm.verts
- faces = bm.faces
-
- planes = [f for f in faces if f.select]
- if not len(planes) == 1:
- failure_message(self)
- return
+ if all([bool(obj), obj.type == "MESH", obj.mode == "EDIT"]):
+ me = obj.data
+ bm = bmesh.from_edit_mesh(me)
+ verts = bm.verts
+ faces = bm.faces
- plane = planes[0]
- plane_vert_indices = plane.verts[:]
- all_selected_vert_indices = [v for v in verts if v.select]
+ planes = [f for f in faces if f.select]
+ if not len(planes) == 1:
+ failure_message(self, context)
+ return
- M = set(plane_vert_indices)
- N = set(all_selected_vert_indices)
- O = N.difference(M)
- O = list(O)
+ plane = planes[0]
+ plane_vert_indices = plane.verts[:]
+ all_selected_vert_indices = [v for v in verts if v.select]
- if not len(O) == 2:
- failure_message(self)
- return
+ M = set(plane_vert_indices)
+ N = set(all_selected_vert_indices)
+ O = N.difference(M)
+ O = list(O)
- (v1_ref, v1), (v2_ref, v2) = [(i, i.co) for i in O]
+ if not len(O) == 2:
+ failure_message(self, context)
+ return
- plane_co = plane.calc_center_median()
- plane_no = plane.normal
+ (v1_ref, v1), (v2_ref, v2) = [(i, i.co) for i in O]
- new_co = intersect_line_plane(v1, v2, plane_co, plane_no, False)
+ plane_co = plane.calc_center_median()
+ plane_no = plane.normal
- if new_co:
- new_vertex = verts.new(new_co)
- A_len = (v1 - new_co).length
- B_len = (v2 - new_co).length
+ new_co = intersect_line_plane(v1, v2, plane_co, plane_no, False)
- vertex_reference = v1_ref if (A_len < B_len) else v2_ref
- bm.edges.new([vertex_reference, new_vertex])
- bmesh.update_edit_mesh(me, True)
+ if new_co:
+ new_vertex = verts.new(new_co)
+ A_len = (v1 - new_co).length
+ B_len = (v2 - new_co).length
+ vertex_reference = v1_ref if (A_len < B_len) else v2_ref
+ bm.edges.new([vertex_reference, new_vertex])
+ bmesh.update_edit_mesh(me, True)
+
+ else:
+ failure_message_on_plane(self, context)
else:
- failure_message_on_plane(self)
+ pg.error = f"{PDT_ERR_EDOB_MODE},{obj.mode})"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
class PDT_OT_EdgeToFace(bpy.types.Operator):
@@ -128,5 +131,6 @@ class PDT_OT_EdgeToFace(bpy.types.Operator):
Returns:
Status Set."""
- extend_vertex(self)
+ pg = context.scene.pdt_pg
+ pg.command = f"etf"
return {"FINISHED"}
diff --git a/precision_drawing_tools/pdt_functions.py b/precision_drawing_tools/pdt_functions.py
index 01e595ff..cc800d61 100644
--- a/precision_drawing_tools/pdt_functions.py
+++ b/precision_drawing_tools/pdt_functions.py
@@ -36,7 +36,12 @@ from .pdt_msg_strings import (
PDT_ERR_SEL_2_V_1_E,
PDT_ERR_SEL_2_OBJS,
PDT_ERR_NO_ACT_OBJ,
- PDT_ERR_SEL_1_EDGEM
+ PDT_ERR_SEL_1_EDGEM,
+ PDT_ERR_BAD1VALS,
+ PDT_ERR_BAD2VALS,
+ PDT_ERR_BAD3VALS,
+ PDT_ERR_SEL_2_VERTS,
+ PDT_ERR_CONNECTED,
)
@@ -88,7 +93,7 @@ def oops(self, context):
self.layout.label(text=pg.error)
-def setMode(mode_pl):
+def set_mode(mode_pl):
"""Sets Active Axes for View Orientation.
Sets indices of axes for locational vectors
@@ -112,7 +117,7 @@ def setMode(mode_pl):
#FIXME: This needs a proper specification and a default
-def setAxis(mode_pl):
+def set_axis(mode_pl):
"""Sets Active Axes for View Orientation.
Sets indices for axes from taper vectors
@@ -142,7 +147,7 @@ def setAxis(mode_pl):
#FIXME: This needs a proper specification and a default
-def checkSelection(num, bm, obj):
+def check_selection(num, bm, obj):
"""Check that the Object's select_history has sufficient entries.
If selection history is not Verts, clears selection and history.
@@ -188,7 +193,7 @@ def checkSelection(num, bm, obj):
return None
-def updateSel(bm, verts, edges, faces):
+def update_sel(bm, verts, edges, faces):
"""Updates Vertex, Edge and Face Selections following a function.
Args:
@@ -214,7 +219,7 @@ def updateSel(bm, verts, edges, faces):
f.select_set(True)
-def viewCoords(x_loc, y_loc, z_loc):
+def view_coords(x_loc, y_loc, z_loc):
"""Converts input Vector values to new Screen Oriented Vector.
Args:
@@ -237,7 +242,7 @@ def viewCoords(x_loc, y_loc, z_loc):
return Vector((0, 0, 0))
-def viewCoordsI(x_loc, y_loc, z_loc):
+def view_coords_i(x_loc, y_loc, z_loc):
"""Converts Screen Oriented input Vector values to new World Vector.
Converts View tranformation Matrix to Rotational Matrix
@@ -262,7 +267,7 @@ def viewCoordsI(x_loc, y_loc, z_loc):
return Vector((0, 0, 0))
-def viewDir(dis_v, ang_v):
+def view_dir(dis_v, ang_v):
"""Converts Distance and Angle to View Oriented Vector.
Converts View Transformation Matrix to Rotational Matrix (3x3)
@@ -314,7 +319,7 @@ def euler_to_quaternion(roll, pitch, yaw):
return Quaternion((qw, qx, qy, qz))
-def arcCentre(actV, othV, lstV):
+def arc_centre(actV, othV, lstV):
"""Calculates Centre of Arc from 3 Vector Locations using standard Numpy routine
Args:
@@ -363,18 +368,18 @@ def intersection(actV, othV, lstV, fstV, plane):
if plane == "LO":
disV = othV - actV
- othV = viewCoordsI(disV.x, disV.y, disV.z)
+ othV = view_coords_i(disV.x, disV.y, disV.z)
disV = lstV - actV
- lstV = viewCoordsI(disV.x, disV.y, disV.z)
+ lstV = view_coords_i(disV.x, disV.y, disV.z)
disV = fstV - actV
- fstV = viewCoordsI(disV.x, disV.y, disV.z)
+ fstV = view_coords_i(disV.x, disV.y, disV.z)
refV = Vector((0, 0, 0))
ap1 = (fstV.x, fstV.y)
ap2 = (lstV.x, lstV.y)
bp1 = (othV.x, othV.y)
bp2 = (refV.x, refV.y)
else:
- a1, a2, a3 = setMode(plane)
+ a1, a2, a3 = set_mode(plane)
ap1 = (fstV[a1], fstV[a2])
ap2 = (lstV[a1], lstV[a2])
bp1 = (othV[a1], othV[a2])
@@ -404,7 +409,7 @@ def intersection(actV, othV, lstV, fstV, plane):
return vector_delta, True
-def getPercent(obj, flip_p, per_v, data, scene):
+def get_percent(obj, flip_p, per_v, data, scene):
"""Calculates a Percentage Distance between 2 Vectors.
Calculates a point that lies a set percentage between two given points
@@ -471,20 +476,20 @@ def getPercent(obj, flip_p, per_v, data, scene):
return Vector((V[0], V[1], V[2]))
-def objCheck(obj, scene, oper):
+def obj_check(obj, scene, operator):
"""Check Object & Selection Validity.
Args:
obj: Active Object
scene: Active Scene
- oper: Operation to check
+ operator: Operation to check
Returns:
Object Bmesh and Validity Boolean.
"""
pg = scene.pdt_pg
- _oper = oper.upper()
+ _operator = operator.upper()
if obj is None:
pg.error = PDT_ERR_NO_ACT_OBJ
@@ -492,7 +497,7 @@ def objCheck(obj, scene, oper):
return None, False
if obj.mode == "EDIT":
bm = bmesh.from_edit_mesh(obj.data)
- if _oper == "S":
+ if _operator == "S":
if len(bm.edges) < 1:
pg.error = f"{PDT_ERR_SEL_1_EDGEM} {len(bm.edges)})"
bpy.context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
@@ -500,8 +505,8 @@ def objCheck(obj, scene, oper):
else:
return bm, True
if len(bm.select_history) >= 1:
- if _oper not in {"D", "E", "F", "G", "N", "S"}:
- actV = checkSelection(1, bm, obj)
+ if _operator not in {"D", "E", "F", "G", "N", "S"}:
+ actV = check_selection(1, bm, obj)
else:
verts = [v for v in bm.verts if v.select]
if len(verts) > 0:
@@ -517,7 +522,7 @@ def objCheck(obj, scene, oper):
return None, True
-def disAng(vals, flip_a, plane, scene):
+def dis_ang(vals, flip_a, plane, scene):
"""Set Working Axes when using Direction command.
Args:
@@ -540,9 +545,9 @@ def disAng(vals, flip_a, plane, scene):
ang_v = ang_v + 180
pg.angle = ang_v
if plane == "LO":
- vector_delta = viewDir(dis_v, ang_v)
+ vector_delta = view_dir(dis_v, ang_v)
else:
- a1, a2, _ = setMode(plane)
+ a1, a2, _ = set_mode(plane)
vector_delta = Vector((0, 0, 0))
# fmt: off
vector_delta[a1] = vector_delta[a1] + (dis_v * cos(ang_v * pi/180))
diff --git a/precision_drawing_tools/pdt_menus.py b/precision_drawing_tools/pdt_menus.py
index 01cd5d09..61444d60 100644
--- a/precision_drawing_tools/pdt_menus.py
+++ b/precision_drawing_tools/pdt_menus.py
@@ -87,7 +87,7 @@ def ui_width():
#
class PDT_PT_PanelDesign(Panel):
bl_idname = "PDT_PT_PanelDesign"
- bl_label = "PDT Design"
+ bl_label = "PDT Design Operations"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = "PDT"
@@ -180,39 +180,51 @@ class PDT_PT_PanelDesign(Panel):
row = box.row()
row.prop(pdt_pg, "flip_percent", text=PDT_LAB_FLIPPERCENT)
+class PDT_PT_PanelTools(Panel):
+ bl_idname = "PDT_PT_PanelTools"
+ bl_label = "PDT Design Tools"
+ bl_space_type = "VIEW_3D"
+ bl_region_type = "UI"
+ bl_category = "PDT"
+ bl_options = {'DEFAULT_CLOSED'}
+
+ def draw(self, context):
+ ui_cutoff = bpy.context.preferences.addons[__package__].preferences.pdt_ui_width
+ layout = self.layout
+ pdt_pg = context.scene.pdt_pg
# -----
# Tools
- toolbox = layout.box()
- toolbox.label(text=PDT_LAB_TOOLS)
- row = toolbox.row()
+ row = layout.row()
+ row.label(text=PDT_LAB_TOOLS)
+ row = layout.row()
row.operator("pdt.origin", text=PDT_LAB_ORIGINCURSOR)
- row = toolbox.row()
+ row = layout.row()
row.operator("pdt.angle2", text=PDT_LAB_AD2D)
row.operator("pdt.angle3", text=PDT_LAB_AD3D)
- row = toolbox.row()
+ row = layout.row()
row.operator("pdt.join", text=PDT_LAB_JOIN2VERTS)
row.operator("pdt.linetobisect", text=PDT_LAB_BISECT)
- row = toolbox.row()
+ row = layout.row()
row.operator("pdt.edge_to_face", text=PDT_LAB_EDGETOEFACE)
row.operator("pdt.intersectall", text=PDT_LAB_INTERSETALL)
#
# Taper tool
- box = toolbox.box()
+ box = layout.box()
row = box.row()
row.operator("pdt.taper", text=PDT_LAB_TAPER)
row.prop(pdt_pg, "taper", text=PDT_LAB_TAPERAXES)
#
# Fillet tool
- box = toolbox.box()
+ box = layout.box()
+ row = box.row()
+ row.operator("pdt.fillet", text=f"{PDT_LAB_FILLET}")
+ row.prop(pdt_pg, "fillet_intersect", text="Intersect")
row = box.row()
row.prop(pdt_pg, "fillet_radius", text=PDT_LAB_RADIUS)
row.prop(pdt_pg, "fillet_profile", text=PDT_LAB_PROFILE)
row = box.row()
row.prop(pdt_pg, "fillet_segments", text=PDT_LAB_SEGMENTS)
row.prop(pdt_pg, "fillet_vertices_only", text=PDT_LAB_USEVERTS)
- row = box.row()
- row.operator("pdt.fillet", text=f"{PDT_LAB_FILLET}")
- row.prop(pdt_pg, "fillet_int", text="Intersect")
class PDT_PT_PanelPivotPoint(Panel):
diff --git a/precision_drawing_tools/pdt_msg_strings.py b/precision_drawing_tools/pdt_msg_strings.py
index 46d8d635..01895c4c 100644
--- a/precision_drawing_tools/pdt_msg_strings.py
+++ b/precision_drawing_tools/pdt_msg_strings.py
@@ -56,10 +56,10 @@ PDT_LAB_TAPERAXES = "" # Intentionally left blank
PDT_LAB_TAPER = "Taper"
PDT_LAB_INTERSETALL = "Intersect All"
PDT_LAB_BISECT = "Bisect"
-PDT_LAB_EDGETOEFACE = "Edge-Face"
+PDT_LAB_EDGETOEFACE = "Edge-To-Face"
PDT_LAB_FILLET = "Fillet"
PDT_LAB_SEGMENTS = "Segments"
-PDT_LAB_USEVERTS = "Use Verts"
+PDT_LAB_USEVERTS = "Use Vertices"
PDT_LAB_RADIUS = "Radius"
PDT_LAB_PROFILE = "Profile"
PDT_LAB_PIVOTSIZE = "" # Intentionally left blank
@@ -114,7 +114,6 @@ PDT_ERR_SCALEZERO = "Scale Distance is 0"
PDT_ERR_CHARS_NUM = "Bad Command Format, not enough Characters"
PDT_ERR_BADFLETTER = "Bad Operator (1st Letter); C D E F G N M P S V or ? only"
-PDT_ERR_BADSLETTER = "Bad Mode (2nd Letter); A D I or P only (+ X Y & Z for Maths) (+ I V & G for Fillet)"
PDT_ERR_BADMATHS = "Not a Valid Mathematical Expression!"
PDT_ERR_BADCOORDL = "X Y & Z Not permitted in anything other than Maths Operations"
PDT_ERR_BAD1VALS = "Bad Command - 1 Value needed"
@@ -130,7 +129,7 @@ PDT_ERR_NOCOMMAS = "No commas allowed in Maths Command"
PDT_ERR_2CPNPE = "Select 2 Co-Planar Non-Parallel Edges"
PDT_ERR_NCEDGES = "Edges must be Co-Planar Non-Parallel Edges, Selected Edges aren't"
PDT_ERR_1EDGE1FACE = "Select 1 face and 1 Detached Edge"
-PDT_ERR_NOINT = "No Intersection Found, see the Info Panel for Details"
+PDT_ERR_NOINT = "No Intersection Found"
# Info messages
#
diff --git a/precision_drawing_tools/pdt_pivot_point.py b/precision_drawing_tools/pdt_pivot_point.py
index f3b2ef0d..865064ed 100644
--- a/precision_drawing_tools/pdt_pivot_point.py
+++ b/precision_drawing_tools/pdt_pivot_point.py
@@ -26,7 +26,7 @@ import bmesh
from bpy.types import Operator, SpaceView3D
from mathutils import Vector, Matrix
from math import pi
-from .pdt_functions import viewCoords, drawCallback3D
+from .pdt_functions import view_coords, drawCallback3D
from .pdt_msg_strings import (
PDT_CON_AREYOURSURE,
PDT_ERR_EDIT_MODE,
@@ -151,7 +151,7 @@ class PDT_OT_ViewPlaneRotate(Operator):
return {"FINISHED"}
bm = bmesh.from_edit_mesh(obj.data)
v1 = Vector((0, 0, 0))
- v2 = viewCoords(0, 0, 1)
+ v2 = view_coords(0, 0, 1)
axis = (v2 - v1).normalized()
rot = Matrix.Rotation((pg.pivot_ang * pi / 180), 4, axis)
verts = verts = [v for v in bm.verts if v.select]
diff --git a/precision_drawing_tools/pdt_view.py b/precision_drawing_tools/pdt_view.py
index 9160aded..f1e73245 100644
--- a/precision_drawing_tools/pdt_view.py
+++ b/precision_drawing_tools/pdt_view.py
@@ -55,14 +55,12 @@ class PDT_OT_ViewRot(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- roll_value = euler_to_quaternion(
- pg.rotation_coords.x * pi / 180,
- pg.rotation_coords.y * pi / 180,
- pg.rotation_coords.z * pi / 180
- )
- areas[0].spaces.active.region_3d.view_rotation = roll_value
+ roll_value = euler_to_quaternion(
+ pg.rotation_coords.x * pi / 180,
+ pg.rotation_coords.y * pi / 180,
+ pg.rotation_coords.z * pi / 180
+ )
+ context.region_data.view_rotation = roll_value
return {"FINISHED"}
@@ -88,9 +86,7 @@ class PDT_OT_vRotL(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITLEFT")
+ bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITLEFT")
return {"FINISHED"}
@@ -117,9 +113,7 @@ class PDT_OT_vRotR(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITRIGHT")
+ bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITRIGHT")
return {"FINISHED"}
@@ -146,9 +140,7 @@ class PDT_OT_vRotU(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITUP")
+ bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITUP")
return {"FINISHED"}
@@ -175,9 +167,7 @@ class PDT_OT_vRotD(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITDOWN")
+ bpy.ops.view3d.view_orbit(angle=(pg.vrotangle * pi / 180), type="ORBITDOWN")
return {"FINISHED"}
@@ -204,9 +194,7 @@ class PDT_OT_vRoll(Operator):
scene = context.scene
pg = scene.pdt_pg
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- bpy.ops.view3d.view_roll(angle=(pg.vrotangle * pi / 180), type="ANGLE")
+ bpy.ops.view3d.view_roll(angle=(pg.vrotangle * pi / 180), type="ANGLE")
return {"FINISHED"}
@@ -219,7 +207,7 @@ class PDT_OT_viso(Operator):
def execute(self, context):
"""Set Isometric View.
- Set view orientation to Isometric
+ Set view orientation to Orthographic Isometric
Args:
context: Blender bpy.context instance.
@@ -227,14 +215,11 @@ class PDT_OT_viso(Operator):
Returns:
Status Set.
"""
-
- areas = [a for a in context.screen.areas if a.type == "VIEW_3D"]
- if len(areas) > 0:
- # Try working this out in your head!
- areas[0].spaces.active.region_3d.view_rotation = Quaternion(
- (0.8205, 0.4247, -0.1759, -0.3399)
- )
- areas[0].spaces.active.region_3d.view_perspective = 'ORTHO'
+ # Try working this out in your head!
+ context.region_data.view_rotation = Quaternion(
+ (0.8205, 0.4247, -0.1759, -0.3399)
+ )
+ context.region_data.view_perspective = 'ORTHO'
return {"FINISHED"}
@@ -256,6 +241,7 @@ class PDT_OT_Reset3DView(Operator):
# The default view_distance to the origin when starting up Blender
default_view_distance = 17.986562728881836
+ default_view_distance = bpy.data.screens['Layout'].areas[-1].spaces[0].region_3d.view_distance
# The default view_matrix when starting up Blender
default_view_matrix = (
(0.41, -0.4017, 0.8188, 0.0),
@@ -264,26 +250,24 @@ class PDT_OT_Reset3DView(Operator):
(0.0, 0.0, -17.9866, 1.0)
)
- for area in (a for a in context.screen.areas if a.type == 'VIEW_3D'):
- view = area.spaces[0].region_3d
- if view is not None:
- debug(f"is_orthographic_side_view: {view.is_orthographic_side_view}")
- if view.is_orthographic_side_view:
- # When the view is orthographic, reset the distance and location.
- # The rotation already fits.
- debug(f"view_distance before reset: {view.view_distance}")
- debug(f"view_location before reset: {view.view_location}")
- view.view_distance = default_view_distance
- view.view_location = (-0.0, -0.0, -0.0)
- view.update()
- debug(f"view_distance AFTER reset: {view.view_distance}")
- debug(f"view_location AFTER reset: {view.view_location}")
- else:
- # Otherwise, the view matrix needs to be reset (includes distance).
- debug(f"view_matrix before reset:\n{view.view_matrix}")
- view.view_matrix = default_view_matrix
- view.view_distance = default_view_distance
- view.update()
- debug(f"view_matrix AFTER reset:\n{view.view_matrix}")
+ view = context.region_data
+ debug(f"is_orthographic_side_view: {view.is_orthographic_side_view}")
+ if view.is_orthographic_side_view:
+ # When the view is orthographic, reset the distance and location.
+ # The rotation already fits.
+ debug(f"view_distance before reset: {view.view_distance}")
+ debug(f"view_location before reset: {view.view_location}")
+ view.view_distance = default_view_distance
+ view.view_location = (-0.0, -0.0, -0.0)
+ view.update()
+ debug(f"view_distance AFTER reset: {view.view_distance}")
+ debug(f"view_location AFTER reset: {view.view_location}")
+ else:
+ # Otherwise, the view matrix needs to be reset.
+ debug(f"view_matrix before reset:\n{view.view_matrix}")
+ view.view_matrix = default_view_matrix
+ view.view_distance = default_view_distance
+ view.update()
+ debug(f"view_matrix AFTER reset:\n{view.view_matrix}")
return {'FINISHED'}
diff --git a/precision_drawing_tools/pdt_xall.py b/precision_drawing_tools/pdt_xall.py
index f27ae6c5..0c01b5d8 100644
--- a/precision_drawing_tools/pdt_xall.py
+++ b/precision_drawing_tools/pdt_xall.py
@@ -146,6 +146,47 @@ def unselect_nonintersecting(bm, d_edges, edge_indices):
bm.edges[edge].select = False
+def intersect_all(self, context):
+ """Computes All intersections with Crossing Geometry.
+
+ Deletes original edges and replaces with new intersected edges
+
+ Args:
+ context: Blender bpy.context instance.
+
+ Returns:
+ Status Set.
+ """
+
+ pg = context.scene.pdt_pg
+ obj = context.active_object
+ if all([bool(obj), obj.type == "MESH", obj.mode == "EDIT"]):
+ # must force edge selection mode here
+ bpy.context.tool_settings.mesh_select_mode = (False, True, False)
+
+
+ if obj.mode == "EDIT":
+ bm = bmesh.from_edit_mesh(obj.data)
+
+ selected_edges = [edge for edge in bm.edges if edge.select]
+ edge_indices = [i.index for i in selected_edges]
+
+ int_dict = get_intersection_dictionary(bm, edge_indices)
+
+ unselect_nonintersecting(bm, int_dict.keys(), edge_indices)
+ update_mesh(bm, int_dict)
+
+ bmesh.update_edit_mesh(obj.data)
+ else:
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
+
+ return
+ else:
+ pg.error = f"{PDT_ERR_EDOB_MODE},{obj.mode})"
+ context.window_manager.popup_menu(oops, title="Error", icon="ERROR")
+ return
+
class PDT_OT_IntersectAllEdges(bpy.types.Operator):
"""Cut Selected Edges at All Intersections."""
@@ -172,24 +213,6 @@ class PDT_OT_IntersectAllEdges(bpy.types.Operator):
Status Set.
"""
- # must force edge selection mode here
- bpy.context.tool_settings.mesh_select_mode = (False, True, False)
-
- obj = context.active_object
- if obj.mode == "EDIT":
- bm = bmesh.from_edit_mesh(obj.data)
-
- selected_edges = [edge for edge in bm.edges if edge.select]
- edge_indices = [i.index for i in selected_edges]
-
- int_dict = get_intersection_dictionary(bm, edge_indices)
-
- unselect_nonintersecting(bm, int_dict.keys(), edge_indices)
- update_mesh(bm, int_dict)
-
- bmesh.update_edit_mesh(obj.data)
- else:
- msg = PDT_ERR_EDIT_MODE + obj.mode + ")"
- self.report({"ERROR"}, msg)
-
+ pg = context.scene.pdt_pg
+ pg.command = f"intall"
return {"FINISHED"}