preferences.py 37 KB

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