[GRASS-SVN] r32352 - in grass/trunk/gui/wxpython: gui_modules xml
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 28 18:22:28 EDT 2008
Author: martinl
Date: 2008-07-28 18:22:28 -0400 (Mon, 28 Jul 2008)
New Revision: 32352
Modified:
grass/trunk/gui/wxpython/gui_modules/nviz.py
grass/trunk/gui/wxpython/gui_modules/workspace.py
grass/trunk/gui/wxpython/xml/grass-gxw.dtd
Log:
nviz2/wxGUI: workspace fixes (vector lines/points)
Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-28 13:31:49 UTC (rev 32351)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-28 22:22:28 UTC (rev 32352)
@@ -356,7 +356,7 @@
self.LoadVector(item)
except gcmd.NvizError, e:
print >> sys.stderr, "Nviz: " + e.message
-
+
stop = time.time()
Debug.msg(3, "GLWindow.LoadDataLayers(): time=%f" % (stop-start))
@@ -364,54 +364,53 @@
# print stop - start
def SetLayerData(self, item, id, nvizType):
- """Set map object properties"""
+ """Set map object properties
+
+ @param item layer item
+ @param id nviz layer id (or -1)
+ @param nvizType nviz data type (surface, points, vector)
+ """
type = self.tree.GetPyData(item)[0]['maplayer'].type
- data = self.tree.GetPyData(item)[0]['nviz']
+ # reference to original layer properties (can be None)
+ dataOrig = self.tree.GetPyData(item)[0]['nviz']
- # set default properties
- if data is None:
+ if dataOrig is None:
+ # set default properties
self.tree.GetPyData(item)[0]['nviz'] = {}
data = self.tree.GetPyData(item)[0]['nviz']
+ else:
+ data = dataOrig
- if type == 'raster':
- data['surface'] = {}
- for sec in ('attribute', 'draw', 'mask', 'position'):
- data['surface'][sec] = {}
+ # reset data
+ if type == 'raster':
+ data[nvizType] = {}
+ for sec in ('attribute', 'draw', 'mask', 'position'):
+ data[nvizType][sec] = {}
+
+ if id > 0:
+ data[nvizType]['object'] = { 'id' : id,
+ 'init' : False }
- if id > 0 and not data[nvizType].has_key('object'):
- data[nvizType]['object'] = { 'id' : id,
- 'init' : False }
+ self.SetSurfaceDefaultProp(data[nvizType])
+ elif type == 'vector':
+ data['vector'] = {}
+ for sec in ('lines', 'points'):
+ data['vector'][sec] = {}
+
+ if id > 0:
+ data['vector'][nvizType]['object'] = { 'id' : id,
+ 'init' : False }
- self.SetSurfaceDefaultProp(data['surface'])
- elif type == 'vector':
- data['vector'] = {}
- for sec in ('lines', 'points'):
- data['vector'][sec] = {}
+ self.SetVectorDefaultProp(data['vector']) # for both - lines/points
- if id > 0 and not data['vector'][nvizType].has_key('object'):
- data['vector'][nvizType]['object'] = { 'id' : id,
- 'init' : False }
-
- self.SetVectorDefaultProp(data['vector'])
-
# set updates
- else:
- if id > 0:
- if type == 'raster':
- if not data[nvizType].has_key('object'):
- data[nvizType]['object'] = { 'id' : id,
- 'init' : False }
- elif type == 'vector':
- if not data['vector'][nvizType].has_key('object'):
- data['vector'][nvizType]['object'] = { 'id' : id,
- 'init' : False }
-
+ if dataOrig:
for sec in data.keys():
for sec1 in data[sec].keys():
for sec2 in data[sec][sec1].keys():
- if sec2 != 'object':
+ if sec2 not in ('object'):
self.update.append('%s:%s:%s' % (sec, sec1, sec2))
-
+
return data
def LoadRaster(self, item):
@@ -584,9 +583,10 @@
'all' : False }
def LoadVector(self, item, vecType=None):
- """Load vector map overlay (lines / points)
+ """Load 2D or 3D vector map overlay
@param item layer item
+ @param vecType vector type (lines / points)
"""
layer = self.tree.GetPyData(item)[0]['maplayer']
@@ -594,11 +594,16 @@
return
if vecType is None:
+ # load data type by default
vecType = []
for v in ('lines', 'points'):
if UserSettings.Get(group='nviz', key='vector',
subkey=[v, 'show']):
vecType.append(v)
+
+ # set default properties
+ self.SetLayerData(item, -1, v)
+
id = -1
for type in vecType:
if type == 'lines':
@@ -606,20 +611,16 @@
else:
id = self.nvizClass.LoadVector(str(layer.name), True)
- # set default/workspace layer properties
- data = self.SetLayerData(item, id, type)['vector']
-
if id < 0:
print >> sys.stderr, _("Vector map <%s> (%s) not loaded") % \
(layer.name, type)
continue
-
+
+ # update layer properties
+ self.SetLayerData(item, id, type)
+
self.layers['v' + type]['name'].append(layer.name)
self.layers['v' + type]['id'].append(id)
-
- if id < 0:
- self.SetLayerData(item, id, 'lines')
- self.SetLayerData(item, id, 'points')
# update properties
self.UpdateLayerProperties(item)
@@ -1573,7 +1574,7 @@
self.win['vector']['points'] = {}
showPoints = wx.CheckBox(parent=panel, id=wx.ID_ANY,
- label=_("Show vector points"))
+ label=_("Show vector points"))
self.win['vector']['points']['show'] = showPoints.GetId()
showPoints.Bind(wx.EVT_CHECKBOX, self.OnVectorShow)
@@ -2532,16 +2533,11 @@
def OnVectorShow(self, event):
"""Show vector lines/points"""
winId = event.GetId()
-
- vecType = None
if winId == self.win['vector']['lines']['show']:
vecType = 'lines'
- elif winId == self.win['vector']['points']['show']:
+ else: # points
vecType = 'points'
- if vecType is None:
- return
-
checked = event.IsChecked()
item = self.mapWindow.GetSelectedLayer(type='item')
data = self.mapWindow.GetSelectedLayer(type='nviz')['vector']
@@ -2550,23 +2546,24 @@
self.mapWindow.LoadVector(item, (vecType,))
else:
self.mapWindow.UnloadVector(item, (vecType,))
-
+
self.UpdateVectorShow(vecType, checked)
if checked:
try:
id = data[vecType]['object']['id']
except KeyError:
- return
+ id = -1
- self.mapWindow.SetLayerData(item, id, vecType)
+ if id > 0:
+ self.mapWindow.SetLayerData(item, id, vecType)
- # update properties
- self.mapWindow.UpdateLayerProperties(item)
+ # update properties
+ self.mapWindow.UpdateLayerProperties(item)
if self.parent.autoRender.IsChecked():
self.mapWindow.Refresh(False)
-
+
event.Skip()
def OnVectorDisplay(self, event):
@@ -2831,13 +2828,15 @@
#
# lines
#
- show = self.FindWindowById(self.win['vector']['lines']['show'])
+ showLines = self.FindWindowById(self.win['vector']['lines']['show'])
+
if data['lines'].has_key('object'):
- show.SetValue(True)
+ showLines.SetValue(True)
else:
- show.SetValue(False)
- self.UpdateVectorShow(show.GetId(),
- show.IsChecked())
+ showLines.SetValue(False)
+
+ self.UpdateVectorShow(showLines.GetId(),
+ showLines.IsChecked())
width = self.FindWindowById(self.win['vector']['lines']['width'])
width.SetValue(data['lines']['width'])
@@ -2866,14 +2865,15 @@
#
# points
#
- show = self.FindWindowById(self.win['vector']['points']['show'])
+ showPoints = self.FindWindowById(self.win['vector']['points']['show'])
+
if data['points'].has_key('object'):
- show.SetValue(True)
+ showPoints.SetValue(True)
else:
- show.SetValue(False)
- self.UpdateVectorShow(show.GetId(),
- show.IsChecked())
-
+ showPoints.SetValue(False)
+ self.UpdateVectorShow(showPoints.GetId(),
+ showPoints.IsChecked())
+
for prop in ('size', 'width', 'marker', 'color'):
win = self.FindWindowById(self.win['vector']['points'][prop])
name = win.GetName()
Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py 2008-07-28 13:31:49 UTC (rev 32351)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2008-07-28 22:22:28 UTC (rev 32352)
@@ -44,11 +44,13 @@
'layer_manager',
'nviz',
# surface
- 'attribute', 'draw', 'resolution',
+ 'surface', 'attribute', 'draw', 'resolution',
'wire_color', 'position', 'x', 'y', 'z',
# vector lines
- 'lines', 'color', 'width', 'mode',
- 'map', 'height'):
+ 'vlines', 'color', 'width', 'mode',
+ 'map', 'height',
+ # vector points
+ 'vpoints'):
self.inTag[tag] = False
#
@@ -163,43 +165,47 @@
self.layerNviz['surface'][sec] = {}
elif self.layerType == 'vector':
self.layerNviz['vector'] = {}
- for sec in ('lines', ):
+ for sec in ('lines', 'points'):
self.layerNviz['vector'][sec] = {}
elif name == 'attribute':
- tagName = str(name)
- attrbName = str(attrs.get('name', ''))
- self.layerNviz['surface'][tagName][attrbName] = {}
- if attrs.get('map', '0') == '0':
- self.layerNviz['surface'][tagName][attrbName]['map'] = False
- else:
- self.layerNviz['surface'][tagName][attrbName]['map'] = True
+ if self.inTag['nviz'] and self.inTag['surface']:
+ tagName = str(name)
+ attrbName = str(attrs.get('name', ''))
+ self.layerNviz['surface'][tagName][attrbName] = {}
+ if attrs.get('map', '0') == '0':
+ self.layerNviz['surface'][tagName][attrbName]['map'] = False
+ else:
+ self.layerNviz['surface'][tagName][attrbName]['map'] = True
- self.refAttribute = self.layerNviz['surface'][tagName][attrbName]
+ self.refAttribute = self.layerNviz['surface'][tagName][attrbName]
elif name == 'draw':
- tagName = str(name)
- self.layerNviz['surface'][tagName]['mode'] = {}
- self.layerNviz['surface'][tagName]['mode']['all'] = False
- self.layerNviz['surface'][tagName]['mode']['value'] = -1 # to be calculated
- self.layerNviz['surface'][tagName]['mode']['desc'] = {}
- self.layerNviz['surface'][tagName]['mode']['desc']['shading'] = \
- str(attrs.get('shading', ''))
- self.layerNviz['surface'][tagName]['mode']['desc']['style'] = \
- str(attrs.get('style', ''))
- self.layerNviz['surface'][tagName]['mode']['desc']['mode'] = \
- str(attrs.get('mode', ''))
+ if self.inTag['nviz'] and self.inTag['surface']:
+ tagName = str(name)
+ self.layerNviz['surface'][tagName]['mode'] = {}
+ self.layerNviz['surface'][tagName]['mode']['all'] = False
+ self.layerNviz['surface'][tagName]['mode']['value'] = -1 # to be calculated
+ self.layerNviz['surface'][tagName]['mode']['desc'] = {}
+ self.layerNviz['surface'][tagName]['mode']['desc']['shading'] = \
+ str(attrs.get('shading', ''))
+ self.layerNviz['surface'][tagName]['mode']['desc']['style'] = \
+ str(attrs.get('style', ''))
+ self.layerNviz['surface'][tagName]['mode']['desc']['mode'] = \
+ str(attrs.get('mode', ''))
elif name == 'resolution':
- self.resolutionType = str(attrs.get('type', ''))
- if not self.layerNviz['surface']['draw'].has_key(str(name)):
- self.layerNviz['surface']['draw'][str(name)] = {}
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.resolutionType = str(attrs.get('type', ''))
+ if not self.layerNviz['surface']['draw'].has_key(str(name)):
+ self.layerNviz['surface']['draw'][str(name)] = {}
elif name == 'position':
- self.layerNviz['surface']['position'] = {}
+ if self.inTag['nviz'] and inTag['surface']:
+ self.layerNviz['surface']['position'] = {}
elif name == 'mode':
- if self.inTag['nviz'] and self.inTag['lines']:
+ if self.inTag['nviz'] and self.inTag['vlines']:
self.layerNviz['vector']['lines']['mode'] = {}
self.layerNviz['vector']['lines']['mode']['type'] = str(attrs.get('type', ''))
@@ -237,47 +243,53 @@
# Nviz section
#
elif name == 'attribute':
- try:
- self.refAttribute['value'] = int(self.value)
- except ValueError:
+ if self.inTag['nviz'] and self.inTag['surface']:
try:
- self.refAttribute['value'] = float(self.value)
+ self.refAttribute['value'] = int(self.value)
except ValueError:
- self.refAttribute['value'] = str(self.value)
+ try:
+ self.refAttribute['value'] = float(self.value)
+ except ValueError:
+ self.refAttribute['value'] = str(self.value)
elif name == 'resolution':
- self.layerNviz['surface']['draw']['resolution']['all'] = False
- self.layerNviz['surface']['draw']['resolution'][self.resolutionType] = int(self.value)
- del self.resolutionType
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.layerNviz['surface']['draw']['resolution']['all'] = False
+ self.layerNviz['surface']['draw']['resolution'][self.resolutionType] = int(self.value)
+ del self.resolutionType
elif name == 'wire_color':
- self.layerNviz['surface']['draw']['wire-color'] = {}
- self.layerNviz['surface']['draw']['wire-color']['all'] = False
- self.layerNviz['surface']['draw']['wire-color']['value'] = str(self.value)
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.layerNviz['surface']['draw']['wire-color'] = {}
+ self.layerNviz['surface']['draw']['wire-color']['all'] = False
+ self.layerNviz['surface']['draw']['wire-color']['value'] = str(self.value)
elif name == 'x':
- self.layerNviz['surface']['position']['x'] = int(self.value)
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.layerNviz['surface']['position']['x'] = int(self.value)
elif name == 'y':
- self.layerNviz['surface']['position']['y'] = int(self.value)
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.layerNviz['surface']['position']['y'] = int(self.value)
elif name == 'z':
- self.layerNviz['surface']['position']['z'] = int(self.value)
+ if self.inTag['nviz'] and self.inTag['surface']:
+ self.layerNviz['surface']['position']['z'] = int(self.value)
elif name == 'color':
- if self.inTag['nviz'] and self.inTag['lines']:
+ if self.inTag['nviz'] and self.inTag['vlines']:
self.layerNviz['vector']['lines']['color'] = str(self.value)
elif name == 'width':
- if self.inTag['nviz'] and self.inTag['lines']:
+ if self.inTag['nviz'] and self.inTag['vlines']:
self.layerNviz['vector']['lines']['width'] = int(self.value)
elif name == 'height':
- if self.inTag['nviz'] and self.inTag['lines']:
+ if self.inTag['nviz'] and self.inTag['vlines']:
self.layerNviz['vector']['lines']['height'] = int(self.value)
elif name == 'color':
- if self.inTag['nviz'] and self.inTag['lines']:
+ if self.inTag['nviz'] and self.inTag['vlines']:
self.layerNviz['vector']['lines']['color'] = str(self.value)
self.inTag[name] = False
@@ -426,6 +438,8 @@
return
self.indent += 4
+ self.file.write('%s<surface>\n' % (' ' * self.indent))
+ self.indent += 4
for attrb in data.iterkeys():
if len(data[attrb]) < 1: # skip empty attributes
continue
@@ -486,6 +500,8 @@
self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
self.indent -= 4
+ self.file.write('%s</surface>\n' % (' ' * self.indent))
+ self.indent -= 4
def __writeNvizVector(self, data):
"""Save Nviz vector layer properties (lines/points) to workspace
@@ -500,7 +516,7 @@
if not data[attrb].has_key('object'): # skip disabled
continue
- self.file.write('%s<%s>\n' % (' ' * self.indent, attrb))
+ self.file.write('%s<v%s>\n' % (' ' * self.indent, attrb))
self.indent += 4
for name in data[attrb].iterkeys():
if name == 'object':
@@ -521,7 +537,7 @@
self.indent -= 4
self.file.write('%s</%s>\n' % (' ' * self.indent, name))
self.indent -= 4
- self.file.write('%s</%s>\n' % (' ' * self.indent, attrb))
+ self.file.write('%s</v%s>\n' % (' ' * self.indent, attrb))
self.indent -= 4
Modified: grass/trunk/gui/wxpython/xml/grass-gxw.dtd
===================================================================
--- grass/trunk/gui/wxpython/xml/grass-gxw.dtd 2008-07-28 13:31:49 UTC (rev 32351)
+++ grass/trunk/gui/wxpython/xml/grass-gxw.dtd 2008-07-28 22:22:28 UTC (rev 32352)
@@ -75,10 +75,16 @@
<!ELEMENT flag EMPTY>
<!ATTLIST flag name CDATA #REQUIRED>
+<!-- *********************** Nviz *********************** -->
+
<!-- nviz layer properties
-->
-<!ELEMENT nviz (attribute*, draw?, position?, lines?)>
+<!ELEMENT nviz (surface? | (vlines | vpoints)?)>
+<!-- nviz surface properties
+-->
+<!ELEMENT surface (attribute*, draw?, position?)>
+
<!-- nviz surface attribute parameter
-->
<!ELEMENT attribute (value)>
@@ -112,7 +118,7 @@
<!-- nviz vector lines element
-->
-<!ELEMENT lines (color?, width?, mode?, height?)>
+<!ELEMENT vlines (color?, width?, mode?, height?)>
<!ELEMENT color (value)>
<!ELEMENT width (value)>
<!ELEMENT height (value)>
More information about the grass-commit
mailing list