nviz_preferences.py 32 KB

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