preferences.py 37 KB

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