Annotation of python/pyvtk/lib/Data.py, revision 1.2

1.1       pearu       1: #!/usr/bin/env python
                      2: """
1.2     ! pearu       3: PointData, CellData
        !             4: """
        !             5: """
1.1       pearu       6: 
                      7: Copyright 2001 Pearu Peterson all rights reserved,
                      8: Pearu Peterson <pearu@ioc.ee>          
                      9: Permission to use, modify, and distribute this software is given under the
                     10: terms of the LGPL.  See http://www.fsf.org
                     11: 
                     12: NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
1.2     ! pearu      13: $Revision: 1.1 $
        !            14: $Date: 2001/05/19 22:21:49 $
1.1       pearu      15: Pearu Peterson
                     16: """
                     17: 
1.2     ! pearu      18: __version__ = "$Id: Data.py,v 1.1 2001/05/19 22:21:49 pearu Exp $"
1.1       pearu      19: 
                     20: 
                     21: import common
                     22: 
                     23: class Data(common.Common):
                     24:     data_type = None
                     25:     def __init__(self,*args):
                     26:         if self.__class__.__name__ not in ['PointData','CellData']:
                     27:             raise TypeError,'use PointData or CellData instead of Data'
1.2     ! pearu      28:         self.data = []
        !            29:         self.length = None
        !            30:         map(self.append,args)
        !            31:     def append(self,obj):
        !            32:         if not common.is_datasetattr(obj):
        !            33:             self.error('expected DataSetAttr argument but got %s'%(type(obj)))
        !            34:             raise TypeError
        !            35:         if self.length is None:
        !            36:             self.length = obj.get_size()
        !            37:         if self.length != obj.get_size():
        !            38:             self.error('attribute data %s must be of length %s (as defined by first DataSetAttr) but got %s'%(`obj.__class__.__name__`,self.length,obj.get_size()))
        !            39:             raise ValueError
        !            40:         self.data.append(obj)
1.1       pearu      41:     def get_size(self):
                     42:         return self.length
                     43:     def to_string(self,format='ascii'):
                     44:         if self.data_type is None:
                     45:             raise TypeError,'use PointData or CellData instead of Data'
                     46:         ret = ['%s %s'%(self.data_type,self.length)]
                     47:         ret += [a.to_string(format) for a in self.data]
                     48:         return '\n'.join(ret)
                     49: 
                     50: class PointData(Data):
1.2     ! pearu      51:     """
        !            52:     Usage:
        !            53:       PointData(<DataSetAttr instances>)
        !            54:     Attributes:
        !            55:       data - list of DataSetAttr instances
        !            56:     Public methods:
        !            57:       get_size()
        !            58:       to_string(format = 'ascii')
        !            59:       append(<DataSetAttr instance>)
        !            60:     """
1.1       pearu      61:     data_type = 'POINT_DATA'
                     62: 
                     63: class CellData(Data):
1.2     ! pearu      64:     """
        !            65:     Usage:
        !            66:       CellData(<DataSetAttr instances>)
        !            67:     Attributes:
        !            68:       data - list of DataSetAttr instances
        !            69:     Public methods:
        !            70:       get_size()
        !            71:       to_string(format = 'ascii')
        !            72:       append(<DataSetAttr instance>)
        !            73:     """
1.1       pearu      74:     data_type = 'CELL_DATA'
1.2     ! pearu      75: 
        !            76: 
1.1       pearu      77: 
                     78: if __name__ == "__main__":
                     79:     import Scalars
                     80:     print PointData(Scalars.Scalars([2,3]))

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>