Changeset 1091

Show
Ignore:
Timestamp:
12/03/06 23:25:49 (2 years ago)
Author:
arjanmol
Message:

loading uml2.gaphor now seems to (really) work.
fixes in association loading and drawing.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/TODO

    r1088 r1091  
    33 - Load / save regression testing 
    44   !!! Create some example diagrams, 
     5 - translate afifne matrices to new format. 
    56 
    67 - split DiagramItem in a stereotype support, SubjectSupport and some 
  • gaphor/branches/new-canvas/gaphor/adapters/connectors.py

    r1088 r1091  
    416416        return connected_items 
    417417 
    418     def glue(self, handle, x, y): 
    419         opposite = self.line.opposite(handle) 
    420         line = self.line 
    421         element = self.element 
    422         connected_to = opposite.connected_to 
    423  
    424         # Element can not be a parent for itself. 
    425         if connected_to is element: 
    426             return None 
    427  
    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 None 
    433  
    434         return super(RelationshipConnect, self).glue(handle, x, y) 
    435  
    436418    def connect_subject(self): 
    437419        """ 
     
    495477        """ 
    496478        opposite = self.line.opposite(handle) 
     479        line = self.line 
    497480        element = self.element 
    498481        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 
    499492 
    500493        # Element should be a NamedElement 
     
    541534        connected_to = opposite.connected_to 
    542535 
     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 
    543546        # Element at the head should be an Interface 
    544547        if handle is line.head and \ 
     
    569572 
    570573#    # 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) 
    582595 
    583596    def connect_subject(self): 
     
    601614        to the same element. Same goes for subjects. 
    602615        """ 
    603         element = self.element 
     616        opposite = self.line.opposite(handle) 
     617        line = self.line 
     618        element = self.element 
     619        connected_to = opposite.connected_to 
    604620         
     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 
    605631        if not (element.subject and isinstance(element.subject, UML.UseCase)): 
    606632            return None 
     
    628654        to the same element. Same goes for subjects. 
    629655        """ 
    630         element = self.element 
     656        opposite = self.line.opposite(handle) 
     657        line = self.line 
     658        element = self.element 
     659        connected_to = opposite.connected_to 
    631660         
     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 
    632671        if not (element.subject and isinstance(element.subject, UML.UseCase)): 
    633672            return None 
     
    659698        element = self.element 
    660699        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 
    661710 
    662711        # Element at the head should be a Class 
  • gaphor/branches/new-canvas/gaphor/diagram/association.py

    r1087 r1091  
    1616from math import atan2, pi 
    1717 
    18 from gaphas.util import text_extents 
     18from gaphas.util import text_extents, text_multiline 
    1919from gaphas import Item 
    2020from gaphas.geometry import Rectangle 
     
    133133        if name in ( 'head_end', 'head_subject', 'head-subject' ): 
    134134            #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 
    136137        elif name in ( 'tail_end', 'tail_subject', 'tail-subject' ): 
    137138            #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 
    139141        else: 
    140142            DiagramLine.load(self, name, value) 
     
    142144    def postload(self): 
    143145        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() 
    146148 
    147149    head_end = property(lambda self: self._head_end) 
     
    374376        if self.subject and self.subject.name: 
    375377            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 ''
    377379 
    378380 
     
    423425        self._mult_bounds = Rectangle() 
    424426        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) 
    425443 
    426444    def get_popup_menu(self): 
     
    565583        dy = float(p2[1]) - float(p1[1]) 
    566584         
    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)) 
    569587 
    570588        if dy == 0: 
     
    696714 
    697715        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) 
    702722        cr.stroke() 
    703723 
    704 #        if context.hovered or context.focused
    705 #            cr.set_line_width(0.5) 
    706 #            b = self._name_bounds 
    707 #            cr.rectangle(b.x0, b.y0, b.width, b.height) 
    708 #            cr.stroke() 
    709             #b = self._mult_bounds 
    710             #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() 
    712732     
    713733 
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r1074 r1091  
    5656            self.width = max(map(lambda p: p[0], sizes)) 
    5757            self.height = sum(map(lambda p: p[1], sizes)) 
     58            vspacing = self.owner.style.compartment_vspacing 
     59            self.height += vspacing * len(sizes) 
    5860        margin = self.owner.style.compartment_margin 
    5961        self.width += margin[1] + margin[3] 
     
    6870        cr = context.cairo 
    6971        margin = self.owner.style.compartment_margin 
     72        vspacing = self.owner.style.compartment_vspacing 
    7073        cr.translate(margin[1], margin[0]) 
     74        offset = 0 
    7175        for item in self: 
    7276            cr.save() 
    7377            try: 
    74                 cr.translate(0, item.height) 
     78                offset += item.height + vspacing 
     79                cr.move_to(0, offset) 
    7580                item.draw(context) 
    7681            finally: 
     
    112117        'icon-size':          (20, 20), 
    113118        'compartment-margin': (5, 5, 5, 5), # (top, right, bottom, left) 
     119        'compartment-vspacing': 2, 
    114120    } 
    115121    # Default size for small icons 
     
    118124    ICON_MARGIN_X = 10 
    119125    ICON_MARGIN_Y = 10 
    120     NAME_COMPARTMENT_HEIGHT = 35 
    121126 
    122127    def __init__(self, id=None): 
     
    266271 
    267272        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) 
    269276 
    270277        if sizes: 
     
    275282            self.min_height += h 
    276283 
    277         super(ClassifierItem, self).pre_update(context) 
    278284 
    279285    def pre_update_compartment_icon(self, context): 
  • gaphor/branches/new-canvas/gaphor/diagram/diagramline.py

    r1079 r1091  
    104104            for i, p in enumerate(points): 
    105105                self.handles()[i].pos = p 
     106        elif name == 'orthogonal': 
     107            self._load_orthogonal = eval(value) 
    106108        elif name in ('head_connection', 'head-connection'): 
    107109            self._load_head_connection = value 
     
    114116        # Ohoh, need the IConnect adapters here 
    115117        from zope import component 
     118        if hasattr(self, '_load_orthogonal'): 
     119            self.orthogonal = self._load_orthogonal 
     120            del self._load_orthogonal 
    116121        if hasattr(self, '_load_head_connection'): 
    117122            adapter = component.queryMultiAdapter((self._load_head_connection, self), IConnect) 
  • gaphor/branches/new-canvas/gaphor/diagram/interfaces.py

    r1023 r1091  
    1515 
    1616class IEditor(interface.Interface): 
    17     """Provide an interface for editing text. with the TextEditTool. 
     17    """ 
     18    Provide an interface for editing text. with the TextEditTool. 
    1819    """ 
    1920 
    2021    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. 
    2224        x, y represent the cursors (x, y) position. 
    2325        (this method should be called before get_text() is called. 
     
    2527 
    2628    def get_text(self): 
    27         """Get the text to be updated 
     29        """ 
     30        Get the text to be updated 
    2831        """ 
    2932 
    3033    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 
    3236        required to do anything with this information but it might help for 
    3337        some nicer displaying of the text widget. 
     
    3741 
    3842    def update_text(self, text): 
    39         """Update with the new text. 
     43        """ 
     44        Update with the new text. 
    4045        """ 
    4146 
    4247    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 
    4450        character in single line editing. 
    4551        """ 
    4652 
    4753class 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 
    4956    lines to element items. For each specific case (Element, Line) an 
    5057    adapter could be written. 
     
    5259 
    5360    def connect(self, handle, x, y): 
    54         """Connect a line's handle to element. 
     61        """ 
     62        Connect a line's handle to element. 
    5563        x and y are translated to the element the handle is connecting to. 
    5664 
     
    6068        """ 
    6169 
    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): 
    6571        """ 
    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 
    6973        element. This requires that the relationship is also removed at 
    7074        model level. 
    7175        """ 
    7276 
     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 
    7388    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. 
    7591 
    7692        Returns a tuple (x, y) if the line and element may connect, None 
     
    7995 
    8096class IPopupMenu(interface.Interface): 
    81     """Interface for providing popup menus for diagram items. 
     97    """ 
     98    Interface for providing popup menus for diagram items. 
    8299    """ 
    83100 
    84101    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. 
    86104        """ 
    87105 
  • gaphor/branches/new-canvas/gaphor/tests/test_storage.py

    r1084 r1091  
    224224        assert a.tail.x == 200, a.tail.pos 
    225225        #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 
    230233 
    231234        UML.flush() 
     
    237240        d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
    238241        a = d.canvas.select(lambda e: isinstance(e, items.AssociationItem))[0] 
     242        assert a.subject 
     243        assert old_a_subject_id == a.subject.id 
    239244        assert a.head.connected_to 
    240245        assert a.tail.connected_to 
    241246        assert not a.head.connected_to is a.tail.connected_to 
     247        #assert a.head_end._name 
    242248 
    243249