def _build_polyline(self): """ build the rectangle with a polyline """ polyline = Polyline(self.points, color=self.color, layer=self.layer) polyline.close() if self.linetype is not None: polyline['linetype'] = self.linetype return polyline
def _build_curve(self): def curve_point(alpha): alpha = radians(alpha) point = (cos(alpha) * self.rx, sin(alpha) * self.ry) point = rotate_2d(point, radians(self.rotation)) x, y = vadd(self.center, point) return (x, y, zaxis) def normalize_angle(angle): angle = fmod(angle, 360.0) if angle < 0: angle += 360.0 return angle zaxis = 0.0 if len(self.center) < 3 else self.center[2] points = [] delta = (self.endangle - self.startangle) / self.segments for segment in xrange(self.segments): alpha = self.startangle + delta * segment points.append(curve_point(alpha)) polyline = Polyline(points, color=self.color, layer=self.layer, linetype=self.linetype) if equals_almost(self.startangle, normalize_angle(self.endangle)): polyline.close() return polyline
def __dxftags__(self): spline = CubicSpline(self.points) polyline = Polyline(spline.approximate(self.segments), layer = self.layer, color=self.color, linetype = self.linetype) return polyline.__dxftags__()
def __dxftags__(self): def curve_point(alpha): alpha = radians(alpha) point = (cos(alpha) * self.rx, sin(alpha) * self.ry) point = rotate_2d(point, radians(self.rotation)) x, y = vadd(self.center, point) return (x, y, zaxis) def normalize_angle(angle): angle = fmod(angle, 360.) if angle < 0: angle += 360. return angle zaxis = 0. if len(self.center) < 3 else self.center[2] points = [] delta = (self.endangle - self.startangle) / self.segments for segment in xrange(self.segments): alpha = self.startangle + delta * segment points.append(curve_point(alpha)) polyline = Polyline(points, color=self.color, layer=self.layer, linetype=self.linetype) if equals_almost(self.startangle, normalize_angle(self.endangle)): polyline.close() return polyline.__dxftags__()
def __dxftags__(self): polyline = Polyline(layer=self.layer, color=self.color, linetype=self.linetype) for segment in self._build_bezier_segments(): points = segment.approximate() polyline.add_vertices(points) return polyline.__dxftags__()
def __dxftags__(self): spline = CubicSpline(self.points) polyline = Polyline(spline.approximate(self.segments), layer=self.layer, color=self.color, linetype=self.linetype) return polyline.__dxftags__()
def _build_polyline(self): '''Build the polyline (key component)''' polyline = Polyline(self.transformed_points, color=self.color, layer=self.layer, flags=0) polyline.close() #redundant in most cases if self.linetype is not None: polyline['linetype'] = self.linetype return polyline
def test_polyline(self): polyline = Polyline() polyline.add_vertex( (0, 0) ) vt1 = " 0\nVERTEX\n 8\n0\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" polyline.add_vertex( (1, 1) ) vt2 = " 0\nVERTEX\n 8\n0\n 10\n1.0\n 20\n1.0\n 30\n0.0\n" expected = " 0\nPOLYLINE\n 8\n0\n 66\n1\n 10\n0.0\n 20\n0.0\n 30\n0.0\n" \ " 70\n8\n" + vt1 + vt2 + " 0\nSEQEND\n" self.assertEqual(dxfstr(polyline), expected)
def __dxftags__(self): def transform(points): for point in points: if self.mirrorx: point = (point[0], -point[1]) if self.mirrory: point = (-point[0], point[1]) point = rotate_2d(point, rotation) x, y = vadd(self.start, point) yield (x, y, zaxis) zaxis = 0. if len(self.start) < 3 else self.start[2] rotation = radians(self.rotation) clothoid = _ClothoidValues(self.paramA) points = clothoid.approximate(self.length, self.segments) return Polyline(transform(points), color=self.color, layer=self.layer, linetype=self.linetype).__dxftags__()
def polyline(points=[], **kwargs): """ Create a new polyline entity. Polymesh and polyface are also polylines. :param points: list of points, 2D or 3D points, z-value of 2D points is 0. :param polyline_elevation: polyline elevation (xyz-tuple), z-axis supplies elevation, x- and y-axis has to be 0.) :param int flags: polyline flags, bit-coded, default=0 :param float startwidth: default starting width, default=0 :param float endwidth: default ending width, default=0 :param int mcount: polygon mesh M vertex count, default=0 :param int ncount: polygon mesh N vertex count, default=0 :param int msmooth_density: (if flags-bit POLYLINE_3D_POLYMESH is set) smooth surface M density, default=0 :param int nsmooth_density: (if flags-bit POLYLINE_3D_POLYMESH is set) smooth surface N density, default=0 same values as msmooth_density :param int smooth_surface: curves and smooth surface type, default=0 ??? see dxf-documentation """ return Polyline(points, **kwargs)
def to_dxf(self, split=False, **attr): """ :param split: bool if True, each segment in Chain is saved separately :param attr: dict of graphic attributes :return: polyline or list of entities along the chain """ if split: #handle polylines as separate entities return super(Chain, self).to_dxf(**attr) if len(self) == 1: return self[0].to_dxf(**attr) #if no color specified assume chain color is the same as the first element's color = attr.get('color', self.color) attr['color'] = color_to_aci(color) try: attr.setdefault('layer', self.layer) except: pass #no layer defined from dxfwrite.entities import Polyline attr['flags'] = 1 if self.isclosed() else 0 res = Polyline(**attr) for e in self: if isinstance(e, Line2): res.add_vertex(e.start.xy) elif isinstance(e, Arc2): bulge = tan(e.angle() / 4) res.add_vertex(e.start.xy, bulge=bulge) else: if attr.pop('R12', True): #R12 doesn't handle splines. attr['color'] = color #otherwise it causes trouble del attr['flags'] return super(Chain, self).to_dxf(**attr) if not self.isclosed(): res.add_vertex(self.end.xy) return res
def to_dxf(self, split=False, **attr): """ :param split: bool if True, each segment in Chain is saved separately :param attr: dict of graphic attributes :return: polyline or list of entities along the chain """ if split: # handle polylines as separate entities return super(Chain, self).to_dxf(**attr) if len(self) == 1: return self[0].to_dxf(**attr) # if no color specified assume chain color is the same as the first element's color = attr.get('color', self.color) attr['color'] = color_to_aci(color) try: attr.setdefault('layer', self.layer) except: pass # no layer defined from dxfwrite.entities import Polyline attr['flags'] = 1 if self.isclosed() else 0 res = Polyline(**attr) for e in self: if isinstance(e, Line2): res.add_vertex(e.start.xy) elif isinstance(e, Arc2): bulge = tan(e.angle() / 4) res.add_vertex(e.start.xy, bulge=bulge) else: if attr.pop('R12', True): # R12 doesn't handle splines. attr['color'] = color # otherwise it causes trouble del attr['flags'] return super(Chain, self).to_dxf(**attr) if not self.isclosed(): res.add_vertex(self.end.xy) return res
def to_dxf(self, split=False, **attr): """:return: polyline or list of entities along the chain""" if split: #handle polylines as separate entities return super(Chain,self).to_dxf(**attr) #assume chain color is the same as the first element's color=self[0]._dxf_color() from dxfwrite.entities import Polyline flags=1 if self.isclosed() else 0 res=Polyline(color=color, flags=flags, **attr) for e in self: if isinstance(e,Line2): res.add_vertex(e.start.xy) elif isinstance(e, Arc2): bulge=tan(e.angle()/4) res.add_vertex(e.start.xy,bulge=bulge) else: #we have a Spline in the chain. Split it for now return super(Chain,self).to_dxf(**attr) if not self.isclosed(): res.add_vertex(self.end.xy) return res
def test_invalid_polyline(self): polyline = Polyline() self.assertFalse(polyline.valid())