[GRASS-SVN] r31991 - in grass/trunk/gui/wxpython: docs gui_modules
nviz
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 4 03:21:06 EDT 2008
Author: martinl
Date: 2008-07-04 03:21:04 -0400 (Fri, 04 Jul 2008)
New Revision: 31991
Added:
grass/trunk/gui/wxpython/docs/wxGUI.Nviz.html
Modified:
grass/trunk/gui/wxpython/docs/Makefile
grass/trunk/gui/wxpython/docs/wxGUI.html
grass/trunk/gui/wxpython/gui_modules/gcmd.py
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/gui_modules/nviz.py
grass/trunk/gui/wxpython/gui_modules/toolbars.py
grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
grass/trunk/gui/wxpython/nviz/load.cpp
grass/trunk/gui/wxpython/nviz/nviz.h
grass/trunk/gui/wxpython/nviz/surface.cpp
Log:
nviz2/wxGUI: various surface-related fixes
wxNviz manual page template added
Modified: grass/trunk/gui/wxpython/docs/Makefile
===================================================================
--- grass/trunk/gui/wxpython/docs/Makefile 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/docs/Makefile 2008-07-04 07:21:04 UTC (rev 31991)
@@ -1,6 +1,9 @@
MODULE_TOPDIR = ../../..
-FILES = wxGUI wxGUI.Vector_Digitizing_Tool wxGUI.Attribute_Table_Manager
+FILES = wxGUI \
+ wxGUI.Vector_Digitizing_Tool \
+ wxGUI.Attribute_Table_Manager \
+ wxGUI.Nviz
include $(MODULE_TOPDIR)/include/Make/Platform.make
include $(MODULE_TOPDIR)/include/Make/Grass.make
Added: grass/trunk/gui/wxpython/docs/wxGUI.Nviz.html
===================================================================
--- grass/trunk/gui/wxpython/docs/wxGUI.Nviz.html (rev 0)
+++ grass/trunk/gui/wxpython/docs/wxGUI.Nviz.html 2008-07-04 07:21:04 UTC (rev 31991)
@@ -0,0 +1,14 @@
+<h2>DESCRIPTION</h2>
+
+TODO
+
+<h2>SEE ALSO</h2>
+
+See also <a href="http://grass.osgeo.org/wiki/WxNVIZ">Wiki</a> page.
+
+<h2>AUTHORS</h2>
+
+Martin Landa, Google Summer of Code 2008 (Mentor: Michael Barton)
+
+<p>
+<i>$Date$</i>
Property changes on: grass/trunk/gui/wxpython/docs/wxGUI.Nviz.html
___________________________________________________________________
Name: svn:mime-type
+ text/html
Name: svn:keywords
+ Author Date Id
Name: svn:eol-style
+ native
Modified: grass/trunk/gui/wxpython/docs/wxGUI.html
===================================================================
--- grass/trunk/gui/wxpython/docs/wxGUI.html 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/docs/wxGUI.html 2008-07-04 07:21:04 UTC (rev 31991)
@@ -399,7 +399,8 @@
<em>
<a href="wxGUI.Vector_Digitizing_Tool.html">Vector digitizing tool</a>,
-<a href="wxGUI.Attribute_Table_Manager.html">Attribute Table Manager</a>
+<a href="wxGUI.Attribute_Table_Manager.html">Attribute Table Manager</a>,
+<a href="wxGUI.Nviz.html">Nviz extension</a>
</em>
<p>
Modified: grass/trunk/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/gui_modules/gcmd.py 2008-07-04 07:21:04 UTC (rev 31991)
@@ -98,12 +98,19 @@
parent=parent)
class DBMError(GException):
- """Exception raised for Attribute Table Manager"""
+ """Attribute Table Manager exception class"""
def __init__(self, message, parent=None):
GException.__init__(self, message,
title=_("Error in Attribute Table Manager"),
parent=parent)
+class NvizError(GException):
+ """Nviz exception class"""
+ def __init__(self, message, parent=None):
+ GException.__init__(self, message,
+ title=_("Nviz error"),
+ parent=parent)
+
class Popen(subprocess.Popen):
"""Subclass subprocess.Popen"""
def recv(self, maxsize=None):
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2008-07-04 07:21:04 UTC (rev 31991)
@@ -2619,6 +2619,17 @@
return
#
+ # add Nviz toolbar and disable 2D display mode tools
+ #
+ self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
+ self.toolbars['map'].Enable2D(False)
+ self.toggleStatus.Enable(False)
+
+ busy = wx.BusyInfo(message=_("Please wait, loading data..."),
+ parent=self)
+ wx.Yield()
+
+ #
# create GL window & NVIZ toolbar
#
if not self.MapWindow3D:
@@ -2627,13 +2638,9 @@
self.nvizToolWin = nviz.NvizToolWindow(self, id=wx.ID_ANY,
mapWindow=self.MapWindow3D)
- #
- # add Nviz toolbar and disable 2D display mode tools
- #
- self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
- self.toolbars['map'].Enable2D(False)
- self.toggleStatus.Enable(False)
+ busy.Destroy()
+
self.nvizToolWin.Show()
#
Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-04 07:21:04 UTC (rev 31991)
@@ -193,7 +193,7 @@
def OnLeftUp(self, event):
self.ReleaseMouse()
- def UpdateMap(self):
+ def UpdateMap(self, render=True):
"""
Updates the canvas anytime there is a change to the
underlaying images or to the geometry of the canvas.
@@ -276,15 +276,40 @@
@todo volumes
"""
for raster in self.Map.GetListOfLayers(l_type='raster', l_active=True):
- id = self.nvizClass.LoadRaster(str(raster.name), None, None)
- # set resolution
- res = UserSettings.Get(group='nviz', key='surface',
- subkey=['draw', 'res-fine'])
- wire = UserSettings.Get(group='nviz', key='surface',
- subkey=['draw', 'res-coarse'])
- self.nvizClass.SetSurfaceRes(id, res, wire)
- self.object[self.Map.GetLayerIndex(raster)] = id
+ self.LoadRaster(raster)
+ def LoadRaster(self, layer):
+ """Load raster"""
+ if layer.type != 'raster':
+ return
+
+ id = self.nvizClass.LoadSurface(str(layer.name), None, None)
+ if id < 0:
+ raise gcmd.NvizError(parent=self.parent,
+ message=_("Unable to load raster map <%s>" % layer.name))
+
+ # set resolution
+ res = UserSettings.Get(group='nviz', key='surface',
+ subkey=['draw', 'res-fine'])
+ wire = UserSettings.Get(group='nviz', key='surface',
+ subkey=['draw', 'res-coarse'])
+ self.nvizClass.SetSurfaceRes(id, res, wire)
+ self.object[self.Map.GetLayerIndex(layer)] = id ### FIXME layer index is not fixed id!
+
+ def UnloadRaster(self, layer):
+ """Unload raster"""
+ if layer.type != 'raster':
+ return
+
+ idx = self.Map.GetLayerIndex(layer) ### FIXME layer index is not fixed id!
+ if not self.object.has_key(idx):
+ return
+
+ if layer.type == 'raster':
+ if self.nvizClass.UnloadSurface(self.object[idx]) == 0:
+ raise gcmd.NvizError(parent=self.parent,
+ message=_("Unable to unload raster map <%s>" % layer.name))
+
def Reset(self):
"""Reset (unload data)"""
self.nvizClass.Reset()
@@ -722,7 +747,7 @@
all = wx.Button(panel, id=wx.ID_ANY, label=_("All"))
all.SetToolTipString(_("Use for all loaded surfaces"))
# self.win['reset'] = reset.GetId()
- # reset.Bind(wx.EVT_BUTTON, self.OnResetView)
+ all.Bind(wx.EVT_BUTTON, self.OnSurfaceModeAll)
gridSizer.Add(item=all, flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
pos=(2, 4))
@@ -740,10 +765,12 @@
elev = wx.CheckBox(parent=panel, id=wx.ID_ANY,
label=_("by elevation"))
+ elev.Enable(False) # TODO: not implemented yet
gridSizer.Add(item=elev, pos=(0, 1))
color = wx.CheckBox(parent=panel, id=wx.ID_ANY,
label=_("by color"))
+ color.Enable(False) # TODO: not implemented yet
gridSizer.Add(item=color, pos=(0, 2))
boxSizer.Add(item=gridSizer, proportion=1,
@@ -768,6 +795,7 @@
initial=0,
min=0,
max=100)
+ x.Enable(False) # TODO: not implemented yet
gridSizer.Add(item=x, pos=(0, 1))
gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
@@ -777,6 +805,7 @@
initial=0,
min=0,
max=100)
+ y.Enable(False) # TODO: not implemented yet
gridSizer.Add(item=y, pos=(0, 3))
gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
@@ -786,6 +815,7 @@
initial=0,
min=0,
max=100)
+ z.Enable(False) # TODO: not implemented yet
gridSizer.Add(item=z, pos=(0, 5))
boxSizer.Add(item=gridSizer, proportion=1,
@@ -1041,17 +1071,26 @@
# draw res
if self.mapWindow.update.has_key('draw-res'):
- coarse, fine = self.mapWindow.update['draw-res']
+ coarse, fine, all = self.mapWindow.update['draw-res']
+ if all:
+ self.mapWindow.nvizClass.SetSurfaceRes(-1, fine, coarse)
+ else:
+ self.mapWindow.nvizClass.SetSurfaceRes(id, fine, coarse)
- self.mapWindow.nvizClass.SetSurfaceRes(id, fine, coarse)
-
# draw style
if self.mapWindow.update.has_key('draw-style'):
- self.mapWindow.nvizClass.SetSurfaceStyle(id, self.mapWindow.update['draw-style'])
-
+ style, all = self.mapWindow.update['draw-style']
+ if all:
+ self.mapWindow.nvizClass.SetSurfaceStyle(-1, style)
+ else:
+ self.mapWindow.nvizClass.SetSurfaceStyle(id, style)
# wire color
if self.mapWindow.update.has_key('draw-color'):
- self.mapWindow.nvizClass.SetWireColor(id, str(self.mapWindow.update['draw-color']))
+ color, all = self.mapWindow.update['draw-color']
+ if all:
+ self.mapWindow.nvizClass.SetWireColor(id, str(color))
+ else:
+ self.mapWindow.nvizClass.SetWireColor(-1, str(color))
self.mapWindow.Refresh(False)
@@ -1152,16 +1191,23 @@
def OnSurfaceResolution(self, event):
"""Draw resolution changed"""
+ self.SetSurfaceResolution()
+
+ def SetSurfaceResolution(self, all=False, apply=True):
+ """Set draw resolution"""
coarse = self.FindWindowById(self.win['surface']['draw']['res-coarse']).GetValue()
fine = self.FindWindowById(self.win['surface']['draw']['res-fine']).GetValue()
- self.mapWindow.update['draw-res'] = (coarse, fine)
+ self.mapWindow.update['draw-res'] = (coarse, fine, all)
- if self.parent.autoRender.IsChecked():
+ if apply and self.parent.autoRender.IsChecked():
self.OnApply(None)
- def SetSurfaceMode(self):
- """Set draw mode"""
+ def SetSurfaceMode(self, apply=True, all=False):
+ """Set draw mode
+
+ @param apply allow auto-rendering
+ """
value = 0
mode = self.FindWindowById(self.win['surface']['draw']['mode']).GetSelection()
@@ -1190,20 +1236,27 @@
else: # surface
value |= wxnviz.DM_GOURAUD
- self.mapWindow.update['draw-style'] = value
+ self.mapWindow.update['draw-style'] = (value, all)
- if self.parent.autoRender.IsChecked():
+ if apply and self.parent.autoRender.IsChecked():
self.OnApply(None)
def OnSurfaceMode(self, event):
"""Set draw mode"""
self.SetSurfaceMode()
- def SetSurfaceWireColor(self, color):
+ def OnSurfaceModeAll(self, event):
+ """Set draw mode (including wire color) for all loaded surfaces"""
+ self.SetSurfaceMode(apply=False, all=True)
+ self.SetSurfaceResolution(apply=False, all=True)
+ color = self.FindWindowById(self.win['surface']['draw']['color']).GetColour()
+ self.SetSurfaceWireColor(color, all=True)
+
+ def SetSurfaceWireColor(self, color, all=False):
"""Set wire color"""
value = str(color[0]) + ':' + str(color[1]) + ':' + str(color[2])
- self.mapWindow.update['draw-color'] = value
+ self.mapWindow.update['draw-color'] = (value, all)
if self.parent.autoRender.IsChecked():
self.OnApply(None)
Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-07-04 07:21:04 UTC (rev 31991)
@@ -1047,8 +1047,10 @@
)
def OnSettings(self, event):
- pass
-
+ win = self.parent.nvizToolWin
+ if not win.IsShown():
+ self.parent.nvizToolWin.Show()
+
def OnExit (self, event=None):
"""Quit nviz tool (swith to 2D mode)"""
Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py 2008-07-04 07:21:04 UTC (rev 31991)
@@ -800,7 +800,7 @@
event.Skip()
def OnLayerChecked(self, event):
- """Enable/disable given layer item"""
+ """Enable/disable data layer"""
item = event.GetItem()
checked = item.IsChecked()
@@ -818,6 +818,16 @@
# update progress bar range (mapwindow statusbar)
self.mapdisplay.onRenderGauge.SetRange(len(self.Map.GetListOfLayers(l_active=True)))
+ if self.mapdisplay.toolbars['nviz']:
+ # nviz - load/unload data layer
+ mapLayer = self.GetPyData(item)[0]['maplayer']
+ if checked: # enable
+ if mapLayer.type == 'raster':
+ self.mapdisplay.MapWindow.LoadRaster(mapLayer)
+ else: # disable
+ if mapLayer.type == 'raster':
+ self.mapdisplay.MapWindow.UnloadRaster(mapLayer)
+
# redraw map if auto-rendering is enabled
if self.mapdisplay.autoRender.GetValue():
self.mapdisplay.OnRender(None)
Modified: grass/trunk/gui/wxpython/nviz/load.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/load.cpp 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/nviz/load.cpp 2008-07-04 07:21:04 UTC (rev 31991)
@@ -32,7 +32,7 @@
\return object id
\return -1 on failure
*/
-int Nviz::LoadRaster(const char* name, const char *color_name, const char *color_value)
+int Nviz::LoadSurface(const char* name, const char *color_name, const char *color_value)
{
char *mapset;
int id;
@@ -85,3 +85,23 @@
return id;
}
+
+/*!
+ \brief Unload surface
+
+ \param id surface id
+
+ \return 1 on success
+ \return 0 on failure
+*/
+int Nviz::UnloadSurface(int id)
+{
+ if (!GS_surf_exists(id)) {
+ return 0;
+ }
+
+ if (GS_delete_surface(id) < 0)
+ return 0;
+
+ return 1;
+}
Modified: grass/trunk/gui/wxpython/nviz/nviz.h
===================================================================
--- grass/trunk/gui/wxpython/nviz/nviz.h 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/nviz/nviz.h 2008-07-04 07:21:04 UTC (rev 31991)
@@ -62,7 +62,8 @@
void SetLightsDefault();
/* load.cpp */
- int LoadRaster(const char*, const char *, const char *);
+ int LoadSurface(const char*, const char *, const char *);
+ int UnloadSurface(int);
/* draw.cpp */
void Draw(bool);
Modified: grass/trunk/gui/wxpython/nviz/surface.cpp
===================================================================
--- grass/trunk/gui/wxpython/nviz/surface.cpp 2008-07-04 01:15:39 UTC (rev 31990)
+++ grass/trunk/gui/wxpython/nviz/surface.cpp 2008-07-04 07:21:04 UTC (rev 31991)
@@ -227,13 +227,18 @@
*/
int Nviz::SetSurfaceRes(int id, int fine, int coarse)
{
- if (!GS_surf_exists(id)) {
- return 0;
- }
+ if (id > 0) {
+ if (!GS_surf_exists(id)) {
+ return 0;
+ }
- if (GS_set_drawres(id, fine, fine, coarse, coarse) < 0) {
- return 0;
+ if (GS_set_drawres(id, fine, fine, coarse, coarse) < 0) {
+ return 0;
+ }
}
+ else {
+ GS_setall_drawres(fine, fine, coarse, coarse);
+ }
return 1;
}
@@ -283,19 +288,35 @@
\todo all
- \param surface id
+ \param surface id (< 0 for all)
\param color color string (R:G:B)
\return 1 on success
\return 0 on failure
*/
-int Nviz::SetWireColor(int id, const char* color)
+int Nviz::SetWireColor(int id, const char* color_str)
{
- if (!GS_surf_exists(id)) {
- return 0;
+ int color;
+
+ color = Nviz_color_from_str(color_str);
+
+ if (id > 0) {
+ if (!GS_surf_exists(id)) {
+ return 0;
+ }
+ GS_set_wire_color(id, color);
}
+ else {
+ int *surf_list, nsurfs, id;
- GS_set_wire_color(id, Nviz_color_from_str(color));
+ surf_list = GS_get_surf_list(&nsurfs);
+ for (int i = 0; i < nsurfs; i++) {
+ id = surf_list[i];
+ GS_set_wire_color(id, color);
+ }
+ G_free(surf_list);
+ }
+
return 1;
}
More information about the grass-commit
mailing list