Changeset 1656
- Timestamp:
- 07/17/07 12:45:00 (1 year ago)
- Files:
-
- gaphas/branches/hw/gaphas/canvas.py (modified) (10 diffs)
- gaphas/branches/hw/gaphas/item.py (modified) (2 diffs)
- gaphas/branches/hw/gaphas/view.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphas/branches/hw/gaphas/canvas.py
r1652 r1656 6 6 __version__ = "$Revision$" 7 7 # $HeadURL$ 8 9 from weakref import WeakKeyDictionary10 8 11 9 import cairo … … 38 36 39 37 40 class ViewBucket(object):41 __slots__ = ('matrix_v2i', 'matrix_i2v', 'handles')42 def __init__(self):43 self.matrix_v2i = None44 self.matrix_i2v = None45 self.handles = []46 47 48 class CanvasBucket(object):49 __slots__ = ('matrix_c2i', 'matrix_i2c', 'view', 'handles')50 def __init__(self):51 self.matrix_c2i = None52 self.matrix_i2c = None53 self.view = {}54 self.handles = []55 56 57 58 38 class Canvas(object): 59 39 """ … … 63 43 - projector: canvas constraint projector between item and canvas 64 44 coordinates 65 - _cache: additional cache of item data66 45 - _canvas_constraints: constraints set between canvas items 67 46 """ … … 74 53 75 54 self._registered_views = set() 76 self._ca che = WeakKeyDictionary()55 self._canvas_constraints = {} 77 56 78 57 self.projector = CanvasProjector(self) 79 80 self._canvas_constraints = {}81 58 82 59 solver = property(lambda s: s._solver) … … 99 76 item.canvas = self 100 77 self._tree.add(item, parent) 101 self._cache[item] = CanvasBucket()102 78 self._canvas_constraints[item] = {} 103 79 104 80 for v in self._registered_views: 105 self._cache[item].view[v] = ViewBucket()106 81 v.update_matrix(item) 107 82 … … 374 349 yet. Note that out-of-date matrices are not recalculated. 375 350 """ 376 data = self._cache[item] 377 if data.matrix_i2c is None or calculate: 351 if item._matrix_i2c is None or calculate: 378 352 self.update_matrix(item, recursive=False) 379 return data.matrix_i2c353 return item._matrix_i2c 380 354 381 355 … … 385 359 See get_matrix_i2w(). 386 360 """ 387 data = self._cache[item] 388 if data.matrix_c2i is None or calculate: 361 if item._matrix_c2i is None or calculate: 389 362 self.update_matrix(item, recursive=False) 390 return data.matrix_c2i363 return item._matrix_c2i 391 364 392 365 … … 549 522 self._dirty_matrix_items.discard(item) 550 523 551 data = self._cache[item]552 524 if parent: 553 525 if parent in self._dirty_matrix_items: … … 556 528 return 557 529 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) 560 532 else: 561 data.matrix_i2c = Matrix(*item.matrix)533 item._matrix_i2c = Matrix(*item.matrix) 562 534 563 535 # 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() 566 538 for v in self._registered_views: 567 539 v.update_matrix(item) … … 626 598 self._registered_views.add(view) 627 599 for item in self.get_all_items(): 628 data = ViewBucket()629 self._cache[item].view[view] = data630 600 view.update_matrix(item) 631 601 gaphas/branches/hw/gaphas/item.py
r1650 r1656 117 117 118 118 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 122 127 """ 123 128 … … 127 132 self._handles = [] 128 133 self._constraints = [] 134 135 self._matrix_i2c = None 136 self._matrix_2ci = None 137 self._matrix_i2v = {} 138 self._matrix_v2i = {} 139 129 140 130 141 @observed gaphas/branches/hw/gaphas/view.py
r1626 r1656 291 291 area=None)) 292 292 293 293 294 def get_matrix_i2v(self, item): 294 return self._canvas._cache[item].view[self].matrix_i2v 295 return item._matrix_i2v[self] 296 295 297 296 298 def get_matrix_v2i(self, item): 297 return self._canvas._cache[item].view[self].matrix_v2i299 return item._matrix_v2i[self] 298 300 299 301 … … 302 304 Update item matrices related to view. 303 305 """ 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() 308 309 309 310
