[GRASS-SVN] r53484 - grass-addons/grass7/gui/wxpython/wx.animation/animation

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Oct 19 00:46:59 PDT 2012


Author: annakrat
Date: 2012-10-19 00:46:59 -0700 (Fri, 19 Oct 2012)
New Revision: 53484

Modified:
   grass-addons/grass7/gui/wxpython/wx.animation/animation/controller.py
   grass-addons/grass7/gui/wxpython/wx.animation/animation/dialogs.py
   grass-addons/grass7/gui/wxpython/wx.animation/animation/mapwindow.py
   grass-addons/grass7/gui/wxpython/wx.animation/animation/nviztask.py
Log:
wx.animation: set temp region for m.nviz.image

Modified: grass-addons/grass7/gui/wxpython/wx.animation/animation/controller.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.animation/animation/controller.py	2012-10-19 06:16:51 UTC (rev 53483)
+++ grass-addons/grass7/gui/wxpython/wx.animation/animation/controller.py	2012-10-19 07:46:59 UTC (rev 53484)
@@ -369,9 +369,11 @@
 
     def _load3DData(self, animationData):
         prov = self.bitmapProviders[animationData.windowIndex]
-        prov.SetData(datasource = animationData.GetNvizCommands(), 
+        nviz = animationData.GetNvizCommands()
+        prov.SetData(datasource = nviz['commands'], 
                      dataNames = animationData.mapData, dataType = 'nviz',
-                     suffix = animationData.nvizParameter)
+                     suffix = animationData.nvizParameter,
+                     nvizRegion = nviz['region'])
 
         self.bitmapProviders[animationData.windowIndex].Load()
 

Modified: grass-addons/grass7/gui/wxpython/wx.animation/animation/dialogs.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.animation/animation/dialogs.py	2012-10-19 06:16:51 UTC (rev 53483)
+++ grass-addons/grass7/gui/wxpython/wx.animation/animation/dialogs.py	2012-10-19 07:46:59 UTC (rev 53484)
@@ -774,8 +774,9 @@
             return []
 
         cmds = self.nvizTask.GetCommandSeries(series = self.mapData, paramName = self.nvizParameter)
+        region = self.nvizTask.GetRegion()
 
-        return cmds
+        return {'commands': cmds, 'region': region}
 
     def __repr__(self):
         return "%s(%r)" % (self.__class__, self.__dict__)

Modified: grass-addons/grass7/gui/wxpython/wx.animation/animation/mapwindow.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.animation/animation/mapwindow.py	2012-10-19 06:16:51 UTC (rev 53483)
+++ grass-addons/grass7/gui/wxpython/wx.animation/animation/mapwindow.py	2012-10-19 07:46:59 UTC (rev 53484)
@@ -195,27 +195,32 @@
         self.datasource = None
         self.dataNames = None
         self.dataType = None
+        self.region = None
         self.bitmapPool = bitmapPool
         self.frame = frame
         self.size = wx.Size()
         self.loadSize = wx.Size()
 
         self.suffix = ''
+        self.nvizRegion = None
 
     def GetDataNames(self):
         return self.dataNames
 
-    def SetData(self, datasource, dataNames = None, dataType = 'rast', suffix = ''):
+    def SetData(self, datasource, dataNames = None, dataType = 'rast',
+                suffix = '', nvizRegion = None):
         """!Sets data.
 
         @param datasource data to load (raster maps, m.nviz.image commands)
         @param dataNames data labels (keys)
         @param dataType 'rast', 'nviz'
+        @param nvizRegion region which must be set for m.nviz.image
         """
         self.datasource = datasource
         self.dataType = dataType
         self.suffix = suffix
-        # add postfix _nviz, _image if needed
+        self.nvizRegion = nvizRegion
+        
         if dataNames:
             self.dataNames = dataNames
         else:
@@ -229,7 +234,8 @@
 
         @param dataId name of bitmap
         """
-        dataId += self.suffix
+        if dataId:
+            dataId += self.suffix
         try:
             bitmap = self.bitmapPool[dataId]
         except KeyError:
@@ -290,7 +296,7 @@
             self._loadRasters(rasters = self.datasource, names = self.dataNames,
                              size = size, scale = scale, force = force, updateFunction = updateFunction)
         elif self.dataType == 'nviz':
-            self._load3D(commands = self.datasource, names = self.dataNames,
+            self._load3D(commands = self.datasource, region = self.nvizRegion, names = self.dataNames,
                          force = force, updateFunction = updateFunction)
         if progress:
             progress.Destroy()
@@ -383,10 +389,11 @@
 
         os.environ.pop('GRASS_REGION')
 
-    def _load3D(self, commands, names, force, updateFunction):
+    def _load3D(self, commands, region, names, force, updateFunction):
         """!Load 3D view images using m.nviz.image.
 
         @param commands 
+        @param region 
         @param names names used as keys for bitmaps
         @param force load everything even though it is already there
         @param updateFunction function called for updating progress dialog
@@ -397,6 +404,8 @@
         format = 'ppm'
         tempFile = grass.tempfile(False)
         tempFileFormat = tempFile + '.' + format
+
+        os.environ['GRASS_REGION'] = grass.region_env(**region)
         # create no data bitmap
         if None not in self.bitmapPool or force:
             self.bitmapPool[None] = self._createNoDataBitmap(ncols, nrows)
@@ -424,6 +433,7 @@
                 if not keepGoing:
                     break
         grass.try_remove(tempFileFormat)
+        os.environ.pop('GRASS_REGION')
 
 class BitmapPool():
     """!Class storing bitmaps (emulates dictionary)"""

Modified: grass-addons/grass7/gui/wxpython/wx.animation/animation/nviztask.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.animation/animation/nviztask.py	2012-10-19 06:16:51 UTC (rev 53483)
+++ grass-addons/grass7/gui/wxpython/wx.animation/animation/nviztask.py	2012-10-19 07:46:59 UTC (rev 53484)
@@ -29,11 +29,13 @@
 from core.gcmd import RunCommand, GException
 from core.utils import GetLayerNameFromCmd, CmdToTuple
 from grass.script import task as gtask
+from grass.script import core as grass
 
 class NvizTask:
     def __init__(self):
         self.task = None
         self.filename = None
+        self.region = {}
 
     def Load(self, filename):
         self.task = gtask.grassTask("m.nviz.image")
@@ -51,12 +53,17 @@
 
         if not gxwXml.nviz_state:
             raise GException(_("No 3d view information in workspace file <%s>.") % self.filename)
-            
-        # self.task.set_param('output', "/home/anna/testy/nviz/out.ppm")
 
+        self._getExtent(gxwXml)
         self._processState(gxwXml.nviz_state)
         self._processLayers(gxwXml.layers)
 
+    def _getExtent(self, root):
+        for display in root.displays:
+            if display['viewMode'] == '3d':
+                self.region['w'], self.region['s'],\
+                self.region['e'], self.region['n'] = display['extent']
+
     def _processLayers(self, layers):
         for layer in layers:
             if not layer['checked']:
@@ -185,8 +192,11 @@
         cmd = self.task.get_cmd(ignoreErrors = False, ignoreRequired = False, ignoreDefault = True)
         return CmdToTuple(cmd)
 
+    def GetRegion(self):
+        return self.region
 
 
+
 def test():
     import gettext
     gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)



More information about the grass-commit mailing list