From 15910ddb9b24a65b82d716a6a6a92686cb5c3f21 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Wed, 1 Dec 2010 02:07:57 +0100 Subject: [PATCH] pyMML: Add base for DTM bindings. --- Projects/libmml/pymml/mmldtm.py | 34 ++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/Projects/libmml/pymml/mmldtm.py b/Projects/libmml/pymml/mmldtm.py index c68bf1b..6d820ce 100755 --- a/Projects/libmml/pymml/mmldtm.py +++ b/Projects/libmml/pymml/mmldtm.py @@ -1,20 +1,43 @@ from ctypes import * from mmltypes import RESULT_OK, RESULT_FALSE, RESULT_ERROR -# TODO: -# Load from user defined points. (So called dynamic) +# There are several problems with DTM and libMML. +# We could create them in the libMML DTM manager, but we'll have to keep track +# of the DTMs; and if Python garbage collector deletes then, we could try to use +# __del__ to clear it from the DTM Manager. +# +# Or we could go for a bit of overhead and create the DTM every time we want to +# 'find' it. +# TMDTMPoint Structure +class _DTMPoint(Structure): + _fields_ = [('x', c_int), ('y', c_int), ('c', c_int), ('t', c_int), \ + ('asz', c_int), ('bp', c_int)] + +class DTMPoint(object): + def __init__(self, x, y, c, t, asz, bp): + self.x, self.y, self.c, self.t, self.asz, self.bp = x, y, c, t, asz, bp + +class DTMException(Exception): + pass class DTM(object): - def __init__(self): - pass + def __init__(self, points): + if type(points) not in [list, tuple]: + raise DTMException('points is not a list or tuple') + for i in points: + if type(i) is not DTMPoint: + raise DTMException('Each point in points should be a DTMPoint') + + self.points = points + self.name = 'Unnamed DTM' def __del__(self): pass def __repr__(self): - pass + return '' % self.name def to_str(self): pass @@ -26,6 +49,7 @@ class DTM(object): pass def set_name(self): + self.name = name pass