Changeset 1074

Show
Ignore:
Timestamp:
11/17/06 02:35:40 (2 years ago)
Author:
arjanmol
Message:

Storage works.

Files:

Legend:

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

    r1057 r1074  
     12006-11-14  arjan <arjan at yirdis dot nl> 
     2 
     3        * setup.py: incremented version to 0.9.0 
     4 
    152006-10-30  arjan <arjan at yirdis dot nl> 
    26 
  • gaphor/branches/new-canvas/gaphor/UML/diagram.py

    r1068 r1074  
    3535    def update_now(self): 
    3636        if self._block_updates: 
    37             log.debug('Update blocked for canvas %s' % self) 
     37            #log.debug('Update blocked for canvas %s' % self) 
    3838            return 
    3939        super(DiagramCanvas, self).update_now() 
     
    4848 
    4949    def postload(self): 
    50         self.block_updates = False 
     50        pass #self.block_updates = False 
    5151 
    5252    def select(self, expression=lambda e: True): 
  • gaphor/branches/new-canvas/gaphor/UML/element.py

    r1066 r1074  
    7878 
    7979    def postload(self): 
    80         """Fix up the odds and ends. 
     80        """ 
     81        Fix up the odds and ends. 
    8182        """ 
    8283        for name in dir(type(self)): 
  • gaphor/branches/new-canvas/gaphor/UML/elementfactory.py

    r1057 r1074  
    147147        # First flush all diagrams: 
    148148        for value in list(self.select(lambda e: isinstance(e, Diagram))): 
     149            # Make sure no updates happen while destroying the canvas 
     150            value.canvas.block_updates = True 
    149151            value.unlink() 
    150152 
  • gaphor/branches/new-canvas/gaphor/diagram/classifier.py

    r1073 r1074  
    258258            s_w, s_h = text_extents(cr, self.stereotype) 
    259259        n_w, n_h = text_extents(cr, self.subject.name) 
     260 
    260261        f_w, f_h = 0, 0 
    261262        if self.subject.namespace: 
     
    273274            self.min_width = max(self.min_width, w) 
    274275            self.min_height += h 
     276 
    275277        super(ClassifierItem, self).pre_update(context) 
    276278 
     
    304306 
    305307    def draw_compartment(self, context): 
    306         if not self.subject: return 
     308        #if not self.subject: return 
    307309        cr = context.cairo 
    308310        cr.rectangle(0, 0, self.width, self.height) 
  • gaphor/branches/new-canvas/gaphor/diagram/diagramitem.py

    r1071 r1074  
    185185 
    186186    def _subject_disconnect_helper(self, element, callback_prefix, prop_list): 
    187         """Disconnect a previously connected signal handler. 
     187        """ 
     188        Disconnect a previously connected signal handler. 
    188189 
    189190        See: DiagramItem.on_subject_notify() 
     
    209210 
    210211    def _on_subject_notify_helper(self, element, pspec, callback_name, prop_list, old): 
    211         """This signal handler handles signals that are not direct properties 
     212        """ 
     213        This signal handler handles signals that are not direct properties 
    212214        of self.subject (e.g. 'subject.lowerValue.value'). This way the 
    213215        presentation class is not bothered with the details of keeping track 
     
    232234 
    233235    def on_subject_notify(self, pspec, notifiers=()): 
    234         """A new subject is set on this model element. 
     236        """ 
     237        A new subject is set on this model element. 
    235238        notifiers is an optional tuple of elements that also need a 
    236239        callback function. Callbacks have the signature 
     
    240243        of a property of subject (e.g. 'lowerValue.value'). 
    241244        """ 
    242         #log.info('DiagramItem.on_subject_notify: %s' % self.__subject_notifier_ids
     245        #log.info('Setting subject from %s to %s' % (self.__the_subject, self.subject)
    243246        # First, split all notifiers on '.' 
    244247        callback_prefix = 'on_subject_notify_' 
  • gaphor/branches/new-canvas/gaphor/diagram/diagramline.py

    r1044 r1074  
    88from gaphas.util import text_extents 
    99from diagramitem import DiagramItem 
    10 #from gaphor.diagram import LineItemMeta 
     10from interfaces import IConnect 
     11 
    1112 
    1213class LineItem(gaphas.Line, DiagramItem): 
     
    7677    ) 
    7778 
    78     def do_set_property (self, pspec, value): 
    79         pass 
    80  
    81     def do_get_property(self, pspec): 
    82         pass 
    83  
    8479    def save (self, save_func): 
    8580        LineItem.save(self, save_func) 
    86         for prop in ('affine', 'color', 'orthogonal', 'horizontal'): 
    87             save_func(prop, self.get_property(prop)) 
     81        save_func('matrix', tuple(self.matrix)) 
     82        for prop in ('orthogonal', 'horizontal'): 
     83            save_func(prop, getattr(self, prop)) 
    8884        points = [ ] 
    89         for h in self.handles: 
    90             pos = h.get_pos_i () 
    91             points.append (pos) 
     85        for h in self.handles(): 
     86            points.append(tuple(map(float, h.pos))) 
    9287        save_func('points', points) 
    93         c = self.handles[0].connected_to 
     88        c = self.handles()[0].connected_to 
    9489        if c: 
    9590            save_func('head-connection', c, reference=True) 
    96         c = self.handles[-1].connected_to 
     91        c = self.handles()[-1].connected_to 
    9792        if c: 
    9893            save_func('tail-connection', c, reference=True) 
     
    10196        if name == 'points': 
    10297            points = eval(value) 
    103             self.set_property('head_pos', points[0]) 
    104             self.set_property('tail_pos', points[1]) 
    105             for p in points[2:]: 
    106                 self.set_property ('add_point', p) 
     98            for x in xrange(len(points) - 2): 
     99                self.split_segment(0) 
     100            #self.set_property('head_pos', points[0]) 
     101            #self.set_property('tail_pos', points[1]) 
     102            for i, p in enumerate(points): 
     103                self.handles()[i].pos = p 
    107104        elif name in ('head_connection', 'head-connection'): 
    108105            self._load_head_connection = value 
     
    113110 
    114111    def postload(self): 
     112        # Ohoh, need the IConnect adapters here 
     113        from zope import component 
    115114        if hasattr(self, '_load_head_connection'): 
    116             self._load_head_connection.connect_handle(self.handles[0]) 
     115            adapter = component.queryMultiAdapter((self._load_head_connection, self), IConnect) 
     116            #self._load_head_connection.connect_handle(self.handles[0]) 
     117            h = self.handles()[0] 
     118 
     119            x, y = self.canvas.get_matrix_i2w(self, calculate=True).transform_point(h.x, h.y) 
     120            x, y = self.canvas.get_matrix_w2i(self._load_head_connection, calculate=True).transform_point(x, y) 
     121            adapter.connect(self.handles()[0], x, y) 
    117122            del self._load_head_connection 
    118123        if hasattr(self, '_load_tail_connection'): 
    119             self._load_tail_connection.connect_handle(self.handles[-1]) 
     124            #self._load_tail_connection.connect_handle(self.handles[-1]) 
     125            adapter = component.queryMultiAdapter((self._load_tail_connection, self), IConnect) 
     126            h = self.handles()[0] 
     127 
     128            x, y = self.canvas.get_matrix_i2w(self, calculate=True).transform_point(h.x, h.y) 
     129            x, y = self.canvas.get_matrix_w2i(self._load_tail_connection, calculate=True).transform_point(x, y) 
     130            adapter.connect(self.handles()[0], x, y) 
    120131            del self._load_tail_connection 
    121132        LineItem.postload(self) 
  • gaphor/branches/new-canvas/gaphor/storage.py

    r1068 r1074  
    176176    version_0_6_2(elements, factory, gaphor_version) 
    177177    version_0_7_2(elements, factory, gaphor_version) 
     178    version_0_9_0(elements, factory, gaphor_version) 
    178179 
    179180    #log.debug("Still have %d elements" % len(elements)) 
     
    210211            for item in elem.canvas.canvasitems: 
    211212                assert item in elements.values(), 'Item %s (%s) is a canvas item, but it is not in the parsed objects table' % (item, item.id) 
    212                 #item.element.set_property('parent', elem.element.canvas.root) 
    213213                elem.element.canvas.add(item.element) 
    214214 
     
    217217            for item in elem.canvasitems: 
    218218                assert item in elements.values(), 'Item %s (%s) is a canvas item, but it is not in the parsed objects table' % (item, item.id) 
    219                 #item.element.set_property('parent', elem.element) 
    220219                elem.element.canvas.add(item.element, parent=elem.element) 
    221220 
     
    256255    version_0_5_2(elements, factory, gaphor_version) 
    257256    version_0_7_1(elements, factory, gaphor_version) 
     257 
    258258    # Before version 0.7.2 there was only decision node (no merge nodes). 
    259259    # This node could have many incoming and outgoing flows (edges). 
     
    272272        yield update_status_queue() 
    273273        elem.element.postload() 
     274 
     275    # Unlock canvas's for updates 
     276    for id, elem in elements.items(): 
     277        if elem.canvas: 
     278            elem.element.canvas.block_updates = False 
    274279 
    275280    factory.notify_model() 
     
    327332    except Exception, e: 
    328333        log.info('file %s could not be loaded' % filename, e) 
    329         import traceback 
    330         traceback.print_exc() 
    331334        raise 
    332335 
    333336 
     337def version_0_9_0(elements, factory, gaphor_version): 
     338    """ 
     339    Before 0.9.0, we used DiaCanvas2 as diagram widget in the GUI. As of 0.9.0 
     340    Gaphas was introduced. Some properties of <item /> elements have changed, 
     341    renamed or been removed at all. 
     342 
     343    This function is called before the actual elements are constructed. 
     344    """ 
     345    if tuple(map(int, gaphor_version.split('.'))) < (0, 9, 0): 
     346        for elem in elements.values(): 
     347            try: 
     348                if type(elem) is parser.canvasitem: 
     349                    # Rename affine to matrix 
     350                    if elem.values.get('affine'): 
     351                        elem.values['matrix'] = elem.values['affine'] 
     352                        del elem.values['affine'] 
     353                    # No more 'color' attribute: 
     354                    if elem.values.get('color'): 
     355                        del elem.values['color'] 
     356 
     357            except Exception, e: 
     358                log.error('Error while updating taggedValues', e) 
     359 
    334360def version_0_7_2(elements, factory, gaphor_version): 
    335     """Before 0.7.2, only Property and Parameter elements had taggedValues. 
     361    """ 
     362    Before 0.7.2, only Property and Parameter elements had taggedValues. 
    336363    Since 0.7.2 all NamedElements are able to have taggedValues. However, 
    337364    the multiplicity of taggedValue has changed from 0..1 to *, so all elements 
     
    362389 
    363390def version_0_7_1(elements, factory, gaphor_version): 
    364     """Before version 0.7.1, there were two states for association 
     391    """ 
     392    Before version 0.7.1, there were two states for association 
    365393    navigability (in terms of UML 2.0): unknown and navigable. 
    366394    In case of unknown navigability Property.owningAssociation was set. 
     
    397425 
    398426def version_0_6_2(elements, factory, gaphor_version): 
    399     """Before 0.6.2 an Interface could be represented by a ClassItem and 
     427    """ 
     428    Before 0.6.2 an Interface could be represented by a ClassItem and 
    400429    a InterfaceItem. Now only InterfaceItems are used. 
    401430    """ 
     
    416445 
    417446def version_0_5_2(elements, factory, gaphor_version): 
    418     """Before version 0.5.2, the wrong memberEnd of the association was 
     447    """ 
     448    Before version 0.5.2, the wrong memberEnd of the association was 
    419449    holding the aggregation information. 
    420450    """ 
  • gaphor/branches/new-canvas/gaphor/tests/test_storage.py

    r1068 r1074  
    6363 
    6464    def test_load_uml(self): 
    65         """Test loading of a freshly saved model. 
     65        """ 
     66        Test loading of a freshly saved model. 
    6667        """ 
    6768        filename = '%s.gaphor' % __module__ 
     
    8889         
    8990 
    90     def test_load_uml(self): 
    91         """Test loading of a freshly saved model. 
     91    def test_load_uml_2(self): 
     92        """ 
     93        Test loading of a freshly saved model. 
    9294        """ 
    9395        filename = '%s.gaphor' % __module__ 
     
    118120        assert len(UML.lselect(lambda e: e.isKindOf(UML.Interface))) == 1 
    119121 
     122        c = UML.lselect(lambda e: e.isKindOf(UML.Class))[0] 
     123        assert c.presentation 
     124        assert c.presentation[0].subject is c 
     125        #assert c.presentation[0].subject.name.startwith('Class') 
     126 
    120127        iface = UML.lselect(lambda e: e.isKindOf(UML.Interface))[0] 
    121128        assert iface.name == 'Circus' 
     
    129136        d1 = d.canvas.select(lambda e: isinstance(e, items.ClassItem))[0] 
    130137        assert d1 
     138        #print d1, d1.subject 
     139 
     140 
     141    def test_load_uml_relationships(self): 
     142        """ 
     143        Test loading of a freshly saved model with relationship objects. 
     144        """ 
     145        filename = '%s.gaphor' % __module__ 
     146 
     147        UML.create(UML.Package) 
     148        diagram = UML.create(UML.Diagram) 
     149        diagram.create(items.CommentItem, subject=UML.create(UML.Comment)) 
     150        c1 = diagram.create(items.ClassItem, subject=UML.create(UML.Class)) 
     151        diagram.create(items.AssociationItem) 
     152 
     153        fd = open(filename, 'w') 
     154        storage.save(XMLWriter(fd)) 
     155        fd.close() 
     156 
     157        UML.flush() 
     158        assert not list(UML.select()) 
     159 
     160        storage.load(filename) 
     161 
     162        assert len(UML.lselect()) == 4 
     163        assert len(UML.lselect(lambda e: e.isKindOf(UML.Package))) == 1 
     164        assert len(UML.lselect(lambda e: e.isKindOf(UML.Diagram))) == 1 
     165        d = UML.lselect(lambda e: e.isKindOf(UML.Diagram))[0] 
     166        assert len(UML.lselect(lambda e: e.isKindOf(UML.Comment))) == 1 
     167        assert len(UML.lselect(lambda e: e.isKindOf(UML.Class))) == 1 
     168        assert len(UML.lselect(lambda e: e.isKindOf(UML.Association))) == 0 
     169 
     170        # Check load/save of other canvas items. 
     171        assert len(d.canvas.get_all_items()) == 3 
     172        #for item in d.canvas.get_all_items(): 
     173        #    assert item.subject, 'No subject for %s' % item  
     174        d1 = d.canvas.select(lambda e: isinstance(e, items.ClassItem))[0] 
     175        assert d1 
    131176        print d1, d1.subject 
    132177 
  • gaphor/branches/new-canvas/setup.py

    r1059 r1074  
    33# setup.py for Gaphor 
    44# 
    5 # vim:sw=4:et 
    6 """Gaphor 
    75""" 
     6Gaphor 
     7""" 
    88 
    99MAJOR_VERSION = 0 
    10 MINOR_VERSION = 8 
    11 MICRO_VERSION = 1 
     10MINOR_VERSION = 9 
     11MICRO_VERSION = 0 
    1212 
    1313VERSION = '%d.%d.%d' % ( MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION ) 
     
    484484     ) 
    485485) 
     486 
     487# vim:sw=4:et