GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vdigit/toolbars.py
Go to the documentation of this file.
1 """!
2 @package vdigit.toolbars
3 
4 @brief wxGUI vector digitizer toolbars
5 
6 List of classes:
7  - toolbars::VDigitToolbar
8 
9 (C) 2007-2011 by the GRASS Development Team
10 
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
13 
14 @author Martin Landa <landa.martin gmail.com>
15 """
16 import wx
17 
18 from grass.script import core as grass
19 
20 from gui_core.toolbars import BaseToolbar, BaseIcons
21 from gui_core.dialogs import CreateNewVector
22 from vdigit.preferences import VDigitSettingsDialog
23 from vdigit.main import VDigit
24 from core.debug import Debug
25 from core.settings import UserSettings
26 from core.gcmd import GError
27 from icons.icon import MetaIcon
28 
30  """!Toolbar for digitization
31  """
32  def __init__(self, parent, mapcontent, layerTree = None, log = None):
33  self.mapcontent = mapcontent # Map class instance
34  self.layerTree = layerTree # reference to layer tree associated to map display
35  self.log = log # log area
36  BaseToolbar.__init__(self, parent)
37  self.digit = None
38 
39  # currently selected map layer for editing (reference to MapLayer instance)
40  self.mapLayer = None
41  # list of vector layers from Layer Manager (only in the current mapset)
42  self.layers = []
43 
44  self.comboid = None
45 
46  # only one dialog can be open
47  self.settingsDialog = None
48 
49  # create toolbars (two rows optionally)
50  self.InitToolbar(self._toolbarData())
51  self.Bind(wx.EVT_TOOL, self.OnTool)
52 
53  # default action (digitize new point, line, etc.)
54  self.action = { 'desc' : '',
55  'type' : '',
56  'id' : -1 }
57 
58  # list of available vector maps
59  self.UpdateListOfLayers(updateTool = True)
60 
61  # realize toolbar
62  self.Realize()
63  # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
64  self.combo.Hide()
65  self.combo.Show()
66 
67  # disable undo/redo
68  self.EnableTool(self.undo, False)
69  ### hide undo - this tool is quite buggy in GRASS 6
70  self.RemoveTool(self.undo)
71 
72  # toogle to pointer by default
73  self.OnTool(None)
74 
75  self.FixSize(width = 105)
76 
77  def _toolbarData(self):
78  """!Toolbar data
79  """
80  data = []
81 
82  icons = {
83  'addPoint' : MetaIcon(img = 'point-create',
84  label = _('Digitize new point'),
85  desc = _('Left: new point')),
86  'addLine' : MetaIcon(img = 'line-create',
87  label = _('Digitize new line'),
88  desc = _('Left: new point; Ctrl+Left: undo last point; Right: close line')),
89  'addBoundary' : MetaIcon(img = 'boundary-create',
90  label = _('Digitize new boundary'),
91  desc = _('Left: new point; Ctrl+Left: undo last point; Right: close line')),
92  'addCentroid' : MetaIcon(img = 'centroid-create',
93  label = _('Digitize new centroid'),
94  desc = _('Left: new point')),
95  'addArea' : MetaIcon(img = 'polygon-create',
96  label = _('Digitize new area (composition of boundaries without category and one centroid with category)'),
97  desc = _('Left: new point')),
98  'addVertex' : MetaIcon(img = 'vertex-create',
99  label = _('Add new vertex'),
100  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
101  'deleteLine' : MetaIcon(img = 'line-delete',
102  label = _('Delete feature(s)'),
103  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
104  'displayAttr' : MetaIcon(img = 'attributes-display',
105  label = _('Display/update attributes'),
106  desc = _('Left: Select')),
107  'displayCats' : MetaIcon(img = 'cats-display',
108  label = _('Display/update categories'),
109  desc = _('Left: Select')),
110  'editLine' : MetaIcon(img = 'line-edit',
111  label = _('Edit line/boundary'),
112  desc = _('Left: new point; Ctrl+Left: undo last point; Right: close line')),
113  'moveLine' : MetaIcon(img = 'line-move',
114  label = _('Move feature(s)'),
115  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
116  'moveVertex' : MetaIcon(img = 'vertex-move',
117  label = _('Move vertex'),
118  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
119  'removeVertex' : MetaIcon(img = 'vertex-delete',
120  label = _('Remove vertex'),
121  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
122  'settings' : BaseIcons['settings'].SetLabel(_('Digitization settings')),
123  'quit' : BaseIcons['quit'].SetLabel(label = _('Quit digitizer'),
124  desc = _('Quit digitizer and save changes')),
125  'help' : BaseIcons['help'].SetLabel(label = _('Vector Digitizer manual'),
126  desc = _('Show Vector Digitizer manual')),
127  'additionalTools' : MetaIcon(img = 'tools',
128  label = _('Additional tools '
129  '(copy, flip, connect, etc.)'),
130  desc = _('Left: Select; Ctrl+Left: Unselect; Right: Confirm')),
131  'undo' : MetaIcon(img = 'undo',
132  label = _('Undo'),
133  desc = _('Undo previous changes')),
134  }
135 
136  return self._getToolbarData(((None, ),
137  ("addPoint", icons["addPoint"],
138  self.OnAddPoint,
139  wx.ITEM_CHECK),
140  ("addLine", icons["addLine"],
141  self.OnAddLine,
142  wx.ITEM_CHECK),
143  ("addBoundary", icons["addBoundary"],
144  self.OnAddBoundary,
145  wx.ITEM_CHECK),
146  ("addCentroid", icons["addCentroid"],
147  self.OnAddCentroid,
148  wx.ITEM_CHECK),
149  ("addArea", icons["addArea"],
150  self.OnAddArea,
151  wx.ITEM_CHECK),
152  ("moveVertex", icons["moveVertex"],
153  self.OnMoveVertex,
154  wx.ITEM_CHECK),
155  ("addVertex", icons["addVertex"],
156  self.OnAddVertex,
157  wx.ITEM_CHECK),
158  ("removeVertex", icons["removeVertex"],
159  self.OnRemoveVertex,
160  wx.ITEM_CHECK),
161  ("editLine", icons["editLine"],
162  self.OnEditLine,
163  wx.ITEM_CHECK),
164  ("moveLine", icons["moveLine"],
165  self.OnMoveLine,
166  wx.ITEM_CHECK),
167  ("deleteLine", icons["deleteLine"],
168  self.OnDeleteLine,
169  wx.ITEM_CHECK),
170  ("displayCats", icons["displayCats"],
171  self.OnDisplayCats,
172  wx.ITEM_CHECK),
173  ("displayAttr", icons["displayAttr"],
174  self.OnDisplayAttr,
175  wx.ITEM_CHECK),
176  ("additionalTools", icons["additionalTools"],
178  wx.ITEM_CHECK),
179  (None, ),
180  ("undo", icons["undo"],
181  self.OnUndo),
182  ("settings", icons["settings"],
183  self.OnSettings),
184  ("help", icons["help"],
185  self.OnHelp),
186  ("quit", icons["quit"],
187  self.OnExit))
188  )
189 
190  def OnTool(self, event):
191  """!Tool selected -> disable selected tool in map toolbar"""
192  aId = self.parent.toolbars['map'].GetAction(type = 'id')
193  self.parent.toolbars['map'].ToggleTool(aId, False)
194 
195  # set cursor
196  cursor = self.parent.cursors["cross"]
197  self.parent.MapWindow.SetCursor(cursor)
198 
199  # pointer
200  self.parent.OnPointer(None)
201 
202  if event:
203  # deselect previously selected tool
204  aId = self.action.get('id', -1)
205  if aId != event.GetId() and \
206  self.action['id'] != -1:
207  self.ToggleTool(self.action['id'], False)
208  else:
209  self.ToggleTool(self.action['id'], True)
210 
211  self.action['id'] = event.GetId()
212 
213  event.Skip()
214 
215  if self.action['id'] != -1:
216  self.ToggleTool(self.action['id'], True)
217 
218  # clear tmp canvas
219  if self.action['id'] != aId:
220  self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
221  if self.digit and \
222  len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
223  # cancel action
224  self.parent.MapWindow.OnMiddleDown(None)
225 
226  # set focus
227  self.parent.MapWindow.SetFocus()
228 
229  def OnAddPoint(self, event):
230  """!Add point to the vector map Laier"""
231  Debug.msg (2, "VDigitToolbar.OnAddPoint()")
232  self.action = { 'desc' : "addLine",
233  'type' : "point",
234  'id' : self.addPoint }
235  self.parent.MapWindow.mouse['box'] = 'point'
236 
237  def OnAddLine(self, event):
238  """!Add line to the vector map layer"""
239  Debug.msg (2, "VDigitToolbar.OnAddLine()")
240  self.action = { 'desc' : "addLine",
241  'type' : "line",
242  'id' : self.addLine }
243  self.parent.MapWindow.mouse['box'] = 'line'
244  ### self.parent.MapWindow.polycoords = [] # reset temp line
245 
246  def OnAddBoundary(self, event):
247  """!Add boundary to the vector map layer"""
248  Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
249  if self.action['desc'] != 'addLine' or \
250  self.action['type'] != 'boundary':
251  self.parent.MapWindow.polycoords = [] # reset temp line
252  self.action = { 'desc' : "addLine",
253  'type' : "boundary",
254  'id' : self.addBoundary }
255  self.parent.MapWindow.mouse['box'] = 'line'
256 
257  def OnAddCentroid(self, event):
258  """!Add centroid to the vector map layer"""
259  Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
260  self.action = { 'desc' : "addLine",
261  'type' : "centroid",
262  'id' : self.addCentroid }
263  self.parent.MapWindow.mouse['box'] = 'point'
264 
265  def OnAddArea(self, event):
266  """!Add area to the vector map layer"""
267  Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
268  self.action = { 'desc' : "addLine",
269  'type' : "area",
270  'id' : self.addArea }
271  self.parent.MapWindow.mouse['box'] = 'line'
272 
273  def OnExit (self, event=None):
274  """!Quit digitization tool"""
275  # stop editing of the currently selected map layer
276  if self.mapLayer:
277  self.StopEditing()
278 
279  # close dialogs if still open
280  if self.settingsDialog:
281  self.settingsDialog.OnCancel(None)
282 
283  # set default mouse settings
284  self.parent.MapWindow.mouse['use'] = "pointer"
285  self.parent.MapWindow.mouse['box'] = "point"
286  self.parent.MapWindow.polycoords = []
287 
288  # disable the toolbar
289  self.parent.RemoveToolbar("vdigit")
290 
291  def OnMoveVertex(self, event):
292  """!Move line vertex"""
293  Debug.msg(2, "Digittoolbar.OnMoveVertex():")
294  self.action = { 'desc' : "moveVertex",
295  'id' : self.moveVertex }
296  self.parent.MapWindow.mouse['box'] = 'point'
297 
298  def OnAddVertex(self, event):
299  """!Add line vertex"""
300  Debug.msg(2, "Digittoolbar.OnAddVertex():")
301  self.action = { 'desc' : "addVertex",
302  'id' : self.addVertex }
303  self.parent.MapWindow.mouse['box'] = 'point'
304 
305  def OnRemoveVertex(self, event):
306  """!Remove line vertex"""
307  Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
308  self.action = { 'desc' : "removeVertex",
309  'id' : self.removeVertex }
310  self.parent.MapWindow.mouse['box'] = 'point'
311 
312  def OnEditLine(self, event):
313  """!Edit line"""
314  Debug.msg(2, "Digittoolbar.OnEditLine():")
315  self.action = { 'desc' : "editLine",
316  'id' : self.editLine }
317  self.parent.MapWindow.mouse['box'] = 'line'
318 
319  def OnMoveLine(self, event):
320  """!Move line"""
321  Debug.msg(2, "Digittoolbar.OnMoveLine():")
322  self.action = { 'desc' : "moveLine",
323  'id' : self.moveLine }
324  self.parent.MapWindow.mouse['box'] = 'box'
325 
326  def OnDeleteLine(self, event):
327  """!Delete line"""
328  Debug.msg(2, "Digittoolbar.OnDeleteLine():")
329  self.action = { 'desc' : "deleteLine",
330  'id' : self.deleteLine }
331  self.parent.MapWindow.mouse['box'] = 'box'
332 
333  def OnDisplayCats(self, event):
334  """!Display/update categories"""
335  Debug.msg(2, "Digittoolbar.OnDisplayCats():")
336  self.action = { 'desc' : "displayCats",
337  'id' : self.displayCats }
338  self.parent.MapWindow.mouse['box'] = 'point'
339 
340  def OnDisplayAttr(self, event):
341  """!Display/update attributes"""
342  Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
343  self.action = { 'desc' : "displayAttrs",
344  'id' : self.displayAttr }
345  self.parent.MapWindow.mouse['box'] = 'point'
346 
347  def OnUndo(self, event):
348  """!Undo previous changes"""
349  self.digit.Undo()
350 
351  event.Skip()
352 
353  def EnableUndo(self, enable=True):
354  """!Enable 'Undo' in toolbar
355 
356  @param enable False for disable
357  """
358  if not self.FindById(self.undo):
359  return
360 
361  if enable:
362  if self.GetToolEnabled(self.undo) is False:
363  self.EnableTool(self.undo, True)
364  else:
365  if self.GetToolEnabled(self.undo) is True:
366  self.EnableTool(self.undo, False)
367 
368  def OnSettings(self, event):
369  """!Show settings dialog"""
370  if self.digit is None:
371  try:
372  self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
373  except SystemExit:
374  self.digit = self.parent.MapWindow.digit = None
375 
376  if not self.settingsDialog:
377  self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
378  style = wx.DEFAULT_DIALOG_STYLE)
379  self.settingsDialog.Show()
380 
381  def OnHelp(self, event):
382  """!Show digitizer help page in web browser"""
383  log = self.parent.GetLayerManager().GetLogWindow()
384  log.RunCmd(['g.manual',
385  'entry=wxGUI.Vector_Digitizer'])
386 
387  def OnAdditionalToolMenu(self, event):
388  """!Menu for additional tools"""
389  point = wx.GetMousePosition()
390  toolMenu = wx.Menu()
391 
392  for label, itype, handler, desc in (
393  (_('Break selected lines/boundaries at intersection'),
394  wx.ITEM_CHECK, self.OnBreak, "breakLine"),
395  (_('Connect selected lines/boundaries'),
396  wx.ITEM_CHECK, self.OnConnect, "connectLine"),
397  (_('Copy categories'),
398  wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
399  (_('Copy features from (background) vector map'),
400  wx.ITEM_CHECK, self.OnCopy, "copyLine"),
401  (_('Copy attributes'),
402  wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
403  (_('Feature type conversion'),
404  wx.ITEM_CHECK, self.OnTypeConversion, "typeConv"),
405  (_('Flip selected lines/boundaries'),
406  wx.ITEM_CHECK, self.OnFlip, "flipLine"),
407  (_('Merge selected lines/boundaries'),
408  wx.ITEM_CHECK, self.OnMerge, "mergeLine"),
409  (_('Snap selected lines/boundaries (only to nodes)'),
410  wx.ITEM_CHECK, self.OnSnap, "snapLine"),
411  (_('Split line/boundary'),
412  wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
413  (_('Query features'),
414  wx.ITEM_CHECK, self.OnQuery, "queryLine"),
415  (_('Z bulk-labeling of 3D lines'),
416  wx.ITEM_CHECK, self.OnZBulk, "zbulkLine")):
417  # Add items to the menu
418  item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
419  text = label,
420  kind = itype)
421  toolMenu.AppendItem(item)
422  self.parent.MapWindow.Bind(wx.EVT_MENU, handler, item)
423  if self.action['desc'] == desc:
424  item.Check(True)
425 
426  # Popup the menu. If an item is selected then its handler
427  # will be called before PopupMenu returns.
428  self.parent.MapWindow.PopupMenu(toolMenu)
429  toolMenu.Destroy()
430 
431  if self.action['desc'] == 'addPoint':
432  self.ToggleTool(self.additionalTools, False)
433 
434  def OnCopy(self, event):
435  """!Copy selected features from (background) vector map"""
436  if self.action['desc'] == 'copyLine': # select previous action
437  self.ToggleTool(self.addPoint, True)
438  self.ToggleTool(self.additionalTools, False)
439  self.OnAddPoint(event)
440  return
441 
442  Debug.msg(2, "Digittoolbar.OnCopy():")
443  self.action = { 'desc' : "copyLine",
444  'id' : self.additionalTools }
445  self.parent.MapWindow.mouse['box'] = 'box'
446 
447  def OnSplitLine(self, event):
448  """!Split line"""
449  if self.action['desc'] == 'splitLine': # select previous action
450  self.ToggleTool(self.addPoint, True)
451  self.ToggleTool(self.additionalTools, False)
452  self.OnAddPoint(event)
453  return
454 
455  Debug.msg(2, "Digittoolbar.OnSplitLine():")
456  self.action = { 'desc' : "splitLine",
457  'id' : self.additionalTools }
458  self.parent.MapWindow.mouse['box'] = 'point'
459 
460 
461  def OnCopyCats(self, event):
462  """!Copy categories"""
463  if self.action['desc'] == 'copyCats': # select previous action
464  self.ToggleTool(self.addPoint, True)
465  self.ToggleTool(self.copyCats, False)
466  self.OnAddPoint(event)
467  return
468 
469  Debug.msg(2, "Digittoolbar.OnCopyCats():")
470  self.action = { 'desc' : "copyCats",
471  'id' : self.additionalTools }
472  self.parent.MapWindow.mouse['box'] = 'point'
473 
474  def OnCopyAttrb(self, event):
475  """!Copy attributes"""
476  if self.action['desc'] == 'copyAttrs': # select previous action
477  self.ToggleTool(self.addPoint, True)
478  self.ToggleTool(self.copyCats, False)
479  self.OnAddPoint(event)
480  return
481 
482  Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
483  self.action = { 'desc' : "copyAttrs",
484  'id' : self.additionalTools }
485  self.parent.MapWindow.mouse['box'] = 'point'
486 
487 
488  def OnFlip(self, event):
489  """!Flip selected lines/boundaries"""
490  if self.action['desc'] == 'flipLine': # select previous action
491  self.ToggleTool(self.addPoint, True)
492  self.ToggleTool(self.additionalTools, False)
493  self.OnAddPoint(event)
494  return
495 
496  Debug.msg(2, "Digittoolbar.OnFlip():")
497  self.action = { 'desc' : "flipLine",
498  'id' : self.additionalTools }
499  self.parent.MapWindow.mouse['box'] = 'box'
500 
501  def OnMerge(self, event):
502  """!Merge selected lines/boundaries"""
503  if self.action['desc'] == 'mergeLine': # select previous action
504  self.ToggleTool(self.addPoint, True)
505  self.ToggleTool(self.additionalTools, False)
506  self.OnAddPoint(event)
507  return
508 
509  Debug.msg(2, "Digittoolbar.OnMerge():")
510  self.action = { 'desc' : "mergeLine",
511  'id' : self.additionalTools }
512  self.parent.MapWindow.mouse['box'] = 'box'
513 
514  def OnBreak(self, event):
515  """!Break selected lines/boundaries"""
516  if self.action['desc'] == 'breakLine': # select previous action
517  self.ToggleTool(self.addPoint, True)
518  self.ToggleTool(self.additionalTools, False)
519  self.OnAddPoint(event)
520  return
521 
522  Debug.msg(2, "Digittoolbar.OnBreak():")
523  self.action = { 'desc' : "breakLine",
524  'id' : self.additionalTools }
525  self.parent.MapWindow.mouse['box'] = 'box'
526 
527  def OnSnap(self, event):
528  """!Snap selected features"""
529  if self.action['desc'] == 'snapLine': # select previous action
530  self.ToggleTool(self.addPoint, True)
531  self.ToggleTool(self.additionalTools, False)
532  self.OnAddPoint(event)
533  return
534 
535  Debug.msg(2, "Digittoolbar.OnSnap():")
536  self.action = { 'desc' : "snapLine",
537  'id' : self.additionalTools }
538  self.parent.MapWindow.mouse['box'] = 'box'
539 
540  def OnConnect(self, event):
541  """!Connect selected lines/boundaries"""
542  if self.action['desc'] == 'connectLine': # select previous action
543  self.ToggleTool(self.addPoint, True)
544  self.ToggleTool(self.additionalTools, False)
545  self.OnAddPoint(event)
546  return
547 
548  Debug.msg(2, "Digittoolbar.OnConnect():")
549  self.action = { 'desc' : "connectLine",
550  'id' : self.additionalTools }
551  self.parent.MapWindow.mouse['box'] = 'box'
552 
553  def OnQuery(self, event):
554  """!Query selected lines/boundaries"""
555  if self.action['desc'] == 'queryLine': # select previous action
556  self.ToggleTool(self.addPoint, True)
557  self.ToggleTool(self.additionalTools, False)
558  self.OnAddPoint(event)
559  return
560 
561  Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
562  UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
563  self.action = { 'desc' : "queryLine",
564  'id' : self.additionalTools }
565  self.parent.MapWindow.mouse['box'] = 'box'
566 
567  def OnZBulk(self, event):
568  """!Z bulk-labeling selected lines/boundaries"""
569  if not self.digit.IsVector3D():
570  GError(parent = self.parent,
571  message = _("Vector map is not 3D. Operation canceled."))
572  return
573 
574  if self.action['desc'] == 'zbulkLine': # select previous action
575  self.ToggleTool(self.addPoint, True)
576  self.ToggleTool(self.additionalTools, False)
577  self.OnAddPoint(event)
578  return
579 
580  Debug.msg(2, "Digittoolbar.OnZBulk():")
581  self.action = { 'desc' : "zbulkLine",
582  'id' : self.additionalTools }
583  self.parent.MapWindow.mouse['box'] = 'line'
584 
585  def OnTypeConversion(self, event):
586  """!Feature type conversion
587 
588  Supported conversions:
589  - point <-> centroid
590  - line <-> boundary
591  """
592  if self.action['desc'] == 'typeConv': # select previous action
593  self.ToggleTool(self.addPoint, True)
594  self.ToggleTool(self.additionalTools, False)
595  self.OnAddPoint(event)
596  return
597 
598  Debug.msg(2, "Digittoolbar.OnTypeConversion():")
599  self.action = { 'desc' : "typeConv",
600  'id' : self.additionalTools }
601  self.parent.MapWindow.mouse['box'] = 'box'
602 
603  def OnSelectMap (self, event):
604  """!Select vector map layer for editing
605 
606  If there is a vector map layer already edited, this action is
607  firstly terminated. The map layer is closed. After this the
608  selected map layer activated for editing.
609  """
610  if event.GetSelection() == 0: # create new vector map layer
611  if self.mapLayer:
612  openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
613  else:
614  openVectorMap = None
615  dlg = CreateNewVector(self.parent,
616  exceptMap = openVectorMap, log = self.log,
617  cmd = (('v.edit',
618  { 'tool' : 'create' },
619  'map')),
620  disableAdd = True)
621 
622  if dlg and dlg.GetName():
623  # add layer to map layer tree
624  if self.layerTree:
625  mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
626  self.layerTree.AddLayer(ltype = 'vector',
627  lname = mapName,
628  lcmd = ['d.vect', 'map=%s' % mapName])
629 
630  vectLayers = self.UpdateListOfLayers(updateTool = True)
631  selection = vectLayers.index(mapName)
632 
633  # create table ?
634  if dlg.IsChecked('table'):
635  lmgr = self.parent.GetLayerManager()
636  if lmgr:
637  lmgr.OnShowAttributeTable(None, selection = 'table')
638  dlg.Destroy()
639  else:
640  self.combo.SetValue(_('Select vector map'))
641  if dlg:
642  dlg.Destroy()
643  return
644  else:
645  selection = event.GetSelection() - 1 # first option is 'New vector map'
646 
647  # skip currently selected map
648  if self.layers[selection] == self.mapLayer:
649  return
650 
651  if self.mapLayer:
652  # deactive map layer for editing
653  self.StopEditing()
654 
655  # select the given map layer for editing
656  self.StartEditing(self.layers[selection])
657 
658  event.Skip()
659 
660  def StartEditing (self, mapLayer):
661  """!Start editing selected vector map layer.
662 
663  @param mapLayer MapLayer to be edited
664  """
665  # deactive layer
666  self.mapcontent.ChangeLayerActive(mapLayer, False)
667 
668  # clean map canvas
669  self.parent.MapWindow.EraseMap()
670 
671  # unset background map if needed
672  if mapLayer:
673  if UserSettings.Get(group = 'vdigit', key = 'bgmap',
674  subkey = 'value', internal = True) == mapLayer.GetName():
675  UserSettings.Set(group = 'vdigit', key = 'bgmap',
676  subkey = 'value', value = '', internal = True)
677 
678  self.parent.SetStatusText(_("Please wait, "
679  "opening vector map <%s> for editing...") % mapLayer.GetName(),
680  0)
681 
682  self.parent.MapWindow.pdcVector = wx.PseudoDC()
683  self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
684 
685  self.mapLayer = mapLayer
686 
687  # open vector map
688  if self.digit.OpenMap(mapLayer.GetName()) is None:
689  self.mapLayer = None
690  self.StopEditing()
691  return False
692 
693  # update toolbar
694  self.combo.SetValue(mapLayer.GetName())
695  self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
696  lmgr = self.parent.GetLayerManager()
697  if lmgr:
698  lmgr.toolbars['tools'].Enable('vdigit', enable = False)
699 
700  Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
701 
702  # change cursor
703  if self.parent.MapWindow.mouse['use'] == 'pointer':
704  self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
705 
706  if not self.parent.MapWindow.resize:
707  self.parent.MapWindow.UpdateMap(render = True)
708 
709  # respect opacity
710  opacity = mapLayer.GetOpacity(float = True)
711  if opacity < 1.0:
712  alpha = int(opacity * 255)
713  self.digit.GetDisplay().UpdateSettings(alpha = alpha)
714 
715  return True
716 
717  def StopEditing(self):
718  """!Stop editing of selected vector map layer.
719 
720  @return True on success
721  @return False on failure
722  """
723  self.combo.SetValue (_('Select vector map'))
724 
725  # save changes
726  if self.mapLayer:
727  Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
728  if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
729  if self.digit.GetUndoLevel() > -1:
730  dlg = wx.MessageDialog(parent = self.parent,
731  message = _("Do you want to save changes "
732  "in vector map <%s>?") % self.mapLayer.GetName(),
733  caption = _("Save changes?"),
734  style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
735  if dlg.ShowModal() == wx.ID_NO:
736  # revert changes
737  self.digit.Undo(0)
738  dlg.Destroy()
739 
740  self.parent.SetStatusText(_("Please wait, "
741  "closing and rebuilding topology of "
742  "vector map <%s>...") % self.mapLayer.GetName(),
743  0)
744  self.digit.CloseMap()
745 
746  lmgr = self.parent.GetLayerManager()
747  if lmgr:
748  lmgr.toolbars['tools'].Enable('vdigit', enable = True)
749  lmgr.GetLogWindow().GetProgressBar().SetValue(0)
750  lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
751  self.mapLayer.GetName(),
752  switchPage = False)
753  # re-active layer
754  item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
755  if item and self.parent.tree.IsItemChecked(item):
756  self.mapcontent.ChangeLayerActive(self.mapLayer, True)
757 
758  # change cursor
759  self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
760  self.parent.MapWindow.pdcVector = None
761 
762  # close dialogs
763  for dialog in ('attributes', 'category'):
764  if self.parent.dialogs[dialog]:
765  self.parent.dialogs[dialog].Close()
766  self.parent.dialogs[dialog] = None
767 
768  del self.digit
769  del self.parent.MapWindow.digit
770 
771  self.mapLayer = None
772 
773  self.parent.MapWindow.redrawAll = True
774 
775  return True
776 
777  def UpdateListOfLayers (self, updateTool = False):
778  """!Update list of available vector map layers.
779  This list consists only editable layers (in the current mapset)
780 
781  @param updateTool True to update also toolbar
782  """
783  Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
784  updateTool)
785 
786  layerNameSelected = None
787  # name of currently selected layer
788  if self.mapLayer:
789  layerNameSelected = self.mapLayer.GetName()
790 
791  # select vector map layer in the current mapset
792  layerNameList = []
793  self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
794  l_mapset = grass.gisenv()['MAPSET'])
795 
796  for layer in self.layers:
797  if not layer.name in layerNameList: # do not duplicate layer
798  layerNameList.append (layer.GetName())
799 
800  if updateTool: # update toolbar
801  if not self.mapLayer:
802  value = _('Select vector map')
803  else:
804  value = layerNameSelected
805 
806  if not self.comboid:
807  self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
808  choices = [_('New vector map'), ] + layerNameList, size = (80, -1),
809  style = wx.CB_READONLY)
810  self.comboid = self.InsertControl(0, self.combo)
811  self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
812  else:
813  self.combo.SetItems([_('New vector map'), ] + layerNameList)
814 
815  self.Realize()
816 
817  return layerNameList
818 
819  def GetLayer(self):
820  """!Get selected layer for editing -- MapLayer instance"""
821  return self.mapLayer
def Enable
Enable defined tool.
def OnZBulk
Z bulk-labeling selected lines/boundaries.
wxGUI command interface
def OnRemoveVertex
Remove line vertex.
def OnAddCentroid
Add centroid to the vector map layer.
wxGUI debugging
def OnSelectMap
Select vector map layer for editing.
def UpdateSettings
Update view from settings values stored in self.mapWindow.view dictionary.
Definition: tools.py:2556
def OnTool
Tool selected.
wxGUI vector digitizer
def OnSplitLine
Split line.
def OnConnect
Connect selected lines/boundaries.
def OnMoveLine
Move line.
def OnBreak
Break selected lines/boundaries.
def _toolbarData
Toolbar data (virtual)
def _getToolbarData
Define tool.
def SetValue
Definition: widgets.py:115
def OnCopyCats
Copy categories.
def InitToolbar
Initialize toolbar, add tools to the toolbar.
Various dialogs used in wxGUI.
Toolbar for digitization.
def OnAddBoundary
Add boundary to the vector map layer.
def OnMerge
Merge selected lines/boundaries.
def OnAddPoint
Add point to the vector map Laier.
def OnFlip
Flip selected lines/boundaries.
def OnSnap
Snap selected features.
def OnAddArea
Add area to the vector map layer.
def OnCopy
Copy selected features from (background) vector map.
def OnSettings
Show settings dialog.
def GetLayer
Get selected layer for editing – MapLayer instance.
def OnDisplayAttr
Display/update attributes.
def OnTool
Tool selected -&gt; disable selected tool in map toolbar.
def OnAddLine
Add line to the vector map layer.
def UpdateListOfLayers
Update list of available vector map layers.
Abstract toolbar class.
def OnUndo
Undo previous changes.
def OnEditLine
Edit line.
def StartEditing
Start editing selected vector map layer.
def FixSize
Fix toolbar width on Windows.
def CreateNewVector
Create new vector map layer.
Base classes toolbar widgets.
wxGUI Layer Manager - toolbars
def EnableUndo
Enable &#39;Undo&#39; in toolbar.
def OnMoveVertex
Move line vertex.
def OnExit
Quit digitization tool.
wxGUI vector digitizer preferences dialogs
Default GUI settings.
def GetAction
Get current action info.
def OnAddVertex
Add line vertex.
def OnCopyAttrb
Copy attributes.
def OnDisplayCats
Display/update categories.
def OnQuery
Query selected lines/boundaries.
def OnAdditionalToolMenu
Menu for additional tools.
def OnDeleteLine
Delete line.
def OnHelp
Show digitizer help page in web browser.
def OnTypeConversion
Feature type conversion.
def StopEditing
Stop editing of selected vector map layer.