GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nviz_tools.py
Go to the documentation of this file.
1 """!
2 @package nviz_tools.py
3 
4 @brief Nviz (3D view) tools window
5 
6 Classes:
7  - NvizToolWindow
8  - PositionWindow
9  - ViewPositionWindow
10  - LightPositionWindow
11 
12 (C) 2008-2010 by the GRASS Development Team
13 
14 This program is free software under the GNU General Public
15 License (>=v2). Read the file COPYING that comes with GRASS
16 for details.
17 
18 @author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
19 @author Enhancements by Michael Barton <michael.barton@asu.edu>
20 """
21 
22 import os
23 import sys
24 import copy
25 import types
26 
27 import wx
28 import wx.lib.colourselect as csel
29 import wx.lib.scrolledpanel as SP
30 try:
31  import wx.lib.agw.flatnotebook as FN
32 except ImportError:
33  import wx.lib.flatnotebook as FN
34 
35 import grass.script as grass
36 
37 import globalvar
38 import gselect
39 import gcmd
40 from preferences import globalSettings as UserSettings
41 from preferences import PreferencesBaseDialog
42 try:
43  from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
44  import wxnviz
45 except (ImportError, NameError):
46  pass
47 from debug import Debug
48 
49 class NvizToolWindow(FN.FlatNotebook):
50  """!Nviz (3D view) tools panel
51  """
52  def __init__(self, parent, display, id = wx.ID_ANY,
53  style = globalvar.FNPageStyle, **kwargs):
54  self.parent = parent # GMFrame
55  self.mapDisplay = display
56  self.mapWindow = display.GetWindow()
57  self._display = self.mapWindow.GetDisplay()
58 
59  if globalvar.hasAgw:
60  kwargs['agwStyle'] = style
61  else:
62  kwargs['style'] = style
63  FN.FlatNotebook.__init__(self, parent, id, **kwargs)
64  self.SetTabAreaColour(globalvar.FNPageColor)
65 
66  self.win = {} # window ids
67  self.page = {} # page ids
68 
69  # view page
70  self.AddPage(page = self._createViewPage(),
71  text = " %s " % _("View"))
72 
73  # data page
74  self.AddPage(page = self._createDataPage(),
75  text = " %s " % _("Data"))
76 
77  # appearance page
78  self.AddPage(page = self._createAppearancePage(),
79  text = " %s " % _("Appearance"))
80 
81  self.UpdateSettings()
82  self.pageChanging = False
83  self.mapWindow.render['quick'] = False
84  self.mapWindow.Refresh(False)
85 
86  # bindings
87  self.Bind(wx.EVT_CLOSE, self.OnClose)
88  self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
89 
90  self.Update()
91  wx.CallAfter(self.SetPage, 'view')
92  wx.CallAfter(self.notebookData.SetSelection, 0)
93  wx.CallAfter(self.notebookAppearance.SetSelection, 0)
94 
95  def OnPageChanged(self, event):
96  new = event.GetSelection()
97  # self.ChangeSelection(new)
98 
99  def PostViewEvent(self, zExag = False):
100  """!Change view settings"""
101  event = wxUpdateView(zExag = zExag)
102  wx.PostEvent(self.mapWindow, event)
103 
104  def _createViewPage(self):
105  """!Create view settings page"""
106  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
107  panel.SetupScrolling(scroll_x = False)
108  self.page['view'] = { 'id' : 0,
109  'notebook' : self.GetId()}
110 
111  pageSizer = wx.BoxSizer(wx.VERTICAL)
112  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
113  label = " %s " % (_("Control View")))
114  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
115  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
116 
117  self.win['view'] = {}
118 
119  # position
120  posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
121  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
122  pos = (1, 0), flag = wx.ALIGN_CENTER)
123  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
124  pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
125  view = ViewPositionWindow(panel, size = (175, 175),
126  mapwindow = self.mapWindow)
127  self.win['view']['position'] = view.GetId()
128  posSizer.Add(item = view,
129  pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
130  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
131  pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
132  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
133  pos = (1, 2), flag = wx.ALIGN_CENTER)
134  gridSizer.Add(item = posSizer, pos = (0, 0))
135 
136  # perspective
137  # set initial defaults here (or perhaps in a default values file), not in user settings
138  self._createControl(panel, data = self.win['view'], name = 'persp',
139  range = (1,100),
140  bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
141  gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Perspective:")),
142  pos = (1, 0), flag = wx.ALIGN_CENTER)
143  gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['slider']), pos = (2, 0))
144  gridSizer.Add(item = self.FindWindowById(self.win['view']['persp']['spin']), pos = (3, 0),
145  flag = wx.ALIGN_CENTER)
146 
147  # twist
148  self._createControl(panel, data = self.win['view'], name = 'twist',
149  range = (-180,180),
150  bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
151  gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Twist:")),
152  pos = (1, 1), flag = wx.ALIGN_CENTER)
153  gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['slider']), pos = (2, 1))
154  gridSizer.Add(item = self.FindWindowById(self.win['view']['twist']['spin']), pos = (3, 1),
155  flag = wx.ALIGN_CENTER)
156 
157  # height + z-exag
158  self._createControl(panel, data = self.win['view'], name = 'height', sliderHor = False,
159  range = (0, 1),
160  bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
161 
162  self._createControl(panel, data = self.win['view'], name = 'z-exag', sliderHor = False,
163  range = (0, 5),
164  bind = (self.OnViewChange, self.OnViewChanged, self.OnViewChangedSpin))
165  self.FindWindowById(self.win['view']['z-exag']['slider']).SetValue(1)
166  self.FindWindowById(self.win['view']['z-exag']['spin']).SetValue(1)
167 
168  heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
169  heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
170  pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
171  heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['slider']),
172  flag = wx.ALIGN_RIGHT, pos = (1, 0))
173  heightSizer.Add(item = self.FindWindowById(self.win['view']['height']['spin']),
174  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
175  wx.BOTTOM | wx.RIGHT, pos = (1, 1))
176  heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Z-exag:")),
177  pos = (0, 2), flag = wx.ALIGN_LEFT, span = (1, 2))
178  heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['slider']),
179  flag = wx.ALIGN_RIGHT, pos = (1, 2))
180  heightSizer.Add(item = self.FindWindowById(self.win['view']['z-exag']['spin']),
181  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
182  wx.BOTTOM | wx.RIGHT, pos = (1, 3))
183 
184  gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
185 
186  # view setup + reset
187  viewSizer = wx.BoxSizer(wx.HORIZONTAL)
188 
189  viewSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY,
190  label = _("Look at:")),
191  flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
192  border = 5)
193 
194  viewType = wx.Choice (parent = panel, id = wx.ID_ANY, size = (125, -1),
195  choices = [_("top"),
196  _("north"),
197  _("south"),
198  _("east"),
199  _("west"),
200  _("north-west"),
201  _("north-east"),
202  _("south-east"),
203  _("south-west")])
204  viewType.SetSelection(0)
205  viewType.Bind(wx.EVT_CHOICE, self.OnLookAt)
206  # self.win['lookAt'] = viewType.GetId()
207  viewSizer.Add(item = viewType,
208  flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL,
209  border = 5)
210 
211  reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
212  reset.SetToolTipString(_("Reset to default view"))
213  # self.win['reset'] = reset.GetId()
214  reset.Bind(wx.EVT_BUTTON, self.OnResetView)
215 
216  viewSizer.Add(item = wx.Size(-1, -1), proportion = 1,
217  flag = wx.EXPAND)
218  viewSizer.Add(item = reset, proportion = 0,
219  flag = wx.ALL | wx.ALIGN_RIGHT,
220  border = 5)
221 
222  gridSizer.AddGrowableCol(2)
223  gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
224  flag = wx.EXPAND)
225 
226  # body
227  boxSizer.Add(item = gridSizer, proportion = 1,
228  flag = wx.ALL | wx.EXPAND, border = 2)
229  pageSizer.Add(item = boxSizer, proportion = 0,
230  flag = wx.EXPAND | wx.ALL,
231  border = 3)
232 
233  box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
234  label = " %s " % (_("Image Appearance")))
235  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
236  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
237  gridSizer.AddGrowableCol(0)
238 
239  # background color
240  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
241  label = _("Background color:")),
242  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
243 
244  color = csel.ColourSelect(panel, id = wx.ID_ANY,
245  colour = UserSettings.Get(group = 'nviz', key = 'view',
246  subkey = ['background', 'color']),
247  size = globalvar.DIALOG_COLOR_SIZE)
248  self.win['view']['bgcolor'] = color.GetId()
249  color.Bind(csel.EVT_COLOURSELECT, self.OnBgColor)
250  gridSizer.Add(item = color, pos = (0, 1))
251 
252  boxSizer.Add(item = gridSizer, proportion = 1,
253  flag = wx.ALL | wx.EXPAND, border = 3)
254  pageSizer.Add(item = boxSizer, proportion = 0,
255  flag = wx.EXPAND | wx.LEFT | wx.RIGHT,
256  border = 3)
257 
258  panel.SetSizer(pageSizer)
259 
260  return panel
261 
262  def _createDataPage(self):
263  """!Create data (surface, vector, volume) settings page"""
264  if globalvar.hasAgw:
265  self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
266  agwStyle = globalvar.FNPageDStyle)
267  else:
268  self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
269  style = globalvar.FNPageDStyle)
270 
271  # surface page
272  self.notebookData.AddPage(page = self._createSurfacePage(),
273  text = " %s " % _("Surface"))
274  self.EnablePage('surface', False)
275 
276  # vector page
277  self.notebookData.AddPage(page = self._createVectorPage(),
278  text = " %s " % _("Vector"))
279  self.EnablePage('vector', False)
280 
281  # volume page
282  self.notebookData.AddPage(page = self._createVolumePage(),
283  text = " %s " % _("Volume"))
284  self.EnablePage('volume', False)
285 
286  return self.notebookData
287 
288  def _createAppearancePage(self):
289  """!Create data (surface, vector, volume) settings page"""
290  if globalvar.hasAgw:
291  self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
292  agwStyle = globalvar.FNPageDStyle)
293  else:
294  self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
295  style = globalvar.FNPageDStyle)
296 
297  # light page
298  self.notebookAppearance.AddPage(page = self._createLightPage(),
299  text = " %s " % _("Lighting"))
300 
301  # fringe page
302  self.notebookAppearance.AddPage(page = self._createFringePage(),
303  text = " %s " % _("Fringe"))
304  self.EnablePage('fringe', False)
305 
306  return self.notebookAppearance
307 
308  def _createSurfacePage(self):
309  """!Create view settings page"""
310  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
311  panel.SetupScrolling(scroll_x = False)
312  self.page['surface'] = { 'id' : 0,
313  'panel' : panel.GetId(),
314  'notebook' : self.notebookData.GetId() }
315  pageSizer = wx.BoxSizer(wx.VERTICAL)
316 
317  self.win['surface'] = {}
318 
319  # selection
320  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
321  label = " %s " % (_("Raster map")))
322  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
323  rmaps = gselect.Select(parent = panel, type = 'raster',
324  onPopup = self.GselectOnPopup)
325  rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster)
326  self.win['surface']['map'] = rmaps.GetId()
327  desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
328  self.win['surface']['desc'] = desc.GetId()
329  boxSizer.Add(item = rmaps, proportion = 0,
330  flag = wx.ALL,
331  border = 3)
332  boxSizer.Add(item = desc, proportion = 0,
333  flag = wx.ALL,
334  border = 3)
335  pageSizer.Add(item = boxSizer, proportion = 0,
336  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
337  border = 3)
338 
339  #
340  # surface attributes
341  #
342  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
343  label = " %s " % (_("Surface attributes")))
344  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
345  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
346 
347  # type
348  self.win['surface']['attr'] = {}
349  row = 0
350  for code, attrb in (('topo', _("Topography")),
351  ('color', _("Color")),
352  ('mask', _("Mask")),
353  ('transp', _("Transparency")),
354  ('shine', _("Shininess")),
355  ('emit', _("Emission"))):
356  self.win['surface'][code] = {}
357  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
358  label = attrb + ':'),
359  pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
360  use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
361  choices = [_("map")])
362 
363  if code not in ('topo', 'color', 'shine'):
364  use.Insert(item = _("unset"), pos = 0)
365  self.win['surface'][code]['required'] = False
366  else:
367  self.win['surface'][code]['required'] = True
368  if code != 'mask':
369  use.Append(item = _('constant'))
370  self.win['surface'][code]['use'] = use.GetId()
371  use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
372  gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
373  pos = (row, 1))
374 
375  map = gselect.Select(parent = panel, id = wx.ID_ANY,
376  # size = globalvar.DIALOG_GSELECT_SIZE,
377  size = (200, -1),
378  type = "raster")
379  self.win['surface'][code]['map'] = map.GetId() - 1 # FIXME
380  map.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
381  # changing map topography not allowed
382  if code == 'topo':
383  map.Enable(False)
384  gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
385  pos = (row, 2))
386 
387  if code == 'color':
388  value = csel.ColourSelect(panel, id = wx.ID_ANY,
389  colour = (0,0,0),
390  size = globalvar.DIALOG_COLOR_SIZE)
391  value.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceMap)
392  elif code == 'mask':
393  value = None
394  else:
395  value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
396  initial = 0)
397  if code == 'topo':
398  value.SetRange(minVal = -1e9, maxVal = 1e9)
399  elif code in ('shine', 'transp', 'emit'):
400  value.SetRange(minVal = 0, maxVal = 255)
401  else:
402  value.SetRange(minVal = 0, maxVal = 100)
403  value.Bind(wx.EVT_TEXT, self.OnSurfaceMap)
404 
405  if value:
406  self.win['surface'][code]['const'] = value.GetId()
407  value.Enable(False)
408  gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
409  pos = (row, 3))
410  else:
411  self.win['surface'][code]['const'] = None
412 
413  self.SetMapObjUseMap(nvizType = 'surface',
414  attrb = code) # -> enable map / disable constant
415 
416  row += 1
417 
418  boxSizer.Add(item = gridSizer, proportion = 1,
419  flag = wx.ALL | wx.EXPAND, border = 3)
420  pageSizer.Add(item = boxSizer, proportion = 0,
421  flag = wx.EXPAND | wx.ALL,
422  border = 3)
423 
424  #
425  # draw
426  #
427  self.win['surface']['draw'] = {}
428  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
429  label = " %s " % (_("Draw")))
430  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
431  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
432  gridSizer.AddGrowableCol(6)
433 
434  # mode
435  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
436  label = _("Mode:")),
437  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
438  mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
439  choices = [_("coarse"),
440  _("fine"),
441  _("both")])
442  mode.SetSelection(0)
443  mode.SetName("selection")
444  mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
445  self.win['surface']['draw']['mode'] = mode.GetId()
446  gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
447  pos = (0, 1))
448 
449  # shading
450  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
451  label = _("Shading:")),
452  pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
453  shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
454  choices = [_("flat"),
455  _("gouraud")])
456  shade.SetName("selection")
457  self.win['surface']['draw']['shading'] = shade.GetId()
458  shade.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
459  gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
460  pos = (0, 3))
461 
462  # set to all
463  all = wx.Button(panel, id = wx.ID_ANY, label = _("Set to all"))
464  all.SetToolTipString(_("Use draw settings for all loaded surfaces"))
465  all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
466  gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
467  pos = (0, 4), span = (1,2), border = 3 )
468 
469  # resolution coarse
470  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
471  label = _("Coarse:")),
472  pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
473  resSizer = wx.BoxSizer(wx.HORIZONTAL)
474  resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
475  label = _("res.")),
476  flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
477  border = 3)
478  resC = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
479  initial = 6,
480  min = 1,
481  max = 100)
482  resC.SetName("value")
483  resC.SetValue(6)
484 
485  self.win['surface']['draw']['res-coarse'] = resC.GetId()
486  resC.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
487  resSizer.Add(item = resC, flag = wx.ALL | wx.ALIGN_LEFT |
488  wx.ALIGN_CENTER_VERTICAL, border = 3)
489  gridSizer.Add(item = resSizer, pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
490 
491  # Coarse style
492  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
493  label = _("style")),
494  pos = (1, 2), flag = wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL)
495  style = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
496  choices = [_("wire"),
497  _("surface")])
498  style.SetName("selection")
499  self.win['surface']['draw']['style'] = style.GetId()
500  style.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
501  gridSizer.Add(item = style, flag = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL,
502  pos = (1, 3))
503 
504  # color
505  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
506  label = _("wire color")),
507  pos = (1, 4), flag = wx.ALIGN_CENTER_VERTICAL |
508  wx.ALIGN_RIGHT | wx.LEFT, border = 3)
509  color = csel.ColourSelect(panel, id = wx.ID_ANY,
510  size = globalvar.DIALOG_COLOR_SIZE)
511  color.SetColour((136,136,136))
512  color.SetName("colour")
513  color.Bind(csel.EVT_COLOURSELECT, self.OnSurfaceWireColor)
514  self.win['surface']['draw']['wire-color'] = color.GetId()
515  gridSizer.Add(item = color, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
516  pos = (1, 5))
517 
518  # resolution fine
519  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
520  label = _("Fine:")),
521  pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
522 
523  resSizer = wx.BoxSizer(wx.HORIZONTAL)
524  resSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
525  label = _("res.")),
526  flag = wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL,
527  border = 3)
528  resF = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
529  initial = 3,
530  min = 1,
531  max = 100)
532  resF.SetName("value")
533  resF.SetValue(3)
534  self.win['surface']['draw']['res-fine'] = resF.GetId()
535  resF.Bind(wx.EVT_SPINCTRL, self.OnSurfaceResolution)
536  resSizer.Add(item = resF, flag = wx.ALL | wx.ALIGN_LEFT |
537  wx.ALIGN_CENTER_VERTICAL, border = 3)
538  gridSizer.Add(item = resSizer, pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
539 
540  boxSizer.Add(item = gridSizer, proportion = 1,
541  flag = wx.ALL | wx.EXPAND, border = 3)
542  pageSizer.Add(item = boxSizer, proportion = 0,
543  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
544  border = 3)
545 
546  #
547  # mask
548  #
549  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
550  label = " %s " % (_("Mask")))
551  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
552  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
553 
554  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
555  label = _("Mask zeros:")),
556  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
557 
558  elev = wx.CheckBox(parent = panel, id = wx.ID_ANY,
559  label = _("by elevation"))
560  elev.Enable(False) # TODO: not implemented yet
561  gridSizer.Add(item = elev, pos = (0, 1))
562 
563  color = wx.CheckBox(parent = panel, id = wx.ID_ANY,
564  label = _("by color"))
565  color.Enable(False) # TODO: not implemented yet
566  gridSizer.Add(item = color, pos = (0, 2))
567 
568  boxSizer.Add(item = gridSizer, proportion = 1,
569  flag = wx.ALL | wx.EXPAND, border = 3)
570  pageSizer.Add(item = boxSizer, proportion = 0,
571  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
572  border = 3)
573 
574  #
575  # position
576  #
577  self.win['surface']['position'] = {}
578  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
579  label = " %s " % (_("Position")))
580  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
581  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
582 
583  # position
584  self._createControl(panel, data = self.win['surface'], name = 'position',
585  range = (-10000, 10000),
586  bind = (self.OnSurfacePosition, self.OnSurfacePosition, self.OnSurfacePosition))
587 
588  axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
589  choices = ["X",
590  "Y",
591  "Z"])
592 
593  self.win['surface']['position']['axis'] = axis.GetId()
594  axis.SetSelection(0)
595  axis.Bind(wx.EVT_CHOICE, self.OnSurfaceAxis)
596 
597  pslide = self.FindWindowById(self.win['surface']['position']['slider'])
598  pspin = self.FindWindowById(self.win['surface']['position']['spin'])
599 
600  gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
601  gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
602  gridSizer.Add(item = pspin, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
603 
604  boxSizer.Add(item = gridSizer, proportion = 1,
605  flag = wx.ALL | wx.EXPAND, border = 3)
606  box.SetSizer(boxSizer)
607  box.Layout()
608 
609  pageSizer.Add(item = boxSizer, proportion = 0,
610  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
611  border = 3)
612 
613  panel.SetSizer(pageSizer)
614 
615  return panel
616 
617  def _createVectorPage(self):
618  """!Create view settings page"""
619  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
620  panel.SetupScrolling(scroll_x = False)
621  self.page['vector'] = { 'id' : 1,
622  'panel' : panel.GetId(),
623  'notebook' : self.notebookData.GetId() }
624  pageSizer = wx.BoxSizer(wx.VERTICAL)
625 
626  self.win['vector'] = {}
627 
628  # selection
629  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
630  label = " %s " % (_("Vector map")))
631  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
632  vmaps = gselect.Select(parent = panel, type = 'vector',
633  onPopup = self.GselectOnPopup)
634  vmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetVector)
635  self.win['vector']['map'] = vmaps.GetId()
636  desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
637  self.win['vector']['desc'] = desc.GetId()
638  boxSizer.Add(item = vmaps, proportion = 0,
639  flag = wx.ALL,
640  border = 3)
641  boxSizer.Add(item = desc, proportion = 0,
642  flag = wx.ALL,
643  border = 3)
644  pageSizer.Add(item = boxSizer, proportion = 0,
645  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
646  border = 3)
647 
648  #
649  # vector lines
650  #
651  self.win['vector']['lines'] = {}
652 
653  showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
654  label = _("Show vector lines"))
655  showLines.SetValue(True)
656 
657  self.win['vector']['lines']['show'] = showLines.GetId()
658  showLines.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
659 
660  pageSizer.Add(item = showLines, proportion = 0,
661  flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
662 
663  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
664  label = " %s " % (_("Vector lines")))
665  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
666  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
667 
668  # width
669  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
670  label = _("Line:")),
671  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
672  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
673  label = _("width")),
674  pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
675  wx.ALIGN_RIGHT)
676 
677  width = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
678  initial = 1,
679  min = 0,
680  max = 100)
681  width.SetValue(1)
682  self.win['vector']['lines']['width'] = width.GetId()
683  width.Bind(wx.EVT_SPINCTRL, self.OnVectorLines)
684  gridSizer.Add(item = width, pos = (0, 2),
685  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
686 
687  # color
688  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
689  label = _("color")),
690  pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
691  wx.ALIGN_RIGHT)
692 
693  color = csel.ColourSelect(panel, id = wx.ID_ANY,
694  colour = (0,0,0),
695  size = globalvar.DIALOG_COLOR_SIZE)
696  self.win['vector']['lines']['color'] = color.GetId()
697  color.Bind(csel.EVT_COLOURSELECT, self.OnVectorLines)
698 
699  gridSizer.Add(item = color, pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL |
700  wx.ALIGN_LEFT)
701 
702  # display
703  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
704  label = _("display")),
705  pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL |
706  wx.ALIGN_RIGHT)
707 
708  display = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
709  choices = [_("on surface"),
710  _("flat")])
711  self.win['vector']['lines']['flat'] = display.GetId()
712  display.Bind(wx.EVT_CHOICE, self.OnVectorDisplay)
713 
714  gridSizer.Add(item = display, flag = wx.ALIGN_CENTER_VERTICAL |
715  wx.ALIGN_LEFT, pos = (1, 2), span = (1,2))
716 
717  # height
718  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
719  label = _("Height above surface:")),
720  pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
721  span = (1, 3))
722 
723  surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
724  style = wx.CB_SIMPLE | wx.CB_READONLY,
725  choices = [])
726  surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
727  self.win['vector']['lines']['surface'] = surface.GetId()
728  gridSizer.Add(item = surface,
729  pos = (2, 3), span = (1, 6),
730  flag = wx.ALIGN_CENTER_VERTICAL)
731 
732  self._createControl(panel, data = self.win['vector']['lines'], name = 'height', size = 300,
733  range = (0, 1000),
734  bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
735  self.FindWindowById(self.win['vector']['lines']['height']['slider']).SetValue(0)
736  self.FindWindowById(self.win['vector']['lines']['height']['spin']).SetValue(0)
737  gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['slider']),
738  pos = (3, 0), span = (1, 7))
739  gridSizer.Add(item = self.FindWindowById(self.win['vector']['lines']['height']['spin']),
740  pos = (3, 7),
741  flag = wx.ALIGN_CENTER)
742 
743  boxSizer.Add(item = gridSizer, proportion = 1,
744  flag = wx.ALL | wx.EXPAND, border = 3)
745  pageSizer.Add(item = boxSizer, proportion = 0,
746  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
747  border = 3)
748 
749  #
750  # vector points
751  #
752  self.win['vector']['points'] = {}
753 
754  showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
755  label = _("Show vector points"))
756  showPoints.SetValue(True)
757  self.win['vector']['points']['show'] = showPoints.GetId()
758  showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
759 
760  pageSizer.Add(item = showPoints, proportion = 0,
761  flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
762 
763  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
764  label = " %s " % (_("Vector points")))
765  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
766  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
767 
768  # icon size
769  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
770  label = _("Icon:")),
771  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
772  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
773  label = _("size")),
774  pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL |
775  wx.ALIGN_RIGHT)
776 
777  isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
778  initial = 1,
779  min = 1,
780  max = 1e6)
781  isize.SetName('value')
782  isize.SetValue(100)
783  self.win['vector']['points']['size'] = isize.GetId()
784  isize.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
785  isize.Bind(wx.EVT_TEXT, self.OnVectorPoints)
786  gridSizer.Add(item = isize, pos = (0, 2),
787  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
788 
789  # icon color
790  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
791  label = _("color")),
792  pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL |
793  wx.ALIGN_RIGHT)
794  icolor = csel.ColourSelect(panel, id = wx.ID_ANY,
795  size = globalvar.DIALOG_COLOR_SIZE)
796  icolor.SetName("color")
797  icolor.SetColour((0,0,255))
798  self.win['vector']['points']['color'] = icolor.GetId()
799  icolor.Bind(csel.EVT_COLOURSELECT, self.OnVectorPoints)
800  gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL |
801  wx.ALIGN_LEFT,
802  pos = (0, 4))
803 
804  # icon width
805  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
806  label = _("width")),
807  pos = (0, 5), flag = wx.ALIGN_CENTER_VERTICAL |
808  wx.ALIGN_RIGHT)
809 
810  iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
811  initial = 1,
812  min = 1,
813  max = 1e6)
814  iwidth.SetName('value')
815  iwidth.SetValue(100)
816  self.win['vector']['points']['width'] = iwidth.GetId()
817  iwidth.Bind(wx.EVT_SPINCTRL, self.OnVectorPoints)
818  iwidth.Bind(wx.EVT_TEXT, self.OnVectorPoints)
819  gridSizer.Add(item = iwidth, pos = (0, 6),
820  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT)
821 
822  # icon symbol
823  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
824  label = _("symbol")),
825  pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
826  isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
827  choices = UserSettings.Get(group = 'nviz', key = 'vector',
828  subkey = ['points', 'marker'], internal = True))
829  isym.SetName("selection")
830  self.win['vector']['points']['marker'] = isym.GetId()
831  isym.Bind(wx.EVT_CHOICE, self.OnVectorPoints)
832  gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
833  pos = (1, 2), span = (1,2))
834 
835  # high
836  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
837  label = _("Height above surface:")),
838  pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL,
839  span = (1, 3))
840 
841  surface = wx.ComboBox(parent = panel, id = wx.ID_ANY, size = (250, -1),
842  style = wx.CB_SIMPLE | wx.CB_READONLY,
843  choices = [])
844  surface.Bind(wx.EVT_COMBOBOX, self.OnVectorSurface)
845  self.win['vector']['points']['surface'] = surface.GetId()
846  gridSizer.Add(item = surface,
847  pos = (2, 3), span = (1, 5),
848  flag = wx.ALIGN_CENTER_VERTICAL)
849 
850  self._createControl(panel, data = self.win['vector']['points'], name = 'height', size = 300,
851  range = (0, 1000),
852  bind = (self.OnVectorHeight, self.OnVectorHeightFull, self.OnVectorHeightSpin))
853 
854  self.FindWindowById(self.win['vector']['points']['height']['slider']).SetValue(0)
855  self.FindWindowById(self.win['vector']['points']['height']['spin']).SetValue(0)
856 
857  gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['slider']),
858  pos = (3, 0), span = (1, 7))
859  gridSizer.Add(item = self.FindWindowById(self.win['vector']['points']['height']['spin']),
860  pos = (3, 7),
861  flag = wx.ALIGN_CENTER)
862 
863  boxSizer.Add(item = gridSizer, proportion = 1,
864  flag = wx.ALL | wx.EXPAND, border = 3)
865  pageSizer.Add(item = boxSizer, proportion = 0,
866  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
867  border = 3)
868 
869  panel.SetSizer(pageSizer)
870 
871  return panel
872 
873  def GselectOnPopup(self, ltype, exclude = False):
874  """Update gselect.Select() items"""
875  maps = list()
876  for layer in self.mapWindow.Map.GetListOfLayers(l_type = ltype):
877  maps.append(layer.GetName())
878  return maps, exclude
879 
880  def _createVolumePage(self):
881  """!Create view settings page"""
882  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
883  panel.SetupScrolling(scroll_x = False)
884  self.page['volume'] = { 'id' : 2,
885  'panel' : panel.GetId(),
886  'notebook' : self.notebookData.GetId() }
887  pageSizer = wx.BoxSizer(wx.VERTICAL)
888 
889  self.win['volume'] = {}
890 
891  # selection
892  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
893  label = " %s " % (_("3D raster map")))
894  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
895  rmaps = gselect.Select(parent = panel, type = 'raster3d',
896  onPopup = self.GselectOnPopup)
897  rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetRaster3D)
898  self.win['volume']['map'] = rmaps.GetId()
899  desc = wx.StaticText(parent = panel, id = wx.ID_ANY)
900  self.win['volume']['desc'] = desc.GetId()
901  boxSizer.Add(item = rmaps, proportion = 0,
902  flag = wx.ALL,
903  border = 3)
904  boxSizer.Add(item = desc, proportion = 0,
905  flag = wx.ALL,
906  border = 3)
907  pageSizer.Add(item = boxSizer, proportion = 0,
908  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
909  border = 3)
910 
911  #
912  # draw
913  #
914  self.win['volume']['draw'] = {}
915  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
916  label = " %s " % (_("Draw")))
917  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
918  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
919  gridSizer.AddGrowableCol(4)
920 
921  # mode
922  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
923  label = _("Mode:")),
924  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
925  mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
926  choices = [_("isosurfaces"),
927  _("slides")])
928  mode.SetSelection(0)
929  mode.SetName("selection")
930  # mode.Bind(wx.EVT_CHOICE, self.OnSurfaceMode)
931  self.win['volume']['draw']['mode'] = mode.GetId()
932  gridSizer.Add(item = mode, flag = wx.ALIGN_CENTER_VERTICAL,
933  pos = (0, 1))
934 
935  # shading
936  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
937  label = _("Shading:")),
938  pos = (0, 2), flag = wx.ALIGN_CENTER_VERTICAL)
939  shade = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
940  choices = [_("flat"),
941  _("gouraud")])
942  shade.SetName("selection")
943  self.win['volume']['draw']['shading'] = shade.GetId()
944  shade.Bind(wx.EVT_CHOICE, self.OnVolumeIsosurfMode)
945  gridSizer.Add(item = shade, flag = wx.ALIGN_CENTER_VERTICAL,
946  pos = (0, 3))
947 
948  # resolution (mode)
949  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
950  label = _("Resolution:")),
951  pos = (0, 4), flag = wx.ALIGN_CENTER_VERTICAL)
952  resol = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
953  initial = 1,
954  min = 1,
955  max = 100)
956  resol.SetName("value")
957  self.win['volume']['draw']['resolution'] = resol.GetId()
958  resol.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfResolution)
959  resol.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfResolution)
960  gridSizer.Add(item = resol, pos = (0, 5))
961 
962  boxSizer.Add(item = gridSizer, proportion = 1,
963  flag = wx.ALL | wx.EXPAND, border = 3)
964  pageSizer.Add(item = boxSizer, proportion = 0,
965  flag = wx.EXPAND | wx.ALL,
966  border = 3)
967 
968  #
969  # manage isosurfaces
970  #
971  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
972  label = " %s " % (_("List of isosurfaces")))
973  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
974  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
975 
976  # list
977  isolevel = wx.CheckListBox(parent = panel, id = wx.ID_ANY,
978  size = (300, 150))
979  self.Bind(wx.EVT_CHECKLISTBOX, self.OnVolumeIsosurfCheck, isolevel)
980  self.Bind(wx.EVT_LISTBOX, self.OnVolumeIsosurfSelect, isolevel)
981 
982  self.win['volume']['isosurfs'] = isolevel.GetId()
983  gridSizer.Add(item = isolevel, pos = (0, 0), span = (4, 1))
984 
985  # buttons (add, delete, move up, move down)
986  btnAdd = wx.Button(parent = panel, id = wx.ID_ADD)
987  self.win['volume']['btnIsosurfAdd'] = btnAdd.GetId()
988  btnAdd.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfAdd)
989  gridSizer.Add(item = btnAdd,
990  pos = (0, 1))
991  btnDelete = wx.Button(parent = panel, id = wx.ID_DELETE)
992  self.win['volume']['btnIsosurfDelete'] = btnDelete.GetId()
993  btnDelete.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfDelete)
994  btnDelete.Enable(False)
995  gridSizer.Add(item = btnDelete,
996  pos = (1, 1))
997  btnMoveUp = wx.Button(parent = panel, id = wx.ID_UP)
998  self.win['volume']['btnIsosurfMoveUp'] = btnMoveUp.GetId()
999  btnMoveUp.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveUp)
1000  btnMoveUp.Enable(False)
1001  gridSizer.Add(item = btnMoveUp,
1002  pos = (2, 1))
1003  btnMoveDown = wx.Button(parent = panel, id = wx.ID_DOWN)
1004  self.win['volume']['btnIsosurfMoveDown'] = btnMoveDown.GetId()
1005  btnMoveDown.Bind(wx.EVT_BUTTON, self.OnVolumeIsosurfMoveDown)
1006  btnMoveDown.Enable(False)
1007  gridSizer.Add(item = btnMoveDown,
1008  pos = (3, 1))
1009 
1010  boxSizer.Add(item = gridSizer, proportion = 1,
1011  flag = wx.ALL | wx.EXPAND, border = 3)
1012  pageSizer.Add(item = boxSizer, proportion = 0,
1013  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1014  border = 3)
1015 
1016  #
1017  # isosurface attributes
1018  #
1019  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1020  label = " %s " % (_("Isosurface attributes")))
1021  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1022  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1023 
1024  self.win['volume']['attr'] = {}
1025  row = 0
1026  for code, attrb in (('topo', _("Topography level")),
1027  ('color', _("Color")),
1028  ('mask', _("Mask")),
1029  ('transp', _("Transparency")),
1030  ('shine', _("Shininess")),
1031  ('emit', _("Emission"))):
1032  self.win['volume'][code] = {}
1033  # label
1034  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
1035  label = attrb + ':'),
1036  pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
1037  if code != 'topo':
1038  use = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
1039  choices = [_("map")])
1040  else:
1041  use = None
1042  # check for required properties
1043  if code not in ('topo', 'color', 'shine'):
1044  use.Insert(item = _("unset"), pos = 0)
1045  self.win['volume'][code]['required'] = False
1046  else:
1047  self.win['volume'][code]['required'] = True
1048  if use and code != 'mask':
1049  use.Append(item = _('constant'))
1050  if use:
1051  self.win['volume'][code]['use'] = use.GetId()
1052  use.Bind(wx.EVT_CHOICE, self.OnMapObjUse)
1053  gridSizer.Add(item = use, flag = wx.ALIGN_CENTER_VERTICAL,
1054  pos = (row, 1))
1055 
1056  if code != 'topo':
1057  map = gselect.Select(parent = panel, id = wx.ID_ANY,
1058  # size = globalvar.DIALOG_GSELECT_SIZE,
1059  size = (200, -1),
1060  type = "grid3")
1061  self.win['volume'][code]['map'] = map.GetId() - 1 # FIXME
1062  map.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
1063  gridSizer.Add(item = map, flag = wx.ALIGN_CENTER_VERTICAL,
1064  pos = (row, 2))
1065  else:
1066  map = None
1067 
1068  if code == 'color':
1069  value = csel.ColourSelect(panel, id = wx.ID_ANY,
1070  colour = (0,0,0),
1071  size = globalvar.DIALOG_COLOR_SIZE)
1072  value.Bind(csel.EVT_COLOURSELECT, self.OnVolumeIsosurfMap)
1073  elif code == 'mask':
1074  value = None
1075  else:
1076  if code == 'topo':
1077  size = (200, -1)
1078  else:
1079  size = (65, -1)
1080  value = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = size,
1081  initial = 0)
1082  if code == 'topo':
1083  value.SetRange(minVal = -1e9, maxVal = 1e9)
1084  elif code in ('shine', 'transp', 'emit'):
1085  value.SetRange(minVal = 0, maxVal = 255)
1086  else:
1087  value.SetRange(minVal = 0, maxVal = 100)
1088  value.Bind(wx.EVT_SPINCTRL, self.OnVolumeIsosurfMap)
1089  value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
1090 
1091  if value:
1092  self.win['volume'][code]['const'] = value.GetId()
1093  if code == 'topo':
1094  gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
1095  pos = (row, 2))
1096  else:
1097  value.Enable(False)
1098  gridSizer.Add(item = value, flag = wx.ALIGN_CENTER_VERTICAL,
1099  pos = (row, 3))
1100  else:
1101  self.win['volume'][code]['const'] = None
1102 
1103  if code != 'topo':
1104  self.SetMapObjUseMap(nvizType = 'volume',
1105  attrb = code) # -> enable map / disable constant
1106 
1107  row += 1
1108 
1109  boxSizer.Add(item = gridSizer, proportion = 1,
1110  flag = wx.ALL | wx.EXPAND, border = 3)
1111  pageSizer.Add(item = boxSizer, proportion = 0,
1112  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1113  border = 3)
1114 
1115  panel.SetSizer(pageSizer)
1116 
1117  return panel
1118 
1119  def _createLightPage(self):
1120  """!Create light page"""
1121  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
1122  panel.SetupScrolling(scroll_x = False)
1123 
1124  self.page['light'] = { 'id' : 0,
1125  'notebook' : self.notebookAppearance.GetId() }
1126  self.win['light'] = {}
1127 
1128  pageSizer = wx.BoxSizer(wx.VERTICAL)
1129 
1130  show = wx.CheckBox(parent = panel, id = wx.ID_ANY,
1131  label = _("Show light model"))
1132  show.Bind(wx.EVT_CHECKBOX, self.OnShowLightModel)
1133  pageSizer.Add(item = show, proportion = 0,
1134  flag = wx.ALL, border = 3)
1135  surface = wx.CheckBox(parent = panel, id = wx.ID_ANY,
1136  label = _("Follow source viewpoint"))
1137  pageSizer.Add(item = surface, proportion = 0,
1138  flag = wx.ALL, border = 3)
1139 
1140  # position
1141  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1142  label = " %s " % (_("Light source position")))
1143  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1144 
1145  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1146  posSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1147  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("W")),
1148  pos = (1, 0), flag = wx.ALIGN_CENTER)
1149  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("N")),
1150  pos = (0, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_BOTTOM)
1151  pos = LightPositionWindow(panel, id = wx.ID_ANY, size = (175, 175),
1152  mapwindow = self.mapWindow)
1153  self.win['light']['position'] = pos.GetId()
1154  posSizer.Add(item = pos,
1155  pos = (1, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)
1156  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("S")),
1157  pos = (2, 1), flag = wx.ALIGN_CENTER | wx.ALIGN_TOP)
1158  posSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("E")),
1159  pos = (1, 2), flag = wx.ALIGN_CENTER)
1160  gridSizer.Add(item = posSizer, pos = (0, 0))
1161 
1162  # height
1163  self._createControl(panel, data = self.win['light'], name = 'z', sliderHor = False,
1164  range = (0, 100),
1165  bind = (self.OnLightChange, None, self.OnLightChange))
1166 
1167  heightSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1168  heightSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Height:")),
1169  pos = (0, 0), flag = wx.ALIGN_LEFT, span = (1, 2))
1170  heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['slider']),
1171  flag = wx.ALIGN_RIGHT, pos = (1, 0))
1172  heightSizer.Add(item = self.FindWindowById(self.win['light']['z']['spin']),
1173  flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT | wx.TOP |
1174  wx.BOTTOM | wx.RIGHT, pos = (1, 1))
1175 
1176  gridSizer.Add(item = heightSizer, pos = (0, 1), flag = wx.ALIGN_RIGHT)
1177 
1178  boxSizer.Add(item = gridSizer, proportion = 1,
1179  flag = wx.ALL | wx.EXPAND, border = 2)
1180  pageSizer.Add(item = boxSizer, proportion = 0,
1181  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1182  border = 3)
1183 
1184  # position
1185  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1186  label = " %s " % (_("Light color and intensity")))
1187  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
1188  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
1189 
1190  gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Color:")),
1191  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
1192  color = csel.ColourSelect(panel, id = wx.ID_ANY,
1193  colour = UserSettings.Get(group = 'nviz', key = 'light',
1194  subkey = 'color'),
1195  size = globalvar.DIALOG_COLOR_SIZE)
1196  self.win['light']['color'] = color.GetId()
1197  color.Bind(csel.EVT_COLOURSELECT, self.OnLightColor)
1198  gridSizer.Add(item = color, pos = (0, 2))
1199 
1200  gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Brightness:")),
1201  pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
1202  self._createControl(panel, data = self.win['light'], name = 'bright', size = 300,
1203  range = (0, 100),
1204  bind = (self.OnLightValue, None, self.OnLightValue))
1205  gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['slider']),
1206  pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL)
1207  gridSizer.Add(item = self.FindWindowById(self.win['light']['bright']['spin']),
1208  pos = (1, 2),
1209  flag = wx.ALIGN_CENTER)
1210  gridSizer.Add(item = wx.StaticText(panel, id = wx.ID_ANY, label = _("Ambient:")),
1211  pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
1212  self._createControl(panel, data = self.win['light'], name = 'ambient', size = 300,
1213  range = (0, 100),
1214  bind = (self.OnLightValue, None, self.OnLightValue))
1215  gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['slider']),
1216  pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL)
1217  gridSizer.Add(item = self.FindWindowById(self.win['light']['ambient']['spin']),
1218  pos = (2, 2),
1219  flag = wx.ALIGN_CENTER)
1220 
1221  boxSizer.Add(item = gridSizer, proportion = 1,
1222  flag = wx.ALL | wx.EXPAND, border = 2)
1223  pageSizer.Add(item = boxSizer, proportion = 0,
1224  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1225  border = 3)
1226 
1227  # reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
1228  # reset.SetToolTipString(_("Reset to default view"))
1229  # # self.win['reset'] = reset.GetId()
1230  # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
1231 
1232  # viewSizer.Add(item = reset, proportion = 1,
1233  # flag = wx.EXPAND | wx.ALL | wx.ALIGN_RIGHT,
1234  # border = 5)
1235 
1236  # gridSizer.AddGrowableCol(3)
1237  # gridSizer.Add(item = viewSizer, pos = (4, 0), span = (1, 2),
1238  # flag = wx.EXPAND)
1239 
1240  panel.SetSizer(pageSizer)
1241 
1242  return panel
1243 
1244  def _createFringePage(self):
1245  """!Create fringe page"""
1246  panel = SP.ScrolledPanel(parent = self, id = wx.ID_ANY)
1247  panel.SetupScrolling(scroll_x = False)
1248 
1249  self.page['fringe'] = { 'id' : 1,
1250  'notebook' : self.notebookAppearance.GetId() }
1251  self.win['fringe'] = {}
1252 
1253  pageSizer = wx.BoxSizer(wx.VERTICAL)
1254 
1255  # selection
1256  rbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1257  label = " %s " % (_("Surface")))
1258  rboxSizer = wx.StaticBoxSizer(rbox, wx.VERTICAL)
1259  rmaps = gselect.Select(parent = panel, type = 'raster',
1260  onPopup = self.GselectOnPopup)
1261  rmaps.GetChildren()[0].Bind(wx.EVT_TEXT, self.OnSetSurface)
1262  self.win['fringe']['map'] = rmaps.GetId()
1263  rboxSizer.Add(item = rmaps, proportion = 0,
1264  flag = wx.ALL,
1265  border = 3)
1266  pageSizer.Add(item = rboxSizer, proportion = 0,
1267  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1268  border = 3)
1269 
1270  ebox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1271  label = " %s " % (_("Edges with fringe")))
1272  eboxSizer = wx.StaticBoxSizer(ebox, wx.HORIZONTAL)
1273  for edge in [(_("N && W"), "nw"),
1274  (_("N && E"), "ne"),
1275  (_("S && W"), "sw"),
1276  (_("S && E"), "se")]:
1277  chkbox = wx.CheckBox(parent = panel,
1278  label = edge[0],
1279  name = edge[1])
1280  self.win['fringe'][edge[1]] = chkbox.GetId()
1281  eboxSizer.Add(item = chkbox, proportion = 0,
1282  flag = wx.ADJUST_MINSIZE | wx.LEFT | wx.RIGHT, border = 5)
1283  chkbox.Bind(wx.EVT_CHECKBOX, self.OnFringe)
1284 
1285  pageSizer.Add(item = eboxSizer, proportion = 0,
1286  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1287  border = 3)
1288 
1289  sbox = wx.StaticBox (parent = panel, id = wx.ID_ANY,
1290  label = " %s " % (_("Settings")))
1291  sboxSizer = wx.StaticBoxSizer(sbox, wx.HORIZONTAL)
1292  gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
1293 
1294  # elevation
1295  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
1296  label = _("Elevation of fringe from bottom:")),
1297  pos = (0, 0),
1298  flag = wx.ALIGN_CENTER_VERTICAL)
1299  spin = wx.SpinCtrl(parent = panel, id = wx.ID_ANY,
1300  size = (65, -1), min = -1e6, max = 1e6)
1301  spin.SetValue(UserSettings.Get(group = 'nviz', key = 'fringe', subkey = 'elev'))
1302  spin.Bind(wx.EVT_SPINCTRL, self.OnFringe)
1303  self.win['fringe']['elev'] = spin.GetId()
1304  gridSizer.Add(item = spin, pos = (0, 1))
1305 
1306  # color
1307  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
1308  label = _("Color:")),
1309  pos = (1, 0),
1310  flag = wx.ALIGN_CENTER_VERTICAL)
1311  color = csel.ColourSelect(parent = panel, id = wx.ID_ANY,
1312  size = globalvar.DIALOG_COLOR_SIZE)
1313  color.SetColour(UserSettings.Get(group = 'nviz', key = 'fringe',
1314  subkey = 'color'))
1315  color.Bind(csel.EVT_COLOURSELECT, self.OnFringe)
1316  self.win['fringe']['color'] = color.GetId()
1317  gridSizer.Add(item = color, pos = (1, 1))
1318 
1319  sboxSizer.Add(item = gridSizer, proportion = 1,
1320  flag = wx.ALL | wx.EXPAND, border = 3)
1321  pageSizer.Add(item = sboxSizer, proportion = 0,
1322  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
1323  border = 3)
1324 
1325  panel.SetSizer(pageSizer)
1326 
1327  return panel
1328 
1329  def GetLayerData(self, nvizType):
1330  """!Get nviz data"""
1331  name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
1332 
1333  if nvizType == 'surface' or nvizType == 'fringe':
1334  return self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
1335  elif nvizType == 'vector':
1336  return self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')
1337  elif nvizType == 'volume':
1338  return self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
1339 
1340  return None
1341 
1342  def OnFringe(self, event):
1343  """!Show/hide fringe"""
1344  enabled = event.IsChecked()
1345  win = self.FindWindowById(event.GetId())
1346 
1347  data = self.GetLayerData('fringe')['surface']
1348 
1349  sid = data['object']['id']
1350  elev = self.FindWindowById(self.win['fringe']['elev']).GetValue()
1351  color = self.FindWindowById(self.win['fringe']['color']).GetValue()
1352 
1353  self._display.SetFringe(sid, color, elev,
1354  self.FindWindowById(self.win['fringe']['nw']).IsChecked(),
1355  self.FindWindowById(self.win['fringe']['ne']).IsChecked(),
1356  self.FindWindowById(self.win['fringe']['sw']).IsChecked(),
1357  self.FindWindowById(self.win['fringe']['se']).IsChecked())
1358  self.mapWindow.Refresh(False)
1359 
1360  def OnScroll(self, event, win, data):
1361  """!Generic scrolling handler"""
1362  winName = self.__GetWindowName(win, event.GetId())
1363  if not winName:
1364  return
1365  data[winName] = event.GetInt()
1366  for w in win[winName].itervalues():
1367  self.FindWindowById(w).SetValue(data[winName])
1368 
1369  event.Skip()
1370 
1371  def _createControl(self, parent, data, name, range, bind = (None, None, None),
1372  sliderHor = True, size = 200):
1373  """!Add control (Slider + SpinCtrl)"""
1374  data[name] = dict()
1375  if sliderHor:
1376  style = wx.SL_HORIZONTAL | wx.SL_AUTOTICKS | \
1377  wx.SL_BOTTOM
1378  sizeW = (size, -1)
1379  else:
1380  style = wx.SL_VERTICAL | wx.SL_AUTOTICKS | \
1381  wx.SL_INVERSE
1382  sizeW = (-1, size)
1383 
1384  slider = wx.Slider(parent = parent, id = wx.ID_ANY,
1385  minValue = range[0],
1386  maxValue = range[1],
1387  style = style,
1388  size = sizeW)
1389  slider.SetName('slider')
1390  if bind[0]:
1391  slider.Bind(wx.EVT_SCROLL, bind[0])
1392 
1393  # slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, bind[1])
1394  if bind[1]:
1395  slider.Bind(wx.EVT_SCROLL_CHANGED, bind[1]) # this only works in MSW
1396  data[name]['slider'] = slider.GetId()
1397 
1398  spin = wx.SpinCtrl(parent = parent, id = wx.ID_ANY, size = (65, -1),
1399  min = range[0],
1400  max = range[1])
1401 
1402  # no 'changed' event ... (FIXME)
1403  spin.SetName('spin')
1404  if bind[2]:
1405  spin.Bind(wx.EVT_SPINCTRL, bind[2])
1406 
1407  data[name]['spin'] = spin.GetId()
1408 
1409  def __GetWindowName(self, data, id):
1410  for name in data.iterkeys():
1411  if type(data[name]) is type({}):
1412  for win in data[name].itervalues():
1413  if win == id:
1414  return name
1415  else:
1416  if data[name] == id:
1417  return name
1418 
1419  return None
1420 
1421  def UpdateSettings(self):
1422  """!Update view from settings values
1423  stored in self.mapWindow.view dictionary"""
1424  for control in ('height',
1425  'persp',
1426  'twist',
1427  'z-exag'):
1428  for win in self.win['view'][control].itervalues():
1429  if control == 'height':
1430  value = UserSettings.Get(group = 'nviz', key = 'view',
1431  subkey = ['height', 'value'], internal = True)
1432  else:
1433  try:
1434  value = self.mapWindow.view[control]['value']
1435  except KeyError:
1436  value = -1
1437 
1438  self.FindWindowById(win).SetValue(value)
1439 
1440  viewWin = self.FindWindowById(self.win['view']['position'])
1441  x, y = viewWin.UpdatePos(self.mapWindow.view['position']['x'],
1442  self.mapWindow.view['position']['y'])
1443  viewWin.Draw(pos = (x, y), scale = True)
1444  viewWin.Refresh(False)
1445 
1446  # bgcolor = self.FindWindowById(self.win['settings']['general']['bgcolor']).GetColour()
1447  # self.OnBgColor(event = bgcolor)
1448  self.Update()
1449 
1450  self.mapWindow.Refresh(eraseBackground = False)
1451  self.mapWindow.render['quick'] = False
1452  self.mapWindow.Refresh(False)
1453 
1454  def OnShowLightModel(self, event):
1455  """!Show light model"""
1456  self._display.showLight = event.IsChecked()
1457  self._display.DrawLightingModel()
1458 
1459  def OnLightChange(self, event):
1460  """!Position of the light changed"""
1461  winName = self.__GetWindowName(self.win['light'], event.GetId())
1462  if not winName:
1463  return
1464 
1465  val = event.GetInt()
1466  self.mapWindow.light['position']['z'] = val
1467  for win in self.win['light'][winName].itervalues():
1468  self.FindWindowById(win).SetValue(val)
1469 
1470  event = wxUpdateLight()
1471  wx.PostEvent(self.mapWindow, event)
1472 
1473  event.Skip()
1474 
1475  def OnLightColor(self, event):
1476  """!Color of the light changed"""
1477  self.mapWindow.light['color'] = event.GetValue()
1478 
1479  event = wxUpdateLight()
1480  wx.PostEvent(self.mapWindow, event)
1481 
1482  event.Skip()
1483 
1484  def OnLightValue(self, event):
1485  """!Light brightness changed"""
1486  data = self.mapWindow.light
1487  self.OnScroll(event, self.win['light'], data)
1488 
1489  event = wxUpdateLight()
1490  wx.PostEvent(self.mapWindow, event)
1491 
1492  event.Skip()
1493 
1494  def OnBgColor(self, event):
1495  """!Background color changed"""
1496  color = event.GetValue()
1497  self.mapWindow.view['background']['color'] = event.GetValue()
1498  color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
1499 
1500  self._display.SetBgColor(str(color))
1501 
1502  if self.mapDisplay.statusbarWin['render'].IsChecked():
1503  self.mapWindow.Refresh(False)
1504 
1505  def OnSetSurface(self, event):
1506  """!Surface selected, currently used for fringes"""
1507  name = event.GetString()
1508  try:
1509  data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
1510  except:
1511  self.EnablePage('fringe', False)
1512  return
1513 
1514  layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
1515  self.EnablePage('fringe', True)
1516 
1517  def OnSetRaster(self, event):
1518  """!Raster map selected, update surface page"""
1519  name = event.GetString()
1520  try:
1521  data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')['surface']
1522  except:
1523  self.EnablePage('surface', False)
1524  return
1525 
1526  layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
1527  self.EnablePage('surface', True)
1528  self.UpdateSurfacePage(layer, data, updateName = False)
1529 
1530  def OnSetVector(self, event):
1531  """!Vector map selected, update properties page"""
1532  name = event.GetString()
1533  try:
1534  data = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'nviz')['vector']
1535  except:
1536  self.EnablePage('vector', False)
1537  return
1538 
1539  layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
1540  self.EnablePage('vector', True)
1541  self.UpdateVectorPage(layer, data, updateName = False)
1542 
1543  def OnSetRaster3D(self, event):
1544  """!3D Raster map selected, update surface page"""
1545  name = event.GetString()
1546  try:
1547  data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')['volume']
1548  except:
1549  self.EnablePage('volume', False)
1550  return
1551 
1552  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
1553  self.EnablePage('volume', True)
1554  self.UpdateVolumePage(layer, data, updateName = False)
1555 
1556  def OnViewChange(self, event):
1557  """!Change view, render in quick mode"""
1558  # find control
1559  winName = self.__GetWindowName(self.win['view'], event.GetId())
1560  if not winName:
1561  return
1562 
1563  if winName == 'height':
1564  view = self.mapWindow.iview # internal
1565  else:
1566  view = self.mapWindow.view
1567 
1568  if winName == 'z-exag' and event.GetInt() >= 0:
1569  self.PostViewEvent(zExag = True)
1570  else:
1571  self.PostViewEvent(zExag = False)
1572 
1573  view[winName]['value'] = event.GetInt()
1574 
1575  for win in self.win['view'][winName].itervalues():
1576  self.FindWindowById(win).SetValue(view[winName]['value'])
1577 
1578  self.mapWindow.render['quick'] = True
1579  self.mapWindow.Refresh(False)
1580 
1581  event.Skip()
1582 
1583  def OnViewChanged(self, event):
1584  """!View changed, render in full resolution"""
1585  self.mapWindow.render['quick'] = False
1586  self.mapWindow.Refresh(False)
1587 
1588  self.UpdateSettings()
1589 
1590  def OnViewChangedSpin(self, event):
1591  """!View changed, render in full resolution"""
1592  self.mapWindow.render['quick'] = False
1593  self.OnViewChange(event)
1594  self.OnViewChanged(None)
1595  self.Update()
1596 
1597  event.Skip()
1598 
1599  def OnResetView(self, event):
1600  """!Reset to default view (view page)"""
1601  self.mapWindow.ResetView()
1602  self.UpdateSettings()
1603  self.mapWindow.Refresh(False)
1604 
1605  def OnLookAt(self, event):
1606  """!Look at (view page)"""
1607  sel = event.GetSelection()
1608  if sel == 0: # top
1609  self.mapWindow.view['position']['x'] = 0.5
1610  self.mapWindow.view['position']['y'] = 0.5
1611  elif sel == 1: # north
1612  self.mapWindow.view['position']['x'] = 0.5
1613  self.mapWindow.view['position']['y'] = 0.0
1614  elif sel == 2: # south
1615  self.mapWindow.view['position']['x'] = 0.5
1616  self.mapWindow.view['position']['y'] = 1.0
1617  elif sel == 3: # east
1618  self.mapWindow.view['position']['x'] = 1.0
1619  self.mapWindow.view['position']['y'] = 0.5
1620  elif sel == 4: # west
1621  self.mapWindow.view['position']['x'] = 0.0
1622  self.mapWindow.view['position']['y'] = 0.5
1623  elif sel == 5: # north-west
1624  self.mapWindow.view['position']['x'] = 0.0
1625  self.mapWindow.view['position']['y'] = 0.0
1626  elif sel == 6: # north-east
1627  self.mapWindow.view['position']['x'] = 1.0
1628  self.mapWindow.view['position']['y'] = 0.0
1629  elif sel == 7: # south-east
1630  self.mapWindow.view['position']['x'] = 1.0
1631  self.mapWindow.view['position']['y'] = 1.0
1632  elif sel == 8: # south-west
1633  self.mapWindow.view['position']['x'] = 0.0
1634  self.mapWindow.view['position']['y'] = 1.0
1635 
1636  self.PostViewEvent(zExag = True)
1637 
1638  self.UpdateSettings()
1639  self.mapWindow.render['quick'] = False
1640  self.mapWindow.Refresh(False)
1641 
1642  def OnClose(self, event):
1643  """!Close button pressed
1644 
1645  Close dialog
1646  """
1647  self.Hide()
1648 
1649  def OnMapObjUse(self, event):
1650  """!Set surface attribute -- use -- map/constant"""
1651  if not self.mapWindow.init:
1652  return
1653 
1654  wx.Yield()
1655 
1656  # find attribute row
1657  attrb = self.__GetWindowName(self.win['surface'], event.GetId())
1658  if not attrb:
1659  attrb = self.__GetWindowName(self.win['volume'], event.GetId())
1660  nvizType = 'volume'
1661  else:
1662  nvizType = 'surface'
1663 
1664  selection = event.GetSelection()
1665  if self.win[nvizType][attrb]['required']: # no 'unset'
1666  selection += 1
1667  if selection == 0: # unset
1668  useMap = None
1669  value = ''
1670  elif selection == 1: # map
1671  useMap = True
1672  value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
1673  elif selection == 2: # constant
1674  useMap = False
1675  if attrb == 'color':
1676  value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
1677  value = self._getColorString(value)
1678  else:
1679  value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
1680 
1681  self.SetMapObjUseMap(nvizType = nvizType,
1682  attrb = attrb, map = useMap)
1683 
1684  name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
1685  if nvizType == 'surface':
1686  data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
1687  data[nvizType]['attribute'][attrb] = { 'map' : useMap,
1688  'value' : str(value),
1689  'update' : None }
1690  else: # volume / isosurface
1691  data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
1692  list = self.FindWindowById(self.win['volume']['isosurfs'])
1693  id = list.GetSelection()
1694  data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
1695  'value' : str(value),
1696  'update' : None }
1697 
1698  # update properties
1699  event = wxUpdateProperties(data = data)
1700  wx.PostEvent(self.mapWindow, event)
1701 
1702  if self.mapDisplay.statusbarWin['render'].IsChecked():
1703  self.mapWindow.Refresh(False)
1704 
1705  def EnablePage(self, name, enabled = True):
1706  """!Enable/disable all widgets on page"""
1707  for key, item in self.win[name].iteritems():
1708  if key == 'map' or key == 'surface':
1709  continue
1710  if type(item) == types.DictType:
1711  for sitem in self.win[name][key].itervalues():
1712  if type(sitem) == types.IntType:
1713  self.FindWindowById(sitem).Enable(enabled)
1714  else:
1715  if type(item) == types.IntType:
1716  self.FindWindowById(item).Enable(enabled)
1717 
1718  def SetMapObjUseMap(self, nvizType, attrb, map = None):
1719  """!Update dialog widgets when attribute type changed"""
1720  if attrb in ('topo', 'color', 'shine'):
1721  incSel = -1 # decrement selection (no 'unset')
1722  else:
1723  incSel = 0
1724 
1725  if map is True: # map
1726  if attrb != 'topo': # changing map topography not allowed
1727  # not sure why, but here must be disabled both ids, should be fixed!
1728  self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(True)
1729  if self.win[nvizType][attrb]['const']:
1730  self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
1731  self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(1 + incSel)
1732  elif map is False: # const
1733  self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
1734  if self.win[nvizType][attrb]['const']:
1735  self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(True)
1736  self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(2 + incSel)
1737  else: # unset
1738  self.FindWindowById(self.win[nvizType][attrb]['map'] + 1).Enable(False)
1739  if self.win[nvizType][attrb]['const']:
1740  self.FindWindowById(self.win[nvizType][attrb]['const']).Enable(False)
1741  self.FindWindowById(self.win[nvizType][attrb]['use']).SetSelection(0)
1742 
1743  def OnSurfaceMap(self, event):
1744  """!Set surface attribute"""
1745  self.SetMapObjAttrb(nvizType = 'surface', winId = event.GetId())
1746 
1747  def SetMapObjAttrb(self, nvizType, winId):
1748  """!Set map object (surface/isosurface) attribute (map/constant)"""
1749  if not self.mapWindow.init:
1750  return
1751 
1752  attrb = self.__GetWindowName(self.win[nvizType], winId)
1753  if not attrb:
1754  return
1755 
1756  if nvizType == 'volume' and attrb == 'topo':
1757  return
1758 
1759  selection = self.FindWindowById(self.win[nvizType][attrb]['use']).GetSelection()
1760  if self.win[nvizType][attrb]['required']:
1761  selection += 1
1762 
1763  if selection == 0: # unset
1764  useMap = None
1765  value = ''
1766  elif selection == 1: # map
1767  value = self.FindWindowById(self.win[nvizType][attrb]['map']).GetValue()
1768  useMap = True
1769  else: # constant
1770  if attrb == 'color':
1771  value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetColour()
1772  # tuple to string
1773  value = self._getColorString(value)
1774  else:
1775  value = self.FindWindowById(self.win[nvizType][attrb]['const']).GetValue()
1776  useMap = False
1777 
1778  if not self.pageChanging:
1779  name = self.FindWindowById(self.win[nvizType]['map']).GetValue()
1780  if nvizType == 'surface':
1781  data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
1782  data[nvizType]['attribute'][attrb] = { 'map' : useMap,
1783  'value' : str(value),
1784  'update' : None }
1785  else:
1786  data = self.mapWindow.GetLayerByName(name, mapType = '3d-raster', dataType = 'nviz')
1787  list = self.FindWindowById(self.win['volume']['isosurfs'])
1788  id = list.GetSelection()
1789  if id > -1:
1790  data[nvizType]['isosurface'][id][attrb] = { 'map' : useMap,
1791  'value' : str(value),
1792  'update' : None }
1793 
1794  # update properties
1795  event = wxUpdateProperties(data = data)
1796  wx.PostEvent(self.mapWindow, event)
1797 
1798  if self.mapDisplay.statusbarWin['render'].IsChecked():
1799  self.mapWindow.Refresh(False)
1800 
1801  def OnSurfaceResolution(self, event):
1802  """!Draw resolution changed"""
1803  self.SetSurfaceResolution()
1804 
1805  if self.mapDisplay.statusbarWin['render'].IsChecked():
1806  self.mapWindow.Refresh(False)
1807 
1809  """!Set draw resolution"""
1810  coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
1811  fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
1812 
1813  data = self.GetLayerData('surface')
1814  data['surface']['draw']['resolution'] = { 'coarse' : coarse,
1815  'fine' : fine,
1816  'update' : None }
1817 
1818  # update properties
1819  event = wxUpdateProperties(data = data)
1820  wx.PostEvent(self.mapWindow, event)
1821 
1822  def SetSurfaceMode(self):
1823  """!Set draw mode"""
1824  mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
1825  if mode == 0: # coarse
1826  self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
1827  self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(False)
1828  elif mode == 1: # fine
1829  self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(False)
1830  self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
1831  else: # both
1832  self.FindWindowById(self.win['surface']['draw']['res-coarse']).Enable(True)
1833  self.FindWindowById(self.win['surface']['draw']['res-fine']).Enable(True)
1834 
1835  style = self.FindWindowById(self.win['surface']['draw']['style']).GetSelection()
1836 
1837  shade = self.FindWindowById(self.win['surface']['draw']['shading']).GetSelection()
1838 
1839  value, desc = self.mapWindow.nvizDefault.GetDrawMode(mode, style, shade)
1840 
1841  return value, desc
1842 
1843  def OnSurfaceMode(self, event):
1844  """!Set draw mode"""
1845  value, desc = self.SetSurfaceMode()
1846 
1847  data = self.GetLayerData('surface')
1848  data['surface']['draw']['mode'] = { 'value' : value,
1849  'desc' : desc,
1850  'update' : None }
1851 
1852  # update properties
1853  event = wxUpdateProperties(data = data)
1854  wx.PostEvent(self.mapWindow, event)
1855 
1856  if self.mapDisplay.statusbarWin['render'].IsChecked():
1857  self.mapWindow.Refresh(False)
1858 
1859  def OnSurfaceModeAll(self, event):
1860  """!Set draw mode (including wire color) for all loaded surfaces"""
1861  value, desc = self.SetSurfaceMode()
1862  coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
1863  fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
1864  color = self.FindWindowById(self.win['surface']['draw']['wire-color']).GetColour()
1865  cvalue = self._getColorString(color)
1866 
1867  for name in self.mapWindow.GetLayerNames(type = 'raster'):
1868 
1869  data = self.mapWindow.GetLayerByName(name, mapType = 'raster', dataType = 'nviz')
1870  if not data:
1871  continue # shouldy no happen
1872 
1873  data['surface']['draw']['all'] = True
1874  data['surface']['draw']['mode'] = { 'value' : value,
1875  'desc' : desc,
1876  'update' : None }
1877  data['surface']['draw']['resolution'] = { 'coarse' : coarse,
1878  'fine' : fine,
1879  'update' : None }
1880  data['surface']['draw']['wire-color'] = { 'value' : cvalue,
1881  'update' : None }
1882 
1883  # update properties
1884  event = wxUpdateProperties(data = data)
1885  wx.PostEvent(self.mapWindow, event)
1886 
1887  if self.mapDisplay.statusbarWin['render'].IsChecked():
1888  self.mapWindow.Refresh(False)
1889 
1890  def _getColorString(self, color):
1891  """!Set wire color"""
1892  return str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
1893 
1894  def OnSurfaceWireColor(self, event):
1895  """!Set wire color"""
1896  data = self.GetLayerData('surface')
1897  value = self._getColorString(event.GetValue())
1898  data['surface']['draw']['wire-color'] = { 'value' : value,
1899  'update' : None }
1900 
1901  # update properties
1902  event = wxUpdateProperties(data = data)
1903  wx.PostEvent(self.mapWindow, event)
1904 
1905  if self.mapDisplay.statusbarWin['render'].IsChecked():
1906  self.mapWindow.Refresh(False)
1907 
1908  def OnSurfaceAxis(self, event):
1909  """!Surface position, axis changed"""
1910  data = self.GetLayerData('surface')
1911  id = data['surface']['object']['id']
1912 
1913  axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
1914  slider = self.FindWindowById(self.win['surface']['position']['slider'])
1915  spin = self.FindWindowById(self.win['surface']['position']['spin'])
1916 
1917  x, y, z = self._display.GetSurfacePosition(id)
1918 
1919  if axis == 0: # x
1920  slider.SetValue(x)
1921  spin.SetValue(x)
1922  elif axis == 1: # y
1923  slider.SetValue(y)
1924  spin.SetValue(y)
1925  else: # z
1926  slider.SetValue(z)
1927  spin.SetValue(z)
1928 
1929  def OnSurfacePosition(self, event):
1930  """!Surface position"""
1931  winName = self.__GetWindowName(self.win['surface'], event.GetId())
1932  if not winName:
1933  return
1934  axis = self.FindWindowById(self.win['surface']['position']['axis']).GetSelection()
1935  value = event.GetInt()
1936 
1937  for win in self.win['surface']['position'].itervalues():
1938  if win == self.win['surface']['position']['axis']:
1939  continue
1940  else:
1941  self.FindWindowById(win).SetValue(value)
1942 
1943  data = self.GetLayerData('surface')
1944  id = data['surface']['object']['id']
1945  x, y, z = self._display.GetSurfacePosition(id)
1946 
1947  if axis == 0: # x
1948  x = value
1949  elif axis == 1: # y
1950  y = value
1951  else: # z
1952  z = value
1953 
1954  data = self.GetLayerData('surface')
1955  data['surface']['position']['x'] = x
1956  data['surface']['position']['y'] = y
1957  data['surface']['position']['z'] = z
1958  data['surface']['position']['update'] = None
1959  # update properties
1960  event = wxUpdateProperties(data = data)
1961  wx.PostEvent(self.mapWindow, event)
1962 
1963  if self.mapDisplay.statusbarWin['render'].IsChecked():
1964  self.mapWindow.Refresh(False)
1965  # self.UpdatePage('surface')
1966 
1967  def UpdateVectorShow(self, vecType, enabled):
1968  """!Enable/disable lines/points widgets
1969 
1970  @param vecType vector type (lines, points)
1971  """
1972  if vecType != 'lines' and vecType != 'points':
1973  return False
1974 
1975  for win in self.win['vector'][vecType].keys():
1976  if win == 'show':
1977  continue
1978  if type(self.win['vector'][vecType][win]) == type({}):
1979  for swin in self.win['vector'][vecType][win].keys():
1980  if enabled:
1981  self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(True)
1982  else:
1983  self.FindWindowById(self.win['vector'][vecType][win][swin]).Enable(False)
1984  else:
1985  if enabled:
1986  self.FindWindowById(self.win['vector'][vecType][win]).Enable(True)
1987  else:
1988  self.FindWindowById(self.win['vector'][vecType][win]).Enable(False)
1989 
1990  return True
1991 
1992  def OnVectorShow(self, event):
1993  """!Show vector lines/points"""
1994  winId = event.GetId()
1995  if winId == self.win['vector']['lines']['show']:
1996  vecType = 'lines'
1997  points = False
1998  else: # points
1999  vecType = 'points'
2000  points = True
2001 
2002  checked = event.IsChecked()
2003  name = self.FindWindowById(self.win['vector']['map']).GetValue()
2004  item = self.mapWindow.GetLayerByName(name, mapType = 'vector', dataType = 'item')
2005  data = self.GetLayerData('vector')['vector']
2006 
2007  if checked:
2008  self.mapWindow.LoadVector(item, points = points)
2009  else:
2010  self.mapWindow.UnloadVector(item, points = points)
2011 
2012  self.UpdateVectorShow(vecType, checked)
2013 
2014  if checked:
2015  try:
2016  id = data[vecType]['object']['id']
2017  except KeyError:
2018  id = -1
2019 
2020  if id > 0:
2021  self.mapWindow.SetMapObjProperties(item, id, vecType)
2022 
2023  # update properties
2024  event = wxUpdateProperties(data = data)
2025  wx.PostEvent(self.mapWindow, event)
2026 
2027  if self.mapDisplay.statusbarWin['render'].IsChecked():
2028  self.mapWindow.Refresh(False)
2029 
2030  event.Skip()
2031 
2032  def OnVectorDisplay(self, event):
2033  """!Display vector lines on surface/flat"""
2034  rasters = self.mapWindow.GetLayerNames('raster')
2035  if event.GetSelection() == 0: # surface
2036  if len(rasters) < 1:
2037  self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
2038  self.FindWindowById(self.win['vector']['lines']['flat']).SetSelection(1)
2039  return
2040 
2041  self.FindWindowById(self.win['vector']['lines']['surface']).Enable(True)
2042  # set first found surface
2043  data = self.GetLayerData('vector')
2044  data['vector']['lines']['mode']['surface'] = rasters[0]
2045  self.FindWindowById(self.win['vector']['lines']['surface']).SetStringSelection( \
2046  rasters[0])
2047  else: # flat
2048  self.FindWindowById(self.win['vector']['lines']['surface']).Enable(False)
2049 
2050  self.OnVectorLines(event)
2051 
2052  event.Skip()
2053 
2054  def OnVectorLines(self, event):
2055  """!Set vector lines mode, apply changes if auto-rendering is enabled"""
2056  data = self.GetLayerData('vector')
2057  width = self.FindWindowById(self.win['vector']['lines']['width']).GetValue()
2058 
2059  mode = {}
2060  if self.FindWindowById(self.win['vector']['lines']['flat']).GetSelection() == 0:
2061  mode['type'] = 'surface'
2062  mode['surface'] = self.FindWindowById(self.win['vector']['lines']['surface']).GetValue()
2063  mode['update'] = None
2064  else:
2065  mode['type'] = 'flat'
2066 
2067  for attrb in ('width', 'mode'):
2068  data['vector']['lines'][attrb]['update'] = None
2069  data['vector']['lines']['width']['value'] = width
2070  data['vector']['lines']['mode']['value'] = mode
2071 
2072  color = self.FindWindowById(self.win['vector']['lines']['color']).GetColour()
2073 
2074  if isinstance(color, csel.ColourSelect):
2075  pass #color picker not yet instantiated
2076  else:
2077  color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
2078  data['vector']['lines']['color']['update'] = None
2079  data['vector']['lines']['color']['value'] = color
2080 
2081  # update properties
2082  event = wxUpdateProperties(data = data)
2083  wx.PostEvent(self.mapWindow, event)
2084 
2085  if self.mapDisplay.statusbarWin['render'].IsChecked():
2086  self.mapWindow.Refresh(False)
2087 
2088  def OnVectorHeight(self, event):
2089  value = event.GetInt()
2090  id = event.GetId()
2091  if id == self.win['vector']['lines']['height']['spin'] or \
2092  id == self.win['vector']['lines']['height']['slider']:
2093  vtype = 'lines'
2094  else:
2095  vtype = 'points'
2096 
2097  if type(event) == type(wx.ScrollEvent()):
2098  # slider
2099  win = self.FindWindowById(self.win['vector'][vtype]['height']['spin'])
2100  else:
2101  # spin
2102  win = self.FindWindowById(self.win['vector'][vtype]['height']['slider'])
2103  win.SetValue(value)
2104 
2105  data = self.GetLayerData('vector')['vector'][vtype]
2106  data['height'] = { 'value' : value,
2107  'update' : None }
2108 
2109  # update properties
2110  event = wxUpdateProperties(data = data)
2111  wx.PostEvent(self.mapWindow, event)
2112 
2113  self.mapWindow.render['quick'] = True
2114  self.mapWindow.render['v' + vtype] = True
2115  self.mapWindow.Refresh(False)
2116 
2117  event.Skip()
2118 
2119  def OnVectorHeightFull(self, event):
2120  """!Vector height changed, render in full resolution"""
2121  self.OnVectorHeight(event)
2122  self.OnVectorSurface(event)
2123  id = event.GetId()
2124  if id == self.win['vector']['lines']['height']['spin'] or \
2125  id == self.win['vector']['lines']['height']['slider']:
2126  vtype = 'lines'
2127  else:
2128  vtype = 'points'
2129 
2130  self.mapWindow.render['quick'] = False
2131  self.mapWindow.render['v' + vtype] = False
2132  self.mapWindow.Refresh(False)
2133 
2134  def OnVectorHeightSpin(self, event):
2135  """!Vector height changed, render in full resolution"""
2136  # TODO: use step value instead
2137 
2138  # self.OnVectorHeight(event)
2139  self.OnVectorHeightFull(event)
2140 
2141  def OnVectorSurface(self, event):
2142  """!Reference surface for vector map (lines/points)"""
2143  id = event.GetId()
2144  if id == self.win['vector']['lines']['surface']:
2145  vtype = 'lines'
2146  else:
2147  vtype = 'points'
2148  data = self.GetLayerData('vector')
2149  data['vector'][vtype]['mode']['surface'] = { 'value' : event.GetString(),
2150  'update' : None }
2151 
2152  # update properties
2153  event = wxUpdateProperties(data = data)
2154  wx.PostEvent(self.mapWindow, event)
2155 
2156  if self.mapDisplay.statusbarWin['render'].IsChecked():
2157  self.mapWindow.Refresh(False)
2158 
2159  def OnVectorPoints(self, event):
2160  """!Set vector points mode, apply changes if auto-rendering is enabled"""
2161  data = self.GetLayerData('vector')
2162 
2163  size = self.FindWindowById(self.win['vector']['points']['size']).GetValue()
2164  marker = self.FindWindowById(self.win['vector']['points']['marker']).GetSelection()
2165  # width = self.FindWindowById(self.win['vector']['points']['width']).GetValue()
2166 
2167  for attrb in ('size', 'marker'):
2168  data['vector']['points'][attrb]['update'] = None
2169  data['vector']['points']['size']['value'] = size
2170  # data['vector']['points']['width']['value'] = width
2171  data['vector']['points']['marker']['value'] = marker
2172 
2173  color = self.FindWindowById(self.win['vector']['points']['color']).GetColour()
2174  if isinstance(color, csel.ColourSelect):
2175  pass #color picker not yet instantiated
2176  else:
2177  color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
2178  data['vector']['points']['color']['update'] = None
2179  data['vector']['points']['color']['value'] = color
2180 
2181  # update properties
2182  event = wxUpdateProperties(data = data)
2183  wx.PostEvent(self.mapWindow, event)
2184 
2185  if self.mapDisplay.statusbarWin['render'].IsChecked():
2186  self.mapWindow.Refresh(False)
2187 
2188  def UpdateIsosurfButtons(self, list):
2189  """!Enable/disable buttons 'add', 'delete',
2190  'move up', 'move down'"""
2191  nitems = list.GetCount()
2192  add = self.parent.FindWindowById(self.win['volume']['btnIsosurfAdd'])
2193  delete = self.parent.FindWindowById(self.win['volume']['btnIsosurfDelete'])
2194  moveDown = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
2195  moveUp = self.parent.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
2196  if nitems >= wxnviz.MAX_ISOSURFS:
2197  # disable add button on max
2198  add.Enable(False)
2199  else:
2200  add.Enable(True)
2201 
2202  if nitems < 1:
2203  # disable 'delete' if only one item in the lis
2204  delete.Enable(False)
2205  else:
2206  delete.Enable(True)
2207 
2208  if list.GetSelection() >= nitems - 1:
2209  # disable 'move-down' if last
2210  moveDown.Enable(False)
2211  else:
2212  moveDown.Enable(True)
2213 
2214  if list.GetSelection() < 1:
2215  # disable 'move-up' if first
2216  moveUp.Enable(False)
2217  else:
2218  moveUp.Enable(True)
2219 
2220  def OnVolumeIsosurfMode(self, event):
2221  """!Set isosurface draw mode"""
2222  self.SetIsosurfaceMode(event.GetSelection())
2223 
2224  def SetIsosurfaceMode(self, selection):
2225  """!Set isosurface draw mode"""
2226  data = self.GetLayerData('volume')['volume']
2227  id = data['object']['id']
2228 
2229  mode = 0
2230  if selection == 0:
2231  mode |= wxnviz.DM_FLAT
2232  else:
2233  mode |= wxnviz.DM_GOURAUD
2234 
2235  self._display.SetIsosurfaceMode(id, mode)
2236 
2237  if self.mapDisplay.statusbarWin['render'].IsChecked():
2238  self.mapWindow.Refresh(False)
2239 
2240  def OnVolumeIsosurfResolution(self, event):
2241  """!Set isosurface draw resolution"""
2242  self.SetIsosurfaceResolution(event.GetInt())
2243 
2244  def SetIsosurfaceResolution(self, res):
2245  """!Set isosurface draw resolution"""
2246  data = self.GetLayerData('volume')['volume']
2247 
2248  id = data['object']['id']
2249  self._display.SetIsosurfaceRes(id, res)
2250 
2251  if self.mapDisplay.statusbarWin['render'].IsChecked():
2252  self.mapWindow.Refresh(False)
2253 
2254  def OnVolumeIsosurfMap(self, event):
2255  """!Set surface attribute"""
2256  self.SetMapObjAttrb(nvizType = 'volume', winId = event.GetId())
2257 
2258  def OnVolumeIsosurfCheck(self, event):
2259  """!Isosurface checked (->load) or unchecked (->unload)"""
2260  index = event.GetSelection()
2261  list = self.FindWindowById(self.win['volume']['isosurfs'])
2262 
2263  data = self.GetLayerData('volume')['volume']
2264  id = data['object']['id']
2265 
2266  isosurfId = event.GetSelection()
2267 
2268  if list.IsChecked(index):
2269  self._display.SetIsosurfaceTransp(id, isosurfId, False, "0")
2270  else:
2271  # disable -> make transparent
2272  self._display.SetIsosurfaceTransp(id, isosurfId, False, "255")
2273 
2274  if self.mapDisplay.statusbarWin['render'].IsChecked():
2275  self.mapWindow.Refresh(False)
2276 
2277  def OnVolumeIsosurfSelect(self, event):
2278  """!Isosurface item selected"""
2279  winUp = self.FindWindowById(self.win['volume']['btnIsosurfMoveUp'])
2280  winDown = self.FindWindowById(self.win['volume']['btnIsosurfMoveDown'])
2281  selection = event.GetSelection()
2282  if selection == 0:
2283  winUp.Enable(False)
2284  if not winDown.IsEnabled():
2285  winDown.Enable()
2286  elif selection == self.FindWindowById(event.GetId()).GetCount() - 1:
2287  winDown.Enable(False)
2288  if not winUp.IsEnabled():
2289  winUp.Enable()
2290  else:
2291  if not winDown.IsEnabled():
2292  winDown.Enable()
2293  if not winUp.IsEnabled():
2294  winUp.Enable()
2295 
2296  # update dialog
2297  name = self.FindWindowById(self.win['volume']['map']).GetValue()
2298  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2299  data = self.GetLayerData('volume')['volume']['isosurface'][selection]
2300 
2301  self.UpdateVolumeIsosurfPage(layer, data)
2302 
2303  def OnVolumeIsosurfAdd(self, event):
2304  """!Add new isosurface to the list"""
2305  list = self.FindWindowById(self.win['volume']['isosurfs'])
2306  level = self.FindWindowById(self.win['volume']['topo']['const']).GetValue()
2307 
2308  sel = list.GetSelection()
2309  if sel < 0 or sel >= list.GetCount() - 1:
2310  item = list.Append(item = "%s %s" % (_("Level"), str(level)))
2311  else:
2312  list.Insert(item = "%s %s" % (_("Level"), str(level)),
2313  pos = sel+1) # append
2314  item = sel + 1
2315 
2316  list.Check(item)
2317  list.SetSelection(item)
2318 
2319  name = self.FindWindowById(self.win['volume']['map']).GetValue()
2320  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2321  data = self.GetLayerData('volume')['volume']
2322  id = data['object']['id']
2323 
2324  # collect properties
2325  isosurfData = {}
2326  for attrb in ('topo', 'color', 'mask',
2327  'transp', 'shine', 'emit'):
2328  if attrb == 'topo':
2329  isosurfData[attrb] = {}
2330  win = self.FindWindowById(self.win['volume'][attrb]['const'])
2331  isosurfData[attrb]['value'] = win.GetValue()
2332  else:
2333  uwin = self.FindWindowById(self.win['volume'][attrb]['use'])
2334  sel = uwin.GetSelection()
2335  if self.win['volume'][attrb]['required']:
2336  sel += 1
2337  if sel == 0: # unset
2338  continue
2339 
2340  isosurfData[attrb] = {}
2341  if sel == 1: # map
2342  isosurfData[attrb]['map'] = True
2343  vwin = self.FindWindowById(self.win['volume'][attrb]['map'])
2344  value = vwin.GetValue()
2345  else: # const
2346  isosurfData[attrb]['map'] = False
2347  vwin = self.FindWindowById(self.win['volume'][attrb]['const'])
2348  if vwin.GetName() == "color":
2349  value = self._getColorString(vwin.GetValue())
2350  else:
2351  value = vwin.GetValue()
2352  isosurfData[attrb]['value'] = value
2353 
2354  data['isosurface'].insert(item, isosurfData)
2355 
2356  # add isosurface
2357  self._display.AddIsosurface(id, level)
2358  # use by default 3d raster map for color
2359  self._display.SetIsosurfaceColor(id, item, True, str(layer.name))
2360 
2361  # update buttons
2362  self.UpdateIsosurfButtons(list)
2363 
2364  if self.mapDisplay.statusbarWin['render'].IsChecked():
2365  self.mapWindow.Refresh(False)
2366 
2367  event.Skip()
2368 
2369  def OnVolumeIsosurfDelete(self, event):
2370  """!Remove isosurface from list"""
2371  list = self.FindWindowById(self.win['volume']['isosurfs'])
2372 
2373  # remove item from list
2374  isosurfId = list.GetSelection()
2375  list.Delete(isosurfId)
2376  # select last item
2377  if list.GetCount() > 0:
2378  list.SetSelection(list.GetCount()-1)
2379 
2380  name = self.FindWindowById(self.win['volume']['map']).GetValue()
2381  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2382  data = self.GetLayerData('volume')['volume']
2383 
2384  id = data['object']['id']
2385 
2386  # delete isosurface
2387  del data['isosurface'][isosurfId]
2388 
2389  self._display.DeleteIsosurface(id, isosurfId)
2390 
2391  # update buttons
2392  self.UpdateIsosurfButtons(list)
2393 
2394  if self.mapDisplay.statusbarWin['render'].IsChecked():
2395  self.mapWindow.Refresh(False)
2396 
2397  event.Skip()
2398 
2399  def OnVolumeIsosurfMoveUp(self, event):
2400  """!Move isosurface up in the list"""
2401  list = self.FindWindowById(self.win['volume']['isosurfs'])
2402  sel = list.GetSelection()
2403 
2404  if sel < 1:
2405  return # this should not happen
2406 
2407  name = self.FindWindowById(self.win['volume']['map']).GetValue()
2408  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2409  data = self.GetLayerData('volume')['volume']
2410 
2411  id = data['object']['id']
2412 
2413  # move item up
2414  text = list.GetStringSelection()
2415  list.Insert(item = text, pos = sel-1)
2416  list.Check(sel-1)
2417  list.SetSelection(sel-1)
2418  list.Delete(sel+1)
2419  data['isosurface'].insert(sel-1, data['isosurface'][sel])
2420  del data['isosurface'][sel+1]
2421  self._display.MoveIsosurface(id, sel, True)
2422 
2423  # update buttons
2424  self.UpdateIsosurfButtons(list)
2425 
2426  if self.mapDisplay.statusbarWin['render'].IsChecked():
2427  self.mapWindow.Refresh(False)
2428 
2429  event.Skip()
2430 
2431  def OnVolumeIsosurfMoveDown(self, event):
2432  """!Move isosurface dowm in the list"""
2433  list = self.FindWindowById(self.win['volume']['isosurfs'])
2434  sel = list.GetSelection()
2435 
2436  if sel >= list.GetCount() - 1:
2437  return # this should not happen
2438 
2439  name = self.FindWindowById(self.win['volume']['map']).GetValue()
2440  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2441  data = self.GetLayerData('volume')['volume']
2442 
2443  id = data['object']['id']
2444 
2445  # move item up
2446  text = list.GetStringSelection()
2447  list.Insert(item = text, pos = sel+2)
2448  list.Check(sel+2)
2449  list.SetSelection(sel+2)
2450  list.Delete(sel)
2451  data['isosurface'].insert(sel+2, data['isosurface'][sel])
2452  del data['isosurface'][sel]
2453  self._display.MoveIsosurface(id, sel, False)
2454 
2455  # update buttons
2456  self.UpdateIsosurfButtons(list)
2457 
2458  if self.mapDisplay.statusbarWin['render'].IsChecked():
2459  self.mapWindow.Refresh(False)
2460 
2461  event.Skip()
2462 
2463  def UpdatePage(self, pageId):
2464  """!Update dialog (selected page)"""
2465  self.pageChanging = True
2466  Debug.msg(1, "NvizToolWindow.UpdatePage(): %s", pageId)
2467 
2468  if pageId == 'view':
2469  self.SetPage('view')
2470  hmin = self.mapWindow.iview['height']['min']
2471  hmax = self.mapWindow.iview['height']['max']
2472  hval = self.mapWindow.iview['height']['value']
2473  zmin = self.mapWindow.view['z-exag']['min']
2474  zmax = self.mapWindow.view['z-exag']['max']
2475  zval = self.mapWindow.view['z-exag']['value']
2476 
2477  for control in ('spin', 'slider'):
2478  self.FindWindowById(self.win['view']['height'][control]).SetRange(hmin,
2479  hmax)
2480  self.FindWindowById(self.win['view']['height'][control]).SetValue(hval)
2481  self.FindWindowById(self.win['view']['z-exag'][control]).SetRange(zmin,
2482  zmax)
2483  self.FindWindowById(self.win['view']['z-exag'][control]).SetValue(zval)
2484 
2485  self.FindWindowById(self.win['view']['bgcolor']).SetColour(\
2486  self.mapWindow.view['background']['color'])
2487 
2488  elif pageId in ('surface', 'vector', 'volume'):
2489  name = self.FindWindowById(self.win[pageId]['map']).GetValue()
2490  data = self.GetLayerData(pageId)
2491  if data:
2492  if pageId == 'surface':
2493  layer = self.mapWindow.GetLayerByName(name, mapType = 'raster')
2494  self.UpdateSurfacePage(layer, data['surface'])
2495  elif pageId == 'vector':
2496  layer = self.mapWindow.GetLayerByName(name, mapType = 'vector')
2497  self.UpdateVectorPage(layer, data['vector'])
2498  elif pageId == 'volume':
2499  layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
2500  self.UpdateVectorPage(layer, data['vector'])
2501  elif pageId == 'light':
2502  zval = self.mapWindow.light['position']['z']
2503  bval = self.mapWindow.light['bright']
2504  aval = self.mapWindow.light['ambient']
2505  for control in ('spin', 'slider'):
2506  self.FindWindowById(self.win['light']['z'][control]).SetValue(zval)
2507  self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
2508  self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
2509  self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
2510  elif pageId == 'fringe':
2511  win = self.FindWindowById(self.win['fringe']['map'])
2512  win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
2513 
2514  self.Update()
2515  self.pageChanging = False
2516 
2517  def UpdateSurfacePage(self, layer, data, updateName = True):
2518  """!Update surface page"""
2519  ret = gcmd.RunCommand('r.info',
2520  read = True,
2521  flags = 'm',
2522  map = layer.name)
2523  if ret:
2524  desc = ret.split('=')[1].rstrip('\n')
2525  else:
2526  desc = None
2527  if updateName:
2528  self.FindWindowById(self.win['surface']['map']).SetValue(layer.name)
2529  self.FindWindowById(self.win['surface']['desc']).SetLabel(desc)
2530 
2531  # attributes
2532  for attr in ('topo', 'color'): # required
2533  if layer and layer.type == 'raster':
2534  self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
2535  else:
2536  self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
2537  self.SetMapObjUseMap(nvizType = 'surface',
2538  attrb = attr, map = True) # -> map
2539 
2540  if 'color' in data['attribute']:
2541  value = data['attribute']['color']['value']
2542  if data['attribute']['color']['map']:
2543  self.FindWindowById(self.win['surface']['color']['map']).SetValue(value)
2544  else: # constant
2545  color = map(int, value.split(':'))
2546  self.FindWindowById(self.win['surface']['color']['const']).SetColour(color)
2547  self.SetMapObjUseMap(nvizType = 'surface',
2548  attrb = attr, map = data['attribute']['color']['map'])
2549 
2550  self.SetMapObjUseMap(nvizType = 'surface',
2551  attrb = 'shine', map = data['attribute']['shine']['map'])
2552  value = data['attribute']['shine']['value']
2553  if data['attribute']['shine']['map']:
2554  self.FindWindowById(self.win['surface']['shine']['map']).SetValue(value)
2555  else:
2556  self.FindWindowById(self.win['surface']['shine']['const']).SetValue(value)
2557 
2558  #
2559  # draw
2560  #
2561  for control, data in data['draw'].iteritems():
2562  if control == 'all': # skip 'all' property
2563  continue
2564  if control == 'resolution':
2565  self.FindWindowById(self.win['surface']['draw']['res-coarse']).SetValue(data['coarse'])
2566  self.FindWindowById(self.win['surface']['draw']['res-fine']).SetValue(data['fine'])
2567  continue
2568 
2569  if control == 'mode':
2570  if data['desc']['mode'] == 'coarse':
2571  self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(0)
2572  elif data['desc']['mode'] == 'fine':
2573  self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(1)
2574  else: # both
2575  self.FindWindowById(self.win['surface']['draw']['mode']).SetSelection(2)
2576 
2577  if data['desc']['style'] == 'wire':
2578  self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(0)
2579  else: # surface
2580  self.FindWindowById(self.win['surface']['draw']['style']).SetSelection(1)
2581 
2582  if data['desc']['shading'] == 'flat':
2583  self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(0)
2584  else: # gouraud
2585  self.FindWindowById(self.win['surface']['draw']['shading']).SetSelection(1)
2586 
2587  continue
2588 
2589  value = data['value']
2590  win = self.FindWindowById(self.win['surface']['draw'][control])
2591 
2592  name = win.GetName()
2593 
2594  if name == "selection":
2595  win.SetSelection(value)
2596  elif name == "colour":
2597  color = map(int, value.split(':'))
2598  win.SetColour(color)
2599  else:
2600  win.SetValue(value)
2601  # enable/disable res widget + set draw mode
2602  self.OnSurfaceMode(event = None)
2603 
2604  def VectorInfo(self, layer):
2605  """!Get number of points/lines
2606 
2607  @param layer MapLayer instance
2608 
2609  @return num of points/features (expect of points)
2610  @return None
2611  """
2612  vInfo = grass.vector_info_topo(layer.GetName())
2613 
2614  if not vInfo:
2615  return None
2616 
2617  nprimitives = 0
2618  for key, value in vInfo.iteritems():
2619  if key in ('points',
2620  'lines',
2621  'boundaries',
2622  'centroids',
2623  'faces',
2624  'kernels'):
2625  nprimitives += value
2626 
2627  return (vInfo['points'], vInfo['lines'], nprimitives, vInfo['map3d'])
2628 
2629  def UpdateVectorPage(self, layer, data, updateName = True):
2630  """!Update vector page"""
2631  npoints, nlines, nfeatures, mapIs3D = self.VectorInfo(layer)
2632  if mapIs3D:
2633  desc = _("Vector map is 3D")
2634  enable = False
2635  else:
2636  desc = _("Vector map is 2D")
2637  enable = True
2638  desc += " - " + _("%(features)d features (%(points)d points)") % \
2639  { 'features' : nfeatures, 'points' : npoints }
2640 
2641  if updateName:
2642  self.FindWindowById(self.win['vector']['map']).SetValue(layer.name)
2643  self.FindWindowById(self.win['vector']['desc']).SetLabel(desc)
2644 
2645  self.FindWindowById(self.win['vector']['lines']['flat']).Enable(enable)
2646  for v in ('lines', 'points'):
2647  self.FindWindowById(self.win['vector'][v]['surface']).Enable(enable)
2648  self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
2649  self.FindWindowById(self.win['vector'][v]['height']['spin']).Enable(enable)
2650 
2651  #
2652  # lines
2653  #
2654  showLines = self.FindWindowById(self.win['vector']['lines']['show'])
2655  if 'object' in data['lines']:
2656  showLines.SetValue(True)
2657  else:
2658  showLines.SetValue(False)
2659  if nlines > 0:
2660  showLines.Enable(True)
2661  else:
2662  showLines.Enable(False)
2663 
2664  self.UpdateVectorShow('lines',
2665  showLines.IsChecked())
2666 
2667  width = self.FindWindowById(self.win['vector']['lines']['width'])
2668  width.SetValue(data['lines']['width']['value'])
2669 
2670  color = self.FindWindowById(self.win['vector']['lines']['color'])
2671  color.SetValue(map(int, data['lines']['color']['value'].split(':')))
2672 
2673  for vtype in ('lines', 'points'):
2674  if vtype == 'lines':
2675  display = self.FindWindowById(self.win['vector']['lines']['flat'])
2676  if data[vtype]['mode']['type'] == 'flat':
2677  display.SetSelection(1)
2678  else:
2679  display.SetSelection(0)
2680 
2681  if data[vtype]['mode']['type'] == 'surface':
2682  rasters = self.mapWindow.GetLayerNames('raster')
2683  surface = self.FindWindowById(self.win['vector'][vtype]['surface'])
2684  surface.SetItems(rasters)
2685  if len(rasters) > 0:
2686  try:
2687  surface.SetStringSelection(data[vtype]['mode']['surface'])
2688  except:
2689  pass
2690 
2691  for type in ('slider', 'spin'):
2692  win = self.FindWindowById(self.win['vector']['lines']['height'][type])
2693  win.SetValue(data['lines']['height']['value'])
2694 
2695  #
2696  # points
2697  #
2698  showPoints = self.FindWindowById(self.win['vector']['points']['show'])
2699 
2700  if 'object' in data['points']:
2701  showPoints.SetValue(True)
2702  else:
2703  showPoints.SetValue(False)
2704  if npoints > 0:
2705  showPoints.Enable(True)
2706  else:
2707  showPoints.Enable(False)
2708 
2709  self.UpdateVectorShow('points',
2710  showPoints.IsChecked())
2711  # size, width, marker, color
2712  for prop in ('size', 'marker', 'color'):
2713  win = self.FindWindowById(self.win['vector']['points'][prop])
2714  name = win.GetName()
2715  if name == 'selection':
2716  win.SetSelection(data['points'][prop]['value'])
2717  elif name == 'color':
2718  color = map(int, data['points'][prop]['value'].split(':'))
2719  win.SetValue(color)
2720  else:
2721  win.SetValue(data['points'][prop]['value'])
2722  # height
2723  for type in ('slider', 'spin'):
2724  win = self.FindWindowById(self.win['vector']['points']['height'][type])
2725  win.SetValue(data['points']['height']['value'])
2726 
2727  def UpdateVolumePage(self, layer, data, updateName = True):
2728  """!Update volume page"""
2729  if updateName:
2730  self.FindWindowById(self.win['volume']['map']).SetValue(layer.name)
2731  list = self.FindWindowById(self.win['volume']['isosurfs'])
2732 
2733  # draw
2734  for control, idata in data['draw'].iteritems():
2735  if control == 'all': # skip 'all' property
2736  continue
2737 
2738  win = self.FindWindowById(self.win['volume']['draw'][control])
2739 
2740  if control == 'shading':
2741  if data['draw']['shading']['desc'] == 'flat':
2742  value = 0
2743  else:
2744  value = 1
2745  else:
2746  value = idata['value']
2747 
2748  if win.GetName() == "selection":
2749  win.SetSelection(value)
2750  else:
2751  win.SetValue(value)
2752 
2753  self.SetIsosurfaceMode(data['draw']['shading']['value'])
2754  self.SetIsosurfaceResolution(data['draw']['resolution']['value'])
2755 
2756  self.UpdateVolumeIsosurfPage(layer, data['attribute'])
2757 
2758  def UpdateVolumeIsosurfPage(self, layer, data):
2759  """!Update dialog -- isosurface attributes"""
2760  #
2761  # isosurface attributes
2762  #
2763  for attrb in ('topo', 'color', 'mask',
2764  'transp', 'shine', 'emit'):
2765  # check required first
2766  if attrb == 'topo':
2767  self.FindWindowById(self.win['volume'][attrb]['const']).SetValue(0)
2768  continue
2769  if attrb == 'color':
2770  if layer and layer.type == '3d-raster':
2771  self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(layer.name)
2772  else:
2773  self.FindWindowById(self.win['volume'][attrb]['map']).SetValue('')
2774  self.SetMapObjUseMap(nvizType = 'volume',
2775  attrb = attrb, map = True) # -> map
2776  continue
2777 
2778  # skip empty attributes
2779  if attrb not in data:
2780  continue
2781 
2782  value = data[attrb]['value']
2783  if attrb == 'color':
2784  if data[attrb]['map']:
2785  self.FindWindowById(self.win['volume'][attrb]['map']).SetValue(value)
2786  else: # constant
2787  color = map(int, value.split(':'))
2788  self.FindWindowById(self.win['volume'][attrb]['const']).SetColour(color)
2789  else:
2790  if data[attrb]['map']:
2791  win = self.FindWindowById(self.win['volume'][attrb]['map'])
2792  else:
2793  win = self.FindWindowById(self.win['volume'][attrb]['const'])
2794  win.SetValue(value)
2795 
2796  self.SetMapObjUseMap(nvizType = 'volume',
2797  attrb = attrb, map = data[attrb]['map'])
2798 
2799  def SetPage(self, name):
2800  """!Get named page"""
2801  if name == 'view':
2802  self.SetSelection(0)
2803  elif name in ('surface', 'vector', 'volume'):
2804  self.SetSelection(1)
2805  else:
2806  self.SetSelection(2)
2807  win = self.FindWindowById(self.page[name]['notebook'])
2808 
2809  win.SetSelection(self.page[name]['id'])
2810 
2811 class PositionWindow(wx.Window):
2812  """!Abstract position control window, see subclasses
2813  ViewPostionWindow and LightPositionWindow"""
2814  def __init__(self, parent, mapwindow, id = wx.ID_ANY,
2815  **kwargs):
2816  self.mapWindow = mapwindow
2817  self.quick = True
2818 
2819  wx.Window.__init__(self, parent, id, **kwargs)
2820 
2821  self.SetBackgroundColour("WHITE")
2822 
2823  self.pdc = wx.PseudoDC()
2824 
2825  self.pdc.SetBrush(wx.Brush(colour = 'dark green', style = wx.SOLID))
2826  self.pdc.SetPen(wx.Pen(colour = 'dark green', width = 2, style = wx.SOLID))
2827 
2828  self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
2829  self.Bind(wx.EVT_PAINT, self.OnPaint)
2830  # self.Bind(wx.EVT_MOTION, self.OnMouse)
2831  self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouse)
2832 
2833  def Draw(self, pos, scale = False):
2834  w, h = self.GetClientSize()
2835  x, y = pos
2836  if scale:
2837  x = x * w
2838  y = y * h
2839  self.pdc.Clear()
2840  self.pdc.BeginDrawing()
2841  self.pdc.DrawLine(w / 2, h / 2, x, y)
2842  self.pdc.DrawCircle(x, y, 5)
2843  self.pdc.EndDrawing()
2844 
2845  def OnPaint(self, event):
2846  dc = wx.BufferedPaintDC(self)
2847  dc.SetBackground(wx.Brush("White"))
2848  dc.Clear()
2849 
2850  self.PrepareDC(dc)
2851  self.pdc.DrawToDC(dc)
2852 
2853  def UpdatePos(self, xcoord, ycoord):
2854  """!Update position coordinates (origin: UL)"""
2855  if xcoord < 0.0:
2856  xcoord = 0.0
2857  elif xcoord > 1.0:
2858  xcoord = 1.0
2859  if ycoord < 0.0:
2860  ycoord = 0.0
2861  elif ycoord > 1.0:
2862  ycoord = 1.0
2863 
2864  self.data['position']['x'] = xcoord
2865  self.data['position']['y'] = ycoord
2866 
2867  return xcoord, ycoord
2868 
2869  def OnMouse(self, event):
2870  if event.LeftIsDown():
2871  x, y = event.GetPosition()
2872  self.Draw(pos = (x, y))
2873  w, h = self.GetClientSize()
2874  x = float(x) / w
2875  y = float(y) / h
2876  self.UpdatePos(x, y)
2877  self.Refresh(False)
2878 
2879  event.Skip()
2880 
2881  def PostDraw(self):
2882  x, y = self.UpdatePos(self.data['position']['x'],
2883  self.data['position']['y'])
2884  self.Draw(pos = (x, y), scale = True)
2885 
2887  """!View position control widget"""
2888  def __init__(self, parent, mapwindow, id = wx.ID_ANY,
2889  **kwargs):
2890  PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
2891 
2892  self.data = self.mapWindow.view
2893  self.PostDraw()
2894 
2895  def UpdatePos(self, xcoord, ycoord):
2896  x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
2897 
2898  event = wxUpdateView(zExag = True)
2899  wx.PostEvent(self.mapWindow, event)
2900 
2901  return x, y
2902 
2903  def OnMouse(self, event):
2904  PositionWindow.OnMouse(self, event)
2905  if event.LeftIsDown():
2906  self.mapWindow.render['quick'] = self.quick
2907  self.mapWindow.Refresh(eraseBackground = False)
2908  elif event.LeftUp():
2909  self.mapWindow.render['quick'] = False
2910  self.mapWindow.Refresh(eraseBackground = False)
2911 
2912  event.Skip()
2913 
2915  """!Light position control widget"""
2916  def __init__(self, parent, mapwindow, id = wx.ID_ANY,
2917  **kwargs):
2918  PositionWindow.__init__(self, parent, mapwindow, id, **kwargs)
2919 
2920  self.data = self.mapWindow.light
2921  self.quick = False
2922  self.PostDraw()
2923 
2924  def UpdatePos(self, xcoord, ycoord):
2925  x, y = PositionWindow.UpdatePos(self, xcoord, ycoord)
2926 
2927  event = wxUpdateLight()
2928  wx.PostEvent(self.mapWindow, event)
2929 
2930  return x, y
2931 
2932  def OnMouse(self, event):
2933  PositionWindow.OnMouse(self, event)
2934  if event.LeftUp():
2935  self.mapWindow.render['quick'] = False
2936  self.mapWindow.Refresh(eraseBackground = False)
2937 
2938 class NvizPreferencesDialog(PreferencesBaseDialog):
2939  """!Nviz preferences dialog"""
2940  def __init__(self, parent, title = _("3D view settings"),
2941  settings = UserSettings):
2942  PreferencesBaseDialog.__init__(self, parent = parent, title = title,
2943  settings = settings)
2944  self.toolWin = self.parent.GetLayerManager().nviz
2945  self.win = dict()
2946 
2947  # create notebook pages
2948  self._createViewPage(self.notebook)
2949  self._createVectorPage(self.notebook)
2950 
2951  self.SetMinSize(self.GetBestSize())
2952  self.SetSize(self.size)
2953 
2954  def _createViewPage(self, notebook):
2955  """!Create notebook page for general settings"""
2956  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
2957 
2958  notebook.AddPage(page = panel,
2959  text = " %s " % _("View"))
2960 
2961  pageSizer = wx.BoxSizer(wx.VERTICAL)
2962 
2963  self.win['general'] = {}
2964  self.win['view'] = {}
2965  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
2966  label = " %s " % (_("View")))
2967  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
2968  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
2969 
2970  # perspective
2971  self.win['view']['persp'] = {}
2972  pvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp')
2973  ipvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'persp', internal = True)
2974  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2975  label = _("Perspective:")),
2976  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
2977  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2978  label = _("(value)")),
2979  pos = (0, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
2980 
2981  pval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
2982  initial = pvals['value'],
2983  min = ipvals['min'],
2984  max = ipvals['max'])
2985  self.win['view']['persp']['value'] = pval.GetId()
2986  gridSizer.Add(item = pval, pos = (0, 2),
2987  flag = wx.ALIGN_CENTER_VERTICAL)
2988 
2989  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
2990  label = _("(step)")),
2991  pos = (0, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
2992 
2993  pstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
2994  initial = pvals['step'],
2995  min = ipvals['min'],
2996  max = ipvals['max']-1)
2997  self.win['view']['persp']['step'] = pstep.GetId()
2998  gridSizer.Add(item = pstep, pos = (0, 4),
2999  flag = wx.ALIGN_CENTER_VERTICAL)
3000 
3001  # position
3002  self.win['view']['position'] = {}
3003  posvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'position')
3004  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3005  label = _("Position:")),
3006  pos = (1, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3007  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3008  label = _("(x)")),
3009  pos = (1, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3010 
3011  px = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3012  initial = posvals['x'] * 100,
3013  min = 0,
3014  max = 100)
3015  self.win['view']['position']['x'] = px.GetId()
3016  gridSizer.Add(item = px, pos = (1, 2),
3017  flag = wx.ALIGN_CENTER_VERTICAL)
3018 
3019  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3020  label = "(y)"),
3021  pos = (1, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3022 
3023  py = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3024  initial = posvals['y'] * 100,
3025  min = 0,
3026  max = 100)
3027  self.win['view']['position']['y'] = py.GetId()
3028  gridSizer.Add(item = py, pos = (1, 4),
3029  flag = wx.ALIGN_CENTER_VERTICAL)
3030 
3031  # height
3032  self.win['view']['height'] = {}
3033  hvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'height')
3034  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3035  label = _("Height:")),
3036  pos = (2, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3037  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3038  label = _("(step)")),
3039  pos = (2, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3040 
3041  hstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3042  initial = hvals['step'],
3043  min = 1,
3044  max = 1e6)
3045  self.win['view']['height']['step'] = hstep.GetId()
3046  gridSizer.Add(item = hstep, pos = (2, 2),
3047  flag = wx.ALIGN_CENTER_VERTICAL)
3048 
3049  # twist
3050  self.win['view']['twist'] = {}
3051  tvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist')
3052  itvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'twist', internal = True)
3053  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3054  label = _("Twist:")),
3055  pos = (3, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3056  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3057  label = _("(value)")),
3058  pos = (3, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3059 
3060  tval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3061  initial = tvals['value'],
3062  min = itvals['min'],
3063  max = itvals['max'])
3064  self.win['view']['twist']['value'] = tval.GetId()
3065  gridSizer.Add(item = tval, pos = (3, 2),
3066  flag = wx.ALIGN_CENTER_VERTICAL)
3067 
3068  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3069  label = _("(step)")),
3070  pos = (3, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3071 
3072  tstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3073  initial = tvals['step'],
3074  min = itvals['min'],
3075  max = itvals['max']-1)
3076  self.win['view']['twist']['step'] = tstep.GetId()
3077  gridSizer.Add(item = tstep, pos = (3, 4),
3078  flag = wx.ALIGN_CENTER_VERTICAL)
3079 
3080  # z-exag
3081  self.win['view']['z-exag'] = {}
3082  zvals = UserSettings.Get(group = 'nviz', key = 'view', subkey = 'z-exag')
3083  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3084  label = _("Z-exag:")),
3085  pos = (4, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3086  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3087  label = _("(value)")),
3088  pos = (4, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3089 
3090  zval = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3091  initial = zvals['value'],
3092  min = -1e6,
3093  max = 1e6)
3094  self.win['view']['z-exag']['value'] = zval.GetId()
3095  gridSizer.Add(item = zval, pos = (4, 2),
3096  flag = wx.ALIGN_CENTER_VERTICAL)
3097 
3098  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3099  label = _("(step)")),
3100  pos = (4, 3), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT)
3101 
3102  zstep = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3103  initial = zvals['step'],
3104  min = -1e6,
3105  max = 1e6)
3106  self.win['view']['z-exag']['step'] = zstep.GetId()
3107  gridSizer.Add(item = zstep, pos = (4, 4),
3108  flag = wx.ALIGN_CENTER_VERTICAL)
3109 
3110  boxSizer.Add(item = gridSizer, proportion = 1,
3111  flag = wx.ALL | wx.EXPAND, border = 3)
3112  pageSizer.Add(item = boxSizer, proportion = 0,
3113  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
3114  border = 3)
3115 
3116  box = wx.StaticBox(parent = panel, id = wx.ID_ANY,
3117  label = " %s " % (_("Image Appearance")))
3118  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3119  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
3120  gridSizer.AddGrowableCol(0)
3121 
3122  # background color
3123  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3124  label = _("Background color:")),
3125  pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3126 
3127  color = csel.ColourSelect(panel, id = wx.ID_ANY,
3128  colour = UserSettings.Get(group = 'nviz', key = 'settings',
3129  subkey = ['general', 'bgcolor']),
3130  size = globalvar.DIALOG_COLOR_SIZE)
3131  self.win['general']['bgcolor'] = color.GetId()
3132  gridSizer.Add(item = color, pos = (0, 1))
3133 
3134  boxSizer.Add(item = gridSizer, proportion = 1,
3135  flag = wx.ALL | wx.EXPAND, border = 3)
3136  pageSizer.Add(item = boxSizer, proportion = 0,
3137  flag = wx.EXPAND | wx.ALL,
3138  border = 3)
3139 
3140  panel.SetSizer(pageSizer)
3141 
3142  return panel
3143 
3144  def _createVectorPage(self, notebook):
3145  """!Create notebook page for general settings"""
3146  panel = wx.Panel(parent = notebook, id = wx.ID_ANY)
3147 
3148  notebook.AddPage(page = panel,
3149  text = " %s " % _("Vector"))
3150 
3151  pageSizer = wx.BoxSizer(wx.VERTICAL)
3152 
3153  # vector lines
3154  self.win['vector'] = {}
3155  self.win['vector']['lines'] = {}
3156  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
3157  label = " %s " % (_("Vector lines")))
3158  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3159  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
3160 
3161  # show
3162  row = 0
3163  showLines = wx.CheckBox(parent = panel, id = wx.ID_ANY,
3164  label = _("Show lines"))
3165  self.win['vector']['lines']['show'] = showLines.GetId()
3166  showLines.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
3167  subkey = ['lines', 'show']))
3168  gridSizer.Add(item = showLines, pos = (row, 0))
3169 
3170  boxSizer.Add(item = gridSizer, proportion = 1,
3171  flag = wx.ALL | wx.EXPAND, border = 3)
3172  pageSizer.Add(item = boxSizer, proportion = 0,
3173  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
3174  border = 3)
3175 
3176  # vector points
3177  self.win['vector']['points'] = {}
3178  box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
3179  label = " %s " % (_("Vector points")))
3180  boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
3181  gridSizer = wx.GridBagSizer(vgap = 3, hgap = 5)
3182 
3183  # show
3184  row = 0
3185  showPoints = wx.CheckBox(parent = panel, id = wx.ID_ANY,
3186  label = _("Show points"))
3187  showPoints.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
3188  subkey = ['points', 'show']))
3189  self.win['vector']['points']['show'] = showPoints.GetId()
3190  gridSizer.Add(item = showPoints, pos = (row, 0), span = (1, 8))
3191 
3192  # icon size
3193  row += 1
3194  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3195  label = _("Size:")),
3196  pos = (row, 0), flag = wx.ALIGN_CENTER_VERTICAL)
3197 
3198  isize = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3199  initial = 100,
3200  min = 1,
3201  max = 1e6)
3202  self.win['vector']['points']['size'] = isize.GetId()
3203  isize.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
3204  subkey = ['points', 'size']))
3205  gridSizer.Add(item = isize, pos = (row, 1),
3206  flag = wx.ALIGN_CENTER_VERTICAL)
3207 
3208  # icon width
3209  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3210  label = _("Width:")),
3211  pos = (row, 2), flag = wx.ALIGN_CENTER_VERTICAL)
3212 
3213  iwidth = wx.SpinCtrl(parent = panel, id = wx.ID_ANY, size = (65, -1),
3214  initial = 2,
3215  min = 1,
3216  max = 1e6)
3217  self.win['vector']['points']['width'] = isize.GetId()
3218  iwidth.SetValue(UserSettings.Get(group = 'nviz', key = 'vector',
3219  subkey = ['points', 'width']))
3220  gridSizer.Add(item = iwidth, pos = (row, 3),
3221  flag = wx.ALIGN_CENTER_VERTICAL)
3222 
3223  # icon symbol
3224  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3225  label = _("Marker:")),
3226  pos = (row, 4), flag = wx.ALIGN_CENTER_VERTICAL)
3227  isym = wx.Choice (parent = panel, id = wx.ID_ANY, size = (100, -1),
3228  choices = UserSettings.Get(group = 'nviz', key = 'vector',
3229  subkey = ['points', 'marker'], internal = True))
3230  isym.SetName("selection")
3231  self.win['vector']['points']['marker'] = isym.GetId()
3232  isym.SetSelection(UserSettings.Get(group = 'nviz', key = 'vector',
3233  subkey = ['points', 'marker']))
3234  gridSizer.Add(item = isym, flag = wx.ALIGN_CENTER_VERTICAL,
3235  pos = (row, 5))
3236 
3237  # icon color
3238  gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
3239  label = _("Color:")),
3240  pos = (row, 6), flag = wx.ALIGN_CENTER_VERTICAL)
3241  icolor = csel.ColourSelect(panel, id = wx.ID_ANY)
3242  icolor.SetName("color")
3243  self.win['vector']['points']['color'] = icolor.GetId()
3244  icolor.SetColour(UserSettings.Get(group = 'nviz', key = 'vector',
3245  subkey = ['points', 'color']))
3246  gridSizer.Add(item = icolor, flag = wx.ALIGN_CENTER_VERTICAL,
3247  pos = (row, 7))
3248 
3249  boxSizer.Add(item = gridSizer, proportion = 1,
3250  flag = wx.ALL | wx.EXPAND, border = 3)
3251  pageSizer.Add(item = boxSizer, proportion = 0,
3252  flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
3253  border = 3)
3254 
3255  panel.SetSizer(pageSizer)
3256 
3257  return panel
3258 
3259  def OnDefault(self, event):
3260  """Restore default settings"""
3261  settings = copy.deepcopy(UserSettings.GetDefaultSettings()['nviz'])
3262  UserSettings.Set(group = 'nviz',
3263  value = settings)
3264 
3265  for subgroup, key in settings.iteritems(): # view, surface, vector...
3266  if subgroup != 'view':
3267  continue
3268  for subkey, value in key.iteritems():
3269  for subvalue in value.keys():
3270  win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
3271  val = settings[subgroup][subkey][subvalue]
3272  if subkey == 'position':
3273  val = int(val * 100)
3274 
3275  win.SetValue(val)
3276 
3277  event.Skip()
3278 
3279  def OnApply(self, event):
3280  """Apply Nviz settings for current session"""
3281  settings = UserSettings.Get(group = 'nviz')
3282  for subgroup, key in settings.iteritems(): # view, surface, vector...
3283  for subkey, value in key.iteritems():
3284  for subvalue in value.keys():
3285  try: # TODO
3286  win = self.FindWindowById(self.win[subgroup][subkey][subvalue])
3287  except:
3288  # print 'e', subgroup, subkey, subvalue
3289  continue
3290 
3291  if win.GetName() == "selection":
3292  value = win.GetSelection()
3293  elif win.GetName() == "color":
3294  value = tuple(win.GetColour())
3295  else:
3296  value = win.GetValue()
3297  if subkey == 'position':
3298  value = float(value) / 100
3299 
3300  settings[subgroup][subkey][subvalue] = value
3301 
3302  def OnSave(self, event):
3303  """!Apply changes, update map and save settings of selected
3304  layer
3305  """
3306  # apply changes
3307  self.OnApply(None)
3308 
3309  if self.GetSelection() == self.page['id']:
3310  fileSettings = {}
3311  UserSettings.ReadSettingsFile(settings = fileSettings)
3312  fileSettings['nviz'] = UserSettings.Get(group = 'nviz')
3313  file = UserSettings.SaveToFile(fileSettings)
3314  self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
3315 
3316  def OnLoad(self, event):
3317  """!Apply button pressed"""
3318  self.LoadSettings()
3319 
3320  if event:
3321  event.Skip()
3322 
3323  def LoadSettings(self):
3324  """!Load saved Nviz settings and apply to current session"""
3325  UserSettings.ReadSettingsFile()
3326  settings = copy.deepcopy(UserSettings.Get(group = 'nviz'))
3327 
3328  for subgroup, key in settings.iteritems(): # view, surface, vector...
3329  for subkey, value in key.iteritems():
3330  for subvalue in value.keys():
3331  if subvalue == 'step':
3332  continue
3333  else:
3334  insetting = value[subvalue]
3335  if subgroup == 'view':
3336  for viewkey, viewitem in self.mapWindow.view[subkey].iteritems():
3337  if viewkey == subvalue:
3338  self.mapWindow.view[subkey][viewkey] = insetting
3339  else:
3340  continue
3341  else:
3342  for otherkey, otheritem in self.win[subgroup][subkey].iteritems():
3343  if type(otheritem) == data:
3344  for endkey, enditem in otheritem.iteritems():
3345  if endkey == subvalue:
3346  paramwin = self.FindWindowById(enditem)
3347  else:
3348  continue
3349  else:
3350  if otherkey == subvalue:
3351  paramwin = self.FindWindowById(otheritem)
3352  else:
3353  continue
3354  if type(insetting) in [tuple, list] and len(insetting) > 2:
3355  insetting = tuple(insetting)
3356  paramwin.SetColour(insetting)
3357  else:
3358  try:
3359  paramwin.SetValue(insetting)
3360  except:
3361  try:
3362  paramwin.SetStringSelection(insetting)
3363  except:
3364  continue
3365 
3366  self.toolWin.UpdateSettings()
3367  self.FindWindowById(self.win['view']['position']).Draw()
3368  self.FindWindowById(self.win['view']['position']).Refresh(False)
3369 
3370  self.mapWindow.render['quick'] = False
3371  self.mapWindow.Refresh(False)
3372 
3373  def OnSave(self, event):
3374  """!Save button pressed
3375 
3376  Save settings to configuration file
3377  """
3378  fileSettings = {}
3379  UserSettings.ReadSettingsFile(settings = fileSettings)
3380 
3381  self.toolWin.UpdateSettings()
3382 
3383  nvsettings = UserSettings.Get(group = 'nviz')
3384  for subgroup, key in nvsettings.iteritems(): # view, surface, vector...
3385  for subkey, value in key.iteritems():
3386  if subkey == 'height': continue
3387  for subvalue in value.keys():
3388  if subvalue == 'step':
3389  #no way to change steps for sliders or spinctrls on non-MSW systems
3390  nvsettings[subgroup][subkey][subvalue] = 1
3391  else:
3392  if subgroup == 'view':
3393  nvsettings[subgroup][subkey][subvalue] = self.mapWindow.view[subkey][subvalue]
3394  elif subvalue == 'map':
3395  if subkey == 'shine':
3396  nvsettings[subgroup][subkey][subvalue] = False
3397  if subkey == 'color':
3398  nvsettings[subgroup][subkey][subvalue] = True
3399  else:
3400  for otherkey, otheritem in self.win[subgroup][subkey].iteritems():
3401  if type(otheritem) == data:
3402  for endkey, enditem in otheritem.iteritems():
3403  if endkey == subvalue:
3404  if self.FindWindowById(enditem).GetClassName() == 'wxChoice':
3405  outsetting = self.FindWindowById(enditem).GetSelection()
3406  else:
3407  try:
3408  outsetting = self.FindWindowById(enditem).GetColour()
3409  outsetting = str(outsetting.Red())+':'+str(outsetting.Green())+':'+str(outsetting.Blue())
3410  except:
3411  try:
3412  outsetting = self.FindWindowById(enditem).GetValue()
3413  except:
3414  try:
3415  outsetting = self.FindWindowById(enditem).GetString()
3416  except:
3417  outsetting = ''
3418  if (type(outsetting) == list or type(outsetting) == tuple) and len(outsetting) > 2:
3419  outsetting = str(outsetting[0])+':'+str(outsetting[1])+':'+str(outsetting[2])
3420 
3421  nvsettings[subgroup][subkey][subvalue][endkey] = outsetting
3422  else:
3423  if otherkey == subvalue:
3424  if self.FindWindowById(otheritem).GetClassName() == 'wxChoice':
3425  outsetting = self.FindWindowById(otheritem).GetSelection()
3426  else:
3427  try:
3428  outsetting = self.FindWindowById(otheritem).GetColour()
3429  outsetting = str(outsetting.Red())+':'+str(outsetting.Green())+':'+str(outsetting.Blue())
3430  except:
3431  try:
3432  outsetting = self.FindWindowById(otheritem).GetValue()
3433  except:
3434  try:
3435  outsetting = self.FindWindowById(enditem).GetString()
3436  except:
3437  outsetting = ''
3438  if (type(outsetting) == list or type(outsetting) == tuple) and len(outsetting) > 2:
3439  outsetting = str(outsetting[0])+':'+str(outsetting[1])+':'+str(outsetting[2])
3440 
3441  nvsettings[subgroup][subkey][subvalue] = outsetting
3442 
3443  UserSettings.Set(group = 'nviz', value = nvsettings)
3444  file = UserSettings.SaveToFile()
3445  self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)