Changeset 757

Show
Ignore:
Timestamp:
02/06/06 00:52:49 (3 years ago)
Author:
wrobell
Message:

- provided and required interfaces of component realizing classifiers are

visible in Component.{provided,required} derived associations

- support for automatic realization dependencies between components and

interfaces

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gaphor/ChangeLog

    r750 r757  
     12006-02-06  wrobell <wrobell@pld-linux.org> 
     2        * gaphor/UML/uml2.override: provided and required interfaces of 
     3        component realizing classifiers are visible in Component.{provided,required} 
     4        derived associations 
     5        * gaphor/UML/util.py: added utility functions for getting provided and 
     6        required interfaces of classifier/component 
     7        * gaphor/diagram/dependency.py: support for automatic realization 
     8        dependencies between components and interfaces 
     9 
    1102006-01-16  wrobell <wrobell@pld-linux.org> 
    211        * gaphor/diagram/commentline.py: allow_connect_handle does not throw an 
  • trunk/gaphor/NEWS

    r755 r757  
    110.8.1 
    22----- 
    3 - small bug fixes 
     3- support for automatic realization dependencies between components and 
     4  interfaces 
     5- provided and required interfaces of component realizing classifiers are 
     6  visible in Component.{provided,required} derived associations 
     7- missing icons added 
    48 
    590.8.0 
  • trunk/gaphor/gaphor/UML/uml2.override

    r728 r757  
    181181override Component.provided 
    182182def component_provided(self): 
    183     interfaces = [ impl.contract[0] for impl in self.implementation \ 
    184         if impl.isKindOf(Implementation) ] # should we process with this condition? 
    185     return interfaces 
     183    from gaphor.UML.util import pr_interface_deps, pr_rc_interface_deps 
     184    import itertools 
     185 
     186    implementations = (impl.contract[0] for impl in self.implementation if impl.isKindOf(Implementation)) 
     187    realizations = pr_interface_deps(self, Realization) 
     188 
     189    # realizing classifiers realizations 
     190    # this generator of generators, so flatten it later 
     191    rc_realizations = pr_rc_interface_deps(self, Realization) 
     192 
     193    return tuple(set(itertools.chain(implementations, realizations, *rc_realizations))) 
    186194 
    187195Component.provided = property(component_provided, doc = \ 
     
    193201override Component.required 
    194202def component_required(self): 
    195     interfaces = [ dep.supplier[0] for dep in self.clientDependency \ 
    196         if dep.isKindOf(Usage) and dep.supplier[0].isKindOf(Interface) ] 
    197     return interfaces 
     203    from gaphor.UML.util import pr_interface_deps, pr_rc_interface_deps 
     204    import itertools 
     205 
     206    usages = pr_interface_deps(self, Usage) 
     207 
     208    # realizing classifiers usages 
     209    # this generator of generators, so flatten it later 
     210    rc_usages = pr_rc_interface_deps(self, Usage) 
     211 
     212    return tuple(set(itertools.chain(usages, *rc_usages))) 
    198213 
    199214Component.required = property(component_required, doc = \ 
  • trunk/gaphor/gaphor/diagram/dependency.py

    r744 r757  
    3535    dependencies to an interface, it will probably not be very explaining 
    3636    (esp. Usage dependencies). 
     37 
     38    Function get_dependency_type should be used to determine automatically 
     39    type of a dependency. 
    3740 
    3841    TODO (see also InterfaceItem): When a Usage dependency is drawn and is 
     
    150153        """See RelationshipItem.find_relationship(). 
    151154        """ 
    152         return self._find_relationship(head_subject, tail_subject, 
    153                                        ('supplier', 'supplierDependency'), 
    154                                        ('client', 'clientDependency')) 
     155        if get_dependency_type(head_subject, tail_subject) == UML.Realization: 
     156            args = (('realizingClassifier', None), ('abstraction', 'realization')) 
     157        else: 
     158            args = (('supplier', 'supplierDependency'), ('client', 'clientDependency')) 
     159        return self._find_relationship(head_subject, tail_subject, *args) 
     160 
    155161 
    156162    def allow_connect_handle(self, handle, connecting_to): 
     
    177183 
    178184        if self.auto_dependency: 
    179             # Determine the dependency_type if only one handle is connected 
    180             if c1 and isinstance(c1.subject, UML.Interface): 
    181                 self.set_dependency_type(UML.Usage) 
    182             else: 
    183                 self.set_dependency_type(UML.Dependency) 
     185            # determining the dependency type can be performed when only 
     186            # one handle is connected 
     187            s1 = s2 = None 
     188            if c1: 
     189                s1 = c1.subject 
     190            if c2: 
     191                s2 = c2.subject 
     192            self.set_dependency_type(get_dependency_type(s1, s2)) 
    184193 
    185194        if c1 and c2: 
     
    189198            if not relation: 
    190199                relation = resource(UML.ElementFactory).create(self.dependency_type) 
    191                 relation.supplier = s1 
    192                 relation.client = s2 
     200                if get_dependency_type(s1, s2) == UML.Realization: 
     201                    relation.realizingClassifier = s1 
     202                    relation.abstraction = s2 
     203                else: 
     204                    relation.supplier = s1 
     205                    relation.client = s2 
    193206            self.subject = relation 
    194207 
     
    200213        self.set_subject(None) 
    201214 
     215 
     216 
     217def is_usage(s): 
     218    """ 
     219    Return true if dependency should be usage dependency. 
     220    """ 
     221    return isinstance(s, UML.Interface) 
     222 
     223 
     224def is_component_realization(ts, hs): 
     225    """ 
     226    Return true if dependency should be realization dependency. 
     227    """ 
     228    return isinstance(ts, UML.Classifier) and isinstance(hs, UML.Component) 
     229 
     230 
     231def get_dependency_type(ts, hs): 
     232    """ 
     233    Determine dependency type: 
     234    - check if it is usage 
     235    - check if it is realization 
     236    - if none of above, then it is normal dependency 
     237 
     238    The checks should be performed in above order. For example if ts and hs 
     239    are Interface and Component, then we have two choices: 
     240    - claim it is an usage (as ts is an Interface) 
     241    - or claim it is a realization (as Interface is Classifier, too) 
     242    In this case we want usage to win over realization. 
     243    """ 
     244    dt = UML.Dependency 
     245    if is_usage(ts): 
     246        dt = UML.Usage 
     247    elif is_component_realization(ts, hs): 
     248        dt = UML.Realization 
     249    return dt 
     250 
     251 
    202252initialize_item(DependencyItem, UML.Dependency)