Changeset 1351
- Timestamp:
- 06/11/07 04:15:48 (1 year ago)
- Files:
-
- gaphor/trunk/gaphor/plugins/diagramlayout/__init__.py (modified) (11 diffs)
- gaphor/trunk/gaphor/plugins/diagramlayout/tests (added)
- gaphor/trunk/gaphor/plugins/diagramlayout/tests/test_diagramlayout.py (added)
- gaphor/trunk/gaphor/plugins/pynsource/__init__.py (modified) (3 diffs)
- gaphor/trunk/gaphor/plugins/pynsource/engineer.py (modified) (12 diffs)
- gaphor/trunk/gaphor/plugins/xmiexport/__init__.py (modified) (1 diff)
- gaphor/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/gaphor/plugins/diagramlayout/__init__.py
r543 r1351 1 # vim:sw=4:et 2 """This module provides a means to automatocally layout diagrams.1 """ 2 This module provides a means to automatocally layout diagrams. 3 3 4 4 The layout is done like this: … … 10 10 """ 11 11 12 import gaphor.plugin 12 __plugin__ = 'diagram_layout' 13 __version__ = '0.1' 14 __author__ = 'Arjan Molenaar' 15 16 from zope import interface, component 17 from gaphor.core import _, inject, action, build_action_group 18 from gaphor.interfaces import IService, IActionProvider 19 13 20 import random 14 from gaphor import diagram21 from gaphor.diagram import items 15 22 import toposort 16 23 17 class DiagramLayoutAction(gaphor.plugin.Action): 24 25 class DiagramLayout(object): 26 27 interface.implements(IService, IActionProvider) 28 29 gui_manager = inject('gui_manager') 30 31 menu_xml = """ 32 <ui> 33 <menubar action="mainwindow"> 34 <menu action="diagram"> 35 <menuitem action="diagram-layout" /> 36 </menu> 37 </menubar> 38 </ui>""" 39 40 def __init__(self): 41 self.action_group = build_action_group(self) 42 43 def init(self, app): 44 pass 45 46 def shutdown(self): 47 pass 18 48 19 49 def update(self): 20 50 self.sensitive = bool(self.get_window().get_current_diagram()) 21 51 52 @action(name='diagram-layout', label='Layout diagram', 53 tooltip='simple diagram layout') 22 54 def execute(self): 23 d = self.get_window().get_current_diagram() 24 if d: 25 layout_diagram(d) 55 d = self.gui_manager.main_window.get_current_diagram() 56 layout_diagram(d) 57 58 def layout_diagram(self, diag): 59 layout_diagram(diag) 26 60 27 61 … … 29 63 30 64 def layout_diagram(diag): 31 """So an attempt to layout (order) the items on a diagram. The items 65 """ 66 So an attempt to layout (order) the items on a diagram. The items 32 67 should already be placed on the diagram and the items should already be 33 68 connected. … … 47 82 # First extract data from the diagram (which ones are the nodes, and 48 83 # the relationships). 49 for item in diag.canvas. root.children:50 if isinstance(item, ( diagram.GeneralizationItem,51 diagram.ImplementationItem)):84 for item in diag.canvas.get_root_items(): 85 if isinstance(item, (items.GeneralizationItem, 86 items.ImplementationItem)): 52 87 # Primary relationships, should be drawn top-down 53 88 try: … … 57 92 except Exception, e: 58 93 log.error(e) 59 elif isinstance(item, diagram.diagramline.DiagramLine):94 elif isinstance(item, items.DiagramLine): 60 95 # Secondary (associations, dependencies) may be drawn top-down 61 96 # or left-right … … 113 148 continue 114 149 maxy = max(maxy, item.height) 115 a = item. get_property('affine')150 a = item.matrix 116 151 a = (a[0], a[1], a[2], a[3], x, y) 117 item.set_property('affine', a) 152 item.matrix = a 153 item.request_update() 118 154 x += item.width + MARGIN 119 155 y += maxy + MARGIN … … 124 160 125 161 def simple_layout_lines(diag): 126 """Just do the layout of the lines in a diagram. The nodes (class, package) 162 """ 163 Just do the layout of the lines in a diagram. The nodes (class, package) 127 164 are left where they are (use layout_diagram() if you want to reorder 128 165 everything). … … 132 169 """ 133 170 lines = {} 134 for item in diag.canvas. root.children:135 if isinstance(item, diagram.diagramline.DiagramLine):171 for item in diag.canvas.get_root_items(): 172 if isinstance(item, items.DiagramLine): 136 173 # Secondary (associations, dependencies) may be drawn top-down 137 174 # or left-right … … 172 209 173 210 def find_related_nodes(item, relations): 174 """Find related nodes of item, given a list of tuples. 211 """ 212 Find related nodes of item, given a list of tuples. 175 213 References to itself are ignored. 176 214 """ … … 187 225 188 226 def find_row(item, related_items, sorted): 189 """Find the row that contains the most references to item. 227 """ 228 Find the row that contains the most references to item. 190 229 """ 191 230 max_refs = 0 … … 199 238 200 239 def find_center(item): 201 """Find the center point of the item, in world coordinates 240 """ 241 Find the center point of the item, in world coordinates 202 242 """ 203 243 x = item.width / 2.0 204 244 y = item.height / 2.0 205 return item.affine_point_i2w(x, y) 245 return item.canvas.get_matrix_i2w(item).transform_point(x, y) 246 247 # vim:sw=4:et gaphor/trunk/gaphor/plugins/pynsource/__init__.py
r1244 r1351 1 # vim:sw=4:et: 2 3 4 import sys 5 import os 1 """ 2 Code reverse engineer plugin for Python source code. 3 4 This plugin uses PyNSource, written by Andy Bulka 5 [http://www.atug.com/andypatterns/pynsource.htm]. 6 7 Depends on the Diagram Layout plugin. 8 """ 9 10 __plugin__ = 'PyNSource' 11 __version__ = '0.1' 12 __author__ = 'Arjan Molenaar' 13 6 14 import gobject 7 import pango8 15 import gtk 9 import gaphor 10 from gaphor.ui.abstractwindow import AbstractWindow 11 from gaphor.core import inject 12 import gaphor.plugin 13 from pynsource import PySourceAsText 16 from zope import interface, component 17 from gaphor.core import _, inject, action, build_action_group 18 from gaphor.interfaces import IService, IActionProvider 19 14 20 from engineer import Engineer 15 21 22 16 23 NAME_COLUMN = 0 17 24 18 25 19 class PyNSourceAction(gaphor.plugin.Action): 20 21 action_manager = inject('action_manager') 26 class PyNSource(object): 27 28 interface.implements(IService, IActionProvider) 29 30 gui_manager = inject('gui_manager') 31 32 menu_xml = """ 33 <ui> 34 <menubar action="mainwindow"> 35 <menu action="file"> 36 <menu action="file-import"> 37 <menuitem action="file-import-pynsource" /> 38 </menu> 39 </menu> 40 </menubar> 41 </ui>""" 22 42 23 43 def __init__(self): 24 gaphor.plugin.Action.__init__(self)25 44 self.win = None 26 45 self.action_group = build_action_group(self) 46 47 def init(self, app): 48 pass 49 50 def shutdown(self): 51 pass 52 53 @action(name='file-import-pynsource', label='Python source code', 54 tooltip='Import Python source code') 27 55 def execute(self): 28 56 dialog = self.create_dialog() … … 49 77 engineer.process(files) 50 78 51 main_window = self.g et_window()79 main_window = self.gui_manager.main_window 52 80 # Open and select the new diagram in the main window: 53 81 main_window.select_element(engineer.diagram) 54 self.action_manager.execute('OpenModelElement')82 main_window.show_diagram(engineer.diagram) 55 83 56 84 def create_dialog(self): 57 85 dialog = gtk.Dialog("Import Python files", 58 self.g et_window().get_window(),86 self.gui_manager.main_window.window, 59 87 gtk.DIALOG_MODAL, 60 88 (gtk.STOCK_OK, gtk.RESPONSE_OK, … … 177 205 178 206 179 if __name__ in ('__main__', '__builtin__'): 180 print 'Loading...' 181 import gtk 182 win = PyNSourceWindow() 183 win.construct() 184 win.get_window().connect('destroy', lambda e: gtk.main_quit()) 185 gtk.main() 186 207 # vim:sw=4:et:ai gaphor/trunk/gaphor/plugins/pynsource/engineer.py
r1219 r1351 4 4 """ 5 5 6 from zope import component 6 7 from gaphor import UML 7 from gaphor import diagram 8 from gaphor.plugin import import_plugin 8 from gaphor.diagram import items 9 from gaphor.core import inject 10 from gaphor.diagram.interfaces import IConnect 9 11 10 12 from pynsource import PySourceAsText … … 13 15 14 16 class Engineer(object): 15 """The Engineer class will create a Gaphor model based on a list of Python 17 """ 18 The Engineer class will create a Gaphor model based on a list of Python 16 19 files. 17 20 """ 21 22 element_factory = inject('element_factory') 23 diagram_layout = inject('diagram_layout') 18 24 19 25 def process(self, files=None): … … 35 41 36 42 try: 37 self._root_package = UML.lselect(lambda e: isinstance(e, UML.Package) and not e.namespace)[0]43 self._root_package = self.element_factory.lselect(lambda e: isinstance(e, UML.Package) and not e.namespace)[0] 38 44 except IndexError: 39 45 pass # running as test? … … 43 49 44 50 # Step 0: create a diagram to put the newly created elements on 45 self.diagram = UML.create(UML.Diagram)51 self.diagram = self.element_factory.create(UML.Diagram) 46 52 self.diagram.name = 'New classes' 47 53 self.diagram.package = self._root_package … … 64 70 self._create_methods(clazz) 65 71 66 layout_diagram = None 67 try: 68 layout_diagram = import_plugin('diagramlayout').layout_diagram 69 except ImportError, e: 70 log.error('Could not import diagramlayout module', e) 71 else: 72 layout_diagram(self.diagram) 72 self.diagram_layout.layout_diagram(self.diagram) 73 73 74 74 def _create_class(self, clazz, name): 75 c = UML.create(UML.Class)75 c = self.element_factory.create(UML.Class) 76 76 c.name = name 77 77 c.package = self.diagram.namespace 78 ci = self.diagram.create( diagram.ClassItem)78 ci = self.diagram.create(items.ClassItem) 79 79 ci.subject = c 80 80 clazz.gaphor_class = c … … 91 91 except KeyError, e: 92 92 print 'No class found named', superclassname 93 others = UML.lselect(lambda e: isinstance(e, UML.Class) and e.name == superclassname)93 others = self.element_factory.lselect(lambda e: isinstance(e, UML.Class) and e.name == superclassname) 94 94 if others: 95 95 superclass = others[0] 96 96 print 'Found class in factory: %s' % superclass.name 97 superclass_item = self.diagram.create( diagram.ClassItem)97 superclass_item = self.diagram.create(items.ClassItem) 98 98 superclass_item.subject = superclass 99 99 else: … … 101 101 # Finally, create the generalization relationship 102 102 print 'Creating Generalization for %s' % clazz, superclass 103 gen = UML.create(UML.Generalization)103 gen = self.element_factory.create(UML.Generalization) 104 104 gen.general = superclass 105 105 gen.specific = clazz.gaphor_class 106 geni = self.diagram.create( diagram.GeneralizationItem)106 geni = self.diagram.create(items.GeneralizationItem) 107 107 geni.subject = gen 108 superclass_item.connect_handle(geni.handles[0]) 109 clazz.gaphor_class_item.connect_handle(geni.handles[-1]) 108 109 adapter = component.queryMultiAdapter((superclass_item, geni), IConnect) 110 assert adapter 111 handle = geni.handles()[0] 112 adapter.connect(handle, handle.x, handle.y) 113 #clazz.gaphor_class_item.connect_handle(geni.handles[-1]) 114 adapter = component.queryMultiAdapter((clazz.gaphor_class_item, geni), IConnect) 115 assert adapter 116 handle = geni.handles()[-1] 117 adapter.connect(handle, handle.x, handle.y) 110 118 111 119 def _create_attributes(self, clazz): … … 117 125 def _create_methods(self, clazz): 118 126 for adef in clazz.defs: 119 op = UML.create(UML.Operation)127 op = self.element_factory.create(UML.Operation) 120 128 op.name = adef 121 129 clazz.gaphor_class.ownedOperation = op … … 127 135 except KeyError, e: 128 136 print 'No class found named', classname 129 others = UML.lselect(lambda e: isinstance(e, UML.Class) and e.name == classname)137 others = self.element_factory.lselect(lambda e: isinstance(e, UML.Class) and e.name == classname) 130 138 if others: 131 139 superclass = others[0] 132 140 print 'Found class in factory: %s' % superclass.name 133 superclass_item = self.diagram.create( diagram.ClassItem)141 superclass_item = self.diagram.create(items.ClassItem) 134 142 superclass_item.subject = superclass 135 143 else: … … 164 172 head_type_item = clazz.gaphor_class_item 165 173 166 relation = UML.create(UML.Association)167 head_end = UML.create(UML.Property)168 head_end.lowerValue = UML.create(UML.LiteralSpecification)169 tail_end = UML.create(UML.Property)174 relation = self.element_factory.create(UML.Association) 175 head_end = self.element_factory.create(UML.Property) 176 head_end.lowerValue = self.element_factory.create(UML.LiteralSpecification) 177 tail_end = self.element_factory.create(UML.Property) 170 178 tail_end.name = attr.attrname 171 179 tail_end.visibility = self._visibility(attr.attrname) 172 180 tail_end.aggregation = 'composite' 173 tail_end.lowerValue = UML.create(UML.LiteralSpecification)181 tail_end.lowerValue = self.element_factory.create(UML.LiteralSpecification) 174 182 relation.package = self.diagram.namespace 175 183 relation.memberEnd = head_end … … 181 189 182 190 # Now create the diagram item: 183 association = self.diagram.create( diagram.AssociationItem)191 association = self.diagram.create(items.AssociationItem) 184 192 185 193 # First connect one handle: 186 head_type_item.connect_handle(association.handles[0]) 194 #head_type_item.connect_handle(association.handles[0]) 195 adapter = component.queryMultiAdapter((head_type_item, association), IConnect) 196 assert adapter 197 handle = association.handles()[0] 198 adapter.connect(handle, handle.x, handle.y) 199 187 200 188 201 # Now the subject … … 194 207 # an Association. in stead the association applied as subject 195 208 # is used. 196 tail_type_item.connect_handle(association.handles[-1]) 209 #tail_type_item.connect_handle(association.handles[-1]) 210 adapter = component.queryMultiAdapter((tail_type_item, association), IConnect) 211 assert adapter 212 handle = association.handles()[-1] 213 adapter.connect(handle, handle.x, handle.y) 197 214 198 215 else: 199 216 # Create a simple attribute: 200 217 #print "%s %s" % (attr.attrname, static) 201 prop = UML.create(UML.Property)218 prop = self.element_factory.create(UML.Property) 202 219 prop.name = attr.attrname 203 220 prop.visibility = self._visibility(attr.attrname) gaphor/trunk/gaphor/plugins/xmiexport/__init__.py
r1348 r1351 6 6 __version__ = "0.1" 7 7 __author__ = "Jeroen Vloothuis" 8 __description__ = 'This plugin extends Gaphor with XMI export functionality.'9 8 10 9 import gtk gaphor/trunk/setup.py
r1348 r1351 129 129 'copy = gaphor.services.copyservice:CopyService', 130 130 'xmi_export = gaphor.plugins.xmiexport:XMIExport', 131 'diagram_layout = gaphor.plugins.diagramlayout:DiagramLayout', 132 'pynsource = gaphor.plugins.pynsource:PyNSource', 131 133 ], 132 134 'gaphor.uicomponents': [
