[GRASS-SVN] r32433 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 31 17:13:46 EDT 2008


Author: martinl
Date: 2008-07-31 17:13:46 -0400 (Thu, 31 Jul 2008)
New Revision: 32433

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
Log:
wxGUI: change map layer properties clean up (merged from trunk, r32432)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2008-07-31 21:12:21 UTC (rev 32432)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/histogram.py	2008-07-31 21:13:46 UTC (rev 32433)
@@ -335,7 +335,7 @@
         #
         # Add layer to the map
         #
-        self.layer = self.Map.AddLayer(type="command", name='', command=['d.histogram'],
+        self.layer = self.Map.AddLayer(type="command", name='histogram', command=['d.histogram'],
                                        l_active=False, l_hidden=False, l_opacity=1, l_render=False)
 
 
@@ -403,9 +403,7 @@
         """
         self.mapname = utils.GetLayerNameFromCmd(cmd)
 
-        self.layer = self.Map.ChangeLayer(layer=self.layer, type="command", name='histogram',
-                                          command=cmd,
-                                          l_active=True, l_hidden=False, l_opacity=1.0)
+        self.layer = self.Map.ChangeLayer(layer=self.layer, command=cmd, active=True)
 
         return self.layer
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-07-31 21:12:21 UTC (rev 32432)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-07-31 21:13:46 UTC (rev 32433)
@@ -193,10 +193,38 @@
         """Check if layer is activated for rendering"""
         return self.active
 
+    def SetType(self, type):
+        """Set layer type"""
+        if type not in ('raster', 'vector', 'overlay', 'command'):
+            raise gcmd.GStdError(_("Unsupported map layer type '%s'") % str(type))
+        
+        self.type = type
+
+    def SetName(self, name):
+        """Set layer name"""
+        self.name = name
+
+    def SetCmd(self, cmd):
+        """Set layer name"""
+        self.cmdlist = cmd
+
     def SetActive(self, enable=True):
         """Active or deactive layer"""
-        self.active = enable
+        self.active = bool(enable)
 
+    def SetHidden(self, enable=False):
+        """Hide or show map layer in Layer Manager"""
+        self.hidden = bool(enable)
+
+    def SetOpacity(self, value):
+        """Set opacity value"""
+        if value < 0:
+            value = 0.
+        elif value > 1:
+            value = 1.
+        
+        self.opacity = float(value)
+        
     def SetCmd(self, cmd):
         """Set new command for layer"""
         self.cmdlist = cmd
@@ -907,40 +935,45 @@
         Debug.msg (4, "Map.ReoderLayers(): layers=%s" % \
                    (layerNameList))
 
-    def ChangeLayer(self, layer, type, command, name=None,
-                    l_active=True, l_hidden=False, l_opacity=1, l_render=False):
+    def ChangeLayer(self, layer, render=False, **kargs):
         """
-        Change layer properties
+        Change map layer properties
 
+        @param layer map layer instance
         @param type layer type ('raster', 'vector', etc.)
         @param command  GRASS command given as list
         @param name layer name
-        @param l_active layer render only if True
-        @param l_hidden layer not displayed in layer tree if True
-        @param l_opacity opacity level range from 0(transparent) - 1(not transparent)
-        @param l_render render an image if True
+        @param active layer render only if True
+        @param hidden layer not displayed in layer tree if True
+        @param opacity opacity level range from 0(transparent) - 1(not transparent)
+        @param render render an image if True
         """
 
-        # l_opacity must be <0;1>
-        if l_opacity < 0: l_opacity = 0
-        elif l_opacity > 1: l_opacity = 1
+        Debug.msg (3, "Map.ChangeLayer(): layer=%s" % layer.name)
 
-        Debug.msg (3, "Map.ChangeLayer():")
+        if kargs.has_key('type'):
+            layer.SetType(kargs['type']) # check type
 
-        newlayer = MapLayer(type=type, cmd=command, name=name,
-                            active=l_active, hidden=l_hidden, opacity=l_opacity)
+        if kargs.has_key('command'):
+            layer.SetCmd(kargs['command'])
+            
+        if kargs.has_key('name'):
+            layer.SetName(kargs['name'])
 
-        oldlayerindex = self.layers.index(layer)
+        if kargs.has_key('active'):
+            layer.SetActive(kargs['active'])
 
-        # add maplayer to the list of layers
-        if layer:
-            self.layers[oldlayerindex] = newlayer
+        if kargs.has_key('hidden'):
+            layer.SetHidden(kargs['hidden'])
 
-        if l_render and not layer.Render():
+        if kargs.has_key('opacity'):
+            layer.SetOpacity(kargs['opacity'])
+            
+        if render and not layer.Render():
             raise gcmd.GException(_("Unable to render map layer <%s>.") % 
                                   (name))
 
-        return self.layers[-1]
+        return layer
 
     def ChangeOpacity(self, layer, l_opacity):
         """

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-31 21:12:21 UTC (rev 32432)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-07-31 21:13:46 UTC (rev 32433)
@@ -1123,12 +1123,11 @@
                 opac = self.GetPyData(item)[0]['maplayer'].GetOpacity(float=True)
                 chk = self.IsItemChecked(item)
                 hidden = not self.IsVisible(item)
-        maplayer = self.Map.ChangeLayer(layer=self.GetPyData(item)[0]['maplayer'], type=type,
-                                        command=cmdlist, name=self.GetItemText(item),
-                                        l_active=chk, l_hidden=hidden, l_opacity=opac, l_render=False)
 
-        self.GetPyData(item)[0]['maplayer'] = maplayer
-
+        self.Map.ChangeLayer(layer=self.GetPyData(item)[0]['maplayer'],
+                             command=cmdlist, name=self.GetItemText(item),
+                             active=chk, l_hidden=hidden, l_opacity=opac)
+        
         # if digitization tool enabled -> update list of available vector map layers
         if self.mapdisplay.toolbars['vdigit']:
             self.mapdisplay.toolbars['vdigit'].UpdateListOfLayers(updateTool=True)



More information about the grass-commit mailing list