[GRASS-SVN] r42689 - in grass/branches/develbranch_6:
gui/wxpython/gui_modules include lib/nviz lib/ogsf
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 1 07:51:26 EDT 2010
Author: martinl
Date: 2010-07-01 11:51:26 +0000 (Thu, 01 Jul 2010)
New Revision: 42689
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
grass/branches/develbranch_6/include/nviz.h
grass/branches/develbranch_6/lib/nviz/nviz.c
grass/branches/develbranch_6/lib/ogsf/GS2.c
Log:
wxNviz: various bugfixes, raster querying in progress
(merge r42683 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/__init__.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -23,7 +23,7 @@
"menudata.py",
"menuform.py",
"nviz_mapdisp.py",
- "nviz.py",
+ "nviz_preferences.py",
"nviz_tools.py",
"ogc_services.py",
"preferences.py",
@@ -37,4 +37,5 @@
"vclean.py",
"vdigit.py",
"workspace.py",
+ "wxnviz.py",
]
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -82,17 +82,14 @@
cmdfilename = None
class MapFrame(wx.Frame):
+ """!Main frame for map display window. Drawing takes place in
+ child double buffered drawing window.
"""
- Main frame for map display window. Drawing takes place in child double buffered
- drawing window.
- """
-
def __init__(self, parent=None, id=wx.ID_ANY, title=_("GRASS GIS - Map display"),
style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"],
tree=None, notebook=None, lmgr=None, page=None,
Map=None, auimgr=None, **kwargs):
- """
- Main map display window with toolbars, statusbar and
+ """!Main map display window with toolbars, statusbar and
DrawWindow
@param toolbars array of activated toolbars, e.g. ['map', 'digit']
@@ -111,9 +108,11 @@
self.layerbook = notebook # Layer Manager layer tree notebook
self.parent = parent
- #
+ if not kwargs.has_key('name'):
+ kwargs['name'] = 'MapWindow'
+ wx.Frame.__init__(self, parent, id, title, style = style, **kwargs)
+
# available cursors
- #
self.cursors = {
# default: cross
# "default" : wx.StockCursor(wx.CURSOR_DEFAULT),
@@ -124,10 +123,6 @@
"sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
}
- if not kwargs.has_key('name'):
- kwargs['name'] = 'MapWindow'
- wx.Frame.__init__(self, parent, id, title, style = style, **kwargs)
-
#
# set the size & system icon
#
@@ -248,7 +243,6 @@
Map=self.Map, tree=self.tree, lmgr=self._layerManager)
# default is 2D display mode
self.MapWindow = self.MapWindow2D
- self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
self.MapWindow.SetCursor(self.cursors["default"])
# used by Nviz (3D display mode)
self.MapWindow3D = None
@@ -419,6 +413,7 @@
self.MapWindow3D = nviz.GLWindow(self, id=wx.ID_ANY,
Map=self.Map, tree=self.tree, lmgr=self._layerManager)
self.MapWindow = self.MapWindow3D
+ self.MapWindow.SetCursor(self.cursors["default"])
# add Nviz notebookpage
self._layerManager.AddNviz()
@@ -534,86 +529,20 @@
self.layerbook.SetSelection(pgnum)
event.Skip()
-
- def OnMotion(self, event):
- """
- Mouse moved
- Track mouse motion and update status bar
- """
- # update statusbar if required
- if self.statusbarWin['toggle'].GetSelection() == 0: # Coordinates
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
- format = UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'll')
- try:
- e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
- except AttributeError:
- return
- if self.toolbars['vdigit'] and \
- self.toolbars['vdigit'].GetAction() == 'addLine' and \
- self.toolbars['vdigit'].GetAction('type') in ('line', 'boundary') and \
- len(self.MapWindow.polycoords) > 0:
- # for linear feature show segment and total length
- distance_seg = self.MapWindow.Distance(self.MapWindow.polycoords[-1],
- (e, n), screen=False)[0]
- distance_tot = distance_seg
- for idx in range(1, len(self.MapWindow.polycoords)):
- distance_tot += self.MapWindow.Distance(self.MapWindow.polycoords[idx-1],
- self.MapWindow.polycoords[idx],
- screen=False )[0]
- self.statusbar.SetStatusText("%.*f, %.*f (seg: %.*f; tot: %.*f)" % \
- (precision, e, precision, n,
- precision, distance_seg,
- precision, distance_tot), 0)
- else:
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- proj, coord = utils.ReprojectCoordinates(coord = (e, n),
- projOut = UserSettings.Get(group='projection',
- key='statusbar',
- subkey='proj4'),
- flags = 'd')
-
- if coord:
- e, n = coord
- if proj in ('ll', 'latlong', 'longlat') and format == 'DMS':
- self.statusbar.SetStatusText("%s" % \
- utils.Deg2DMS(e, n, precision = precision),
- 0)
- else:
- self.statusbar.SetStatusText("%.*f; %.*f" % \
- (precision, e, precision, n), 0)
- else:
- self.statusbar.SetStatusText(_("Error in projection (check the settings)"), 0)
- else:
- if self.Map.projinfo['proj'] == 'll' and format == 'DMS':
- self.statusbar.SetStatusText("%s" % \
- utils.Deg2DMS(e, n, precision = precision),
- 0)
- else:
- self.statusbar.SetStatusText("%.*f; %.*f" % \
- (precision, e, precision, n), 0)
-
- event.Skip()
-
+
def OnDraw(self, event):
+ """!Re-display current map composition
"""
- Re-display current map composition
- """
- self.MapWindow.UpdateMap(render=False)
+ self.MapWindow.UpdateMap(render = False)
def OnRender(self, event):
+ """!Re-render map composition (each map layer)
"""
- Re-render map composition (each map layer)
- """
# delete tmp map layers (queries)
qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)
for layer in qlayer:
self.Map.DeleteLayer(layer)
-
+
# delete tmp lines
if self.MapWindow.mouse["use"] in ("measure",
"profile"):
@@ -631,9 +560,8 @@
self.StatusbarUpdate()
def OnPointer(self, event):
+ """!Pointer button clicked
"""
- Pointer button clicked
- """
if self.toolbars['map']:
if event:
self.toolbars['map'].OnTool(event)
@@ -1270,9 +1198,8 @@
return self.MapWindow
def OnQueryDisplay(self, event):
+ """!Query currrent raster/vector map layers (display mode)
"""
- Query currrent raster/vector map layers (display mode)
- """
if self.toolbars['map'].GetAction() == 'displayAttrb': # select previous action
self.toolbars['map'].SelectDefault(event)
return
@@ -1309,7 +1236,7 @@
def QueryMap(self, x, y):
"""!Query map layer features
-
+
Currently only raster and vector map layers are supported.
@param x,y coordinates
@@ -1317,7 +1244,7 @@
#set query snap distance for v.what at mapunit equivalent of 10 pixels
qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / self.Map.width)
east, north = self.MapWindow.Pixel2Cell((x, y))
-
+
num = 0
for layer in self.tree.GetSelections():
type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
@@ -1326,10 +1253,10 @@
num += 1
if num < 1:
- dlg = wx.MessageDialog(parent=self,
- message=_('No raster or vector map layer selected for querying.'),
- caption=_('No map layer selected'),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
+ dlg = wx.MessageDialog(parent = self,
+ message = _('No raster or vector map layer selected for querying.'),
+ caption = _('No map layer selected'),
+ style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
dlg.ShowModal()
dlg.Destroy()
return
@@ -1349,7 +1276,7 @@
raststr += "%s," % name
elif type in ('vector', 'thememap', 'themechart'):
vectstr += "%s," % name
-
+
# use display region settings instead of computation region settings
self.tmpreg = os.getenv("GRASS_REGION")
os.environ["GRASS_REGION"] = self.Map.SetRegion(windres=False)
@@ -1373,7 +1300,7 @@
continue
vect.append(vector)
vectstr = ','.join(vect)
-
+
if len(vectstr) <= 1:
self._layerManager.goutput.WriteCmdLog("Nothing to query.")
return
@@ -1663,11 +1590,9 @@
style)
def MeasureDist(self, beginpt, endpt):
- """
- Calculate map distance from screen distance
+ """!Calculate map distance from screen distance
and print to output window
"""
-
if self._layerManager.notebook.GetSelection() != 1:
self._layerManager.notebook.SetSelection(1)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -45,23 +45,20 @@
from vdigit import PseudoDC as VDigitPseudoDC
class MapWindow(object):
- """!
- Abstract map window class
+ """!Abstract map window class
Parent for BufferedWindow class (2D display mode) and
GLWindow (3D display mode)
"""
def __init__(self, parent, id = wx.ID_ANY,
- Map = None, tree = None, lmgr = None):
+ Map = None, tree = None, lmgr = None, **kwargs):
self.parent = parent # MapFrame
self.Map = Map
self.tree = tree
self.lmgr = lmgr
- #
# mouse attributes -- position on the screen, begin and end of
# dragging, and type of drawing
- #
self.mouse = {
'begin': [0, 0], # screen coordinates
'end' : [0, 0],
@@ -70,14 +67,12 @@
}
def EraseMap(self):
- """!
- Erase the canvas (virtual method)
+ """!Erase the canvas (virtual method)
"""
pass
def UpdateMap(self):
- """!
- Updates the canvas anytime there is a change to the
+ """!Updates the canvas anytime there is a change to the
underlaying images or to the geometry of the canvas.
"""
pass
@@ -91,8 +86,66 @@
def OnKeyDown(self, event):
pass
- def OnMouseMotion(self, event):
- pass
+ def OnMotion(self, event):
+ """!Mouse moved
+ Track mouse motion and update status bar
+ """
+ if self.parent.statusbarWin['toggle'].GetSelection() == 0: # Coordinates
+ precision = int(UserSettings.Get(group = 'projection', key = 'format',
+ subkey = 'precision'))
+ format = UserSettings.Get(group = 'projection', key = 'format',
+ subkey = 'll')
+ try:
+ e, n = self.Pixel2Cell(event.GetPositionTuple())
+ except (TypeError, ValueError):
+ self.parent.statusbar.SetStatusText("", 0)
+ return
+
+ if self.parent.toolbars['vdigit'] and \
+ self.parent.toolbars['vdigit'].GetAction() == 'addLine' and \
+ self.parent.toolbars['vdigit'].GetAction('type') in ('line', 'boundary') and \
+ len(self.polycoords) > 0:
+ # for linear feature show segment and total length
+ distance_seg = self.Distance(self.polycoords[-1],
+ (e, n), screen=False)[0]
+ distance_tot = distance_seg
+ for idx in range(1, len(self.polycoords)):
+ distance_tot += self.Distance(self.polycoords[idx-1],
+ self.polycoords[idx],
+ screen=False )[0]
+ self.parent.statusbar.SetStatusText("%.*f, %.*f (seg: %.*f; tot: %.*f)" % \
+ (precision, e, precision, n,
+ precision, distance_seg,
+ precision, distance_tot), 0)
+ else:
+ if self.parent.statusbarWin['projection'].IsChecked():
+ if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
+ self.parent.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
+ else:
+ proj, coord = utils.ReprojectCoordinates(coord = (e, n),
+ projOut = UserSettings.Get(group='projection',
+ key='statusbar',
+ subkey='proj4'),
+ flags = 'd')
+
+ if coord:
+ e, n = coord
+ if proj in ('ll', 'latlong', 'longlat') and format == 'DMS':
+ self.parent.statusbar.SetStatusText(utils.Deg2DMS(e, n, precision = precision),
+ 0)
+ else:
+ self.parent.statusbar.SetStatusText("%.*f; %.*f" % \
+ (precision, e, precision, n), 0)
+ else:
+ self.parent.statusbar.SetStatusText(_("Error in projection (check the settings)"), 0)
+ else:
+ if self.parent.Map.projinfo['proj'] == 'll' and format == 'DMS':
+ self.parent.statusbar.SetStatusText(utils.Deg2DMS(e, n, precision = precision),
+ 0)
+ else:
+ self.parent.statusbar.SetStatusText("%.*f; %.*f" % \
+ (precision, e, precision, n), 0)
+ event.Skip()
def OnZoomToMap(self, event):
pass
@@ -101,8 +154,7 @@
pass
def GetSelectedLayer(self, type = 'layer', multi = False):
- """!
- Get selected layer from layer tree
+ """!Get selected layer from layer tree
@param type 'item' / 'layer' / 'nviz'
@param multi return first selected layer or all
@@ -148,8 +200,7 @@
return ret
class BufferedWindow(MapWindow, wx.Window):
- """!
- A Buffered window class.
+ """!A Buffered window class.
When the drawing needs to change, you app needs to call the
UpdateMap() method. Since the drawing is stored in a bitmap, you
@@ -157,9 +208,9 @@
SaveToFile(self,file_name,file_type) method.
"""
def __init__(self, parent, id = wx.ID_ANY,
- style = wx.NO_FULL_REPAINT_ON_RESIZE,
- Map = None, tree = None, lmgr = None, **kwargs):
- MapWindow.__init__(self, parent, id, Map, tree, lmgr)
+ Map = None, tree = None, lmgr = None,
+ style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs):
+ MapWindow.__init__(self, parent, id, Map, tree, lmgr, **kwargs)
wx.Window.__init__(self, parent, id, style = style, **kwargs)
# flags
@@ -180,8 +231,10 @@
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Bind(wx.EVT_IDLE, self.OnIdle)
- self.Bind(wx.EVT_MOTION, self.MouseActions)
+ ### self.Bind(wx.EVT_MOTION, self.MouseActions)
self.Bind(wx.EVT_MOUSE_EVENTS, self.MouseActions)
+ self.Bind(wx.EVT_MOTION, self.OnMotion)
+
self.processMouse = True
# render output objects
@@ -1842,8 +1895,7 @@
self.UpdateMap(render=False)
def OnLeftUp(self, event):
- """!
- Left mouse button released
+ """!Left mouse button released
"""
Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
self.mouse["use"])
@@ -2406,61 +2458,52 @@
return True
def Pixel2Cell(self, (x, y)):
- """!
- Convert image coordinates to real word coordinates
+ """!Convert image coordinates to real word coordinates
- Input : int x, int y
- Output: float x, float y
+ @param x, y image coordinates
+
+ @return easting, northing
+ @return None on error
"""
-
try:
x = int(x)
y = int(y)
except:
return None
-
+
if self.Map.region["ewres"] > self.Map.region["nsres"]:
res = self.Map.region["ewres"]
else:
res = self.Map.region["nsres"]
-
+
w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
+
east = w + x * res
north = n - y * res
-
- # extent does not correspond with whole map canvas area...
- # east = self.Map.region['w'] + x * self.Map.region["ewres"]
- # north = self.Map.region['n'] - y * self.Map.region["nsres"]
-
+
return (east, north)
def Cell2Pixel(self, (east, north)):
- """!
- Convert real word coordinates to image coordinates
+ """!Convert real word coordinates to image coordinates
"""
-
try:
east = float(east)
north = float(north)
except:
return None
-
+
if self.Map.region["ewres"] > self.Map.region["nsres"]:
res = self.Map.region["ewres"]
else:
res = self.Map.region["nsres"]
-
+
w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- # x = int((east - w) / res)
- # y = int((n - north) / res)
-
+
x = (east - w) / res
y = (n - north) / res
-
+
return (x, y)
def Zoom(self, begin, end, zoomtype):
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -21,6 +21,7 @@
import sys
import time
import copy
+import math
from threading import Thread
@@ -70,7 +71,6 @@
"""!OpenGL canvas for Map Display Window"""
def __init__(self, parent, id = wx.ID_ANY,
Map = None, tree = None, lmgr = None):
-
self.parent = parent # MapFrame
glcanvas.GLCanvas.__init__(self, parent, id)
@@ -88,7 +88,9 @@
'vpoints' : False }
# list of loaded map layers (layer tree items)
- self.layers = []
+ self.layers = list()
+ # list of query points
+ self.qpoints = list()
#
# use display region instead of computational
@@ -124,14 +126,12 @@
self.nvizDefault = NvizDefault()
self.light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
- self.size = None
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
- self.Bind(wx.EVT_SIZE, self.OnSize)
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
- self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
- self.Bind(wx.EVT_MOTION, self.OnMouseAction)
- self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseAction)
+ self.Bind(wx.EVT_SIZE, self.OnSize)
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+ self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
+ self.Bind(wx.EVT_MOUSE_EVENTS, self.OnMouseAction)
+ self.Bind(wx.EVT_MOTION, self.OnMotion)
self.Bind(EVT_UPDATE_PROP, self.UpdateMapObjProperties)
self.Bind(EVT_UPDATE_VIEW, self.UpdateView)
@@ -147,13 +147,13 @@
pass # do nothing, to avoid flashing on MSW
def OnSize(self, event):
- self.size = self.GetClientSize()
+ size = self.GetClientSize()
if self.GetContext():
Debug.msg(3, "GLCanvas.OnSize(): w = %d, h = %d" % \
- (self.size.width, self.size.height))
+ (size.width, size.height))
self.SetCurrent()
- self._display.ResizeWindow(self.size.width,
- self.size.height)
+ self._display.ResizeWindow(size.width,
+ size.height)
event.Skip()
@@ -196,13 +196,6 @@
self.UpdateMap()
def OnMouseAction(self, event):
- # change position
- if event.Dragging() and event.LeftIsDown():
- ### self.lastX = self.lastY = self.x = self.y
- ### self.x, self.y = event.GetPosition()
- ### self.Refresh(False)
- pass
-
# change perspective with mouse wheel
wheel = event.GetWheelRotation()
@@ -234,12 +227,62 @@
# update statusbar
### self.parent.StatusbarUpdate()
-
- def OnLeftDown(self, event):
- self.CaptureMouse()
-
+
+ event.Skip()
+
+ def Pixel2Cell(self, (x, y)):
+ """!Convert image coordinates to real word coordinates
+
+ @param x, y image coordinates
+
+ @return easting, northing
+ @return None on error
+ """
+ size = self.GetClientSize()
+ # UL -> LL
+ sid, x, y, z = self._display.GetPointOnSurface(x, y)
+
+ if not sid:
+ return None
+
+ return (x, y)
+
def OnLeftUp(self, event):
self.ReleaseMouse()
+ if self.mouse["use"] == "query":
+ result = self._display.QueryMap(event.GetX(), event.GetY())
+ log = self.lmgr.goutput
+ if result:
+ self.qpoints.append((result['x'], result['y'], result['z']))
+ log.WriteLog("%-30s: %.3f" % (_("Easting"), result['x']))
+ log.WriteLog("%-30s: %.3f" % (_("Northing"), result['y']))
+ log.WriteLog("%-30s: %.3f" % (_("Elevation"), result['z']))
+ log.WriteLog("%-30s: %s" % (_("Surface map elevation"), result['elevation']))
+ log.WriteLog("%-30s: %s" % (_("Surface map color"), result['color']))
+ if len(self.qpoints) > 1:
+ prev = self.qpoints[-2]
+ curr = self.qpoints[-1]
+ dxy = math.sqrt(pow(prev[0]-curr[0], 2) +
+ pow(prev[1]-curr[1], 2))
+ dxyz = math.sqrt(pow(prev[0]-curr[0], 2) +
+ pow(prev[1]-curr[1], 2) +
+ pow(prev[2]-curr[2], 2))
+ log.WriteLog("%-30s: %.3f" % (_("XY distance from previous"), dxy))
+ log.WriteLog("%-30s: %.3f" % (_("XYZ distance from previous"), dxyz))
+ log.WriteLog("%-30s: %.3f" % (_("Distance along surface"),
+ self._display.GetDistanceAlongSurface(result['id'],
+ (curr[0], curr[1]),
+ (prev[0], prev[1]),
+ useExag = False)))
+ log.WriteLog("%-30s: %.3f" % (_("Distance along exag. surface"),
+ self._display.GetDistanceAlongSurface(result['id'],
+ (curr[0], curr[1]),
+ (prev[0], prev[1]),
+ useExag = True)))
+ log.WriteLog('-' * 80)
+ else:
+ log.WriteLog(_("No point on surface"))
+ log.WriteLog('-' * 80)
def UpdateView(self, event):
"""!Change view settings"""
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -8,7 +8,6 @@
- PositionWindow
- ViewPositionWindow
- LightPositionWindow
- - NvizPreferencesDialog
(C) 2008-2010 by the GRASS Development Team
@@ -36,15 +35,10 @@
import gselect
import gcmd
from preferences import globalSettings as UserSettings
-from preferences import PreferencesBaseDialog
from nviz_mapdisp import wxUpdateView, wxUpdateLight, wxUpdateProperties
from debug import Debug
-try:
- sys.path.append(os.path.join(globalvar.ETCWXDIR, "nviz"))
- import grass6_wxnviz as wxnviz
-except ImportError:
- pass
+import wxnviz
class NvizToolWindow(FN.FlatNotebook):
"""!Nviz (3D view) tools panel
@@ -258,8 +252,13 @@
def _createDataPage(self):
"""!Create data (surface, vector, volume) settings page"""
- self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
- style = globalvar.FNPageDStyle)
+ if globalvar.hasAgw:
+ self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
+ agwStyle = globalvar.FNPageDStyle)
+ else:
+ self.notebookData = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
+ agwStyle = globalvar.FNPageDStyle)
+
# surface page
self.notebookData.AddPage(page = self._createSurfacePage(),
text = " %s " % _("Surface"))
@@ -274,8 +273,13 @@
def _createAppearancePage(self):
"""!Create data (surface, vector, volume) settings page"""
- self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
- style = globalvar.FNPageDStyle)
+ if globalvar.hasAgw:
+ self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
+ agwStyle = globalvar.FNPageDStyle)
+ else:
+ self.notebookAppearance = FN.FlatNotebook(parent = self, id = wx.ID_ANY,
+ style = globalvar.FNPageDStyle)
+
# light page
self.notebookAppearance.AddPage(page = self._createLightPage(),
text = " %s " % _("Lighting"))
@@ -2853,6 +2857,7 @@
if event.LeftUp():
self.mapWindow.render['quick'] = False
self.mapWindow.Refresh(eraseBackground = False)
+<<<<<<< .working
class NvizPreferencesDialog(PreferencesBaseDialog):
"""!Nviz preferences dialog"""
@@ -3362,4 +3367,3 @@
UserSettings.Set(group = 'nviz', value = nvsettings)
file = UserSettings.SaveToFile()
self.parent.goutput.WriteLog(_('Nviz settings saved to file <%s>.') % file)
-
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -26,6 +26,7 @@
import sys
import copy
import stat
+import types
try:
import pwd
havePwd = True
@@ -458,6 +459,9 @@
'z-exag' : {
'step' : 1,
},
+ 'background' : {
+ 'color' : (255, 255, 255, 255), # white
+ },
},
'surface' : {
'shine': {
@@ -514,22 +518,14 @@
'value' : 60.0,
},
},
- 'settings': {
- 'general' : {
- 'bgcolor' : (255, 255, 255, 255), # white
- },
- },
- 'light' : {
- 'color' : (255, 255, 255, 255), # white
- },
'light' : {
'pos' : {
'x' : 0.68,
'y' : 0.68,
'z' : 80,
},
- 'color' : (255, 255, 255, 255), # white
- 'bright' : 80,
+ 'color' : (255, 255, 255, 255), # white
+ 'bright' : 80,
'ambient' : 20,
},
'fringe' : {
@@ -881,16 +877,21 @@
@param subkey subkey (value or list)
@param value value
"""
+ print dict
+ print group, key, subkey, value
+ print 'x'
if not dict.has_key(group):
dict[group] = {}
if not dict[group].has_key(key):
dict[group][key] = {}
- if type(subkey) == type([]):
+ if type(subkey) == types.ListType:
# TODO: len(subkey) > 2
if not dict[group][key].has_key(subkey[0]):
dict[group][key][subkey[0]] = {}
+ print group, key, subkey, value
+ print dict[group][key]
dict[group][key][subkey[0]][subkey[1]] = value
else:
dict[group][key][subkey] = value
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -39,7 +39,7 @@
from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
from debug import Debug as Debug
from preferences import globalSettings as UserSettings
-from nviz_tools import NvizPreferencesDialog
+from nviz_preferences import NvizPreferencesDialog
gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
sys.path.append(gmpath)
@@ -301,7 +301,6 @@
def Enable2D(self, enabled):
"""!Enable/Disable 2D display mode specific tools"""
for tool in (self.pointer,
- self.query,
self.pan,
self.zoomin,
self.zoomout,
@@ -1435,12 +1434,6 @@
(self.relation, 'relation', Icons['modelRelation'].GetBitmap(),
wx.ITEM_NORMAL, Icons['modelRelation'].GetLabel(), Icons['modelRelation'].GetDesc(),
self.parent.OnDefineRelation),
- # (self.properties, "properties", Icons["modelProperties"].GetBitmap(),
- # wx.ITEM_NORMAL, Icons["modelProperties"].GetLabel(), Icons["modelProperties"].GetDesc(),
- # self.parent.OnModelProperties),
- (self.variables, "variables", Icons["modelVariables"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["modelVariables"].GetLabel(), Icons["modelVariables"].GetDesc(),
- self.parent.OnModelVariables),
('', '', '', '', '', '', ''),
(self.run, 'run', Icons['modelRun'].GetBitmap(),
wx.ITEM_NORMAL, Icons['modelRun'].GetLabel(), Icons['modelRun'].GetDesc(),
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxnviz.py 2010-07-01 11:51:26 UTC (rev 42689)
@@ -146,8 +146,8 @@
def EraseMap(self):
"""!Erase map display (with background color)
"""
- GS_clear(self.data.bgcolor)
Debug.msg(1, "Nviz::EraseMap()")
+ GS_clear(Nviz_get_bgcolor(self.data))
def InitView(self):
"""!Initialize view"""
@@ -159,6 +159,7 @@
# set background color
Nviz_set_bgcolor(self.data, Nviz_color_from_str("white"))
+ GS_clear(Nviz_get_bgcolor(self.data))
# initialize view, lights
Nviz_init_view(self.data)
@@ -554,12 +555,12 @@
@return -2 setting attributes failed
"""
Debug.msg(3, "Nviz::SetSurfaceRes(): id=%d, fine=%d, coarse=%d",
- id, fine, coarse)
+ id, fine, coarse)
if id > 0:
if not GS_surf_exists(id):
return -1
-
+
if GS_set_drawres(id, fine, fine, coarse, coarse) < 0:
return -2
else:
@@ -1126,3 +1127,49 @@
Nviz_set_fringe(self.data,
sid, Nviz_color_from_str(scolor),
elev, int(nw), int(ne), int(sw), int(se))
+
+ def GetPointOnSurface(self, sx, sy):
+ """!Get point on surface
+
+ @param sx,sy canvas coordinates (LL)
+ """
+ sid = c_int()
+ x = c_float()
+ y = c_float()
+ z = c_float()
+ Debug.msg(5, "GLWindow.GetPointOnSurface(): sx=%d sy=%d" % (sx, sy))
+ num = GS_get_selected_point_on_surface(sx, sy, byref(sid), byref(x), byref(y), byref(z))
+ if num == 0:
+ return (None, None, None, None)
+
+ return (sid.value, x.value, y.value, z.value)
+
+ def QueryMap(self, sx, sy):
+ """!Query surface map
+
+ @param sx,sy canvas coordinates (LL)
+ """
+ sid, x, y, z = self.GetPointOnSurface(sx, sy)
+ if not sid:
+ return None
+
+ catstr = c_char * 256
+ valstr = c_char * 256
+ #GS_get_cat_at_xy(sid, MAP_ATT, pointer(catstr), x, y)
+ #GS_get_val_at_xy(sid, MAP_ATT, pointer(valstr), x, y)
+
+ return { 'id' : sid,
+ 'x' : x,
+ 'y' : y,
+ 'z' : z,
+ 'elevation' : catstr.value,
+ 'color' : valstr.value }
+
+ def GetDistanceAlongSurface(self, sid, p1, p2, useExag = True):
+ """!Get distance measured along surface"""
+ d = c_float()
+
+ GS_get_distance_alongsurf(sid, p1[0], p1[1], p2[0], p2[1],
+ byref(d), int(useExag))
+
+ return d.value
Modified: grass/branches/develbranch_6/include/nviz.h
===================================================================
--- grass/branches/develbranch_6/include/nviz.h 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/include/nviz.h 2010-07-01 11:51:26 UTC (rev 42689)
@@ -171,6 +171,7 @@
void Nviz_init_data(nv_data *);
void Nviz_destroy_data(nv_data *);
void Nviz_set_bgcolor(nv_data *, int);
+int Nviz_get_bgcolor(nv_data *);
int Nviz_color_from_str(const char *);
struct fringe_data *Nviz_new_fringe(nv_data *, int, unsigned long,
double, int, int, int, int);
Modified: grass/branches/develbranch_6/lib/nviz/nviz.c
===================================================================
--- grass/branches/develbranch_6/lib/nviz/nviz.c 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/lib/nviz/nviz.c 2010-07-01 11:51:26 UTC (rev 42689)
@@ -77,6 +77,18 @@
}
/*!
+ \brief Get background color
+
+ \param data nviz data
+
+ \return color color value
+ */
+int Nviz_get_bgcolor(nv_data * data)
+{
+ return data->bgcolor;
+}
+
+/*!
\brief Get color value from color string (name or RGB triplet)
\param color_str color string
Modified: grass/branches/develbranch_6/lib/ogsf/GS2.c
===================================================================
--- grass/branches/develbranch_6/lib/ogsf/GS2.c 2010-07-01 11:49:10 UTC (rev 42688)
+++ grass/branches/develbranch_6/lib/ogsf/GS2.c 2010-07-01 11:51:26 UTC (rev 42689)
@@ -1146,23 +1146,23 @@
return (-1);
}
-#define CATSREADY
-#ifdef CATSREADY
/*!
- \brief Print categories on given position
+ \brief Get surface category on given position
- prints "no data" or a description (i.e., "coniferous forest") to catstr
- Usually call after GS_get_selected_point_on_surface
- att_src must be MAP_ATT
+ Prints "no data" or a description (i.e., "coniferous forest") to
+ <i>catstr</i>. Usually call after GS_get_selected_point_on_surface().
+ Define <i>att</i> as MAP_ATT
+ \todo Allocate catstr using G_store()
+
\param id surface id
- \param att
+ \param att attribute id (MAP_ATT)
\param catstr cat string (must be allocated, dim?)
\param x,y real coordinates
\return -1 if no category info or point outside of window
\return 1 on success
- */
+*/
int GS_get_cat_at_xy(int id, int att, char *catstr, float x, float y)
{
int offset, drow, dcol, vrow, vcol;
@@ -1174,7 +1174,7 @@
gs = gs_get_surf(id);
if (NULL == gs) {
- return (-1);
+ return -1;
}
pt[X] = x;
@@ -1182,16 +1182,16 @@
gsd_real2surf(gs, pt);
if (gs_point_is_masked(gs, pt)) {
- return (-1);
+ return -1;
}
if (!in_vregion(gs, pt)) {
- return (-1);
+ return -1;
}
if (MAP_ATT != gs_get_att_src(gs, att)) {
- sprintf(catstr, "no category info");
- return (-1);
+ sprintf(catstr, _("no category info"));
+ return -1;
}
buff = gs_get_att_typbuff(gs, att, 0);
@@ -1202,17 +1202,16 @@
dcol = VCOL2DCOL(gs, vcol);
offset = DRC2OFF(gs, drow, dcol);
-
-
+
if (GET_MAPATT(buff, offset, ftmp)) {
return
- (Gs_get_cat_label
- (gsds_get_name(gs->att[att].hdata), drow, dcol, catstr));
+ (Gs_get_cat_label(gsds_get_name(gs->att[att].hdata),
+ drow, dcol, catstr));
}
- sprintf(catstr, "no data");
+ sprintf(catstr, _("no data"));
- return (1);
+ return 1;
}
/*!
@@ -1276,20 +1275,18 @@
}
/*!
- \brief Get RGB color at given point
+ \brief Get RGB color at given point
- Colors are translated to rgb and returned as Rxxx Gxxx Bxxx
- Usually call after GS_get_selected_point_on_surface()
+ Colors are translated to rgb and returned as Rxxx Gxxx Bxxx Usually
+ call after GS_get_selected_point_on_surface().
- Prints "NULL" or the value (i.e., "921.5") to valstr
+ Prints NULL or the value (i.e., "921.5") to valstr
- Usually call after GS_get_selected_point_on_surface()
-
\param id surface id
- \param att
+ \param att attribute id
\param[out] valstr value string (allocated, dim?)
\param x,y real coordinates
-
+
\return -1 if point outside of window or masked
\return 1 on success
*/
@@ -1302,9 +1299,9 @@
*valstr = '\0';
gs = gs_get_surf(id);
-
+
if (NULL == gs) {
- return (-1);
+ return -1;
}
pt[X] = x;
@@ -1313,7 +1310,7 @@
gsd_real2surf(gs, pt);
if (gs_point_is_masked(gs, pt)) {
- return (-1);
+ return -1;
}
if (!in_vregion(gs, pt)) {
@@ -1332,10 +1329,10 @@
sprintf(valstr, "%f", gs->att[att].constant);
}
- return (1);
+ return 1;
}
else if (MAP_ATT != gs_get_att_src(gs, att)) {
- return (-1);
+ return -1;
}
buff = gs_get_att_typbuff(gs, att, 0);
@@ -1368,8 +1365,6 @@
return (1);
}
-#endif
-
/*!
\brief Unset attribute
@@ -3191,14 +3186,15 @@
}
/*!
- \brief Measure distance "as the ball rolls" between two points on surface
+ \brief Measure distance "as the ball rolls" between two points on
+ surface
- \param hs
- \param x1,y1,x2,y2 distance line nodes
- \param dist ?
- \param use_exag use exag ?
+ \param hs surface id
+ \param x1,y1,x2,y2 two points on surface
+ \param[out] dist measured distance
+ \param use_exag use exag. surface
- \return 0 on error or if one or more points is not in region,
+ \return 0 on error or if one or more points is not in region
\return distance following terrain
*/
int GS_get_distance_alongsurf(int hs, float x1, float y1, float x2, float y2,
@@ -3206,11 +3202,12 @@
{
geosurf *gs;
float p1[2], p2[2];
-
- if (NULL == (gs = gs_get_surf(hs))) {
- return (0);
+
+ gs = gs_get_surf(hs);
+ if (gs == NULL) {
+ return 0;
}
-
+
p1[X] = x1;
p1[Y] = y1;
p2[X] = x2;
@@ -3218,7 +3215,9 @@
gsd_real2surf(gs, p1);
gsd_real2surf(gs, p2);
- return (gs_distance_onsurf(gs, p1, p2, dist, use_exag));
+ G_debug(3, "GS_get_distance_alongsurf(): hs=%d p1=%f,%f p2=%f,%f",
+ hs, x1, y1, x2, y2);
+ return gs_distance_onsurf(gs, p1, p2, dist, use_exag);
}
/*!
More information about the grass-commit
mailing list