GRASS Programmer's Manual  6.4.2(2012)
nviz_tools.py
Go to the documentation of this file.
00001 """!
00002 @package nviz_tools.py
00003 
00004 @brief Nviz (3D view) tools window
00005 
00006 Classes:
00007  - NvizToolWindow
00008  - PositionWindow
00009  - ViewPositionWindow
00010  - LightPositionWindow
00011 
00012 (C) 2008-2010 by the GRASS Development Team
00013 
00014 This program is free software under the GNU General Public
00015 License (>=v2). Read the file COPYING that comes with GRASS
00016 for details.
00017 
00018 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
00019 @author Enhancements by Michael Barton <michael.barton@asu.edu>
00020 """
00021 
00022 import os
00023 import sys
00024 import copy
00025 import types
00026 
00027 import wx
00028 import wx.lib.colourselect as csel
00029 import wx.lib.scrolledpanel as SP
00030 try:
00031     import wx.lib.agw.flatnotebook as FN
00032 except ImportError:
00033     import wx.lib.flatnotebook as FN
00034 
00035 import grass.script as grass
00036 
00037 import globalvar
00038 import gselect
00039 import gcmd
00040 from preferences import globalSettings as UserSettings
00041 from preferences import PreferencesBaseDialog
00042 try:
00043     from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
00044     import wxnviz
00045 except (ImportError, NameError):
00046     pass
00047 from debug import Debug
00048 
00049 class NvizToolWindow(FN.FlatNotebook):
00050     """!Nviz (3D view) tools panel
00051     """
00052     def __init__(self, parent, display, id = wx.ID_ANY,
00053                  style = globalvar.FNPageStyle, **kwargs):
00054         self.parent     = parent # GMFrame
00055         self.mapDisplay = display
00056         self.mapWindow  = display.GetWindow()
00057         self._display   = self.mapWindow.GetDisplay()
00058         
00059         if globalvar.hasAgw:
00060             kwargs['agwStyle'] = style
00061         else:
00062             kwargs['style'] = style
00063         FN.FlatNotebook.__init__(self, parent, id, **kwargs)
00064         self.SetTabAreaColour(globalvar.FNPageColor)
00065         
00066         self.win  = {} # window ids
00067         self.page = {} # page ids
00068 
00069         # view page
00070         self.AddPage(page = self._createViewPage(),
00071                      text = " %s " % _("View"))
00072 
00073         # data page
00074         self.AddPage(page = self._createDataPage(),
00075                      text = " %s " % _("Data"))
00076 
00077         # appearance page
00078         self.AddPage(page = self._createAppearancePage(),
00079                      text = " %s " % _("Appearance"))
00080         
00081         self.UpdateSettings()
00082         self.pageChanging = False
00083         self.mapWindow.render['quick'] = False
00084         self.mapWindow.Refresh(False)
00085         
00086         # bindings
00087         self.Bind(wx.EVT_CLOSE, self.OnClose)
00088         self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
00089         
00090         self.Update()
00091         wx.CallAfter(self.SetPage, 'view')
00092         wx.CallAfter(self.notebookData.SetSelection, 0)
00093         wx.CallAfter(self.notebookAppearance.SetSelection, 0)
00094         
00095     def OnPageChanged(self, event):
00096         new = event.GetSelection()
00097         # self.ChangeSelection(new)
00098     
00099     def PostViewEvent(self, zExag = False):
00100         """!Change view settings"""
00101         event = wxUpdateView(zExag = zExag)
00102         wx.PostEvent(self.mapWindow, event)
00103 
00104     def _createViewPage(self):
00105         """!Create view settings page"""
00106         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
00107         panel.SetupScrolling(scroll_x = False)
00108         self.page['view'] = { 'id' : 0,
00109                               'notebook' : self.GetId()}
00110         
00111         pageSizer = wx.BoxSizer(wx.VERTICAL)
00112         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00113                             label = " %s " % (_("Control View")))
00114         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00115         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00116         
00117         self.win['view'] = {}
00118         
00119         # position
00120         posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00121         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
00122                      pos = (1, 0), flag = wx.ALIGN_CENTER)
00123         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
00124                      pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
00125         view = ViewPositionWindow(panel, size = (175, 175),
00126                                   mapwindow = self.mapWindow)
00127         self.win['view']['position'] = view.GetId()
00128         posSizer.Add(item = view,
00129                      pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
00130         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
00131                      pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
00132         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
00133                      pos = (1, 2), flag = wx.ALIGN_CENTER)
00134         gridSizer.Add(item = posSizer, pos = (0, 0))
00135                   
00136         # perspective
00137         # set initial defaults here (or perhaps in a default values file), not in user settings
00138         self._createControl(panel, data = self.win['view'], name = 'persp',
00139                             range = (1,100),
00140                             bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
00141         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
00142                       pos = (1, 0), flag = wx.ALIGN_CENTER)
00143         gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0))
00144         gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['spin']), pos = (3, 0),
00145                       flag = wx.ALIGN_CENTER)        
00146         
00147         # twist
00148         self._createControl(panel, data = self.win['view'], name = 'twist',
00149                             range = (-180,180),
00150                             bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
00151         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
00152                       pos = (1, 1), flag = wx.ALIGN_CENTER)
00153         gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
00154         gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['spin']), pos = (3, 1),
00155                       flag = wx.ALIGN_CENTER)        
00156         
00157         # height + z-exag
00158         self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
00159                             range = (0, 1),
00160                             bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
00161         
00162         self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
00163                             range = (0, 5),
00164                             bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
00165         self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
00166         self.FindWindowById(self.win['view']['z-exag']['spin']).SetValue(1)
00167         
00168         heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00169         heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
00170                       pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
00171         heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
00172                         flag = wx.ALIGN_RIGHT, pos = (1, 0))
00173         heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['spin']),
00174                         flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
00175                         wx.BOTTOM | wx.RIGHT, pos = (1, 1))
00176         heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
00177                       pos = (0, 2), flag = wx.ALIGN_LEFT, span = (1, 2))
00178         heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
00179                         flag = wx.ALIGN_RIGHT, pos = (1, 2))
00180         heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['spin']),
00181                         flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
00182                         wx.BOTTOM | wx.RIGHT, pos = (1, 3))
00183         
00184         gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
00185         
00186         # view setup + reset
00187         viewSizer = wx.BoxSizer(wx.HORIZONTAL)
00188         
00189         viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
00190                                            label = _("Look at:")),
00191                       flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
00192                       border = 5)
00193         
00194         viewType = wx.Choice (parent = panel, id = wx.ID_ANY, size = (125, -1),
00195                               choices = [_("top"),
00196                                          _("north"),
00197                                          _("south"),
00198                                          _("east"),
00199                                          _("west"),
00200                                          _("north-west"),
00201                                          _("north-east"),
00202                                          _("south-east"),
00203                                          _("south-west")])
00204         viewType.SetSelection(0)
00205         viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
00206         # self.win['lookAt'] = viewType.GetId()
00207         viewSizer.Add(item = viewType,
00208                       flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
00209                       border = 5)
00210         
00211         reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
00212         reset.SetToolTipString(_("Reset to default view"))
00213         # self.win['reset'] = reset.GetId()
00214         reset.Bind(wx.EVT_BUTTON, self.OnResetView)
00215         
00216         viewSizer.Add(item = wx.Size(-1, -1), proportion = 1,
00217                       flag = wx.EXPAND)
00218         viewSizer.Add(item = reset, proportion = 0,
00219                       flag = wx.ALL | wx.ALIGN_RIGHT,
00220                       border = 5)
00221         
00222         gridSizer.AddGrowableCol(2)
00223         gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
00224                       flag = wx.EXPAND)
00225         
00226         # body
00227         boxSizer.Add(item = gridSizer, proportion = 1,
00228                   flag = wx.ALL | wx.EXPAND, border = 2)
00229         pageSizer.Add(item = boxSizer, proportion = 0,
00230                       flag = wx.EXPAND | wx.ALL,
00231                       border = 3)
00232         
00233         box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
00234                            label = " %s " % (_("Image Appearance")))
00235         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00236         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00237         gridSizer.AddGrowableCol(0)
00238         
00239         # background color
00240         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00241                                          label = _("Background color:")),
00242                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00243         
00244         color = csel.ColourSelect(panel, id = wx.ID_ANY,
00245                                   colour = UserSettings.Get(group = 'nviz', key = 'view',
00246                                                             subkey = ['background', 'color']),
00247                                   size = globalvar.DIALOG_COLOR_SIZE)
00248         self.win['view']['bgcolor'] = color.GetId()
00249         color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
00250         gridSizer.Add(item = color, pos = (0, 1))
00251         
00252         boxSizer.Add(item = gridSizer, proportion = 1,
00253                   flag = wx.ALL | wx.EXPAND, border = 3)
00254         pageSizer.Add(item = boxSizer, proportion = 0,
00255                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
00256                       border = 3)
00257         
00258         panel.SetSizer(pageSizer)
00259         
00260         return panel
00261 
00262     def _createDataPage(self):
00263         """!Create data (surface, vector, volume) settings page"""
00264         if globalvar.hasAgw:
00265             self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
00266                                                 agwStyle = globalvar.FNPageDStyle)
00267         else:
00268             self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
00269                                                 style = globalvar.FNPageDStyle)
00270         
00271         # surface page
00272         self.notebookData.AddPage(page = self._createSurfacePage(),
00273                                   text = " %s " % _("Surface"))
00274         self.EnablePage('surface', False)
00275         
00276         # vector page
00277         self.notebookData.AddPage(page = self._createVectorPage(),
00278                                   text = " %s " % _("Vector"))
00279         self.EnablePage('vector', False)
00280         
00281         # volume page
00282         self.notebookData.AddPage(page = self._createVolumePage(),
00283                                   text = " %s " % _("Volume"))
00284         self.EnablePage('volume', False)
00285         
00286         return self.notebookData
00287     
00288     def _createAppearancePage(self):
00289         """!Create data (surface, vector, volume) settings page"""
00290         if globalvar.hasAgw:
00291             self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
00292                                                       agwStyle = globalvar.FNPageDStyle)
00293         else:
00294             self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
00295                                                       style = globalvar.FNPageDStyle)
00296         
00297         # light page
00298         self.notebookAppearance.AddPage(page = self._createLightPage(),
00299                                         text = " %s " % _("Lighting"))
00300     
00301         # fringe page
00302         self.notebookAppearance.AddPage(page = self._createFringePage(),
00303                                         text = " %s " % _("Fringe"))
00304         self.EnablePage('fringe', False)
00305 
00306         return self.notebookAppearance
00307     
00308     def _createSurfacePage(self):
00309         """!Create view settings page"""
00310         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
00311         panel.SetupScrolling(scroll_x = False)
00312         self.page['surface'] = { 'id' : 0,
00313                                  'panel' : panel.GetId(),
00314                                  'notebook' : self.notebookData.GetId() }
00315         pageSizer = wx.BoxSizer(wx.VERTICAL)
00316         
00317         self.win['surface'] = {}
00318         
00319         # selection
00320         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00321                             label = " %s " % (_("Raster map")))
00322         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00323         rmaps = gselect.Select(parent = panel, type = 'raster',
00324                                onPopup = self.GselectOnPopup)
00325         rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
00326         self.win['surface']['map'] = rmaps.GetId()
00327         desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
00328         self.win['surface']['desc'] = desc.GetId()
00329         boxSizer.Add(item = rmaps, proportion = 0,
00330                      flag = wx.ALL,
00331                      border = 3)
00332         boxSizer.Add(item = desc, proportion = 0,
00333                      flag = wx.ALL,
00334                      border = 3)
00335         pageSizer.Add(item = boxSizer, proportion = 0,
00336                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00337                       border = 3)
00338         
00339         #
00340         # surface attributes
00341         #
00342         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00343                             label = " %s " % (_("Surface attributes")))
00344         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00345         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00346         
00347         # type 
00348         self.win['surface']['attr'] = {}
00349         row = 0
00350         for code, attrb in (('topo', _("Topography")),
00351                            ('color', _("Color")),
00352                            ('mask', _("Mask")),
00353                            ('transp', _("Transparency")),
00354                            ('shine', _("Shininess")),
00355                            ('emit', _("Emission"))):
00356             self.win['surface'][code] = {} 
00357             gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00358                                              label = attrb + ':'),
00359                           pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00360             use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00361                              choices = [_("map")])
00362             
00363             if code not in ('topo', 'color', 'shine'):
00364                 use.Insert(item = _("unset"), pos = 0)
00365                 self.win['surface'][code]['required'] = False
00366             else:
00367                 self.win['surface'][code]['required'] = True
00368             if code != 'mask':
00369                 use.Append(item = _('constant'))
00370             self.win['surface'][code]['use'] = use.GetId()
00371             use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
00372             gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
00373                           pos = (row, 1))
00374             
00375             map = gselect.Select(parent = panel, id = wx.ID_ANY,
00376                                  # size = globalvar.DIALOG_GSELECT_SIZE,
00377                                  size = (200, -1),
00378                                  type = "raster")
00379             self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
00380             map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
00381             # changing map topography not allowed
00382             if code == 'topo':
00383                 map.Enable(False)
00384             gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
00385                           pos = (row, 2))
00386             
00387             if code == 'color':
00388                 value = csel.ColourSelect(panel, id = wx.ID_ANY,
00389                                           colour = (0,0,0),
00390                                           size = globalvar.DIALOG_COLOR_SIZE)
00391                 value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
00392             elif code == 'mask':
00393                 value = None
00394             else:
00395                 value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00396                                     initial = 0)
00397                 if code == 'topo':
00398                     value.SetRange(minVal = -1e9, maxVal = 1e9)
00399                 elif code in ('shine', 'transp', 'emit'):
00400                     value.SetRange(minVal = 0, maxVal = 255)
00401                 else:
00402                     value.SetRange(minVal = 0, maxVal = 100)
00403                 value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
00404             
00405             if value:
00406                 self.win['surface'][code]['const'] = value.GetId()
00407                 value.Enable(False)
00408                 gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
00409                               pos = (row, 3))
00410             else:
00411                 self.win['surface'][code]['const'] = None
00412             
00413             self.SetMapObjUseMap(nvizType = 'surface',
00414                                  attrb = code) # -> enable map / disable constant
00415                 
00416             row += 1
00417         
00418         boxSizer.Add(item = gridSizer, proportion = 1,
00419                   flag = wx.ALL | wx.EXPAND, border = 3)
00420         pageSizer.Add(item = boxSizer, proportion = 0,
00421                       flag = wx.EXPAND | wx.ALL,
00422                       border = 3)
00423         
00424         #
00425         # draw
00426         #
00427         self.win['surface']['draw'] = {}
00428         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00429                             label = " %s " % (_("Draw")))
00430         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00431         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00432         gridSizer.AddGrowableCol(6)
00433         
00434         # mode
00435         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00436                                          label = _("Mode:")),
00437                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00438         mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
00439                           choices = [_("coarse"),
00440                                      _("fine"),
00441                                      _("both")])
00442         mode.SetSelection(0)
00443         mode.SetName("selection")
00444         mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
00445         self.win['surface']['draw']['mode'] = mode.GetId()
00446         gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
00447                       pos = (0, 1))
00448         
00449         # shading
00450         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00451                                          label = _("Shading:")),
00452                       pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
00453         shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00454                            choices = [_("flat"),
00455                                       _("gouraud")])
00456         shade.SetName("selection")
00457         self.win['surface']['draw']['shading'] = shade.GetId()
00458         shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
00459         gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
00460                       pos = (0, 3))
00461         
00462         # set to all
00463         all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
00464         all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
00465         all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
00466         gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
00467                       pos = (0, 4), span = (1,2), border = 3 )
00468         
00469         # resolution coarse
00470         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00471                                          label = _("Coarse:")),
00472                       pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00473         resSizer = wx.BoxSizer(wx.HORIZONTAL)
00474         resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00475                                         label = _("res.")),
00476                      flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 
00477                      border = 3)
00478         resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00479                            initial = 6,
00480                            min = 1,
00481                            max = 100)
00482         resC.SetName("value")
00483         resC.SetValue(6)
00484         
00485         self.win['surface']['draw']['res-coarse'] = resC.GetId()
00486         resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
00487         resSizer.Add(item = resC, flag = wx.ALL | wx.ALIGN_LEFT | 
00488                       wx.ALIGN_CENTER_VERTICAL, border = 3)
00489         gridSizer.Add(item = resSizer, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
00490         
00491         # Coarse style
00492         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00493                                          label = _("style")),
00494                       pos = (1, 2), flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
00495         style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00496                           choices = [_("wire"),
00497                                      _("surface")])
00498         style.SetName("selection")
00499         self.win['surface']['draw']['style'] = style.GetId()
00500         style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
00501         gridSizer.Add(item = style, flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
00502                       pos = (1, 3))
00503         
00504         # color
00505         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00506                                          label = _("wire color")),
00507                       pos = (1, 4), flag = wx.ALIGN_CENTER_VERTICAL | 
00508                       wx.ALIGN_RIGHT | wx.LEFT, border = 3)
00509         color = csel.ColourSelect(panel, id = wx.ID_ANY,
00510                                   size = globalvar.DIALOG_COLOR_SIZE)
00511         color.SetColour((136,136,136))
00512         color.SetName("colour")
00513         color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
00514         self.win['surface']['draw']['wire-color'] = color.GetId()
00515         gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
00516                       pos = (1, 5))
00517         
00518         # resolution fine
00519         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00520                                          label = _("Fine:")),
00521                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00522         
00523         resSizer = wx.BoxSizer(wx.HORIZONTAL)
00524         resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00525                                         label = _("res.")),
00526                      flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 
00527                      border = 3)
00528         resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00529                            initial = 3,
00530                            min = 1,
00531                            max = 100)
00532         resF.SetName("value")
00533         resF.SetValue(3)
00534         self.win['surface']['draw']['res-fine'] = resF.GetId()
00535         resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
00536         resSizer.Add(item = resF, flag = wx.ALL | wx.ALIGN_LEFT | 
00537                       wx.ALIGN_CENTER_VERTICAL, border = 3)
00538         gridSizer.Add(item = resSizer, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
00539         
00540         boxSizer.Add(item = gridSizer, proportion = 1,
00541                   flag = wx.ALL | wx.EXPAND, border = 3)
00542         pageSizer.Add(item = boxSizer, proportion = 0,
00543                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00544                       border = 3)
00545         
00546         #
00547         # mask
00548         #
00549         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00550                             label = " %s " % (_("Mask")))
00551         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00552         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00553         
00554         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00555                                          label = _("Mask zeros:")),
00556                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00557         
00558         elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
00559                            label = _("by elevation"))
00560         elev.Enable(False) # TODO: not implemented yet
00561         gridSizer.Add(item = elev, pos = (0, 1))
00562         
00563         color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
00564                            label = _("by color"))
00565         color.Enable(False) # TODO: not implemented yet
00566         gridSizer.Add(item = color, pos = (0, 2))
00567         
00568         boxSizer.Add(item = gridSizer, proportion = 1,
00569                   flag = wx.ALL | wx.EXPAND, border = 3)
00570         pageSizer.Add(item = boxSizer, proportion = 0,
00571                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00572                       border = 3)
00573         
00574         #
00575         # position
00576         #
00577         self.win['surface']['position'] = {}
00578         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00579                             label = " %s " % (_("Position")))
00580         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00581         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00582         
00583         # position
00584         self._createControl(panel, data = self.win['surface'], name = 'position',
00585                             range = (-10000, 10000),
00586                             bind = (self.OnSurfacePosition, self.OnSurfacePosition, self.OnSurfacePosition))
00587         
00588         axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
00589                           choices = ["X",
00590                                      "Y",
00591                                      "Z"])
00592         
00593         self.win['surface']['position']['axis'] = axis.GetId()
00594         axis.SetSelection(0)
00595         axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
00596         
00597         pslide = self.FindWindowById(self.win['surface']['position']['slider'])
00598         pspin = self.FindWindowById(self.win['surface']['position']['spin'])
00599         
00600         gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
00601         gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
00602         gridSizer.Add(item = pspin, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
00603         
00604         boxSizer.Add(item = gridSizer, proportion = 1,
00605                   flag = wx.ALL | wx.EXPAND, border = 3)
00606         box.SetSizer(boxSizer)
00607         box.Layout()
00608         
00609         pageSizer.Add(item = boxSizer, proportion = 0,
00610                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00611                       border = 3)
00612         
00613         panel.SetSizer(pageSizer)
00614         
00615         return panel
00616 
00617     def _createVectorPage(self):
00618         """!Create view settings page"""
00619         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
00620         panel.SetupScrolling(scroll_x = False)
00621         self.page['vector'] = { 'id' : 1,
00622                                 'panel' : panel.GetId(),
00623                                 'notebook' : self.notebookData.GetId() }
00624         pageSizer = wx.BoxSizer(wx.VERTICAL)
00625         
00626         self.win['vector'] = {}
00627         
00628         # selection
00629         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00630                             label = " %s " % (_("Vector map")))
00631         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00632         vmaps = gselect.Select(parent = panel, type = 'vector',
00633                                onPopup = self.GselectOnPopup)
00634         vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
00635         self.win['vector']['map'] = vmaps.GetId()
00636         desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
00637         self.win['vector']['desc'] = desc.GetId()
00638         boxSizer.Add(item = vmaps, proportion = 0,
00639                      flag = wx.ALL,
00640                      border = 3)
00641         boxSizer.Add(item = desc, proportion = 0,
00642                      flag = wx.ALL,
00643                      border = 3)
00644         pageSizer.Add(item = boxSizer, proportion = 0,
00645                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00646                       border = 3)
00647         
00648         #
00649         # vector lines
00650         #
00651         self.win['vector']['lines'] = {}
00652         
00653         showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
00654                                 label = _("Show vector lines"))
00655         showLines.SetValue(True)
00656         
00657         self.win['vector']['lines']['show'] = showLines.GetId()
00658         showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
00659         
00660         pageSizer.Add(item = showLines, proportion = 0,
00661                       flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
00662         
00663         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00664                             label = " %s " % (_("Vector lines")))
00665         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00666         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00667         
00668         # width
00669         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00670                                          label = _("Line:")),
00671                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00672         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00673                                          label = _("width")),
00674                       pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | 
00675                       wx.ALIGN_RIGHT)
00676         
00677         width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00678                             initial = 1,
00679                             min = 0,
00680                             max = 100)
00681         width.SetValue(1)
00682         self.win['vector']['lines']['width'] = width.GetId()
00683         width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
00684         gridSizer.Add(item = width, pos = (0, 2),
00685                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
00686         
00687         # color
00688         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00689                                          label = _("color")),
00690                       pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
00691                       wx.ALIGN_RIGHT)
00692         
00693         color = csel.ColourSelect(panel, id = wx.ID_ANY,
00694                                   colour = (0,0,0),
00695                                   size = globalvar.DIALOG_COLOR_SIZE)
00696         self.win['vector']['lines']['color'] = color.GetId()
00697         color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
00698 
00699         gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
00700                       wx.ALIGN_LEFT)
00701         
00702         # display
00703         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00704                                          label = _("display")),
00705                       pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
00706                       wx.ALIGN_RIGHT)
00707         
00708         display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00709                              choices = [_("on surface"),
00710                                         _("flat")])
00711         self.win['vector']['lines']['flat'] = display.GetId()
00712         display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
00713         
00714         gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL | 
00715                       wx.ALIGN_LEFT, pos = (1, 2), span = (1,2))
00716         
00717         # height
00718         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00719                                          label = _("Height above surface:")),
00720                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
00721                       span = (1, 3))
00722         
00723         surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
00724                               style = wx.CB_SIMPLE | wx.CB_READONLY,
00725                               choices = [])
00726         surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
00727         self.win['vector']['lines']['surface'] = surface.GetId()
00728         gridSizer.Add(item = surface, 
00729                       pos = (2, 3), span = (1, 6),
00730                       flag = wx.ALIGN_CENTER_VERTICAL)
00731         
00732         self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = 300,
00733                             range = (0, 1000),
00734                             bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
00735         self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
00736         self.FindWindowById(self.win['vector']['lines']['height']['spin']).SetValue(0)
00737         gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
00738                       pos = (3, 0), span = (1, 7))
00739         gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['spin']),
00740                       pos = (3, 7),
00741                       flag = wx.ALIGN_CENTER)
00742         
00743         boxSizer.Add(item = gridSizer, proportion = 1,
00744                      flag = wx.ALL | wx.EXPAND, border = 3)
00745         pageSizer.Add(item = boxSizer, proportion = 0,
00746                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00747                       border = 3)
00748         
00749         #
00750         # vector points
00751         #
00752         self.win['vector']['points'] = {}
00753         
00754         showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
00755                                  label = _("Show vector points"))
00756         showPoints.SetValue(True)
00757         self.win['vector']['points']['show'] = showPoints.GetId()
00758         showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
00759         
00760         pageSizer.Add(item = showPoints, proportion = 0,
00761                       flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
00762         
00763         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00764                             label = " %s " % (_("Vector points")))
00765         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00766         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00767         
00768         # icon size
00769         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00770                                          label = _("Icon:")),
00771                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00772         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00773                                          label = _("size")),
00774                       pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
00775                       wx.ALIGN_RIGHT)
00776         
00777         isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00778                             initial = 1,
00779                             min = 1,
00780                             max = 1e6)
00781         isize.SetName('value')
00782         isize.SetValue(100)
00783         self.win['vector']['points']['size'] = isize.GetId()
00784         isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
00785         isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
00786         gridSizer.Add(item = isize, pos = (0, 2),
00787                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
00788         
00789         # icon color
00790         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00791                                          label = _("color")),
00792                       pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
00793                       wx.ALIGN_RIGHT)
00794         icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
00795                                    size = globalvar.DIALOG_COLOR_SIZE)
00796         icolor.SetName("color")
00797         icolor.SetColour((0,0,255))
00798         self.win['vector']['points']['color'] = icolor.GetId()
00799         icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
00800         gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL | 
00801                       wx.ALIGN_LEFT,
00802                       pos = (0, 4))
00803 
00804         # icon width
00805         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00806                                            label = _("width")),
00807                       pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL |
00808                       wx.ALIGN_RIGHT)
00809         
00810         iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00811                              initial = 1,
00812                              min = 1,
00813                              max = 1e6)
00814         iwidth.SetName('value')
00815         iwidth.SetValue(100)
00816         self.win['vector']['points']['width'] = iwidth.GetId()
00817         iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
00818         iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
00819         gridSizer.Add(item = iwidth, pos = (0, 6),
00820                       flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
00821         
00822         # icon symbol
00823         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00824                                          label = _("symbol")),
00825                       pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
00826         isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00827                           choices = UserSettings.Get(group = 'nviz', key = 'vector',
00828                                                    subkey = ['points', 'marker'], internal = True))
00829         isym.SetName("selection")
00830         self.win['vector']['points']['marker'] = isym.GetId()
00831         isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
00832         gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
00833                       pos = (1, 2), span = (1,2))
00834         
00835         # high
00836         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00837                                          label = _("Height above surface:")),
00838                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
00839                       span = (1, 3))
00840         
00841         surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
00842                               style = wx.CB_SIMPLE | wx.CB_READONLY,
00843                               choices = [])
00844         surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
00845         self.win['vector']['points']['surface'] = surface.GetId()
00846         gridSizer.Add(item = surface, 
00847                       pos = (2, 3), span = (1, 5),
00848                       flag = wx.ALIGN_CENTER_VERTICAL)
00849         
00850         self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = 300,
00851                             range = (0, 1000),
00852                             bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
00853         
00854         self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
00855         self.FindWindowById(self.win['vector']['points']['height']['spin']).SetValue(0)
00856         
00857         gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
00858                       pos = (3, 0), span = (1, 7))
00859         gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['spin']),
00860                       pos = (3, 7),
00861                       flag = wx.ALIGN_CENTER)
00862         
00863         boxSizer.Add(item = gridSizer, proportion = 1,
00864                      flag = wx.ALL | wx.EXPAND, border = 3)
00865         pageSizer.Add(item = boxSizer, proportion = 0,
00866                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00867                       border = 3)
00868         
00869         panel.SetSizer(pageSizer)
00870 
00871         return panel
00872 
00873     def GselectOnPopup(self, ltype, exclude = False):
00874         """Update gselect.Select() items"""
00875         maps = list()
00876         for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype):
00877             maps.append(layer.GetName())
00878         return maps, exclude
00879     
00880     def _createVolumePage(self):
00881         """!Create view settings page"""
00882         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
00883         panel.SetupScrolling(scroll_x = False)
00884         self.page['volume'] = { 'id' : 2,
00885                                 'panel' : panel.GetId(),
00886                                 'notebook' : self.notebookData.GetId() }
00887         pageSizer = wx.BoxSizer(wx.VERTICAL)
00888         
00889         self.win['volume'] = {}
00890         
00891         # selection
00892         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00893                             label = " %s " % (_("3D raster map")))
00894         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00895         rmaps = gselect.Select(parent = panel, type = 'raster3d',
00896                                onPopup = self.GselectOnPopup)
00897         rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
00898         self.win['volume']['map'] = rmaps.GetId()
00899         desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
00900         self.win['volume']['desc'] = desc.GetId()
00901         boxSizer.Add(item = rmaps, proportion = 0,
00902                      flag = wx.ALL,
00903                      border = 3)
00904         boxSizer.Add(item = desc, proportion = 0,
00905                      flag = wx.ALL,
00906                      border = 3)
00907         pageSizer.Add(item = boxSizer, proportion = 0,
00908                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
00909                       border = 3)
00910                 
00911         #
00912         # draw
00913         #
00914         self.win['volume']['draw'] = {}
00915         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00916                             label = " %s " % (_("Draw")))
00917         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00918         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
00919         gridSizer.AddGrowableCol(4)
00920         
00921         # mode
00922         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00923                                          label = _("Mode:")),
00924                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
00925         mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
00926                           choices = [_("isosurfaces"),
00927                                      _("slides")])
00928         mode.SetSelection(0)
00929         mode.SetName("selection")
00930         # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
00931         self.win['volume']['draw']['mode'] = mode.GetId()
00932         gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
00933                       pos = (0, 1))
00934         
00935         # shading
00936         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00937                                          label = _("Shading:")),
00938                       pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
00939         shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
00940                            choices = [_("flat"),
00941                                       _("gouraud")])
00942         shade.SetName("selection")
00943         self.win['volume']['draw']['shading'] = shade.GetId()
00944         shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
00945         gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
00946                       pos = (0, 3))
00947         
00948         # resolution (mode)
00949         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
00950                                          label = _("Resolution:")),
00951                       pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
00952         resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
00953                             initial = 1,
00954                             min = 1,
00955                             max = 100)
00956         resol.SetName("value")
00957         self.win['volume']['draw']['resolution'] = resol.GetId()
00958         resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
00959         resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
00960         gridSizer.Add(item = resol, pos = (0, 5))
00961         
00962         boxSizer.Add(item = gridSizer, proportion = 1,
00963                      flag = wx.ALL | wx.EXPAND, border = 3)
00964         pageSizer.Add(item = boxSizer, proportion = 0,
00965                       flag = wx.EXPAND | wx.ALL,
00966                       border = 3)
00967         
00968         #
00969         # manage isosurfaces
00970         #
00971         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
00972                             label = " %s " % (_("List of isosurfaces")))
00973         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
00974         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
00975         
00976         # list
00977         isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
00978                                    size = (300, 150))
00979         self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
00980         self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
00981         
00982         self.win['volume']['isosurfs'] = isolevel.GetId()
00983         gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
00984         
00985         # buttons (add, delete, move up, move down)
00986         btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
00987         self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
00988         btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
00989         gridSizer.Add(item = btnAdd,
00990                       pos = (0, 1))
00991         btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
00992         self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
00993         btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
00994         btnDelete.Enable(False)
00995         gridSizer.Add(item = btnDelete,
00996                       pos = (1, 1))
00997         btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
00998         self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
00999         btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
01000         btnMoveUp.Enable(False)
01001         gridSizer.Add(item = btnMoveUp,
01002                       pos = (2, 1))
01003         btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
01004         self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
01005         btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
01006         btnMoveDown.Enable(False)
01007         gridSizer.Add(item = btnMoveDown,
01008                       pos = (3, 1))
01009         
01010         boxSizer.Add(item = gridSizer, proportion = 1,
01011                      flag = wx.ALL | wx.EXPAND, border = 3)
01012         pageSizer.Add(item = boxSizer, proportion = 0,
01013                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01014                       border = 3)
01015         
01016         #
01017         # isosurface attributes
01018         #
01019         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01020                             label = " %s " % (_("Isosurface attributes")))
01021         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01022         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
01023         
01024         self.win['volume']['attr'] = {}
01025         row = 0
01026         for code, attrb in (('topo', _("Topography level")),
01027                             ('color', _("Color")),
01028                             ('mask', _("Mask")),
01029                             ('transp', _("Transparency")),
01030                             ('shine', _("Shininess")),
01031                             ('emit', _("Emission"))):
01032             self.win['volume'][code] = {} 
01033             # label
01034             gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
01035                                              label = attrb + ':'),
01036                           pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
01037             if code != 'topo':
01038                 use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
01039                                  choices = [_("map")])
01040             else:
01041                 use = None
01042             # check for required properties
01043             if code not in ('topo', 'color', 'shine'):
01044                 use.Insert(item = _("unset"), pos = 0)
01045                 self.win['volume'][code]['required'] = False
01046             else:
01047                 self.win['volume'][code]['required'] = True
01048             if use and code != 'mask':
01049                 use.Append(item = _('constant'))
01050             if use:
01051                 self.win['volume'][code]['use'] = use.GetId()
01052                 use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
01053                 gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
01054                               pos = (row, 1))
01055             
01056             if code != 'topo':
01057                 map = gselect.Select(parent = panel, id = wx.ID_ANY,
01058                                      # size = globalvar.DIALOG_GSELECT_SIZE,
01059                                      size = (200, -1),
01060                                      type = "grid3")
01061                 self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
01062                 map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
01063                 gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
01064                               pos = (row, 2))
01065             else:
01066                 map = None
01067             
01068             if code == 'color':
01069                 value = csel.ColourSelect(panel, id = wx.ID_ANY,
01070                                           colour = (0,0,0),
01071                                           size = globalvar.DIALOG_COLOR_SIZE)
01072                 value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
01073             elif code == 'mask':
01074                 value = None
01075             else:
01076                 if code == 'topo':
01077                     size = (200, -1)
01078                 else:
01079                     size = (65, -1)
01080                 value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
01081                                     initial = 0)
01082                 if code == 'topo':
01083                     value.SetRange(minVal = -1e9, maxVal = 1e9)
01084                 elif code in ('shine', 'transp', 'emit'):
01085                     value.SetRange(minVal = 0, maxVal = 255)
01086                 else:
01087                     value.SetRange(minVal = 0, maxVal = 100)
01088                 value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
01089                 value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
01090             
01091             if value:
01092                 self.win['volume'][code]['const'] = value.GetId()
01093                 if code == 'topo':
01094                     gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
01095                                   pos = (row, 2))
01096                 else:
01097                     value.Enable(False)
01098                     gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
01099                                   pos = (row, 3))
01100             else:
01101                 self.win['volume'][code]['const'] = None
01102             
01103             if code != 'topo':
01104                 self.SetMapObjUseMap(nvizType = 'volume',
01105                                      attrb = code) # -> enable map / disable constant
01106             
01107             row += 1
01108         
01109         boxSizer.Add(item = gridSizer, proportion = 1,
01110                      flag = wx.ALL | wx.EXPAND, border = 3)
01111         pageSizer.Add(item = boxSizer, proportion = 0,
01112                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01113                       border = 3)
01114         
01115         panel.SetSizer(pageSizer)
01116         
01117         return panel
01118     
01119     def _createLightPage(self):
01120         """!Create light page"""
01121         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
01122         panel.SetupScrolling(scroll_x = False)
01123         
01124         self.page['light'] = { 'id' : 0, 
01125                                'notebook' : self.notebookAppearance.GetId() }
01126         self.win['light'] = {}
01127         
01128         pageSizer = wx.BoxSizer(wx.VERTICAL)
01129         
01130         show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
01131                            label = _("Show light model"))
01132         show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
01133         pageSizer.Add(item = show, proportion = 0,
01134                       flag = wx.ALL, border = 3)
01135         surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
01136                               label = _("Follow source viewpoint"))
01137         pageSizer.Add(item = surface, proportion = 0,
01138                       flag = wx.ALL, border = 3)
01139         
01140         # position
01141         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01142                             label = " %s " % (_("Light source position")))
01143         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01144         
01145         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
01146         posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
01147         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
01148                      pos = (1, 0), flag = wx.ALIGN_CENTER)
01149         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
01150                      pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
01151         pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
01152                                   mapwindow = self.mapWindow)
01153         self.win['light']['position'] = pos.GetId()
01154         posSizer.Add(item = pos,
01155                      pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
01156         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
01157                      pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
01158         posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
01159                      pos = (1, 2), flag = wx.ALIGN_CENTER)
01160         gridSizer.Add(item = posSizer, pos = (0, 0))
01161         
01162         # height
01163         self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
01164                             range = (0, 100),
01165                             bind = (self.OnLightChange, None, self.OnLightChange))
01166         
01167         heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
01168         heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
01169                       pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
01170         heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
01171                         flag = wx.ALIGN_RIGHT, pos = (1, 0))
01172         heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['spin']),
01173                         flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
01174                         wx.BOTTOM | wx.RIGHT, pos = (1, 1))
01175         
01176         gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
01177         
01178         boxSizer.Add(item = gridSizer, proportion = 1,
01179                      flag = wx.ALL | wx.EXPAND, border = 2)
01180         pageSizer.Add(item = boxSizer, proportion = 0,
01181                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01182                       border = 3)
01183         
01184         # position
01185         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01186                             label = " %s " % (_("Light color and intensity")))
01187         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
01188         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
01189 
01190         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
01191                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
01192         color = csel.ColourSelect(panel, id = wx.ID_ANY,
01193                                   colour = UserSettings.Get(group = 'nviz', key = 'light',
01194                                                             subkey = 'color'),
01195                                   size = globalvar.DIALOG_COLOR_SIZE)
01196         self.win['light']['color'] = color.GetId()
01197         color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
01198         gridSizer.Add(item = color, pos = (0, 2))
01199 
01200         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
01201                       pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
01202         self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
01203                             range = (0, 100),
01204                             bind = (self.OnLightValue, None, self.OnLightValue))
01205         gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
01206                       pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
01207         gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['spin']),
01208                       pos = (1, 2),
01209                       flag = wx.ALIGN_CENTER)
01210         gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
01211                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
01212         self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
01213                             range = (0, 100),
01214                             bind = (self.OnLightValue, None, self.OnLightValue))
01215         gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
01216                       pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
01217         gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['spin']),
01218                       pos = (2, 2),
01219                       flag = wx.ALIGN_CENTER)
01220 
01221         boxSizer.Add(item = gridSizer, proportion = 1,
01222                      flag = wx.ALL | wx.EXPAND, border = 2)
01223         pageSizer.Add(item = boxSizer, proportion = 0,
01224                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01225                       border = 3)
01226         
01227         # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
01228         # reset.SetToolTipString(_("Reset to default view"))
01229         # # self.win['reset'] = reset.GetId()
01230         # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
01231         
01232         # viewSizer.Add(item = reset, proportion = 1,
01233         #               flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
01234         #               border = 5)
01235         
01236         # gridSizer.AddGrowableCol(3)
01237         # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
01238         #               flag = wx.EXPAND)
01239         
01240         panel.SetSizer(pageSizer)
01241         
01242         return panel
01243 
01244     def _createFringePage(self):
01245         """!Create fringe page"""
01246         panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
01247         panel.SetupScrolling(scroll_x = False)
01248         
01249         self.page['fringe'] = { 'id' : 1,
01250                                 'notebook' : self.notebookAppearance.GetId() }
01251         self.win['fringe'] = {}
01252 
01253         pageSizer = wx.BoxSizer(wx.VERTICAL)
01254         
01255         # selection
01256         rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01257                              label = " %s " % (_("Surface")))
01258         rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
01259         rmaps = gselect.Select(parent = panel, type = 'raster',
01260                                onPopup = self.GselectOnPopup)
01261         rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
01262         self.win['fringe']['map'] = rmaps.GetId()
01263         rboxSizer.Add(item = rmaps, proportion = 0,
01264                       flag = wx.ALL,
01265                       border = 3)
01266         pageSizer.Add(item = rboxSizer, proportion = 0,
01267                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01268                       border = 3)
01269         
01270         ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01271                              label = " %s " % (_("Edges with fringe")))
01272         eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
01273         for edge in [(_("N && W"), "nw"),
01274                      (_("N && E"), "ne"),
01275                      (_("S && W"), "sw"),
01276                      (_("S && E"), "se")]:
01277             chkbox = wx.CheckBox(parent = panel,
01278                                  label = edge[0],
01279                                  name = edge[1])
01280             self.win['fringe'][edge[1]] = chkbox.GetId()
01281             eboxSizer.Add(item = chkbox, proportion = 0,
01282                          flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
01283             chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
01284         
01285         pageSizer.Add(item = eboxSizer, proportion = 0,
01286                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01287                       border = 3)
01288 
01289         sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
01290                              label = " %s " % (_("Settings")))
01291         sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
01292         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
01293         
01294         # elevation
01295         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
01296                                            label = _("Elevation of fringe from bottom:")),
01297                       pos = (0, 0),
01298                       flag = wx.ALIGN_CENTER_VERTICAL)
01299         spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
01300                            size = (65, -1), min = -1e6, max = 1e6)
01301         spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
01302         spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
01303         self.win['fringe']['elev'] = spin.GetId()
01304         gridSizer.Add(item = spin, pos = (0, 1))
01305         
01306         # color
01307         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
01308                                            label = _("Color:")),
01309                       pos = (1, 0),
01310                       flag = wx.ALIGN_CENTER_VERTICAL)
01311         color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
01312                                   size = globalvar.DIALOG_COLOR_SIZE)
01313         color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
01314                                          subkey = 'color'))
01315         color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
01316         self.win['fringe']['color'] = color.GetId()
01317         gridSizer.Add(item = color, pos = (1, 1))
01318         
01319         sboxSizer.Add(item = gridSizer, proportion = 1,
01320                       flag = wx.ALL | wx.EXPAND, border = 3)
01321         pageSizer.Add(item = sboxSizer, proportion = 0,
01322                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
01323                       border = 3)
01324         
01325         panel.SetSizer(pageSizer)
01326 
01327         return panel
01328 
01329     def GetLayerData(self, nvizType):
01330         """!Get nviz data"""
01331         name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
01332         
01333         if nvizType == 'surface' or nvizType == 'fringe':
01334             return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
01335         elif nvizType == 'vector':
01336             return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
01337         elif nvizType == 'volume':
01338             return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
01339         
01340         return None
01341     
01342     def OnFringe(self, event):
01343         """!Show/hide fringe"""
01344         enabled = event.IsChecked()
01345         win = self.FindWindowById(event.GetId())
01346         
01347         data = self.GetLayerData('fringe')['surface']
01348         
01349         sid = data['object']['id']
01350         elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
01351         color = self.FindWindowById(self.win['fringe']['color']).GetValue()
01352         
01353         self._display.SetFringe(sid, color, elev,
01354                                 self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
01355                                 self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
01356                                 self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
01357                                 self.FindWindowById(self.win['fringe']['se']).IsChecked())
01358         self.mapWindow.Refresh(False)
01359         
01360     def OnScroll(self, event, win, data):
01361         """!Generic scrolling handler"""
01362         winName = self.__GetWindowName(win, event.GetId())
01363         if not winName:
01364             return
01365         data[winName] = event.GetInt()
01366         for w in win[winName].itervalues():
01367             self.FindWindowById(w).SetValue(data[winName])
01368         
01369         event.Skip()
01370         
01371     def _createControl(self, parent, data, name, range, bind = (None, None, None),
01372                        sliderHor = True, size = 200):
01373         """!Add control (Slider + SpinCtrl)"""
01374         data[name] = dict()
01375         if sliderHor:
01376             style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
01377                 wx.SL_BOTTOM
01378             sizeW = (size, -1)
01379         else:
01380             style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
01381                 wx.SL_INVERSE
01382             sizeW = (-1, size)
01383         
01384         slider = wx.Slider(parent = parent, id = wx.ID_ANY,
01385                            minValue = range[0],
01386                            maxValue = range[1],
01387                            style = style,
01388                            size = sizeW)
01389         slider.SetName('slider')
01390         if bind[0]:
01391             slider.Bind(wx.EVT_SCROLL, bind[0])
01392         
01393         # slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
01394         if bind[1]:
01395             slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
01396         data[name]['slider'] = slider.GetId()
01397         
01398         spin = wx.SpinCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
01399                            min = range[0],
01400                            max = range[1])
01401         
01402         # no 'changed' event ... (FIXME)
01403         spin.SetName('spin')
01404         if bind[2]:
01405             spin.Bind(wx.EVT_SPINCTRL, bind[2])
01406         
01407         data[name]['spin'] = spin.GetId()
01408         
01409     def __GetWindowName(self, data, id):
01410         for name in data.iterkeys():
01411             if type(data[name]) is type({}):
01412                 for win in data[name].itervalues():
01413                     if win == id:
01414                         return name
01415             else:
01416                 if data[name] == id:
01417                     return name
01418         
01419         return None
01420 
01421     def UpdateSettings(self):
01422         """!Update view from settings values 
01423         stored in self.mapWindow.view dictionary"""
01424         for control in ('height',
01425                         'persp',
01426                         'twist',
01427                         'z-exag'):
01428             for win in self.win['view'][control].itervalues():                
01429                 if control == 'height':
01430                     value = UserSettings.Get(group = 'nviz', key = 'view',
01431                                              subkey = ['height', 'value'], internal = True)
01432                 else:
01433                     try:
01434                         value = self.mapWindow.view[control]['value']
01435                     except KeyError:
01436                         value = -1
01437                 
01438                 self.FindWindowById(win).SetValue(value)
01439         
01440         viewWin = self.FindWindowById(self.win['view']['position'])
01441         x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
01442                                  self.mapWindow.view['position']['y'])
01443         viewWin.Draw(pos = (x, y), scale = True)
01444         viewWin.Refresh(False)
01445         
01446         # bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
01447         # self.OnBgColor(event = bgcolor)
01448         self.Update()
01449         
01450         self.mapWindow.Refresh(eraseBackground = False)
01451         self.mapWindow.render['quick'] = False
01452         self.mapWindow.Refresh(False)
01453         
01454     def OnShowLightModel(self, event):
01455         """!Show light model"""
01456         self._display.showLight = event.IsChecked()
01457         self._display.DrawLightingModel()
01458         
01459     def OnLightChange(self, event):
01460         """!Position of the light changed"""
01461         winName = self.__GetWindowName(self.win['light'], event.GetId())
01462         if not winName:
01463             return
01464         
01465         val = event.GetInt()
01466         self.mapWindow.light['position']['z'] = val
01467         for win in self.win['light'][winName].itervalues():
01468             self.FindWindowById(win).SetValue(val)
01469         
01470         event = wxUpdateLight()
01471         wx.PostEvent(self.mapWindow, event)
01472         
01473         event.Skip()
01474 
01475     def OnLightColor(self, event):
01476         """!Color of the light changed"""
01477         self.mapWindow.light['color'] = event.GetValue()
01478         
01479         event = wxUpdateLight()
01480         wx.PostEvent(self.mapWindow, event)
01481         
01482         event.Skip()
01483         
01484     def OnLightValue(self, event):
01485         """!Light brightness changed"""
01486         data = self.mapWindow.light
01487         self.OnScroll(event, self.win['light'], data)
01488         
01489         event = wxUpdateLight()
01490         wx.PostEvent(self.mapWindow, event)
01491         
01492         event.Skip()
01493         
01494     def OnBgColor(self, event):
01495         """!Background color changed"""
01496         color = event.GetValue()
01497         self.mapWindow.view['background']['color'] = event.GetValue()
01498         color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
01499         
01500         self._display.SetBgColor(str(color))
01501         
01502         if self.mapDisplay.statusbarWin['render'].IsChecked():
01503             self.mapWindow.Refresh(False)
01504         
01505     def OnSetSurface(self, event):
01506         """!Surface selected, currently used for fringes"""
01507         name = event.GetString()
01508         try:
01509             data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
01510         except:
01511             self.EnablePage('fringe', False)
01512             return
01513         
01514         layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
01515         self.EnablePage('fringe', True)
01516         
01517     def OnSetRaster(self, event):
01518         """!Raster map selected, update surface page"""
01519         name = event.GetString()
01520         try:
01521             data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
01522         except:
01523             self.EnablePage('surface', False)
01524             return
01525         
01526         layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
01527         self.EnablePage('surface', True)
01528         self.UpdateSurfacePage(layer, data, updateName = False)
01529         
01530     def OnSetVector(self, event):
01531         """!Vector map selected, update properties page"""
01532         name = event.GetString()
01533         try:
01534             data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
01535         except:
01536             self.EnablePage('vector', False)
01537             return
01538         
01539         layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
01540         self.EnablePage('vector', True)
01541         self.UpdateVectorPage(layer, data, updateName = False)
01542 
01543     def OnSetRaster3D(self, event):
01544         """!3D Raster map selected, update surface page"""
01545         name = event.GetString()
01546         try:
01547             data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
01548         except:
01549             self.EnablePage('volume', False)
01550             return
01551         
01552         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
01553         self.EnablePage('volume', True)
01554         self.UpdateVolumePage(layer, data, updateName = False)
01555         
01556     def OnViewChange(self, event):
01557         """!Change view, render in quick mode"""
01558         # find control
01559         winName = self.__GetWindowName(self.win['view'], event.GetId())
01560         if not winName:
01561             return
01562         
01563         if winName == 'height':
01564             view = self.mapWindow.iview # internal
01565         else:
01566             view = self.mapWindow.view
01567         
01568         if winName == 'z-exag' and event.GetInt() >= 0:
01569             self.PostViewEvent(zExag = True)
01570         else:
01571             self.PostViewEvent(zExag = False)
01572         
01573         view[winName]['value'] = event.GetInt()
01574         
01575         for win in self.win['view'][winName].itervalues():
01576             self.FindWindowById(win).SetValue(view[winName]['value'])
01577                 
01578         self.mapWindow.render['quick'] = True
01579         self.mapWindow.Refresh(False)
01580         
01581         event.Skip()
01582         
01583     def OnViewChanged(self, event):
01584         """!View changed, render in full resolution"""
01585         self.mapWindow.render['quick'] = False
01586         self.mapWindow.Refresh(False)
01587         
01588         self.UpdateSettings()
01589         
01590     def OnViewChangedSpin(self, event):
01591         """!View changed, render in full resolution"""
01592         self.mapWindow.render['quick'] = False
01593         self.OnViewChange(event)
01594         self.OnViewChanged(None)
01595         self.Update()
01596         
01597         event.Skip()
01598         
01599     def OnResetView(self, event):
01600         """!Reset to default view (view page)"""
01601         self.mapWindow.ResetView()
01602         self.UpdateSettings()
01603         self.mapWindow.Refresh(False)
01604         
01605     def OnLookAt(self, event):
01606         """!Look at (view page)"""
01607         sel = event.GetSelection()
01608         if sel == 0: # top
01609             self.mapWindow.view['position']['x'] = 0.5
01610             self.mapWindow.view['position']['y'] = 0.5
01611         elif sel == 1: # north
01612             self.mapWindow.view['position']['x'] = 0.5
01613             self.mapWindow.view['position']['y'] = 0.0
01614         elif sel == 2: # south
01615             self.mapWindow.view['position']['x'] = 0.5
01616             self.mapWindow.view['position']['y'] = 1.0
01617         elif sel == 3: # east
01618             self.mapWindow.view['position']['x'] = 1.0
01619             self.mapWindow.view['position']['y'] = 0.5
01620         elif sel == 4: # west
01621             self.mapWindow.view['position']['x'] = 0.0
01622             self.mapWindow.view['position']['y'] = 0.5
01623         elif sel == 5: # north-west
01624             self.mapWindow.view['position']['x'] = 0.0
01625             self.mapWindow.view['position']['y'] = 0.0
01626         elif sel == 6: # north-east
01627             self.mapWindow.view['position']['x'] = 1.0
01628             self.mapWindow.view['position']['y'] = 0.0
01629         elif sel == 7: # south-east
01630             self.mapWindow.view['position']['x'] = 1.0
01631             self.mapWindow.view['position']['y'] = 1.0
01632         elif sel == 8: # south-west
01633             self.mapWindow.view['position']['x'] = 0.0
01634             self.mapWindow.view['position']['y'] = 1.0
01635         
01636         self.PostViewEvent(zExag = True)
01637         
01638         self.UpdateSettings()
01639         self.mapWindow.render['quick'] = False
01640         self.mapWindow.Refresh(False)
01641 
01642     def OnClose(self, event):
01643         """!Close button pressed
01644         
01645         Close dialog
01646         """
01647         self.Hide()
01648         
01649     def OnMapObjUse(self, event):
01650         """!Set surface attribute -- use -- map/constant"""
01651         if not self.mapWindow.init:
01652             return
01653         
01654         wx.Yield()
01655         
01656         # find attribute row
01657         attrb = self.__GetWindowName(self.win['surface'], event.GetId())
01658         if not attrb:
01659             attrb = self.__GetWindowName(self.win['volume'], event.GetId())
01660             nvizType = 'volume'
01661         else:
01662             nvizType = 'surface'
01663         
01664         selection = event.GetSelection()
01665         if self.win[nvizType][attrb]['required']: # no 'unset'
01666             selection += 1
01667         if selection == 0: # unset
01668             useMap = None
01669             value = ''
01670         elif selection == 1: # map
01671             useMap = True
01672             value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
01673         elif selection == 2: # constant
01674             useMap = False
01675             if attrb == 'color':
01676                 value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
01677                 value = self._getColorString(value)
01678             else:
01679                 value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
01680         
01681         self.SetMapObjUseMap(nvizType = nvizType,
01682                              attrb = attrb, map = useMap)
01683         
01684         name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
01685         if nvizType == 'surface':
01686             data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
01687             data[nvizType]['attribute'][attrb] = { 'map' : useMap,
01688                                                    'value' : str(value),
01689                                                    'update' : None }
01690         else: # volume / isosurface
01691             data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
01692             list = self.FindWindowById(self.win['volume']['isosurfs'])
01693             id = list.GetSelection()
01694             data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
01695                                                         'value' : str(value),
01696                                                         'update' : None }
01697         
01698         # update properties
01699         event = wxUpdateProperties(data = data)
01700         wx.PostEvent(self.mapWindow, event)
01701         
01702         if self.mapDisplay.statusbarWin['render'].IsChecked():
01703             self.mapWindow.Refresh(False)
01704         
01705     def EnablePage(self, name, enabled = True):
01706         """!Enable/disable all widgets on page"""
01707         for key, item in self.win[name].iteritems():
01708             if key == 'map' or key == 'surface':
01709                 continue
01710             if type(item) == types.DictType:
01711                 for sitem in self.win[name][key].itervalues():
01712                     if type(sitem) == types.IntType:
01713                         self.FindWindowById(sitem).Enable(enabled)
01714             else:
01715                 if type(item) == types.IntType:
01716                     self.FindWindowById(item).Enable(enabled)
01717         
01718     def SetMapObjUseMap(self, nvizType, attrb, map = None):
01719         """!Update dialog widgets when attribute type changed"""
01720         if attrb in ('topo', 'color', 'shine'):
01721             incSel = -1 # decrement selection (no 'unset')
01722         else:
01723             incSel = 0
01724         
01725         if map is True: # map
01726             if attrb != 'topo': # changing map topography not allowed
01727                 # not sure why, but here must be disabled both ids, should be fixed!
01728                 self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
01729             if self.win[nvizType][attrb]['const']:
01730                 self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
01731             self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
01732         elif map is False: # const
01733             self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
01734             if self.win[nvizType][attrb]['const']:
01735                 self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
01736             self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
01737         else: # unset
01738             self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
01739             if self.win[nvizType][attrb]['const']:
01740                 self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
01741             self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
01742         
01743     def OnSurfaceMap(self, event):
01744         """!Set surface attribute"""
01745         self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
01746         
01747     def SetMapObjAttrb(self, nvizType, winId):
01748         """!Set map object (surface/isosurface) attribute (map/constant)"""
01749         if not self.mapWindow.init:
01750             return
01751         
01752         attrb = self.__GetWindowName(self.win[nvizType], winId) 
01753         if not attrb:
01754             return
01755         
01756         if nvizType == 'volume' and attrb == 'topo':
01757             return
01758         
01759         selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
01760         if self.win[nvizType][attrb]['required']:
01761             selection += 1
01762         
01763         if selection == 0: # unset
01764             useMap = None
01765             value = ''
01766         elif selection == 1: # map
01767             value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
01768             useMap = True
01769         else: # constant
01770             if attrb == 'color':
01771                 value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
01772                 # tuple to string
01773                 value = self._getColorString(value)
01774             else:
01775                 value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
01776             useMap = False
01777         
01778         if not self.pageChanging:
01779             name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
01780             if nvizType == 'surface':
01781                 data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
01782                 data[nvizType]['attribute'][attrb] = { 'map' : useMap,
01783                                                        'value' : str(value),
01784                                                        'update' : None }
01785             else:
01786                 data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
01787                 list = self.FindWindowById(self.win['volume']['isosurfs'])
01788                 id = list.GetSelection()
01789                 if id > -1:
01790                     data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
01791                                                                 'value' : str(value),
01792                                                                 'update' : None }
01793             
01794             # update properties
01795             event = wxUpdateProperties(data = data)
01796             wx.PostEvent(self.mapWindow, event)
01797             
01798             if self.mapDisplay.statusbarWin['render'].IsChecked():
01799                 self.mapWindow.Refresh(False)
01800         
01801     def OnSurfaceResolution(self, event):
01802         """!Draw resolution changed"""
01803         self.SetSurfaceResolution()
01804         
01805         if self.mapDisplay.statusbarWin['render'].IsChecked():
01806             self.mapWindow.Refresh(False)
01807         
01808     def SetSurfaceResolution(self):
01809         """!Set draw resolution"""
01810         coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
01811         fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
01812         
01813         data = self.GetLayerData('surface')
01814         data['surface']['draw']['resolution'] = { 'coarse' : coarse,
01815                                                   'fine' : fine,
01816                                                   'update' : None }
01817         
01818         # update properties
01819         event = wxUpdateProperties(data = data)
01820         wx.PostEvent(self.mapWindow, event)
01821         
01822     def SetSurfaceMode(self):
01823         """!Set draw mode"""
01824         mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
01825         if mode == 0: # coarse
01826             self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
01827             self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
01828         elif mode == 1: # fine
01829             self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
01830             self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
01831         else: # both
01832             self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
01833             self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
01834         
01835         style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
01836         
01837         shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
01838         
01839         value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
01840         
01841         return value, desc
01842 
01843     def OnSurfaceMode(self, event):
01844         """!Set draw mode"""
01845         value, desc = self.SetSurfaceMode()
01846         
01847         data = self.GetLayerData('surface')
01848         data['surface']['draw']['mode'] = { 'value' : value,
01849                                             'desc' : desc,
01850                                             'update' : None }
01851         
01852         # update properties
01853         event = wxUpdateProperties(data = data)
01854         wx.PostEvent(self.mapWindow, event)
01855         
01856         if self.mapDisplay.statusbarWin['render'].IsChecked():
01857             self.mapWindow.Refresh(False)
01858 
01859     def OnSurfaceModeAll(self, event):
01860         """!Set draw mode (including wire color) for all loaded surfaces"""
01861         value, desc = self.SetSurfaceMode()
01862         coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
01863         fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
01864         color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
01865         cvalue = self._getColorString(color)
01866         
01867         for name in self.mapWindow.GetLayerNames(type = 'raster'):
01868             
01869             data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
01870             if not data:
01871                 continue # shouldy no happen
01872             
01873             data['surface']['draw']['all'] = True
01874             data['surface']['draw']['mode'] = { 'value' : value,
01875                                                 'desc' : desc,
01876                                                 'update' : None }
01877             data['surface']['draw']['resolution'] = { 'coarse' : coarse,
01878                                                       'fine' : fine,
01879                                                       'update' : None }
01880             data['surface']['draw']['wire-color'] = { 'value' : cvalue,
01881                                                       'update' : None }
01882             
01883             # update properties
01884             event = wxUpdateProperties(data = data)
01885             wx.PostEvent(self.mapWindow, event)
01886             
01887         if self.mapDisplay.statusbarWin['render'].IsChecked():
01888             self.mapWindow.Refresh(False)
01889         
01890     def _getColorString(self, color):
01891         """!Set wire color"""
01892         return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
01893     
01894     def OnSurfaceWireColor(self, event):
01895         """!Set wire color"""
01896         data = self.GetLayerData('surface')
01897         value = self._getColorString(event.GetValue())
01898         data['surface']['draw']['wire-color'] = { 'value' : value,
01899                                                   'update' : None }
01900         
01901         # update properties
01902         event = wxUpdateProperties(data = data)
01903         wx.PostEvent(self.mapWindow, event)
01904         
01905         if self.mapDisplay.statusbarWin['render'].IsChecked():
01906             self.mapWindow.Refresh(False)
01907         
01908     def OnSurfaceAxis(self, event):
01909         """!Surface position, axis changed"""
01910         data = self.GetLayerData('surface')
01911         id = data['surface']['object']['id']
01912         
01913         axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
01914         slider = self.FindWindowById(self.win['surface']['position']['slider'])
01915         spin = self.FindWindowById(self.win['surface']['position']['spin'])
01916         
01917         x, y, z = self._display.GetSurfacePosition(id)
01918         
01919         if axis == 0: # x
01920             slider.SetValue(x)
01921             spin.SetValue(x)
01922         elif axis == 1: # y
01923             slider.SetValue(y)
01924             spin.SetValue(y)
01925         else: # z
01926             slider.SetValue(z)
01927             spin.SetValue(z)
01928         
01929     def OnSurfacePosition(self, event):
01930         """!Surface position"""
01931         winName = self.__GetWindowName(self.win['surface'], event.GetId())
01932         if not winName:
01933             return
01934         axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
01935         value = event.GetInt()
01936         
01937         for win in self.win['surface']['position'].itervalues():
01938             if win == self.win['surface']['position']['axis']:
01939                 continue
01940             else:
01941                 self.FindWindowById(win).SetValue(value)
01942         
01943         data = self.GetLayerData('surface')
01944         id = data['surface']['object']['id']
01945         x, y, z = self._display.GetSurfacePosition(id)
01946         
01947         if axis == 0: # x
01948             x = value
01949         elif axis == 1: # y
01950             y = value
01951         else: # z
01952             z = value
01953         
01954         data = self.GetLayerData('surface')
01955         data['surface']['position']['x'] = x
01956         data['surface']['position']['y'] = y
01957         data['surface']['position']['z'] = z
01958         data['surface']['position']['update'] = None
01959         # update properties
01960         event = wxUpdateProperties(data = data)
01961         wx.PostEvent(self.mapWindow, event)
01962         
01963         if self.mapDisplay.statusbarWin['render'].IsChecked():
01964             self.mapWindow.Refresh(False)
01965         #        self.UpdatePage('surface')
01966 
01967     def UpdateVectorShow(self, vecType, enabled):
01968         """!Enable/disable lines/points widgets
01969         
01970         @param vecType vector type (lines, points)
01971         """
01972         if vecType != 'lines' and vecType != 'points':
01973             return False
01974         
01975         for win in self.win['vector'][vecType].keys():
01976             if win == 'show':
01977                 continue
01978             if type(self.win['vector'][vecType][win]) == type({}):
01979                 for swin in self.win['vector'][vecType][win].keys():
01980                     if enabled:
01981                         self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
01982                     else:
01983                         self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
01984             else:
01985                 if enabled:
01986                     self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
01987                 else:
01988                     self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
01989         
01990         return True
01991     
01992     def OnVectorShow(self, event):
01993         """!Show vector lines/points"""
01994         winId = event.GetId()
01995         if winId == self.win['vector']['lines']['show']:
01996             vecType = 'lines'
01997             points = False
01998         else: # points
01999             vecType = 'points' 
02000             points = True
02001        
02002         checked = event.IsChecked()
02003         name = self.FindWindowById(self.win['vector']['map']).GetValue()
02004         item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
02005         data = self.GetLayerData('vector')['vector']
02006         
02007         if checked:
02008             self.mapWindow.LoadVector(item, points = points)
02009         else:
02010             self.mapWindow.UnloadVector(item, points = points)
02011         
02012         self.UpdateVectorShow(vecType, checked)
02013         
02014         if checked:
02015             try:
02016                 id = data[vecType]['object']['id']
02017             except KeyError:
02018                 id = -1
02019             
02020             if id > 0:
02021                 self.mapWindow.SetMapObjProperties(item, id, vecType)
02022                 
02023                 # update properties
02024                 event = wxUpdateProperties(data = data)
02025                 wx.PostEvent(self.mapWindow, event)
02026         
02027         if self.mapDisplay.statusbarWin['render'].IsChecked():
02028             self.mapWindow.Refresh(False)
02029         
02030         event.Skip()
02031     
02032     def OnVectorDisplay(self, event):
02033         """!Display vector lines on surface/flat"""
02034         rasters = self.mapWindow.GetLayerNames('raster')
02035         if event.GetSelection() == 0: # surface
02036             if len(rasters) < 1:
02037                 self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
02038                 self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
02039                 return
02040             
02041             self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
02042             # set first found surface
02043             data = self.GetLayerData('vector')
02044             data['vector']['lines']['mode']['surface'] = rasters[0]
02045             self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
02046                 rasters[0])
02047         else: # flat
02048             self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
02049         
02050         self.OnVectorLines(event)
02051         
02052         event.Skip()
02053 
02054     def OnVectorLines(self, event):
02055         """!Set vector lines mode, apply changes if auto-rendering is enabled"""
02056         data = self.GetLayerData('vector')
02057         width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
02058         
02059         mode = {}
02060         if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
02061             mode['type'] = 'surface'
02062             mode['surface'] = self.FindWindowById(self.win['vector']['lines']['surface']).GetValue()
02063             mode['update'] = None
02064         else:
02065             mode['type'] = 'flat'
02066         
02067         for attrb in ('width', 'mode'):
02068             data['vector']['lines'][attrb]['update'] = None
02069         data['vector']['lines']['width']['value'] = width
02070         data['vector']['lines']['mode']['value'] = mode
02071         
02072         color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
02073         
02074         if isinstance(color, csel.ColourSelect):
02075             pass #color picker not yet instantiated
02076         else:
02077             color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
02078             data['vector']['lines']['color']['update'] = None
02079             data['vector']['lines']['color']['value'] = color
02080         
02081         # update properties
02082         event = wxUpdateProperties(data = data)
02083         wx.PostEvent(self.mapWindow, event)
02084                         
02085         if self.mapDisplay.statusbarWin['render'].IsChecked():
02086             self.mapWindow.Refresh(False)
02087         
02088     def OnVectorHeight(self, event):
02089         value = event.GetInt()
02090         id = event.GetId()
02091         if id == self.win['vector']['lines']['height']['spin'] or \
02092                 id == self.win['vector']['lines']['height']['slider']:
02093             vtype = 'lines'
02094         else:
02095             vtype = 'points'
02096         
02097         if type(event) == type(wx.ScrollEvent()):
02098             # slider
02099             win = self.FindWindowById(self.win['vector'][vtype]['height']['spin'])
02100         else:
02101             # spin
02102             win = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
02103         win.SetValue(value)
02104 
02105         data = self.GetLayerData('vector')['vector'][vtype]
02106         data['height'] = { 'value' : value,
02107                            'update' : None }
02108         
02109         # update properties
02110         event = wxUpdateProperties(data = data)
02111         wx.PostEvent(self.mapWindow, event)
02112         
02113         self.mapWindow.render['quick'] = True
02114         self.mapWindow.render['v' + vtype] = True
02115         self.mapWindow.Refresh(False)
02116         
02117         event.Skip()
02118     
02119     def OnVectorHeightFull(self, event):
02120         """!Vector height changed, render in full resolution"""
02121         self.OnVectorHeight(event)
02122         self.OnVectorSurface(event)
02123         id = event.GetId()
02124         if id == self.win['vector']['lines']['height']['spin'] or \
02125                 id == self.win['vector']['lines']['height']['slider']:
02126             vtype = 'lines'
02127         else:
02128             vtype = 'points'
02129         
02130         self.mapWindow.render['quick'] = False
02131         self.mapWindow.render['v' + vtype] = False
02132         self.mapWindow.Refresh(False)
02133 
02134     def OnVectorHeightSpin(self, event):
02135         """!Vector height changed, render in full resolution"""
02136         # TODO: use step value instead
02137         
02138         #        self.OnVectorHeight(event)
02139         self.OnVectorHeightFull(event)
02140         
02141     def OnVectorSurface(self, event):
02142         """!Reference surface for vector map (lines/points)"""
02143         id = event.GetId()
02144         if id == self.win['vector']['lines']['surface']:
02145             vtype = 'lines'
02146         else:
02147             vtype = 'points'
02148         data = self.GetLayerData('vector')
02149         data['vector'][vtype]['mode']['surface'] = { 'value' : event.GetString(),
02150                                                      'update' : None }
02151         
02152         # update properties
02153         event = wxUpdateProperties(data = data)
02154         wx.PostEvent(self.mapWindow, event)
02155         
02156         if self.mapDisplay.statusbarWin['render'].IsChecked():
02157             self.mapWindow.Refresh(False)
02158         
02159     def OnVectorPoints(self, event):
02160         """!Set vector points mode, apply changes if auto-rendering is enabled"""
02161         data = self.GetLayerData('vector')
02162         
02163         size  = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
02164         marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
02165         #        width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
02166         
02167         for attrb in ('size', 'marker'):
02168             data['vector']['points'][attrb]['update'] = None
02169         data['vector']['points']['size']['value'] = size
02170         #        data['vector']['points']['width']['value'] = width
02171         data['vector']['points']['marker']['value'] = marker
02172         
02173         color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
02174         if isinstance(color, csel.ColourSelect):
02175             pass #color picker not yet instantiated
02176         else:
02177             color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
02178             data['vector']['points']['color']['update'] = None
02179             data['vector']['points']['color']['value'] = color
02180         
02181         # update properties
02182         event = wxUpdateProperties(data = data)
02183         wx.PostEvent(self.mapWindow, event)
02184         
02185         if self.mapDisplay.statusbarWin['render'].IsChecked():
02186             self.mapWindow.Refresh(False)
02187 
02188     def UpdateIsosurfButtons(self, list):
02189         """!Enable/disable buttons 'add', 'delete',
02190         'move up', 'move down'"""
02191         nitems = list.GetCount()
02192         add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
02193         delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
02194         moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
02195         moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
02196         if nitems >= wxnviz.MAX_ISOSURFS:
02197             # disable add button on max
02198             add.Enable(False)
02199         else:
02200             add.Enable(True)
02201         
02202         if nitems < 1:
02203             # disable 'delete' if only one item in the lis
02204             delete.Enable(False)
02205         else:
02206             delete.Enable(True)
02207         
02208         if list.GetSelection() >= nitems - 1:
02209             # disable 'move-down' if last
02210             moveDown.Enable(False)
02211         else:
02212             moveDown.Enable(True)
02213         
02214         if list.GetSelection() < 1:
02215             # disable 'move-up' if first
02216             moveUp.Enable(False)
02217         else:
02218             moveUp.Enable(True)
02219         
02220     def OnVolumeIsosurfMode(self, event):
02221         """!Set isosurface draw mode"""
02222         self.SetIsosurfaceMode(event.GetSelection())
02223     
02224     def SetIsosurfaceMode(self, selection):
02225         """!Set isosurface draw mode"""
02226         data = self.GetLayerData('volume')['volume']
02227         id = data['object']['id']
02228         
02229         mode = 0
02230         if selection == 0:
02231             mode |= wxnviz.DM_FLAT
02232         else:
02233             mode |= wxnviz.DM_GOURAUD
02234         
02235         self._display.SetIsosurfaceMode(id, mode)
02236         
02237         if self.mapDisplay.statusbarWin['render'].IsChecked():
02238             self.mapWindow.Refresh(False)
02239         
02240     def OnVolumeIsosurfResolution(self, event):
02241         """!Set isosurface draw resolution"""
02242         self.SetIsosurfaceResolution(event.GetInt())
02243         
02244     def SetIsosurfaceResolution(self, res):
02245         """!Set isosurface draw resolution"""
02246         data = self.GetLayerData('volume')['volume']
02247         
02248         id = data['object']['id']
02249         self._display.SetIsosurfaceRes(id, res)
02250         
02251         if self.mapDisplay.statusbarWin['render'].IsChecked():
02252             self.mapWindow.Refresh(False)
02253         
02254     def OnVolumeIsosurfMap(self, event):
02255         """!Set surface attribute"""
02256         self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
02257         
02258     def OnVolumeIsosurfCheck(self, event):
02259         """!Isosurface checked (->load) or unchecked (->unload)"""
02260         index = event.GetSelection()
02261         list = self.FindWindowById(self.win['volume']['isosurfs'])
02262         
02263         data = self.GetLayerData('volume')['volume']
02264         id = data['object']['id']
02265         
02266         isosurfId = event.GetSelection()
02267         
02268         if list.IsChecked(index):
02269             self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
02270         else:
02271             # disable -> make transparent
02272             self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
02273         
02274         if self.mapDisplay.statusbarWin['render'].IsChecked():
02275             self.mapWindow.Refresh(False)
02276         
02277     def OnVolumeIsosurfSelect(self, event):
02278         """!Isosurface item selected"""
02279         winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
02280         winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
02281         selection = event.GetSelection()
02282         if selection == 0:
02283             winUp.Enable(False)
02284             if not winDown.IsEnabled():
02285                 winDown.Enable()
02286         elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
02287             winDown.Enable(False)
02288             if not winUp.IsEnabled():
02289                 winUp.Enable()
02290         else:
02291             if not winDown.IsEnabled():
02292                 winDown.Enable()
02293             if not winUp.IsEnabled():
02294                 winUp.Enable()
02295         
02296         # update dialog
02297         name = self.FindWindowById(self.win['volume']['map']).GetValue()
02298         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02299         data = self.GetLayerData('volume')['volume']['isosurface'][selection]
02300         
02301         self.UpdateVolumeIsosurfPage(layer, data)
02302         
02303     def OnVolumeIsosurfAdd(self, event):
02304         """!Add new isosurface to the list"""
02305         list = self.FindWindowById(self.win['volume']['isosurfs'])
02306         level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
02307         
02308         sel = list.GetSelection()
02309         if sel < 0 or sel >= list.GetCount() - 1:
02310             item = list.Append(item = "%s %s" % (_("Level"), str(level)))
02311         else:
02312             list.Insert(item = "%s %s" % (_("Level"), str(level)),
02313                         pos = sel+1) # append
02314             item = sel + 1
02315         
02316         list.Check(item)
02317         list.SetSelection(item)
02318         
02319         name = self.FindWindowById(self.win['volume']['map']).GetValue()
02320         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02321         data = self.GetLayerData('volume')['volume']
02322         id = data['object']['id']
02323         
02324         # collect properties
02325         isosurfData = {}
02326         for attrb in ('topo', 'color', 'mask',
02327                       'transp', 'shine', 'emit'):
02328             if attrb == 'topo':
02329                 isosurfData[attrb] = {}
02330                 win = self.FindWindowById(self.win['volume'][attrb]['const'])
02331                 isosurfData[attrb]['value'] = win.GetValue()
02332             else:
02333                 uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
02334                 sel = uwin.GetSelection()
02335                 if self.win['volume'][attrb]['required']:
02336                     sel += 1
02337                 if sel == 0: # unset
02338                     continue
02339                 
02340                 isosurfData[attrb] = {}
02341                 if sel == 1: # map
02342                     isosurfData[attrb]['map'] = True
02343                     vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
02344                     value = vwin.GetValue()
02345                 else: # const
02346                     isosurfData[attrb]['map'] = False
02347                     vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
02348                     if vwin.GetName() == "color":
02349                         value = self._getColorString(vwin.GetValue())
02350                     else:
02351                         value = vwin.GetValue()
02352                 isosurfData[attrb]['value'] = value
02353         
02354         data['isosurface'].insert(item, isosurfData)
02355         
02356         # add isosurface        
02357         self._display.AddIsosurface(id, level)
02358         # use by default 3d raster map for color
02359         self._display.SetIsosurfaceColor(id, item, True, str(layer.name))
02360         
02361         # update buttons
02362         self.UpdateIsosurfButtons(list)
02363         
02364         if self.mapDisplay.statusbarWin['render'].IsChecked():
02365             self.mapWindow.Refresh(False)
02366         
02367         event.Skip()
02368         
02369     def OnVolumeIsosurfDelete(self, event):
02370         """!Remove isosurface from list"""
02371         list = self.FindWindowById(self.win['volume']['isosurfs'])
02372         
02373         # remove item from list
02374         isosurfId = list.GetSelection()
02375         list.Delete(isosurfId)
02376         # select last item
02377         if list.GetCount() > 0:
02378             list.SetSelection(list.GetCount()-1)
02379         
02380         name = self.FindWindowById(self.win['volume']['map']).GetValue()
02381         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02382         data = self.GetLayerData('volume')['volume']
02383 
02384         id = data['object']['id']
02385         
02386         # delete isosurface
02387         del data['isosurface'][isosurfId]
02388         
02389         self._display.DeleteIsosurface(id, isosurfId)
02390         
02391         # update buttons
02392         self.UpdateIsosurfButtons(list)
02393         
02394         if self.mapDisplay.statusbarWin['render'].IsChecked():
02395             self.mapWindow.Refresh(False)
02396         
02397         event.Skip()
02398         
02399     def OnVolumeIsosurfMoveUp(self, event):
02400         """!Move isosurface up in the list"""
02401         list = self.FindWindowById(self.win['volume']['isosurfs'])
02402         sel = list.GetSelection()
02403         
02404         if sel < 1:
02405             return # this should not happen
02406         
02407         name = self.FindWindowById(self.win['volume']['map']).GetValue()
02408         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02409         data = self.GetLayerData('volume')['volume']
02410         
02411         id = data['object']['id']
02412         
02413         # move item up
02414         text = list.GetStringSelection()
02415         list.Insert(item = text, pos = sel-1)
02416         list.Check(sel-1)
02417         list.SetSelection(sel-1)
02418         list.Delete(sel+1)
02419         data['isosurface'].insert(sel-1, data['isosurface'][sel])
02420         del data['isosurface'][sel+1]
02421         self._display.MoveIsosurface(id, sel, True)
02422         
02423         # update buttons
02424         self.UpdateIsosurfButtons(list)
02425         
02426         if self.mapDisplay.statusbarWin['render'].IsChecked():
02427             self.mapWindow.Refresh(False)
02428         
02429         event.Skip()
02430         
02431     def OnVolumeIsosurfMoveDown(self, event):
02432         """!Move isosurface dowm in the list"""
02433         list = self.FindWindowById(self.win['volume']['isosurfs'])
02434         sel = list.GetSelection()
02435         
02436         if sel >= list.GetCount() - 1:
02437             return # this should not happen
02438         
02439         name = self.FindWindowById(self.win['volume']['map']).GetValue()
02440         layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02441         data = self.GetLayerData('volume')['volume']
02442         
02443         id = data['object']['id']
02444         
02445         # move item up
02446         text = list.GetStringSelection()
02447         list.Insert(item = text, pos = sel+2)
02448         list.Check(sel+2)
02449         list.SetSelection(sel+2)
02450         list.Delete(sel)
02451         data['isosurface'].insert(sel+2, data['isosurface'][sel])
02452         del data['isosurface'][sel]
02453         self._display.MoveIsosurface(id, sel, False)
02454         
02455         # update buttons
02456         self.UpdateIsosurfButtons(list)
02457         
02458         if self.mapDisplay.statusbarWin['render'].IsChecked():
02459             self.mapWindow.Refresh(False)
02460         
02461         event.Skip()
02462         
02463     def UpdatePage(self, pageId):
02464         """!Update dialog (selected page)"""
02465         self.pageChanging = True
02466         Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
02467         
02468         if pageId == 'view':
02469             self.SetPage('view')
02470             hmin = self.mapWindow.iview['height']['min']
02471             hmax = self.mapWindow.iview['height']['max']
02472             hval = self.mapWindow.iview['height']['value']
02473             zmin = self.mapWindow.view['z-exag']['min']
02474             zmax = self.mapWindow.view['z-exag']['max']
02475             zval = self.mapWindow.view['z-exag']['value']
02476             
02477             for control in ('spin', 'slider'):
02478                 self.FindWindowById(self.win['view']['height'][control]).SetRange(hmin,
02479                                                                                   hmax)
02480                 self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)                                      
02481                 self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(zmin,
02482                                                                                   zmax)
02483                 self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)                                      
02484         
02485             self.FindWindowById(self.win['view']['bgcolor']).SetColour(\
02486                             self.mapWindow.view['background']['color'])
02487             
02488         elif pageId in ('surface', 'vector', 'volume'):
02489             name = self.FindWindowById(self.win[pageId]['map']).GetValue()
02490             data = self.GetLayerData(pageId)
02491             if data:
02492                 if pageId == 'surface':
02493                     layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
02494                     self.UpdateSurfacePage(layer, data['surface'])
02495                 elif pageId == 'vector':
02496                     layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
02497                     self.UpdateVectorPage(layer, data['vector'])
02498                 elif pageId == 'volume':
02499                     layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
02500                     self.UpdateVectorPage(layer, data['vector'])
02501         elif pageId == 'light':
02502             zval = self.mapWindow.light['position']['z']
02503             bval = self.mapWindow.light['bright']
02504             aval = self.mapWindow.light['ambient']
02505             for control in ('spin', 'slider'):
02506                 self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
02507                 self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
02508                 self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
02509             self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
02510         elif pageId == 'fringe':
02511             win = self.FindWindowById(self.win['fringe']['map'])
02512             win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
02513         
02514         self.Update()
02515         self.pageChanging = False
02516         
02517     def UpdateSurfacePage(self, layer, data, updateName = True):
02518         """!Update surface page"""
02519         ret = gcmd.RunCommand('r.info',
02520                               read = True,
02521                               flags = 'm',
02522                               map = layer.name)
02523         if ret:
02524             desc = ret.split('=')[1].rstrip('\n')
02525         else:
02526             desc = None
02527         if updateName:
02528             self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
02529         self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
02530         
02531         # attributes
02532         for attr in ('topo', 'color'): # required
02533             if layer and layer.type == 'raster':
02534                 self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
02535             else:
02536                 self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
02537             self.SetMapObjUseMap(nvizType = 'surface',
02538                                  attrb = attr, map = True) # -> map
02539         
02540         if 'color' in data['attribute']:
02541             value = data['attribute']['color']['value']
02542             if data['attribute']['color']['map']:
02543                 self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
02544             else: # constant
02545                 color = map(int, value.split(':'))
02546                 self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
02547             self.SetMapObjUseMap(nvizType = 'surface',
02548                                  attrb = attr, map = data['attribute']['color']['map'])
02549         
02550         self.SetMapObjUseMap(nvizType = 'surface',
02551                              attrb = 'shine', map = data['attribute']['shine']['map'])
02552         value = data['attribute']['shine']['value']
02553         if data['attribute']['shine']['map']:
02554             self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
02555         else:
02556             self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
02557         
02558         #
02559         # draw
02560         #
02561         for control, data in data['draw'].iteritems():
02562             if control == 'all': # skip 'all' property
02563                 continue
02564             if control == 'resolution':
02565                 self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(data['coarse'])
02566                 self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(data['fine'])
02567                 continue
02568             
02569             if control == 'mode':
02570                 if data['desc']['mode'] == 'coarse':
02571                     self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
02572                 elif data['desc']['mode'] == 'fine':
02573                     self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
02574                 else: # both
02575                     self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
02576                 
02577                 if data['desc']['style'] == 'wire':
02578                     self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
02579                 else: # surface
02580                     self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
02581                 
02582                 if data['desc']['shading'] == 'flat':
02583                     self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
02584                 else: # gouraud
02585                     self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
02586                 
02587                 continue
02588             
02589             value = data['value']
02590             win = self.FindWindowById(self.win['surface']['draw'][control])
02591             
02592             name = win.GetName()
02593             
02594             if name == "selection":
02595                 win.SetSelection(value)
02596             elif name == "colour":
02597                 color = map(int, value.split(':'))
02598                 win.SetColour(color)
02599             else:
02600                 win.SetValue(value)
02601         # enable/disable res widget + set draw mode
02602         self.OnSurfaceMode(event = None)
02603 
02604     def VectorInfo(self, layer):
02605         """!Get number of points/lines
02606         
02607         @param layer MapLayer instance
02608         
02609         @return num of points/features (expect of points)
02610         @return None
02611         """
02612         vInfo = grass.vector_info_topo(layer.GetName())
02613         
02614         if not vInfo:
02615             return None
02616         
02617         nprimitives = 0
02618         for key, value in vInfo.iteritems():
02619             if key in ('points',
02620                        'lines',
02621                        'boundaries',
02622                        'centroids',
02623                        'faces',
02624                        'kernels'):
02625                 nprimitives += value
02626         
02627         return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
02628         
02629     def UpdateVectorPage(self, layer, data, updateName = True):
02630         """!Update vector page"""
02631         npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
02632         if mapIs3D:
02633             desc = _("Vector map is 3D")
02634             enable = False
02635         else:
02636             desc = _("Vector map is 2D")
02637             enable = True
02638         desc += " - " + _("%(features)d features (%(points)d points)") % \
02639             { 'features' : nfeatures, 'points' : npoints }
02640         
02641         if updateName:
02642             self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
02643         self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
02644         
02645         self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
02646         for v in ('lines', 'points'):
02647             self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
02648             self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
02649             self.FindWindowById(self.win['vector'][v]['height']['spin']).Enable(enable)
02650             
02651         #
02652         # lines
02653         #
02654         showLines = self.FindWindowById(self.win['vector']['lines']['show'])
02655         if 'object' in data['lines']:
02656             showLines.SetValue(True)
02657         else:
02658             showLines.SetValue(False)
02659             if nlines > 0:
02660                 showLines.Enable(True)
02661             else:
02662                 showLines.Enable(False)
02663         
02664         self.UpdateVectorShow('lines',
02665                               showLines.IsChecked())
02666         
02667         width = self.FindWindowById(self.win['vector']['lines']['width'])
02668         width.SetValue(data['lines']['width']['value'])
02669         
02670         color = self.FindWindowById(self.win['vector']['lines']['color'])
02671         color.SetValue(map(int, data['lines']['color']['value'].split(':')))
02672         
02673         for vtype in ('lines', 'points'):
02674             if vtype == 'lines':
02675                 display = self.FindWindowById(self.win['vector']['lines']['flat'])
02676                 if data[vtype]['mode']['type'] == 'flat':
02677                     display.SetSelection(1)
02678                 else:
02679                     display.SetSelection(0)
02680             
02681             if data[vtype]['mode']['type'] == 'surface':
02682                 rasters = self.mapWindow.GetLayerNames('raster')
02683                 surface = self.FindWindowById(self.win['vector'][vtype]['surface'])
02684                 surface.SetItems(rasters)
02685                 if len(rasters) > 0:
02686                     try:
02687                         surface.SetStringSelection(data[vtype]['mode']['surface'])
02688                     except:
02689                         pass
02690         
02691         for type in ('slider', 'spin'):
02692             win = self.FindWindowById(self.win['vector']['lines']['height'][type])
02693             win.SetValue(data['lines']['height']['value'])
02694         
02695         #
02696         # points
02697         #
02698         showPoints = self.FindWindowById(self.win['vector']['points']['show'])
02699         
02700         if 'object' in data['points']:
02701             showPoints.SetValue(True)
02702         else:
02703             showPoints.SetValue(False)
02704             if npoints > 0:
02705                 showPoints.Enable(True)
02706             else:
02707                 showPoints.Enable(False)
02708         
02709         self.UpdateVectorShow('points',
02710                               showPoints.IsChecked())
02711         # size, width, marker, color
02712         for prop in ('size', 'marker', 'color'):
02713             win = self.FindWindowById(self.win['vector']['points'][prop])
02714             name = win.GetName()
02715             if name == 'selection':
02716                 win.SetSelection(data['points'][prop]['value'])
02717             elif name == 'color':
02718                 color = map(int, data['points'][prop]['value'].split(':'))
02719                 win.SetValue(color)
02720             else:
02721                 win.SetValue(data['points'][prop]['value'])
02722         # height
02723         for type in ('slider', 'spin'):
02724             win = self.FindWindowById(self.win['vector']['points']['height'][type])
02725             win.SetValue(data['points']['height']['value'])
02726         
02727     def UpdateVolumePage(self, layer, data, updateName = True):
02728         """!Update volume page"""
02729         if updateName:
02730             self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
02731         list = self.FindWindowById(self.win['volume']['isosurfs'])
02732         
02733         # draw
02734         for control, idata in data['draw'].iteritems():
02735             if control == 'all': # skip 'all' property
02736                 continue
02737             
02738             win = self.FindWindowById(self.win['volume']['draw'][control])
02739             
02740             if control == 'shading':
02741                 if data['draw']['shading']['desc'] == 'flat':
02742                     value = 0
02743                 else:
02744                     value = 1
02745             else:
02746                 value = idata['value']
02747             
02748             if win.GetName() == "selection":
02749                 win.SetSelection(value)
02750             else:
02751                 win.SetValue(value)
02752         
02753         self.SetIsosurfaceMode(data['draw']['shading']['value'])
02754         self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
02755         
02756         self.UpdateVolumeIsosurfPage(layer, data['attribute'])
02757         
02758     def UpdateVolumeIsosurfPage(self, layer, data):
02759         """!Update dialog -- isosurface attributes"""
02760         #
02761         # isosurface attributes
02762         #
02763         for attrb in ('topo', 'color', 'mask',
02764                      'transp', 'shine', 'emit'):
02765             # check required first
02766             if attrb == 'topo':
02767                 self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
02768                 continue
02769             if attrb == 'color':
02770                 if layer and layer.type == '3d-raster':
02771                     self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
02772                 else:
02773                     self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
02774                 self.SetMapObjUseMap(nvizType = 'volume',
02775                                      attrb = attrb, map = True) # -> map
02776                 continue
02777             
02778             # skip empty attributes
02779             if attrb not in data:
02780                 continue
02781             
02782             value = data[attrb]['value']
02783             if attrb == 'color':
02784                 if data[attrb]['map']:
02785                     self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
02786                 else: # constant
02787                     color = map(int, value.split(':'))
02788                     self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
02789             else:
02790                 if data[attrb]['map']:
02791                     win = self.FindWindowById(self.win['volume'][attrb]['map'])
02792                 else:
02793                     win = self.FindWindowById(self.win['volume'][attrb]['const'])
02794                 win.SetValue(value)
02795             
02796             self.SetMapObjUseMap(nvizType = 'volume',
02797                                  attrb = attrb, map = data[attrb]['map'])
02798         
02799     def SetPage(self, name):
02800         """!Get named page"""
02801         if name == 'view':
02802             self.SetSelection(0)
02803         elif name in ('surface', 'vector', 'volume'):
02804             self.SetSelection(1)
02805         else:
02806             self.SetSelection(2)
02807         win = self.FindWindowById(self.page[name]['notebook'])
02808         
02809         win.SetSelection(self.page[name]['id'])
02810 
02811 class PositionWindow(wx.Window):
02812     """!Abstract position control window, see subclasses
02813     ViewPostionWindow and LightPositionWindow"""
02814     def __init__(self, parent, mapwindow, id = wx.ID_ANY,
02815                  **kwargs):
02816         self.mapWindow = mapwindow
02817         self.quick = True
02818         
02819         wx.Window.__init__(self, parent, id, **kwargs)
02820         
02821         self.SetBackgroundColour("WHITE")
02822         
02823         self.pdc = wx.PseudoDC()
02824         
02825         self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
02826         self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
02827 
02828         self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
02829         self.Bind(wx.EVT_PAINT, self.OnPaint)
02830         # self.Bind(wx.EVT_MOTION,       self.OnMouse)
02831         self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
02832         
02833     def Draw(self, pos, scale = False):
02834         w, h = self.GetClientSize()
02835         x, y = pos
02836         if scale:
02837             x = x * w
02838             y = y * h
02839         self.pdc.Clear()
02840         self.pdc.BeginDrawing()
02841         self.pdc.DrawLine(w / 2, h / 2, x, y)
02842         self.pdc.DrawCircle(x, y, 5)
02843         self.pdc.EndDrawing()
02844         
02845     def OnPaint(self, event):
02846         dc = wx.BufferedPaintDC(self)
02847         dc.SetBackground(wx.Brush("White"))
02848         dc.Clear()
02849         
02850         self.PrepareDC(dc)
02851         self.pdc.DrawToDC(dc)
02852         
02853     def UpdatePos(self, xcoord, ycoord):
02854         """!Update position coordinates (origin: UL)"""
02855         if xcoord < 0.0:
02856             xcoord = 0.0
02857         elif xcoord > 1.0:
02858             xcoord = 1.0
02859         if ycoord < 0.0:
02860             ycoord = 0.0
02861         elif ycoord > 1.0:
02862             ycoord = 1.0
02863 
02864         self.data['position']['x'] = xcoord        
02865         self.data['position']['y'] = ycoord
02866         
02867         return xcoord, ycoord
02868     
02869     def OnMouse(self, event):
02870         if event.LeftIsDown():
02871             x, y = event.GetPosition()
02872             self.Draw(pos = (x, y))
02873             w, h = self.GetClientSize()
02874             x = float(x) / w
02875             y = float(y) / h
02876             self.UpdatePos(x, y)
02877             self.Refresh(False)
02878         
02879         event.Skip()
02880         
02881     def PostDraw(self):
02882         x, y = self.UpdatePos(self.data['position']['x'],
02883                               self.data['position']['y'])
02884         self.Draw(pos = (x, y), scale = True)
02885 
02886 class ViewPositionWindow(PositionWindow):
02887     """!View position control widget"""
02888     def __init__(self, parent, mapwindow, id = wx.ID_ANY,
02889                  **kwargs):
02890         PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
02891 
02892         self.data = self.mapWindow.view
02893         self.PostDraw()
02894         
02895     def UpdatePos(self, xcoord, ycoord):
02896         x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
02897         
02898         event = wxUpdateView(zExag = True)
02899         wx.PostEvent(self.mapWindow, event)
02900 
02901         return x, y
02902 
02903     def OnMouse(self, event):
02904         PositionWindow.OnMouse(self, event)
02905         if event.LeftIsDown():
02906             self.mapWindow.render['quick'] = self.quick
02907             self.mapWindow.Refresh(eraseBackground = False)
02908         elif event.LeftUp():
02909             self.mapWindow.render['quick'] = False
02910             self.mapWindow.Refresh(eraseBackground = False)
02911         
02912         event.Skip()
02913 
02914 class LightPositionWindow(PositionWindow):
02915     """!Light position control widget"""
02916     def __init__(self, parent, mapwindow, id = wx.ID_ANY,
02917                  **kwargs):
02918         PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
02919 
02920         self.data = self.mapWindow.light
02921         self.quick = False
02922         self.PostDraw()
02923 
02924     def UpdatePos(self, xcoord, ycoord):
02925         x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
02926         
02927         event = wxUpdateLight()
02928         wx.PostEvent(self.mapWindow, event)
02929     
02930         return x, y
02931 
02932     def OnMouse(self, event):
02933         PositionWindow.OnMouse(self, event)
02934         if event.LeftUp():
02935             self.mapWindow.render['quick'] = False
02936             self.mapWindow.Refresh(eraseBackground = False)
02937 
02938 class NvizPreferencesDialog(PreferencesBaseDialog):
02939     """!Nviz preferences dialog"""
02940     def __init__(self, parent, title = _("3D view settings"),
02941                  settings = UserSettings):
02942         PreferencesBaseDialog.__init__(self, parent = parent, title = title,
02943                                        settings = settings)
02944         self.toolWin = self.parent.GetLayerManager().nviz
02945         self.win = dict()
02946         
02947         # create notebook pages
02948         self._createViewPage(self.notebook)
02949         self._createVectorPage(self.notebook)
02950         
02951         self.SetMinSize(self.GetBestSize())
02952         self.SetSize(self.size)
02953         
02954     def _createViewPage(self, notebook):
02955         """!Create notebook page for general settings"""
02956         panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
02957         
02958         notebook.AddPage(page = panel,
02959                          text = " %s " % _("View"))
02960         
02961         pageSizer = wx.BoxSizer(wx.VERTICAL)
02962         
02963         self.win['general'] = {}
02964         self.win['view'] = {}
02965         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
02966                             label = " %s " % (_("View")))
02967         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
02968         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
02969         
02970         # perspective
02971         self.win['view']['persp'] = {}
02972         pvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp')
02973         ipvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp', internal = True)
02974         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
02975                                          label = _("Perspective:")),
02976                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
02977         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
02978                                          label = _("(value)")),
02979                       pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
02980         
02981         pval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
02982                            initial = pvals['value'],
02983                            min = ipvals['min'],
02984                            max = ipvals['max'])
02985         self.win['view']['persp']['value'] = pval.GetId()
02986         gridSizer.Add(item = pval, pos = (0, 2),
02987                       flag = wx.ALIGN_CENTER_VERTICAL)
02988         
02989         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
02990                                          label = _("(step)")),
02991                       pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
02992         
02993         pstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
02994                            initial = pvals['step'],
02995                            min = ipvals['min'],
02996                            max = ipvals['max']-1)
02997         self.win['view']['persp']['step'] = pstep.GetId()
02998         gridSizer.Add(item = pstep, pos = (0, 4),
02999                       flag = wx.ALIGN_CENTER_VERTICAL)
03000         
03001         # position
03002         self.win['view']['position'] = {}
03003         posvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'position')
03004         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03005                                          label = _("Position:")),
03006                       pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03007         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03008                                          label = _("(x)")),
03009                       pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03010         
03011         px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03012                            initial = posvals['x'] * 100,
03013                            min = 0,
03014                            max = 100)
03015         self.win['view']['position']['x'] = px.GetId()
03016         gridSizer.Add(item = px, pos = (1, 2),
03017                       flag = wx.ALIGN_CENTER_VERTICAL)
03018         
03019         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03020                                          label = "(y)"),
03021                       pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03022         
03023         py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03024                            initial = posvals['y'] * 100,
03025                            min = 0,
03026                            max = 100)
03027         self.win['view']['position']['y'] = py.GetId()
03028         gridSizer.Add(item = py, pos = (1, 4),
03029                       flag = wx.ALIGN_CENTER_VERTICAL)
03030         
03031         # height
03032         self.win['view']['height'] = {}
03033         hvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'height')
03034         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03035                                          label = _("Height:")),
03036                       pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03037         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03038                                          label = _("(step)")),
03039                       pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03040         
03041         hstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03042                            initial = hvals['step'],
03043                            min = 1,
03044                            max = 1e6)
03045         self.win['view']['height']['step'] = hstep.GetId()
03046         gridSizer.Add(item = hstep, pos = (2, 2),
03047                       flag = wx.ALIGN_CENTER_VERTICAL)
03048         
03049         # twist
03050         self.win['view']['twist'] = {}
03051         tvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist')
03052         itvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist', internal = True)
03053         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03054                                          label = _("Twist:")),
03055                       pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03056         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03057                                          label = _("(value)")),
03058                       pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03059         
03060         tval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03061                            initial = tvals['value'],
03062                            min = itvals['min'],
03063                            max = itvals['max'])
03064         self.win['view']['twist']['value'] = tval.GetId()
03065         gridSizer.Add(item = tval, pos = (3, 2),
03066                       flag = wx.ALIGN_CENTER_VERTICAL)
03067         
03068         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03069                                          label = _("(step)")),
03070                       pos = (3, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03071         
03072         tstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03073                            initial = tvals['step'],
03074                            min = itvals['min'],
03075                            max = itvals['max']-1)
03076         self.win['view']['twist']['step'] = tstep.GetId()
03077         gridSizer.Add(item = tstep, pos = (3, 4),
03078                       flag = wx.ALIGN_CENTER_VERTICAL)
03079         
03080         # z-exag
03081         self.win['view']['z-exag'] = {}
03082         zvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'z-exag')
03083         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03084                                          label = _("Z-exag:")),
03085                       pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03086         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03087                                          label = _("(value)")),
03088                       pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03089         
03090         zval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03091                            initial = zvals['value'],
03092                            min = -1e6,
03093                            max = 1e6)
03094         self.win['view']['z-exag']['value'] = zval.GetId()
03095         gridSizer.Add(item = zval, pos = (4, 2),
03096                       flag = wx.ALIGN_CENTER_VERTICAL)
03097         
03098         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03099                                          label = _("(step)")),
03100                       pos = (4, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
03101         
03102         zstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03103                            initial = zvals['step'],
03104                            min = -1e6,
03105                            max = 1e6)
03106         self.win['view']['z-exag']['step'] = zstep.GetId()
03107         gridSizer.Add(item = zstep, pos = (4, 4),
03108                       flag = wx.ALIGN_CENTER_VERTICAL)
03109         
03110         boxSizer.Add(item = gridSizer, proportion = 1,
03111                   flag = wx.ALL | wx.EXPAND, border = 3)
03112         pageSizer.Add(item = boxSizer, proportion = 0,
03113                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
03114                       border = 3)
03115 
03116         box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
03117                            label = " %s " % (_("Image Appearance")))
03118         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03119         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
03120         gridSizer.AddGrowableCol(0)
03121         
03122         # background color
03123         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03124                                          label = _("Background color:")),
03125                       pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03126         
03127         color = csel.ColourSelect(panel, id = wx.ID_ANY,
03128                                   colour = UserSettings.Get(group = 'nviz', key = 'settings',
03129                                                             subkey = ['general', 'bgcolor']),
03130                                   size = globalvar.DIALOG_COLOR_SIZE)
03131         self.win['general']['bgcolor'] = color.GetId()
03132         gridSizer.Add(item = color, pos = (0, 1))
03133         
03134         boxSizer.Add(item = gridSizer, proportion = 1,
03135                   flag = wx.ALL | wx.EXPAND, border = 3)
03136         pageSizer.Add(item = boxSizer, proportion = 0,
03137                       flag = wx.EXPAND | wx.ALL,
03138                       border = 3)
03139         
03140         panel.SetSizer(pageSizer)
03141         
03142         return panel
03143     
03144     def _createVectorPage(self, notebook):
03145         """!Create notebook page for general settings"""
03146         panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
03147         
03148         notebook.AddPage(page = panel,
03149                          text = " %s " % _("Vector"))
03150         
03151         pageSizer = wx.BoxSizer(wx.VERTICAL)
03152         
03153         # vector lines
03154         self.win['vector'] = {}
03155         self.win['vector']['lines'] = {}
03156         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
03157                             label = " %s " % (_("Vector lines")))
03158         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03159         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
03160         
03161         # show
03162         row = 0
03163         showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
03164                                 label = _("Show lines"))
03165         self.win['vector']['lines']['show'] = showLines.GetId()
03166         showLines.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
03167                                             subkey = ['lines', 'show']))
03168         gridSizer.Add(item = showLines, pos = (row, 0))
03169         
03170         boxSizer.Add(item = gridSizer, proportion = 1,
03171                   flag = wx.ALL | wx.EXPAND, border = 3)
03172         pageSizer.Add(item = boxSizer, proportion = 0,
03173                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
03174                       border = 3)
03175         
03176         # vector points
03177         self.win['vector']['points'] = {}
03178         box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
03179                             label = " %s " % (_("Vector points")))
03180         boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
03181         gridSizer = wx.GridBagSizer(vgap = 3, hgap = 5)
03182         
03183         # show
03184         row = 0
03185         showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
03186                                  label = _("Show points"))
03187         showPoints.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
03188                                              subkey = ['points', 'show']))
03189         self.win['vector']['points']['show'] = showPoints.GetId()
03190         gridSizer.Add(item = showPoints, pos = (row, 0), span = (1, 8))
03191         
03192         # icon size
03193         row += 1 
03194         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03195                                          label = _("Size:")),
03196                       pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
03197         
03198         isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03199                             initial = 100,
03200                             min = 1,
03201                             max = 1e6)
03202         self.win['vector']['points']['size'] = isize.GetId()
03203         isize.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
03204                                         subkey = ['points', 'size']))
03205         gridSizer.Add(item = isize, pos = (row, 1),
03206                       flag = wx.ALIGN_CENTER_VERTICAL)
03207         
03208         # icon width
03209         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03210                                          label = _("Width:")),
03211                       pos = (row, 2), flag = wx.ALIGN_CENTER_VERTICAL)
03212         
03213         iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
03214                             initial = 2,
03215                             min = 1,
03216                             max = 1e6)
03217         self.win['vector']['points']['width'] = isize.GetId()
03218         iwidth.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
03219                                          subkey = ['points', 'width']))
03220         gridSizer.Add(item = iwidth, pos = (row, 3),
03221                       flag = wx.ALIGN_CENTER_VERTICAL)
03222         
03223         # icon symbol
03224         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03225                                          label = _("Marker:")),
03226                       pos = (row, 4), flag = wx.ALIGN_CENTER_VERTICAL)
03227         isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
03228                           choices = UserSettings.Get(group = 'nviz', key = 'vector',
03229                                                    subkey = ['points', 'marker'], internal = True))
03230         isym.SetName("selection")
03231         self.win['vector']['points']['marker'] = isym.GetId()
03232         isym.SetSelection(UserSettings.Get(group = 'nviz', key = 'vector',
03233                                            subkey = ['points', 'marker']))
03234         gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
03235                       pos = (row, 5))
03236         
03237         # icon color
03238         gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
03239                                          label = _("Color:")),
03240                       pos = (row, 6), flag = wx.ALIGN_CENTER_VERTICAL)
03241         icolor = csel.ColourSelect(panel, id = wx.ID_ANY)
03242         icolor.SetName("color")
03243         self.win['vector']['points']['color'] = icolor.GetId()
03244         icolor.SetColour(UserSettings.Get(group = 'nviz', key = 'vector',
03245                                           subkey = ['points', 'color']))
03246         gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL,
03247                       pos = (row, 7))
03248         
03249         boxSizer.Add(item = gridSizer, proportion = 1,
03250                   flag = wx.ALL | wx.EXPAND, border = 3)
03251         pageSizer.Add(item = boxSizer, proportion = 0,
03252                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
03253                       border = 3)
03254         
03255         panel.SetSizer(pageSizer)
03256         
03257         return panel
03258     
03259     def OnDefault(self, event):
03260         """Restore default settings"""
03261         settings = copy.deepcopy(UserSettings.GetDefaultSettings()['nviz'])
03262         UserSettings.Set(group = 'nviz',
03263                          value = settings)
03264         
03265         for subgroup, key in settings.iteritems(): # view, surface, vector...
03266             if subgroup != 'view':
03267                 continue
03268             for subkey, value in key.iteritems():
03269                 for subvalue in value.keys():
03270                     win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
03271                     val = settings[subgroup][subkey][subvalue]
03272                     if subkey == 'position':
03273                         val = int(val * 100)
03274                     
03275                     win.SetValue(val)
03276         
03277         event.Skip()
03278         
03279     def OnApply(self, event):
03280         """Apply Nviz settings for current session"""
03281         settings = UserSettings.Get(group = 'nviz')
03282         for subgroup, key in settings.iteritems(): # view, surface, vector...
03283             for subkey, value in key.iteritems():
03284                 for subvalue in value.keys():
03285                     try: # TODO
03286                         win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
03287                     except:
03288                         # print 'e', subgroup, subkey, subvalue
03289                         continue
03290                     
03291                     if win.GetName() == "selection":
03292                         value = win.GetSelection()
03293                     elif win.GetName() == "color":
03294                         value = tuple(win.GetColour())
03295                     else:
03296                         value = win.GetValue()
03297                     if subkey == 'position':
03298                         value = float(value) / 100
03299                     
03300                     settings[subgroup][subkey][subvalue] = value
03301                     
03302     def OnSave(self, event):
03303         """!Apply changes, update map and save settings of selected
03304         layer
03305         """
03306         # apply changes
03307         self.OnApply(None)
03308         
03309         if self.GetSelection() == self.page['id']:
03310             fileSettings = {}
03311             UserSettings.ReadSettingsFile(settings = fileSettings)
03312             fileSettings['nviz'] = UserSettings.Get(group = 'nviz')
03313             file = UserSettings.SaveToFile(fileSettings)
03314             self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
03315         
03316     def OnLoad(self, event):
03317         """!Apply button pressed"""
03318         self.LoadSettings()
03319         
03320         if event:
03321             event.Skip()
03322 
03323     def LoadSettings(self):
03324         """!Load saved Nviz settings and apply to current session"""
03325         UserSettings.ReadSettingsFile()
03326         settings = copy.deepcopy(UserSettings.Get(group = 'nviz'))
03327         
03328         for subgroup, key in settings.iteritems(): # view, surface, vector...
03329             for subkey, value in key.iteritems():
03330                 for subvalue in value.keys():
03331                     if subvalue == 'step':
03332                         continue
03333                     else:
03334                         insetting = value[subvalue]                                                    
03335                     if subgroup == 'view':
03336                         for viewkey, viewitem in self.mapWindow.view[subkey].iteritems(): 
03337                             if viewkey == subvalue:
03338                                 self.mapWindow.view[subkey][viewkey] = insetting 
03339                             else:
03340                                 continue
03341                     else:
03342                         for otherkey, otheritem in self.win[subgroup][subkey].iteritems():
03343                             if type(otheritem) == data:
03344                                 for endkey, enditem in otheritem.iteritems():
03345                                     if endkey == subvalue:
03346                                         paramwin = self.FindWindowById(enditem)
03347                                     else:
03348                                         continue
03349                             else:
03350                                 if otherkey == subvalue:
03351                                     paramwin = self.FindWindowById(otheritem)
03352                                 else:
03353                                     continue
03354                             if type(insetting) in [tuple, list] and len(insetting) > 2:
03355                                 insetting = tuple(insetting)
03356                                 paramwin.SetColour(insetting)
03357                             else:
03358                                 try:
03359                                     paramwin.SetValue(insetting)
03360                                 except:
03361                                     try:
03362                                         paramwin.SetStringSelection(insetting)
03363                                     except:
03364                                         continue
03365                                 
03366         self.toolWin.UpdateSettings()
03367         self.FindWindowById(self.win['view']['position']).Draw()
03368         self.FindWindowById(self.win['view']['position']).Refresh(False)
03369         
03370         self.mapWindow.render['quick'] = False
03371         self.mapWindow.Refresh(False)
03372         
03373     def OnSave(self, event):
03374         """!Save button pressed
03375         
03376         Save settings to configuration file
03377         """
03378         fileSettings = {}
03379         UserSettings.ReadSettingsFile(settings = fileSettings)
03380         
03381         self.toolWin.UpdateSettings()
03382         
03383         nvsettings = UserSettings.Get(group = 'nviz')
03384         for subgroup, key in nvsettings.iteritems(): # view, surface, vector...
03385             for subkey, value in key.iteritems():
03386                 if subkey == 'height': continue
03387                 for subvalue in value.keys():
03388                     if subvalue == 'step':
03389                         #no way to change steps for sliders or spinctrls on non-MSW systems
03390                         nvsettings[subgroup][subkey][subvalue] = 1 
03391                     else:
03392                         if subgroup == 'view':
03393                             nvsettings[subgroup][subkey][subvalue] = self.mapWindow.view[subkey][subvalue]                            
03394                         elif subvalue == 'map':
03395                             if subkey == 'shine': 
03396                                 nvsettings[subgroup][subkey][subvalue] = False
03397                             if subkey == 'color': 
03398                                 nvsettings[subgroup][subkey][subvalue] = True
03399                         else:
03400                             for otherkey, otheritem in self.win[subgroup][subkey].iteritems():
03401                                 if type(otheritem) == data:
03402                                     for endkey, enditem in otheritem.iteritems():
03403                                         if endkey == subvalue:
03404                                             if self.FindWindowById(enditem).GetClassName() == 'wxChoice':
03405                                                 outsetting = self.FindWindowById(enditem).GetSelection()
03406                                             else:
03407                                                 try:
03408                                                     outsetting = self.FindWindowById(enditem).GetColour()
03409                                                     outsetting = str(outsetting.Red())+':'+str(outsetting.Green())+':'+str(outsetting.Blue())
03410                                                 except:
03411                                                     try:
03412                                                         outsetting = self.FindWindowById(enditem).GetValue()
03413                                                     except:
03414                                                         try:
03415                                                             outsetting = self.FindWindowById(enditem).GetString()
03416                                                         except:
03417                                                             outsetting = ''
03418                                             if (type(outsetting) == list or type(outsetting) == tuple) and len(outsetting) > 2:
03419                                                 outsetting = str(outsetting[0])+':'+str(outsetting[1])+':'+str(outsetting[2])
03420                                                 
03421                                             nvsettings[subgroup][subkey][subvalue][endkey] = outsetting
03422                                 else:
03423                                     if otherkey == subvalue:
03424                                         if self.FindWindowById(otheritem).GetClassName() == 'wxChoice':
03425                                             outsetting = self.FindWindowById(otheritem).GetSelection()
03426                                         else:
03427                                             try:
03428                                                 outsetting = self.FindWindowById(otheritem).GetColour()
03429                                                 outsetting = str(outsetting.Red())+':'+str(outsetting.Green())+':'+str(outsetting.Blue())
03430                                             except:
03431                                                 try:
03432                                                     outsetting = self.FindWindowById(otheritem).GetValue()
03433                                                 except:
03434                                                     try:
03435                                                         outsetting = self.FindWindowById(enditem).GetString()
03436                                                     except:
03437                                                         outsetting = ''
03438                                         if (type(outsetting) == list or type(outsetting) == tuple) and len(outsetting) > 2:
03439                                             outsetting = str(outsetting[0])+':'+str(outsetting[1])+':'+str(outsetting[2])
03440 
03441                                         nvsettings[subgroup][subkey][subvalue] = outsetting
03442                                
03443         UserSettings.Set(group = 'nviz', value = nvsettings)
03444         file = UserSettings.SaveToFile()
03445         self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines