GRASS Programmer's Manual
6.4.2(2012)
|
00001 """ 00002 @package nviz_preferences.py 00003 00004 @brief Nviz (3D view) preferences window 00005 00006 Classes: 00007 - NvizPreferencesDialog 00008 00009 (C) 2008-2010 by the GRASS Development Team 00010 00011 This program is free software under the GNU General Public License 00012 (>=v2). Read the file COPYING that comes with GRASS for details. 00013 00014 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010) 00015 @author Enhancements by Michael Barton <michael.barton@asu.edu> 00016 """ 00017 00018 import types 00019 00020 import wx 00021 import wx.lib.colourselect as csel 00022 00023 import globalvar 00024 from preferences import globalSettings as UserSettings 00025 from preferences import PreferencesBaseDialog 00026 00027 class NvizPreferencesDialog(PreferencesBaseDialog): 00028 """!Nviz preferences dialog""" 00029 def __init__(self, parent, title = _("3D view settings"), 00030 settings = UserSettings): 00031 PreferencesBaseDialog.__init__(self, parent = parent, title = title, 00032 settings = settings) 00033 self.toolWin = self.parent.GetLayerManager().nviz 00034 self.win = dict() 00035 00036 # create notebook pages 00037 self._createViewPage(self.notebook) 00038 self._createVectorPage(self.notebook) 00039 00040 self.SetMinSize(self.GetBestSize()) 00041 self.SetSize(self.size) 00042 00043 def _createViewPage(self, notebook): 00044 """!Create notebook page for general settings""" 00045 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00046 00047 notebook.AddPage(page = panel, 00048 text = " %s " % _("View")) 00049 00050 pageSizer = wx.BoxSizer(wx.VERTICAL) 00051 00052 self.win['general'] = {} 00053 self.win['view'] = {} 00054 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, 00055 label = " %s " % (_("View"))) 00056 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00057 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3) 00058 00059 # perspective 00060 self.win['view']['persp'] = {} 00061 pvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp') 00062 ipvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp', internal = True) 00063 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00064 label = _("Perspective:")), 00065 pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00066 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00067 label = _("(value)")), 00068 pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00069 00070 pval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00071 initial = pvals['value'], 00072 min = ipvals['min'], 00073 max = ipvals['max']) 00074 self.win['view']['persp']['value'] = pval.GetId() 00075 gridSizer.Add(item = pval, pos = (0, 2), 00076 flag = wx.ALIGN_CENTER_VERTICAL) 00077 00078 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00079 label = _("(step)")), 00080 pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00081 00082 pstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00083 initial = pvals['step'], 00084 min = ipvals['min'], 00085 max = ipvals['max']-1) 00086 self.win['view']['persp']['step'] = pstep.GetId() 00087 gridSizer.Add(item = pstep, pos = (0, 4), 00088 flag = wx.ALIGN_CENTER_VERTICAL) 00089 00090 # position 00091 self.win['view']['pos'] = {} 00092 posvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'position') 00093 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00094 label = _("Position:")), 00095 pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00096 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00097 label = _("(x)")), 00098 pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00099 00100 px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00101 initial = posvals['x'] * 100, 00102 min = 0, 00103 max = 100) 00104 self.win['view']['pos']['x'] = px.GetId() 00105 gridSizer.Add(item = px, pos = (1, 2), 00106 flag = wx.ALIGN_CENTER_VERTICAL) 00107 00108 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00109 label = "(y)"), 00110 pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00111 00112 py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00113 initial = posvals['y'] * 100, 00114 min = 0, 00115 max = 100) 00116 self.win['view']['pos']['y'] = py.GetId() 00117 gridSizer.Add(item = py, pos = (1, 4), 00118 flag = wx.ALIGN_CENTER_VERTICAL) 00119 00120 # height 00121 self.win['view']['height'] = {} 00122 hvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'height') 00123 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00124 label = _("Height:")), 00125 pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00126 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00127 label = _("(step)")), 00128 pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00129 00130 hstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00131 initial = hvals['step'], 00132 min = 1, 00133 max = 1e6) 00134 self.win['view']['height']['step'] = hstep.GetId() 00135 gridSizer.Add(item = hstep, pos = (2, 2), 00136 flag = wx.ALIGN_CENTER_VERTICAL) 00137 00138 # twist 00139 self.win['view']['twist'] = {} 00140 tvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist') 00141 itvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist', internal = True) 00142 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00143 label = _("Twist:")), 00144 pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00145 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00146 label = _("(value)")), 00147 pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00148 00149 tval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00150 initial = tvals['value'], 00151 min = itvals['min'], 00152 max = itvals['max']) 00153 self.win['view']['twist']['value'] = tval.GetId() 00154 gridSizer.Add(item = tval, pos = (3, 2), 00155 flag = wx.ALIGN_CENTER_VERTICAL) 00156 00157 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00158 label = _("(step)")), 00159 pos = (3, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00160 00161 tstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00162 initial = tvals['step'], 00163 min = itvals['min'], 00164 max = itvals['max']-1) 00165 self.win['view']['twist']['step'] = tstep.GetId() 00166 gridSizer.Add(item = tstep, pos = (3, 4), 00167 flag = wx.ALIGN_CENTER_VERTICAL) 00168 00169 # z-exag 00170 self.win['view']['z-exag'] = {} 00171 zvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'z-exag') 00172 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00173 label = _("Z-exag:")), 00174 pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00175 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00176 label = _("(value)")), 00177 pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00178 00179 zval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00180 min = -1e6, 00181 max = 1e6) 00182 self.win['view']['z-exag']['value'] = zval.GetId() 00183 gridSizer.Add(item = zval, pos = (4, 2), 00184 flag = wx.ALIGN_CENTER_VERTICAL) 00185 00186 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00187 label = _("(step)")), 00188 pos = (4, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) 00189 00190 zstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00191 initial = zvals['step'], 00192 min = -1e6, 00193 max = 1e6) 00194 self.win['view']['z-exag']['step'] = zstep.GetId() 00195 gridSizer.Add(item = zstep, pos = (4, 4), 00196 flag = wx.ALIGN_CENTER_VERTICAL) 00197 00198 boxSizer.Add(item = gridSizer, proportion = 1, 00199 flag = wx.ALL | wx.EXPAND, border = 3) 00200 pageSizer.Add(item = boxSizer, proportion = 0, 00201 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 00202 border = 3) 00203 00204 box = wx.StaticBox(parent = panel, id = wx.ID_ANY, 00205 label = " %s " % (_("Image Appearance"))) 00206 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00207 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3) 00208 gridSizer.AddGrowableCol(0) 00209 00210 # background color 00211 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00212 label = _("Background color:")), 00213 pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00214 00215 color = csel.ColourSelect(panel, id = wx.ID_ANY, 00216 colour = UserSettings.Get(group = 'nviz', key = 'settings', 00217 subkey = ['general', 'bgcolor']), 00218 size = globalvar.DIALOG_COLOR_SIZE) 00219 self.win['general']['bgcolor'] = color.GetId() 00220 gridSizer.Add(item = color, pos = (0, 1)) 00221 00222 boxSizer.Add(item = gridSizer, proportion = 1, 00223 flag = wx.ALL | wx.EXPAND, border = 3) 00224 pageSizer.Add(item = boxSizer, proportion = 0, 00225 flag = wx.EXPAND | wx.ALL, 00226 border = 3) 00227 00228 panel.SetSizer(pageSizer) 00229 00230 return panel 00231 00232 def _createVectorPage(self, notebook): 00233 """!Create notebook page for general settings""" 00234 panel = wx.Panel(parent = notebook, id = wx.ID_ANY) 00235 00236 notebook.AddPage(page = panel, 00237 text = " %s " % _("Vector")) 00238 00239 pageSizer = wx.BoxSizer(wx.VERTICAL) 00240 00241 # vector lines 00242 self.win['vector'] = {} 00243 self.win['vector']['lines'] = {} 00244 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, 00245 label = " %s " % (_("Vector lines"))) 00246 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00247 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3) 00248 00249 # show 00250 row = 0 00251 showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00252 label = _("Show lines")) 00253 self.win['vector']['lines']['show'] = showLines.GetId() 00254 showLines.SetValue(UserSettings.Get(group = 'nviz', key = 'vector', 00255 subkey = ['lines', 'show'])) 00256 gridSizer.Add(item = showLines, pos = (row, 0)) 00257 00258 boxSizer.Add(item = gridSizer, proportion = 1, 00259 flag = wx.ALL | wx.EXPAND, border = 3) 00260 pageSizer.Add(item = boxSizer, proportion = 0, 00261 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 00262 border = 3) 00263 00264 # vector points 00265 self.win['vector']['points'] = {} 00266 box = wx.StaticBox (parent = panel, id = wx.ID_ANY, 00267 label = " %s " % (_("Vector points"))) 00268 boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) 00269 gridSizer = wx.GridBagSizer(vgap = 3, hgap = 5) 00270 00271 # show 00272 row = 0 00273 showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY, 00274 label = _("Show points")) 00275 showPoints.SetValue(UserSettings.Get(group = 'nviz', key = 'vector', 00276 subkey = ['points', 'show'])) 00277 self.win['vector']['points']['show'] = showPoints.GetId() 00278 gridSizer.Add(item = showPoints, pos = (row, 0), span = (1, 8)) 00279 00280 # icon size 00281 row += 1 00282 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00283 label = _("Size:")), 00284 pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL) 00285 00286 isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00287 initial = 100, 00288 min = 1, 00289 max = 1e6) 00290 self.win['vector']['points']['size'] = isize.GetId() 00291 isize.SetValue(UserSettings.Get(group = 'nviz', key = 'vector', 00292 subkey = ['points', 'size'])) 00293 gridSizer.Add(item = isize, pos = (row, 1), 00294 flag = wx.ALIGN_CENTER_VERTICAL) 00295 00296 # icon width 00297 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00298 label = _("Width:")), 00299 pos = (row, 2), flag = wx.ALIGN_CENTER_VERTICAL) 00300 00301 iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1), 00302 initial = 2, 00303 min = 1, 00304 max = 1e6) 00305 self.win['vector']['points']['width'] = isize.GetId() 00306 iwidth.SetValue(UserSettings.Get(group = 'nviz', key = 'vector', 00307 subkey = ['points', 'width'])) 00308 gridSizer.Add(item = iwidth, pos = (row, 3), 00309 flag = wx.ALIGN_CENTER_VERTICAL) 00310 00311 # icon symbol 00312 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00313 label = _("Marker:")), 00314 pos = (row, 4), flag = wx.ALIGN_CENTER_VERTICAL) 00315 isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1), 00316 choices = UserSettings.Get(group = 'nviz', key = 'vector', 00317 subkey = ['points', 'marker'], internal = True)) 00318 isym.SetName("selection") 00319 self.win['vector']['points']['marker'] = isym.GetId() 00320 isym.SetSelection(UserSettings.Get(group = 'nviz', key = 'vector', 00321 subkey = ['points', 'marker'])) 00322 gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL, 00323 pos = (row, 5)) 00324 00325 # icon color 00326 gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY, 00327 label = _("Color:")), 00328 pos = (row, 6), flag = wx.ALIGN_CENTER_VERTICAL) 00329 icolor = csel.ColourSelect(panel, id = wx.ID_ANY) 00330 icolor.SetName("color") 00331 self.win['vector']['points']['color'] = icolor.GetId() 00332 icolor.SetColour(UserSettings.Get(group = 'nviz', key = 'vector', 00333 subkey = ['points', 'color'])) 00334 gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL, 00335 pos = (row, 7)) 00336 00337 boxSizer.Add(item = gridSizer, proportion = 1, 00338 flag = wx.ALL | wx.EXPAND, border = 3) 00339 pageSizer.Add(item = boxSizer, proportion = 0, 00340 flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 00341 border = 3) 00342 00343 panel.SetSizer(pageSizer) 00344 00345 return panel 00346 00347 def OnDefault(self, event): 00348 """Restore default settings""" 00349 settings = copy.deepcopy(UserSettings.GetDefaultSettings()['nviz']) 00350 UserSettings.Set(group = 'nviz', 00351 value = settings) 00352 00353 for subgroup, key in settings.iteritems(): # view, surface, vector... 00354 if subgroup != 'view': 00355 continue 00356 for subkey, value in key.iteritems(): 00357 for subvalue in value.keys(): 00358 win = self.FindWindowById(self.win[subgroup][subkey][subvalue]) 00359 val = settings[subgroup][subkey][subvalue] 00360 if subkey == 'position': 00361 val = int(val * 100) 00362 00363 win.SetValue(val) 00364 00365 event.Skip() 00366 00367 def OnApply(self, event): 00368 """Apply Nviz settings for current session""" 00369 settings = UserSettings.Get(group = 'nviz') 00370 for subgroup, key in settings.iteritems(): # view, surface, vector... 00371 for subkey, value in key.iteritems(): 00372 if type(value) == types.DictType: 00373 for subvalue in value.keys(): 00374 try: # TODO 00375 win = self.FindWindowById(self.win[subgroup][subkey][subvalue]) 00376 except: 00377 # print 'e', subgroup, subkey, subvalue 00378 continue 00379 00380 if win.GetName() == "selection": 00381 value = win.GetSelection() 00382 elif win.GetName() == "color": 00383 value = tuple(win.GetColour()) 00384 else: 00385 value = win.GetValue() 00386 if subkey == 'pos': 00387 value = float(value) / 100 00388 00389 settings[subgroup][subkey][subvalue] = value 00390 00391 def OnSave(self, event): 00392 """!Apply changes, update map and save settings of selected 00393 layer 00394 """ 00395 # apply changes 00396 self.OnApply(None) 00397 00398 if self.GetSelection() == self.page['id']: 00399 fileSettings = {} 00400 UserSettings.ReadSettingsFile(settings = fileSettings) 00401 fileSettings['nviz'] = UserSettings.Get(group = 'nviz') 00402 file = UserSettings.SaveToFile(fileSettings) 00403 self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file) 00404 00405 def OnLoad(self, event): 00406 """!Apply button pressed""" 00407 self.LoadSettings() 00408 00409 if event: 00410 event.Skip() 00411 00412 def LoadSettings(self): 00413 """!Load saved Nviz settings and apply to current session""" 00414 UserSettings.ReadSettingsFile() 00415 settings = copy.deepcopy(UserSettings.Get(group = 'nviz')) 00416 00417 for subgroup, key in settings.iteritems(): # view, surface, vector... 00418 for subkey, value in key.iteritems(): 00419 for subvalue in value.keys(): 00420 if subvalue == 'step': 00421 continue 00422 else: 00423 insetting = value[subvalue] 00424 if subgroup == 'view': 00425 for viewkey, viewitem in self.mapWindow.view[subkey].iteritems(): 00426 if viewkey == subvalue: 00427 self.mapWindow.view[subkey][viewkey] = insetting 00428 else: 00429 continue 00430 else: 00431 for otherkey, otheritem in self.win[subgroup][subkey].iteritems(): 00432 if type(otheritem) == data: 00433 for endkey, enditem in otheritem.iteritems(): 00434 if endkey == subvalue: 00435 paramwin = self.FindWindowById(enditem) 00436 else: 00437 continue 00438 else: 00439 if otherkey == subvalue: 00440 paramwin = self.FindWindowById(otheritem) 00441 else: 00442 continue 00443 if type(insetting) in [tuple, list] and len(insetting) > 2: 00444 insetting = tuple(insetting) 00445 paramwin.SetColour(insetting) 00446 else: 00447 try: 00448 paramwin.SetValue(insetting) 00449 except: 00450 try: 00451 paramwin.SetStringSelection(insetting) 00452 except: 00453 continue 00454 00455 self.toolWin.UpdateSettings() 00456 self.FindWindowById(self.win['view']['pos']).Draw() 00457 self.FindWindowById(self.win['view']['pos']).Refresh(False) 00458 00459 self.mapWindow.render['quick'] = False 00460 self.mapWindow.Refresh(False) 00461 00462 def OnSave(self, event): 00463 """!Save button pressed 00464 00465 Save settings to configuration file 00466 """ 00467 fileSettings = {} 00468 UserSettings.ReadSettingsFile(settings = fileSettings) 00469 fileSettings['nviz'] = UserSettings.Get(group = 'nviz') 00470 00471 fileName = UserSettings.SaveToFile(fileSettings) 00472 self.parent.GetLayerManager().goutput.WriteLog(_('3D view settings saved to file <%s>.') % fileName) 00473 00474 self.Destroy() 00475