root/gaphor/tags/gaphor-0.3.0/gaphor/diagram/generalization.py

Revision 215, 2.9 kB (checked in by arjanmol, 5 years ago)

*** empty log message ***

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 '''
2 Generalization --
3 '''
4 # vim:sw=4
5
6 import gobject
7 import diacanvas
8 import gaphor
9 import gaphor.UML as UML
10 from gaphor.diagram import initialize_item
11 import relationship
12
13 class GeneralizationItem(relationship.RelationshipItem):
14
15     def __init__(self, id=None):
16         relationship.RelationshipItem.__init__(self, id)
17         self.set(has_head=1, head_fill_color=0,
18                  head_a=15.0, head_b=15.0, head_c=10.0, head_d=10.0)
19        
20     # Gaphor Connection Protocol
21
22     def find_relationship(self, head_subject, tail_subject):
23         """See RelationshipItem.find_relationship().
24         """
25         if self.subject and \
26            self.subject.general is head_subject and \
27            self.subject.specific is tail_subject:
28             return self.subject
29
30         for gen in tail_subject.generalization:
31             if gen.general is head_subject:
32                 # check for this entry on self.canvas
33                 for item in spec.subject.presentation:
34                     # Allow self to be returned. Avoids strange
35                     # behaviour during loading
36                     if item.canvas is self.canvas and item is not self:
37                         break
38                 else:
39                     return spec
40         return None
41
42     def allow_connect_handle(self, handle, connecting_to):
43         """See RelationshipItem.allow_connect_handle().
44         """
45         try:
46             if not isinstance(connecting_to.subject, UML.Classifier):
47                 return False
48
49             c1 = self.handles[0].connected_to
50             c2 = self.handles[-1].connected_to
51             if not c1 and not c2:
52                 return True
53             if self.handles[0] is handle:
54                 return (self.handles[-1].connected_to.subject is not connecting_to.subject)
55             elif self.handles[-1] is handle:
56                 return (self.handles[0].connected_to.subject is not connecting_to.subject)
57             assert 1, 'Should never be reached...'
58         except AttributeError, e:
59             log.debug('Generalization.allow_connect_handle: %s' % e)
60             return False
61
62     def confirm_connect_handle (self, handle):
63         """See RelationshipItem.confirm_connect_handle().
64         """
65         #print 'confirm_connect_handle', handle
66         c1 = self.handles[0].connected_to
67         c2 = self.handles[-1].connected_to
68         if c1 and c2:
69             s1 = c1.subject
70             s2 = c2.subject
71             relation = self.find_relationship(s1, s2)
72             if not relation:
73                 relation = gaphor.resource(UML.ElementFactory).create(UML.Generalization)
74                 relation.general = s1
75                 relation.specific = s2
76             self.subject = relation
77
78     def confirm_disconnect_handle (self, handle, was_connected_to):
79         """See RelationshipItem.confirm_disconnect_handle().
80         """
81         #print 'confirm_disconnect_handle', handle
82         if self.subject:
83             del self.subject
84
85 initialize_item(GeneralizationItem, UML.Generalization)
Note: See TracBrowser for help on using the browser.