Changeset 1959

Show
Ignore:
Timestamp:
08/18/07 06:57:22 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- reimplemented lifeline lifetime's functionality using constraints; it is

more reliable, now

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/diagram/lifeline.py

    r1950 r1959  
    2525from gaphas.solver import STRONG 
    2626from gaphas.geometry import distance_line_point, Rectangle 
    27 from gaphas.constraint import EqualsConstraint, CenterConstraint 
     27from gaphas.constraint import LessThanConstraint, EqualsConstraint, CenterConstraint 
    2828 
    2929from gaphor import UML 
     
    4242    def __init__(self): 
    4343        super(LifetimeItem, self).__init__() 
    44         self._handles = [gaphas.Handle(strength=STRONG), gaphas.Handle(strength=STRONG)] 
     44        self._handles = [gaphas.Handle(strength=STRONG - 1), gaphas.Handle(strength=STRONG)] 
    4545 
    4646        self._handles[0].movable = False 
     
    4848        self._messages_count = 0 
    4949        self._is_destroyed = False 
     50 
     51        # create constraint to keep bottom handle below top handle 
     52        top, bottom = self._handles 
     53        self._c_length = LessThanConstraint(smaller=top.y, 
     54                bigger=bottom.y, 
     55                delta=LifetimeItem.MIN_LENGTH) 
     56 
    5057 
    5158    top = property(lambda s: s._handles[0]) 
     
    6572        return bottom.y - top.y > self.MIN_LENGTH 
    6673 
     74 
    6775    def pre_update(self, context): 
    68         top, bottom = self._handles 
    69  
    70         d = LifetimeItem.MIN_LENGTH 
    71  
    7276        # if lifetime is visible and there are messages connected, then 
    7377        # disallow hiding of lifetime 
    7478        if not self.is_visible() and self._messages_count > 0: 
    75             d *= 3 
    76         if bottom.y - top.y <= d
    77             bottom.y = top.y + d 
     79            self._c_length.delta = LifetimeItem.MIN_LENGTH * 3  
     80        elif self._messages_count == 0
     81            self._c_length.delta = LifetimeItem.MIN_LENGTH 
    7882 
    79     def post_update(self, context): 
    80         pass 
    8183 
    8284    def draw(self, context): 
     
    125127            EqualsConstraint(top.x, bottom.x), 
    126128            EqualsConstraint(self._handles[SW].y, top.y), 
     129            self._lifetime._c_length, 
    127130        ] 
    128131        self._constraints.extend(constraints) 
     
    151154 
    152155 
    153     def post_update(self, context): 
    154         super(LifelineItem, self).post_update(context) 
    155         #self._lifetime.post_update(context) 
    156  
    157  
    158156    def draw(self, context): 
    159157        super(LifelineItem, self).draw(context)