| 3119 |
|
def OnMouse(self, event):
|
| 3120 |
|
global hitradius
|
| 3121 |
|
if event.LeftDClick():
|
| 3122 |
|
if debug: print "Double Click - OnMouse"
|
| 3123 |
|
# need to remember whether the drag started with control down
|
| 3124 |
|
# I don't handle if it was changed during the drag --IMPORTANT!
|
| 3125 |
|
if self.demo.draw_mode or event.ShiftDown(): # "demo" is a poor name, this is where the window global data is
|
| 3126 |
|
if event.LeftDown(): # select object -> object potentially source of arrow
|
| 3127 |
|
x,y = self.ConvertEventCoords(event)
|
| 3128 |
|
l = self.pdc.FindObjects(x, y, hitradius)
|
| 3129 |
|
if l: # select existing object
|
| 3130 |
|
for id in l:
|
| 3131 |
|
if not self.pdc.GetIdGreyedOut(id):
|
| 3132 |
|
self.dragid = id
|
| 3133 |
|
self.lastpos = (event.GetX(),event.GetY())
|
| 3134 |
|
if debug: print 'left clicked on', self.dcid_to_shape_xref.get(id)
|
| 3135 |
|
if not self.InSelection(id):
|
| 3136 |
|
self.ClearSelection()
|
| 3137 |
|
self.AddToSelection(id)
|
| 3138 |
|
if event.LeftDClick(): # this doesn't fire - dclick is instead
|
| 3139 |
|
if debug: print "Double Click - selection"
|
| 3140 |
|
break
|
| 3141 |
|
else: # didn't click on any object
|
| 3142 |
|
# add new object
|
| 3143 |
|
new_shape = self.AddNode(self.leftClickType, x, y)
|
| 3144 |
|
Data.SetUndo('Add %s' % self.leftClickType)
|
| 3145 |
|
# redisplay object??
|
| 3146 |
|
# id = self.shapeid_to_dcid_xref[new_shape.ID]
|
| 3147 |
|
self.RedisplayID(new_shape.dcid)
|
| 3148 |
|
# make object current selection
|
| 3149 |
|
self.dragid = new_shape.dcid # remember start of drag
|
| 3150 |
|
self.lastpos = (event.GetX(),event.GetY()) # needed?
|
| 3151 |
|
l = [new_shape.dcid]
|
| 3152 |
|
|
| 3153 |
|
# keyboard input
|
| 3154 |
|
self.keyboard_target_dcid = l
|
| 3155 |
|
# self.SetFocusEnable() # this didn't work
|
| 3156 |
|
self.SetFocus()
|
| 3157 |
|
|
| 3158 |
|
elif event.RightDown():
|
| 3159 |
|
x,y = self.ConvertEventCoords(event)
|
| 3160 |
|
#l = self.pdc.FindObjectsByBBox(x, y)
|
| 3161 |
|
l = self.pdc.FindObjects(x, y, hitradius)
|
| 3162 |
|
if l:
|
| 3163 |
|
self.pdc.SetIdGreyedOut(l[0], not self.pdc.GetIdGreyedOut(l[0]))
|
| 3164 |
|
r = self.pdc.GetIdBounds(l[0])
|
| 3165 |
|
r.Inflate(4,4)
|
| 3166 |
|
self.OffsetRect(r)
|
| 3167 |
|
self.RefreshRect(r, False)
|
| 3168 |
|
# -- code for popup menu on canvas??? --
|
| 3169 |
|
else: # didn't click on any object
|
| 3170 |
|
self.OnContextMenu(event)
|
| 3171 |
|
# -- end code for popup menu on canvas??? --
|
| 3172 |
|
elif event.Dragging() or event.LeftUp():
|
| 3173 |
|
if self.dragid != -1:
|
| 3174 |
|
pass
|
| 3175 |
|
if event.LeftUp():
|
| 3176 |
|
# self.dragid = -1
|
| 3177 |
|
# what did we release on?
|
| 3178 |
|
x,y = self.ConvertEventCoords(event)
|
| 3179 |
|
#l = self.pdc.FindObjectsByBBox(x, y)
|
| 3180 |
|
l = self.pdc.FindObjects(x, y, hitradius)
|
| 3181 |
|
if l: # connect to this object and maybe connection (if legal)
|
| 3182 |
|
target = self.dcid_to_shape_xref.get(l[0])
|
| 3183 |
|
source = self.dcid_to_shape_xref.get(self.dragid)
|
| 3184 |
|
if source.ID != target.ID:
|
| 3185 |
|
connected = self.ConnectEm(source, target) # return value if connected?
|
| 3186 |
|
if connected: Data.SetUndo('Add %s' % 'Connector')
|
| 3187 |
|
else: # create target object and connection (if legal)
|
| 3188 |
|
source = self.dcid_to_shape_xref.get(self.dragid)
|
| 3189 |
|
if debug: print "source class:", source.__class__
|
| 3190 |
|
target = None
|
| 3191 |
|
if isinstance(source, ORMObjectTypeShape):
|
| 3192 |
|
target = self.AddNode('ORMFactTypeShape', x, y)
|
| 3193 |
|
elif isinstance(source, ORMFactTypeShape):
|
| 3194 |
|
target = self.AddNode('ORMObjectTypeShape', x, y)
|
| 3195 |
|
if not target is None:
|
| 3196 |
|
Data.SetUndo('Add %s' % target.__class__)
|
| 3197 |
|
self.RedisplayID(target.dcid)
|
| 3198 |
|
connected = self.ConnectEm(source, target)
|
| 3199 |
|
if connected:
|
| 3200 |
|
self.RedrawID(source.dcid) # better way to do?
|
| 3201 |
|
self.RedrawID(target.dcid)
|
| 3202 |
|
Data.SetUndo('Add %s' % 'Connector')
|
| 3203 |
|
else:
|
| 3204 |
|
if event.LeftDown():
|
| 3205 |
|
x,y = self.ConvertEventCoords(event)
|
| 3206 |
|
#l = self.pdc.FindObjectsByBBox(x, y)
|
| 3207 |
|
l = self.pdc.FindObjects(x, y, hitradius)
|
| 3208 |
|
if l: # select object (future manage multiple selected objects)
|
| 3209 |
|
for id in l:
|
| 3210 |
|
if not self.pdc.GetIdGreyedOut(id):
|
| 3211 |
|
self.dragid = id
|
| 3212 |
|
self.lastpos = (event.GetX(),event.GetY())
|
| 3213 |
|
source = self.dcid_to_shape_xref.get(self.dragid)
|
| 3214 |
|
source.SetSelected()
|
| 3215 |
|
break
|
| 3216 |
|
else: # didn't click on any object
|
| 3217 |
|
pass
|
| 3218 |
|
# self.AddNode(self.leftClickType, x, y)
|
| 3219 |
|
|
| 3220 |
|
# keyboard input
|
| 3221 |
|
self.keyboard_target_dcid = l
|
| 3222 |
|
# self.SetFocusEnable() # this didn't work
|
| 3223 |
|
self.SetFocus()
|
| 3224 |
|
|
| 3225 |
|
elif event.RightDown():
|
| 3226 |
|
x,y = self.ConvertEventCoords(event)
|
| 3227 |
|
#l = self.pdc.FindObjectsByBBox(x, y)
|
| 3228 |
|
l = self.pdc.FindObjects(x, y, hitradius)
|
| 3229 |
|
if l:
|
| 3230 |
|
self.pdc.SetIdGreyedOut(l[0], not self.pdc.GetIdGreyedOut(l[0]))
|
| 3231 |
|
r = self.pdc.GetIdBounds(l[0])
|
| 3232 |
|
r.Inflate(4,4)
|
| 3233 |
|
self.OffsetRect(r)
|
| 3234 |
|
self.RefreshRect(r, False)
|
| 3235 |
|
# -- code for popup menu on canvas??? --
|
| 3236 |
|
else: # didn't click on any object
|
| 3237 |
|
self.OnContextMenu(event)
|
| 3238 |
|
# -- end code for popup menu on canvas??? --
|
| 3239 |
|
elif event.Dragging() or event.LeftUp():
|
| 3240 |
|
if self.dragid != -1:
|
| 3241 |
|
x,y = self.lastpos
|
| 3242 |
|
dx = event.GetX() - x
|
| 3243 |
|
dy = event.GetY() - y
|
| 3244 |
|
self.MoveID(self.dragid, dx, dy)
|
| 3245 |
|
self.lastpos = (event.GetX(),event.GetY())
|
| 3246 |
|
# adjust all arrows pointing to dragged object
|
| 3247 |
|
if event.LeftUp():
|
| 3248 |
|
self.CommitPositionID(self.dragid)
|
| 3249 |
|
Data.SetUndo('Move')
|
| 3250 |
|
self.dragid = -1
|