コード例 #1
0
    def convert2Polyline(self, splineSegs):
        """Convert complex objects (SPLINE,ELLIPSE) to polylines"""
        if self.type == "SPLINE":
            # Convert to polyline
            xyz = zip(self[10], self[20], self[30])
            flag = int(self.get(70, 0))
            closed = bool(flag & Entity.CLOSED)
            periodic = bool(flag & Entity.PERIODIC)
            rational = bool(flag & Entity.RATIONAL)
            planar = bool(flag & Entity.PLANAR)
            linear = bool(flag & Entity.LINEAR)
            #			print "\nSPLINE"
            #			print "closed=",closed
            #			print "periodic=",periodic
            #			print "rational=",rational
            #			print "planar=",planar
            #			print "linear=",linear
            #			for n in sorted(self.keys()): print n,"=",self[n]
            knots = self[40]
            xx, yy, zz = spline.spline2Polyline(xyz, int(self[71]), closed,
                                                splineSegs, knots)
            self[10] = xx
            self[20] = yy
            self[30] = zz
            self[42] = 0  # bulge FIXME maybe I should use it
            self.type = "LWPOLYLINE"

        elif self.type == "ELLIPSE":
            center = self.start()
            major = self.point(1)
            ratio = self.get(40, 1.0)
            sPhi = self.get(41, 0.0)
            ePhi = self.get(42, 2.0 * math.pi)

            # minor length
            major_length = major.normalize()
            minor_length = ratio * major_length

            xx = []
            yy = []
            if ePhi < sPhi: ePhi += 2.0 * math.pi
            nseg = int((ePhi - sPhi) / math.pi * Entity.ELLIPSE_SEGMENTS)
            dphi = (ePhi - sPhi) / float(nseg)
            phi = sPhi
            for i in range(nseg + 1):
                vx = major_length * math.cos(phi)
                vy = minor_length * math.sin(phi)
                xx.append(vx * major[0] - vy * major[1] + center[0])
                yy.append(vx * major[1] + vy * major[0] + center[1])
                phi += dphi
            self[10] = xx
            self[20] = yy
            self[42] = 0  # bulge FIXME maybe I should use it
            self.type = "LWPOLYLINE"
        self._initCache()
コード例 #2
0
ファイル: dxf.py プロジェクト: moacirbmn/bCNC
	def convert2Polyline(self, splineSegs):
		"""Convert complex objects (SPLINE,ELLIPSE) to polylines"""
		if self.type == "SPLINE":
			# Convert to polyline
			xyz  = zip(self[10], self[20], self[30])
			flag = int(self.get(70,0))
			closed   = bool(flag & Entity.CLOSED)
			periodic = bool(flag & Entity.PERIODIC)
			rational = bool(flag & Entity.RATIONAL)
			planar   = bool(flag & Entity.PLANAR)
			linear   = bool(flag & Entity.LINEAR)
#			print "\nSPLINE"
#			print "closed=",closed
#			print "periodic=",periodic
#			print "rational=",rational
#			print "planar=",planar
#			print "linear=",linear
#			for n in sorted(self.keys()): print n,"=",self[n]
			knots = self[40]
			xx,yy,zz = spline.spline2Polyline(xyz, int(self[71]),
					closed, splineSegs, knots)
			self[10] = xx
			self[20] = yy
			self[30] = zz
			self[42] = 0	# bulge FIXME maybe I should use it
			self.type = "LWPOLYLINE"

		elif self.type == "ELLIPSE":
			center = self.start()
			major  = self.point(1)
			ratio  = self.get(40,1.0)
			sPhi   = self.get(41,0.0)
			ePhi   = self.get(42,2.0*math.pi)

			# minor length
			major_length = major.normalize()
			minor_length = ratio*major_length

			xx = []
			yy = []
			if ePhi < sPhi: ePhi += 2.0*math.pi
			nseg = int((ePhi-sPhi) / math.pi * Entity.ELLIPSE_SEGMENTS)
			dphi = (ePhi-sPhi)/float(nseg)
			phi = sPhi
			for i in range(nseg+1):
				vx = major_length*math.cos(phi)
				vy = minor_length*math.sin(phi)
				xx.append(vx*major[0] - vy*major[1] + center[0])
				yy.append(vx*major[1] + vy*major[0] + center[1])
				phi += dphi
			self[10] = xx
			self[20] = yy
			self[42] = 0	# bulge FIXME maybe I should use it
			self.type = "LWPOLYLINE"
		self._initCache()