Exemplo n.º 1
0
	def saveDXF(self, filename):
		try:
			dxf = DXF(filename,"w")
		except:
			return False
		dxf.writeHeader()
		for block in self.blocks:
			name = block.name()
			for line in block:
				cmds = self.cnc.parseLine(line)
				if cmds is None: continue
				self.cnc.processPath(cmds)
				if self.cnc.gcode == 1:	# line
					dxf.line(self.cnc.x, self.cnc.y, self.cnc.xval, self.cnc.yval, name)
				elif self.cnc.gcode in (2,3):	# arc
					xc,yc,zc = self.cnc.motionCenter()
					sphi = math.atan2(self.cnc.y-yc,    self.cnc.x-xc)
					ephi = math.atan2(self.cnc.yval-yc, self.cnc.xval-xc)
					if self.cnc.gcode==2:
						if ephi<=sphi+1e-10: ephi += 2.0*math.pi
						dxf.arc(xc,yc,self.cnc.rval, math.degrees(ephi), math.degrees(sphi),name)
					else:
						if ephi<=sphi+1e-10: ephi += 2.0*math.pi
						dxf.arc(xc,yc,self.cnc.rval, math.degrees(sphi), math.degrees(ephi),name)
				self.cnc.motionPathEnd()
		dxf.writeEOF()
		dxf.close()
		return True
Exemplo n.º 2
0
	def loadDXF(self, filename):
		try:
			dxf = DXF(filename,"r")
		except:
			return False
		dxf.readFile()
		dxf.close()
		for name in dxf.layers.keys():
			layer = dxf.sortLayer(name)
			path = Path(name)
			path.fromLayer(layer)
			path.removeZeroLength()
			opath = path.order()
			changed = True
			while changed:
				longest = opath[0]
				for p in opath:
					if longest.length() > p.length():
						longest = p
				opath.remove(longest)
				changed = longest.mergeLoops(opath)
				self.fromPath(longest)
			self.fromPath(opath)
		return True
Exemplo n.º 3
0
        # generate a point on the curve
        for j in range(1, 4):
            jcount = j
            p[icount + j] = 0.0

            #  Do local matrix multiplication
            for i in range(1, npts + 1):
                p[icount + j] += nbasis[i] * b[jcount]
                jcount += 3
        icount += 3
        t += step


# =============================================================================
if __name__ == "__main__":
    SPLINE_SEGMENTS = 20
    from dxf import DXF
    #	from dxfwrite.algebra import CubicSpline, CubicBezierCurve
    dxf = DXF(sys.argv[1], "r")
    dxf.readFile()
    dxf.close()
    for name, layer in dxf.layers.items():
        for entity in layer.entities:
            if entity.type == "SPLINE":
                xy = zip(entity[10], entity[20])
                x, y = spline2Polyline(xy, int(entity[71]), True,
                                       SPLINE_SEGMENTS)
                #for a,b in zip(x,y):
                #	print a,b
Exemplo n.º 4
0
		# generate the basis function for this value of t
		rbasis(k,t,npts,x,h,nbasis)

		# generate a point on the curve
		for j in range(1,4):
			jcount = j
			p[icount+j] = 0.0

			#  Do local matrix multiplication
			for i in range(1,npts+1):
				p[icount+j] += nbasis[i]*b[jcount]
				jcount += 3
		icount += 3
		t += step

# =============================================================================
if __name__ == "__main__":
	SPLINE_SEGMENTS = 20
	from dxf import DXF
#	from dxfwrite.algebra import CubicSpline, CubicBezierCurve
	dxf = DXF(sys.argv[1],"r")
	dxf.readFile()
	dxf.close()
	for name,layer in dxf.layers.items():
		for entity in layer.entities:
			if entity.type == "SPLINE":
				xy = zip(entity[10], entity[20])
				x,y = spline2Polyline(xy, int(entity[71]), True, SPLINE_SEGMENTS)
				#for a,b in zip(x,y):
				#	print a,b