Changeset 901

Show
Ignore:
Timestamp:
05/31/06 03:24:40 (2 years ago)
Author:
wrobell
Message:

- include and extend use case relationships refactorized to support

stereotypes

- start dependency refactorization

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stereotypes/gaphor/gaphor/diagram/dependency.py

    r779 r901  
    3737    """This class represents all types of dependencies. 
    3838 
    39     Normally a dependency looks like a dashed line woth an arrow head. 
     39    Normally a dependency looks like a dashed line with an arrow head. 
    4040    The dependency can have a stereotype attached to it, stating the kind of 
    4141    dependency we're dealing with. The dependency kind can only be changed if 
     
    6161    __uml__ = UML.Dependency 
    6262 
     63    # do not use issubclass, because issubclass(UML.Implementation, UML.Realization) 
     64    # we need to be very strict here 
     65    __stereotype__ = { 
     66        'use':        lambda self: self.dependency_type == UML.Usage, 
     67        'realize':    lambda self: self.dependency_type == UML.Realization, 
     68        'implements': lambda self: self.dependency_type == UML.Implementation, 
     69    } 
     70 
    6371    relationship = DependencyRelationship() 
    64  
    65     FONT = 'sans 10' 
    6672 
    6773    dependency_popup_menu = ( 
     
    8187        DiagramLine.__init__(self, id) 
    8288 
    83         font = pango.FontDescription(self.FONT) 
    84         self._stereotype = diacanvas.shape.Text() 
    85         self._stereotype.set_font_description(font) 
    86         self._stereotype.set_wrap_mode(diacanvas.shape.WRAP_NONE) 
    87         self._stereotype.set_markup(False) 
    88  
    8989        self.set(head_fill_color=0, head_a=0.0, head_b=15.0, head_c=6.0, head_d=6.0) 
    9090        self._set_line_style() 
     91 
    9192 
    9293    def save(self, save_func): 
     
    9495        save_func('dependency_type', self.dependency_type.__name__) 
    9596        save_func('auto_dependency', self.auto_dependency) 
     97 
    9698 
    9799    def load(self, name, value): 
     
    103105            DiagramLine.load(self, name, value) 
    104106 
     107 
    105108    def get_popup_menu(self): 
    106109        if self.subject: 
     
    109112            return self.popup_menu + self.dependency_popup_menu 
    110113 
     114 
    111115    def get_dependency_type(self): 
    112116        return self.dependency_type 
     117 
    113118 
    114119    def set_dependency_type(self, dependency_type): 
    115120        self.dependency_type = dependency_type 
    116121        self._set_line_style() 
     122 
    117123 
    118124    def _set_line_style(self, c1=None): 
     
    125131            if self.get_property('has_head'): 
    126132                self.set(dash=None, has_head=0) 
    127             self._stereotype.set_text('') 
    128133        else: 
    129134            if not self.get_property('has_head'): 
    130135                self.set(dash=(7.0, 5.0), has_head=1) 
    131             if dependency_type is UML.Usage: 
    132                 self._stereotype.set_text(STEREOTYPE_OPEN + 'use' + STEREOTYPE_CLOSE) 
    133             elif dependency_type is UML.Realization: 
    134                 self._stereotype.set_text(STEREOTYPE_OPEN + 'realize' + STEREOTYPE_CLOSE) 
    135             elif dependency_type is UML.Implementation: 
    136                 self._stereotype.set_text(STEREOTYPE_OPEN + 'implements' + STEREOTYPE_CLOSE) 
    137             else: 
    138                 self._stereotype.set_text('') 
    139  
    140     def update_label(self, p1, p2): 
    141         w, h = self._stereotype.to_pango_layout(True).get_pixel_size() 
    142  
    143         x = p1[0] > p2[0] and w + 2 or -2 
    144         x = (p1[0] + p2[0]) / 2.0 - x 
    145         y = p1[1] <= p2[1] and h or 0 
    146         y = (p1[1] + p2[1]) / 2.0 - y 
    147  
    148         self._stereotype.set_pos((x, y)) 
    149  
    150         return x, y, x + w, y + h 
    151  
    152     def on_update(self, affine): 
    153         self._set_line_style(); 
    154         DiagramLine.on_update(self, affine) 
    155         handles = self.handles 
    156         middle = len(handles)/2 
    157         b1 = self.update_label(handles[middle-1].get_pos_i(), 
    158                                  handles[middle].get_pos_i()) 
    159  
    160         b2 = self.bounds 
    161         self.set_bounds((min(b1[0], b2[0]), min(b1[1], b2[1]), 
    162                          max(b1[2] + b1[0], b2[2]), max(b1[3] + b1[1], b2[3]))) 
    163  
    164     def on_shape_iter(self): 
    165         for s in DiagramLine.on_shape_iter(self): 
    166             yield s 
    167         yield self._stereotype 
     136 
    168137 
    169138    # 
     
    200169 
    201170        if self.auto_dependency: 
    202             # determining the dependency type can be performed when only 
    203             # one handle is connected 
     171            # when one handle is connected then it is possible to determe 
     172            # the dependency type 
    204173            self.set_dependency_type(determine_dependency_type(s1, s2)) 
    205174 
  • branches/stereotypes/gaphor/gaphor/diagram/diagramitem.py

    r832 r901  
    232232 
    233233        if self.get_fixed_stereotype(): 
    234             pass 
    235         else: 
     234            pass # do nothing in case of fixed stereotype 
     235        elif subject: 
     236            # look for stereotypes to put them into context menu of an item 
     237            # this can be only done when subject exists 
     238 
    236239            from itemactions import ApplyStereotypeAction, register_action 
    237240 
     
    241244            # subject 
    242245            names = set(c.__name__ for c in cls.__mro__ if issubclass(c, Element)) 
    243             # Find stereotypes that extend out metaclass 
    244             classes = self._subject._factory.select(lambda e: e.isKindOf(UML.Class) and e.name in names) 
     246 
     247            # find stereotypes that extend out metaclass 
     248            classes = subject._factory.select(lambda e: e.isKindOf(UML.Class) and e.name in names) 
    245249 
    246250            for class_ in classes: 
     
    449453        ExtensionItem.confirm_connect_handle method. 
    450454        """ 
    451         subject = self.subject 
    452         applied_stereotype = subject.appliedStereotype 
     455        if self.subject: 
     456            applied_stereotype = self.subject.appliedStereotype 
     457        else: 
     458            applied_stereotype = None 
    453459 
    454460        def stereotype_name(name): 
     
    512518 
    513519 
    514 def pget(self, value): 
    515     # if there is additional predicate, then check subject 
     520def pget(obj, value): 
     521    """ 
     522    Return value if not a tuple. 
     523 
     524    If value is tuple, then it is divided into two parts value and 
     525    predicate. Then value is returned if predicate(obj) returns true. 
     526    Otherwise None is returned. 
     527    """ 
    516528    if isinstance(value, tuple): 
    517529        value, predicate = value 
    518530        assert callable(predicate) 
    519531 
    520         if not predicate(self): 
     532        if not predicate(obj): 
    521533            value = None 
    522534 
  • branches/stereotypes/gaphor/gaphor/diagram/diagramline.py

    r779 r901  
    1 # vim:sw=4:et 
    2 """Basic functionality for line-like objects on a diagram. 
    31""" 
     2Basic functionality for canvas line based items on a diagram. 
     3""" 
     4 
     5import itertools 
    46 
    57import diacanvas 
     
    7880 
    7981 
     82    def on_update (self, affine): 
     83        diacanvas.CanvasLine.on_update(self, affine) 
     84 
     85        # update stereotype 
     86        # fixme: use util function 
     87        sw, sh = self._stereotype.to_pango_layout(True).get_pixel_size() 
     88 
     89        handles = self.handles 
     90        middle = len(handles)/2 
     91        p1 = handles[middle-1].get_pos_i() 
     92        p2 = handles[middle].get_pos_i() 
     93 
     94        x = p1[0] > p2[0] and sw + 2 or -2 
     95        x = (p1[0] + p2[0]) / 2.0 - x 
     96        y = p1[1] <= p2[1] and sh or 0 
     97        y = (p1[1] + p2[1]) / 2.0 - y 
     98 
     99        self._stereotype.set_pos((x, y)) 
     100        self._stereotype.set_max_width(sw) 
     101        self._stereotype.set_max_height(sh) 
     102 
     103        b1 = x, y, sw, sh 
     104 
     105        b2 = self.bounds 
     106        self.set_bounds((min(b1[0], b2[0]), min(b1[1], b2[1]), 
     107                         max(b1[2] + b1[0], b2[2]), max(b1[3] + b1[1], b2[3]))) 
     108 
     109        self.update_stereotype() 
     110 
     111 
     112    def on_shape_iter(self): 
     113        return itertools.chain(diacanvas.CanvasLine.on_shape_iter(self), self._shapes) 
     114 
     115 
    80116 
    81117class DiagramLine(LineItem): 
     
    85121    """ 
    86122 
    87     popup_menu = ( 
     123    popup_menu = LineItem.popup_menu + ( 
     124        'separator',  
    88125        'AddSegment', 
    89126        'DeleteSegment', 
     
    172209 
    173210        LineItem.on_update(self, affine) 
     211 
     212# vim:sw=4:et 
  • branches/stereotypes/gaphor/gaphor/diagram/extend.py

    r779 r901  
    1 ''' 
    2 Dependency --  
    3 ''' 
    4 # vim:sw=4:et 
     1""" 
     2Use case extension relationship. 
     3""" 
    54 
    6 from __future__ import generators 
    7  
    8 import math 
    9 import gobject 
    10 import pango 
    11 import diacanvas 
    12 import gaphor 
    135from gaphor import UML 
    14  
    15 from include import IncludeItem, STEREOTYPE_OPEN, STEREOTYPE_CLOSE 
     6from gaphor.diagram.include import IncludeItem 
    167 
    178 
    189class ExtendItem(IncludeItem): 
    19     """A UseCase Include dependency. 
    2010    """ 
    21  
     11    Use case extension relationship. 
     12    """ 
    2213    __uml__ = UML.Extend 
    2314    __relationship__ = 'extendedCase', None, 'extension', 'extend' 
     15    __stereotype__ = 'extend' 
    2416 
    25     FONT = 'sans 10' 
    2617 
    27     def __init__(self, id=None): 
    28         IncludeItem.__init__(self, id) 
    2918 
    30         self._stereotype.set_text(STEREOTYPE_OPEN + 'extend' + STEREOTYPE_CLOSE) 
    31  
    32     # 
    33     # Gaphor Connection Protocol 
    34     # 
    35  
    36     def confirm_connect_handle (self, handle): 
    37         """See RelationshipItem.confirm_connect_handle(). 
    38  
    39         In case of an Implementation, the head should be connected to an 
    40         Interface and the tail to a BehavioredClassifier. 
    41  
    42         TODO: Should Class also inherit from BehavioredClassifier? 
    43         """ 
    44         #print 'confirm_connect_handle', handle, self.subject 
    45         c1 = self.handles[0].connected_to 
    46  
    47         c2 = self.handles[-1].connected_to 
    48         if c1 and c2: 
    49             s1 = c1.subject 
    50             s2 = c2.subject 
    51             relation = self.relationship 
    52             if not relation: 
    53                 relation = UML.create(UML.Extend) 
    54                 relation.extendedCase = s1 
    55                 relation.extension = s2 
    56             self.subject = relation 
     19# vim:sw=4:et 
  • branches/stereotypes/gaphor/gaphor/diagram/include.py

    r779 r901  
    1 ''' 
    2 Dependency --  
    3 ''' 
    4 # vim:sw=4:et 
    5  
    6 from __future__ import generators 
    7  
    8 import math 
    9 import gobject 
    10 import pango 
    11 import diacanvas 
     1""" 
     2Use case inclusion relationship. 
     3""" 
    124 
    135from gaphor import resource 
     
    157from gaphor.diagram.relationship import DiagramLine 
    168 
    17 STEREOTYPE_OPEN = '\xc2\xab' # '<<' 
    18 STEREOTYPE_CLOSE = '\xc2\xbb' # '>>' 
    19  
    209class IncludeItem(DiagramLine): 
    21     """A UseCase Include dependency. 
     10    """ 
     11    Use case inclusion relationship. 
    2212    """ 
    2313 
    2414    __uml__ = UML.Include 
    2515    __relationship__ = 'addition', None, 'includingCase', 'include' 
    26  
    27     FONT = 'sans 10' 
     16    __stereotype__ = 'include' 
    2817 
    2918    def __init__(self, id=None): 
    3019        DiagramLine.__init__(self, id) 
    31  
    32         font = pango.FontDescription(self.FONT) 
    33         self._stereotype = diacanvas.shape.Text() 
    34         self._stereotype.set_font_description(font) 
    35         self._stereotype.set_wrap_mode(diacanvas.shape.WRAP_NONE) 
    36         self._stereotype.set_markup(False) 
    37         self._stereotype.set_text(STEREOTYPE_OPEN + 'include' + STEREOTYPE_CLOSE) 
    3820        self.set(head_fill_color=0, head_a=0.0, head_b=15.0, head_c=6.0, head_d=6.0) 
    3921        self.set(dash=(7.0, 5.0), has_head=1) 
    40  
    41     def save(self, save_func): 
    42         DiagramLine.save(self, save_func) 
    43  
    44     def load(self, name, value): 
    45         DiagramLine.load(self, name, value) 
    46  
    47     def update_label(self, p1, p2): 
    48         w, h = self._stereotype.to_pango_layout(True).get_pixel_size() 
    49  
    50         x = p1[0] > p2[0] and w + 2 or -2 
    51         x = (p1[0] + p2[0]) / 2.0 - x 
    52         y = p1[1] <= p2[1] and h or 0 
    53         y = (p1[1] + p2[1]) / 2.0 - y 
    54  
    55         self._stereotype.set_pos((x, y)) 
    56  
    57         return x, y, w, h 
    58  
    59     def on_update (self, affine): 
    60         DiagramLine.on_update(self, affine) 
    61         handles = self.handles 
    62         middle = len(handles)/2 
    63         b1 = self.update_label(handles[middle-1].get_pos_i(), 
    64                                  handles[middle].get_pos_i()) 
    65  
    66         b2 = self.bounds 
    67         self.set_bounds((min(b1[0], b2[0]), min(b1[1], b2[1]), 
    68                          max(b1[2] + b1[0], b2[2]), max(b1[3] + b1[1], b2[3]))) 
    69  
    70     def on_shape_iter(self): 
    71         for s in DiagramLine.on_shape_iter(self): 
    72             yield s 
    73         yield self._stereotype 
    7422 
    7523    # 
     
    8836        """See DiagramLine.confirm_connect_handle(). 
    8937 
    90         In case of an Implementation, the head should be connected to an 
    91         Interface and the tail to a BehavioredClassifier. 
    92  
    9338        TODO: Should Class also inherit from BehavioredClassifier? 
    9439        """ 
    95         #print 'confirm_connect_handle', handle, self.subject 
    9640        c1 = self.handles[0].connected_to 
    97  
    9841        c2 = self.handles[-1].connected_to 
    9942        if c1 and c2: 
     
    10245            relation = self.relationship 
    10346            if not relation: 
    104                 relation = resource(UML.ElementFactory).create(UML.Include) 
    105                 relation.addition = s1 
    106                 relation.includingCase = s2 
     47                relation = resource(UML.ElementFactory).create(self.__uml__) 
     48 
     49                # in case of Include: set addition and includingCase attributes 
     50                # in case of Extend: set extendedCase and extension attributes 
     51                setattr(relation, self.__relationship__[0], s1) 
     52                setattr(relation, self.__relationship__[3], s2) 
    10753            self.subject = relation 
     54 
    10855 
    10956    def confirm_disconnect_handle (self, handle, was_connected_to): 
    11057        """See DiagramLine.confirm_disconnect_handle(). 
    11158        """ 
    112         #print 'confirm_disconnect_handle', handle 
    11359        self.set_subject(None) 
     60 
     61# vim:sw=4:et 
  • branches/stereotypes/gaphor/gaphor/diagram/klass.py

    r832 r901  
    66#       probably best to do is subclass Feature in OperationItem and A.Item 
    77 
    8 from __future__ import generators 
    9  
    108import gobject 
    11 import pango 
    129import diacanvas 
    1310