preferences.py 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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. if tree:
  362. item = tree.FindItemByData('maplayer', mapLayer)
  363. else:
  364. item = None
  365. row = 0
  366. for attrb in ['length', 'area', 'perimeter']:
  367. # checkbox
  368. check = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  369. label = self.geomAttrb[attrb]['label'])
  370. ### self.deleteRecord.SetValue(UserSettings.Get(group='vdigit', key="delRecord", subkey='enabled'))
  371. check.Bind(wx.EVT_CHECKBOX, self.OnGeomAttrb)
  372. # column (only numeric)
  373. column = ColumnSelect(parent = panel, size = (200, -1))
  374. column.InsertColumns(vector = vectorName,
  375. layer = layer, excludeKey = True,
  376. type = ['integer', 'double precision'])
  377. # units
  378. if attrb == 'area':
  379. choices = Units.GetUnitsList('area')
  380. else:
  381. choices = Units.GetUnitsList('length')
  382. win_units = wx.Choice(parent = panel, id = wx.ID_ANY,
  383. choices = choices, size = (120, -1))
  384. # default values
  385. check.SetValue(False)
  386. if item and tree.GetLayerInfo(item, key = 'vdigit') and \
  387. 'geomAttr' in tree.GetLayerInfo(item, key = 'vdigit') and \
  388. attrb in tree.GetLayerInfo(item, key = 'vdigit')['geomAttr']:
  389. check.SetValue(True)
  390. column.SetStringSelection(tree.GetLayerInfo(item, key = 'vdigit')['geomAttr'][attrb]['column'])
  391. if attrb == 'area':
  392. type = 'area'
  393. else:
  394. type = 'length'
  395. unitsIdx = Units.GetUnitsIndex(type,
  396. tree.GetLayerInfo(item, key = 'vdigit')['geomAttr'][attrb]['units'])
  397. win_units.SetSelection(unitsIdx)
  398. if not vectorName:
  399. check.Enable(False)
  400. column.Enable(False)
  401. if not check.IsChecked():
  402. column.Enable(False)
  403. self.geomAttrb[attrb]['check'] = check.GetId()
  404. self.geomAttrb[attrb]['column'] = column.GetId()
  405. self.geomAttrb[attrb]['units'] = win_units.GetId()
  406. gridSizer.Add(item = check,
  407. flag = wx.ALIGN_CENTER_VERTICAL,
  408. pos = (row, 0))
  409. gridSizer.Add(item = column,
  410. pos = (row, 1))
  411. gridSizer.Add(item = win_units,
  412. pos = (row, 2))
  413. row += 1
  414. note = '\n'.join(textwrap.wrap(_("Note: These settings are stored "
  415. "in the workspace not in the vector digitizer "
  416. "preferences."), 55))
  417. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  418. label = note),
  419. pos = (3, 0), span = (1, 3))
  420. sizer.Add(item = gridSizer, proportion = 1,
  421. flag = wx.ALL | wx.EXPAND, border = 1)
  422. border.Add(item = sizer, proportion = 0,
  423. flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
  424. # bindings
  425. self.Bind(wx.EVT_CHECKBOX, self.OnChangeAddRecord, self.addRecord)
  426. self.Bind(wx.EVT_CHOICE, self.OnChangeCategoryMode, self.categoryMode)
  427. self.Bind(wx.EVT_SPINCTRL, self.OnChangeLayer, self.layer)
  428. panel.SetSizer(border)
  429. return panel
  430. def _symbologyData(self):
  431. """!Data for _createSymbologyPage()
  432. label | checkbox | color
  433. """
  434. return (
  435. (_("Digitize new line segment"), "newSegment"),
  436. (_("Digitize new line/boundary"), "newLine"),
  437. (_("Highlight"), "highlight"),
  438. (_("Highlight (duplicates)"), "highlightDupl"),
  439. (_("Point"), "point"),
  440. (_("Line"), "line"),
  441. (_("Boundary (no area)"), "boundaryNo"),
  442. (_("Boundary (one area)"), "boundaryOne"),
  443. (_("Boundary (two areas)"), "boundaryTwo"),
  444. (_("Centroid (in area)"), "centroidIn"),
  445. (_("Centroid (outside area)"), "centroidOut"),
  446. (_("Centroid (duplicate in area)"), "centroidDup"),
  447. (_("Node (one line)"), "nodeOne"),
  448. (_("Node (two lines)"), "nodeTwo"),
  449. (_("Vertex"), "vertex"),
  450. (_("Area (closed boundary + centroid)"), "area"),
  451. (_("Direction"), "direction"),)
  452. def OnGeomAttrb(self, event):
  453. """!Register geometry attributes (enable/disable)
  454. """
  455. checked = event.IsChecked()
  456. id = event.GetId()
  457. key = None
  458. for attrb, val in self.geomAttrb.iteritems():
  459. if val['check'] == id:
  460. key = attrb
  461. break
  462. column = self.FindWindowById(self.geomAttrb[key]['column'])
  463. if checked:
  464. column.Enable()
  465. else:
  466. column.Enable(False)
  467. def OnChangeCategoryMode(self, event):
  468. """!Change category mode
  469. """
  470. mode = event.GetSelection()
  471. UserSettings.Set(group = 'vdigit', key = "categoryMode", subkey = 'selection', value = mode)
  472. if mode == 1: # manual entry
  473. self.category.Enable(True)
  474. elif self.category.IsEnabled(): # disable
  475. self.category.Enable(False)
  476. if mode == 2 and self.addRecord.IsChecked(): # no category
  477. self.addRecord.SetValue(False)
  478. self.digit.SetCategory()
  479. self.category.SetValue(UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value'))
  480. def OnChangeLayer(self, event):
  481. """!Layer changed
  482. """
  483. layer = event.GetInt()
  484. if layer > 0:
  485. UserSettings.Set(group = 'vdigit', key = 'layer', subkey = 'value', value = layer)
  486. self.digit.SetCategory()
  487. self.category.SetValue(UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value'))
  488. event.Skip()
  489. def OnChangeAddRecord(self, event):
  490. """!Checkbox 'Add new record' status changed
  491. """
  492. pass
  493. # self.category.SetValue(self.digit.SetCategory())
  494. def OnChangeSnappingValue(self, event):
  495. """!Change snapping value - update static text
  496. """
  497. value = self.snappingValue.GetValue()
  498. if value < 0:
  499. region = self.parent.MapWindow.Map.GetRegion()
  500. res = (region['nsres'] + region['ewres']) / 2.
  501. threshold = self.digit.GetDisplay().GetThreshold(value = res)
  502. else:
  503. if self.snappingUnit.GetStringSelection() == "map units":
  504. threshold = value
  505. else:
  506. threshold = self.digit.GetDisplay().GetThreshold(value = value)
  507. if value == 0:
  508. self.snappingInfo.SetLabel(_("Snapping disabled"))
  509. elif value < 0:
  510. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s "
  511. "(based on comp. resolution)") %
  512. {'value' : threshold,
  513. 'units' : self.mapUnits.lower()})
  514. else:
  515. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  516. {'value' : threshold,
  517. 'units' : self.mapUnits.lower()})
  518. event.Skip()
  519. def OnChangeSnappingUnits(self, event):
  520. """!Snapping units change -> update static text
  521. """
  522. value = self.snappingValue.GetValue()
  523. units = self.snappingUnit.GetStringSelection()
  524. threshold = self.digit.GetDisplay().GetThreshold(value = value, units = units)
  525. if units == "map units":
  526. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  527. {'value' : value,
  528. 'units' : self.mapUnits})
  529. else:
  530. self.snappingInfo.SetLabel(_("Snapping threshold is %(value).1f %(units)s") %
  531. {'value' : threshold,
  532. 'units' : self.mapUnits})
  533. event.Skip()
  534. def OnChangeQuery(self, event):
  535. """!Change query
  536. """
  537. if self.queryLength.GetValue():
  538. # length
  539. self.queryLengthSL.Enable(True)
  540. self.queryLengthValue.Enable(True)
  541. self.queryDangleSL.Enable(False)
  542. self.queryDangleValue.Enable(False)
  543. else:
  544. # dangle
  545. self.queryLengthSL.Enable(False)
  546. self.queryLengthValue.Enable(False)
  547. self.queryDangleSL.Enable(True)
  548. self.queryDangleValue.Enable(True)
  549. def OnSave(self, event):
  550. """!Button 'Save' pressed
  551. """
  552. self.UpdateSettings()
  553. self.parent.toolbars['vdigit'].settingsDialog = None
  554. fileSettings = {}
  555. UserSettings.ReadSettingsFile(settings = fileSettings)
  556. fileSettings['vdigit'] = UserSettings.Get(group = 'vdigit')
  557. file = UserSettings.SaveToFile(fileSettings)
  558. self.parent.GetLayerManager().GetLogWindow().WriteLog(_('Vector digitizer settings saved to file <%s>.') % file)
  559. self.Destroy()
  560. event.Skip()
  561. def OnApply(self, event):
  562. """!Button 'Apply' pressed
  563. """
  564. self.UpdateSettings()
  565. def OnCancel(self, event):
  566. """!Button 'Cancel' pressed
  567. """
  568. self.parent.toolbars['vdigit'].settingsDialog = None
  569. self.Destroy()
  570. if event:
  571. event.Skip()
  572. def UpdateSettings(self):
  573. """!Update digitizer settings
  574. """
  575. self.parent.GetLayerManager().WorkspaceChanged() # geometry attributes
  576. # symbology
  577. for key, (enabled, color) in self.symbology.iteritems():
  578. if enabled:
  579. UserSettings.Set(group = 'vdigit', key = 'symbol',
  580. subkey = [key, 'enabled'],
  581. value = enabled.IsChecked())
  582. UserSettings.Set(group = 'vdigit', key = 'symbol',
  583. subkey = [key, 'color'],
  584. value = tuple(color.GetColour()))
  585. else:
  586. UserSettings.Set(group = 'vdigit', key = 'symbol',
  587. subkey = [key, 'color'],
  588. value = tuple(color.GetColour()))
  589. # display
  590. UserSettings.Set(group = 'vdigit', key = "lineWidth", subkey = 'value',
  591. value = int(self.lineWidthValue.GetValue()))
  592. # snapping
  593. UserSettings.Set(group = 'vdigit', key = "snapping", subkey = 'value',
  594. value = int(self.snappingValue.GetValue()))
  595. UserSettings.Set(group = 'vdigit', key = "snapping", subkey = 'units',
  596. value = self.snappingUnit.GetStringSelection())
  597. UserSettings.Set(group = 'vdigit', key = "snapToVertex", subkey = 'enabled',
  598. value = self.snapVertex.IsChecked())
  599. # digitize new feature
  600. UserSettings.Set(group = 'vdigit', key = "addRecord", subkey = 'enabled',
  601. value = self.addRecord.IsChecked())
  602. UserSettings.Set(group = 'vdigit', key = "layer", subkey = 'value',
  603. value = int(self.layer.GetValue()))
  604. UserSettings.Set(group = 'vdigit', key = "category", subkey = 'value',
  605. value = int(self.category.GetValue()))
  606. UserSettings.Set(group = 'vdigit', key = "categoryMode", subkey = 'selection',
  607. value = self.categoryMode.GetSelection())
  608. # delete existing feature
  609. UserSettings.Set(group = 'vdigit', key = "delRecord", subkey = 'enabled',
  610. value = self.deleteRecord.IsChecked())
  611. # geometry attributes (workspace)
  612. mapLayer = self.parent.toolbars['vdigit'].GetLayer()
  613. tree = self.parent.tree
  614. item = tree.FindItemByData('maplayer', mapLayer)
  615. for key, val in self.geomAttrb.iteritems():
  616. checked = self.FindWindowById(val['check']).IsChecked()
  617. column = self.FindWindowById(val['column']).GetValue()
  618. unitsIdx = self.FindWindowById(val['units']).GetSelection()
  619. if item and not tree.GetLayerInfo(item, key = 'vdigit'):
  620. tree.SetLayerInfo(item, key = 'vdigit', value = { 'geomAttr' : dict() })
  621. if checked: # enable
  622. if key == 'area':
  623. type = key
  624. else:
  625. type = 'length'
  626. unitsKey = Units.GetUnitsKey(type, unitsIdx)
  627. tree.GetLayerInfo(item, key = 'vdigit')['geomAttr'][key] = { 'column' : column,
  628. 'units' : unitsKey }
  629. else:
  630. if item and tree.GetLayerInfo(item, key = 'vdigit') and \
  631. key in tree.GetLayerInfo(item, key = 'vdigit')['geomAttr']:
  632. del tree.GetLayerInfo(item, key = 'vdigit')['geomAttr'][key]
  633. # query tool
  634. if self.queryLength.GetValue():
  635. UserSettings.Set(group = 'vdigit', key = "query", subkey = 'selection',
  636. value = 0)
  637. else:
  638. UserSettings.Set(group = 'vdigit', key = "query", subkey = 'type',
  639. value = 1)
  640. UserSettings.Set(group = 'vdigit', key = "query", subkey = 'box',
  641. value = self.queryBox.IsChecked())
  642. UserSettings.Set(group = 'vdigit', key = "queryLength", subkey = 'than-selection',
  643. value = self.queryLengthSL.GetSelection())
  644. UserSettings.Set(group = 'vdigit', key = "queryLength", subkey = 'thresh',
  645. value = int(self.queryLengthValue.GetValue()))
  646. UserSettings.Set(group = 'vdigit', key = "queryDangle", subkey = 'than-selection',
  647. value = self.queryDangleSL.GetSelection())
  648. UserSettings.Set(group = 'vdigit', key = "queryDangle", subkey = 'thresh',
  649. value = int(self.queryDangleValue.GetValue()))
  650. # select features
  651. for feature in ('point', 'line',
  652. 'centroid', 'boundary'):
  653. UserSettings.Set(group = 'vdigit', key = 'selectType',
  654. subkey = [feature, 'enabled'],
  655. value = self.FindWindowById(self.selectFeature[feature]).IsChecked())
  656. UserSettings.Set(group = 'vdigit', key = "selectThresh", subkey = 'value',
  657. value = int(self.selectThreshValue.GetValue()))
  658. UserSettings.Set(group = 'vdigit', key = "checkForDupl", subkey = 'enabled',
  659. value = self.checkForDupl.IsChecked())
  660. UserSettings.Set(group = 'vdigit', key = "selectInside", subkey = 'enabled',
  661. value = self.selectIn.IsChecked())
  662. # on-exit
  663. UserSettings.Set(group = 'vdigit', key = "saveOnExit", subkey = 'enabled',
  664. value = self.save.IsChecked())
  665. # break lines
  666. UserSettings.Set(group = 'vdigit', key = "breakLines", subkey = 'enabled',
  667. value = self.intersect.IsChecked())
  668. self.digit.UpdateSettings()
  669. # redraw map if auto-rendering is enabled
  670. if self.parent.IsAutoRendered():
  671. self.parent.OnRender(None)