Pārlūkot izejas kodu

wxGUI/wxNviz: color rules dialog changed to support both v.colors and attribute columns

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47714 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 13 gadi atpakaļ
vecāks
revīzija
e387a3a551

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 548 - 720
gui/wxpython/gui_modules/colorrules.py


+ 11 - 3
gui/wxpython/gui_modules/gselect.py

@@ -800,12 +800,13 @@ class ColumnSelect(wx.ComboBox):
         if vector:
             self.InsertColumns(vector, layer)
     
-    def InsertColumns(self, vector, layer, excludeKey = False, type = None, dbInfo = None):
+    def InsertColumns(self, vector, layer, excludeKey = False, excludeCols = None, type = None, dbInfo = None):
         """!Insert columns for a vector attribute table into the columns combobox
 
         @param vector vector name
         @param layer vector layer number
         @param excludeKey exclude key column from the list?
+        @param excludeCols list of columns to be removed from the list
         @param type only columns of given type (given as list)
         """
         if not dbInfo:
@@ -820,13 +821,20 @@ class ColumnSelect(wx.ComboBox):
                 columns[val['index']] = key
             if excludeKey: # exclude key column
                 columns.remove(keyColumn)
+            if excludeCols: # exclude key column
+                for key in columnchoices.iterkeys():
+                    if key in excludeCols:
+                        columns.remove(key)
             if type: # only selected column types
                 for key, value in columnchoices.iteritems():
                     if value['type'] not in type:
-                        columns.remove(key)
+                        try:
+                            columns.remove(key)
+                        except ValueError:
+                            pass
         except (KeyError, ValueError):
             columns = list()
-        
+            
         self.SetItems(columns)
         self.SetValue(self.defaultValue)
         

+ 22 - 6
gui/wxpython/gui_modules/nviz_mapdisp.py

@@ -1543,10 +1543,18 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
             
         # thematic
         if 'update' in data['thematic']:
-            if data['thematic']['use']:
+            color = width = None
+            colorTable = False
+            if data['thematic']['usecolor'] or data['thematic']['usewidth']:
+                if data['thematic']['usecolor']:
+                    color = data['thematic']['rgbcolumn']
+                    colorTable = True
+                if data['thematic']['usewidth']:
+                    width = data['thematic']['sizecolumn']
                 self._display.SetLinesStyleThematic(id = id, layer = data['thematic']['layer'],
-                                               color = data['thematic']['rgbcolumn'],
-                                               width = data['thematic']['sizecolumn'])
+                                                     color = color,
+                                                     colorTable = colorTable, 
+                                                     width = width)
             else:
                 self._display.UnsetLinesStyleThematic(id = id)
             data['thematic'].pop('update')
@@ -1598,10 +1606,18 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
         
         # thematic
         if 'update' in data['thematic']:
-            if data['thematic']['use']:
+            color = size = None
+            colorTable = False
+            if data['thematic']['usecolor'] or data['thematic']['usesize']:
+                if data['thematic']['usecolor']:
+                    color = data['thematic']['rgbcolumn']
+                    colorTable = True
+                if data['thematic']['usesize']:
+                    size = data['thematic']['sizecolumn']
                 self._display.SetPointsStyleThematic(id = id, layer = data['thematic']['layer'],
-                                               color = data['thematic']['rgbcolumn'],
-                                               size = data['thematic']['sizecolumn'])
+                                                     color = color,
+                                                     colorTable = colorTable, 
+                                                     size = size)
             else:
                 self._display.UnsetPointsStyleThematic(id = id)
             data['thematic'].pop('update')

+ 91 - 33
gui/wxpython/gui_modules/nviz_tools.py

@@ -1147,25 +1147,43 @@ class NvizToolWindow(FN.FlatNotebook):
         
         # thematic mapping
         self.win['vector']['lines']['thematic'] = {}
-        checkThematic = wx.CheckBox(parent = panel, id = wx.ID_ANY,
-                                         label = _("use thematic mapping for vector lines"))
-        self.win['vector']['lines']['thematic']['check'] = checkThematic.GetId()
-        checkThematic.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
-        checkThematic.SetValue(False)
-        
+        checkThematicColor = wx.CheckBox(parent = panel, id = wx.ID_ANY,
+                                         label = _("use color for thematic mapping"))
+        checkThematicWidth = wx.CheckBox(parent = panel, id = wx.ID_ANY,
+                                         label = _("use width for thematic mapping"))
+        self.win['vector']['lines']['thematic']['checkcolor'] = checkThematicColor.GetId()
+        self.win['vector']['lines']['thematic']['checkwidth'] = checkThematicWidth.GetId()
+        checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
+        checkThematicWidth.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
+        checkThematicColor.SetValue(False)
+        checkThematicWidth.SetValue(False)
+        
+        vSizer = wx.BoxSizer(wx.VERTICAL)
         hSizer = wx.BoxSizer(wx.HORIZONTAL)
-        hSizer.Add(item = checkThematic, flag = wx.ALIGN_CENTER_VERTICAL,
+        hSizer.Add(item = checkThematicColor, flag = wx.ALIGN_CENTER_VERTICAL,
+                    border = 5)
+        setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
+                                         label = _("Set options..."))
+        self.win['vector']['lines']['thematic']['buttoncolor'] = setThematic.GetId()
+        setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
+        hSizer.Add(item = wx.Size(-1, -1), proportion = 1)
+        hSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT,
+                    border = 5, proportion = 0)
+        vSizer.Add(hSizer, flag = wx.EXPAND)
+                    
+        hSizer = wx.BoxSizer(wx.HORIZONTAL)
+        hSizer.Add(item = checkThematicWidth, flag = wx.ALIGN_CENTER_VERTICAL,
                     border = 5)
-        
         setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
                                          label = _("Set options..."))
-        self.win['vector']['lines']['thematic']['button'] = setThematic.GetId()
+        self.win['vector']['lines']['thematic']['buttonwidth'] = setThematic.GetId()
         setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
         hSizer.Add(item = wx.Size(-1, -1), proportion = 1)
         hSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL|wx.LEFT,
                     border = 5, proportion = 0)
         
-        gridSizer.Add(item = hSizer, flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
+        vSizer.Add(hSizer, flag = wx.EXPAND)
+        gridSizer.Add(item = vSizer, flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,
                       pos = (1, 1), span = (1, 5))
         
         # display
@@ -1305,21 +1323,34 @@ class NvizToolWindow(FN.FlatNotebook):
                       pos = (0, 6))
         # thematic mapping
         self.win['vector']['points']['thematic'] = {}
-        checkThematic = wx.CheckBox(parent = panel, id = wx.ID_ANY,
-                                         label = _("use thematic mapping for vector points"))
-        self.win['vector']['points']['thematic']['check'] = checkThematic.GetId()
-        checkThematic.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
-        checkThematic.SetValue(False)
-        
-        gridSizer.Add(item = checkThematic, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
+        checkThematicColor = wx.CheckBox(parent = panel, id = wx.ID_ANY,
+                                         label = _("use color for thematic mapping"))
+        checkThematicSize = wx.CheckBox(parent = panel, id = wx.ID_ANY,
+                                         label = _("use size for thematic mapping"))
+        self.win['vector']['points']['thematic']['checkcolor'] = checkThematicColor.GetId()
+        self.win['vector']['points']['thematic']['checksize'] = checkThematicSize.GetId()
+        checkThematicColor.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
+        checkThematicSize.Bind(wx.EVT_CHECKBOX, self.OnCheckThematic)
+        checkThematicColor.SetValue(False)
+        checkThematicSize.SetValue(False)
+        
+        gridSizer.Add(item = checkThematicColor, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
                       pos = (1, 1), span = (1, 5))
         setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
                                          label = _("Set options..."))
-        self.win['vector']['points']['thematic']['button'] = setThematic.GetId()
+        self.win['vector']['points']['thematic']['buttoncolor'] = setThematic.GetId()
         setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
         gridSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL,
                       pos = (1, 6))
-                           
+                    
+        gridSizer.Add(item = checkThematicSize, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT,
+                      pos = (2, 1), span = (1, 5))
+        setThematic = wx.Button(parent = panel, id = wx.ID_ANY,
+                                         label = _("Set options..."))
+        self.win['vector']['points']['thematic']['buttonsize'] = setThematic.GetId()
+        setThematic.Bind(wx.EVT_BUTTON, self.OnSetThematic)
+        gridSizer.Add(item = setThematic, flag = wx.ALIGN_CENTER_VERTICAL,
+                      pos = (2, 6))                   
         vertSizer.Add(gridSizer, proportion = 0, flag = wx.EXPAND, border = 0)
         # high
         gridSizer = wx.GridBagSizer(vgap = 5, hgap = 5)
@@ -3211,17 +3242,28 @@ class NvizToolWindow(FN.FlatNotebook):
         """!Switch on/off thematic mapping"""
         # can be called with no event to enable/disable button
         if not event:
-            ids = (self.win['vector']['points']['thematic']['check'],
-                  self.win['vector']['lines']['thematic']['check'])
+            ids = (self.win['vector']['points']['thematic']['checkcolor'],
+                  self.win['vector']['lines']['thematic']['checkcolor'],
+                  self.win['vector']['points']['thematic']['checksize'],
+                  self.win['vector']['lines']['thematic']['checkwidth'])
         else:
             ids = (event.GetId(),)
         for id in ids:
-            if id == self.win['vector']['points']['thematic']['check']:
-                type = 'points'
+            if id in self.win['vector']['points']['thematic'].values():
+                vtype = 'points'
+                if id == self.win['vector'][vtype]['thematic']['checkcolor']:
+                    attrType = 'color'
+                else:
+                    attrType = 'size'
             else:
-                type = 'lines'
-            check = self.win['vector'][type]['thematic']['check']
-            button = self.win['vector'][type]['thematic']['button']
+                vtype = 'lines'
+                if id == self.win['vector'][vtype]['thematic']['checkcolor']:
+                    attrType = 'color'
+                else:
+                    attrType = 'width'
+                
+            check = self.win['vector'][vtype]['thematic']['check' + attrType]
+            button = self.win['vector'][vtype]['thematic']['button' + attrType]
             if self.FindWindowById(check).GetValue():
                 checked = True
             else:
@@ -3229,8 +3271,8 @@ class NvizToolWindow(FN.FlatNotebook):
             self.FindWindowById(button).Enable(checked)
             
             data = self.GetLayerData('vector')
-            data['vector'][type]['thematic']['use'] = checked
-            data['vector'][type]['thematic']['update'] = None
+            data['vector'][vtype]['thematic']['use' + attrType] = checked
+            data['vector'][vtype]['thematic']['update'] = None
         
         # update properties
         event = wxUpdateProperties(data = data)
@@ -3241,11 +3283,17 @@ class NvizToolWindow(FN.FlatNotebook):
             
     def OnSetThematic(self, event):
         """!Set options for thematic points"""
-        if event.GetId() == self.win['vector']['points']['thematic']['button']:
-            vectorType = 'points'
+        if event.GetId() in self.win['vector']['points']['thematic'].values():
+            vtype = 'points'
+        else:
+            vtype = 'lines'
+        if event.GetId() == self.win['vector'][vtype]['thematic']['buttoncolor']:
+            attrType = 'color'
+        elif vtype == 'points':
+            attrType = 'size'
         else:
-            vectorType = 'lines'            
-        ctable = colorrules.ThematicVectorTable(self, vectorType)
+            attrType = 'width'
+        ctable = colorrules.ThematicVectorTable(self, vtype, attributeType = attrType)
         ctable.CentreOnScreen()
         ctable.Show()
         
@@ -4269,6 +4317,16 @@ class NvizToolWindow(FN.FlatNotebook):
             self.FindWindowById(self.win['vector'][v]['height']['slider']).Enable(enable)
             self.FindWindowById(self.win['vector'][v]['height']['text']).Enable(enable)
             
+            if data[v]['thematic']['usecolor']:
+                check = self.FindWindowById(self.win['vector'][v]['thematic']['checkcolor'])
+                check.SetValue(data[v]['thematic']['usecolor'])
+            if 'usesize' in data[v]['thematic'] and data[v]['thematic']['usesize']:
+                check = self.FindWindowById(self.win['vector'][v]['thematic']['checksize'])
+                check.SetValue(data[v]['thematic']['usesize'])
+            elif 'usewidth' in data[v]['thematic'] and data[v]['thematic']['usewidth']:
+                check = self.FindWindowById(self.win['vector'][v]['thematic']['checkwidth'])
+                check.SetValue(data[v]['thematic']['usewidth'])
+            self.OnCheckThematic(None)
         #
         # lines
         #
@@ -4342,7 +4400,7 @@ class NvizToolWindow(FN.FlatNotebook):
                 win.SetValue(color)
             else:
                 win.SetValue(data['points'][prop]['value'])
-        self.OnCheckThematic(None)
+##        self.OnCheckThematic(None)
         # height
         for type in ('slider', 'text'):
             win = self.FindWindowById(self.win['vector']['points']['height'][type])

+ 48 - 5
gui/wxpython/gui_modules/workspace.py

@@ -387,7 +387,20 @@ class ProcessWorkspaceFile:
                 # height
                 self.__processLayerNvizNode(node_vpoints, 'size', int,
                                             nviz['vector']['points'])
-            
+                
+                # thematic
+                node_thematic = node_vpoints.find('thematic')
+                thematic = nviz['vector']['points']['thematic'] = {}
+                thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
+                thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
+                for col in ('rgbcolumn', 'sizecolumn'):
+                    if thematic[col] == 'None':
+                        thematic[col] = None
+                thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
+                for use in ('usecolor', 'usesize', 'usewidth'):
+                    if node_thematic.get(use, ''):
+                        thematic[use] = int(node_thematic.get(use, '0'))
+                
             # vlines
             node_vlines = node_nviz.find('vlines')
             if node_vlines is not None:
@@ -417,6 +430,19 @@ class ProcessWorkspaceFile:
                 # height
                 self.__processLayerNvizNode(node_vlines, 'height', int,
                                             nviz['vector']['lines'])
+                
+                # thematic
+                node_thematic = node_vlines.find('thematic')
+                thematic = nviz['vector']['lines']['thematic'] = {}
+                thematic['rgbcolumn'] = self.__processLayerNvizNode(node_thematic, 'rgbcolumn', str)
+                thematic['sizecolumn'] = self.__processLayerNvizNode(node_thematic, 'sizecolumn', str)
+                for col in ('rgbcolumn', 'sizecolumn'):
+                    if thematic[col] == 'None':
+                        thematic[col] = None
+                thematic['layer'] = self.__processLayerNvizNode(node_thematic, 'layer', int)
+                for use in ('usecolor', 'usesize', 'usewidth'):
+                    if node_thematic.get(use, ''):
+                        thematic[use] = int(node_thematic.get(use, '0'))
             
         return nviz
     
@@ -711,7 +737,8 @@ class Nviz:
                             'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
                                                       subkey=['lines', 'sizecolumn']),
                             'layer': 1,
-                            'use' : False}
+                            'usecolor' : False,
+                            'usewidth' : False}
         if 'object' in data:
             for attrb in ('color', 'width', 'mode', 'height'):
                 data[attrb]['update'] = None
@@ -749,7 +776,8 @@ class Nviz:
                             'sizecolumn' : UserSettings.Get(group='nviz', key='vector',
                                                       subkey=['points', 'sizecolumn']),
                             'layer': 1,
-                            'use' : False}
+                            'usecolor' : False,
+                            'usesize' : False}
         if 'object' in data:
             for attrb in ('size', 'width', 'marker',
                           'color', 'surface', 'height', 'thematic'):
@@ -1123,7 +1151,7 @@ class WriteWorkspaceFile(object):
                                                            marker))
             self.indent += 4
             for name in data[attrb].iterkeys():
-                if name in ('object', 'marker', 'thematic'):
+                if name in ('object', 'marker'):
                     continue
                 if name == 'mode':
                     self.file.write('%s<%s type="%s">\n' % (' ' * self.indent, name,
@@ -1140,6 +1168,21 @@ class WriteWorkspaceFile(object):
                             self.file.write('%s</map>\n' % (' ' * self.indent))
                         self.indent -= 4
                     self.file.write('%s</%s>\n' % ((' ' * self.indent, name)))
+                elif name == 'thematic':
+                    self.file.write('%s<%s ' % (' ' * self.indent, name))
+                    for key in data[attrb][name].iterkeys():
+                        if key.startswith('use'):
+                            self.file.write('%s="%s" ' % (key, int(data[attrb][name][key])))
+                    self.file.write('>\n')
+                    self.indent += 4
+                    for key, value in data[attrb][name].iteritems():
+                        if key.startswith('use'):
+                            continue
+                        if value is None:
+                            value = ''
+                        self.file.write('%s<%s>%s</%s>\n' % (' ' * self.indent, key, value, key))
+                    self.indent -= 4
+                    self.file.write('%s</%s>\n' % (' ' * self.indent, name))
                 else:
                     self.file.write('%s<%s>\n' % (' ' * self.indent, name))
                     self.indent += 4
@@ -1219,7 +1262,7 @@ class WriteWorkspaceFile(object):
         self.indent -= 4
         self.file.write('%s</focus>\n' % (' ' * self.indent))
         # background
-        self.__writeTagWithValue('background_color', view['background']['color'], format = 'd:%d:%d')
+        self.__writeTagWithValue('background_color', view['background']['color'][:3], format = 'd:%d:%d')
         
         self.indent -= 4
         self.file.write('%s</view>\n' % (' ' * self.indent))

+ 65 - 8
gui/wxpython/gui_modules/wxnviz.py

@@ -29,6 +29,7 @@ from ctypes import *
 try:
     from grass.lib.gis   import *
     from grass.lib.raster3d   import *
+    from grass.lib.vector  import *
     from grass.lib.ogsf  import *
     from grass.lib.nviz  import *
     from grass.lib.raster import *
@@ -84,6 +85,9 @@ class Nviz(object):
         
         self.data_obj = nv_data()
         self.data = pointer(self.data_obj)
+        self.color_obj = Colors()
+        self.color = pointer(self.color_obj)
+        
         self.width = self.height = -1
         self.showLight = False
         
@@ -943,21 +947,74 @@ class Nviz(object):
         
         return 1
 
-    def SetPointsStyleThematic(self, id, layer, color = None, width = None, size = None, symbol = None):
-        """!Set thematic style for vector points"""
-        GP_set_style_thematic(id, layer, color, width, size, symbol)
+    def ReadVectorColors(self, name, mapset):
+        """!Read vector colors
+        
+        @param name vector map name
+        @mapset mapset name ("" for search path)
+        
+        @return -1 on error 
+        @return 0 if color table missing 
+        @return 1 on success (color table found) 
+        """
+        return Vect_read_colors(name, mapset, self.color)
+        
+    def SetPointsStyleThematic(self, id, layer, color = None, colorTable = False, 
+                               width = None, size = None, symbol = None):
+        """!Set thematic style for vector points
+        
+        @param id vector set id
+        @param layer layer number for thematic mapping
+        @param colorTable use color table 
+        @param color color column name 
+        @param width width column name 
+        @param size size column name 
+        @param symbol symbol column name 
+        """
+        file = c_char_p()
+        ret = GP_get_sitename(id, byref(file))
+        if ret < 0:
+            return -1
+        
+        ret = self.ReadVectorColors(file, "")
+        if ret < 0:
+            return -1
+        
+        if colorTable:
+            GP_set_style_thematic(id, layer, color, width, size, symbol, self.color)
+        else:
+            GP_set_style_thematic(id, layer, color, width, size, symbol, None)
 
-    def SetLinesStyleThematic(self, id, layer, color = None, width = None):
-        """!Set thematic style for vector lines"""
-        GV_set_style_thematic(id, layer, color, width) 
+    def SetLinesStyleThematic(self, id, layer, color = None, colorTable = False, width = None):
+        """!Set thematic style for vector lines
+        
+        @param id vector set id
+        @param layer layer number for thematic mapping
+        @param color color column name 
+        @param colorTable use color table 
+        @param width width column name 
+        """
+        file = c_char_p()
+        ret = GV_get_vectname(id, byref(file))
+        if ret < 0:
+            return -1
+        
+        ret = self.ReadVectorColors(file, "")
+        if ret < 0:
+            return -1
+        
+        if colorTable:
+            GV_set_style_thematic(id, layer, color, width, self.color)
+        else:
+            GV_set_style_thematic(id, layer, color, width, None)
         
     def UnsetLinesStyleThematic(self, id):
         """!Unset thematic style for vector points"""
-        GP_unset_style_thematic(id)      
+        GV_unset_style_thematic(id)      
          
     def UnsetPointsStyleThematic(self, id):
         """!Unset thematic style for vector lines"""
-        GV_unset_style_thematic(id)
+        GP_unset_style_thematic(id)
         
     def UnsetVectorPointSurface(self, id, surf_id):
         """!Unset reference surface of vector set (points)

+ 1 - 1
gui/wxpython/wxgui.py

@@ -1041,7 +1041,7 @@ class GMFrame(wx.Frame):
         if cmd[0] == 'r.colors':
             ctable = colorrules.RasterColorTable(self)
         else:
-            ctable = colorrules.VectorColorTable(self)
+            ctable = colorrules.VectorColorTable(self, attributeType = 'color')
         ctable.CentreOnScreen()
         ctable.Show()