nviz_preferences.py 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. """
  2. @package nviz_preferences.py
  3. @brief Nviz (3D view) preferences window
  4. Classes:
  5. - NvizPreferencesDialog
  6. (C) 2008-2010 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> (Google SoC 2008/2010)
  10. @author Enhancements by Michael Barton <michael.barton@asu.edu>
  11. """
  12. import types
  13. import copy
  14. import wx
  15. import wx.lib.colourselect as csel
  16. import globalvar
  17. from preferences import globalSettings as UserSettings
  18. from preferences import PreferencesBaseDialog
  19. class NvizPreferencesDialog(PreferencesBaseDialog):
  20. """!Nviz preferences dialog"""
  21. def __init__(self, parent, title = _("3D view settings"),
  22. settings = UserSettings):
  23. PreferencesBaseDialog.__init__(self, parent = parent, title = title,
  24. settings = settings)
  25. self.toolWin = self.parent.GetLayerManager().nviz
  26. self.win = dict()
  27. # create notebook pages
  28. self._createViewPage(self.notebook)
  29. self._createLightPage(self.notebook)
  30. self._createSurfacePage(self.notebook)
  31. self._createVectorPage(self.notebook)
  32. self.SetMinSize(self.GetBestSize())
  33. self.SetSize(self.size)
  34. def _createViewPage(self, notebook):
  35. """!Create notebook page for general settings"""
  36. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  37. notebook.AddPage(page = panel,
  38. text = " %s " % _("View"))
  39. pageSizer = wx.BoxSizer(wx.VERTICAL)
  40. self.win['general'] = {}
  41. self.win['view'] = {}
  42. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  43. label = " %s " % (_("View")))
  44. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  45. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  46. # perspective
  47. self.win['view']['persp'] = {}
  48. pvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp')
  49. ipvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp', internal = True)
  50. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  51. label = _("Perspective:")),
  52. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  53. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  54. label = _("(value)")),
  55. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  56. pval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  57. initial = pvals['value'],
  58. min = ipvals['min'],
  59. max = ipvals['max'])
  60. self.win['view']['persp']['value'] = pval.GetId()
  61. gridSizer.Add(item = pval, pos = (0, 2),
  62. flag = wx.ALIGN_CENTER_VERTICAL)
  63. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  64. label = _("(step)")),
  65. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  66. pstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  67. initial = pvals['step'],
  68. min = ipvals['min'],
  69. max = ipvals['max']-1)
  70. self.win['view']['persp']['step'] = pstep.GetId()
  71. gridSizer.Add(item = pstep, pos = (0, 4),
  72. flag = wx.ALIGN_CENTER_VERTICAL)
  73. # position
  74. self.win['view']['position'] = {}
  75. posvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'position')
  76. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  77. label = _("Position:")),
  78. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  79. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  80. label = _("(x)")),
  81. pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  82. px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  83. initial = posvals['x'] * 100,
  84. min = 0,
  85. max = 100)
  86. self.win['view']['position']['x'] = px.GetId()
  87. gridSizer.Add(item = px, pos = (1, 2),
  88. flag = wx.ALIGN_CENTER_VERTICAL)
  89. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  90. label = "(y)"),
  91. pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  92. py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  93. initial = posvals['y'] * 100,
  94. min = 0,
  95. max = 100)
  96. self.win['view']['position']['y'] = py.GetId()
  97. gridSizer.Add(item = py, pos = (1, 4),
  98. flag = wx.ALIGN_CENTER_VERTICAL)
  99. # height
  100. self.win['view']['height'] = {}
  101. hvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'height')
  102. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  103. label = _("Height:")),
  104. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  105. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  106. label = _("(step)")),
  107. pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  108. hstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  109. initial = hvals['step'],
  110. min = 1,
  111. max = 1e6)
  112. self.win['view']['height']['step'] = hstep.GetId()
  113. gridSizer.Add(item = hstep, pos = (2, 2),
  114. flag = wx.ALIGN_CENTER_VERTICAL)
  115. # twist
  116. self.win['view']['twist'] = {}
  117. tvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist')
  118. itvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist', internal = True)
  119. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  120. label = _("Twist:")),
  121. pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  122. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  123. label = _("(value)")),
  124. pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  125. tval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  126. initial = tvals['value'],
  127. min = itvals['min'],
  128. max = itvals['max'])
  129. self.win['view']['twist']['value'] = tval.GetId()
  130. gridSizer.Add(item = tval, pos = (3, 2),
  131. flag = wx.ALIGN_CENTER_VERTICAL)
  132. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  133. label = _("(step)")),
  134. pos = (3, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  135. tstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  136. initial = tvals['step'],
  137. min = itvals['min'],
  138. max = itvals['max']-1)
  139. self.win['view']['twist']['step'] = tstep.GetId()
  140. gridSizer.Add(item = tstep, pos = (3, 4),
  141. flag = wx.ALIGN_CENTER_VERTICAL)
  142. # z-exag
  143. self.win['view']['z-exag'] = {}
  144. zvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'z-exag')
  145. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  146. label = _("Z-exag:")),
  147. pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  148. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  149. label = _("(value)")),
  150. pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  151. zval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  152. min = -1e6,
  153. max = 1e6)
  154. self.win['view']['z-exag']['value'] = zval.GetId()
  155. gridSizer.Add(item = zval, pos = (4, 2),
  156. flag = wx.ALIGN_CENTER_VERTICAL)
  157. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  158. label = _("(step)")),
  159. pos = (4, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  160. zstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  161. initial = zvals['step'],
  162. min = -1e6,
  163. max = 1e6)
  164. self.win['view']['z-exag']['step'] = zstep.GetId()
  165. gridSizer.Add(item = zstep, pos = (4, 4),
  166. flag = wx.ALIGN_CENTER_VERTICAL)
  167. boxSizer.Add(item = gridSizer, proportion = 1,
  168. flag = wx.ALL | wx.EXPAND, border = 3)
  169. pageSizer.Add(item = boxSizer, proportion = 0,
  170. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  171. border = 3)
  172. box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
  173. label = " %s " % (_("Image Appearance")))
  174. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  175. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  176. gridSizer.AddGrowableCol(0)
  177. # background color
  178. self.win['view']['background'] = {}
  179. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  180. label = _("Background color:")),
  181. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  182. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  183. colour = UserSettings.Get(group = 'nviz', key = 'view',
  184. subkey = ['background', 'color']),
  185. size = globalvar.DIALOG_COLOR_SIZE)
  186. color.SetName("color")
  187. self.win['view']['background']['color'] = color.GetId()
  188. gridSizer.Add(item = color, pos = (0, 1))
  189. boxSizer.Add(item = gridSizer, proportion = 1,
  190. flag = wx.ALL | wx.EXPAND, border = 3)
  191. pageSizer.Add(item = boxSizer, proportion = 0,
  192. flag = wx.EXPAND | wx.ALL,
  193. border = 3)
  194. panel.SetSizer(pageSizer)
  195. return panel
  196. def _createLightPage(self, notebook):
  197. """!Create notebook page for general settings"""
  198. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  199. notebook.AddPage(page = panel,
  200. text = " %s " % _("Lighting"))
  201. pageSizer = wx.BoxSizer(wx.VERTICAL)
  202. self.win['light'] = {}
  203. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  204. label = " %s " % (_("Light")))
  205. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  206. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  207. # position
  208. self.win['light']['position'] = {}
  209. posvals = UserSettings.Get(group = 'nviz', key = 'light', subkey = 'position')
  210. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  211. label = _("Position:")),
  212. pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  213. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  214. label = _("(x)")),
  215. pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  216. px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  217. initial = posvals['x'] * 100,
  218. min = -100,
  219. max = 100)
  220. self.win['light']['position']['x'] = px.GetId()
  221. gridSizer.Add(item = px, pos = (0, 2),
  222. flag = wx.ALIGN_CENTER_VERTICAL)
  223. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  224. label = "(y)"),
  225. pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  226. py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  227. initial = posvals['y'] * 100,
  228. min = -100,
  229. max = 100)
  230. self.win['light']['position']['y'] = py.GetId()
  231. gridSizer.Add(item = py, pos = (0, 4),
  232. flag = wx.ALIGN_CENTER_VERTICAL)
  233. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  234. label = _("(z)")),
  235. pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
  236. pz = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  237. initial = posvals['z'],
  238. min = 0,
  239. max = 100)
  240. self.win['light']['position']['z'] = pz.GetId()
  241. gridSizer.Add(item = pz, pos = (0, 6),
  242. flag = wx.ALIGN_CENTER_VERTICAL)
  243. # brightness
  244. brightval = UserSettings.Get(group = 'nviz', key = 'light', subkey = 'bright')
  245. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  246. label = _("Brightness:")),
  247. pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  248. bright = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  249. initial = brightval,
  250. min = 0,
  251. max = 100)
  252. self.win['light']['bright'] = bright.GetId()
  253. gridSizer.Add(item = bright, pos = (1, 2),
  254. flag = wx.ALIGN_CENTER_VERTICAL)
  255. # ambient
  256. ambval = UserSettings.Get(group = 'nviz', key = 'light', subkey = 'ambient')
  257. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  258. label = _("Ambient:")),
  259. pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  260. amb = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  261. initial = ambval,
  262. min = 0,
  263. max = 100)
  264. self.win['light']['ambient'] = amb.GetId()
  265. gridSizer.Add(item = amb, pos = (2, 2),
  266. flag = wx.ALIGN_CENTER_VERTICAL)
  267. # light color
  268. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  269. label = _("Color:")),
  270. pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  271. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  272. colour = UserSettings.Get(group = 'nviz', key = 'light',
  273. subkey = 'color'),
  274. size = globalvar.DIALOG_COLOR_SIZE)
  275. color.SetName("color")
  276. self.win['light']['color'] = color.GetId()
  277. gridSizer.Add(item = color, pos = (3, 2))
  278. boxSizer.Add(item = gridSizer, proportion = 1,
  279. flag = wx.ALL | wx.EXPAND, border = 3)
  280. pageSizer.Add(item = boxSizer, proportion = 0,
  281. flag = wx.EXPAND | wx.ALL,
  282. border = 3)
  283. panel.SetSizer(pageSizer)
  284. return panel
  285. def _createSurfacePage(self, notebook):
  286. """!Create notebook page for general settings"""
  287. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  288. notebook.AddPage(page = panel,
  289. text = " %s " % _("Surface"))
  290. pageSizer = wx.BoxSizer(wx.VERTICAL)
  291. self.win['surface'] = {}
  292. # draw
  293. self.win['surface']['draw'] = {}
  294. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  295. label = " %s " % (_("Draw")))
  296. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  297. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  298. # mode
  299. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  300. label = _("Mode:")), flag = wx.ALIGN_CENTER_VERTICAL,
  301. pos = (0, 0))
  302. mode = wx.Choice(parent = panel, id = wx.ID_ANY, size = (-1, -1),
  303. choices = [_("coarse"),
  304. _("fine"),
  305. _("both")])
  306. self.win['surface']['draw']['mode'] = mode.GetId()
  307. mode.SetName('selection')
  308. mode.SetSelection(UserSettings.Get(group = 'nviz', key = 'surface',
  309. subkey = ['draw', 'mode']))
  310. gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
  311. pos = (0, 1))
  312. # fine
  313. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  314. label = _("Fine mode:")), flag = wx.ALIGN_CENTER_VERTICAL,
  315. pos = (1, 0))
  316. res = UserSettings.Get(group = 'nviz', key = 'surface', subkey = ['draw','res-fine'])
  317. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  318. label = _("resolution:")), flag = wx.ALIGN_CENTER_VERTICAL,
  319. pos = (1, 1))
  320. fine = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  321. initial = res,
  322. min = 1,
  323. max = 100)
  324. self.win['surface']['draw']['res-fine'] = fine.GetId()
  325. gridSizer.Add(item = fine, flag = wx.ALIGN_CENTER_VERTICAL,
  326. pos = (1, 2))
  327. # coarse
  328. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  329. label = _("Coarse mode:")), flag = wx.ALIGN_CENTER_VERTICAL,
  330. pos = (2, 0))
  331. res = UserSettings.Get(group = 'nviz', key = 'surface', subkey = ['draw','res-coarse'])
  332. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  333. label = _("resolution:")), flag = wx.ALIGN_CENTER_VERTICAL,
  334. pos = (2, 1))
  335. coarse = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  336. initial = res,
  337. min = 1,
  338. max = 100)
  339. self.win['surface']['draw']['res-coarse'] = coarse.GetId()
  340. gridSizer.Add(item = coarse, flag = wx.ALIGN_CENTER_VERTICAL,
  341. pos = (2, 2))
  342. #style
  343. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  344. label = _("style:")), flag = wx.ALIGN_CENTER_VERTICAL,
  345. pos = (3, 1))
  346. style = wx.Choice(parent = panel, id = wx.ID_ANY, size = (-1, -1),
  347. choices = [_("wire"),
  348. _("surface")])
  349. self.win['surface']['draw']['style'] = style.GetId()
  350. style.SetName('selection')
  351. style.SetSelection(UserSettings.Get(group = 'nviz', key = 'surface',
  352. subkey = ['draw', 'style']))
  353. self.win['surface']['draw']['style'] = style.GetId()
  354. gridSizer.Add(item = style, flag = wx.ALIGN_CENTER_VERTICAL,
  355. pos = (3, 2))
  356. #wire color
  357. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  358. label = _("wire color:")), flag = wx.ALIGN_CENTER_VERTICAL,
  359. pos = (4, 1))
  360. color = csel.ColourSelect(panel, id = wx.ID_ANY,
  361. colour = UserSettings.Get(group = 'nviz', key = 'surface',
  362. subkey = ['draw', 'wire-color']),
  363. size = globalvar.DIALOG_COLOR_SIZE)
  364. color.SetName("color")
  365. self.win['surface']['draw']['wire-color'] = color.GetId()
  366. gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL,
  367. pos = (4, 2))
  368. boxSizer.Add(item = gridSizer, proportion = 1,
  369. flag = wx.ALL | wx.EXPAND, border = 3)
  370. pageSizer.Add(item = boxSizer, proportion = 0,
  371. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  372. border = 3)
  373. panel.SetSizer(pageSizer)
  374. return panel
  375. def _createVectorPage(self, notebook):
  376. """!Create notebook page for general settings"""
  377. panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
  378. notebook.AddPage(page = panel,
  379. text = " %s " % _("Vector"))
  380. pageSizer = wx.BoxSizer(wx.VERTICAL)
  381. # vector lines
  382. self.win['vector'] = {}
  383. self.win['vector']['lines'] = {}
  384. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  385. label = " %s " % (_("Vector lines")))
  386. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  387. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
  388. # show
  389. row = 0
  390. showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  391. label = _("Show lines"))
  392. self.win['vector']['lines']['show'] = showLines.GetId()
  393. showLines.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
  394. subkey = ['lines', 'show']))
  395. gridSizer.Add(item = showLines, pos = (row, 0))
  396. boxSizer.Add(item = gridSizer, proportion = 1,
  397. flag = wx.ALL | wx.EXPAND, border = 3)
  398. pageSizer.Add(item = boxSizer, proportion = 0,
  399. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  400. border = 3)
  401. # vector points
  402. self.win['vector']['points'] = {}
  403. box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
  404. label = " %s " % (_("Vector points")))
  405. boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
  406. gridSizer = wx.GridBagSizer(vgap = 3, hgap = 5)
  407. # show
  408. row = 0
  409. showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
  410. label = _("Show points"))
  411. showPoints.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
  412. subkey = ['points', 'show']))
  413. self.win['vector']['points']['show'] = showPoints.GetId()
  414. gridSizer.Add(item = showPoints, pos = (row, 0), span = (1, 8))
  415. # icon size
  416. row += 1
  417. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  418. label = _("Size:")),
  419. pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
  420. isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  421. initial = 100,
  422. min = 1,
  423. max = 1e6)
  424. self.win['vector']['points']['size'] = isize.GetId()
  425. isize.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
  426. subkey = ['points', 'size']))
  427. gridSizer.Add(item = isize, pos = (row, 1),
  428. flag = wx.ALIGN_CENTER_VERTICAL)
  429. # icon width
  430. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  431. label = _("Width:")),
  432. pos = (row, 2), flag = wx.ALIGN_CENTER_VERTICAL)
  433. iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
  434. initial = 2,
  435. min = 1,
  436. max = 1e6)
  437. self.win['vector']['points']['width'] = isize.GetId()
  438. iwidth.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
  439. subkey = ['points', 'width']))
  440. gridSizer.Add(item = iwidth, pos = (row, 3),
  441. flag = wx.ALIGN_CENTER_VERTICAL)
  442. # icon symbol
  443. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  444. label = _("Marker:")),
  445. pos = (row, 4), flag = wx.ALIGN_CENTER_VERTICAL)
  446. isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
  447. choices = UserSettings.Get(group = 'nviz', key = 'vector',
  448. subkey = ['points', 'marker'], internal = True))
  449. isym.SetName("selection")
  450. self.win['vector']['points']['marker'] = isym.GetId()
  451. isym.SetSelection(UserSettings.Get(group = 'nviz', key = 'vector',
  452. subkey = ['points', 'marker']))
  453. gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
  454. pos = (row, 5))
  455. # icon color
  456. gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
  457. label = _("Color:")),
  458. pos = (row, 6), flag = wx.ALIGN_CENTER_VERTICAL)
  459. icolor = csel.ColourSelect(panel, id = wx.ID_ANY)
  460. icolor.SetName("color")
  461. self.win['vector']['points']['color'] = icolor.GetId()
  462. icolor.SetColour(UserSettings.Get(group = 'nviz', key = 'vector',
  463. subkey = ['points', 'color']))
  464. gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL,
  465. pos = (row, 7))
  466. boxSizer.Add(item = gridSizer, proportion = 1,
  467. flag = wx.ALL | wx.EXPAND, border = 3)
  468. pageSizer.Add(item = boxSizer, proportion = 0,
  469. flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
  470. border = 3)
  471. panel.SetSizer(pageSizer)
  472. return panel
  473. def _getValue(self, win):
  474. if win.GetName() == "selection":
  475. value = win.GetSelection()
  476. elif win.GetName() == "color":
  477. value = tuple(win.GetColour())
  478. else:
  479. value = win.GetValue()
  480. return value
  481. def OnDefault(self, event):
  482. """Restore default settings"""
  483. settings = copy.deepcopy(UserSettings.GetDefaultSettings()['nviz'])
  484. UserSettings.Set(group = 'nviz',
  485. value = settings)
  486. for subgroup, key in settings.iteritems(): # view, surface, vector...
  487. if subgroup != 'view':
  488. continue
  489. for subkey, value in key.iteritems():
  490. for subvalue in value.keys():
  491. win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
  492. val = settings[subgroup][subkey][subvalue]
  493. if subkey == 'position':
  494. if val < 1:
  495. val = int(val * 100)
  496. win.SetValue(val)
  497. event.Skip()
  498. def OnApply(self, event):
  499. """Apply Nviz settings for current session"""
  500. settings = UserSettings.Get(group = 'nviz')
  501. for subgroup, key in settings.iteritems(): # view, surface, vector...
  502. for subkey, value in key.iteritems():
  503. if type(value) == types.DictType:
  504. for subvalue in value.keys():
  505. try:
  506. win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
  507. except KeyError, e:
  508. #print "error", str(e)+ str(subgroup)+str(subkey)+str(subvalue)
  509. continue
  510. value = self._getValue(win)
  511. if subkey == 'position':
  512. if subvalue in ('x', 'y'):
  513. value = float(value) / 100
  514. settings[subgroup][subkey][subvalue] = value
  515. else:
  516. try:
  517. win = self.FindWindowById(self.win[subgroup][subkey])
  518. except KeyError, e:
  519. #print "error", str(subgroup)+" "+str(subkey)+" "+str(value)
  520. continue
  521. value = self._getValue(win)
  522. settings[subgroup][subkey] = value
  523. def OnLoad(self, event):
  524. """!Apply button pressed"""
  525. self.LoadSettings()
  526. if event:
  527. event.Skip()
  528. def LoadSettings(self):
  529. """!Load saved Nviz settings and apply to current session"""
  530. UserSettings.ReadSettingsFile()
  531. settings = copy.deepcopy(UserSettings.Get(group = 'nviz'))
  532. for subgroup, key in settings.iteritems(): # view, surface, vector...
  533. for subkey, value in key.iteritems():
  534. for subvalue in value.keys():
  535. if subvalue == 'step':
  536. continue
  537. else:
  538. insetting = value[subvalue]
  539. if subgroup == 'view':
  540. for viewkey, viewitem in self.mapWindow.view[subkey].iteritems():
  541. if viewkey == subvalue:
  542. self.mapWindow.view[subkey][viewkey] = insetting
  543. else:
  544. continue
  545. else:
  546. for otherkey, otheritem in self.win[subgroup][subkey].iteritems():
  547. if type(otheritem) == data:
  548. for endkey, enditem in otheritem.iteritems():
  549. if endkey == subvalue:
  550. paramwin = self.FindWindowById(enditem)
  551. else:
  552. continue
  553. else:
  554. if otherkey == subvalue:
  555. paramwin = self.FindWindowById(otheritem)
  556. else:
  557. continue
  558. if type(insetting) in [tuple, list] and len(insetting) > 2:
  559. insetting = tuple(insetting)
  560. paramwin.SetColour(insetting)
  561. else:
  562. try:
  563. paramwin.SetValue(insetting)
  564. except:
  565. try:
  566. paramwin.SetStringSelection(insetting)
  567. except:
  568. continue
  569. self.toolWin.UpdateSettings()
  570. self.FindWindowById(self.win['view']['position']).Draw()
  571. self.FindWindowById(self.win['view']['position']).Refresh(False)
  572. self.mapWindow.render['quick'] = False
  573. self.mapWindow.Refresh(False)
  574. def OnSave(self, event):
  575. """!Save button pressed
  576. Save settings to configuration file
  577. """
  578. self.OnApply(None)
  579. fileSettings = {}
  580. UserSettings.ReadSettingsFile(settings = fileSettings)
  581. fileSettings['nviz'] = UserSettings.Get(group = 'nviz')
  582. UserSettings.SaveToFile(fileSettings)
  583. self.parent.GetLayerManager().goutput.WriteLog(
  584. _('3D view settings saved to file <%s>.') % UserSettings.filePath)
  585. self.Destroy()