Browse Source

support more d. commands

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54714 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 years ago
parent
commit
1ee2eb64d3

+ 2 - 10
gui/wxpython/core/render.py

@@ -126,11 +126,7 @@ class Layer(object):
                        (self.type, self.name))
                        (self.type, self.name))
         
         
         # prepare command for each layer
         # prepare command for each layer
-        layertypes = ('raster', 'rgb', 'his', 'shaded', 'rastarrow', 'rastnum',
-                      'vector','thememap','themechart',
-                      'grid', 'geodesic', 'rhumb', 'labels',
-                      'command', 'rastleg','maplegend',
-                      'overlay', 'wms')
+        layertypes = utils.command2ltype.values() + ['overlay', 'command']
         
         
         if self.type not in layertypes:
         if self.type not in layertypes:
             raise GException(_("<%(name)s>: layer type <%(type)s> is not supported") % \
             raise GException(_("<%(name)s>: layer type <%(type)s> is not supported") % \
@@ -257,11 +253,7 @@ class Layer(object):
     
     
     def SetType(self, ltype):
     def SetType(self, ltype):
         """!Set layer type"""
         """!Set layer type"""
-        if ltype not in ('raster', '3d-raster', 'vector',
-                        'overlay', 'command',
-                        'shaded', 'rgb', 'his', 'rastarrow', 'rastnum','maplegend',
-                        'thememap', 'themechart', 'grid', 'labels',
-                        'geodesic','rhumb', 'wms'):
+        if ltype not in utils.command2ltype.values() + ['overlay', 'command']:
             raise GException(_("Unsupported map layer type '%s'") % ltype)
             raise GException(_("Unsupported map layer type '%s'") % ltype)
         
         
         if ltype == 'wms' and not isinstance(self.renderMgr, RenderWMSMgr):
         if ltype == 'wms' and not isinstance(self.renderMgr, RenderWMSMgr):

+ 28 - 0
gui/wxpython/core/utils.py

@@ -909,6 +909,34 @@ def color_resolve(color):
             label = _('Select Color')
             label = _('Select Color')
     return (rgb, label)
     return (rgb, label)
 
 
+command2ltype = {'d.rast'         : 'raster',
+                 'd.rast3d'       : '3d-raster',
+                 'd.rgb'          : 'rgb',
+                 'd.his'          : 'his',
+                 'd.shadedmap'    : 'shaded',
+                 'd.legend'       : 'rastleg',
+                 'd.rast.arrow'   : 'rastarrow',
+                 'd.rast.num'     : 'rastnum',
+                 'd.rast.leg'     : 'maplegend',
+                 'd.vect'         : 'vector',
+                 'd.thematic.area': 'thememap',
+                 'd.vect.chart'   : 'themechart',
+                 'd.grid'         : 'grid',
+                 'd.geodesic'     : 'geodesic',
+                 'd.rhumbline'    : 'rhumb',
+                 'd.labels'       : 'labels',
+                 'd.barscale'     : 'barscale',
+                 'd.redraw'       : 'redraw',
+                 'd.wms'          : 'wms',
+                 'd.histogram'    : 'histogram',
+                 'd.colortable'   : 'colortable',
+                 'd.graph'        : 'graph'
+                 }
+ltype2command = {}
+for (cmd, ltype) in command2ltype.items():
+    ltype2command[ltype] = cmd
+
+
 def GetGEventAttribsForHandler(method, event):
 def GetGEventAttribsForHandler(method, event):
     """!Get attributes from event, which can be used by handler method. 
     """!Get attributes from event, which can be used by handler method. 
 
 

+ 2 - 20
gui/wxpython/lmgr/frame.py

@@ -42,7 +42,7 @@ from grass.script          import core as grass
 
 
 from core.gcmd             import RunCommand, GError, GMessage, GException
 from core.gcmd             import RunCommand, GError, GMessage, GException
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.settings         import UserSettings, GetDisplayVectSettings
-from core.utils            import SetAddOnPath, GetLayerNameFromCmd
+from core.utils            import SetAddOnPath, GetLayerNameFromCmd, command2ltype
 from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
 from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from lmgr.layertree        import LayerTree, LMIcons
 from lmgr.layertree        import LayerTree, LMIcons
@@ -594,25 +594,7 @@ class GMFrame(wx.Frame):
             self.NewDisplay(show = True)
             self.NewDisplay(show = True)
         try:
         try:
             # display GRASS commands
             # display GRASS commands
-            layertype = {'d.rast'         : 'raster',
-                         'd.rast3d'       : '3d-raster',
-                         'd.rgb'          : 'rgb',
-                         'd.his'          : 'his',
-                         'd.shaded'       : 'shaded',
-                         'd.legend'       : 'rastleg',
-                         'd.rast.arrow'   : 'rastarrow',
-                         'd.rast.num'     : 'rastnum',
-                         'd.rast.leg'     : 'maplegend',
-                         'd.vect'         : 'vector',
-                         'd.thematic.area': 'thememap',
-                         'd.vect.chart'   : 'themechart',
-                         'd.grid'         : 'grid',
-                         'd.geodesic'     : 'geodesic',
-                         'd.rhumbline'    : 'rhumb',
-                         'd.labels'       : 'labels',
-                         'd.barscale'     : 'barscale',
-                         'd.redraw'       : 'redraw',
-                         'd.wms'          : 'wms'}[command[0]]
+            layertype = command2ltype[command[0]]
         except KeyError:
         except KeyError:
             GMessage(parent = self,
             GMessage(parent = self,
                      message = _("Command '%s' not yet implemented in the WxGUI. "
                      message = _("Command '%s' not yet implemented in the WxGUI. "

+ 13 - 48
gui/wxpython/lmgr/layertree.py

@@ -35,7 +35,7 @@ from gui_core.forms       import GUI
 from mapdisp.frame        import MapFrame
 from mapdisp.frame        import MapFrame
 from core.render          import Map
 from core.render          import Map
 from modules.histogram    import HistogramFrame
 from modules.histogram    import HistogramFrame
-from core.utils           import GetLayerNameFromCmd
+from core.utils           import GetLayerNameFromCmd, ltype2command
 from wxplot.profile       import ProfileFrame
 from wxplot.profile       import ProfileFrame
 from core.debug           import Debug
 from core.debug           import Debug
 from core.settings        import UserSettings, GetDisplayVectSettings
 from core.settings        import UserSettings, GetDisplayVectSettings
@@ -1077,56 +1077,21 @@ class LayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
                                 completed = (self.GetOptData,layer,params))
                                 completed = (self.GetOptData,layer,params))
             
             
             self.SetLayerInfo(layer, key = 'cmd', value = module.GetCmd())
             self.SetLayerInfo(layer, key = 'cmd', value = module.GetCmd())
-        elif ltype == 'raster':
-            cmd = ['d.rast']
-            if UserSettings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'):
-                cmd.append('-n')
-                         
-        elif ltype == '3d-raster':
-            cmd = ['d.rast3d']
-                                        
-        elif ltype == 'rgb':
-            cmd = ['d.rgb']
-            if UserSettings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'):
-                cmd.append('-n')
-            
-        elif ltype == 'his':
-            cmd = ['d.his']
-            
-        elif ltype == 'shaded':
-            cmd = ['d.shadedmap']
-            
-        elif ltype == 'rastarrow':
-            cmd = ['d.rast.arrow']
-            
-        elif ltype == 'rastnum':
-            cmd = ['d.rast.num']
-            
-        elif ltype == 'vector':
-            cmd = ['d.vect'] + GetDisplayVectSettings()
-            
-        elif ltype == 'thememap':
+        else:
+            cmd = [ltype2command[ltype]]
+            if ltype == 'raster':
+                if UserSettings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'):
+                    cmd.append('-n')
+            elif ltype == 'rgb':
+                if UserSettings.Get(group = 'rasterLayer', key = 'opaque', subkey = 'enabled'):
+                    cmd.append('-n')
+            elif ltype == 'vector':
+                cmd.append(GetDisplayVectSettings())
+
+            # ltype == 'thememap':
             # -s flag requested, otherwise only first thematic category is displayed
             # -s flag requested, otherwise only first thematic category is displayed
             # should be fixed by C-based d.thematic.* modules
             # should be fixed by C-based d.thematic.* modules
-            cmd = ['d.thematic.area']
-            
-        elif ltype == 'themechart':
-            cmd = ['d.vect.chart']
-            
-        elif ltype == 'grid':
-            cmd = ['d.grid']
             
             
-        elif ltype == 'geodesic':
-            cmd = ['d.geodesic']
-            
-        elif ltype == 'rhumb':
-            cmd = ['d.rhumbline']
-            
-        elif ltype == 'labels':
-            cmd = ['d.labels']
-
-        elif ltype == 'wms':
-            cmd = ['d.wms']
 
 
         if cmd:
         if cmd:
             GUI(parent = self, centreOnParent = False).ParseCommand(cmd,
             GUI(parent = self, centreOnParent = False).ParseCommand(cmd,

+ 8 - 6
gui/wxpython/mapdisp/main.py

@@ -90,14 +90,16 @@ class DMonMap(Map):
             for line in fd.readlines():
             for line in fd.readlines():
                 cmd = utils.split(line.strip())
                 cmd = utils.split(line.strip())
                 ltype = None
                 ltype = None
-                if cmd[0] == 'd.rast':
-                    ltype = 'raster'
-                elif cmd[0] == 'd.vect':
-                    ltype = 'vector'
-                
+
+                try:
+                    ltype = utils.command2ltype[cmd[0]]
+                except KeyError:
+                    grass.warning(_("Unsupported command %s.") % cmd[0])
+                    continue
+
                 name = utils.GetLayerNameFromCmd(cmd, fullyQualified = True,
                 name = utils.GetLayerNameFromCmd(cmd, fullyQualified = True,
                                                  layerType = ltype)[0]
                                                  layerType = ltype)[0]
-                
+
                 self.AddLayer(ltype = ltype, command = cmd, active = False, name = name)
                 self.AddLayer(ltype = ltype, command = cmd, active = False, name = name)
                 nlayers += 1
                 nlayers += 1
         except IOError, e:
         except IOError, e: