[GRASS-SVN] r46775 - in grass/trunk: gui/wxpython
gui/wxpython/gui_modules include lib/nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 24 09:39:26 EDT 2011
Author: annakrat
Date: 2011-06-24 06:39:26 -0700 (Fri, 24 Jun 2011)
New Revision: 46775
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/preferences.py
grass/trunk/gui/wxpython/gui_modules/workspace.py
grass/trunk/gui/wxpython/gui_modules/wxnviz.py
grass/trunk/gui/wxpython/wxgui.py
grass/trunk/include/nviz.h
grass/trunk/lib/nviz/position.c
Log:
wxNviz: 3d mode in workspace
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -165,6 +165,7 @@
cplane = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'cplane'))
self.cplanes.append(cplane)
+
def OnClose(self, event):
# cleanup when window actually closes (on quit) and not just is hidden
self.Reset()
@@ -215,7 +216,7 @@
elif layer.type == 'vector':
self.lmgr.nviz.UpdatePage('vector')
- ### self.lmgr.nviz.UpdateSettings()
+ self.lmgr.nviz.UpdateSettings()
# update widgets
win = self.lmgr.nviz.FindWindowById( \
@@ -264,7 +265,10 @@
pos = event.GetPosition()
size = self.GetClientSize()
self._display.LookHere(pos[0], size[1] - pos[1])
- self.DoPaint()
+ self.Refresh(False)
+ focus = self._display.GetFocus()
+ for i, coord in enumerate(('x', 'y', 'z')):
+ self.iview['focus'][coord] = focus[i]
toggle = self.lmgr.nviz.FindWindowByName('here')
toggle.SetValue(False)
self.mouse['use'] = 'default'
@@ -339,6 +343,7 @@
def UpdateView(self, event):
"""!Change view settings"""
data = self.view
+ print self.view
self._display.SetView(data['position']['x'], data['position']['y'],
self.iview['height']['value'],
data['persp']['value'],
@@ -346,6 +351,9 @@
if event and event.zExag and 'value' in data['z-exag']:
self._display.SetZExag(data['z-exag']['value'])
+ if self.iview['focus']['x'] != -1:
+ self._display.SetFocus(self.iview['focus']['x'], self.iview['focus']['y'],
+ self.iview['focus']['z'])
if event:
event.Skip()
@@ -531,7 +539,16 @@
stop = time.time()
Debug.msg(3, "GLWindow.UnloadDataLayers(): time = %f" % (stop-start))
-
+
+ def SetVectorSurface(self, data):
+ """!Set reference surfaces of vector"""
+ data['mode']['surface'] = {}
+ data['mode']['surface']['value'] = list()
+ data['mode']['surface']['show'] = list()
+ for name in self.GetLayerNames('raster'):
+ data['mode']['surface']['value'].append(name)
+ data['mode']['surface']['show'].append(True)
+
def SetVectorFromCmd(self, item, data):
"""!Set 3D view properties from cmd (d.vect)
@@ -582,6 +599,8 @@
# 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':
# reset to default properties
@@ -688,8 +707,8 @@
return id
- def AddConstant(self):
- """!Add new constant"""
+ def NewConstant(self):
+ """!Create new constant"""
index = len(self.constants)
try:
name = self.constants[-1]['constant']['object']['name'] + 1
@@ -698,13 +717,16 @@
data = dict()
self.constants.append(data)
data = self.SetMapObjProperties(item = index, id = -1, nvizType = 'constant')
+ self.AddConstant(data, name)
+ return name
+
+ def AddConstant(self, data, name):
+ """!Add new constant"""
id = self._display.AddConstant(value = data['constant']['value'], color = data['constant']['color'])
self._display.SetSurfaceRes(id, data['constant']['resolution'], data['constant']['resolution'])
data['constant']['object'] = { 'id' : id,
'name': name,
'init' : False }
-
- return index, name
def DeleteConstant(self, index):
"""!Delete constant layer"""
@@ -1134,7 +1156,7 @@
if data['mode']['type'] == 'flat':
flat = True
if 'surface' in data['mode']:
- data.pop('surface')
+ data['mode'].pop('surface')
else:
flat = False
@@ -1145,8 +1167,6 @@
data['color'].pop('update')
if 'update' in data['width']:
data['width'].pop('update')
- if 'update' in data['mode']:
- data['mode'].pop('update')
# height
if 'update' in data['height']:
@@ -1155,20 +1175,20 @@
data['height'].pop('update')
# surface
- if 'surface' in data['mode']:
- if 'update' in data['mode']['surface']:
- for item in range(len(data['mode']['surface']['value'])):
- for type in ('raster', 'constant'):
- sid = self.GetLayerId(type = type,
- name = data['mode']['surface']['value'][item])
- if sid > -1:
- if data['mode']['surface']['show'][item]:
- self._display.SetVectorLineSurface(id, sid)
- else:
- self._display.UnsetVectorLineSurface(id, sid)
- break
+ if 'surface' in data['mode'] and 'update' in data['mode']:
+ for item in range(len(data['mode']['surface']['value'])):
+ for type in ('raster', 'constant'):
+ sid = self.GetLayerId(type = type,
+ name = data['mode']['surface']['value'][item])
+ if sid > -1:
+ if data['mode']['surface']['show'][item]:
+ self._display.SetVectorLineSurface(id, sid)
+ else:
+ self._display.UnsetVectorLineSurface(id, sid)
+ break
- data['mode']['surface'].pop('update')
+ if 'update' in data['mode']:
+ data['mode'].pop('update')
def UpdateVectorPointsProperties(self, id, data):
"""!Update vector point map object properties"""
@@ -1200,19 +1220,18 @@
data['height'].pop('update')
# surface
- if 'surface' in data['mode']:
- if 'update' in data['mode']['surface']:
- for item in range(len(data['mode']['surface']['value'])):
- for type in ('raster', 'constant'):
- sid = self.GetLayerId(type = type,
- name = data['mode']['surface']['value'][item])
- if sid > -1:
- if data['mode']['surface']['show'][item]:
- self._display.SetVectorPointSurface(id, sid)
- else:
- self._display.UnsetVectorPointSurface(id, sid)
- break
- data['mode']['surface'].pop('update')
+ if 'update' in data['mode']:
+ for item in range(len(data['mode']['surface']['value'])):
+ for type in ('raster', 'constant'):
+ sid = self.GetLayerId(type = type,
+ name = data['mode']['surface']['value'][item])
+ if sid > -1:
+ if data['mode']['surface']['show'][item]:
+ self._display.SetVectorPointSurface(id, sid)
+ else:
+ self._display.UnsetVectorPointSurface(id, sid)
+ break
+ data['mode'].pop('update')
def GetLayerNames(self, type):
"""!Return list of map layer names of given type"""
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_tools.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -131,7 +131,6 @@
self.win = {} # window ids
self.page = {} # page ids
- self.constantIndex = len(self.mapWindow.constants) # index of constant surface
# view page
self.AddPage(page = self._createViewPage(),
@@ -181,7 +180,17 @@
self.FindWindowById(self.win['vector']['map']).SetValue(selectedVector)
except IndexError:
pass
-
+
+ def UpdateState(self, **kwargs):
+ if 'view' in kwargs:
+ self.mapWindow.view = kwargs['view']
+ self.FindWindowById(self.win['view']['position']).data = kwargs['view']
+ if 'iview' in kwargs:
+ self.mapWindow.iview = kwargs['iview']
+ if 'light' in kwargs:
+ self.mapWindow.light = kwargs['light']
+ self.FindWindowById(self.win['light']['position']).data = kwargs['light']
+
def OnPageChanged(self, event):
new = event.GetSelection()
# self.ChangeSelection(new)
@@ -1716,7 +1725,7 @@
def OnNewConstant(self, event):
"""!Create new surface with constant value"""
#TODO settings
- index, name = self.mapWindow.AddConstant()
+ name = self.mapWindow.NewConstant()
win = self.FindWindowById(self.win['constant']['surface'])
name = _("constant#") + str(name)
win.Append(name)
@@ -1877,14 +1886,13 @@
'twist',
'z-exag'):
for win in self.win['view'][control].itervalues():
- if control == 'height':
- value = UserSettings.Get(group = 'nviz', key = 'view',
- subkey = ['height', 'value'], internal = True)
- else:
- try:
+ try:
+ if control == 'height':
+ value = self.mapWindow.iview[control]['value']
+ else:
value = self.mapWindow.view[control]['value']
- except KeyError:
- value = -1
+ except KeyError:
+ value = -1
self.FindWindowById(win).SetValue(value)
@@ -1894,6 +1902,8 @@
viewWin.Draw(pos = (x, y), scale = True)
viewWin.Refresh(False)
+ color = self._getColorString(self.mapWindow.view['background']['color'])
+ self._display.SetBgColor(str(color))
self.Update()
@@ -1929,7 +1939,7 @@
def OnLightColor(self, event):
"""!Color of the light changed"""
- self.mapWindow.light['color'] = event.GetValue()
+ self.mapWindow.light['color'] = tuple(event.GetValue())
event = wxUpdateLight(refresh = True)
wx.PostEvent(self.mapWindow, event)
@@ -1948,7 +1958,7 @@
def OnBgColor(self, event):
"""!Background color changed"""
color = event.GetValue()
- self.mapWindow.view['background']['color'] = color
+ self.mapWindow.view['background']['color'] = tuple(color)
color = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
self._display.SetBgColor(str(color))
@@ -2576,7 +2586,6 @@
mode['surface']['value'] = value
mode['surface']['show'] = checked
- mode['surface']['update'] = None
else:
mode['type'] = 'flat'
@@ -2666,8 +2675,9 @@
data = self.GetLayerData('vector')
data['vector'][vtype]['mode']['surface'] = { 'value' : surfaces,
- 'show' : checked,
- 'update': None }
+ 'show' : checked}
+ data['vector'][vtype]['mode']['update'] = None
+
# update properties
event = wxUpdateProperties(data = data)
wx.PostEvent(self.mapWindow, event)
@@ -3088,7 +3098,15 @@
self.FindWindowById(self.win['view']['background']['color']).SetColour(\
self.mapWindow.view['background']['color'])
+
+ tval = self.mapWindow.view['twist']['value']
+ pval = self.mapWindow.view['persp']['value']
+ for control in ('slider','text'):
+ self.FindWindowById(self.win['view']['twist'][control]).SetValue(tval)
+
+ self.FindWindowById(self.win['view']['persp'][control]).SetValue(pval)
+
elif pageId in ('surface', 'vector', 'volume'):
name = self.FindWindowById(self.win[pageId]['map']).GetValue()
data = self.GetLayerData(pageId)
@@ -3111,6 +3129,7 @@
self.FindWindowById(self.win['light']['bright'][control]).SetValue(bval)
self.FindWindowById(self.win['light']['ambient'][control]).SetValue(aval)
self.FindWindowById(self.win['light']['color']).SetColour(self.mapWindow.light['color'])
+ self.FindWindowById(self.win['light']['position']).PostDraw()
elif pageId == 'fringe':
win = self.FindWindowById(self.win['fringe']['map'])
win.SetValue(self.FindWindowById(self.win['surface']['map']).GetValue())
@@ -3118,7 +3137,7 @@
if self.mapWindow.constants:
surface = self.FindWindowById(self.win['constant']['surface'])
for item in self.mapWindow.constants:
- surface.Append(_("constant") + str(item['constant']['object']['name']))
+ surface.Append(_("constant#") + str(item['constant']['object']['name']))
surface.SetSelection(0)
self.OnConstantSelection(None)
self.EnablePage('constant', True)
@@ -3322,30 +3341,16 @@
else:
display.SetSelection(0)
if data[vtype]['mode']['type'] == 'surface':
- if npoints:
- vsubtyp = 'vpoint'
- else:
- vsubtyp = 'vline'
- vid = self.mapWindow.GetLayerId(type = 'vector', vsubtyp = vsubtyp, name = layer.name)
rasters = self.mapWindow.GetLayerNames('raster')
constants = self.mapWindow.GetLayerNames('constant')
surfaces = rasters + constants
surfaceWin = self.FindWindowById(self.win['vector'][vtype]['surface'])
surfaceWin.SetItems(surfaces)
for idx, surface in enumerate(surfaces):
- if vtype == 'lines':
- sid = self.mapWindow.GetLayerId(type = 'raster', name = surface)
- if sid == -1:
- sid = self.mapWindow.GetLayerId(type = 'constant', name = surface)
- if vid > -1 and sid > -1:
- selected = self._display.VectorSurfaceSelected(vid, sid)
- else:
- selected = False
- else: # points
- try:# TODO fix this mess
- selected = data[vtype]['mode']['surface']['show'][idx]
- except (TypeError, IndexError, KeyError):
- selected = False
+ try:# TODO fix this mess
+ selected = data[vtype]['mode']['surface']['show'][idx]
+ except (TypeError, IndexError, KeyError):
+ selected = False
surfaceWin.Check(idx, selected)
for type in ('slider', 'text'):
@@ -3567,7 +3572,7 @@
def TransformCoordinates(self, x, y, toLight = True):
return x, y
-
+
def OnMouse(self, event):
PositionWindow.OnMouse(self, event)
if event.LeftIsDown():
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -679,6 +679,10 @@
self.internalSettings['nviz']['view']['persp']['max'] = 100
self.internalSettings['nviz']['view']['height'] = {}
self.internalSettings['nviz']['view']['height']['value'] = -1
+ self.internalSettings['nviz']['view']['focus'] = {}
+ self.internalSettings['nviz']['view']['focus']['x'] = -1
+ self.internalSettings['nviz']['view']['focus']['y'] = -1
+ self.internalSettings['nviz']['view']['focus']['z'] = -1
self.internalSettings['nviz']['vector'] = {}
self.internalSettings['nviz']['vector']['points'] = {}
self.internalSettings['nviz']['vector']['points']['marker'] = ("x",
Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -64,6 +64,10 @@
# list of map layers
#
self.layers = []
+ #
+ # nviz state
+ #
+ self.nviz_state = {}
self.displayIndex = -1 # first display has index '0'
@@ -149,10 +153,13 @@
"size" : size,
"extent" : extent,
"constrainRes" : bool(int(display.get('constrainRes', "0"))),
- "projection" : projection, } )
+ "projection" : projection,
+ "viewMode" : display.get('viewMode', '2d')} )
# process all layers/groups in the display
self.__processLayers(display)
+ # process nviz_state
+ self.__processNvizState(display)
def __processLayers(self, node, inGroup = -1):
"""!Process layers/groups of selected display
@@ -350,9 +357,17 @@
node_mode = node_vpoints.find('mode')
if node_mode is not None:
nviz['vector']['points']['mode'] = {}
- nviz['vector']['points']['mode']['type'] = str(node_mode.get('type', ''))
- nviz['vector']['points']['mode']['surface'] = \
- self.__processLayerNvizNode(node_mode, 'map', str)
+ nviz['vector']['points']['mode']['type'] = str(node_mode.get('type', 'surface'))
+ nviz['vector']['points']['mode']['surface'] = {}
+ nviz['vector']['points']['mode']['surface']['value'] = []
+ nviz['vector']['points']['mode']['surface']['show'] = []
+
+ # map
+ for node_map in node_mode.findall('map'):
+ nviz['vector']['points']['mode']['surface']['value'].append(
+ self.__processLayerNvizNode(node_map, 'name', str))
+ nviz['vector']['points']['mode']['surface']['show'].append(bool(
+ self.__processLayerNvizNode(node_map, 'checked', int)))
# color
self.__processLayerNvizNode(node_vpoints, 'color', str,
@@ -377,11 +392,16 @@
if node_mode is not None:
nviz['vector']['lines']['mode'] = {}
nviz['vector']['lines']['mode']['type'] = str(node_mode.get('type', ''))
- nviz['vector']['lines']['mode']['surface'] = ''
+ nviz['vector']['lines']['mode']['surface'] = {}
+ nviz['vector']['lines']['mode']['surface']['value'] = []
+ nviz['vector']['lines']['mode']['surface']['show'] = []
# map
- nviz['vector']['lines']['mode']['surface'] = \
- self.__processLayerNvizNode(node_mode, 'map', str)
+ for node_map in node_mode.findall('map'):
+ nviz['vector']['lines']['mode']['surface']['value'].append(
+ self.__processLayerNvizNode(node_map, 'name', str))
+ nviz['vector']['lines']['mode']['surface']['show'].append(bool(
+ self.__processLayerNvizNode(node_map, 'checked', int)))
# color
self.__processLayerNvizNode(node_vlines, 'color', str,
@@ -417,6 +437,92 @@
else:
return value
+ def __processNvizState(self, node):
+ """!Process tag nviz_state"""
+ node_state = node.find('nviz_state')
+ if node_state is None:
+ return
+ self.nviz_state['display'] = self.displayIndex
+ #
+ # view
+ #
+ node_view = node_state.find('view')
+ view = {}
+ iview = {}
+
+ node_position = node_view.find('position')
+ view['position'] = {}
+ view['position']['x'] = float(self.__getNodeText(node_position, 'x'))
+ view['position']['y'] = float(self.__getNodeText(node_position, 'y'))
+ node_persp = node_view.find('persp')
+ view['persp'] = {}
+ iview['persp'] = {}
+ view['persp']['value'] = int(self.__getNodeText(node_persp, 'value'))
+ view['persp']['step'] = int(self.__getNodeText(node_persp, 'step'))
+ iview['persp']['min'] = int(self.__getNodeText(node_persp, 'min'))
+ iview['persp']['max'] = int(self.__getNodeText(node_persp, 'max'))
+ node_height = node_view.find('height')
+ view['height'] = {}
+ iview['height'] = {}
+ iview['height']['value'] = int(self.__getNodeText(node_height, 'value'))
+ view['height']['step'] = int(self.__getNodeText(node_height, 'step'))
+ iview['height']['min'] = int(self.__getNodeText(node_height, 'min'))
+ iview['height']['max'] = int(self.__getNodeText(node_height, 'max'))
+ node_twist = node_view.find('twist')
+ view['twist'] = {}
+ iview['twist'] = {}
+ view['twist']['value'] = int(self.__getNodeText(node_twist, 'value'))
+ view['twist']['step'] = int(self.__getNodeText(node_twist, 'step'))
+ iview['twist']['min'] = int(self.__getNodeText(node_twist, 'min'))
+ iview['twist']['max'] = int(self.__getNodeText(node_twist, 'max'))
+ node_zexag = node_view.find('z-exag')
+ view['z-exag'] = {}
+ view['z-exag']['step'] = int(self.__getNodeText(node_zexag, 'step'))
+ view['z-exag']['value'] = int(self.__getNodeText(node_zexag, 'value'))
+ view['z-exag']['min'] = int(self.__getNodeText(node_zexag, 'min'))
+ view['z-exag']['max'] = int(self.__getNodeText(node_zexag, 'max'))
+ node_focus = node_view.find('focus')
+ iview['focus'] = {}
+ iview['focus']['x'] = int(self.__getNodeText(node_focus, 'x'))
+ iview['focus']['y'] = int(self.__getNodeText(node_focus, 'y'))
+ iview['focus']['z'] = int(self.__getNodeText(node_focus, 'z'))
+ node_background = node_view.find('background')
+ view['background'] = {}
+ view['background']['color'] = tuple(map(int,self.__getNodeText(node_background, 'color').split(':')))
+
+ self.nviz_state['view'] = view
+ self.nviz_state['iview'] = iview
+ #
+ # light
+ #
+ node_light = node_state.find('light')
+ light = {}
+
+ node_position = node_light.find('position')
+ light['position'] = {}
+ light['position']['x'] = float(self.__getNodeText(node_position, 'x'))
+ light['position']['y'] = float(self.__getNodeText(node_position, 'y'))
+ light['position']['z'] = float(self.__getNodeText(node_position, 'z'))
+
+
+ light['bright'] = int(node_light.get('bright', '80'))
+ light['ambient'] = int(node_light.get('ambient', '20'))
+ light['color'] = tuple(map(int,(node_light.get('color', '255:255:255')).split(':')))
+
+ self.nviz_state['light'] = light
+
+ node_constants = node_state.find('constant_planes')
+ constants = []
+ for i, node_plane in enumerate(node_constants.findall('plane')):
+ plane = {}
+ plane['value'] = int(self.__getNodeText(node_plane, 'value'))
+ plane['resolution'] = int(self.__getNodeText(node_plane, 'resolution'))
+ plane['color'] = self.__getNodeText(node_plane, 'color')
+ plane['object'] = {}
+ constants.append({'constant': plane})
+ self.nviz_state['constants'] = constants
+
+
class Nviz:
def __init__(self):
"""Default 3D settings"""
@@ -590,8 +696,8 @@
data['color'] = { 'value' : color }
# mode
- data['mode'] = { 'type' : 'surface',
- 'surface' : '', }
+ data['mode'] = { 'type' : 'surface'}
+## 'surface' : '', }
# height
data['height'] = { 'value' : UserSettings.Get(group='nviz', key='vector',
@@ -701,12 +807,17 @@
displayPos = mapTree.mapdisplay.GetPosition()
displaySize = mapTree.mapdisplay.GetSize()
+ if mapTree.mapdisplay.toolbars['map'].combo.GetSelection() == 1:
+ viewmode = '3d'
+ else:
+ viewmode = '2d'
file.write('%s<display render="%d" '
'mode="%d" showCompExtent="%d" '
'constrainRes="%d" '
'dim="%d,%d,%d,%d" '
- 'extent="%f,%f,%f,%f">\n' % (' ' * self.indent,
+ 'extent="%f,%f,%f,%f" '
+ 'viewMode="%s" >\n' % (' ' * self.indent,
int(mapTree.mapdisplay.statusbarWin['render'].IsChecked()),
mapTree.mapdisplay.statusbarWin['toggle'].GetSelection(),
int(mapTree.mapdisplay.statusbarWin['region'].IsChecked()),
@@ -718,7 +829,8 @@
region['w'],
region['s'],
region['e'],
- region['n']
+ region['n'],
+ viewmode
))
# projection statusbar info
if mapTree.mapdisplay.statusbarWin['projection'].IsChecked() and \
@@ -739,6 +851,12 @@
# list of layers
item = mapTree.GetFirstChild(mapTree.root)[0]
self.__writeLayer(mapTree, item)
+
+ if mapTree.mapdisplay.MapWindow3D is not None:
+ nvizDisp = mapTree.mapdisplay.MapWindow3D
+ self.__writeNvizState(view = nvizDisp.view, iview = nvizDisp.iview,
+ light = nvizDisp.light, constants = nvizDisp.constants)
+
file.write('%s</display>\n' % (' ' * self.indent))
self.indent =- 4
@@ -944,8 +1062,14 @@
data[attrb][name]['type']))
if data[attrb][name]['type'] == 'surface':
self.indent += 4
- self.file.write('%s<map>%s</map>\n' % (' ' * self.indent,
- data[attrb][name]['surface']))
+ for idx, surface in enumerate(data[attrb][name]['surface']['value']):
+ checked = data[attrb][name]['surface']['show'][idx]
+ self.file.write('%s<map>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.file.write('%s<name>%s</name>\n' % (' ' * self.indent, surface))
+ self.file.write('%s<checked>%s</checked>\n' % (' ' * self.indent, int(checked)))
+ self.indent -= 4
+ self.file.write('%s</map>\n' % (' ' * self.indent))
self.indent -= 4
self.file.write('%s</%s>\n' % ((' ' * self.indent, name)))
else:
@@ -959,6 +1083,130 @@
self.indent -= 4
+ def __writeNvizState(self, view, iview, light, constants):
+ """"!Save Nviz properties (view, light) to workspace
+
+ @param view Nviz view properties
+ @param iview Nviz internal view properties
+ @param light Nviz light properties
+ """
+ self.indent += 4
+ self.file.write('%s<nviz_state>\n' % (' ' * self.indent))
+ #
+ # view
+ #
+ self.indent += 4
+ self.file.write('%s<view>\n' % (' ' * self.indent))
+ self.indent += 4
+ # position
+ self.file.write('%s<position>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('x', view['position'], format = '.2f')
+ self.__writePairTag('y', view['position'], format = '.2f')
+ self.indent -= 4
+ self.file.write('%s</position>\n' % (' ' * self.indent))
+ # perspective
+ self.file.write('%s<persp>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('value', view['persp'])
+ self.__writePairTag('step', view['persp'])
+ self.__writePairTag('max', iview['persp'])
+ self.__writePairTag('min', iview['persp'])
+ self.indent -= 4
+ self.file.write('%s</persp>\n' % (' ' * self.indent))
+ # height
+ self.file.write('%s<height>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('value', iview['height'])
+ self.__writePairTag('step', view['height'])
+ self.__writePairTag('max', iview['height'])
+ self.__writePairTag('min', iview['height'])
+ self.indent -= 4
+ self.file.write('%s</height>\n' % (' ' * self.indent))
+ # twist
+ self.file.write('%s<twist>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('step', view['twist'])
+ self.__writePairTag('value', view['twist'])
+ self.__writePairTag('max', iview['twist'])
+ self.__writePairTag('min', iview['twist'])
+ self.indent -= 4
+ self.file.write('%s</twist>\n' % (' ' * self.indent))
+ # z-exag
+ self.file.write('%s<z-exag>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('step', view['z-exag'])
+ self.__writePairTag('value', view['z-exag'])
+ self.__writePairTag('max', view['z-exag'])
+ self.__writePairTag('min', view['z-exag'])
+ self.indent -= 4
+ self.file.write('%s</z-exag>\n' % (' ' * self.indent))
+ # focus (look here)
+ self.file.write('%s<focus>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('x', iview['focus'])
+ self.__writePairTag('y', iview['focus'])
+ self.__writePairTag('z', iview['focus'])
+ self.indent -= 4
+ self.file.write('%s</focus>\n' % (' ' * self.indent))
+ # background
+ self.file.write('%s<background>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.file.write('%s<color>' % (' ' * self.indent))
+ self.file.write('%d:%d:%d</color>\n' % (view['background']['color']))
+ self.indent -= 4
+ self.file.write('%s</background>\n' % (' ' * self.indent))
+
+ self.indent -= 4
+ self.file.write('%s</view>\n' % (' ' * self.indent))
+ #
+ # light
+ #
+ self.file.write('%s<light bright="%d" ambient="%d" '
+ % (' ' * self.indent, light['bright'], light['ambient']))
+ self.file.write('color="%d:%d:%d">\n' % (light['color']))
+ self.indent += 4
+ # position
+ self.file.write('%s<position>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('x', light['position'], format = '.2f')
+ self.__writePairTag('y', light['position'], format = '.2f')
+ self.__writePairTag('z', light['position'], format = '.2f')
+ self.indent -= 4
+ self.file.write('%s</position>\n' % (' ' * self.indent))
+
+ self.indent -= 4
+ self.file.write('%s</light>\n' % (' ' * self.indent))
+ #
+ # constant planes
+ #
+ self.file.write('%s<constant_planes>\n' % (' ' * self.indent))
+ self.indent += 4
+ for idx, plane in enumerate(constants):
+ self.file.write('%s<plane>\n' % (' ' * self.indent))
+ self.indent += 4
+ self.__writePairTag('value', constants[idx]['constant'])
+ self.__writePairTag('resolution', constants[idx]['constant'])
+ self.__writePairTag('color', constants[idx]['constant'], format = 's')
+ self.indent -= 4
+ self.file.write('%s</plane>\n' % (' ' * self.indent))
+ self.indent -= 4
+ self.file.write('%s</constant_planes>\n' % (' ' * self.indent))
+ self.indent -= 4
+
+ self.file.write('%s</nviz_state>\n' % (' ' * self.indent))
+ self.indent -= 4
+
+ def __writePairTag(self, tag, data, format = 'd'):
+ """!Helper function for writing pair tag
+
+ @param tag written tag
+ @param data written data
+ @param format conversion type
+ """
+ self.file.write(('%s<%s>%' + format + '</%s>\n') % \
+ (' ' * self.indent, tag, data[tag], tag))
+
class ProcessGrcFile(object):
def __init__(self, filename):
"""!Process GRC file"""
Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -151,7 +151,24 @@
"""!Center view at center of displayed surface"""
Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1)
Debug.msg(3, "Nviz::LookAtCenter()")
+
+ def GetFocus(self):
+ """!Get focus"""
+ Debug.msg(3, "Nviz::GetFocus()")
+ if Nviz_has_focus(self.data):
+ x = c_float()
+ y = c_float()
+ z = c_float()
+ Nviz_get_focus(self.data, byref(x), byref(y), byref(z))
+ return x.value, y.value, z.value
+ else:
+ return -1, -1, -1
+ def SetFocus(self, x, y, z):
+ """!Set focus"""
+ Debug.msg(3, "Nviz::SetFocus()")
+ Nviz_set_focus(self.data, x, y, z)
+
def SetZExag(self, z_exag):
"""!Set z-exag value
@@ -365,7 +382,7 @@
return 1
def VectorSurfaceSelected(self, vid, sid):
- """!Check if surface is selected
+ """!Check if surface is selected (currently unused)
@param vid vector id
@param sid surface id
Modified: grass/trunk/gui/wxpython/wxgui.py
===================================================================
--- grass/trunk/gui/wxpython/wxgui.py 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/gui/wxpython/wxgui.py 2011-06-24 13:39:26 UTC (rev 46775)
@@ -712,7 +712,7 @@
return
Debug.msg(4, "GMFrame.OnWorkspaceOpen(): filename=%s" % filename)
-
+
# delete current layer tree content
self.OnWorkspaceClose()
@@ -835,9 +835,30 @@
# reverse list of map layers
maptree.Map.ReverseListOfLayers()
- for mdisp in mapdisplay:
+ for idx, mdisp in enumerate(mapdisplay):
mdisp.MapWindow2D.UpdateMap()
+ #nviz
+ if gxwXml.displays[idx]['viewMode'] == '3d':
+ # check if nviz exist, if so, don't open workspace in 3D mode
+ # sofar only one nviz can exist
+ if self.existNviz:
+ gcmd.GMessage(parent = self,
+ message = _("3D view is not available. Please do not switch to 3D view "
+ "before opening workspace in 3D view mode."))
+ continue
+ mdisp.AddToolbar(name = 'nviz')
+ self.nviz.UpdateState(view = gxwXml.nviz_state['view'],
+ iview = gxwXml.nviz_state['iview'],
+ light = gxwXml.nviz_state['light'])
+ mdisp.MapWindow3D.constants = gxwXml.nviz_state['constants']
+ for idx, constant in enumerate(mdisp.MapWindow3D.constants):
+ mdisp.MapWindow3D.AddConstant(constant, idx + 1)
+ for page in ('view', 'light', 'fringe', 'constant', 'cplane'):
+ self.nviz.UpdatePage(page)
+ self.nviz.UpdateSettings()
+ mapdisp.toolbars['map'].combo.SetSelection(1)
+
return True
def OnWorkspaceLoadGrcFile(self, event):
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/include/nviz.h 2011-06-24 13:39:26 UTC (rev 46775)
@@ -192,6 +192,9 @@
void Nviz_init_view(nv_data *);
int Nviz_set_focus_state(int);
int Nviz_set_focus_map(int, int);
+int Nviz_has_focus(nv_data *);
+int Nviz_set_focus(nv_data *, float, float, float);
+int Nviz_get_focus(nv_data *, float *, float *, float *);
float Nviz_get_xyrange(nv_data *);
int Nviz_get_zrange(nv_data *, float *, float *);
Modified: grass/trunk/lib/nviz/position.c
===================================================================
--- grass/trunk/lib/nviz/position.c 2011-06-24 13:17:31 UTC (rev 46774)
+++ grass/trunk/lib/nviz/position.c 2011-06-24 13:39:26 UTC (rev 46775)
@@ -23,7 +23,7 @@
void Nviz_init_view(nv_data *data)
{
GS_init_view();
- Nviz_set_focus_state(1); /* center of view */
+ Nviz_set_focus_state(1); /* center of view */
/* set default lights (1 & 2) */
Nviz_set_light_position(data, 1, 0.68, -0.68, 0.80, 0.0);
@@ -49,12 +49,12 @@
int Nviz_set_focus_state(int state_flag)
{
if (state_flag == 1)
- GS_set_infocus(); /* return center of view */
+ GS_set_infocus(); /* return center of view */
else if (state_flag == 0)
- GS_set_nofocus(); /* no center of view -- use viewdir */
+ GS_set_nofocus(); /* no center of view -- use viewdir */
else {
- G_warning(_("Unable to set focus"));
- return 0;
+ G_warning(_("Unable to set focus"));
+ return 0;
}
return 1;
@@ -75,41 +75,95 @@
int Nviz_set_focus_map(int type, int id)
{
if (GS_num_surfs() < 0 && GVL_num_vols() < 0) {
- GS_set_nofocus();
- return 0;
+ GS_set_nofocus();
+ return 0;
}
if (type == MAP_OBJ_UNDEFINED) {
- int *surf_list, num_surfs, *vol_list;
+ int *surf_list, num_surfs, *vol_list;
- if (GS_num_surfs() > 0) {
- surf_list = GS_get_surf_list(&num_surfs);
- id = surf_list[0];
- G_free(surf_list);
+ if (GS_num_surfs() > 0) {
+ surf_list = GS_get_surf_list(&num_surfs);
+ id = surf_list[0];
+ G_free(surf_list);
+
+ GS_set_focus_center_map(id);
+ }
- GS_set_focus_center_map(id);
- }
-
- if (GVL_num_vols() > 0) {
- vol_list = GVL_get_vol_list(&num_surfs);
- id = vol_list[0];
- G_free(vol_list);
-
- GVL_set_focus_center_map(id);
- }
- return id;
+ if (GVL_num_vols() > 0) {
+ vol_list = GVL_get_vol_list(&num_surfs);
+ id = vol_list[0];
+ G_free(vol_list);
+
+ GVL_set_focus_center_map(id);
+ }
+ return id;
}
if (type == MAP_OBJ_SURF) {
- GS_set_focus_center_map(id);
+ GS_set_focus_center_map(id);
}
else if (type == MAP_OBJ_VOL) {
- GVL_set_focus_center_map(id);
+ GVL_set_focus_center_map(id);
}
return id;
}
/*!
+ \brief Get focus
+
+ \param data nviz data
+ \param x,y,z focus coordinates
+ */
+int Nviz_get_focus(nv_data * data, float * x, float * y, float * z)
+{
+ float realto[3];
+ /* Get current center */
+ GS_get_focus(realto);
+ *x = realto[0];
+ *y = realto[1];
+ *z = realto[2];
+ // old nviz code is more complicated and it doesn't work properly,
+ // no idea why
+
+ return 1;
+
+}
+/*!
+ \brief Set focus
+
+ \param data nviz data
+ \param x, y, z focus coordinates
+ */
+int Nviz_set_focus(nv_data * data, float x, float y, float z)
+{
+ float realto[3];
+
+ realto[0] = x;
+ realto[1] = y;
+ realto[2] = z;
+ GS_set_focus(realto);
+ // old nviz code is more complicated and it doesn't work properly,
+ // no idea why
+
+ return 1;
+
+}
+/*!
+ \brief Test focus
+
+ \param data nviz data
+ */
+int Nviz_has_focus(nv_data * data)
+{
+ float realto[3];
+
+ if (GS_get_focus(realto))
+ return 1;
+ else
+ return 0;
+}
+/*!
\brief Get xy range
\param data nviz data
@@ -126,6 +180,6 @@
*/
int Nviz_get_zrange(nv_data * data, float *min, float *max)
{
- GS_get_zrange_nz(min, max);
- return 1;
+ GS_get_zrange_nz(min, max);
+ return 1;
}
More information about the grass-commit
mailing list