2 @package nviz_preferences.py
4 @brief Nviz (3D view) preferences window
7 - NvizPreferencesDialog
9 (C) 2008-2010 by the GRASS Development Team
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
14 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
15 @author Enhancements by Michael Barton <michael.barton@asu.edu>
21 import wx.lib.colourselect
as csel
24 from preferences
import globalSettings
as UserSettings
25 from preferences
import PreferencesBaseDialog
28 """!Nviz preferences dialog"""
29 def __init__(self, parent, title = _(
"3D view settings"),
30 settings = UserSettings):
31 PreferencesBaseDialog.__init__(self, parent = parent, title = title,
33 self.
toolWin = self.parent.GetLayerManager().nviz
40 self.SetMinSize(self.GetBestSize())
41 self.SetSize(self.size)
43 def _createViewPage(self, notebook):
44 """!Create notebook page for general settings"""
45 panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
47 notebook.AddPage(page = panel,
48 text =
" %s " % _(
"View"))
50 pageSizer = wx.BoxSizer(wx.VERTICAL)
52 self.
win[
'general'] = {}
54 box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
55 label =
" %s " % (_(
"View")))
56 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
57 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
60 self.
win[
'view'][
'persp'] = {}
61 pvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'persp')
62 ipvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'persp', internal =
True)
63 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
64 label = _(
"Perspective:")),
65 pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
66 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
67 label = _(
"(value)")),
68 pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
70 pval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
71 initial = pvals[
'value'],
74 self.
win[
'view'][
'persp'][
'value'] = pval.GetId()
75 gridSizer.Add(item = pval, pos = (0, 2),
76 flag = wx.ALIGN_CENTER_VERTICAL)
78 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
80 pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
82 pstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
83 initial = pvals[
'step'],
85 max = ipvals[
'max']-1)
86 self.
win[
'view'][
'persp'][
'step'] = pstep.GetId()
87 gridSizer.Add(item = pstep, pos = (0, 4),
88 flag = wx.ALIGN_CENTER_VERTICAL)
91 self.
win[
'view'][
'pos'] = {}
92 posvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'position')
93 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
94 label = _(
"Position:")),
95 pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
96 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
98 pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
100 px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
101 initial = posvals[
'x'] * 100,
104 self.
win[
'view'][
'pos'][
'x'] = px.GetId()
105 gridSizer.Add(item = px, pos = (1, 2),
106 flag = wx.ALIGN_CENTER_VERTICAL)
108 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
110 pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
112 py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
113 initial = posvals[
'y'] * 100,
116 self.
win[
'view'][
'pos'][
'y'] = py.GetId()
117 gridSizer.Add(item = py, pos = (1, 4),
118 flag = wx.ALIGN_CENTER_VERTICAL)
121 self.
win[
'view'][
'height'] = {}
122 hvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'height')
123 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
124 label = _(
"Height:")),
125 pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
126 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
127 label = _(
"(step)")),
128 pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
130 hstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
131 initial = hvals[
'step'],
134 self.
win[
'view'][
'height'][
'step'] = hstep.GetId()
135 gridSizer.Add(item = hstep, pos = (2, 2),
136 flag = wx.ALIGN_CENTER_VERTICAL)
139 self.
win[
'view'][
'twist'] = {}
140 tvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'twist')
141 itvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'twist', internal =
True)
142 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
143 label = _(
"Twist:")),
144 pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
145 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
146 label = _(
"(value)")),
147 pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
149 tval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
150 initial = tvals[
'value'],
153 self.
win[
'view'][
'twist'][
'value'] = tval.GetId()
154 gridSizer.Add(item = tval, pos = (3, 2),
155 flag = wx.ALIGN_CENTER_VERTICAL)
157 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
158 label = _(
"(step)")),
159 pos = (3, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
161 tstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
162 initial = tvals[
'step'],
164 max = itvals[
'max']-1)
165 self.
win[
'view'][
'twist'][
'step'] = tstep.GetId()
166 gridSizer.Add(item = tstep, pos = (3, 4),
167 flag = wx.ALIGN_CENTER_VERTICAL)
170 self.
win[
'view'][
'z-exag'] = {}
171 zvals = UserSettings.Get(group =
'nviz', key =
'view', subkey =
'z-exag')
172 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
173 label = _(
"Z-exag:")),
174 pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
175 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
176 label = _(
"(value)")),
177 pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
179 zval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
182 self.
win[
'view'][
'z-exag'][
'value'] = zval.GetId()
183 gridSizer.Add(item = zval, pos = (4, 2),
184 flag = wx.ALIGN_CENTER_VERTICAL)
186 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
187 label = _(
"(step)")),
188 pos = (4, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
190 zstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
191 initial = zvals[
'step'],
194 self.
win[
'view'][
'z-exag'][
'step'] = zstep.GetId()
195 gridSizer.Add(item = zstep, pos = (4, 4),
196 flag = wx.ALIGN_CENTER_VERTICAL)
198 boxSizer.Add(item = gridSizer, proportion = 1,
199 flag = wx.ALL | wx.EXPAND, border = 3)
200 pageSizer.Add(item = boxSizer, proportion = 0,
201 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
204 box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
205 label =
" %s " % (_(
"Image Appearance")))
206 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
207 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
208 gridSizer.AddGrowableCol(0)
211 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
212 label = _(
"Background color:")),
213 pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
215 color = csel.ColourSelect(panel, id = wx.ID_ANY,
216 colour = UserSettings.Get(group =
'nviz', key =
'settings',
217 subkey = [
'general',
'bgcolor']),
218 size = globalvar.DIALOG_COLOR_SIZE)
219 self.
win[
'general'][
'bgcolor'] = color.GetId()
220 gridSizer.Add(item = color, pos = (0, 1))
222 boxSizer.Add(item = gridSizer, proportion = 1,
223 flag = wx.ALL | wx.EXPAND, border = 3)
224 pageSizer.Add(item = boxSizer, proportion = 0,
225 flag = wx.EXPAND | wx.ALL,
228 panel.SetSizer(pageSizer)
232 def _createVectorPage(self, notebook):
233 """!Create notebook page for general settings"""
234 panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
236 notebook.AddPage(page = panel,
237 text =
" %s " % _(
"Vector"))
239 pageSizer = wx.BoxSizer(wx.VERTICAL)
242 self.
win[
'vector'] = {}
243 self.
win[
'vector'][
'lines'] = {}
244 box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
245 label =
" %s " % (_(
"Vector lines")))
246 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
247 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
251 showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
252 label = _(
"Show lines"))
253 self.
win[
'vector'][
'lines'][
'show'] = showLines.GetId()
254 showLines.SetValue(UserSettings.Get(group =
'nviz', key =
'vector',
255 subkey = [
'lines',
'show']))
256 gridSizer.Add(item = showLines, pos = (row, 0))
258 boxSizer.Add(item = gridSizer, proportion = 1,
259 flag = wx.ALL | wx.EXPAND, border = 3)
260 pageSizer.Add(item = boxSizer, proportion = 0,
261 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
265 self.
win[
'vector'][
'points'] = {}
266 box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
267 label =
" %s " % (_(
"Vector points")))
268 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
269 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 5)
273 showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
274 label = _(
"Show points"))
275 showPoints.SetValue(UserSettings.Get(group =
'nviz', key =
'vector',
276 subkey = [
'points',
'show']))
277 self.
win[
'vector'][
'points'][
'show'] = showPoints.GetId()
278 gridSizer.Add(item = showPoints, pos = (row, 0), span = (1, 8))
282 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
284 pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
286 isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
290 self.
win[
'vector'][
'points'][
'size'] = isize.GetId()
291 isize.SetValue(UserSettings.Get(group =
'nviz', key =
'vector',
292 subkey = [
'points',
'size']))
293 gridSizer.Add(item = isize, pos = (row, 1),
294 flag = wx.ALIGN_CENTER_VERTICAL)
297 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
298 label = _(
"Width:")),
299 pos = (row, 2), flag = wx.ALIGN_CENTER_VERTICAL)
301 iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
305 self.
win[
'vector'][
'points'][
'width'] = isize.GetId()
306 iwidth.SetValue(UserSettings.Get(group =
'nviz', key =
'vector',
307 subkey = [
'points',
'width']))
308 gridSizer.Add(item = iwidth, pos = (row, 3),
309 flag = wx.ALIGN_CENTER_VERTICAL)
312 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
313 label = _(
"Marker:")),
314 pos = (row, 4), flag = wx.ALIGN_CENTER_VERTICAL)
315 isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
316 choices = UserSettings.Get(group =
'nviz', key =
'vector',
317 subkey = [
'points',
'marker'], internal =
True))
318 isym.SetName(
"selection")
319 self.
win[
'vector'][
'points'][
'marker'] = isym.GetId()
320 isym.SetSelection(UserSettings.Get(group =
'nviz', key =
'vector',
321 subkey = [
'points',
'marker']))
322 gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
326 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
327 label = _(
"Color:")),
328 pos = (row, 6), flag = wx.ALIGN_CENTER_VERTICAL)
329 icolor = csel.ColourSelect(panel, id = wx.ID_ANY)
330 icolor.SetName(
"color")
331 self.
win[
'vector'][
'points'][
'color'] = icolor.GetId()
332 icolor.SetColour(UserSettings.Get(group =
'nviz', key =
'vector',
333 subkey = [
'points',
'color']))
334 gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL,
337 boxSizer.Add(item = gridSizer, proportion = 1,
338 flag = wx.ALL | wx.EXPAND, border = 3)
339 pageSizer.Add(item = boxSizer, proportion = 0,
340 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
343 panel.SetSizer(pageSizer)
348 """Restore default settings"""
349 settings = copy.deepcopy(UserSettings.GetDefaultSettings()[
'nviz'])
350 UserSettings.Set(group =
'nviz',
353 for subgroup, key
in settings.iteritems():
354 if subgroup !=
'view':
356 for subkey, value
in key.iteritems():
357 for subvalue
in value.keys():
358 win = self.FindWindowById(self.
win[subgroup][subkey][subvalue])
359 val = settings[subgroup][subkey][subvalue]
360 if subkey ==
'position':
368 """Apply Nviz settings for current session"""
369 settings = UserSettings.Get(group =
'nviz')
370 for subgroup, key
in settings.iteritems():
371 for subkey, value
in key.iteritems():
372 if type(value) == types.DictType:
373 for subvalue
in value.keys():
375 win = self.FindWindowById(self.
win[subgroup][subkey][subvalue])
380 if win.GetName() ==
"selection":
381 value = win.GetSelection()
382 elif win.GetName() ==
"color":
383 value = tuple(win.GetColour())
385 value = win.GetValue()
387 value = float(value) / 100
389 settings[subgroup][subkey][subvalue] = value
392 """!Apply changes, update map and save settings of selected
398 if self.GetSelection() == self.page[
'id']:
400 UserSettings.ReadSettingsFile(settings = fileSettings)
401 fileSettings[
'nviz'] = UserSettings.Get(group =
'nviz')
402 file = UserSettings.SaveToFile(fileSettings)
403 self.parent.goutput.WriteLog(_(
'Nviz settings saved to file <%s>.') % file)
406 """!Apply button pressed"""
413 """!Load saved Nviz settings and apply to current session"""
414 UserSettings.ReadSettingsFile()
415 settings = copy.deepcopy(UserSettings.Get(group =
'nviz'))
417 for subgroup, key
in settings.iteritems():
418 for subkey, value
in key.iteritems():
419 for subvalue
in value.keys():
420 if subvalue ==
'step':
423 insetting = value[subvalue]
424 if subgroup ==
'view':
425 for viewkey, viewitem
in self.mapWindow.view[subkey].iteritems():
426 if viewkey == subvalue:
427 self.mapWindow.view[subkey][viewkey] = insetting
431 for otherkey, otheritem
in self.
win[subgroup][subkey].iteritems():
432 if type(otheritem) == data:
433 for endkey, enditem
in otheritem.iteritems():
434 if endkey == subvalue:
435 paramwin = self.FindWindowById(enditem)
439 if otherkey == subvalue:
440 paramwin = self.FindWindowById(otheritem)
443 if type(insetting)
in [tuple, list]
and len(insetting) > 2:
444 insetting = tuple(insetting)
445 paramwin.SetColour(insetting)
448 paramwin.SetValue(insetting)
451 paramwin.SetStringSelection(insetting)
455 self.toolWin.UpdateSettings()
456 self.FindWindowById(self.
win[
'view'][
'pos']).Draw()
457 self.FindWindowById(self.
win[
'view'][
'pos']).Refresh(
False)
459 self.mapWindow.render[
'quick'] =
False
460 self.mapWindow.Refresh(
False)
463 """!Save button pressed
465 Save settings to configuration file
468 UserSettings.ReadSettingsFile(settings = fileSettings)
469 fileSettings[
'nviz'] = UserSettings.Get(group =
'nviz')
471 fileName = UserSettings.SaveToFile(fileSettings)
472 self.parent.GetLayerManager().goutput.WriteLog(_(
'3D view settings saved to file <%s>.') % fileName)