Skip to content

Commit

Permalink
Draft: make sure normal is consistent for whole path in PathArray
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Apr 10, 2015
1 parent 7a096ac commit 0c32b1b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Mod/Draft/Draft.py
Expand Up @@ -4871,7 +4871,7 @@ def getParameterFromV0(self, edge, offset):
length = offset
return(edge.getParameterByLength(length))

def orientShape(self,shape,edge,offset,RefPt,xlate,align):
def orientShape(self,shape,edge,offset,RefPt,xlate,align,normal=None):
'''Orient shape to tangent at parm offset along edge.'''
# http://en.wikipedia.org/wiki/Euler_angles
import Part
Expand All @@ -4893,8 +4893,11 @@ def orientShape(self,shape,edge,offset,RefPt,xlate,align):
t = edge.tangentAt(self.getParameterFromV0(edge,offset))
t.normalize()
try:
n = edge.normalAt(self.getParameterFromV0(edge,offset))
n.normalize()
if normal:
n = normal
else:
n = edge.normalAt(self.getParameterFromV0(edge,offset))
n.normalize()
b = (t.cross(n))
b.normalize()
except FreeCAD.Base.FreeCADError: # no normal defined here
Expand Down Expand Up @@ -4932,19 +4935,20 @@ def pathArray(self,shape,pathwire,count,xlate,align):
import Part
import DraftGeomUtils
closedpath = DraftGeomUtils.isReallyClosed(pathwire)
path = DraftGeomUtils.sortEdges(pathwire.Edges)
normal = DraftGeomUtils.getNormal(pathwire)
path = DraftGeomUtils.sortEdges(pathwire.Edges)
ends = []
cdist = 0
for e in path: # find cumulative edge end distance
cdist += e.Length
ends.append(cdist)
base = []
pt = path[0].Vertexes[0].Point # place the start shape
ns = self.orientShape(shape,path[0],0,pt,xlate,align)
ns = self.orientShape(shape,path[0],0,pt,xlate,align,normal)
base.append(ns)
if not(closedpath): # closed path doesn't need shape on last vertex
pt = path[-1].Vertexes[-1].Point # place the end shape
ns = self.orientShape(shape,path[-1],path[-1].Length,pt,xlate,align)
ns = self.orientShape(shape,path[-1],path[-1].Length,pt,xlate,align,normal)
base.append(ns)
if count < 3:
return(Part.makeCompound(base))
Expand All @@ -4968,7 +4972,7 @@ def pathArray(self,shape,pathwire,count,xlate,align):
remains = ends[iend] - travel
offset = path[iend].Length - remains
pt = path[iend].valueAt(self.getParameterFromV0(path[iend],offset))
ns = self.orientShape(shape,path[iend],offset,pt,xlate,align)
ns = self.orientShape(shape,path[iend],offset,pt,xlate,align,normal)
base.append(ns)
travel += step
return(Part.makeCompound(base))
Expand Down

0 comments on commit 0c32b1b

Please sign in to comment.