[GRASS-SVN] r47291 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 28 06:54:22 EDT 2011
Author: martinl
Date: 2011-07-28 03:54:22 -0700 (Thu, 28 Jul 2011)
New Revision: 47291
Modified:
grass/trunk/gui/wxpython/gui_modules/goutput.py
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.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
Log:
wxNviz: attempt to fix bug when restarting wxNviz instance
Modified: grass/trunk/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/goutput.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/goutput.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -392,7 +392,7 @@
# p1 = self.cmd_output.GetCurrentPos()
p1 = self.cmd_output.GetEndStyled()
-# self.cmd_output.GotoPos(p1)
+ # self.cmd_output.GotoPos(p1)
self.cmd_output.DocumentEnd()
for line in text.splitlines():
@@ -410,11 +410,16 @@
self.cmd_output.EnsureCaretVisible()
- def WriteCmdLog(self, line, pid=None):
- """!Write message in selected style"""
+ def WriteCmdLog(self, line, pid = None, switchPage = True):
+ """!Write message in selected style
+
+ @param line message to be printed
+ @param pid process pid or None
+ @param switchPage True to switch page
+ """
if pid:
line = '(' + str(pid) + ') ' + line
- self.WriteLog(line, style=self.cmd_output.StyleCommand, switchPage = True)
+ self.WriteLog(line, style = self.cmd_output.StyleCommand, switchPage = switchPage)
def WriteWarning(self, line):
"""!Write message in warning style"""
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -350,7 +350,7 @@
"""!Add 3D view mode toolbar
"""
import nviz
- Debug.msg(5, "MapFrame._addToolbarNviz(): begin")
+
# check for GLCanvas and OpenGL
if not nviz.haveNviz:
self.toolbars['map'].combo.SetValue(_("2D view"))
@@ -375,12 +375,12 @@
# erase map window
self.MapWindow.EraseMap()
- self._layerManager.goutput.WriteCmdLog(_("Starting 3D view mode..."))
+ self._layerManager.goutput.WriteCmdLog(_("Starting 3D view mode..."),
+ switchPage = False)
self.statusbar.SetStatusText(_("Please wait, loading data..."), 0)
# create GL window & NVIZ toolbar
if not self.MapWindow3D:
- Debug.msg(5, "MapFrame._addToolbarNviz(): GLWindow will be created")
self.MapWindow3D = nviz.GLWindow(self, id = wx.ID_ANY,
Map = self.Map, tree = self.tree, lmgr = self._layerManager)
self.MapWindow = self.MapWindow3D
@@ -389,7 +389,7 @@
self.MapWindow3D.textdict = self.MapWindow2D.textdict
self.MapWindow3D.UpdateOverlays()
- # add Nviz notebookpage
+ # add Nviz notebookpage
self._layerManager.AddNviz()
self.MapWindow3D.OnPaint(None) # -> LoadData
@@ -402,7 +402,6 @@
self._layerManager.AddNviz()
for page in ('view', 'light', 'fringe', 'constant', 'cplane'):
self._layerManager.nviz.UpdatePage(page)
-
# switch from MapWindow to MapWindowGL
# add nviz toolbar
@@ -422,8 +421,7 @@
BestSize((self.toolbars['nviz'].GetBestSize())))
self.SetStatusText("", 0)
- Debug.msg(5, "MapFrame._addToolbarNviz(): end")
-
+
def AddToolbar(self, name):
"""!Add defined toolbar to the window
@@ -494,11 +492,14 @@
self.MapWindow = self.MapWindow2D
elif name == 'nviz':
- # unload data
- # self.MapWindow3D.Reset()
+ self.statusbar.SetStatusText(_("Please wait, unloading data..."), 0)
+ self._layerManager.goutput.WriteCmdLog(_("Switching back to 2D view mode..."),
+ switchPage = False)
+ # self.MapWindow3D.UnloadDataLayers(force = True)
# switch from MapWindowGL to MapWindow
self._mgr.DetachPane(self.MapWindow3D)
- self.MapWindow3D.Hide()
+ self.MapWindow3D.Destroy()
+ self.MapWindow3D = None
self.MapWindow2D.Show()
self._mgr.AddPane(self.MapWindow2D, wx.aui.AuiPaneInfo().CentrePane().
Dockable(False).BestSize((-1,-1)).
@@ -538,8 +539,7 @@
event.Skip()
def OnFocus(self, event):
- """
- Change choicebook page to match display.
+ """!Change choicebook page to match display.
Or set display for georectifying
"""
if self._layerManager and \
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -8,6 +8,7 @@
List of classes:
- NvizThread
- GLWindow
+ - DragShape
(C) 2008-2011 by the GRASS Development Team
@@ -24,6 +25,7 @@
import time
import copy
import math
+import types
from threading import Thread
@@ -65,13 +67,13 @@
def GetDisplay(self):
"""!Get display instance"""
return self._display
-
+
class GLWindow(MapWindow, glcanvas.GLCanvas):
"""!OpenGL canvas for Map Display Window"""
def __init__(self, parent, id = wx.ID_ANY,
Map = None, tree = None, lmgr = None):
self.parent = parent # MapFrame
- Debug.msg(5, "GLCanvas.__init__(): begin")
+
glcanvas.GLCanvas.__init__(self, parent, id)
MapWindow.__init__(self, parent, id,
Map, tree, lmgr)
@@ -109,14 +111,6 @@
self.textdict = {}
self.dragid = None
- #
- # use display region instead of computational
- #
- os.environ['GRASS_REGION'] = self.Map.SetRegion()
-
- #
- # create nviz instance
- #
if self.lmgr:
self.log = self.lmgr.goutput
logerr = self.lmgr.goutput.cmd_stderr
@@ -125,6 +119,9 @@
self.log = logmsg = sys.stdout
logerr = sys.stderr
+ # create nviz instanve - use display region instead of computational
+ os.environ['GRASS_REGION'] = self.Map.SetRegion()
+
self.nvizThread = NvizThread(logerr,
self.parent.statusbarWin['progress'],
logmsg)
@@ -138,18 +135,16 @@
self.img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
# size of MapWindow, to avoid resizing if size is the same
- self.size = (0,0)
+ self.size = (0, 0)
- #
# default values
- #
self.view = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'view')) # copy
self.iview = UserSettings.Get(group = 'nviz', key = 'view', internal = True)
self.nvizDefault = NvizDefault()
self.light = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'light')) # copy
self.decoration = self.nvizDefault.SetDecorDefaultProp()
- arwSize = self._display.GetLongDim()/8.
+ arwSize = self._display.GetLongDim() / 8.
coef = 0.01
if arwSize < 1:
coef = 100.
@@ -161,16 +156,18 @@
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)
- self.Bind(EVT_UPDATE_LIGHT, self.UpdateLight)
+ self.Bind(EVT_UPDATE_PROP, self.UpdateMapObjProperties)
+ self.Bind(EVT_UPDATE_VIEW, self.UpdateView)
+ self.Bind(EVT_UPDATE_LIGHT, self.UpdateLight)
self.Bind(EVT_UPDATE_CPLANE, self.UpdateCPlane)
self.Bind(wx.EVT_CLOSE, self.OnClose)
- Debug.msg(5, "GLCanvas.__init__(): end")
- #cplanes cannot be initialized now
+ # cplanes cannot be initialized now
wx.CallAfter(self.InitCPlanes)
+
+ def __del__(self):
+ self.UnloadDataLayers(force = True)
def InitCPlanes(self):
"""!Initialize cutting planes list"""
@@ -178,7 +175,7 @@
cplane = copy.deepcopy(UserSettings.Get(group = 'nviz', key = 'cplane'))
cplane['on'] = False
self.cplanes.append(cplane)
-
+
def GetOverlay(self):
"""!Converts rendered overlay files to wx.Image
@@ -195,10 +192,10 @@
imgs.append(img)
return imgs
-
+
def OnClose(self, event):
# cleanup when window actually closes (on quit) and not just is hidden
- self.Reset()
+ self.UnloadDataLayers(force = True)
def OnEraseBackground(self, event):
pass # do nothing, to avoid flashing on MSW
@@ -767,41 +764,48 @@
stop = time.time()
- Debug.msg(3, "GLWindow.LoadDataLayers(): time = %f" % (stop-start))
+ Debug.msg(1, "GLWindow.LoadDataLayers(): time = %f" % (stop-start))
- def UnloadDataLayers(self):
- """!Unload any layers that have been deleted from layer tree"""
+ def UnloadDataLayers(self, force = False):
+ """!Unload any layers that have been deleted from layer tree
+
+ @param force True to unload all data layers
+ """
if not self.tree:
return
listOfItems = []
- item = self.tree.GetFirstChild(self.tree.root)[0]
- self._GetDataLayers(item, listOfItems)
+ if not force:
+ item = self.tree.GetFirstChild(self.tree.root)[0]
+ self._GetDataLayers(item, listOfItems)
start = time.time()
+ update = False
for layer in self.layers:
- if layer not in listOfItems:
- ltype = self.tree.GetPyData(layer)[0]['type']
- try:
- if ltype == 'raster':
- self.UnloadRaster(layer)
- elif ltype == '3d-raster':
- self.UnloadRaster3d(layer)
- elif ltype == 'vector':
- self.UnloadVector(layer, True)
- self.UnloadVector(layer, False)
-
- self.UpdateView(None)
- except gcmd.GException, e:
- gcmd.GError(parent = self,
- message = e.value)
-
- self.lmgr.nviz.UpdateSettings()
+ if layer in listOfItems:
+ continue
+ ltype = self.tree.GetPyData(layer)[0]['type']
+ try:
+ if ltype == 'raster':
+ self.UnloadRaster(layer)
+ elif ltype == '3d-raster':
+ self.UnloadRaster3d(layer)
+ elif ltype == 'vector':
+ self.UnloadVector(layer, True)
+ self.UnloadVector(layer, False)
+
+ except gcmd.GException, e:
+ gcmd.GError(parent = self,
+ message = e.value)
+ if update:
+ self.lmgr.nviz.UpdateSettings()
+ self.UpdateView(None)
+
stop = time.time()
- Debug.msg(3, "GLWindow.UnloadDataLayers(): time = %f" % (stop-start))
+ Debug.msg(1, "GLWindow.UnloadDataLayers(): time = %f" % (stop-start))
def SetVectorSurface(self, data):
"""!Set reference surfaces of vector"""
@@ -847,7 +851,7 @@
else:
mapType = nvizType
data = self.constants[item]
-
+
if not data:
# init data structure
if nvizType != 'constant':
@@ -888,11 +892,11 @@
if sec1 == 'position':
data[sec][sec1]['update'] = None
continue
- if type(data[sec][sec1]) == type({}):
+ if type(data[sec][sec1]) == types.DictType:
for sec2 in data[sec][sec1].keys():
- if sec2 != 'all':
+ if sec2 not in ('all', 'init', 'id'):
data[sec][sec1][sec2]['update'] = None
- elif type(data[sec][sec1]) == type([]):
+ elif type(data[sec][sec1]) == types.ListType:
for i in range(len(data[sec][sec1])):
for sec2 in data[sec][sec1][i].keys():
data[sec][sec1][i][sec2]['update'] = None
@@ -1093,7 +1097,7 @@
if layer.type == 'vector':
win = toolWin.FindWindowById(toolWin.win['vector']['map'])
win.SetValue('')
-
+
def LoadVector(self, item, points = None):
"""!Load 2D or 3D vector map overlay
@@ -1190,19 +1194,6 @@
### self.layers.remove(id)
- def Reset(self):
- """!Reset (unload data)"""
- for item in self.layers:
- type = self.tree.GetPyData(item)[0]['maplayer'].type
- if type == 'raster':
- self.UnloadRaster(item)
- elif type == '3d-raster':
- self.UnloadRaster3d(item)
- elif type == 'vector':
- self.UnloadVector(item)
-
- self.init = False
-
def OnZoomToMap(self, event):
"""!Set display extents to match selected raster or vector
map or volume.
@@ -1318,7 +1309,7 @@
elif attrb == 'transp':
self._display.UnsetSurfaceTransp(id)
else:
- if type(value) == type('') and \
+ if type(value) == types.StringType and \
len(value) <= 0: # ignore empty values (TODO: warning)
continue
if attrb == 'color':
@@ -1426,7 +1417,7 @@
elif attrb == 'transp':
self._display.UnsetIsosurfaceTransp(id, isosurfId)
else:
- if type(value) == type('') and \
+ if type(value) == types.StringType and \
len(value) <= 0: # ignore empty values (TODO: warning)
continue
elif attrb == 'color':
@@ -1931,7 +1922,6 @@
@param textinfo text metadata (text, font, color, rotation)
"""
return self.parent.MapWindow2D.TextBounds(textinfo, relcoords = True)
-
class DragShape:
"""!Class for drawing overlays (based on wxpython demo)"""
Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -606,7 +606,7 @@
'color' : (128, 128, 128, 255), # grey
},
'arrow': {
- 'color': (0, 0, 0)
+ 'color': (0, 0, 0),
}
},
'modeler' : {
@@ -979,6 +979,16 @@
"""!Get default user settings"""
return self.defaultSettings
+ def Reset(self, key = None):
+ """!Reset to default settings
+
+ @key key in settings dict (None for all keys)
+ """
+ if not key:
+ self.userSettings = copy.deepcopy(self.defaultSettings)
+ else:
+ self.userSettings[key] = copy.deepcopy(self.defaultSettings[key])
+
globalSettings = Settings()
class PreferencesBaseDialog(wx.Dialog):
Modified: grass/trunk/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/workspace.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -9,17 +9,19 @@
- WriteWorkspaceFile
- ProcessGrcFile
-(C) 2007-2010 by the GRASS Development Team
+(C) 2007-2011 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
for details.
@author Martin Landa <landa.martin gmail.com>
+ at author Anna Kratochvilova <kratochanna gmail.com> (wxNviz / Google SoC 2011)
"""
import os
import sys
import copy
+import types
import wx
@@ -525,11 +527,10 @@
constants.append({'constant': plane})
self.nviz_state['constants'] = constants
-
class Nviz:
def __init__(self):
"""Default 3D settings"""
- pass
+ UserSettings.Reset('nviz')
def SetConstantDefaultProp(self):
"""Set default constant data properties"""
@@ -807,18 +808,19 @@
return (value, desc)
def SetDecorDefaultProp(self):
+ """!Set default arrow properties
+ """
data = {}
-
+
# arrow
data['arrow'] = UserSettings.Get(group = 'nviz', key = 'arrow')
data['arrow']['color'] = "%d:%d:%d" % (
- UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
+ UserSettings.Get(group = 'nviz', key = 'arrow', subkey = 'color')[:3])
data['arrow'].update(UserSettings.Get(group = 'nviz', key = 'arrow', internal = True))
data['arrow']['show'] = False
+
return data
-
-
-
+
class WriteWorkspaceFile(object):
"""!Generic class for writing workspace file"""
def __init__(self, lmgr, file):
Modified: grass/trunk/gui/wxpython/gui_modules/wxnviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-28 07:25:20 UTC (rev 47290)
+++ grass/trunk/gui/wxpython/gui_modules/wxnviz.py 2011-07-28 10:54:22 UTC (rev 47291)
@@ -3,12 +3,13 @@
@brief wxGUI 3D view mode
-This module implements 3D visualization mode for map display.
+This module implements 3D visualization mode for map display (ctypes
+required).
List of classes:
- Nviz
-(C) 2008-2010 by the GRASS Development Team
+(C) 2008-2011 by the GRASS Development Team
This program is free software under the GNU General Public
License (>=v2). Read the file COPYING that comes with GRASS
@@ -16,6 +17,7 @@
@author Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
@author Pythonized by Glynn Clements
+ at author Anna Kratochvilova <KratochAnna seznam.cz> (Google SoC 2011)
"""
import sys
@@ -62,6 +64,7 @@
"""!Initialize Nviz class instance
@param log logging area
+ @param gprogress progressbar
"""
global errfunc, perfunc, log, progress
log = glog
@@ -71,6 +74,7 @@
G_set_error_routine(errfunc)
G_set_percent_routine(perfunc)
+ G_unset_window()
GS_libinit()
GVL_libinit()
@@ -1563,7 +1567,6 @@
@param index type of fence - from 0 (off) to 4
"""
-
Nviz_set_fence_color(self.data, index)
def GetXYRange(self):
@@ -1683,3 +1686,4 @@
byref(d), int(useExag))
return d.value
+
More information about the grass-commit
mailing list