CMS 3D CMS Logo

Public Member Functions | Public Attributes

svgfig::Fig Class Reference

List of all members.

Public Member Functions

def __init__
def __repr__
def SVG

Public Attributes

 d
 trans

Detailed Description

Stores graphics primitive objects and applies a single coordinate
transformation to them. To compose coordinate systems, nest Fig
objects.

Fig(obj, obj, obj..., trans=function)

obj     optional list    a list of drawing primatives
trans   default=None     a coordinate transformation function

>>> fig = Fig(Line(0,0,1,1), Rect(0.2,0.2,0.8,0.8), trans="2*x, 2*y")
>>> print fig.SVG().xml()
<g>
    <path d='M0 0L2 2' />
    <path d='M0.4 0.4L1.6 0.4ZL1.6 1.6ZL0.4 1.6ZL0.4 0.4ZZ' />
</g>
>>> print Fig(fig, trans="x/2., y/2.").SVG().xml()
<g>
    <path d='M0 0L1 1' />
    <path d='M0.2 0.2L0.8 0.2ZL0.8 0.8ZL0.2 0.8ZL0.2 0.2ZZ' />
</g>

Definition at line 710 of file svgfig.py.


Constructor & Destructor Documentation

def svgfig::Fig::__init__ (   self,
  d,
  kwds 
)

Definition at line 741 of file svgfig.py.

00742                                 :
00743     self.d = list(d)
00744     defaults = {"trans":None}
00745     defaults.update(kwds)
00746     kwds = defaults
00747 
00748     self.trans = kwds["trans"]; del kwds["trans"]
00749     if len(kwds) != 0:
00750       raise TypeError, "Fig() got unexpected keyword arguments %s" % kwds.keys()


Member Function Documentation

def svgfig::Fig::__repr__ (   self)

Definition at line 733 of file svgfig.py.

00734                     :
00735     if self.trans == None:
00736       return "<Fig (%d items)>" % len(self.d)
00737     elif isinstance(self.trans, basestring):
00738       return "<Fig (%d items) x,y -> %s>" % (len(self.d), self.trans)
00739     else:
00740       return "<Fig (%d items) %s>" % (len(self.d), self.trans.func_name)

def svgfig::Fig::SVG (   self,
  trans = None 
)
Apply the transformation "trans" and return an SVG object.

Coordinate transformations in nested Figs will be composed.

Definition at line 751 of file svgfig.py.

00752                            :
00753     """Apply the transformation "trans" and return an SVG object.
00754 
00755     Coordinate transformations in nested Figs will be composed.
00756     """
00757 
00758     if trans == None: trans = self.trans
00759     if isinstance(trans, basestring): trans = totrans(trans)
00760 
00761     output = SVG("g")
00762     for s in self.d:
00763       if isinstance(s, SVG):
00764         output.append(s)
00765 
00766       elif isinstance(s, Fig):
00767         strans = s.trans
00768         if isinstance(strans, basestring): strans = totrans(strans)
00769 
00770         if trans == None: subtrans = strans
00771         elif strans == None: subtrans = trans
00772         else: subtrans = lambda x,y: trans(*strans(x, y))
00773 
00774         output.sub += s.SVG(subtrans).sub
00775 
00776       elif s == None: pass
00777 
00778       else:
00779         output.append(s.SVG(trans))
00780 
00781     return output


Member Data Documentation

Definition at line 741 of file svgfig.py.

Definition at line 733 of file svgfig.py.