root/gaphor/tags/gaphor-0.12.5/gaphor/adapters/relationships.py
| Revision 2054, 1.8 kB (checked in by wrobe..@pld-linux.org, 1 year ago) |
|---|
| Line | |
|---|---|
| 1 | """ |
| 2 | |
| 3 | This module is not yet ready to be used for adapters. |
| 4 | |
| 5 | Here the logic should be placed that allows the application to draw already |
| 6 | existing relationships on the diagram when a model element is added (e.g. |
| 7 | by drag and drop). |
| 8 | """ |
| 9 | |
| 10 | from zope import component |
| 11 | |
| 12 | |
| 13 | ###class AssociationRelationship(Relationship): |
| 14 | ### """Relationship for associations. |
| 15 | ### """ |
| 16 | ### def relationship(self, line, head_subject = None, tail_subject = None): |
| 17 | ### # First check if we do not already contain the right subject: |
| 18 | ### if line.subject: |
| 19 | ### end1 = line.subject.memberEnd[0] |
| 20 | ### end2 = line.subject.memberEnd[1] |
| 21 | ### if (end1.type is head_type and end2.type is tail_type) \ |
| 22 | ### or (end2.type is head_type and end1.type is tail_type): |
| 23 | ### return |
| 24 | ### |
| 25 | ### # Find all associations and determine if the properties on the |
| 26 | ### # association ends have a type that points to the class. |
| 27 | ### Association = UML.Association |
| 28 | ### for assoc in resource(UML.ElementFactory).itervalues(): |
| 29 | ### if isinstance(assoc, Association): |
| 30 | ### #print 'assoc.memberEnd', assoc.memberEnd |
| 31 | ### end1 = assoc.memberEnd[0] |
| 32 | ### end2 = assoc.memberEnd[1] |
| 33 | ### if (end1.type is head_type and end2.type is tail_type) \ |
| 34 | ### or (end2.type is head_type and end1.type is tail_type): |
| 35 | ### # check if this entry is not yet in the diagram |
| 36 | ### # Return if the association is not (yet) on the canvas |
| 37 | ### for item in assoc.presentation: |
| 38 | ### if item.canvas is line.canvas: |
| 39 | ### break |
| 40 | ### else: |
| 41 | ### return assoc |
| 42 | ### return None |
| 43 | |
| 44 | |
| 45 | # vim:sw=4:et:ai |
Note: See TracBrowser for help on using the browser.
