Changeset 2164

Show
Ignore:
Timestamp:
10/10/07 16:13:12 (1 year ago)
Author:
wrobe..@pld-linux.org
Message:

- refactored relationship code to kill few common lines as it is usually

binary, still it is possible to create unary relationships

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/adapters/connectors.py

    r2160 r2164  
    369369 
    370370    element_factory = inject('element_factory') 
     371 
     372    # relationships can sometimes by unary, i.e. association, flow 
     373    # override in deriving class to allow unary relationship 
     374    CAN_BE_UNARY = False 
     375 
     376    def glue(self, handle): 
     377        """ 
     378        In addition to the normal check, both relationship ends may not be 
     379        connected to the same element. Same goes for subjects. 
     380        """ 
     381        if not self.CAN_BE_UNARY: 
     382            opposite = self.line.opposite(handle) 
     383            line = self.line 
     384            element = self.element 
     385            connected_to = opposite.connected_to 
     386 
     387            # Element can not be a parent for itself. 
     388            if connected_to is element: 
     389                return None 
     390 
     391            # Same goes for subjects: 
     392            if connected_to and \ 
     393                    (not (connected_to.subject or element.subject)) \ 
     394                     and connected_to.subject is element.subject: 
     395                return None 
     396 
     397        return super(RelationshipConnect, self).glue(handle) 
     398 
    371399 
    372400    def relationship(self, required_type, head, tail): 
     
    528556 
    529557    def glue(self, handle): 
    530         """ 
    531         In addition to the normal check, both line ends may not be connected 
    532         to the same element. Same goes for subjects. 
    533         """ 
    534         opposite = self.line.opposite(handle) 
    535         line = self.line 
    536         element = self.element 
    537         connected_to = opposite.connected_to 
    538  
    539         # Element can not be a parent for itself. 
    540         if connected_to is element: 
    541             return None 
    542  
    543         # Same goes for subjects: 
    544         if connected_to and \ 
    545                 (not (connected_to.subject or element.subject)) \ 
    546                  and connected_to.subject is element.subject: 
    547             return None 
     558        line = self.line 
     559        element = self.element 
    548560 
    549561        # Element should be a NamedElement 
     
    581593 
    582594    def glue(self, handle): 
    583         """ 
    584         In addition to the normal check, both line ends may not be connected 
    585         to the same element. Same goes for subjects. 
    586         """ 
    587         opposite = self.line.opposite(handle) 
    588         line = self.line 
    589         element = self.element 
    590         connected_to = opposite.connected_to 
    591  
    592         # Element can not be a parent for itself. 
    593         if connected_to is element: 
    594             return None 
    595  
    596         # Same goes for subjects: 
    597         if connected_to and \ 
    598                 (not (connected_to.subject or element.subject)) \ 
    599                  and connected_to.subject is element.subject: 
    600             return None 
     595        line = self.line 
     596        element = self.element 
    601597 
    602598        # Element at the head should be an Interface 
     
    625621    Connect Classifiers with a Generalization relationship. 
    626622    """ 
     623    # FixMe: Both ends of the generalization should be of the same  type? 
    627624    component.adapts(items.ClassifierItem, items.GeneralizationItem) 
    628  
    629 #    # FixMe: Both ends of the generalization should be of the same  type? 
    630     def glue(self, handle): 
    631         """ 
    632         In addition to the normal check, both line ends may not be connected 
    633         to the same element. Same goes for subjects. 
    634         """ 
    635         opposite = self.line.opposite(handle) 
    636         line = self.line 
    637         element = self.element 
    638         connected_to = opposite.connected_to 
    639  
    640         # Element can not be a parent for itself. 
    641         if connected_to is element: 
    642             return None 
    643  
    644         # Same goes for subjects: 
    645         if connected_to and \ 
    646                 (not (connected_to.subject or element.subject)) \ 
    647                  and connected_to.subject is element.subject: 
    648             return None 
    649  
    650         return super(GeneralizationConnect, self).glue(handle) 
    651625 
    652626    def connect_subject(self, handle): 
     
    666640 
    667641    def glue(self, handle): 
    668         """ 
    669         In addition to the normal check, both line ends may not be connected 
    670         to the same element. Same goes for subjects. 
    671         """ 
    672         opposite = self.line.opposite(handle) 
    673         line = self.line 
    674         element = self.element 
    675         connected_to = opposite.connected_to 
    676          
    677         # Element can not be a parent for itself. 
    678         if connected_to is element: 
    679             return None 
    680  
    681         # Same goes for subjects: 
    682         if connected_to and \ 
    683                 (not (connected_to.subject or element.subject)) \ 
    684                  and connected_to.subject is element.subject: 
    685             return None 
     642        line = self.line 
     643        element = self.element 
    686644 
    687645        if not (element.subject and isinstance(element.subject, UML.UseCase)): 
     
    706664 
    707665    def glue(self, handle): 
    708         """ 
    709         In addition to the normal check, both line ends may not be connected 
    710         to the same element. Same goes for subjects. 
    711         """ 
    712         opposite = self.line.opposite(handle) 
    713         line = self.line 
    714         element = self.element 
    715         connected_to = opposite.connected_to 
     666        line = self.line 
     667        element = self.element 
    716668         
    717         # Element can not be a parent for itself. 
    718         if connected_to is element: 
    719             return None 
    720  
    721         # Same goes for subjects: 
    722         if connected_to and \ 
    723                 (not (connected_to.subject or element.subject)) \ 
    724                  and connected_to.subject is element.subject: 
    725             return None 
    726  
    727669        if not (element.subject and isinstance(element.subject, UML.UseCase)): 
    728670            return None 
     
    746688 
    747689    def glue(self, handle): 
    748         """ 
    749         In addition to the normal check, both line ends may not be connected 
    750         to the same element. Same goes for subjects. 
    751         """ 
    752         opposite = self.line.opposite(handle) 
    753         line = self.line 
    754         element = self.element 
    755         connected_to = opposite.connected_to 
    756  
    757         # Element can not be a parent for itself. 
    758         if connected_to is element: 
    759             return None 
    760  
    761         # Same goes for subjects: 
    762         if connected_to and \ 
    763                 (not (connected_to.subject or element.subject)) \ 
    764                  and connected_to.subject is element.subject: 
    765             return None 
     690        line = self.line 
     691        element = self.element 
    766692 
    767693        # Element at the head should be a Class 
     
    855781    component.adapts(items.ClassifierItem, items.AssociationItem) 
    856782 
    857     def glue(self, handle): 
    858         opposite = self.line.opposite(handle) 
    859         line = self.line 
    860         element = self.element 
    861         connected_to = opposite.connected_to 
     783    CAN_BE_UNARY = True    # allow one classifier to be connected by association 
     784 
     785    def glue(self, handle): 
     786        element = self.element 
    862787 
    863788        # Element should be a Classifier 
     
    953878    """ 
    954879 
    955     def glue(self, handle): 
    956         """ 
    957         In addition to the normal check, both line ends may not be connected 
    958         to the same element. Same goes for subjects. 
    959         """ 
    960         opposite = self.line.opposite(handle) 
    961         line = self.line 
    962         element = self.element 
    963         subject = element.subject 
    964         connected_to = opposite.connected_to 
     880    CAN_BE_UNARY = True   # flow can connect same actions 
     881 
     882    def glue(self, handle): 
     883        line = self.line 
     884        subject = self.element.subject 
    965885 
    966886        if handle is line.head and isinstance(subject, UML.FinalNode) \ 
     
    1014934    """ 
    1015935    def glue(self, handle): 
    1016         """ 
    1017         In addition to the normal check, one end should have at most one 
    1018         edge (incoming or outgoing). 
    1019         """ 
    1020         opposite = self.line.opposite(handle) 
    1021         line = self.line 
    1022         element = self.element 
    1023         subject = element.subject 
    1024         connected_to = opposite.connected_to 
    1025  
    1026         # Element can not connect back to itself 
    1027         if connected_to is element: 
    1028             return None 
    1029  
    1030         # Same goes for subjects: 
    1031         if connected_to and \ 
    1032                 (not (connected_to.subject or element.subject)) \ 
    1033                  and connected_to.subject is element.subject: 
    1034             return None 
    1035  
    1036936        # If one side of self.element has more than one edge, the 
    1037937        # type of node is determined (either join or fork).