Changeset 1575

Show
Ignore:
Timestamp:
07/05/07 01:57:49 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- try to implement fork/join node item as an item with two handles

Files:

Legend:

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

    r1571 r1575  
    55import math 
    66 
    7 from gaphas.util import path_ellipse, text_align 
     7from gaphas.util import path_ellipse 
    88from gaphas.state import observed, reversible_property 
    9 from gaphas.item import NW, SE, NE, SW, Handle 
    10 from gaphas.solver import Variable, STRONG 
     9from gaphas.item import Handle, Item 
    1110from gaphas.constraint import EqualsConstraint, LessThanConstraint 
    1211 
    1312from gaphor import UML 
    1413from gaphor.core import inject 
     14from gaphor.diagram.diagramitem import DiagramItem 
    1515from gaphor.diagram.nameditem import NamedItem 
    1616from gaphor.diagram.style import ALIGN_LEFT, ALIGN_CENTER, ALIGN_TOP, \ 
    1717        ALIGN_RIGHT, ALIGN_BOTTOM 
     18from gaphor.diagram.style import get_text_point 
    1819 
    1920 
     
    188189 
    189190 
    190 class ForkNodeItem(ForkDecisionNodeItem): 
     191class ForkNodeItem(Item, DiagramItem): 
    191192    """ 
    192193    Representation of fork and join node. 
    193194    """ 
     195    __namedelement__ = True 
    194196 
    195197    element_factory = inject('element_factory') 
    196198 
    197     __uml__   = UML.JoinNode 
    198     #__uml__   = UML.ForkNode 
     199    __uml__   = UML.ForkNode 
    199200 
    200201    __style__ = { 
    201202        'min-size':   (6, 45), 
    202203        'name-align': (ALIGN_CENTER, ALIGN_BOTTOM), 
     204        'name-padding': (2, 2, 2, 2), 
     205        'name-outside': True, 
    203206    } 
    204207 
     
    209212 
    210213    def __init__(self, id=None): 
    211         ForkDecisionNodeItem.__init__(self, id) 
    212  
    213         self._join_spec=self.add_text('joinSpec.value', 
     214        Item.__init__(self) 
     215        DiagramItem.__init__(self, id) 
     216         
     217        self._handles.extend((Handle(), Handle())) 
     218 
     219        self._constraints = [] 
     220 
     221        self._join_spec = self.add_text('joinSpec.value', 
    214222            pattern='{ joinSpec = %s }', 
    215223            style=self.STYLE_TOP, 
    216224            visible=self.is_join_spec_visible) 
    217225 
    218         # disable Element handles 
    219         for h in self._handles: 
    220             h.movable = False 
    221             #h.visible = False 
    222  
    223         # add vertical handles 
    224         self._handles.append(Handle(strength=STRONG+1)) 
    225         self._handles.append(Handle(strength=STRONG+1)) 
     226 
     227    def setup_canvas(self): 
     228        Item.setup_canvas(self) 
     229 
     230        h1, h2 = self._handles 
     231        cadd = self.canvas.solver.add_constraint 
     232        c1 = EqualsConstraint(a=h1.x, b=h2.x) 
     233        c2 = LessThanConstraint(smaller=h1.y, bigger=h2.y, delta=30) 
     234        self._constraints.extend((cadd(c1), cadd(c2))) 
     235 
     236 
     237    def teardown_canvas(self): 
     238        super(Item, self).teardown_canvas() 
     239        for c in self._constraints: 
     240            self.canvas.solver.remove_constraint(c) 
    226241 
    227242 
     
    231246        """ 
    232247        return isinstance(self.subject, UML.JoinNode) \ 
     248            and self.subject.joinSpec is not None \ 
    233249            and self.subject.joinSpec.value != DEFAULT_JOIN_SPEC 
    234250 
    235251 
    236     def setup_canvas(self): 
    237         super(ForkNodeItem, self).setup_canvas() 
    238         cadd = self.canvas.solver.add_constraint 
    239 #       h1, h2 = self._handles[4:] 
    240 #       h_nw = self._handles[NW] 
    241 #       h_sw = self._handles[SW] 
    242 #       h1.y = h_nw.y 
    243 #       h2.y = h_sw.y 
    244 #       c1 = EqualsConstraint(a=h_nw.y, b=h1.y) 
    245 #       c2 = EqualsConstraint(a=h_sw.y, b=h2.y) 
    246 #       w = Variable(self.width / 2.0, STRONG+2) 
    247 #       h1.x = h2.x = w 
    248 #       c3 = EqualsConstraint(a=h1.x, b=w) 
    249 #       c4 = EqualsConstraint(a=h2.x, b=w) 
    250 #       c5 = LessThanConstraint(smaller=h1.y, bigger=h2.y) 
    251 #       cadd(c1) 
    252 #       cadd(c2) 
    253 #       cadd(c3) 
    254 #       cadd(c4) 
    255 #       cadd(c5) 
    256 #       self._constraints.append(c1) 
    257 #       self._constraints.append(c2) 
    258 #       self._constraints.append(c3) 
    259 #       self._constraints.append(c4) 
    260 #       self._constraints.append(c5) 
     252    def text_align(self, extents, align, padding, outside): 
     253        h1, h2 = self._handles 
     254        w, _ = self.style.min_size 
     255        h = h2.y - h1.y 
     256        x, y = get_text_point(extents, w, h, align, padding, outside) 
     257 
     258        return x, y 
     259 
     260 
     261    def pre_update(self, context): 
     262        self.update_stereotype() 
     263        Item.pre_update(self, context) 
     264        DiagramItem.pre_update(self, context) 
     265 
     266 
     267    def update(self, context): 
     268        Item.update(self, context) 
     269        DiagramItem.update(self, context) 
    261270 
    262271 
     
    266275        specification is also drawn above the item. 
    267276        """ 
    268         cr = context.cairo 
     277        Item.draw(self, context) 
     278        DiagramItem.draw(self, context) 
     279 
     280        cr = context.cairo 
     281 
    269282        cr.set_line_width(6) 
    270         h1, h2 = self._handles[4:] 
    271         cr.move_to(h1.x, 0) 
    272         cr.line_to(h2.x, self.height) 
    273  
    274         cr.stroke() 
    275         super(ForkNodeItem, self).draw(context) 
     283        h1, h2 = self._handles 
     284        cr.move_to(h1.x, h1.y) 
     285        cr.line_to(h2.x, h2.y) 
     286 
     287        cr.stroke() 
     288 
     289 
     290    def point(self, x, y): 
     291        return DiagramItem.point(self, x, y) 
    276292 
    277293 
     
    283299        text element. 
    284300        """ 
    285         ForkDecisionNodeItem.on_subject_notify(self, pspec, 
     301        DiagramItem.on_subject_notify(self, pspec, 
    286302                ('joinSpec', 'joinSpec.value') + notifiers) 
    287303        self.set_join_spec(DEFAULT_JOIN_SPEC) 
  • gaphor/trunk/gaphor/ui/diagramtoolbox.py

    r1524 r1575  
    274274                item_factory=self._item_factory(items.ForkNodeItem, 
    275275                                                UML.JoinNode), 
    276                 handle_index=SE
     276                handle_index=1
    277277                after_handler=self._after_handler) 
    278278