[GRASS-SVN] r47048 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 7 12:05:40 EDT 2011
Author: annakrat
Date: 2011-07-07 09:05:40 -0700 (Thu, 07 Jul 2011)
New Revision: 47048
Modified:
grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
grass/trunk/gui/wxpython/gui_modules/wxnviz.py
Log:
wxNviz: volumes: fixed loading when re-checking layer, added positioning
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-07 12:21:52 UTC (rev 47047)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-07 16:05:40 UTC (rev 47048)
@@ -650,11 +650,11 @@
@param nvizType nviz data type (surface, points, vector)
"""
if nvizType != 'constant':
- type = self.tree.GetPyData(item)[0]['maplayer'].type
+ mapType = self.tree.GetPyData(item)[0]['maplayer'].type
# reference to original layer properties (can be None)
data = self.tree.GetPyData(item)[0]['nviz']
else:
- type = nvizType
+ mapType = nvizType
data = self.constants[item]
if not data:
@@ -663,56 +663,60 @@
self.tree.GetPyData(item)[0]['nviz'] = {}
data = self.tree.GetPyData(item)[0]['nviz']
- if type == 'raster':
+ if mapType == 'raster':
# reset to default properties
data[nvizType] = self.nvizDefault.SetSurfaceDefaultProp()
- elif type == 'vector':
+ elif mapType == 'vector':
# reset to default properties (lines/points)
data['vector'] = self.nvizDefault.SetVectorDefaultProp()
self.SetVectorFromCmd(item, data['vector'])
self.SetVectorSurface(data['vector']['points'])
self.SetVectorSurface(data['vector']['lines'])
- elif type == '3d-raster':
+ elif mapType == '3d-raster':
# reset to default properties
data[nvizType] = self.nvizDefault.SetVolumeDefaultProp()
- elif type == 'constant':
+ elif mapType == 'constant':
data['constant'] = self.nvizDefault.SetConstantDefaultProp()
else:
# complete data (use default values), not sure if this is necessary
- if type == 'raster':
+ if mapType == 'raster':
if not data['surface']:
data['surface'] = self.nvizDefault.SetSurfaceDefaultProp()
- if type == 'vector':
+ if mapType == 'vector':
if not data['vector']['lines']:
self.nvizDefault.SetVectorLinesDefaultProp(data['vector']['lines'])
if not data['vector']['points']:
- self.nvizDefault.SetVectorPointsDefaultProp(data['vector']['points'])
-
+ self.nvizDefault.SetVectorPointsDefaultProp(data['vector']['points'])
# set updates
for sec in data.keys():
for sec1 in data[sec].keys():
if sec1 == 'position':
data[sec][sec1]['update'] = None
continue
- for sec2 in data[sec][sec1].keys():
- if sec2 != 'all':
- data[sec][sec1][sec2]['update'] = None
+ if type(data[sec][sec1]) == type({}):
+ for sec2 in data[sec][sec1].keys():
+ if sec2 != 'all':
+ data[sec][sec1][sec2]['update'] = None
+ elif type(data[sec][sec1]) == type([]):
+ for i in range(len(data[sec][sec1])):
+ for sec2 in data[sec][sec1][i].keys():
+ data[sec][sec1][i][sec2]['update'] = None
event = wxUpdateProperties(data = data)
wx.PostEvent(self, event)
# set id
if id > 0:
- if type in ('raster', '3d-raster'):
+ if mapType in ('raster', '3d-raster'):
data[nvizType]['object'] = { 'id' : id,
'init' : False }
- elif type == 'vector':
+ elif mapType == 'vector':
data['vector'][nvizType]['object'] = { 'id' : id,
'init' : False }
- elif type == 'constant':
+ elif mapType == 'constant':
data[nvizType]['object'] = { 'id' : id,
'init' : False }
@@ -880,12 +884,19 @@
self.layers.remove(item)
# update tools window
- if hasattr(self.lmgr, "nviz") and \
- layer.type == 'raster':
+ if hasattr(self.lmgr, "nviz"):
toolWin = self.lmgr.nviz
- win = toolWin.FindWindowById( \
- toolWin.win['vector']['lines']['surface'])
- win.SetItems(self.GetLayerNames(layer.type))
+ if layer.type == 'raster':
+ win = toolWin.FindWindowById(toolWin.win['vector']['lines']['surface'])
+ win.SetItems(self.GetLayerNames(layer.type))
+ win = toolWin.FindWindowById(toolWin.win['surface']['map'])
+ win.SetValue('')
+ if layer.type == '3d-raster':
+ win = toolWin.FindWindowById(toolWin.win['volume']['map'])
+ win.SetValue('')
+ if layer.type == 'vector':
+ win = toolWin.FindWindowById(toolWin.win['vector']['map'])
+ win.SetValue('')
def LoadVector(self, item, points = None):
"""!Load 2D or 3D vector map overlay
@@ -1176,6 +1187,7 @@
#
isosurfId = 0
for isosurf in data['isosurface']:
+ self._display.AddIsosurface(id, 0, isosurf_id = isosurfId)
for attrb in ('topo', 'color', 'mask',
'transp', 'shine'):
if attrb not in isosurf or \
@@ -1187,7 +1199,7 @@
if map is None: # unset
# only optional attributes
if attrb == 'topo' :
- self._display.SetIsosurfaceTopo(id, isosurfId, map, str(value))
+ self._display.SetIsosurfaceTopo(id, isosurfId, map, str(value))
elif attrb == 'mask':
# TODO: invert mask
# TODO: broken in NVIZ
@@ -1210,7 +1222,14 @@
self._display.SetIsosurfaceShine(id, isosurfId, map, str(value))
isosurf[attrb].pop('update')
isosurfId += 1
-
+ # position
+ if 'update' in data['position']:
+ x = data['position']['x']
+ y = data['position']['y']
+ z = data['position']['z']
+ self._display.SetVolumePosition(id, x, y, z)
+ data['position'].pop('update')
+
def UpdateVectorProperties(self, id, data, type):
"""!Update vector layer properties
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-07 12:21:52 UTC (rev 47047)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-07-07 16:05:40 UTC (rev 47048)
@@ -551,6 +551,7 @@
all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
gridSizer.Add(item = all, flag = wx.ALL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos = (3, 4))
+ self.win['surface']['all'] = all.GetId()
# resolution coarse
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
@@ -704,7 +705,7 @@
# position
self._createControl(panel, data = self.win['surface'], name = 'position',
range = (-10000, 10000),
- bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePosition))
+ bind = (self.OnSurfacePosition, self.OnSurfacePositionChanged, self.OnSurfacePositionText))
axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
choices = ["X",
@@ -714,6 +715,7 @@
reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
reset.SetToolTipString(_("Reset to default position"))
reset.Bind(wx.EVT_BUTTON, self.OnResetSurfacePosition)
+ self.win['surface']['position']['reset'] = reset.GetId()
self.win['surface']['position']['axis'] = axis.GetId()
axis.SetSelection(0)
@@ -1291,13 +1293,13 @@
label = " %s " % (_("Draw")))
boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
- gridSizer.AddGrowableCol(4)
+## gridSizer.AddGrowableCol(4)
# mode
gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
label = _("Mode:")),
pos = (0, 0), flag = wx.ALIGN_CENTER_VERTICAL)
- mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (150, -1),
+ mode = wx.Choice (parent = panel, id = wx.ID_ANY, size = (-1, -1),
choices = [_("isosurfaces"),
_("slides")])
mode.SetSelection(0)
@@ -1506,6 +1508,50 @@
flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
border = 3)
+ #
+ # position
+ #
+ self.win['volume']['position'] = {}
+ box = wx.StaticBox (parent = panel, id = wx.ID_ANY,
+ label = " %s " % (_("Position")))
+ boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+ gridSizer = wx.GridBagSizer(vgap = 3, hgap = 3)
+ gridSizer.AddGrowableCol(3)
+
+ # position
+ self._createControl(panel, data = self.win['volume'], name = 'position',
+ range = (-10000, 10000),
+ bind = (self.OnVolumePosition, self.OnVolumePositionChanged, self.OnVolumePositionText))
+
+ axis = wx.Choice (parent = panel, id = wx.ID_ANY, size = (75, -1),
+ choices = ["X",
+ "Y",
+ "Z"])
+
+ reset = wx.Button(panel, id = wx.ID_ANY, label = _("Reset"))
+ reset.SetToolTipString(_("Reset to default position"))
+ reset.Bind(wx.EVT_BUTTON, self.OnResetVolumePosition)
+ self.win['volume']['position']['reset'] = reset.GetId()
+
+ self.win['volume']['position']['axis'] = axis.GetId()
+ axis.SetSelection(0)
+ axis.Bind(wx.EVT_CHOICE, self.OnVolumeAxis)
+
+ pslide = self.FindWindowById(self.win['volume']['position']['slider'])
+ ptext = self.FindWindowById(self.win['volume']['position']['text'])
+ ptext.SetValue('0')
+
+ gridSizer.Add(item = axis, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
+ gridSizer.Add(item = pslide, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 1))
+ gridSizer.Add(item = ptext, flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 2))
+ gridSizer.Add(item = reset, flag = wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_RIGHT, pos = (0, 3))
+
+ boxSizer.Add(item = gridSizer, proportion = 1,
+ flag = wx.ALL | wx.EXPAND, border = 3)
+
+ pageSizer.Add(item = boxSizer, proportion = 1,
+ flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM,
+ border = 3)
panel.SetSizer(pageSizer)
panel.Fit()
@@ -2194,6 +2240,8 @@
for win in self.win['surface']['position'].itervalues():
if win == self.win['surface']['position']['axis']:
self.FindWindowById(win).SetSelection(0)
+ elif win == self.win['surface']['position']['reset']:
+ continue
else:
self.FindWindowById(win).SetValue(0)
@@ -2566,7 +2614,8 @@
self.AdjustSliderRange(slider = slider, value = value)
for win in self.win['surface']['position'].itervalues():
- if win == self.win['surface']['position']['axis']:
+ if win in (self.win['surface']['position']['axis'],
+ self.win['surface']['position']['reset']):
continue
else:
self.FindWindowById(win).SetValue(value)
@@ -2601,6 +2650,11 @@
self.mapWindow.render['quick'] = False
self.mapWindow.Refresh(False)
+ def OnSurfacePositionText(self, event):
+ """!Surface position changed by textctrl"""
+ self.OnSurfacePosition(event)
+ self.OnSurfacePositionChanged(None)
+
def UpdateVectorShow(self, vecType, enabled):
"""!Enable/disable lines/points widgets
@@ -3140,6 +3194,101 @@
event.Skip()
+ def OnVolumePositionChanged(self, event):
+ """!Volume position changed"""
+ self.mapWindow.render['quick'] = False
+ self.mapWindow.Refresh(False)
+
+ def OnVolumePosition(self, event):
+ """!Volume position"""
+ winName = self.__GetWindowName(self.win['volume'], event.GetId())
+ if not winName:
+ return
+ axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
+
+ value = self.FindWindowById(event.GetId()).GetValue()
+ slider = self.FindWindowById(self.win['volume'][winName]['slider'])
+ self.AdjustSliderRange(slider = slider, value = value)
+
+ for win in self.win['volume']['position'].itervalues():
+ if win in (self.win['volume']['position']['axis'],
+ self.win['volume']['position']['reset']):
+ continue
+ else:
+ self.FindWindowById(win).SetValue(value)
+
+ data = self.GetLayerData('volume')
+ id = data['volume']['object']['id']
+ x, y, z = self._display.GetVolumePosition(id)
+
+ if axis == 0: # x
+ x = value
+ elif axis == 1: # y
+ y = value
+ else: # z
+ z = value
+
+ data['volume']['position']['x'] = x
+ data['volume']['position']['y'] = y
+ data['volume']['position']['z'] = z
+ data['volume']['position']['update'] = None
+ # update properties
+
+ event = wxUpdateProperties(data = data)
+ wx.PostEvent(self.mapWindow, event)
+
+ self.mapWindow.render['quick'] = True
+ if self.mapDisplay.statusbarWin['render'].IsChecked():
+ self.mapWindow.Refresh(False)
+
+ def OnVolumeAxis(self, event):
+ """!Volume position, axis changed"""
+ data = self.GetLayerData('volume')
+ id = data['volume']['object']['id']
+
+ axis = self.FindWindowById(self.win['volume']['position']['axis']).GetSelection()
+ slider = self.FindWindowById(self.win['volume']['position']['slider'])
+ text = self.FindWindowById(self.win['volume']['position']['text'])
+
+ x, y, z = self._display.GetVolumePosition(id)
+
+ if axis == 0: # x
+ slider.SetValue(x)
+ text.SetValue(x)
+ elif axis == 1: # y
+ slider.SetValue(y)
+ text.SetValue(y)
+ else: # z
+ slider.SetValue(z)
+ text.SetValue(z)
+
+ def OnVolumePositionText(self, event):
+ """!Volume position changed by textctrl"""
+ self.OnVolumePosition(event)
+ self.OnVolumePositionChanged(None)
+
+ def OnResetVolumePosition(self, event):
+ """!Reset position of volume"""
+ for win in self.win['volume']['position'].itervalues():
+ if win == self.win['volume']['position']['axis']:
+ self.FindWindowById(win).SetSelection(0)
+ elif win == self.win['volume']['position']['reset']:
+ continue
+ else:
+ self.FindWindowById(win).SetValue(0)
+
+ data = self.GetLayerData('volume')
+ data['volume']['position']['x'] = 0
+ data['volume']['position']['y'] = 0
+ data['volume']['position']['z'] = 0
+ data['volume']['position']['update'] = None
+ # update properties
+ event = wxUpdateProperties(data = data)
+ wx.PostEvent(self.mapWindow, event)
+
+ if self.mapDisplay.statusbarWin['render'].IsChecked():
+ self.mapWindow.Refresh(False)
+
def OnCPlaneSelection(self, event):
"""!Cutting plane selected"""
plane = self.FindWindowById(self.win['cplane']['planes']).GetStringSelection()
@@ -3307,7 +3456,7 @@
self.UpdateVectorPage(layer, data['vector'])
elif pageId == 'volume':
layer = self.mapWindow.GetLayerByName(name, mapType = '3d-raster')
- self.UpdateVectorPage(layer, data['vector'])
+ self.UpdateVolumePage(layer, data['volume'])
elif pageId == 'light':
zval = self.mapWindow.light['position']['z']
bval = self.mapWindow.light['bright']
@@ -3635,7 +3784,14 @@
self.UpdateVolumeIsosurfPage(layer, data['isosurface'][0])
else:
self.UpdateVolumeIsosurfPage(layer, data['attribute'])
-
+ #
+ # position
+ #
+ if 'x' in data['position']:
+ xval = data['position']['x']
+ self.FindWindowById(self.win['volume']['position']['axis']).SetSelection(0)
+ for control in ('slider','text'):
+ self.FindWindowById(self.win['volume']['position'][control]).SetValue(xval)
def UpdateVolumeIsosurfPage(self, layer, data):
"""!Update dialog -- isosurface attributes"""
Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-07 12:21:52 UTC (rev 47047)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-07 16:05:40 UTC (rev 47048)
@@ -949,7 +949,7 @@
return 1
- def AddIsosurface(self, id, level):
+ def AddIsosurface(self, id, level, isosurf_id = None):
"""!Add new isosurface
@param id volume id
@@ -961,6 +961,11 @@
if not GVL_vol_exists(id):
return -1
+ if isosurf_id is not None:
+ num = GVL_isosurf_num_isosurfs(id)
+ if num < 0 or isosurf_id != num:
+ return -1
+
if GVL_isosurf_add(id) < 0:
return -1
@@ -1280,6 +1285,45 @@
return 1
+ def GetVolumePosition(self, id):
+ """!Get volume position
+
+ @param id volume id
+
+ @return x,y,z
+ @return zero-length vector on error
+ """
+ if not GVL_vol_exists(id):
+ return []
+
+ x, y, z = c_float(), c_float(), c_float()
+ GVL_get_trans(id, byref(x), byref(y), byref(z))
+
+ Debug.msg(3, "Nviz::GetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
+ id, x.value, y.value, z.value)
+
+ return [x.value, y.value, z.value]
+
+ def SetVolumePosition(self, id, x, y, z):
+ """!Set volume position
+
+ @param id volume id
+ @param x,y,z translation values
+
+ @return 1 on success
+ @return -1 volume not found
+ @return -2 setting position failed
+ """
+ if not GVL_vol_exists(id):
+ return -1
+
+ Debug.msg(3, "Nviz::SetVolumePosition(): id=%d, x=%f, y=%f, z=%f",
+ id, x, y, z)
+
+ GVL_set_trans(id, x, y, z)
+
+ return 1
+
def GetCPlaneCurrent(self):
return Nviz_get_current_cplane(self.data)
More information about the grass-commit
mailing list