Skip to content

Commit

Permalink
Add support for full circles to PathGeom.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlampert authored and yorikvanhavre committed Jun 15, 2018
1 parent a59e879 commit 36a82c6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
29 changes: 19 additions & 10 deletions src/Mod/Path/PathScripts/PathGeom.py
Expand Up @@ -33,7 +33,11 @@

PathGeomTolerance = 0.000001

PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())
if False:
PathLog.setLevel(PathLog.Level.DEBUG, PathLog.thisModule())
PathLog.trackModule(PathLog.thisModule())
else:
PathLog.setLevel(PathLog.Level.INFO, PathLog.thisModule())

# Qt tanslation handling
def translate(context, text, disambig=None):
Expand Down Expand Up @@ -229,17 +233,22 @@ def cmdsForEdge(cls, edge, flip = False, useHelixForBSpline = True, segm = 50):
cmd = 'G2' if not flip else 'G3'
else:
cmd = 'G3' if not flip else 'G2'
pd = Part.Circle(PathGeom.xy(p1), PathGeom.xy(p2), PathGeom.xy(p3)).Center
PathLog.debug("**** %s.%d: (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f) -> center=(%.2f, %.2f)" % (cmd, flip, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, pd.x, pd.y))

# Have to calculate the center in the XY plane, using pd leads to an error if this is a helix
pa = PathGeom.xy(p1)
pb = PathGeom.xy(p2)
pc = PathGeom.xy(p3)
offset = Part.Circle(pa, pb, pc).Center - pa
if cls.pointsCoincide(p1, p3):
# A full circle
offset = edge.Curve.Center - pt
else:
pd = Part.Circle(PathGeom.xy(p1), PathGeom.xy(p2), PathGeom.xy(p3)).Center
PathLog.debug("**** %s.%d: (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f) -> center=(%.2f, %.2f)" % (cmd, flip, p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, pd.x, pd.y))

# Have to calculate the center in the XY plane, using pd leads to an error if this is a helix
pa = PathGeom.xy(p1)
pb = PathGeom.xy(p2)
pc = PathGeom.xy(p3)
offset = Part.Circle(pa, pb, pc).Center - pa

PathLog.debug("**** (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)" % (pa.x, pa.y, pa.z, pc.x, pc.y, pc.z))
PathLog.debug("**** (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)" % (pb.x, pb.y, pb.z, pd.x, pd.y, pd.z))
PathLog.debug("**** (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)" % (pa.x, pa.y, pa.z, pc.x, pc.y, pc.z))
PathLog.debug("**** (%.2f, %.2f, %.2f) - (%.2f, %.2f, %.2f)" % (pb.x, pb.y, pb.z, pd.x, pd.y, pd.z))
PathLog.debug("**** (%.2f, %.2f, %.2f)" % (offset.x, offset.y, offset.z))

params.update({'I': offset.x, 'J': offset.y, 'K': (p3.z - p1.z)/2})
Expand Down
18 changes: 16 additions & 2 deletions src/Mod/Path/PathTests/TestPathGeom.py
Expand Up @@ -239,15 +239,29 @@ def test40(self):

def cmds(pa, pb, pc, flip):
return PathGeom.cmdsForEdge(Part.Edge(Part.Arc(pa, pb, pc)), flip)[0]
def cmd(c, end, off):
return Path.Command(c, {'X': end.x, 'Y': end.y, 'Z': end.z, 'I': off.x, 'J': off.y, 'K': off.z})
def cmd(g, end, off):
return Path.Command(g, {'X': end.x, 'Y': end.y, 'Z': end.z, 'I': off.x, 'J': off.y, 'K': off.z})

self.assertCommandEqual(cmds(p1, p2, p3, False), cmd('G2', p3, Vector(0, 10, 0)))
self.assertCommandEqual(cmds(p1, p4, p3, False), cmd('G3', p3, Vector(0, 10, 0)))

self.assertCommandEqual(cmds(p1, p2, p3, True), cmd('G3', p1, Vector(0, -10, 0)))
self.assertCommandEqual(cmds(p1, p4, p3, True), cmd('G2', p1, Vector(0, -10, 0)))

def test41(self):
"""Verify circle results in proper G2/G3 comamnds."""

def cmds(center, radius, up = True):
norm = Vector(0, 0, 1) if up else Vector(0, 0, -1)
return PathGeom.cmdsForEdge(Part.Edge(Part.Circle(center, norm, radius)))[0]
def cmd(g, end, off):
return Path.Command(g, {'X': end.x, 'Y': end.y, 'Z': end.z, 'I': off.x, 'J': off.y, 'K': off.z})

center = Vector(10, 10, 0)
radius = 5

self.assertCommandEqual(cmds(center, radius), cmd('G3', Vector(15, 10, 0), Vector(-5, 0, 0)))


def test50(self):
"""Verify proper wire(s) aggregation from a Path."""
Expand Down

0 comments on commit 36a82c6

Please sign in to comment.