Changeset 1046
- Timestamp:
- 10/25/06 23:26:45 (2 years ago)
- Files:
-
- gaphor/branches/new-canvas/gaphor/actions/diagramactions.py (modified) (4 diffs)
- gaphor/branches/new-canvas/gaphor/actions/itemactions.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/actions/placementactions.py (modified) (6 diffs)
- gaphor/branches/new-canvas/gaphor/actions/tests/test_placementactions.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py (modified) (5 diffs)
- gaphor/branches/new-canvas/gaphor/diagram/items.py (modified) (1 diff)
- gaphor/branches/new-canvas/gaphor/diagram/usecase.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/branches/new-canvas/gaphor/actions/diagramactions.py
r1006 r1046 196 196 # Confirm deletion of last views to model objects 197 197 # They will be deleted along with their last view 198 if not self.mayRemoveFromMod al(view):198 if not self.mayRemoveFromModel(view): 199 199 return 200 200 … … 204 204 items = view.selected_items 205 205 for i in items: 206 i. item.unlink()206 i.unlink() 207 207 finally: 208 208 get_undo_manager().commit_transaction() 209 209 210 def mayRemoveFromMod al(self, view):210 def mayRemoveFromModel(self, view): 211 211 ''' Check if there are items which will be deleted from the model (when their last views are deleted). If so request user confirmation before deletion. ''' 212 212 items = view.selected_items … … 218 218 def isLastView(self, item): 219 219 ''' Check if the current view is the last view to its object ''' 220 if item. item.subject and len(item.item.subject.presentation)==1:220 if item.subject and len(item.subject.presentation)==1: 221 221 return True 222 222 return False … … 274 274 copy_items = [] 275 275 for i in items: 276 copy_items.append(i .item)277 #i. item.save(save_func)276 copy_items.append(i) 277 #i.save(save_func) 278 278 if copy_items: 279 279 resource.set('copy-buffer', copy_items) gaphor/branches/new-canvas/gaphor/actions/itemactions.py
r1044 r1046 3 3 Commands related to the Diagram (DiaCanvas) 4 4 """ 5 6 from __future__ import generators7 8 5 9 6 from gaphor import GaphorError, resource gaphor/branches/new-canvas/gaphor/actions/placementactions.py
r1029 r1046 179 179 180 180 181 class InterfacePlacementTool(gaphas.tool.PlacementTool):182 """The Interface placement tool creates an InterfaceItem and a183 DependencyItem (for the Implementation relationship) on the diagram.184 """185 186 def __init__(self, window, action_id):187 gaphas.tool.PlacementTool.__init__(self, None)188 self._window = window189 self.action_id = action_id190 self.handle_tool = diacanvas.view.HandleTool()191 192 def do_button_press_event(self, view, event):193 factory = resource(UML.ElementFactory)194 diag = self._window.get_current_diagram()195 iface = factory.create(UML.Interface)196 iface.package = diag.namespace197 iface_item = diag.create(interface.InterfaceItem)198 iface_item.set_property('parent', view.canvas.root)199 iface_item.subject = iface200 impl_item = diag.create(dependency.DependencyItem)201 impl_item.set_dependency_type(UML.Implementation)202 impl_item.set_property('parent', view.canvas.root)203 204 wx, wy = view.window_to_world(event.x, event.y)205 ix, iy = iface_item.affine_point_w2i(wx, wy)206 iface_item.move(ix, iy)207 208 ix += iface_item.RADIUS * 2209 iy += iface_item.RADIUS210 impl_item.move(ix, iy)211 212 # Select the new items:213 view.unselect_all()214 view.select(iface_item)215 view.focus(impl_item)216 217 # Attach the head handle to the interface item:218 first = impl_item.head219 iface_item.connect_handle(first)220 221 # Grab the last handle with the mouse cursor222 last = impl_item.last223 last.set_pos_i(20,0)224 #self.handle_tool.set_grabbed_handle(last)225 return True226 227 def do_button_release_event(self, view, event):228 view.set_tool(None)229 return self.handle_tool.button_release(view, event)230 231 def do_motion_notify_event(self, view, event):232 return self.handle_tool.motion_notify(view, event)233 234 #import gobject235 #gobject.type_register(InterfacePlacementTool)236 237 181 class InterfacePlacementAction(NamespacePlacementAction): 238 182 id = 'InsertInterface' … … 244 188 subject_type = UML.Interface 245 189 246 # def _execute(self):247 # tool = InterfacePlacementTool(self._window, self.id)248 # self._window.get_current_diagram_view().set_tool(tool)249 # self._window.set_message('Create new %s' % self.name)250 251 190 register_action(InterfacePlacementAction) 252 191 … … 288 227 289 228 290 #class InitialNodePlacementAction(PlacementAction):291 #id = 'InsertInitialNode'292 #label = 'Initial Node'293 #tooltip = 'Create a new initial node'294 #stock_id = 'gaphor-initial-node'295 #name = 'InitialNode'296 #type = items.InitialNodeItem297 #subject_type = UML.InitialNode298 # 299 #register_action(InitialNodePlacementAction)300 301 302 #class ActivityFinalNodePlacementAction(PlacementAction):303 #id = 'InsertActivityFinalNode'304 #label = 'Activity Final Node'305 #tooltip = 'Create a new activity final node'306 #stock_id = 'gaphor-activity-final-node'307 #name = 'ActivityFinalNode'308 # type = diagram.ActivityFinalNodeItem309 #subject_type = UML.ActivityFinalNode310 # 311 #register_action(ActivityFinalNodePlacementAction)312 313 314 #class FlowFinalNodePlacementAction(PlacementAction):315 #id = 'InsertFlowFinalNode'316 #label = 'Flow Final Node'317 #tooltip = 'Create a new flow final node'318 #stock_id = 'gaphor-flow-final-node'319 #name = 'FlowFinalNode'320 # type = diagram.FlowFinalNodeItem321 #subject_type = UML.FlowFinalNode322 # 323 #register_action(FlowFinalNodePlacementAction)229 class InitialNodePlacementAction(PlacementAction): 230 id = 'InsertInitialNode' 231 label = 'Initial Node' 232 tooltip = 'Create a new initial node' 233 stock_id = 'gaphor-initial-node' 234 name = 'InitialNode' 235 type = items.InitialNodeItem 236 subject_type = UML.InitialNode 237 238 register_action(InitialNodePlacementAction) 239 240 241 class ActivityFinalNodePlacementAction(PlacementAction): 242 id = 'InsertActivityFinalNode' 243 label = 'Activity Final Node' 244 tooltip = 'Create a new activity final node' 245 stock_id = 'gaphor-activity-final-node' 246 name = 'ActivityFinalNode' 247 type = items.ActivityFinalNodeItem 248 subject_type = UML.ActivityFinalNode 249 250 register_action(ActivityFinalNodePlacementAction) 251 252 253 class FlowFinalNodePlacementAction(PlacementAction): 254 id = 'InsertFlowFinalNode' 255 label = 'Flow Final Node' 256 tooltip = 'Create a new flow final node' 257 stock_id = 'gaphor-flow-final-node' 258 name = 'FlowFinalNode' 259 type = items.FlowFinalNodeItem 260 subject_type = UML.FlowFinalNode 261 262 register_action(FlowFinalNodePlacementAction) 324 263 325 264 … … 406 345 407 346 408 #class UseCaseAssociationPlacementAction(AssociationPlacementAction):409 #id = 'InsertUseCaseAssociation'410 # 411 #register_action(UseCaseAssociationPlacementAction)347 class UseCaseAssociationPlacementAction(AssociationPlacementAction): 348 id = 'InsertUseCaseAssociation' 349 350 register_action(UseCaseAssociationPlacementAction) 412 351 413 352 … … 525 464 register_action(NodePlacementAction) 526 465 466 527 467 #class InteractionPlacementAction(NamespacePlacementAction): 528 468 # id = 'InsertInteraction' … … 535 475 # 536 476 #register_action(InteractionPlacementAction) 477 537 478 538 479 #class LifelinePlacementAction(PlacementAction): gaphor/branches/new-canvas/gaphor/actions/tests/test_placementactions.py
r1031 r1046 95 95 self.do_test_placement(placementactions.ActionPlacementAction()) 96 96 97 def test_initialnode_placement(self): 98 self.do_test_placement(placementactions.InitialNodePlacementAction()) 99 100 def test_activityfinalnode_placement(self): 101 self.do_test_placement(placementactions.ActivityFinalNodePlacementAction()) 102 103 def test_flowfinalnode_placement(self): 104 self.do_test_placement(placementactions.FlowFinalNodePlacementAction()) 105 106 97 107 # vim:sw=4:et:ai gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py
r926 r1046 7 7 import itertools 8 8 9 import gobject 10 import pango 11 12 import diacanvas 9 from gaphas.util import path_ellipse, text_align, text_extents 10 13 11 from gaphor import UML 14 12 from gaphor import resource 15 from gaphor.diagram import TextElement16 from gaphor.diagram.groupable import GroupBase13 #from gaphor.diagram import TextElement 14 #from gaphor.diagram.groupable import GroupBase 17 15 from gaphor.diagram.nameditem import NamedItem 18 16 from gaphor.diagram.align import H_ALIGN_LEFT, H_ALIGN_RIGHT, V_ALIGN_BOTTOM … … 20 18 21 19 class ActivityNodeItem(NamedItem): 22 """ 23 Basic class for simple activity nodes. Simple activity node is not 24 resizable. 25 """ 26 __o_align__ = True 27 28 def __init__(self, id = None): 29 NamedItem.__init__(self, id) 20 """Basic class for simple activity nodes. 21 Simple activity node is not resizable. 22 """ 23 24 def __init__(self, id=None, width=0, height=0): 25 NamedItem.__init__(self, id, width, height) 30 26 # Do not allow resizing of the node 31 for h in self. handles:32 h. props.movable = False33 34 27 for h in self._handles: 28 h.movable = False 29 30 35 31 class InitialNodeItem(ActivityNodeItem): 36 32 """ … … 39 35 """ 40 36 __uml__ = UML.InitialNode 41 __s_align__ = H_ALIGN_LEFT42 37 43 38 RADIUS = 10 44 39 45 def create_border(self): 40 def __init__(self, id=None, width=20, height=20): 41 ActivityNodeItem.__init__(self, id, width, height) 42 43 def draw(self, context): 44 cr = context.cairo 46 45 r = self.RADIUS 47 46 d = r * 2 48 circle = diacanvas.shape.Ellipse() 49 circle.ellipse((r, r), d, d) 50 circle.set_line_width(0.01) 51 circle.set_fill(diacanvas.shape.FILL_SOLID) 52 circle.set_fill_color(diacanvas.color(0, 0, 0, 255)) 53 self.set(width = d, height = d) 54 return circle 55 56 57 def draw_border(self): 58 """ 59 Draw nothing as initial node does not change. 60 """ 61 pass 47 path_ellipse(cr, r, r, d, d) 48 cr.set_line_width(0.01) 49 cr.fill() 50 51 cr.move_to(d, r) 52 cr.show_text(self.subject.name or '') 62 53 63 54 64 55 class ActivityFinalNodeItem(ActivityNodeItem): 65 """ 66 Representation of activity final node. Activity final node has name 56 """Representation of activity final node. Activity final node has name 67 57 which is put near right-bottom side of node. 68 58 """ 69 59 70 __uml__ = UML.ActivityFinalNode 71 __s_align__ = H_ALIGN_RIGHT 72 __s_valign__ = V_ALIGN_BOTTOM 60 __uml__ = UML.ActivityFinalNode 73 61 74 62 RADIUS_1 = 10 75 63 RADIUS_2 = 15 76 64 77 def create_border(self): 78 r = self.RADIUS_2 65 def __init__(self, id=None, width=30, height=30): 66 ActivityNodeItem.__init__(self, id, width, height) 67 68 def draw(self, context): 69 cr = context.cairo 70 r = self.RADIUS_2 + 1 79 71 d = self.RADIUS_1 * 2 80 self._inner = diacanvas.shape.Ellipse() 81 self._inner.ellipse((r + 1, r + 1), d, d) 82 self._inner.set_line_width(0.01) 83 self._inner.set_fill(diacanvas.shape.FILL_SOLID) 84 self._inner.set_fill_color(diacanvas.color(0, 0, 0, 255)) 72 path_ellipse(cr, r, r, d, d) 73 cr.set_line_width(0.01) 74 cr.fill() 85 75 86 76 d = r * 2 87 border = diacanvas.shape.Ellipse() 88 border.ellipse((r + 1, r + 1), d, d) 89 border.set_line_width(2) 90 border.set_color(diacanvas.color(0, 0, 0, 255)) 91 92 self.set(width = d + 2, height = d + 2) 93 return border 94 95 96 def draw_border(self): 97 """ 98 Draw nothing as activity final node does not change. 99 """ 100 pass 101 102 103 def on_shape_iter(self): 104 return itertools.chain([self._inner], ActivityNodeItem.on_shape_iter(self)) 77 path_ellipse(cr, r, r, d, d) 78 cr.set_line_width(0.01) 79 cr.set_line_width(2) 80 cr.stroke() 81 82 cr.move_to(d, r) 83 cr.show_text(self.subject.name or '') 105 84 106 85 … … 111 90 """ 112 91 113 __uml__ = UML.FlowFinalNode 114 __s_align__ = H_ALIGN_RIGHT 115 __s_valign__ = V_ALIGN_BOTTOM 92 __uml__ = UML.FlowFinalNode 116 93 117 94 RADIUS = 10 118 95 119 def create_border(self): 96 def __init__(self, id=None, width=20, height=20): 97 ActivityNodeItem.__init__(self, id, width, height) 98 99 def draw(self, context): 100 cr = context.cairo 120 101 r = self.RADIUS 121 102 d = r * 2 122 border = diacanvas.shape.Ellipse() 123 border.ellipse((r, r), d, d) 124 border.set_line_width(2) 125 126 def get_line(p1, p2): 127 line = diacanvas.shape.Path() 128 line.line((p1, p2)) 129 line.set_line_width(2) 130 return line 103 path_ellipse(cr, r, r, d, d) 104 cr.stroke() 105 106 cr.move_to(d, r) 107 cr.show_text(self.subject.name or '') 131 108 132 109 dr = (1 - math.sin(math.pi / 4)) * r 133 self._line1 = get_line((dr, dr), (d - dr, d - dr)) 134 self._line2 = get_line((dr, d - dr), (d - dr, dr)) 135 136 self.set(width = d, height = d) 137 138 return border 139 140 141 def draw_border(self): 142 """ 143 Draw nothing as flow final node does not change. 144 """ 145 pass 146 147 148 def on_shape_iter(self): 149 return itertools.chain(ActivityNodeItem.on_shape_iter(self), [self._line1, self._line2]) 150 110 cr.move_to(dr, dr) 111 cr.line_to(d - dr, d - dr) 112 cr.move_to(dr, d - dr) 113 cr.line_to(d - dr, dr) 114 cr.stroke() 115 151 116 152 117 153 118 class FDNode(ActivityNodeItem): 154 """ 155 Abstract class for fork and decision UI nodes. These nodes contain 119 """Abstract class for fork and decision UI nodes. These nodes contain 156 120 combined property, which determines if the they represent combination 157 121 of fork/join or decision/merge nodes as described in UML 158 122 specification. 159 160 """ 161 __gproperties__ = { 162 'combined': (gobject.TYPE_BOOLEAN, 'combined', 163 'check if node item is combination of fork/join or decision/merge nodes', 164 False, 165 gobject.PARAM_READWRITE), 166 } 123 """ 167 124 168 125 def __init__(self, id): … … 220 177 221 178 222 class ForkNodeItem(FDNode , GroupBase):179 class ForkNodeItem(FDNode): 223 180 """ 224 181 Representation of fork or join node. gaphor/branches/new-canvas/gaphor/diagram/items.py
r1029 r1046 30 30 # Actions: 31 31 from gaphor.diagram.action import ActionItem 32 from gaphor.diagram.activitynodes import InitialNodeItem, ActivityFinalNodeItem 33 from gaphor.diagram.activitynodes import FlowFinalNodeItem 32 34 33 35 # Use Cases: gaphor/branches/new-canvas/gaphor/diagram/usecase.py
r1033 r1046 12 12 """Presentation of gaphor.UML.UseCase. 13 13 """ 14 __uml__ = UML.UseCase14 __uml__ = UML.UseCase 15 15 16 16 def __init__(self, id):
