Changeset 1091
- Timestamp:
- 12/03/06 23:25:49 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/TODO (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/adapters/connectors.py (modified) (7 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/association.py (modified) (7 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/classifier.py (modified) (6 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/diagramline.py (modified) (2 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/interfaces.py (modified) (6 diffs)
- gaphor/branches/new-canvas/gaphor/tests/test_storage.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/TODO
r1088 r1091 3 3 - Load / save regression testing 4 4 !!! Create some example diagrams, 5 - translate afifne matrices to new format. 5 6 6 7 - split DiagramItem in a stereotype support, SubjectSupport and some gaphor/branches/new-canvas/gaphor/adapters/connectors.py
r1088 r1091 416 416 return connected_items 417 417 418 def glue(self, handle, x, y):419 opposite = self.line.opposite(handle)420 line = self.line421 element = self.element422 connected_to = opposite.connected_to423 424 # Element can not be a parent for itself.425 if connected_to is element:426 return None427 428 # Same goes for subjects:429 if connected_to and \430 (not (connected_to.subject or element.subject)) \431 and connected_to.subject is element.subject:432 return None433 434 return super(RelationshipConnect, self).glue(handle, x, y)435 436 418 def connect_subject(self): 437 419 """ … … 495 477 """ 496 478 opposite = self.line.opposite(handle) 479 line = self.line 497 480 element = self.element 498 481 connected_to = opposite.connected_to 482 483 # Element can not be a parent for itself. 484 if connected_to is element: 485 return None 486 487 # Same goes for subjects: 488 if connected_to and \ 489 (not (connected_to.subject or element.subject)) \ 490 and connected_to.subject is element.subject: 491 return None 499 492 500 493 # Element should be a NamedElement … … 541 534 connected_to = opposite.connected_to 542 535 536 # Element can not be a parent for itself. 537 if connected_to is element: 538 return None 539 540 # Same goes for subjects: 541 if connected_to and \ 542 (not (connected_to.subject or element.subject)) \ 543 and connected_to.subject is element.subject: 544 return None 545 543 546 # Element at the head should be an Interface 544 547 if handle is line.head and \ … … 569 572 570 573 # # FixMe: Both ends of the generalization should be of the same type? 571 # def glue(self, handle, x, y): 572 # """In addition to the normal check, both line ends may not be connected 573 # to the same element. Same goes for subjects. 574 # """ 575 # opposite = self.line.opposite(handle) 576 # line = self.line 577 # element = self.element 578 # connected_to = opposite.connected_to 579 # 580 # 581 # return super(GeneralizationConnect, self).glue(handle, x, y) 574 def glue(self, handle, x, y): 575 """ 576 In addition to the normal check, both line ends may not be connected 577 to the same element. Same goes for subjects. 578 """ 579 opposite = self.line.opposite(handle) 580 line = self.line 581 element = self.element 582 connected_to = opposite.connected_to 583 584 # Element can not be a parent for itself. 585 if connected_to is element: 586 return None 587 588 # Same goes for subjects: 589 if connected_to and \ 590 (not (connected_to.subject or element.subject)) \ 591 and connected_to.subject is element.subject: 592 return None 593 594 return super(GeneralizationConnect, self).glue(handle, x, y) 582 595 583 596 def connect_subject(self): … … 601 614 to the same element. Same goes for subjects. 602 615 """ 603 element = self.element 616 opposite = self.line.opposite(handle) 617 line = self.line 618 element = self.element 619 connected_to = opposite.connected_to 604 620 621 # Element can not be a parent for itself. 622 if connected_to is element: 623 return None 624 625 # Same goes for subjects: 626 if connected_to and \ 627 (not (connected_to.subject or element.subject)) \ 628 and connected_to.subject is element.subject: 629 return None 630 605 631 if not (element.subject and isinstance(element.subject, UML.UseCase)): 606 632 return None … … 628 654 to the same element. Same goes for subjects. 629 655 """ 630 element = self.element 656 opposite = self.line.opposite(handle) 657 line = self.line 658 element = self.element 659 connected_to = opposite.connected_to 631 660 661 # Element can not be a parent for itself. 662 if connected_to is element: 663 return None 664 665 # Same goes for subjects: 666 if connected_to and \ 667 (not (connected_to.subject or element.subject)) \ 668 and connected_to.subject is element.subject: 669 return None 670 632 671 if not (element.subject and isinstance(element.subject, UML.UseCase)): 633 672 return None … … 659 698 element = self.element 660 699 connected_to = opposite.connected_to 700 701 # Element can not be a parent for itself. 702 if connected_to is element: 703 return None 704 705 # Same goes for subjects: 706 if connected_to and \ 707 (not (connected_to.subject or element.subject)) \ 708 and connected_to.subject is element.subject: 709 return None 661 710 662 711 # Element at the head should be a Class gaphor/branches/new-canvas/gaphor/diagram/association.py
r1087 r1091 16 16 from math import atan2, pi 17 17 18 from gaphas.util import text_extents 18 from gaphas.util import text_extents, text_multiline 19 19 from gaphas import Item 20 20 from gaphas.geometry import Rectangle … … 133 133 if name in ( 'head_end', 'head_subject', 'head-subject' ): 134 134 #type(self._head_end).subject.load(self._head_end, value) 135 self._head_end.load('subject', value) 135 #self._head_end.load('subject', value) 136 self._head_end.subject = value 136 137 elif name in ( 'tail_end', 'tail_subject', 'tail-subject' ): 137 138 #type(self._tail_end).subject.load(self._tail_end, value) 138 self._tail_end.load('subject', value) 139 #self._tail_end.load('subject', value) 140 self._tail_end.subject = value 139 141 else: 140 142 DiagramLine.load(self, name, value) … … 142 144 def postload(self): 143 145 DiagramLine.postload(self) 144 self._head_end. postload()145 self._tail_end. postload()146 self._head_end.set_text() 147 self._tail_end.set_text() 146 148 147 149 head_end = property(lambda self: self._head_end) … … 374 376 if self.subject and self.subject.name: 375 377 cr.move_to(self._label_bounds[0], self._label_bounds[1]) 376 cr.show_text(self.subject.name )378 cr.show_text(self.subject.name or '') 377 379 378 380 … … 423 425 self._mult_bounds = Rectangle() 424 426 self._point1 = self._point2 = (0, 0) 427 428 self._subject = None 429 430 def _set_subject(self, value): 431 self._subject = value 432 class pspec: 433 name = 'subject' 434 self.on_subject_notify(pspec) 435 436 def _del_subject(self): 437 self._subject = None 438 class pspec: 439 name = 'subject' 440 self.on_subject_notify(pspec) 441 442 subject = property(lambda s: s._subject, _set_subject, _del_subject) 425 443 426 444 def get_popup_menu(self): … … 565 583 dy = float(p2[1]) - float(p1[1]) 566 584 567 name_w, name_h = map(max, text_extents(cr, self._name ), (10, 10))568 mult_w, mult_h = map(max, text_extents(cr, self._mult ), (10, 10))585 name_w, name_h = map(max, text_extents(cr, self._name, multiline=True), (10, 10)) 586 mult_w, mult_h = map(max, text_extents(cr, self._mult, multiline=True), (10, 10)) 569 587 570 588 if dy == 0: … … 696 714 697 715 cr = context.cairo 698 cr.move_to(self._name_bounds[0], self._name_bounds[3]) 699 cr.show_text(self._name) 700 cr.move_to(self._mult_bounds[0], self._mult_bounds[3]) 701 cr.show_text(self._mult) 716 #cr.move_to(self._name_bounds[0], self._name_bounds[3]) 717 #cr.show_text(self._name or '') 718 text_multiline(cr, self._name_bounds[0], self._name_bounds[3], self._name) 719 #cr.move_to(self._mult_bounds[0], self._mult_bounds[3]) 720 #cr.show_text(self._mult or '') 721 text_multiline(cr, self._mult_bounds[0], self._mult_bounds[3], self._mult) 702 722 cr.stroke() 703 723 704 # if context.hovered or context.focused:705 #cr.set_line_width(0.5)706 #b = self._name_bounds707 #cr.rectangle(b.x0, b.y0, b.width, b.height)708 #cr.stroke()709 #b = self._mult_bounds710 #cr.rectangle(b.x0, b.y0, b.width, b.height)711 #cr.stroke()724 if context.hovered or context.focused or context.draw_all: 725 cr.set_line_width(0.5) 726 b = self._name_bounds 727 cr.rectangle(b.x0, b.y0, b.width, b.height) 728 cr.stroke() 729 b = self._mult_bounds 730 cr.rectangle(b.x0, b.y0, b.width, b.height) 731 cr.stroke() 712 732 713 733 gaphor/branches/new-canvas/gaphor/diagram/classifier.py
r1074 r1091 56 56 self.width = max(map(lambda p: p[0], sizes)) 57 57 self.height = sum(map(lambda p: p[1], sizes)) 58 vspacing = self.owner.style.compartment_vspacing 59 self.height += vspacing * len(sizes) 58 60 margin = self.owner.style.compartment_margin 59 61 self.width += margin[1] + margin[3] … … 68 70 cr = context.cairo 69 71 margin = self.owner.style.compartment_margin 72 vspacing = self.owner.style.compartment_vspacing 70 73 cr.translate(margin[1], margin[0]) 74 offset = 0 71 75 for item in self: 72 76 cr.save() 73 77 try: 74 cr.translate(0, item.height) 78 offset += item.height + vspacing 79 cr.move_to(0, offset) 75 80 item.draw(context) 76 81 finally: … … 112 117 'icon-size': (20, 20), 113 118 'compartment-margin': (5, 5, 5, 5), # (top, right, bottom, left) 119 'compartment-vspacing': 2, 114 120 } 115 121 # Default size for small icons … … 118 124 ICON_MARGIN_X = 10 119 125 ICON_MARGIN_Y = 10 120 NAME_COMPARTMENT_HEIGHT = 35121 126 122 127 def __init__(self, id=None): … … 266 271 267 272 self.min_width = max(s_w, n_w, f_w) 268 self.min_height = self.NAME_COMPARTMENT_HEIGHT 273 self.min_height = 0 274 275 super(ClassifierItem, self).pre_update(context) 269 276 270 277 if sizes: … … 275 282 self.min_height += h 276 283 277 super(ClassifierItem, self).pre_update(context)278 284 279 285 def pre_update_compartment_icon(self, context): gaphor/branches/new-canvas/gaphor/diagram/diagramline.py
r1079 r1091 104 104 for i, p in enumerate(points): 105 105 self.handles()[i].pos = p 106 elif name == 'orthogonal': 107 self._load_orthogonal = eval(value) 106 108 elif name in ('head_connection', 'head-connection'): 107 109 self._load_head_connection = value … … 114 116 # Ohoh, need the IConnect adapters here 115 117 from zope import component 118 if hasattr(self, '_load_orthogonal'): 119 self.orthogonal = self._load_orthogonal 120 del self._load_orthogonal 116 121 if hasattr(self, '_load_head_connection'): 117 122 adapter = component.queryMultiAdapter((self._load_head_connection, self), IConnect) gaphor/branches/new-canvas/gaphor/diagram/interfaces.py
r1023 r1091 15 15 16 16 class IEditor(interface.Interface): 17 """Provide an interface for editing text. with the TextEditTool. 17 """ 18 Provide an interface for editing text. with the TextEditTool. 18 19 """ 19 20 20 21 def is_editable(self, x, y): 21 """Is this item editable in it's current state. 22 """ 23 Is this item editable in it's current state. 22 24 x, y represent the cursors (x, y) position. 23 25 (this method should be called before get_text() is called. … … 25 27 26 28 def get_text(self): 27 """Get the text to be updated 29 """ 30 Get the text to be updated 28 31 """ 29 32 30 33 def get_bounds(self): 31 """Get the bounding box of the (current) text. The edit tool is not 34 """ 35 Get the bounding box of the (current) text. The edit tool is not 32 36 required to do anything with this information but it might help for 33 37 some nicer displaying of the text widget. … … 37 41 38 42 def update_text(self, text): 39 """Update with the new text. 43 """ 44 Update with the new text. 40 45 """ 41 46 42 47 def key_pressed(self, pos, key): 43 """Called every time a key is pressed. Allows for 'Enter' as escape 48 """ 49 Called every time a key is pressed. Allows for 'Enter' as escape 44 50 character in single line editing. 45 51 """ 46 52 47 53 class IConnect(interface.Interface): 48 """This interface is used by the HandleTool to allow connecting 54 """ 55 This interface is used by the HandleTool to allow connecting 49 56 lines to element items. For each specific case (Element, Line) an 50 57 adapter could be written. … … 52 59 53 60 def connect(self, handle, x, y): 54 """Connect a line's handle to element. 61 """ 62 Connect a line's handle to element. 55 63 x and y are translated to the element the handle is connecting to. 56 64 … … 60 68 """ 61 69 62 def disconnect_constraints(self, handle): 63 """Disconnect a line's handle from an element. 64 This is called whenever a handle is dragged. 70 def disconnect(self, handle): 65 71 """ 66 67 def disconnect(self, handle): 68 """The true disconnect. Disconnect a handle.connected_to from an 72 The true disconnect. Disconnect a handle.connected_to from an 69 73 element. This requires that the relationship is also removed at 70 74 model level. 71 75 """ 72 76 77 def connect_constraint(self, handle, x, y): 78 """ 79 Connect a handle to the element. 80 """ 81 82 def disconnect_constraints(self, handle): 83 """ 84 Disconnect a line's handle from an element. 85 This is called whenever a handle is dragged. 86 """ 87 73 88 def glue(self, handle, x, y): 74 """Determine if a handle can glue to a specific element. 89 """ 90 Determine if a handle can glue to a specific element. 75 91 76 92 Returns a tuple (x, y) if the line and element may connect, None … … 79 95 80 96 class IPopupMenu(interface.Interface): 81 """Interface for providing popup menus for diagram items. 97 """ 98 Interface for providing popup menus for diagram items. 82 99 """ 83 100 84 101 def get_popup_menu(self): 85 """Return the popup menu for the adapted diagram item. 102 """ 103 Return the popup menu for the adapted diagram item. 86 104 """ 87 105 gaphor/branches/new-canvas/gaphor/tests/test_storage.py
r1084 r1091 224 224 assert a.tail.x == 200, a.tail.pos 225 225 #assert a.tail.y == 200, a.tail.pos 226 227 fd = open(filename, 'w') 228 storage.save(XMLWriter(fd)) 229 fd.close() 226 assert a.subject 227 228 fd = open(filename, 'w') 229 storage.save(XMLWriter(fd)) 230 fd.close() 231 232 old_a_subject_id = a.subject.id 230 233 231 234 UML.flush() … … 237 240 d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 238 241 a = d.canvas.select(lambda e: isinstance(e, items.AssociationItem))[0] 242 assert a.subject 243 assert old_a_subject_id == a.subject.id 239 244 assert a.head.connected_to 240 245 assert a.tail.connected_to 241 246 assert not a.head.connected_to is a.tail.connected_to 247 #assert a.head_end._name 242 248 243 249
