[Bf-extensions-cvs] [706fce2d] master: xoffsets: fixing spacing, mutable args, var names

NBurn noreply at git.blender.org
Tue May 30 03:23:23 CEST 2017


Commit: 706fce2d1d195096d081b92ba47b43a38dc120f7
Author: NBurn
Date:   Mon May 29 21:18:28 2017 -0400
Branches: master
https://developer.blender.org/rBAC706fce2d1d195096d081b92ba47b43a38dc120f7

xoffsets: fixing spacing, mutable args, var names

fixed spacing around parantheses and brackets
removed mutable default arguments
changed variable names in ReferencePoints and global constant list

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

M	mesh_xoffsets.py

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

diff --git a/mesh_xoffsets.py b/mesh_xoffsets.py
index 2c7d98af..9059c041 100644
--- a/mesh_xoffsets.py
+++ b/mesh_xoffsets.py
@@ -59,6 +59,7 @@ import bpy
 import bgl
 import blf
 import bmesh
+from copy import deepcopy
 from math import fmod, sqrt, degrees, radians
 from mathutils import Vector, geometry, Quaternion, Euler
 from mathutils.geometry import intersect_line_line_2d
@@ -70,15 +71,14 @@ from bpy_extras.view3d_utils import location_3d_to_region_2d
 print("Exact Offsets loaded")
 
 (
-    SET_REF_PTS, 
-    GET_TRANSF_MODE, 
-    CHECK_POPUP_INFO, 
-    DO_TRANSFORM, 
-    GET_0_OR_180, 
-    MOVE, 
-    SCALE, 
-    ROTATE, 
-) = range(8)
+    XO_CLICK_CHECK,
+    XO_CHECK_POPUP_INFO,
+    XO_DO_TRANSFORM,
+    XO_GET_0_OR_180,
+    XO_MOVE,
+    XO_SCALE,
+    XO_ROTATE,
+) = range(7)
 
 currMeasStor = 0.0
 newMeasStor = None
@@ -107,7 +107,7 @@ class Colr:
 
 # vertex storage class, stores reference point info
 class VertObj:
-    def __init__(self, objInd=-1, vertInd=-1, co3D=[], co2D=[], dist2D=-1, refInd=-1):
+    def __init__(self, objInd=-1, vertInd=-1, co3D=(), co2D=(), dist2D=-1, refInd=-1):
         self.objInd = objInd
         self.vertInd = vertInd
         self.co3D = co3D
@@ -116,8 +116,11 @@ class VertObj:
         self.refInd = refInd
         self.obj = bpy.context.scene.objects  # short hand, for internal use
 
-    def copy(self):  # return independent copy of vertObj
-        return VertObj( self.objInd, self.vertInd, self.co3D.copy(), [*self.co2D], self.dist2D, self.refInd )
+    # Have to use deepcopy for co's as tuples are the default init
+    # value and tuples don't have a ".copy()" method.
+    def copy(self):  # returns independent copy of VertObj
+        return VertObj(self.objInd, self.vertInd, deepcopy(self.co3D),
+                deepcopy(self.co2D), self.dist2D, self.refInd)
 
     def set2D(self):
         global RegRv3d
@@ -130,19 +133,19 @@ class VertObj:
 
 
 # Stores the reference points and ref pt related info.
-class ReferencePoints():
-    def __init__(self, count=0, rLs=[(),(),()], mLs=[(),(),()], axisLock='', col_ls=[]):
-        self.cnt = count
-        self.rLs = rLs
-        self.mLs = mLs
-        self.axLock = axisLock
-        self.col_ls = col_ls
-
-    def update_col_ls(self):
+class ReferencePoints:
+    def __init__(self):
+        self.cnt = 0  # count
+        self.rpLs = [(),(),()]  # ref pt list
+        self.lpLs = [(),(),()]  # lock pt list
+        self.axLock = ''  # axis lock
+        self.colrLs = Colr.red, Colr.green
+
+    def update_colrLs(self):
         if self.cnt < 3:
-            self.col_ls = [Colr.red, Colr.green]
+            self.colrLs = Colr.red, Colr.green
         else:  # self.cnt > 2
-            self.col_ls = [Colr.red, Colr.blue, Colr.green]
+            self.colrLs = Colr.red, Colr.blue, Colr.green
 
     def removePt(self, remInd):
         # hackery or smart, you decide...
@@ -150,33 +153,33 @@ class ReferencePoints():
             ind = [0, 1, 2][:self.cnt]
             ind.remove(remInd)
             for i in range(len(ind)):
-                self.rLs[i] = self.rLs[ind[i]].copy()
-                self.rLs[i].refInd = i
+                self.rpLs[i] = self.rpLs[ind[i]].copy()
+                self.rpLs[i].refInd = i
         self.cnt -= 1
 
     def tryAdd(self, found_pt):
         if self.cnt > 0:
             for rp in range(self.cnt):
-                if self.rLs[rp].co3D == found_pt.co3D:
+                if self.rpLs[rp].co3D == found_pt.co3D:
                     self.axLock = ''
-                    self.removePt( self.rLs[rp].refInd )
-                    self.mLs = self.rLs
+                    self.removePt(self.rpLs[rp].refInd)
+                    self.lpLs = self.rpLs
                     #print("ref pt removed:", rp, "cnt:", self.cnt)  # debug
-                    self.update_col_ls()
+                    self.update_colrLs()
                     return
-        # if duplicate not found and cnt not max, add found_pt to rLs
+        # if duplicate not found and cnt not max, add found_pt to rpLs
         if self.cnt < 3:
-            self.rLs[self.cnt] = found_pt
-            self.rLs[self.cnt].refInd = self.cnt
+            self.rpLs[self.cnt] = found_pt.copy()
+            self.rpLs[self.cnt].refInd = self.cnt
             ''' Begin Debug 
-            ptFndStr = str(self.rLs[self.cnt].co3D)
+            ptFndStr = str(self.rpLs[self.cnt].co3D)
             ptFndStr = ptFndStr.replace("<Vector ", "Vector(")
             ptFndStr = ptFndStr.replace(">", ")")
             print("Ref_pt_" + str(self.cnt) + ' =', ptFndStr)
             #print("ref pt added:", self.cnt, "cnt:", self.cnt+1) 
             End Debug ''' 
             self.cnt += 1
-        self.update_col_ls()
+        self.update_colrLs()
         return
 
 
@@ -227,7 +230,7 @@ def slope_check(pt1, pt2):
 
 
 def get_slope_3D(self, ptA, ptB):
-    dist3D = get_dist_3D( ptA, ptB )
+    dist3D = get_dist_3D(ptA, ptB)
     x1, y1, z1 = ptA[0], ptA[1], ptA[2]
     x2, y2, z2 = ptB[0], ptB[1], ptB[2]
     if dist3D == 0:
@@ -236,16 +239,16 @@ def get_slope_3D(self, ptA, ptB):
     xSlope = (x1 - x2) / dist3D
     ySlope = (y1 - y2) / dist3D
     zSlope = (z1 - z2) / dist3D
-    return ( xSlope, ySlope, zSlope )
+    return (xSlope, ySlope, zSlope)
 
 
 def get_new_pt_3D(xyz, slope3D, dis3D):
-    #newX = (x1 +- ( dis3D * slopeX ) )
+    #newX = (x1 +- (dis3D * slopeX) )
     x1, y1, z1 = xyz[0], xyz[1], xyz[2]
     slopeX, slopeY, slopeZ = slope3D[0], slope3D[1], slope3D[2]
-    newX = x1 + ( dis3D * slopeX )
-    newY = y1 + ( dis3D * slopeY )
-    newZ = z1 + ( dis3D * slopeZ )
+    newX = x1 + (dis3D * slopeX)
+    newY = y1 + (dis3D * slopeY)
+    newZ = z1 + (dis3D * slopeZ)
     return Vector([newX, newY, newZ])
 
 
@@ -257,12 +260,12 @@ def get_new_3D_coor(self, lock, ptA, ptF, newDis):
         if newDis == 0:
             return ptA
         origSlope = slope_check(ptA, ptF)
-        slope3D = get_slope_3D(self, ptF, ptA )
-        ptN_1 = get_new_pt_3D( ptA, slope3D, newDis )
-        ptN_2 = get_new_pt_3D( ptA, slope3D, -newDis )
-        ptN_1_slp = slope_check( ptA, ptN_1 )
-        ptN_2_slp = slope_check( ptA, ptN_2 )
-        if   origSlope == ptN_1_slp:
+        slope3D = get_slope_3D(self, ptF, ptA)
+        ptN_1 = get_new_pt_3D(ptA, slope3D, newDis)
+        ptN_2 = get_new_pt_3D(ptA, slope3D, -newDis)
+        ptN_1_slp = slope_check(ptA, ptN_1)
+        ptN_2_slp = slope_check(ptA, ptN_2)
+        if origSlope == ptN_1_slp:
             if newDis > 0:
                 return ptN_1
             else:
@@ -275,7 +278,7 @@ def get_new_3D_coor(self, lock, ptA, ptF, newDis):
                 return ptN_1
         else:  # neither slope matches
             self.report({'ERROR'}, 'Slope mismatch. Cannot calculate new point.')
-            return []
+            return None
     elif lock == 'X':
         if ptF[0] > ptA[0]: return Vector([ ptA[0] + newDis, ptF[1], ptF[2] ])
         else: return Vector([ ptA[0] - newDis, ptF[1], ptF[2] ])
@@ -287,7 +290,7 @@ def get_new_3D_coor(self, lock, ptA, ptF, newDis):
         else: return Vector([ ptF[0], ptF[1], ptA[2] - newDis ])
     else:  # neither slope matches
         self.report({'ERROR'}, "Slope mismatch. Can't calculate new point.")
-        return []
+        return None
 
 
 # Floating point math fun! Since equality tests on floats are a crap shoot,
@@ -319,8 +322,8 @@ def angleMatch3D(pt1, pt2, pt3, expAng):
     #print("pt1", pt1)  # debug
     #print("pt2", pt2)  # debug
     #print("pt3", pt3)  # debug
-    #print( "expAng ", expAng )  # debug
-    #print( "angMeas ", angMeas )  # debug
+    #print("expAng ", expAng)  # debug
+    #print("angMeas ", angMeas)  # debug
     return AreFloatsEq(angMeas, expAng)
 
 
@@ -359,10 +362,11 @@ def setLockPts(axis, rPts, refCount):
     else:
         NewPtLs = [ VertObj(), VertObj() ]
         rPts2 = [rPts[i].co3D for i in range(refCount)]  # shorthand
-        if refCount == 2:  # translate
+
         # finds 3D midpoint between 2 supplied coordinates
         # axis determines which coordinates are assigned midpoint values
         # if X, Anchor is [AncX, MidY, MidZ] and Free is [FreeX, MidY, MidZ]
+        if refCount == 2:  # translate
             mid3D = getMidpoint3D( rPts2[0], rPts2[1] )
             if axis == 'X':
                 NewPtLs[0].co3D = Vector([ rPts2[0][0], mid3D[1], mid3D[2] ])
@@ -397,7 +401,7 @@ def setLockPts(axis, rPts, refCount):
                 # axis lock creates identical points, return empty list
                 return []
             else:
-                NewPtLs.append( VertObj( -1, -1, movCo, [], -1, -1 ) )
+                NewPtLs.append( VertObj(-1, -1, movCo, [], -1, -1) )
 
         for itm in NewPtLs: itm.set2D()
         return NewPtLs
@@ -405,21 +409,21 @@ def setLockPts(axis, rPts, refCount):
 
 # Finds out whether positive rotDat.newAngR or negative rotDat.newAngR
 # will result in the desired rotation angle.
-# todo : move self.refPts.rLs to passed args ?
+# todo : move self.refPts.rpLs to passed args ?
 def findCorrectRot(self, rotDat):
-    refPts2 = self.refPts.rLs
+    refPts2 = self.refPts.rpLs
     angDiffRad, newAngleRad = rotDat.angDiffR, rotDat.newAngR
     PivPt, movePt = refPts2[1].co3D, refPts2[2].co3D
     tmpCoP = getRotatedPoint(PivPt, angDiffRad, rotDat, movePt)
     tmpCoN = getRotatedPoint(PivPt, -angDiffRad, rotDat, movePt)
     #print("tmpCoP", tmpCoP, "\ntmpCoN", tmpCoN)  # debug
-    self.refPts.mLs = setLockPts(self.refPts.axLock, refPts2, self.refPts.cnt)
-    lockPts = self.refPts.mLs
+    self.refPts.lpLs = setLockPts(self.refPts.axLock, refPts2, self.refPts.cnt)
+    lockPts = self.refPts.lpLs
     # is below check needed? is lockPts tested before findCorrectRot called?
     # will be needed for a selection move?
     if lockPts == []:
         print("lockPts == [] CHECK IS NEEDED!")
-        self.refPts.mLs = refPts2
+        self.refPts.lpLs = refPts2
         self.refPts.axLock = ''
         return ()
     else:
@@ -440,7 +444,7 @@ def find_closest_vert(obInd, loc, meshObj):
         tmpOb = VertObj(obInd, i)
         tmpOb.co3D = meshObj.matrix_world * v.co # global instead of local
 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list