def test30(self): """Verify proper geometry for arcs with rising and fall ing Z-axis are created.""" #print("------ rising helix -------") p1 = Vector(0, 1, 0) p2 = Vector(1, 0, 2) self.assertCurve( PathGeom.edgeForCmd( Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': -1, 'K': 1}), p1), p1, Vector(1/math.sqrt(2), 1/math.sqrt(2), 1), p2) p1 = Vector(-1, 0, 0) p2 = Vector(0, -1, 2) self.assertCurve( PathGeom.edgeForCmd( Path.Command('G3', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 1, 'J': 0, 'K': 1}), p1), p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2) #print("------ falling helix -------") p1 = Vector(0, -1, 2) p2 = Vector(-1, 0, 0) self.assertCurve( PathGeom.edgeForCmd( Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': 1, 'K': -1}), p1), p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2) p1 = Vector(-1, 0, 2) p2 = Vector(0, -1, 0) self.assertCurve( PathGeom.edgeForCmd( Path.Command('G3', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 1, 'J': 0, 'K': -1}), p1), p1, Vector(-1/math.sqrt(2), -1/math.sqrt(2), 1), p2)
def test20(self): """Verify proper geometry for arcs in the XY-plane are created.""" p1 = Vector(0, -1, 2) p2 = Vector(-1, 0, 2) self.assertArc( PathGeom.edgeForCmd( Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': 1, 'K': 0}), p1), p1, p2, 'CW') self.assertArc( PathGeom.edgeForCmd( Path.Command('G3', {'X': p1.x, 'Y': p1.y, 'z': p1.z, 'I': -1, 'J': 0, 'K': 0}), p2), p2, p1, 'CCW')
def test20(self): """Verfiy proper geometry for arcs in the XY-plane are created.""" p1 = Vector(0, -1, 2) p2 = Vector(-1, 0, 2) self.assertArc( PathGeom.edgeForCmd( Path.Command('G2', {'X': p2.x, 'Y': p2.y, 'Z': p2.z, 'I': 0, 'J': 1, 'K': 0}), p1), p1, p2, 'CW') self.assertArc( PathGeom.edgeForCmd( Path.Command('G3', {'X': p1.x, 'Y': p1.y, 'z': p1.z, 'I': -1, 'J': 0, 'K': 0}), p2), p2, p1, 'CCW')
def test10(self): """Verify proper geometry objects for G1 and G01 commands are created.""" spt = Vector(1, 2, 3) self.assertLine( PathGeom.edgeForCmd(Path.Command('G1', { 'X': 7, 'Y': 2, 'Z': 3 }), spt), spt, Vector(7, 2, 3)) self.assertLine( PathGeom.edgeForCmd(Path.Command('G01', { 'X': 1, 'Y': 3, 'Z': 5 }), spt), spt, Vector(1, 3, 5))
def GetPathSolid(self, tool, cmd, pos): toolPath = PathGeom.edgeForCmd(cmd, pos) # curpos = e1.valueAt(e1.LastParameter) startDir = toolPath.tangentAt(0) startDir[2] = 0.0 endPos = toolPath.valueAt(toolPath.LastParameter) endDir = toolPath.tangentAt(toolPath.LastParameter) try: startDir.normalize() endDir.normalize() except: return (None, endPos) # height = self.height # hack to overcome occ bugs rad = tool.Diameter / 2.0 - 0.001 * pos[2] # rad = rad + 0.001 * self.icmd if type(toolPath.Curve ) is Part.Circle and toolPath.Curve.Radius <= rad: rad = toolPath.Curve.Radius - 0.01 * (pos[2] + 1) return (None, endPos) # create the path shell toolProf = self.CreateToolProfile(tool, startDir, pos, rad) rotmat = Base.Matrix() rotmat.move(pos.negative()) rotmat.rotateZ(math.pi) rotmat.move(pos) mirroredProf = toolProf.transformGeometry(rotmat) fullProf = Part.Wire([toolProf, mirroredProf]) pathWire = Part.Wire(toolPath) try: pathShell = pathWire.makePipeShell([fullProf], False, True) except: if self.debug: Part.show(pathWire) Part.show(fullProf) return (None, endPos) # create the start cup startCup = toolProf.revolve(pos, Vector(0, 0, 1), -180) # create the end cup endProf = self.CreateToolProfile(tool, endDir, endPos, rad) endCup = endProf.revolve(endPos, Vector(0, 0, 1), 180) fullShell = Part.makeShell(startCup.Faces + pathShell.Faces + endCup.Faces) return (Part.makeSolid(fullShell).removeSplitter(), endPos)
def GetPathSolidOld(self, tool, cmd, curpos): e1 = PathGeom.edgeForCmd(cmd, curpos) # curpos = e1.valueAt(e1.LastParameter) n1 = e1.tangentAt(0) n1[2] = 0.0 try: n1.normalize() except: return (None, e1.valueAt(e1.LastParameter)) height = self.height rad = tool.Diameter / 2.0 - 0.001 * curpos[ 2] # hack to overcome occ bug if type( e1.Curve ) is Part.Circle and e1.Curve.Radius <= rad: # hack to overcome occ bug rad = e1.Curve.Radius - 0.001 # return (None, e1.valueAt(e1.LastParameter)) xf = n1[0] * rad yf = n1[1] * rad xp = curpos[0] yp = curpos[1] zp = curpos[2] v1 = Vector(yf + xp, -xf + yp, zp) v2 = Vector(yf + xp, -xf + yp, zp + height) v3 = Vector(-yf + xp, xf + yp, zp + height) v4 = Vector(-yf + xp, xf + yp, zp) # vc1 = Vector(xf + xp, yf + yp, zp) # vc2 = Vector(xf + xp, yf + yp, zp + height) l1 = Part.makeLine(v1, v2) l2 = Part.makeLine(v2, v3) # l2 = Part.Edge(Part.Arc(v2, vc2, v3)) l3 = Part.makeLine(v3, v4) l4 = Part.makeLine(v4, v1) # l4 = Part.Edge(Part.Arc(v4, vc1, v1)) w1 = Part.Wire([l1, l2, l3, l4]) w2 = Part.Wire(e1) try: ex1 = w2.makePipeShell([w1], True, True) except: # Part.show(w1) # Part.show(w2) return (None, e1.valueAt(e1.LastParameter)) cyl1 = Part.makeCylinder(rad, height, curpos) curpos = e1.valueAt(e1.LastParameter) cyl2 = Part.makeCylinder(rad, height, curpos) ex1s = Part.Solid(ex1) f1 = ex1s.fuse([cyl1, cyl2]).removeSplitter() return (f1, curpos)
def GetPathSolid(self, tool, cmd, pos): toolPath = PathGeom.edgeForCmd(cmd, pos) # curpos = e1.valueAt(e1.LastParameter) startDir = toolPath.tangentAt(0) startDir[2] = 0.0 endPos = toolPath.valueAt(toolPath.LastParameter) endDir = toolPath.tangentAt(toolPath.LastParameter) try: startDir.normalize() endDir.normalize() except: return (None, endPos) # height = self.height # hack to overcome occ bugs rad = tool.Diameter / 2.0 - 0.001 * pos[2] # rad = rad + 0.001 * self.icmd if type(toolPath.Curve) is Part.Circle and toolPath.Curve.Radius <= rad: rad = toolPath.Curve.Radius - 0.01 * (pos[2] + 1) return (None, endPos) # create the path shell toolProf = self.CreateToolProfile(tool, startDir, pos, rad) rotmat = Base.Matrix() rotmat.move(pos.negative()) rotmat.rotateZ(math.pi) rotmat.move(pos) mirroredProf = toolProf.transformGeometry(rotmat) fullProf = Part.Wire([toolProf, mirroredProf]) pathWire = Part.Wire(toolPath) try: pathShell = pathWire.makePipeShell([fullProf], False, True) except: if self.debug: Part.show(pathWire) Part.show(fullProf) return (None, endPos) # create the start cup startCup = toolProf.revolve(pos, Vector(0, 0, 1), -180) # create the end cup endProf = self.CreateToolProfile(tool, endDir, endPos, rad) endCup = endProf.revolve(endPos, Vector(0, 0, 1), 180) fullShell = Part.makeShell(startCup.Faces + pathShell.Faces + endCup.Faces) return (Part.makeSolid(fullShell).removeSplitter(), endPos)
def GetPathSolidOld(self, tool, cmd, curpos): e1 = PathGeom.edgeForCmd(cmd, curpos) # curpos = e1.valueAt(e1.LastParameter) n1 = e1.tangentAt(0) n1[2] = 0.0 try: n1.normalize() except: return (None, e1.valueAt(e1.LastParameter)) height = self.height rad = tool.Diameter / 2.0 - 0.001 * curpos[2] # hack to overcome occ bug if type(e1.Curve) is Part.Circle and e1.Curve.Radius <= rad: # hack to overcome occ bug rad = e1.Curve.Radius - 0.001 # return (None, e1.valueAt(e1.LastParameter)) xf = n1[0] * rad yf = n1[1] * rad xp = curpos[0] yp = curpos[1] zp = curpos[2] v1 = Vector(yf + xp, -xf + yp, zp) v2 = Vector(yf + xp, -xf + yp, zp + height) v3 = Vector(-yf + xp, xf + yp, zp + height) v4 = Vector(-yf + xp, xf + yp, zp) # vc1 = Vector(xf + xp, yf + yp, zp) # vc2 = Vector(xf + xp, yf + yp, zp + height) l1 = Part.makeLine(v1, v2) l2 = Part.makeLine(v2, v3) # l2 = Part.Edge(Part.Arc(v2, vc2, v3)) l3 = Part.makeLine(v3, v4) l4 = Part.makeLine(v4, v1) # l4 = Part.Edge(Part.Arc(v4, vc1, v1)) w1 = Part.Wire([l1, l2, l3, l4]) w2 = Part.Wire(e1) try: ex1 = w2.makePipeShell([w1], True, True) except: # Part.show(w1) # Part.show(w2) return (None, e1.valueAt(e1.LastParameter)) cyl1 = Part.makeCylinder(rad, height, curpos) curpos = e1.valueAt(e1.LastParameter) cyl2 = Part.makeCylinder(rad, height, curpos) ex1s = Part.Solid(ex1) f1 = ex1s.fuse([cyl1, cyl2]).removeSplitter() return (f1, curpos)
def test10(self): """Verify proper geometry objects for G1 and G01 commands are created.""" spt = Vector(1,2,3) self.assertLine(PathGeom.edgeForCmd(Path.Command('G1', {'X': 7, 'Y': 2, 'Z': 3}), spt), spt, Vector(7, 2, 3)) self.assertLine(PathGeom.edgeForCmd(Path.Command('G01', {'X': 1, 'Y': 3, 'Z': 5}), spt), spt, Vector(1, 3, 5))
def RapidMove(self, cmd, curpos): path = PathGeom.edgeForCmd(cmd, curpos) # hack to overcome occ bug if path is None: return curpos return path.valueAt(path.LastParameter)