[GRASS-SVN] r32138 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 16 15:51:36 EDT 2008


Author: martinl
Date: 2008-07-16 15:51:36 -0400 (Wed, 16 Jul 2008)
New Revision: 32138

Modified:
   grass/trunk/gui/wxpython/gui_modules/nviz.py
   grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
Log:
nviz2/wxGUI: load/unload data layers fix

Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-16 19:11:01 UTC (rev 32137)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py	2008-07-16 19:51:36 UTC (rev 32138)
@@ -278,7 +278,7 @@
         self.SwapBuffers()
 
     def IsLoaded(self, layer):
-        """Check if layer is already loaded"""
+        """Check if layer (item) is already loaded"""
         data = self.tree.GetPyData(layer)[0]['nviz']
 
         if not data or not data.has_key('object'):
@@ -309,7 +309,6 @@
             item = listOfItems.pop()
             type = self.tree.GetPyData(item)[0]['type']
             mapLayer = self.tree.GetPyData(item)[0]['maplayer']
-            data = self.tree.GetPyData(item)[0]['nviz']
 
             if type == 'raster':
                 id = self.LoadRaster(mapLayer)
@@ -317,42 +316,11 @@
                 id = self.LoadVector(mapLayer)
 
             if type == 'raster' or type == 'vector':
-                # init layer data properties
-                if data is None:
-                    self.tree.GetPyData(item)[0]['nviz'] = {}
-                    data = self.tree.GetPyData(item)[0]['nviz']
-
-                    if type == 'raster':
-                        data['surface'] = {}
-                        for sec in ('attribute', 'draw', 'mask', 'position'):
-                            data['surface'][sec] = {}
-
-                        self.SetSurfaceDefaultProp(data['surface'])
-                    elif type == 'vector':
-                        data['vector'] = {}
-                        for sec in ('lines', ):
-                            data['vector'][sec] = {}
-
-                        self.SetVectorDefaultProp(data['vector'])
-
-                # set updates
-                else:
-                    for sec in data.keys():
-                        for sec1 in data[sec].keys():
-                            for sec2 in data[sec][sec1].keys():
-                                self.update.append('%s:%s:%s' % (sec, sec1, sec2))
-
-                # associate with map object id
-                if not data.has_key('object'):
-                    data['object'] = { 'id' : id,
-                                       'init' : False }
-                
-                if not data.has_key('view'):
-                    data['view'] = None
-
+                self.SetLayerData(item, id)
                 self.UpdateLayerProperties(item)
             
-                # print data
+                # print self.tree.GetPyData(item)[0]['nviz']
+                # print self.update
 
         stop = time.time()
         
@@ -360,6 +328,43 @@
 
         # print stop - start
 
+    def SetLayerData(self, item, id):
+        """Set map object properties"""
+        data = self.tree.GetPyData(item)[0]['nviz']
+            
+        # init layer data properties
+        if data is None:
+            self.tree.GetPyData(item)[0]['nviz'] = {}
+            data = self.tree.GetPyData(item)[0]['nviz']
+
+            if type == 'raster':
+                data['surface'] = {}
+                for sec in ('attribute', 'draw', 'mask', 'position'):
+                    data['surface'][sec] = {}
+
+                self.SetSurfaceDefaultProp(data['surface'])
+            elif type == 'vector':
+                data['vector'] = {}
+                for sec in ('lines', ):
+                    data['vector'][sec] = {}
+
+                self.SetVectorDefaultProp(data['vector'])
+
+        # set updates
+        else:
+            for sec in data.keys():
+                for sec1 in data[sec].keys():
+                    for sec2 in data[sec][sec1].keys():
+                        self.update.append('%s:%s:%s' % (sec, sec1, sec2))
+
+        # associate with map object id
+        if not data.has_key('object'):
+            data['object'] = { 'id' : id,
+                               'init' : False }
+                
+            if not data.has_key('view'):
+                data['view'] = None
+
     def LoadRaster(self, layer):
         """Load raster map -> surface"""
         if layer.type != 'raster':

Modified: grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-16 19:11:01 UTC (rev 32137)
+++ grass/trunk/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-16 19:51:36 UTC (rev 32138)
@@ -829,18 +829,22 @@
             # nviz - load/unload data layer
             mapLayer = self.GetPyData(item)[0]['maplayer']
 
+            busy = wx.BusyInfo(message=_("Please wait, updating data..."),
+                               parent=self.mapdisplay)
+
+            wx.Yield()            
+
             if checked: # enable
-                
-                busy = wx.BusyInfo(message=_("Please wait, loading data..."),
-                                   parent=self.mapdisplay)
-                wx.Yield()
-
+                id = -1
                 if mapLayer.type == 'raster':
-                    self.mapdisplay.MapWindow.LoadRaster(mapLayer)
+                    id = self.mapdisplay.MapWindow.LoadRaster(mapLayer)
                 elif mapLayer.type == 'vector':
-                    self.mapdisplay.MapWindow.LoadVector(mapLayer)
+                    id = self.mapdisplay.MapWindow.LoadVector(mapLayer)
 
-                busy.Destroy()
+                if id > 0:
+                    self.mapdisplay.MapWindow.SetLayerData(item, id)
+                    self.mapdisplay.MapWindow.UpdateLayerProperties(item)
+
             else: # disable
                 data = self.GetPyData(item)[0]['nviz']
                 id = data['object']['id']
@@ -848,7 +852,11 @@
                     self.mapdisplay.MapWindow.UnloadRaster(id)
                 elif mapLayer.type == 'vector':
                     self.mapdisplay.MapWindow.UnloadVector(id)
+                data.pop('object')
+                data.pop('view')
 
+            busy.Destroy()
+        
         # redraw map if auto-rendering is enabled
         if self.mapdisplay.autoRender.GetValue(): 
             self.mapdisplay.OnRender(None)
@@ -1136,12 +1144,12 @@
                 if mapLayer.type == 'raster':
                     self.mapdisplay.nvizToolWin.UpdatePage('surface')
                     self.mapdisplay.nvizToolWin.SetPage('surface')
-                    if not mapWin.IsLoaded(mapLayer):
+                    if not mapWin.IsLoaded(layer):
                         mapWin.LoadRaster(mapLayer)
                 elif mapLayer.type == 'vector':
                     self.mapdisplay.nvizToolWin.UpdatePage('vector')
                     self.mapdisplay.nvizToolWin.SetPage('vector')
-                    if not mapWin.IsLoaded(mapLayer):
+                    if not mapWin.IsLoaded(layer):
                         mapWin.LoadVector(mapLayer)
                 
                 # reset view when first layer loaded



More information about the grass-commit mailing list