[GRASS-SVN] r69754 - in grass/trunk/gui/wxpython: mapdisp mapwin

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Oct 29 15:01:54 PDT 2016


Author: annakrat
Date: 2016-10-29 15:01:52 -0700 (Sat, 29 Oct 2016)
New Revision: 69754

Modified:
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapwin/buffered.py
Log:
fix d.to.rast, which was broken since new rendering

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2016-10-28 22:00:39 UTC (rev 69753)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2016-10-29 22:01:52 UTC (rev 69754)
@@ -665,7 +665,7 @@
 
         dlg.Destroy()
 
-    def DOutFile(self, command):
+    def DOutFile(self, command, callback=None):
         """Saves map to image by running d.out.file from gui or d.mon.
         Command is expected to be validated by parser.
         """
@@ -699,7 +699,7 @@
             if each['ext'] == extType:
                 bitmapType = each['type']
                 break
-        self.MapWindow.SaveToFile(name, bitmapType, int(width), int(height))
+        self.MapWindow.SaveToFile(name, bitmapType, int(width), int(height), callback)
 
     def DOutFileOptData(self, dcmd, layer, params, propwin):
         """Dummy function which is called when d.out.file is called
@@ -713,6 +713,49 @@
     def DToRast(self, command):
         """Saves currently loaded composition of layers as a raster map.
         """
+        def _DToRastDone():
+            # import back as red, green, blue rasters
+            returncode, messages = RunCommand(
+                'r.in.gdal', flags='o', input=pngFile, output=tmpName, quiet=True,
+                overwrite=overwrite, getErrorMsg=True)
+            if not returncode == 0:
+                self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+                return
+            # set region for composite
+            grass.use_temp_region()
+            returncode, messages = RunCommand('g.region', raster=tmpName + '.red',
+                                              quiet=True, getErrorMsg=True)
+            if not returncode == 0:
+                grass.del_temp_region()
+                self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+                return
+            # composite
+            returncode, messages = RunCommand(
+                'r.composite', red=tmpName + '.red', green=tmpName + '.green',
+                blue=tmpName + '.blue', output=outputRaster, quiet=True,
+                overwrite=overwrite, getErrorMsg=True)
+            grass.del_temp_region()
+            RunCommand(
+                'g.remove',
+                type='raster',
+                flags='f',
+                quiet=True,
+                name=[tmpName + '.red', tmpName + '.green', tmpName + '.blue'])
+            if not returncode == 0:
+                self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
+                grass.try_remove(pngFile)
+                return
+    
+            # alignExtent changes only region variable
+            oldRegion = self.GetMap().GetCurrentRegion().copy()
+            self.GetMap().AlignExtentFromDisplay()
+            region = self.GetMap().GetCurrentRegion().copy()
+            self.GetMap().region.update(oldRegion)
+            RunCommand('r.region', map=outputRaster, n=region['n'], s=region['s'],
+                       e=region['e'], w=region['w'], quiet=True)
+            grass.try_remove(pngFile)
+
+
         if self.IsPaneShown('3d'):
             self._giface.WriteError(
                 _('d.to.rast can be used only in 2D mode.'))
@@ -734,55 +777,10 @@
         tmpName = 'd_to_rast_tmp'
         pngFile = grass.tempfile(create=False) + '.png'
         dOutFileCmd = ['d.out.file', 'output=' + pngFile, 'format=png']
-        self.DOutFile(dOutFileCmd)
-        # import back as red, green, blue rasters
-        returncode, messages = RunCommand(
-            'r.in.gdal', flags='o', input=pngFile, output=tmpName, quiet=True,
-            overwrite=overwrite, getErrorMsg=True)
-        if not returncode == 0:
-            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
-            return
-        # set region for composite
-        grass.use_temp_region()
-        returncode, messages = RunCommand('g.region', raster=tmpName + '.red',
-                                          quiet=True, getErrorMsg=True)
-        if not returncode == 0:
-            grass.del_temp_region()
-            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
-            return
-        # composite
-        returncode, messages = RunCommand(
-            'r.composite', red=tmpName + '.red', green=tmpName + '.green',
-            blue=tmpName + '.blue', output=outputRaster, quiet=True,
-            overwrite=overwrite, getErrorMsg=True)
-        grass.del_temp_region()
-        RunCommand(
-            'g.remove',
-            type='raster',
-            flags='f',
-            quiet=True,
-            name=[
-                tmpName +
-                '.red',
-                tmpName +
-                '.green',
-                tmpName +
-                '.blue'])
-        if not returncode == 0:
-            self._giface.WriteError(_('Failed to run d.to.rast:\n') + messages)
-            grass.try_remove(pngFile)
-            return
+        self.DOutFile(dOutFileCmd, callback=_DToRastDone)
+        
 
-        # alignExtent changes only region variable
-        oldRegion = self.GetMap().GetCurrentRegion().copy()
-        self.GetMap().AlignExtentFromDisplay()
-        region = self.GetMap().GetCurrentRegion().copy()
-        self.GetMap().region.update(oldRegion)
-        RunCommand('r.region', map=outputRaster, n=region['n'], s=region['s'],
-                   e=region['e'], w=region['w'], quiet=True)
 
-        grass.try_remove(pngFile)
-
     def DToRastOptData(self, dcmd, layer, params, propwin):
         """Dummy function which is called when d.to.rast is called
         and returns parsed and validated command which is then passed

Modified: grass/trunk/gui/wxpython/mapwin/buffered.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/buffered.py	2016-10-28 22:00:39 UTC (rev 69753)
+++ grass/trunk/gui/wxpython/mapwin/buffered.py	2016-10-29 22:01:52 UTC (rev 69754)
@@ -671,7 +671,7 @@
 
         event.Skip()
 
-    def SaveToFile(self, FileName, FileType, width, height):
+    def SaveToFile(self, FileName, FileType, width, height, callback=None):
         """This draws the pseudo DC to a buffer that can be saved to
         a file.
 
@@ -689,18 +689,22 @@
 
         self._fileName = FileName
         self._fileType = FileType
+        self._saveToFileCallback = callback
 
         self._busy = wx.BusyInfo(message=_("Please wait, exporting image..."),
                                  parent=self)
         wx.Yield()
 
         self.Map.ChangeMapSize((width, height))
-        self.Map.Render(force=True, windres=self._properties.resolution)
         renderMgr = self.Map.GetRenderMgr()
+        # this seems wrong, rendering should have callback
+        # when callback present, rendering does not emit signal
+        # just calls callback
         renderMgr.renderDone.disconnect(self._updateMFinished)
         renderMgr.renderDone.connect(self._saveToFileDone)
+        self.Map.Render(force=True, windres=self._properties.resolution)
 
-    def _saveToFileDone(self):
+    def _saveToFileDone(self, callback=None):
         renderMgr = self.Map.GetRenderMgr()
         renderMgr.renderDone.disconnect(self._saveToFileDone)
 
@@ -756,6 +760,8 @@
 
         self.UpdateMap(render=True)
         self.Refresh()
+        if self._saveToFileCallback:
+            self._saveToFileCallback()
 
     def GetOverlay(self):
         """Converts rendered overlay files to wx.Image



More information about the grass-commit mailing list