GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vdigit/preferences.py
Go to the documentation of this file.
1 """!
2 @package vdigit.preferences
3 
4 @brief wxGUI vector digitizer preferences dialogs
5 
6 Classes:
7  - preferences::VDigitSettingsDialog
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 
17 import textwrap
18 
19 import wx
20 import wx.lib.colourselect as csel
21 
22 from core import globalvar
23 from core.debug import Debug
24 from gui_core.gselect import ColumnSelect
25 from core.units import Units
26 from core.settings import UserSettings
27 
28 class VDigitSettingsDialog(wx.Dialog):
29  def __init__(self, parent, title, style = wx.DEFAULT_DIALOG_STYLE):
30  """!Standard settings dialog for digitization purposes
31  """
32  wx.Dialog.__init__(self, parent = parent, id = wx.ID_ANY, title = title, style = style)
33 
34  self.parent = parent # mapdisplay.MapFrame class instance
35  self.digit = self.parent.MapWindow.digit
36 
37  # notebook
38  notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
39  self._createGeneralPage(notebook)
40  self._createSymbologyPage(notebook)
41  self.digit.SetCategory()
42  self._createAttributesPage(notebook)
43  self._createQueryPage(notebook)
44 
45  # buttons
46  btnApply = wx.Button(self, wx.ID_APPLY)
47  btnCancel = wx.Button(self, wx.ID_CANCEL)
48  btnSave = wx.Button(self, wx.ID_SAVE)
49  btnSave.SetDefault()
50 
51  # bindigs
52  btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
53  btnApply.SetToolTipString(_("Apply changes for this session"))
54  btnApply.SetDefault()
55  btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
56  btnSave.SetToolTipString(_("Close dialog and save changes to user settings file"))
57  btnCancel.Bind(wx.EVT_BUTTON, self.OnCancel)
58  btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
59 
60  # sizers
61  btnSizer = wx.StdDialogButtonSizer()
62  btnSizer.AddButton(btnCancel)
63  btnSizer.AddButton(btnApply)
64  btnSizer.AddButton(btnSave)
65  btnSizer.Realize()
66 
67  mainSizer = wx.BoxSizer(wx.VERTICAL)
68  mainSizer.Add(item = notebook, proportion = 1, flag = wx.EXPAND | wx.ALL, border = 5)
69  mainSizer.Add(item = btnSizer, proportion = 0,
70  flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
71 
72  self.Bind(wx.EVT_CLOSE, self.OnCancel)
73 
74  self.SetSizer(mainSizer)
75  mainSizer.Fit(self)
76 
77  def _createSymbologyPage(self, notebook):
78  """!Create notebook page concerning symbology settings"""
79  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
80  notebook.AddPage(page = panel, text = _("Symbology"))
81 
82  sizer = wx.BoxSizer(wx.VERTICAL)
83 
84  flexSizer = wx.FlexGridSizer (cols = 3, hgap = 5, vgap = 5)
85  flexSizer.AddGrowableCol(0)
86 
87  self.symbology = {}
88  for label, key in self._symbologyData():
89  textLabel = wx.StaticText(panel, wx.ID_ANY, label)
90  color = csel.ColourSelect(panel, id = wx.ID_ANY,
91  colour = UserSettings.Get(group = 'vdigit', key = 'symbol',
92  subkey = [key, 'color']),
93  size = (40, 25))
94  isEnabled = UserSettings.Get(group = 'vdigit', key = 'symbol',
95  subkey = [key, 'enabled'])
96  if isEnabled is not None:
97  enabled = wx.CheckBox(panel, id = wx.ID_ANY, label = "")
98  enabled.SetValue(isEnabled)
99  self.symbology[key] = (enabled, color)
100  else:
101  enabled = (1, 1)
102  self.symbology[key] = (None, color)
103 
104  flexSizer.Add(textLabel, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
105  flexSizer.Add(enabled, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
106  flexSizer.Add(color, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
107  color.SetName("GetColour")
108 
109  sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 10)
110 
111  panel.SetSizer(sizer)
112 
113  return panel
114 
115  def _createGeneralPage(self, notebook):
116  """!Create notebook page concerning general settings"""
117  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
118  notebook.AddPage(page = panel, text = _("General"))
119 
120  border = wx.BoxSizer(wx.VERTICAL)
121 
122  #
123  # display section
124  #
125  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Display"))
126  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
127  flexSizer = wx.FlexGridSizer (cols = 3, hgap = 5, vgap = 5)
128  flexSizer.AddGrowableCol(0)
129  # line width
130  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Line width"))
131  self.lineWidthValue = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (75, -1),
132  initial = UserSettings.Get(group = 'vdigit', key = "lineWidth", subkey = 'value'),
133  min = 1, max = 1e6)
134  units = wx.StaticText(parent = panel, id = wx.ID_ANY, size = (115, -1),
135  label = UserSettings.Get(group = 'vdigit', key = "lineWidth", subkey = 'units'),
136  style = wx.ALIGN_LEFT)
137  flexSizer.Add(text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
138  flexSizer.Add(self.lineWidthValue, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
139  flexSizer.Add(units, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
140  border = 10)
141 
142  sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
143  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
144 
145  #
146  # snapping section
147  #
148  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Snapping"))
149  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
150  flexSizer = wx.FlexGridSizer(cols = 3, hgap = 5, vgap = 5)
151  flexSizer.AddGrowableCol(0)
152 
153  # snapping
154  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Snapping threshold"))
155  self.snappingValue = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (75, -1),
156  initial = UserSettings.Get(group = 'vdigit', key = "snapping", subkey = 'value'),
157  min = -1, max = 1e6)
158  self.snappingValue.Bind(wx.EVT_SPINCTRL, self.OnChangeSnappingValue)
159  self.snappingValue.Bind(wx.EVT_TEXT, self.OnChangeSnappingValue)
160  self.snappingUnit = wx.Choice(parent = panel, id = wx.ID_ANY, size = (125, -1),
161  choices = [_("screen pixels"), _("map units")])
162  self.snappingUnit.SetStringSelection(UserSettings.Get(group = 'vdigit', key = "snapping", subkey = 'units'))
163  self.snappingUnit.Bind(wx.EVT_CHOICE, self.OnChangeSnappingUnits)
164  flexSizer.Add(text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
165  flexSizer.Add(self.snappingValue, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
166  flexSizer.Add(self.snappingUnit, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
167 
168  vertexSizer = wx.BoxSizer(wx.VERTICAL)
169  self.snapVertex = wx.CheckBox(parent = panel, id = wx.ID_ANY,
170  label = _("Snap also to vertex"))
171  self.snapVertex.SetValue(UserSettings.Get(group = 'vdigit', key = "snapToVertex", subkey = 'enabled'))
172  vertexSizer.Add(item = self.snapVertex, proportion = 0, flag = wx.EXPAND)
173  self.mapUnits = self.parent.MapWindow.Map.GetProjInfo()['units']
174  self.snappingInfo = wx.StaticText(parent = panel, id = wx.ID_ANY,
175  label = _("Snapping threshold is %(value).1f %(units)s") % \
176  {'value' : self.digit.GetDisplay().GetThreshold(),
177  'units' : self.mapUnits})
178  vertexSizer.Add(item = self.snappingInfo, proportion = 0,
179  flag = wx.ALL | wx.EXPAND, border = 1)
180 
181  sizer.Add(item = flexSizer, proportion = 1, flag = wx.EXPAND)
182  sizer.Add(item = vertexSizer, proportion = 1, flag = wx.EXPAND)
183  border.Add(item = sizer, proportion = 0, flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
184 
185  #
186  # select box
187  #
188  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Select vector features"))
189  # feature type
190  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
191  inSizer = wx.BoxSizer(wx.HORIZONTAL)
192  self.selectFeature = {}
193  for feature in ('point', 'line',
194  'centroid', 'boundary'):
195  chkbox = wx.CheckBox(parent = panel, label = feature)
196  self.selectFeature[feature] = chkbox.GetId()
197  chkbox.SetValue(UserSettings.Get(group = 'vdigit', key = 'selectType',
198  subkey = [feature, 'enabled']))
199  inSizer.Add(item = chkbox, proportion = 0,
200  flag = wx.EXPAND | wx.ALL, border = 5)
201  sizer.Add(item = inSizer, proportion = 0, flag = wx.EXPAND)
202  # threshold
203  flexSizer = wx.FlexGridSizer (cols = 3, hgap = 5, vgap = 5)
204  flexSizer.AddGrowableCol(0)
205  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select threshold"))
206  self.selectThreshValue = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (75, -1),
207  initial = UserSettings.Get(group = 'vdigit', key = "selectThresh", subkey = 'value'),
208  min = 1, max = 1e6)
209  units = wx.StaticText(parent = panel, id = wx.ID_ANY, size = (115, -1),
210  label = UserSettings.Get(group = 'vdigit', key = "lineWidth", subkey = 'units'),
211  style = wx.ALIGN_LEFT)
212  flexSizer.Add(text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
213  flexSizer.Add(self.selectThreshValue, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
214  flexSizer.Add(units, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL | wx.LEFT,
215  border = 10)
216 
217  self.selectIn = wx.CheckBox(parent = panel, id = wx.ID_ANY,
218  label = _("Select only features inside of selection bounding box"))
219  self.selectIn.SetValue(UserSettings.Get(group = 'vdigit', key = "selectInside", subkey = 'enabled'))
220  self.selectIn.SetToolTipString(_("By default are selected all features overlapping selection bounding box "))
221 
222  self.checkForDupl = wx.CheckBox(parent = panel, id = wx.ID_ANY,
223  label = _("Check for duplicates"))
224  self.checkForDupl.SetValue(UserSettings.Get(group = 'vdigit', key = "checkForDupl", subkey = 'enabled'))
225 
226 
227  sizer.Add(item = flexSizer, proportion = 0, flag = wx.EXPAND)
228  sizer.Add(item = self.selectIn, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 1)
229  sizer.Add(item = self.checkForDupl, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 1)
230  border.Add(item = sizer, proportion = 0, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
231 
232  #
233  # digitize lines box
234  #
235  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Digitize line features"))
236  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
237 
238  self.intersect = wx.CheckBox(parent = panel, label = _("Break lines at intersection"))
239  self.intersect.SetValue(UserSettings.Get(group = 'vdigit', key = 'breakLines', subkey = 'enabled'))
240 
241  sizer.Add(item = self.intersect, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
242 
243  border.Add(item = sizer, proportion = 0, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
244 
245  #
246  # save-on-exit box
247  #
248  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Save changes"))
249  # save changes on exit?
250  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
251  self.save = wx.CheckBox(parent = panel, label = _("Save changes on exit"))
252  self.save.SetValue(UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled'))
253  sizer.Add(item = self.save, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
254  border.Add(item = sizer, proportion = 0, flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border = 5)
255 
256  panel.SetSizer(border)
257 
258  return panel
259 
260  def _createQueryPage(self, notebook):
261  """!Create notebook page for query tool"""
262  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
263  notebook.AddPage(page = panel, text = _("Query tool"))
264 
265  border = wx.BoxSizer(wx.VERTICAL)
266 
267  #
268  # query tool box
269  #
270  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Choose query tool"))
271  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
272 
273  LocUnits = self.parent.MapWindow.Map.GetProjInfo()['units']
274 
275  self.queryBox = wx.CheckBox(parent = panel, id = wx.ID_ANY, label = _("Select by box"))
276  self.queryBox.SetValue(UserSettings.Get(group = 'vdigit', key = "query", subkey = 'box'))
277 
278  sizer.Add(item = self.queryBox, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
279  sizer.Add((0, 5))
280 
281  #
282  # length
283  #
284  self.queryLength = wx.RadioButton(parent = panel, id = wx.ID_ANY, label = _("length"))
285  self.queryLength.Bind(wx.EVT_RADIOBUTTON, self.OnChangeQuery)
286  sizer.Add(item = self.queryLength, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
287  flexSizer = wx.FlexGridSizer (cols = 4, hgap = 5, vgap = 5)
288  flexSizer.AddGrowableCol(0)
289  txt = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select lines"))
290  self.queryLengthSL = wx.Choice (parent = panel, id = wx.ID_ANY,
291  choices = [_("shorter than"), _("longer than")])
292  self.queryLengthSL.SetSelection(UserSettings.Get(group = 'vdigit', key = "queryLength", subkey = 'than-selection'))
293  self.queryLengthValue = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1),
294  initial = 1,
295  min = 0, max = 1e6)
296  self.queryLengthValue.SetValue(UserSettings.Get(group = 'vdigit', key = "queryLength", subkey = 'thresh'))
297  units = wx.StaticText(parent = panel, id = wx.ID_ANY, label = "%s" % LocUnits)
298  flexSizer.Add(txt, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
299  flexSizer.Add(self.queryLengthSL, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
300  flexSizer.Add(self.queryLengthValue, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
301  flexSizer.Add(units, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
302  sizer.Add(item = flexSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
303 
304  #
305  # dangle
306  #
307  self.queryDangle = wx.RadioButton(parent = panel, id = wx.ID_ANY, label = _("dangle"))
308  self.queryDangle.Bind(wx.EVT_RADIOBUTTON, self.OnChangeQuery)
309  sizer.Add(item = self.queryDangle, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
310  flexSizer = wx.FlexGridSizer (cols = 4, hgap = 5, vgap = 5)
311  flexSizer.AddGrowableCol(0)
312  txt = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Select dangles"))
313  self.queryDangleSL = wx.Choice (parent = panel, id = wx.ID_ANY,
314  choices = [_("shorter than"), _("longer than")])
315  self.queryDangleSL.SetSelection(UserSettings.Get(group = 'vdigit', key = "queryDangle", subkey = 'than-selection'))
316  self.queryDangleValue = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (100, -1),
317  initial = 1,
318  min = 0, max = 1e6)
319  self.queryDangleValue.SetValue(UserSettings.Get(group = 'vdigit', key = "queryDangle", subkey = 'thresh'))
320  units = wx.StaticText(parent = panel, id = wx.ID_ANY, label = "%s" % LocUnits)
321  flexSizer.Add(txt, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
322  flexSizer.Add(self.queryDangleSL, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
323  flexSizer.Add(self.queryDangleValue, proportion = 0, flag = wx.ALIGN_CENTER | wx.FIXED_MINSIZE)
324  flexSizer.Add(units, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
325  sizer.Add(item = flexSizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
326 
327  if UserSettings.Get(group = 'vdigit', key = "query", subkey = 'selection') == 0:
328  self.queryLength.SetValue(True)
329  else:
330  self.queryDangle.SetValue(True)
331 
332  # enable & disable items
333  self.OnChangeQuery(None)
334 
335  border.Add(item = sizer, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 5)
336 
337  panel.SetSizer(border)
338 
339  return panel
340 
341  def _createAttributesPage(self, notebook):
342  """!Create notebook page for attributes"""
343  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
344  notebook.AddPage(page = panel, text = _("Attributes"))
345 
346  border = wx.BoxSizer(wx.VERTICAL)
347 
348  #
349  # add new record
350  #
351  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Digitize new feature"))
352  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
353 
354  # checkbox
355  self.addRecord = wx.CheckBox(parent = panel, id = wx.ID_ANY,
356  label = _("Add new record into table"))
357  self.addRecord.SetValue(UserSettings.Get(group = 'vdigit', key = "addRecord", subkey = 'enabled'))
358  sizer.Add(item = self.addRecord, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
359  # settings
360  flexSizer = wx.FlexGridSizer(cols = 2, hgap = 3, vgap = 3)
361  flexSizer.AddGrowableCol(0)
362  settings = ((_("Layer"), 1), (_("Category"), 1), (_("Mode"), _("Next to use")))
363  # layer
364  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Layer"))
365  self.layer = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (125, -1),
366  min = 1, max = 1e3)
367  self.layer.SetValue(int(UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value')))
368  flexSizer.Add(item = text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
369  flexSizer.Add(item = self.layer, proportion = 0,
370  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
371  # category number
372  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Category number"))
373  self.category = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (125, -1),
374  initial = UserSettings.Get(group = 'vdigit', key = "category", subkey = 'value'),
375  min = -1e9, max = 1e9)
376  if UserSettings.Get(group = 'vdigit', key = "categoryMode", subkey = 'selection') != 1:
377  self.category.Enable(False)
378  flexSizer.Add(item = text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
379  flexSizer.Add(item = self.category, proportion = 0,
380  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
381  # category mode
382  text = wx.StaticText(parent = panel, id = wx.ID_ANY, label = _("Category mode"))
383  self.categoryMode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (125, -1),
384  choices = [_("Next to use"), _("Manual entry"), _("No category")])
385  self.categoryMode.SetSelection(UserSettings.Get(group = 'vdigit', key = "categoryMode", subkey = 'selection'))
386  flexSizer.Add(item = text, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
387  flexSizer.Add(item = self.categoryMode, proportion = 0,
388  flag = wx.FIXED_MINSIZE | wx.ALIGN_CENTER_VERTICAL)
389 
390  sizer.Add(item = flexSizer, proportion = 1, flag = wx.ALL | wx.EXPAND, border = 1)
391  border.Add(item = sizer, proportion = 0,
392  flag = wx.ALL | wx.EXPAND, border = 5)
393 
394  #
395  # delete existing record
396  #
397  box = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Delete existing feature(s)"))
398  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
399 
400  # checkbox
401  self.deleteRecord = wx.CheckBox(parent = panel, id = wx.ID_ANY,
402  label = _("Delete record from table"))
403  self.deleteRecord.SetValue(UserSettings.Get(group = 'vdigit', key = "delRecord", subkey = 'enabled'))
404  sizer.Add(item = self.deleteRecord, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
405  border.Add(item = sizer, proportion = 0,
406  flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
407 
408  #
409  # geometry attributes (currently only length and area are supported)
410  #
411  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
412  label = " %s " % _("Geometry attributes"))
413  sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
414  gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
415  gridSizer.AddGrowableCol(0)
416  self.geomAttrb = { 'length' : { 'label' : _('length') },
417  'area' : { 'label' : _('area') },
418  'perimeter' : { 'label' : _('perimeter') } }
419 
420  digitToolbar = self.parent.toolbars['vdigit']
421  try:
422  vectorName = digitToolbar.GetLayer().GetName()
423  except AttributeError:
424  vectorName = None # no vector selected for editing
425  layer = UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value')
426  mapLayer = self.parent.toolbars['vdigit'].GetLayer()
427  tree = self.parent.tree
428  item = tree.FindItemByData('maplayer', mapLayer)
429  row = 0
430  for attrb in ['length', 'area', 'perimeter']:
431  # checkbox
432  check = wx.CheckBox(parent = panel, id = wx.ID_ANY,
433  label = self.geomAttrb[attrb]['label'])
434  ### self.deleteRecord.SetValue(UserSettings.Get(group='vdigit', key="delRecord", subkey='enabled'))
435  check.Bind(wx.EVT_CHECKBOX, self.OnGeomAttrb)
436  # column (only numeric)
437  column = ColumnSelect(parent = panel, size = (200, -1))
438  column.InsertColumns(vector = vectorName,
439  layer = layer, excludeKey = True,
440  type = ['integer', 'double precision'])
441  # units
442  if attrb == 'area':
443  choices = Units.GetUnitsList('area')
444  else:
445  choices = Units.GetUnitsList('length')
446  win_units = wx.Choice(parent = panel, id = wx.ID_ANY,
447  choices = choices, size = (120, -1))
448 
449  # default values
450  check.SetValue(False)
451  if item and tree.GetPyData(item)[0]['vdigit'] and \
452  'geomAttr' in tree.GetPyData(item)[0]['vdigit'] and \
453  attrb in tree.GetPyData(item)[0]['vdigit']['geomAttr']:
454  check.SetValue(True)
455  column.SetStringSelection(tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb]['column'])
456  if attrb == 'area':
457  type = 'area'
458  else:
459  type = 'length'
460  unitsIdx = Units.GetUnitsIndex(type,
461  tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb]['units'])
462  win_units.SetSelection(unitsIdx)
463 
464  if not vectorName:
465  check.Enable(False)
466  column.Enable(False)
467 
468  if not check.IsChecked():
469  column.Enable(False)
470 
471  self.geomAttrb[attrb]['check'] = check.GetId()
472  self.geomAttrb[attrb]['column'] = column.GetId()
473  self.geomAttrb[attrb]['units'] = win_units.GetId()
474 
475  gridSizer.Add(item = check,
476  flag = wx.ALIGN_CENTER_VERTICAL,
477  pos = (row, 0))
478  gridSizer.Add(item = column,
479  pos = (row, 1))
480  gridSizer.Add(item = win_units,
481  pos = (row, 2))
482  row += 1
483 
484  note = '\n'.join(textwrap.wrap(_("Note: These settings are stored "
485  "in the workspace not in the vector digitizer "
486  "preferences."), 55))
487  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
488  label = note),
489  pos = (3, 0), span = (1, 3))
490 
491  sizer.Add(item = gridSizer, proportion = 1,
492  flag = wx.ALL | wx.EXPAND, border = 1)
493  border.Add(item = sizer, proportion = 0,
494  flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
495 
496  # bindings
497  self.Bind(wx.EVT_CHECKBOX, self.OnChangeAddRecord, self.addRecord)
498  self.Bind(wx.EVT_CHOICE, self.OnChangeCategoryMode, self.categoryMode)
499  self.Bind(wx.EVT_SPINCTRL, self.OnChangeLayer, self.layer)
500 
501  panel.SetSizer(border)
502 
503  return panel
504 
505  def _symbologyData(self):
506  """!Data for _createSymbologyPage()
507 
508  label | checkbox | color
509  """
510 
511  return (
512  (_("Digitize new line segment"), "newSegment"),
513  (_("Digitize new line/boundary"), "newLine"),
514  (_("Highlight"), "highlight"),
515  (_("Highlight (duplicates)"), "highlightDupl"),
516  (_("Point"), "point"),
517  (_("Line"), "line"),
518  (_("Boundary (no area)"), "boundaryNo"),
519  (_("Boundary (one area)"), "boundaryOne"),
520  (_("Boundary (two areas)"), "boundaryTwo"),
521  (_("Centroid (in area)"), "centroidIn"),
522  (_("Centroid (outside area)"), "centroidOut"),
523  (_("Centroid (duplicate in area)"), "centroidDup"),
524  (_("Node (one line)"), "nodeOne"),
525  (_("Node (two lines)"), "nodeTwo"),
526  (_("Vertex"), "vertex"),
527  (_("Area (closed boundary + centroid)"), "area"),
528  (_("Direction"), "direction"),)
529 
530  def OnGeomAttrb(self, event):
531  """!Register geometry attributes (enable/disable)
532  """
533  checked = event.IsChecked()
534  id = event.GetId()
535  key = None
536  for attrb, val in self.geomAttrb.iteritems():
537  if val['check'] == id:
538  key = attrb
539  break
540 
541  column = self.FindWindowById(self.geomAttrb[key]['column'])
542  if checked:
543  column.Enable()
544  else:
545  column.Enable(False)
546 
547  def OnChangeCategoryMode(self, event):
548  """!Change category mode
549  """
550  mode = event.GetSelection()
551  UserSettings.Set(group = 'vdigit', key = "categoryMode", subkey = 'selection', value = mode)
552  if mode == 1: # manual entry
553  self.category.Enable(True)
554  elif self.category.IsEnabled(): # disable
555  self.category.Enable(False)
556 
557  if mode == 2 and self.addRecord.IsChecked(): # no category
558  self.addRecord.SetValue(False)
559 
560  self.digit.SetCategory()
561  self.category.SetValue(UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value'))
562 
563  def OnChangeLayer(self, event):
564  """!Layer changed
565  """
566  layer = event.GetInt()
567  if layer > 0:
568  UserSettings.Set(group = 'vdigit', key = 'layer', subkey = 'value', value = layer)
569  self.digit.SetCategory()
570  self.category.SetValue(UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value'))
571 
572  event.Skip()
573 
574  def OnChangeAddRecord(self, event):
575  """!Checkbox 'Add new record' status changed
576  """
577  pass
578  # self.category.SetValue(self.digit.SetCategory())
579 
580  def OnChangeSnappingValue(self, event):
581  """!Change snapping value - update static text
582  """
583  value = self.snappingValue.GetValue()
584 
585  if value < 0:
586  region = self.parent.MapWindow.Map.GetRegion()
587  res = (region['nsres'] + region['ewres']) / 2.
588  threshold = self.digit.GetDisplay().GetThreshold(value = res)
589  else:
590  if self.snappingUnit.GetStringSelection() == "map units":
591  threshold = value
592  else:
593  threshold = self.digit.GetDisplay().GetThreshold(value = value)
594 
595  if value == 0:
596  self.snappingInfo.SetLabel(_("Snapping disabled"))
597  elif value < 0:
598  self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s "
599  "(based on comp. resolution)") %
600  {'value' : threshold,
601  'units' : self.mapUnits.lower()})
602  else:
603  self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
604  {'value' : threshold,
605  'units' : self.mapUnits.lower()})
606 
607  event.Skip()
608 
609  def OnChangeSnappingUnits(self, event):
610  """!Snapping units change -> update static text
611  """
612  value = self.snappingValue.GetValue()
613  units = self.snappingUnit.GetStringSelection()
614  threshold = self.digit.GetDisplay().GetThreshold(value = value, units = units)
615 
616  if units == "map units":
617  self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
618  {'value' : value,
619  'units' : self.mapUnits})
620  else:
621  self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
622  {'value' : threshold,
623  'units' : self.mapUnits})
624 
625  event.Skip()
626 
627  def OnChangeQuery(self, event):
628  """!Change query
629  """
630  if self.queryLength.GetValue():
631  # length
632  self.queryLengthSL.Enable(True)
633  self.queryLengthValue.Enable(True)
634  self.queryDangleSL.Enable(False)
635  self.queryDangleValue.Enable(False)
636  else:
637  # dangle
638  self.queryLengthSL.Enable(False)
639  self.queryLengthValue.Enable(False)
640  self.queryDangleSL.Enable(True)
641  self.queryDangleValue.Enable(True)
642 
643  def OnSave(self, event):
644  """!Button 'Save' pressed
645  """
646  self.UpdateSettings()
647  self.parent.toolbars['vdigit'].settingsDialog = None
648 
649  fileSettings = {}
650  UserSettings.ReadSettingsFile(settings = fileSettings)
651  fileSettings['vdigit'] = UserSettings.Get(group = 'vdigit')
652 
653  file = UserSettings.SaveToFile(fileSettings)
654  self.parent.GetLayerManager().goutput.WriteLog(_('Vector digitizer settings saved to file <%s>.') % file)
655 
656  self.Destroy()
657 
658  event.Skip()
659 
660  def OnApply(self, event):
661  """!Button 'Apply' pressed
662  """
663  self.UpdateSettings()
664 
665  def OnCancel(self, event):
666  """!Button 'Cancel' pressed
667  """
668  self.parent.toolbars['vdigit'].settingsDialog = None
669  self.Destroy()
670 
671  if event:
672  event.Skip()
673 
674  def UpdateSettings(self):
675  """!Update digitizer settings
676  """
677  self.parent.GetLayerManager().WorkspaceChanged() # geometry attributes
678  # symbology
679  for key, (enabled, color) in self.symbology.iteritems():
680  if enabled:
681  UserSettings.Set(group = 'vdigit', key = 'symbol',
682  subkey = [key, 'enabled'],
683  value = enabled.IsChecked())
684  UserSettings.Set(group = 'vdigit', key = 'symbol',
685  subkey = [key, 'color'],
686  value = tuple(color.GetColour()))
687  else:
688  UserSettings.Set(group = 'vdigit', key = 'symbol',
689  subkey = [key, 'color'],
690  value = tuple(color.GetColour()))
691  # display
692  UserSettings.Set(group = 'vdigit', key = "lineWidth", subkey = 'value',
693  value = int(self.lineWidthValue.GetValue()))
694 
695  # snapping
696  UserSettings.Set(group = 'vdigit', key = "snapping", subkey = 'value',
697  value = int(self.snappingValue.GetValue()))
698  UserSettings.Set(group = 'vdigit', key = "snapping", subkey = 'units',
699  value = self.snappingUnit.GetStringSelection())
700  UserSettings.Set(group = 'vdigit', key = "snapToVertex", subkey = 'enabled',
701  value = self.snapVertex.IsChecked())
702 
703  # digitize new feature
704  UserSettings.Set(group = 'vdigit', key = "addRecord", subkey = 'enabled',
705  value = self.addRecord.IsChecked())
706  UserSettings.Set(group = 'vdigit', key = "layer", subkey = 'value',
707  value = int(self.layer.GetValue()))
708  UserSettings.Set(group = 'vdigit', key = "category", subkey = 'value',
709  value = int(self.category.GetValue()))
710  UserSettings.Set(group = 'vdigit', key = "categoryMode", subkey = 'selection',
711  value = self.categoryMode.GetSelection())
712 
713  # delete existing feature
714  UserSettings.Set(group = 'vdigit', key = "delRecord", subkey = 'enabled',
715  value = self.deleteRecord.IsChecked())
716 
717  # geometry attributes (workspace)
718  mapLayer = self.parent.toolbars['vdigit'].GetLayer()
719  tree = self.parent.tree
720  item = tree.FindItemByData('maplayer', mapLayer)
721  for key, val in self.geomAttrb.iteritems():
722  checked = self.FindWindowById(val['check']).IsChecked()
723  column = self.FindWindowById(val['column']).GetValue()
724  unitsIdx = self.FindWindowById(val['units']).GetSelection()
725  if item and not tree.GetPyData(item)[0]['vdigit']:
726  tree.GetPyData(item)[0]['vdigit'] = { 'geomAttr' : dict() }
727 
728  if checked: # enable
729  if key == 'area':
730  type = key
731  else:
732  type = 'length'
733  unitsKey = Units.GetUnitsKey(type, unitsIdx)
734  tree.GetPyData(item)[0]['vdigit']['geomAttr'][key] = { 'column' : column,
735  'units' : unitsKey }
736  else:
737  if item and tree.GetPyData(item)[0]['vdigit'] and \
738  key in tree.GetPyData(item)[0]['vdigit']['geomAttr']:
739  del tree.GetPyData(item)[0]['vdigit']['geomAttr'][key]
740 
741  # query tool
742  if self.queryLength.GetValue():
743  UserSettings.Set(group = 'vdigit', key = "query", subkey = 'selection',
744  value = 0)
745  else:
746  UserSettings.Set(group = 'vdigit', key = "query", subkey = 'type',
747  value = 1)
748  UserSettings.Set(group = 'vdigit', key = "query", subkey = 'box',
749  value = self.queryBox.IsChecked())
750  UserSettings.Set(group = 'vdigit', key = "queryLength", subkey = 'than-selection',
751  value = self.queryLengthSL.GetSelection())
752  UserSettings.Set(group = 'vdigit', key = "queryLength", subkey = 'thresh',
753  value = int(self.queryLengthValue.GetValue()))
754  UserSettings.Set(group = 'vdigit', key = "queryDangle", subkey = 'than-selection',
755  value = self.queryDangleSL.GetSelection())
756  UserSettings.Set(group = 'vdigit', key = "queryDangle", subkey = 'thresh',
757  value = int(self.queryDangleValue.GetValue()))
758 
759  # select features
760  for feature in ('point', 'line',
761  'centroid', 'boundary'):
762  UserSettings.Set(group = 'vdigit', key = 'selectType',
763  subkey = [feature, 'enabled'],
764  value = self.FindWindowById(self.selectFeature[feature]).IsChecked())
765  UserSettings.Set(group = 'vdigit', key = "selectThresh", subkey = 'value',
766  value = int(self.selectThreshValue.GetValue()))
767  UserSettings.Set(group = 'vdigit', key = "checkForDupl", subkey = 'enabled',
768  value = self.checkForDupl.IsChecked())
769  UserSettings.Set(group = 'vdigit', key = "selectInside", subkey = 'enabled',
770  value = self.selectIn.IsChecked())
771 
772  # on-exit
773  UserSettings.Set(group = 'vdigit', key = "saveOnExit", subkey = 'enabled',
774  value = self.save.IsChecked())
775 
776  # break lines
777  UserSettings.Set(group = 'vdigit', key = "breakLines", subkey = 'enabled',
778  value = self.intersect.IsChecked())
779 
780  self.digit.UpdateSettings()
781 
782  # redraw map if auto-rendering is enabled
783  if self.parent.IsAutoRendered():
784  self.parent.OnRender(None)
Units management.
def OnApply
Button &#39;Apply&#39; pressed.
def UpdateSettings
Update digitizer settings.
def GetValue
Definition: widgets.py:118
def OnSave
Button &#39;Save&#39; pressed.
wxGUI debugging
def _createSymbologyPage
Create notebook page concerning symbology settings.
def __init__
Standard settings dialog for digitization purposes.
def OnChangeSnappingValue
Change snapping value - update static text.
Custom control that selects elements.
def OnCancel
Button &#39;Cancel&#39; pressed.
def OnChangeAddRecord
Checkbox &#39;Add new record&#39; status changed.
def OnGeomAttrb
Register geometry attributes (enable/disable)
def OnChangeSnappingUnits
Snapping units change -&gt; update static text.
def OnChangeCategoryMode
Change category mode.
def _createQueryPage
Create notebook page for query tool.
def _symbologyData
Data for _createSymbologyPage()
def _createGeneralPage
Create notebook page concerning general settings.
Default GUI settings.
def _createAttributesPage
Create notebook page for attributes.