Changeset 1046

Show
Ignore:
Timestamp:
10/25/06 23:26:45 (2 years ago)
Author:
arjanmol
Message:

added actions stuff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/actions/diagramactions.py

    r1006 r1046  
    196196        # Confirm deletion of last views to model objects 
    197197        # They will be deleted along with their last view 
    198         if not self.mayRemoveFromModal(view): 
     198        if not self.mayRemoveFromModel(view): 
    199199            return 
    200200 
     
    204204                items = view.selected_items 
    205205                for i in items: 
    206                     i.item.unlink() 
     206                    i.unlink() 
    207207            finally: 
    208208                get_undo_manager().commit_transaction() 
    209209     
    210     def mayRemoveFromModal(self, view): 
     210    def mayRemoveFromModel(self, view): 
    211211        ''' 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. ''' 
    212212        items = view.selected_items 
     
    218218    def isLastView(self, item): 
    219219        ''' 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: 
    221221            return True 
    222222        return False 
     
    274274            copy_items = [] 
    275275            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) 
    278278            if copy_items: 
    279279                resource.set('copy-buffer', copy_items) 
  • gaphor/branches/new-canvas/gaphor/actions/itemactions.py

    r1044 r1046  
    33Commands related to the Diagram (DiaCanvas) 
    44""" 
    5  
    6 from __future__ import generators 
    7  
    85 
    96from gaphor import GaphorError, resource 
  • gaphor/branches/new-canvas/gaphor/actions/placementactions.py

    r1029 r1046  
    179179 
    180180 
    181 class InterfacePlacementTool(gaphas.tool.PlacementTool): 
    182     """The Interface placement tool creates an InterfaceItem and a 
    183     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 = window 
    189         self.action_id = action_id 
    190         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.namespace 
    197         iface_item = diag.create(interface.InterfaceItem) 
    198         iface_item.set_property('parent', view.canvas.root) 
    199         iface_item.subject = iface 
    200         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 * 2 
    209         iy += iface_item.RADIUS 
    210         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.head 
    219         iface_item.connect_handle(first) 
    220  
    221         # Grab the last handle with the mouse cursor 
    222         last = impl_item.last 
    223         last.set_pos_i(20,0) 
    224         #self.handle_tool.set_grabbed_handle(last) 
    225         return True 
    226  
    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 gobject 
    235 #gobject.type_register(InterfacePlacementTool) 
    236  
    237181class InterfacePlacementAction(NamespacePlacementAction): 
    238182    id = 'InsertInterface' 
     
    244188    subject_type = UML.Interface 
    245189 
    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  
    251190register_action(InterfacePlacementAction) 
    252191 
     
    288227 
    289228 
    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.InitialNodeItem 
    297 #    subject_type = UML.InitialNode 
    298 
    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.ActivityFinalNodeItem 
    309 #    subject_type = UML.ActivityFinalNode 
    310 
    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.FlowFinalNodeItem 
    321 #    subject_type = UML.FlowFinalNode 
    322 
    323 #register_action(FlowFinalNodePlacementAction) 
     229class 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 
     238register_action(InitialNodePlacementAction) 
     239 
     240 
     241class 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 
     250register_action(ActivityFinalNodePlacementAction) 
     251 
     252 
     253class 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 
     262register_action(FlowFinalNodePlacementAction) 
    324263 
    325264 
     
    406345 
    407346 
    408 #class UseCaseAssociationPlacementAction(AssociationPlacementAction): 
    409 #    id = 'InsertUseCaseAssociation' 
    410 
    411 #register_action(UseCaseAssociationPlacementAction) 
     347class UseCaseAssociationPlacementAction(AssociationPlacementAction): 
     348    id = 'InsertUseCaseAssociation' 
     349 
     350register_action(UseCaseAssociationPlacementAction) 
    412351 
    413352 
     
    525464register_action(NodePlacementAction) 
    526465 
     466 
    527467#class InteractionPlacementAction(NamespacePlacementAction): 
    528468#    id = 'InsertInteraction' 
     
    535475# 
    536476#register_action(InteractionPlacementAction) 
     477 
    537478 
    538479#class LifelinePlacementAction(PlacementAction): 
  • gaphor/branches/new-canvas/gaphor/actions/tests/test_placementactions.py

    r1031 r1046  
    9595        self.do_test_placement(placementactions.ActionPlacementAction()) 
    9696 
     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 
    97107# vim:sw=4:et:ai 
  • gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py

    r926 r1046  
    77import itertools 
    88 
    9 import gobject 
    10 import pango 
    11  
    12 import diacanvas 
     9from gaphas.util import path_ellipse, text_align, text_extents 
     10 
    1311from gaphor import UML 
    1412from gaphor import resource 
    15 from gaphor.diagram import TextElement 
    16 from gaphor.diagram.groupable import GroupBase 
     13#from gaphor.diagram import TextElement 
     14#from gaphor.diagram.groupable import GroupBase 
    1715from gaphor.diagram.nameditem import NamedItem 
    1816from gaphor.diagram.align import H_ALIGN_LEFT, H_ALIGN_RIGHT, V_ALIGN_BOTTOM 
     
    2018 
    2119class 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) 
    3026        # Do not allow resizing of the node 
    31         for h in self.handles: 
    32             h.props.movable = False 
    33  
    34  
     27        for h in self._handles: 
     28            h.movable = False 
     29 
     30         
    3531class InitialNodeItem(ActivityNodeItem): 
    3632    """ 
     
    3935    """ 
    4036    __uml__     = UML.InitialNode 
    41     __s_align__ = H_ALIGN_LEFT 
    4237     
    4338    RADIUS = 10 
    4439 
    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 
    4645        r = self.RADIUS 
    4746        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 '') 
    6253 
    6354 
    6455class 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 
    6757    which is put near right-bottom side of node. 
    6858    """ 
    6959 
    70     __uml__      = UML.ActivityFinalNode 
    71     __s_align__  = H_ALIGN_RIGHT 
    72     __s_valign__ = V_ALIGN_BOTTOM 
     60    __uml__ = UML.ActivityFinalNode 
    7361 
    7462    RADIUS_1 = 10 
    7563    RADIUS_2 = 15 
    7664 
    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 
    7971        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() 
    8575 
    8676        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 '') 
    10584 
    10685 
     
    11190    """ 
    11291 
    113     __uml__      = UML.FlowFinalNode 
    114     __s_align__  = H_ALIGN_RIGHT 
    115     __s_valign__ = V_ALIGN_BOTTOM 
     92    __uml__ = UML.FlowFinalNode 
    11693 
    11794    RADIUS = 10 
    11895 
    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 
    120101        r = self.RADIUS 
    121102        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 '') 
    131108 
    132109        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         
    151116 
    152117 
    153118class 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 
    156120    combined property, which determines if the they represent combination 
    157121    of fork/join or decision/merge nodes as described in UML 
    158122    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    """ 
    167124 
    168125    def __init__(self, id): 
     
    220177 
    221178 
    222 class ForkNodeItem(FDNode, GroupBase): 
     179class ForkNodeItem(FDNode): 
    223180    """ 
    224181    Representation of fork or join node. 
  • gaphor/branches/new-canvas/gaphor/diagram/items.py

    r1029 r1046  
    3030# Actions: 
    3131from gaphor.diagram.action import ActionItem 
     32from gaphor.diagram.activitynodes import InitialNodeItem, ActivityFinalNodeItem 
     33from gaphor.diagram.activitynodes import FlowFinalNodeItem 
    3234 
    3335# Use Cases: 
  • gaphor/branches/new-canvas/gaphor/diagram/usecase.py

    r1033 r1046  
    1212    """Presentation of gaphor.UML.UseCase. 
    1313    """ 
    14     __uml__      = UML.UseCase 
     14    __uml__ = UML.UseCase 
    1515 
    1616    def __init__(self, id):