Changeset 1656

Show
Ignore:
Timestamp:
07/17/07 12:45:00 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- killed {Canvas,View}Bucket classes and canvas cache as agreed

and created i2c/c2i/i2v/v2i matrices on Item class level

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphas/branches/hw/gaphas/canvas.py

    r1652 r1656  
    66__version__ = "$Revision$" 
    77# $HeadURL$ 
    8  
    9 from weakref import WeakKeyDictionary 
    108 
    119import cairo 
     
    3836 
    3937 
    40 class ViewBucket(object): 
    41     __slots__ = ('matrix_v2i', 'matrix_i2v', 'handles') 
    42     def __init__(self): 
    43         self.matrix_v2i = None 
    44         self.matrix_i2v = None 
    45         self.handles = [] 
    46  
    47  
    48 class CanvasBucket(object): 
    49     __slots__ = ('matrix_c2i', 'matrix_i2c', 'view', 'handles') 
    50     def __init__(self): 
    51         self.matrix_c2i = None 
    52         self.matrix_i2c = None 
    53         self.view = {} 
    54         self.handles = [] 
    55  
    56  
    57  
    5838class Canvas(object): 
    5939    """ 
     
    6343     - projector: canvas constraint projector between item and canvas 
    6444       coordinates 
    65      - _cache: additional cache of item data 
    6645     - _canvas_constraints: constraints set between canvas items 
    6746    """ 
     
    7453 
    7554        self._registered_views = set() 
    76         self._cache = WeakKeyDictionary() 
     55        self._canvas_constraints = {} 
    7756 
    7857        self.projector = CanvasProjector(self) 
    79  
    80         self._canvas_constraints = {} 
    8158 
    8259    solver = property(lambda s: s._solver) 
     
    9976        item.canvas = self 
    10077        self._tree.add(item, parent) 
    101         self._cache[item] = CanvasBucket() 
    10278        self._canvas_constraints[item] = {} 
    10379 
    10480        for v in self._registered_views: 
    105             self._cache[item].view[v] = ViewBucket() 
    10681            v.update_matrix(item) 
    10782 
     
    374349              yet. Note that out-of-date matrices are not recalculated. 
    375350        """ 
    376         data = self._cache[item] 
    377         if data.matrix_i2c is None or calculate: 
     351        if item._matrix_i2c is None or calculate: 
    378352            self.update_matrix(item, recursive=False) 
    379         return data.matrix_i2c 
     353        return item._matrix_i2c 
    380354 
    381355 
     
    385359        See get_matrix_i2w(). 
    386360        """ 
    387         data = self._cache[item] 
    388         if data.matrix_c2i is None or calculate: 
     361        if item._matrix_c2i is None or calculate: 
    389362            self.update_matrix(item, recursive=False) 
    390         return data.matrix_c2i 
     363        return item._matrix_c2i 
    391364 
    392365 
     
    549522        self._dirty_matrix_items.discard(item) 
    550523 
    551         data = self._cache[item] 
    552524        if parent: 
    553525            if parent in self._dirty_matrix_items: 
     
    556528                return 
    557529            else: 
    558                 data.matrix_i2c = Matrix(*item.matrix) 
    559                 data.matrix_i2c *= self.get_matrix_i2c(parent) 
     530                item._matrix_i2c = Matrix(*item.matrix) 
     531                item._matrix_i2c *= self.get_matrix_i2c(parent) 
    560532        else: 
    561             data.matrix_i2c = Matrix(*item.matrix) 
     533            item._matrix_i2c = Matrix(*item.matrix) 
    562534 
    563535        # It's nice to have the W2I matrix present too: 
    564         data.matrix_c2i = Matrix(*data.matrix_i2c) 
    565         data.matrix_c2i.invert() 
     536        item._matrix_c2i = Matrix(*item._matrix_i2c) 
     537        item._matrix_c2i.invert() 
    566538        for v in self._registered_views: 
    567539            v.update_matrix(item) 
     
    626598        self._registered_views.add(view) 
    627599        for item in self.get_all_items(): 
    628             data = ViewBucket() 
    629             self._cache[item].view[view] = data 
    630600            view.update_matrix(item) 
    631601 
  • gaphas/branches/hw/gaphas/item.py

    r1650 r1656  
    117117 
    118118    Attributes: 
    119      - _canvas:  canvas, which owns an item 
    120      - _handles: list of handles owned by an item 
    121      - _matrix:  item's transformation matrix 
     119     - _canvas:      canvas, which owns an item 
     120     - _handles:     list of handles owned by an item 
     121     - _constraints: item's constraints 
     122     - matrix:       item's transformation matrix 
     123     - _matrix_i2c:  item to canvas coordinates matrix 
     124     - _matrix_c2i:  canvas to item coordinates matrix 
     125     - _matrix_i2v:  item to view coordinates matrices 
     126     - _matrix_v2i:  view to item coordinates matrices 
    122127    """ 
    123128 
     
    127132        self._handles = [] 
    128133        self._constraints = [] 
     134 
     135        self._matrix_i2c = None 
     136        self._matrix_2ci = None 
     137        self._matrix_i2v = {} 
     138        self._matrix_v2i = {} 
     139 
    129140 
    130141    @observed 
  • gaphas/branches/hw/gaphas/view.py

    r1626 r1656  
    291291                                    area=None)) 
    292292 
     293 
    293294    def get_matrix_i2v(self, item): 
    294         return self._canvas._cache[item].view[self].matrix_i2v 
     295        return item._matrix_i2v[self] 
     296 
    295297 
    296298    def get_matrix_v2i(self, item): 
    297         return self._canvas._cache[item].view[self].matrix_v2i 
     299        return item._matrix_v2i[self] 
    298300 
    299301 
     
    302304        Update item matrices related to view. 
    303305        """ 
    304         v = self._canvas._cache[item].view[self] 
    305         v.matrix_i2v = self._canvas.get_matrix_i2c(item) * self._matrix 
    306         v.matrix_v2i = Matrix(*v.matrix_i2v) 
    307         v.matrix_v2i.invert() 
     306        i2v = item._matrix_i2v[self] = self._canvas.get_matrix_i2c(item) * self._matrix 
     307        v2i = item._matrix_v2i[self] = Matrix(*i2v) 
     308        v2i.invert() 
    308309 
    309310