Source code for Feature

# Feature.py
# By MW, Jul 2013
# GPLv3+
#
# Feature classes
#+In the end, should it use TimeTrack classes?

import logging

[docs]class Feature : """A generic class to define a feature""" def __init__(self, name, sh_name, color, descr, model=None) : self.typ = 'feature' self.name = name self.short_name = sh_name self.color = color self.descr = descr self.model = model
[docs] def get_save_dict(self) : dic = {} dic['typ'] = {'descr' : 'Type of the feature', 'value' : self.typ} dic['name'] = {'descr' : 'Name of the feature', 'value' : self.name} dic['short_name'] = {'descr' : 'Short name of the feature', 'value' : self.short_name} dic['color'] = {'descr' : 'Color', 'value' : self.color} dic['descr'] = {'descr' : 'Description of the feature', 'value' : self.descr} # TYPO FIXED IN V6 dic['model'] = {'descr' : 'Model associated with the feature', 'value' : self.model} return {'descr' : 'Class describing a feature', 'value' : dic}
[docs] def load_save_dict(self, dic) : self.typ = dic['typ']['value'] self.name = dic['name']['value'] self.short_name = dic['short_name']['value'] self.color = dic['color']['value'] self.descr = dic['descr']['value'] # TYPO FIXED IN V6 self.model = dic['model']['value']
[docs] def get_color(self) : return self.color
[docs] def get_name(self) : return self.name
[docs] def get_short_name(self) : return self.short_name
[docs] def get_type(self) : return self.typ
[docs]class Point(Feature) : def __init__(self, name, sh_name, color, descr, model=None) : Feature.__init__(self, name, sh_name, color, descr, model) self.typ = 'point' self.point = None
[docs] def get_point(self) : return self.point
[docs] def set_point(self, frame) : """frame should be an integer""" logging.info("Setting point at frame %s", frame) print "point", frame self.point = frame
[docs] def get_save_dict(self) : dic = Feature.get_save_dict(self) dic['value']['point'] = {'descr' : 'frame where the feature applies', 'value' : self.point} return dic
[docs] def load_save_dict(self, dic) : Feature.load_save_dict(self, dic) self.set_point(dic['point']['value'])
[docs]class Multipoint(Feature) : """Should multipoint inherit from Point rather than Feature?""" def __init__(self, name, sh_name, color, descr, model=None) : Feature.__init__(self, name, sh_name, color, descr, model) self.typ = 'multipoint'
[docs]class Segment(Feature) : def __init__(self, name, sh_name, color, descr, model=None) : Feature.__init__(self, name, sh_name, color, descr, model) self.typ = 'segment' self.segment = (None, None)
[docs] def get_segment(self) : return self.segment
[docs] def set_segment(self, seg) : """A segment is a tuple (begin_frame, end_frame)""" self.segment = seg
[docs] def get_save_dict(self) : dic = Feature.get_save_dict(self) dic['value']['segment'] = {'descr' : 'frames where the feature applies', 'value' : self.segment} return dic
[docs] def load_save_dict(self, dic) : Feature.load_save_dict(self, dic) #self.segment = dic['segment']['value'] self.set_segment(dic['segment']['value'])
[docs]class Cell(Segment) : """Class to represent a Cell object""" def __init__(self, name, sh_name, color, descr, model=None) : Segment.__init__(self, name, sh_name, color, descr, model) self.typ = 'cell'
[docs] def set_cell(self, c) : self.cell = c self.update()
[docs] def update(self) : self.segment = self.cell.get_bounds() #def get_save_dict(self) : # dic = Feature.__init__(self) # dic['value']['cell'] = {'descr' : 'cell', 'value' : self.cell}
[docs]class Multisegment(Feature) : def __init__(self, name, sh_name, color, descr, model=None) : Feature.__init__(self, name, sh_name, color, descr, model) self.typ = 'multisegment'