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

Revision 215, 2.2 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 Dependency --
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
12 import relationship
13
14 class DependencyItem(relationship.RelationshipItem):
15
16     def __init__(self, id=None):
17         relationship.RelationshipItem.__init__(self, id)
18         self.set(dash=(7.0, 5.0), has_head=1, head_fill_color=0,
19                  head_a=0.0, head_b=15.0, head_c=6.0, head_d=6.0)
20        
21     # Gaphor Connection Protocol
22
23     def find_relationship(self, head_subject, tail_subject):
24         """See RelationshipItem.find_relationship().
25         """
26         for supplier in head_subject.supplierDependency:
27             #print 'supplier', supplier, supplier.client, tail_subject
28             if tail_subject in supplier.client:
29                 # Check if the dependency is not already in our diagram
30                 for item in self.subject.presentation:
31                     if item.canvas is self.canvas and item is not self:
32                         break
33                 else:
34                     return supplier
35
36     def allow_connect_handle(self, handle, connecting_to):
37         """See RelationshipItem.allow_connect_handle().
38         """
39         try:
40             return isinstance(connecting_to.subject, UML.NamedElement)
41         except AttributeError:
42             return 0
43
44     def confirm_connect_handle (self, handle):
45         """See RelationshipItem.confirm_connect_handle().
46         """
47         #print 'confirm_connect_handle', handle, self.subject
48         c1 = self.handles[0].connected_to
49         c2 = self.handles[-1].connected_to
50         if c1 and c2:
51             s1 = c1.subject
52             s2 = c2.subject
53             relation = self.find_relationship(s1, s2)
54             if not relation:
55                 relation = gaphor.resource(UML.ElementFactory).create(UML.Dependency)
56                 relation.supplier = s1
57                 relation.client = s2
58             self.subject = relation
59
60     def confirm_disconnect_handle (self, handle, was_connected_to):
61         """See RelationshipItem.confirm_disconnect_handle().
62         """
63         #print 'confirm_disconnect_handle', handle
64         if self.subject:
65             del self.subject
66
67 initialize_item(DependencyItem, UML.Dependency)
Note: See TracBrowser for help on using the browser.