Changeset 1559

Show
Ignore:
Timestamp:
07/02/07 23:53:34 (1 year ago)
Author:
arj..@yirdis.nl
Message:

fixed bug in storage module. Make constraints connect properly when loading a model.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/trunk/gaphor/UML/diagram.py

    r1502 r1559  
    8585            obj.subject = subject 
    8686        self.canvas.add(obj, parent) 
    87         for kid in obj._items: 
    88             self.canvas.add(kid, parent=obj) 
     87#        for kid in obj._items: 
     88#            self.canvas.add(kid, parent=obj) 
    8989        return obj 
    9090 
  • gaphor/trunk/gaphor/adapters/grouping.py

    r1502 r1559  
    8181    def group(self): 
    8282        self.parent.subject.lifeline = self.item.subject 
    83         self.parent.add_item(self.item) 
     83        self.parent.canvas.reparent(self.item, self.parent) 
     84        #self.parent.add_item(self.item) 
    8485 
    8586 
  • gaphor/trunk/gaphor/diagram/classifier.py

    r1470 r1559  
    179179            self._drawing_style = style 
    180180            self.request_update() 
     181#            if self.canvas: 
     182#                request_resolve = self.canvas.solver.request_resolve 
     183#                for h in self._handles:  
     184#                    request_resolve(h.x) 
     185#                    request_resolve(h.y) 
    181186 
    182187        if self._drawing_style == self.DRAW_COMPARTMENT: 
     
    267272    def pre_update_compartment_icon(self, context): 
    268273        self.pre_update_compartment(context) 
     274        # icon width plus right margin 
    269275        self.min_width = max(self.min_width, 
    270                 self._header_size[0] + self.ICON_WIDTH + 10) # icon width plus right margin 
     276                self._header_size[0] + self.ICON_WIDTH + 10) 
    271277 
    272278    def pre_update_icon(self, context): 
  • gaphor/trunk/gaphor/diagram/diagramitem.py

    r1514 r1559  
    282282        self._persistent_props = set() 
    283283 
    284         self._items = [] 
    285284 
    286285    id = property(lambda self: self._id, doc='Id') 
    287  
    288  
    289     def add_item(self, item): 
    290         self._items.append(item) 
    291286 
    292287 
     
    309304            save_func(p, getattr(self, p.replace('-', '_')), reference=True) 
    310305 
    311         parent = self.canvas.get_parent(self) 
    312         if parent: 
    313             save_func('parent', parent, reference=True) 
    314  
    315         # save kids 
    316         if self._items: 
    317             save_func('items', self._items) 
    318  
    319306 
    320307    def load(self, name, value): 
    321         self._parent = None # temporary value to be killed in postload 
    322308        if name == 'subject': 
    323309            type(self).subject.load(self, value) 
    324         elif name == 'items': 
    325             self._items.append(value) 
    326310        else: 
    327311            #log.debug('Setting unknown property "%s" -> "%s"' % (name, value)) 
     
    334318        if self.subject: 
    335319            self.on_subject_notify(type(self).subject) 
    336         for item in self._items: 
    337             self.canvas.reparent(item, self) 
    338             assert self is self.canvas.get_parent(item) 
    339320 
    340321 
     
    357338        """ 
    358339        if self.canvas: 
    359             self.canvas.remove(self) 
     340            try: 
     341                self.canvas.remove(self) 
     342            except KeyError: 
     343                # Canvas was already removed 
     344                pass 
    360345        self.subject = None 
    361346        super(DiagramItem, self).unlink() 
  • gaphor/trunk/gaphor/diagram/diagramline.py

    r1536 r1559  
    106106        # lazy and are resolved by the constraint solver rather than set 
    107107        # directly. 
    108         self.canvas.update_matrix(self) 
    109         self.canvas.solver.solve() 
     108        #self.canvas.update_matrix(self) 
     109        #self.canvas.solver.solve() 
    110110 
    111111        if hasattr(self, '_load_head_connection'): 
     
    114114            h = self.head 
    115115 
    116             x, y = self.canvas.get_matrix_i2w(self, calculate=True).transform_point(h.x, h.y) 
    117             x, y = self.canvas.get_matrix_w2i(self._load_head_connection, calculate=True).transform_point(x, y) 
     116            x, y = self.canvas.get_matrix_i2w(self).transform_point(h.x, h.y) 
     117            x, y = self.canvas.get_matrix_w2i(self._load_head_connection).transform_point(x, y) 
    118118            adapter.connect(h, x, y) 
    119119            del self._load_head_connection 
     120 
    120121        if hasattr(self, '_load_tail_connection'): 
    121122            adapter = component.queryMultiAdapter((self._load_tail_connection, self), IConnect) 
     
    123124            h = self.tail 
    124125 
    125             x, y = self.canvas.get_matrix_i2w(self, calculate=True).transform_point(h.x, h.y) 
    126             x, y = self.canvas.get_matrix_w2i(self._load_tail_connection, calculate=True).transform_point(x, y) 
     126            x, y = self.canvas.get_matrix_i2w(self).transform_point(h.x, h.y) 
     127            x, y = self.canvas.get_matrix_w2i(self._load_tail_connection).transform_point(x, y) 
    127128            adapter.connect(h, x, y) 
    128129            del self._load_tail_connection 
  • gaphor/trunk/gaphor/diagram/interface.py

    r1505 r1559  
    121121        super(InterfaceItem, self).pre_update_icon(context) 
    122122 
    123  
    124123    def draw_icon(self, context): 
    125124        cr = context.cairo 
  • gaphor/trunk/gaphor/storage.py

    r1502 r1559  
    3939 
    4040def save_generator(writer, factory): 
    41     """Save the current model using @writer, which is a 
     41    """ 
     42    Save the current model using @writer, which is a 
    4243    gaphor.misc.xmlwriter.XMLWriter instance (or at least a SAX serializer 
    4344    with CDATA support). 
    4445    """ 
    45     # Make bool work for Python 2.2 
    46     bool_ = type(bool(0)) 
    4746 
    4847    def save_reference(name, value): 
    49         """Save a value as a reference to another element in the model. 
     48        """ 
     49        Save a value as a reference to another element in the model. 
    5050        This applies to both UML as well as canvas items. 
    5151        """ 
     
    5858 
    5959    def save_collection(name, value): 
    60         """Save a list of references. 
     60        """ 
     61        Save a list of references. 
    6162        """ 
    6263        if len(value) > 0: 
     
    7273 
    7374    def save_value(name, value): 
    74         """Save a value (attribute). 
     75        """ 
     76        Save a value (attribute). 
    7577        If the value is a string, it is saves as a CDATA block. 
    7678        """ 
     
    8284                writer.characters(value) 
    8385                writer.endCDATA() 
    84             elif isinstance(value, bool_): 
     86            elif isinstance(value, bool): 
    8587                # Write booleans as 0/1. 
    8688                writer.characters(str(int(value))) 
     
    9193 
    9294    def save_element(name, value): 
    93         """Save attributes and references from items in the gaphor.UML module. 
     95        """ 
     96        Save attributes and references from items in the gaphor.UML module. 
    9497        A value may be a primitive (string, int), a gaphor.UML.collection 
    9598        (which contains a list of references to other UML elements) or a 
     
    109112 
    110113    def save_canvasitem(name, value, reference=False): 
    111         """Save attributes and references in a gaphor.diagram.* object. 
     114        """ 
     115        Save attributes and references in a gaphor.diagram.* object. 
    112116        The extra attribute reference can be used to force UML  
    113117        """ 
     
    115119        if reference: 
    116120            save_reference(name, value) 
    117         elif isinstance(value, (UML.collection, list)): 
     121        elif isinstance(value, UML.collection): 
    118122            save_collection(name, value) 
    119123        elif isinstance(value, gaphas.Item): 
     
    121125                                          'type': value.__class__.__name__ }) 
    122126            value.save(save_canvasitem) 
     127 
     128            # save subitems 
     129            for child in value.canvas.get_children(value): 
     130                save_canvasitem(None, child) 
     131#                writer.startElement('item', { 'id': child.id, 
     132#                                              'type': kid.__class__.__name__ }) 
     133#                child.save(save_canvasitem) 
     134#                writer.endElement('item') 
     135 
    123136            writer.endElement('item') 
    124  
    125             # save subitems 
    126             for kid in value._items: 
    127                 writer.startElement('item', { 
    128                     'id': kid.id, 
    129                     'type': kid.__class__.__name__ }) 
    130                 kid.save(save_canvasitem) 
    131                 writer.endElement('item') 
    132137 
    133138        elif isinstance(value, UML.Element): 
     
    163168 
    164169def load_elements_generator(elements, factory, gaphor_version=None): 
    165     """Load a file and create a model if possible. 
     170    """ 
     171    Load a file and create a model if possible. 
    166172    Exceptions: IOError, ValueError. 
    167173    """ 
     
    273279    # no need for special function. 
    274280 
     281    for d in factory.select(lambda e: isinstance(e, UML.Diagram)): 
     282        # update_now() is implicitly called when lock is released 
     283        d.canvas.block_updates = False 
     284 
    275285    # do a postload: 
    276286    for id, elem in elements.items(): 
     
    278288        elem.element.postload() 
    279289 
    280     # Unlock canvas's for updates 
    281     for id, elem in elements.items(): 
    282         if isinstance(elem, parser.element) and elem.canvas: 
    283             elem.element.canvas.block_updates = False 
    284  
    285290    factory.notify_model() 
    286291 
    287292 
    288293def load(filename, factory, status_queue=None): 
    289     """Load a file and create a model if possible. 
     294    """ 
     295    Load a file and create a model if possible. 
    290296    Optionally, a status queue function can be given, to which the 
    291297    progress is written (as status_queue(progress)). 
     
    297303 
    298304def load_generator(filename, factory): 
    299     """Load a file and create a model if possible. 
     305    """ 
     306    Load a file and create a model if possible. 
    300307    This function is a generator. It will yield values from 0 to 100 (%) 
    301308    to indicate its progression.