Changeset 463

Show
Ignore:
Timestamp:
11/09/04 23:44:53 (4 years ago)
Author:
arjanmol
Message:

*** empty log message ***

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gaphor/ChangeLog

    r462 r463  
     12004-11-10  Arjan Molenaar  <arjanmolenaar@hetnet.nl> 
     2 
     3        * data/plugins/xmiexport/__init__.py: Added action with save dialog. 
     4        * data/plugins/xmiexport/exportmodel.py: Added timestamp, use 
     5        XMLWriter. 
     6        * FAQ: new file. 
     7 
    182004-11-09  Arjan Molenaar  <arjanmolenaar@hetnet.nl> 
    29 
     
    411        undo can work properly. 
    512        * data/plugins/alignment: Make only sensitive if items are selected. 
     13        * data/plugins/svgexport: New plugin. 
     14        * gaphor/ui/diagramactions.py: Moved SVG export code to svgexport 
     15        plugin. 
     16        * gaphor/diagram/association.py: Moved the Side A/B submenu's in 
     17        separate sub menu's that can be activated when the mouse pointer is 
     18        at the end of the association. 
    619 
    7202004-11-07  Jeroen Vloothuis  <jeroen@vloothuis.net> 
     21 
    822        * data/plugins/alignment: Added a plugin for adjusting the 
    923        alignment of diagram items. Currentyl does horizontal and 
  • trunk/gaphor/NEWS

    r445 r463  
     10.7.0 
     2----- 
     3- XMI export plugin 
     4- Item alignment 
     5- Full featured undo mechanism 
     6- Copy/paste 
     7- usability improvements 
     8- require DiaCanvas2 0.14.2 
     9 
    1100.6.0 
    211----- 
  • trunk/gaphor/TODO

    r445 r463  
    1414- An option that shows the selected item (in the namespace view) in a diagram. 
    1515 
    16 - Copy/Paste for diagramitems 
     16#- Copy/Paste for diagramitems 
    1717  - in order to make copy/paste work, the load/save functions should be 
    1818    generatlised to allow a subset to be saved/loaded (which is needed 
     
    3838  on menu items 
    3939 
    40 #- Undo/redo functionality doesn't work as espected 
    41   ==> Create our own UndoManager, this should also register connect/disconnect 
    42   actions on gaphor.UML classes. 
    43   AJM: Looks like it really works now. 
     40#- Undo/redo functionality 
    4441 
    4542- Exporting diagrams to UML XMI (work in progress), 
  • trunk/gaphor/data/plugins/pngexport/plugin.xml

    r440 r463  
    2929        Add optional dependencies to this action. The action is then updated 
    3030        when actions defined in the depends tag are executed. 
    31       - -> 
    32       <depends action=""/> 
    3331      --> 
     32      <depends action="TabChange"/> 
    3433    </action> 
    3534  </provide> 
  • trunk/gaphor/data/plugins/xmiexport/__init__.py

    r406 r463  
    11# vim:sw=4:et 
    22 
     3import gtk 
    34from exportmodel import XMIExport         
     5from gaphor.plugin import Action 
     6 
     7 
     8class XMIExportAction(Action): 
     9 
     10    def execute(self): 
     11        filesel = gtk.FileSelection('Export model to XMI file') 
     12        filesel.set_modal(True) 
     13        filename = self.get_window().get_filename() 
     14        if filename: 
     15            filename = filename.replace('.gaphor', '.xmi') 
     16        else: 
     17            filename = 'model.xmi' 
     18        filesel.set_filename(filename) 
     19 
     20        response = filesel.run() 
     21        filesel.hide() 
     22        if response == gtk.RESPONSE_OK: 
     23            filename = filesel.get_filename() 
     24            if filename and len(filename) > 0: 
     25                #self.filename = filename 
     26                log.debug('Exporting XMI model to: %s' % filename) 
     27                export = XMIExport() 
     28                try: 
     29                    export.export(filename) 
     30                except Exception, e: 
     31                    log.error('Error while saving model to file %s: %s' % (filename, e)) 
     32 
  • trunk/gaphor/data/plugins/xmiexport/exportmodel.py

    r447 r463  
    11# vim:sw=4:et 
    22 
    3 from xml.sax.saxutils import XMLGenerator 
     3#from xml.sax.saxutils import XMLGenerator 
     4import time 
    45import gaphor 
    56from gaphor import UML 
    6 from gaphor.plugin import Action 
    7  
    8 try: 
    9     dict() 
    10 except: 
    11     from UserDict import UserDict as dict 
     7from gaphor.misc.xmlwriter import XMLWriter 
     8 
    129class XMLAttributes(dict): 
    1310    def getLength(self): 
     
    2724        return self[name] 
    2825 
    29 class XMIExport(Action): 
     26 
     27class XMIExport(object): 
    3028 
    3129    def handleClass(self, xmi, node): 
     
    215213             
    216214             
    217     def export(self): 
    218         out=open('/Users/vloothuis/test.xmi','w') 
    219         xmi=XMLGenerator(out) 
     215    def export(self, filename): 
     216        #out=open('/Users/vloothuis/test.xmi','w') 
     217        out=open(filename,'w') 
     218 
     219        xmi=XMLWriter(out) 
    220220         
    221221        # Start XML generation 
     
    223223        attributes['xmi.version']='1.2' 
    224224        attributes['xmlns:UML']='org.omg.xmi.namespace.UML' 
    225         attributes['timestamp']='Tue Sep 28 10:48:06 CEST 2004' # TODO! 
     225        attributes['timestamp'] = time.strftime('%a %b %d %H:%M:%S %Z %Y') 
    226226        xmi.startElement('XMI', attrs=attributes) 
    227227         
     
    274274        xmi.endElement('XMI.content') 
    275275 
    276     def execute(self): 
    277         self.export() 
    278      
  • trunk/gaphor/data/plugins/xmiexport/plugin.xml

    r406 r463  
    2525            label="XMI Export" 
    2626            tooltip="Export the model to XMI" 
    27             class="XMIExport" slot="FileExportSlot"> 
     27            class="XMIExportAction" slot="FileExportSlot"> 
    2828      <!-- 
    2929        Add optional dependencies to this action. The action is then updated 
  • trunk/gaphor/gaphor/UML

    • Property svn:ignore changed from
      *.pyc
      *.pyo
      modelelements.py
      to
      *.pyc
      *.pyo
  • trunk/gaphor/gaphor/UML/.cvsignore

    r123 r463  
    11*.pyc 
    22*.pyo 
    3 modelelements.py 
  • trunk/gaphor/gaphor/diagram/association.py

    r460 r463  
    5454        'AssociationInvertDirection', 
    5555        'separator', 
    56         'Side _A', ( 
    57             'Head_isNavigable', 
    58             'separator', 
    59             'Head_AggregationNone', 
    60             'Head_AggregationShared', 
    61             'Head_AggregationComposite'), 
    62         'Side _B', ( 
    63             'Tail_isNavigable', 
    64             'separator', 
    65             'Tail_AggregationNone', 
    66             'Tail_AggregationShared', 
    67             'Tail_AggregationComposite') 
     56#        'Side _A', ( 
     57#            'Head_isNavigable', 
     58#            'separator', 
     59#            'Head_AggregationNone', 
     60#            'Head_AggregationShared', 
     61#            'Head_AggregationComposite'), 
     62#        'Side _B', ( 
     63#            'Tail_isNavigable', 
     64#            'separator', 
     65#            'Tail_AggregationNone', 
     66#            'Tail_AggregationShared', 
     67#            'Tail_AggregationComposite') 
    6868    ) 
    6969 
     
    7373        # AssociationEnds are really inseperable from the AssociationItem. 
    7474        # We give them the same id as the association item. 
    75         self._head_end = AssociationEnd(
     75        self._head_end = AssociationEnd(end="head"
    7676        self._head_end.set_child_of(self) 
    77         self._tail_end = AssociationEnd(
     77        self._tail_end = AssociationEnd(end="tail"
    7878        self._tail_end.set_child_of(self) 
    7979 
     
    454454    FONT='sans 10' 
    455455 
    456     def __init__(self, id=None): 
     456    head_popup_menu = ( 
     457        'Head_isNavigable', 
     458        'separator', 
     459        'Head_AggregationNone', 
     460        'Head_AggregationShared', 
     461        'Head_AggregationComposite' 
     462    ) 
     463 
     464    tail_popup_menu = ( 
     465        'Tail_isNavigable', 
     466        'separator', 
     467        'Tail_AggregationNone', 
     468        'Tail_AggregationShared', 
     469        'Tail_AggregationComposite' 
     470    ) 
     471 
     472    def __init__(self, id=None, end=None): 
    457473        self.__gobject_init__() 
    458474        DiagramItem.__init__(self, id) 
     475        self._end = end 
    459476        self.set_flags(diacanvas.COMPOSITE) 
    460477         
     
    477494 
    478495        self._name_bounds = self._mult_bounds = (0, 0, 0, 0) 
     496        self._point1 = self._point2 = (0, 0) 
    479497 
    480498    # Ensure we call the right connect functions: 
     
    486504        DiagramItem.postload(self) 
    487505        #self.set_text() 
     506 
     507    def get_popup_menu(self): 
     508        if self.subject: 
     509            if self._end == 'head': 
     510                return self.head_popup_menu 
     511            else: 
     512                return self.tail_popup_menu 
     513        elif self.parent: 
     514            return self.parent.get_popup_menu() 
    488515 
    489516    def set_text(self): 
     
    630657        self._mult.set_pos((p1[0] + mult_dx, p1[1] + mult_dy)) 
    631658 
     659        self._point1 = p1 
     660        self._point2 = p2 
     661 
    632662    def on_subject_notify(self, pspec, notifiers=()): 
    633663        DiagramItem.on_subject_notify(self, pspec, 
     
    681711        d1 = drp(self._name_bounds, p) 
    682712        d2 = drp(self._mult_bounds, p) 
    683         return min(d1, d2) 
     713        try: 
     714            d3 = diacanvas.geometry.distance_point_point(self._point1, p) 
     715            d4, dummy = diacanvas.geometry.distance_line_point(self._point1, self._point2, p, 1.0, diacanvas.shape.CAP_ROUND) 
     716            if d3 < 15 and d4 < 5: 
     717                d3 = 0.0 
     718        except Exception, e: 
     719            log.error("Could not determine distance", e) 
     720            d3 = 1000.0 
     721        return min(d1, d2, d3) 
    684722 
    685723    def on_shape_iter(self): 
  • trunk/gaphor/gaphor/diagram/itemactions.py

    r455 r463  
    109109    def execute(self): 
    110110        item = get_parent_focus_item(self._window) 
    111         #get_undo_manager().begin_transaction() 
    112111        item.subject.isAbstract = self.active 
    113         #get_undo_manager().commit_transaction() 
    114112 
    115113weave_method(AbstractClassAction.execute, UndoTransactionAspect) 
     
    145143        elemfact = gaphor.resource(UML.ElementFactory) 
    146144         
    147         #get_undo_manager().begin_transaction() 
    148145        attribute = elemfact.create(UML.Property) 
    149146        attribute.parse('new') 
     
    160157                view.start_editing(vf, wx, wy) 
    161158                break 
    162         #get_undo_manager().commit_transaction() 
    163159 
    164160weave_method(CreateAttributeAction.execute, UndoTransactionAspect) 
     
    190186        elemfact = gaphor.resource(UML.ElementFactory) 
    191187 
    192         #get_undo_manager().begin_transaction() 
    193188        operation = elemfact.create(UML.Operation) 
    194189        operation.parse('new()') 
     
    204199                view.start_editing(vf, wx, wy) 
    205200                break 
    206         #get_undo_manager().commit_transaction() 
    207201 
    208202weave_method(CreateOperationAction.execute, UndoTransactionAspect) 
     
    219213        item = self._window.get_current_diagram_view().focus_item.item 
    220214        #assert isinstance(subject, (UML.Property, UML.Operation)) 
    221         #get_undo_manager().begin_transaction() 
    222215        item.subject.unlink() 
    223         #get_undo_manager().commit_transaction() 
    224216 
    225217 
     
    261253    def execute(self): 
    262254        item = get_parent_focus_item(self._window) 
    263         #get_undo_manager().begin_transaction() 
    264255        item.set_property('show-attributes', self.active) 
    265         #get_undo_manager().commit_transaction() 
    266256 
    267257weave_method(DeleteOperationAction.execute, UndoTransactionAspect) 
     
    289279    def execute(self): 
    290280        item = get_parent_focus_item(self._window) 
    291         #get_undo_manager().begin_transaction() 
    292281        item.set_property('show-operations', self.active) 
    293         #get_undo_manager().commit_transaction() 
    294282 
    295283weave_method(ShowOperationsAction.execute, UndoTransactionAspect) 
     
    326314        item, segment = self.get_item_and_segment() 
    327315        if item: 
    328             #get_undo_manager().begin_transaction() 
    329316            item.set_property('add_segment', segment) 
    330             #get_undo_manager().commit_transaction() 
    331317             
    332318weave_method(AddSegmentAction.execute, UndoTransactionAspect) 
     
    350336        item, segment = self.get_item_and_segment() 
    351337        if item: 
    352             #get_undo_manager().begin_transaction() 
    353338            item.set_property('del_segment', segment) 
    354             #get_undo_manager().commit_transaction() 
    355339             
    356340weave_method(DeleteSegmentAction.execute, UndoTransactionAspect) 
     
    377361        fi = get_parent_focus_item(self._window) 
    378362        assert isinstance(fi, diacanvas.CanvasLine) 
    379         #get_undo_manager().begin_transaction() 
    380363        if self.active and len(fi.handles) < 3: 
    381364            fi.set_property('add_segment', 0) 
    382365        fi.set_property('orthogonal', self.active) 
    383         #get_undo_manager().commit_transaction() 
    384366 
    385367weave_method(OrthogonalAction.execute, UndoTransactionAspect) 
     
    407389        fi = get_parent_focus_item(self._window) 
    408390        assert isinstance(fi, diacanvas.CanvasLine) 
    409         #get_undo_manager().begin_transaction() 
    410391        fi.set_property('horizontal', self.active) 
    411         #get_undo_manager().commit_transaction() 
    412392 
    413393weave_method(OrthogonalAlignmentAction.execute, UndoTransactionAspect) 
     
    438418        fi = get_parent_focus_item(self._window) 
    439419        assert isinstance(fi, AssociationItem) 
    440         #get_undo_manager().begin_transaction() 
    441420        fi.set_property('show-direction', self.active) 
    442421 
     
    484463        assert item.subject 
    485464        assert isinstance(item.subject, UML.Property) 
    486         #get_undo_manager().begin_transaction() 
    487465        item.set_navigable(self.active) 
    488         #get_undo_manager().commit_transaction() 
    489466 
    490467weave_method(NavigableAction.execute, UndoTransactionAspect) 
     
    526503            subject = get_parent_focus_item(self._window).get_property(self.end_name).subject 
    527504            assert isinstance(subject, UML.Property) 
    528             #get_undo_manager().begin_transaction() 
    529505            subject.aggregation = self.aggregation 
    530             #get_undo_manager().commit_transaction() 
    531506 
    532507weave_method(AggregationAction.execute, UndoTransactionAspect) 
     
    664639        if self.active: 
    665640            item = get_parent_focus_item(self._window) 
    666             #get_undo_manager().begin_transaction() 
    667641            item.set_dependency_type(self.dependency_type) 
    668642            #item.auto_dependency = False 
    669643            self._window.get_action_pool().execute('AutoDependency', active=False) 
    670             #get_undo_manager().commit_transaction() 
    671644 
    672645weave_method(DependencyTypeAction.execute, UndoTransactionAspect) 
     
    727700    def execute(self): 
    728701        item = get_parent_focus_item(self._window) 
    729         #get_undo_manager().begin_transaction() 
    730702        item.auto_dependency = self.active 
    731         #get_undo_manager().commit_transaction() 
    732703 
    733704weave_method(AutoDependencyAction.execute, UndoTransactionAspect) 
     
    754725    def execute(self): 
    755726        item = get_parent_focus_item(self._window) 
    756         #get_undo_manager().begin_transaction() 
    757727        item.subject.isIndirectlyInstantiated = self.active 
    758         #get_undo_manager().commit_transaction() 
    759728 
    760729weave_method(IndirectlyInstantiatedComponentAction.execute, UndoTransactionAspect) 
     
    803772        # get method to move the element: moveUp or moveDown 
    804773        move = getattr(self._getElements(cls, item), self.move_action) 
    805         #get_undo_manager().begin_transaction() 
    806774        move(item.subject) 
    807         #get_undo_manager().commit_transaction() 
    808775        self._window.execute_action('ItemFocus') 
    809776 
     
    856823        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    857824 
    858         #get_undo_manager().begin_transaction() 
    859825        item.set_property('drawing-style', InterfaceItem.DRAW_ICON) 
    860         #get_undo_manager().commit_transaction() 
    861826 
    862827weave_method(FoldAction.execute, UndoTransactionAspect) 
     
    873838        #log.debug('Action %s: %s' % (self.id, item.subject.name)) 
    874839 
    875         #get_undo_manager().begin_transaction() 
    876840        item.set_property('drawing-style', InterfaceItem.DRAW_COMPARTMENT) 
    877         #get_undo_manager().commit_transaction() 
    878841        # Make sure lines are updated properly: 
    879842        item.canvas.update_now() 
     
    902865        else: 
    903866            self.sensitive = isinstance(item, ClassItem) 
    904             if self.sensitive
     867            if self.sensitive and item.subject
    905868                self.active = self.stereotype in item.subject.appliedStereotype 
     869            else: 
     870                self.active = False 
    906871 
    907872    def execute(self): 
    908873        item = get_parent_focus_item(self._window) 
    909         #get_undo_manager().begin_transaction() 
    910874        if self.active: 
    911875            item.subject.appliedStereotype = self.stereotype 
    912876        else: 
    913877            del item.subject.appliedStereotype[self.stereotype] 
    914         #get_undo_manager().commit_transaction() 
    915878 
    916879weave_method(ApplyStereotypeAction.execute, UndoTransactionAspect) 
  • trunk/gaphor/gaphor/ui/diagramactions.py

    r460 r463  
    3434register_action(CloseTabAction) 
    3535 
    36  
    37 class ExportSVGAction(Action): 
    38     id = 'FileExportSVG' 
    39     label = '_Export SVG' 
    40     tooltip = 'Write the contents of this diagram to a SVG file' 
    41  
    42     def init(self, window): 
    43         self.filename = None 
    44         self._window = window 
    45  
    46     def update(self): 
    47         tab = self._window.get_current_diagram_tab() 
    48         self.sensitive = tab and True or False 
    49  
    50     def execute(self): 
    51         filesel = gtk.FileSelection('Export diagram to SVG file') 
    52         filesel.set_modal(True) 
    53         filesel.set_filename(self.filename or self._window.get_current_diagram().name + '.svg' or 'export.svg') 
    54  
    55         #filesel.ok_button.connect('clicked', self.on_ok_button_pressed, filesel) 
    56         #filesel.cancel_button.connect('clicked', 
    57         #                             self.on_cancel_button_pressed, filesel) 
    58          
    59         #filesel.show() 
    60         response = filesel.run() 
    61         filesel.hide() 
    62         if response == gtk.RESPONSE_OK: 
    63             filename = filesel.get_filename() 
    64             if filename and len(filename) > 0: 
    65                 self.filename = filename 
    66                 log.debug('Exporting SVG image to: %s' % filename) 
    67                 canvas = self._window.get_current_diagram_tab().get_canvas() 
    68                 export = diacanvas.ExportSVG() 
    69                 try: 
    70                     export.render (canvas) 
    71                     export.save(filename) 
    72                 except Exception, e: 
    73                     log.error('Error while saving model to file %s: %s' % (filename, e)) 
    74  
    75 register_action(ExportSVGAction) 
    7636 
    7737class UndoStackAction(Action): 
  • trunk/gaphor/gaphor/ui/mainwindow.py

    r460 r463  
    6969                    '<FileImportSlot>',), 
    7070                _('_Export'), ( 
    71                     'FileExportSVG', 
    72                     '<FileExportSlot>'), 
     71                    '<FileExportSlot>',), 
    7372                'separator', 
    7473                'FileCloseTab',