Beispiel #1
0
 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)
Beispiel #2
0
    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
Beispiel #3
0
    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
Beispiel #4
0
 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