preferences.py 25 KB

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