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