[GRASS-SVN] r37938 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules xml

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 18 18:06:26 EDT 2009


Author: martinl
Date: 2009-06-18 18:06:26 -0400 (Thu, 18 Jun 2009)
New Revision: 37938

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
   grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd
Log:
wxGUI: move geometry attributes settings to the workspace
       (merge from trunk, r37937)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -1147,8 +1147,10 @@
                                                                    action="add")
 
                 if not point:
-                    self.__geomAttrb(fid, addRecordDlg, 'area', digitClass)
-                    self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass)
+                    self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
+                                     digitToolbar.GetLayer())
+                    self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
+                                     digitToolbar.GetLayer())
 
                 if addRecordDlg.mapDBInfo and \
                         addRecordDlg.ShowModal() == wx.ID_OK:
@@ -1170,10 +1172,11 @@
             self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
             self.DrawLines(pdc=self.pdcTmp)
     
-    def __geomAttrb(self, fid, dialog, attrb, digit):
+    def __geomAttrb(self, fid, dialog, attrb, digit, mapLayer):
         """!Trac geometry attributes?"""
-        if UserSettings.Get(group = 'vdigit', key = 'geomAttrb',
-                            subkey = [attrb, 'enabled'], internal = True):
+        item = self.tree.FindItemByData('maplayer', mapLayer)
+        vdigit = self.tree.GetPyData(item)[0]['vdigit']
+        if vdigit.has_key('geomAttr') and vdigit['geomAttr'].has_key(attrb):
             val = -1
             if attrb == 'length':
                 val = digit.GetLineLength(fid)
@@ -1184,8 +1187,7 @@
             
             if val > 0:
                 layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
-                column =  UserSettings.Get(group = 'vdigit', key = 'geomAttrb',
-                                           subkey = [attrb, 'column'], internal = True)
+                column =  vdigit['geomAttr'][attrb]
                 dialog.SetColumnValue(layer, column, val)
                 dialog.OnReset()
         
@@ -1960,7 +1962,6 @@
                     self.redrawAll = True
                     
                     # add new record into atribute table
-                    print UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled'), line, fid
                     if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') and \
                             (line is True or \
                                  (not line and fid > 0)):
@@ -1978,10 +1979,13 @@
                                                                            pos=posWindow,
                                                                            action="add")
 
-                        self.__geomAttrb(fid, addRecordDlg, 'length', digitClass)
+                        self.__geomAttrb(fid, addRecordDlg, 'length', digitClass,
+                                         digitToolbar.GetLayer())
                         # auto-placing centroid
-                        self.__geomAttrb(fid, addRecordDlg, 'area', digitClass)
-                        self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass)
+                        self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
+                                         digitToolbar.GetLayer())
+                        self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
+                                         digitToolbar.GetLayer())
 
                         if addRecordDlg.mapDBInfo and \
                                addRecordDlg.ShowModal() == wx.ID_OK:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -34,7 +34,6 @@
 import wx.lib.filebrowsebutton as filebrowse
 import wx.lib.colourselect as csel
 import wx.lib.mixins.listctrl as listmix
-from wx.lib.wordwrap import wordwrap
 
 from grass.script import core as grass
 import gcmd
@@ -554,13 +553,6 @@
                                                                        _("histogram"))
         self.internalSettings['vdigit']['bgmap'] = {}
         self.internalSettings['vdigit']['bgmap']['value'] = ''
-        self.internalSettings['vdigit']['geomAttrb'] = dict()
-        self.internalSettings['vdigit']['geomAttrb']['length'] = { 'enabled' : False,
-                                                                   'column' : '' }
-        self.internalSettings['vdigit']['geomAttrb']['area']   = { 'enabled' : False,
-                                                                   'column' : '' }
-        self.internalSettings['vdigit']['geomAttrb']['perimeter']   = { 'enabled' : False,
-                                                                        'column' : '' }
         
     def ReadSettingsFile(self, settings=None):
         """!Reads settings file (mapset, location, gisdbase)"""

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -33,6 +33,7 @@
 import sys
 import string
 import copy
+import textwrap
 
 from threading import Thread
 
@@ -1513,8 +1514,8 @@
         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY,
                               label = " %s " % _("Geometry attributes"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-        flexSizer = wx.FlexGridSizer(cols=3, hgap=3, vgap=3)
-        flexSizer.AddGrowableCol(0)
+        gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
+        gridSizer.AddGrowableCol(0)
         self.geomAttrb = { 'length' : { 'label' : _('length') },
                            'area' : { 'label' : _('area') },
                            'perimeter' : { 'label' : _('perimeter') } }
@@ -1525,6 +1526,10 @@
         except AttributeError:
             vectorName = None # no vector selected for editing
         layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
+        mapLayer = self.parent.toolbars['vdigit'].GetLayer()
+        tree = self.parent.tree
+        item = tree.FindItemByData('maplayer', mapLayer)
+        row = 0
         for attrb in ['length', 'area', 'perimeter']:
             # checkbox
             check = wx.CheckBox(parent = panel, id = wx.ID_ANY,
@@ -1542,13 +1547,14 @@
                               choices = [_("map units")])
             
             # default values
-            check.SetValue(UserSettings.Get(group='vdigit', key='geomAttrb',
-                                            subkey=[attrb, 'enabled'],
-                                            internal=True))
-            column.SetStringSelection(UserSettings.Get(group='vdigit', key='geomAttrb',
-                                                       subkey=[attrb, 'column'],
-                                                       internal=True))
+            check.SetValue(False)
             
+            if item and tree.GetPyData(item)[0]['vdigit'] and \
+                    tree.GetPyData(item)[0]['vdigit'].has_key('geomAttr') and \
+                    tree.GetPyData(item)[0]['vdigit']['geomAttr'].has_key(attrb):
+                check.SetValue(True)
+                column.SetStringSelection(tree.GetPyData(item)[0]['vdigit']['geomAttr'][attrb])
+            
             if not vectorName:
                 check.Enable(False)
                 column.Enable(False)
@@ -1560,12 +1566,23 @@
             self.geomAttrb[attrb]['column'] = column.GetId()
             self.geomAttrb[attrb]['units']  = units.GetId()
 
-            flexSizer.Add(item = check, proportion = 0,
-                          flag = wx.ALIGN_CENTER_VERTICAL)
-            flexSizer.Add(item = column, proportion = 0)
-            flexSizer.Add(item = units, proportion = 0)
-
-        sizer.Add(item=flexSizer, proportion=1,
+            gridSizer.Add(item = check,
+                          flag = wx.ALIGN_CENTER_VERTICAL,
+                          pos = (row, 0))
+            gridSizer.Add(item = column,
+                          pos = (row, 1))
+            gridSizer.Add(item = units,
+                          pos = (row, 2))
+            row += 1
+        
+        note = '\n'.join(textwrap.wrap(_("Note: These settings are stored "
+                                         " in the workspace not in the vector digitizer "
+                                         "preferences."), 55))
+        gridSizer.Add(item = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                                           label = note),
+                      pos = (3, 0), span=(1, 3))
+                      
+        sizer.Add(item=gridSizer, proportion=1,
                   flag=wx.ALL | wx.EXPAND, border=1)
         border.Add(item=sizer, proportion=0,
                    flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5)
@@ -1786,16 +1803,21 @@
         UserSettings.Set(group='vdigit', key="delRecord", subkey='enabled',
                          value=self.deleteRecord.IsChecked())
 
-        # geometry attributes
+        # geometry attributes (workspace)
+        mapLayer = self.parent.toolbars['vdigit'].GetLayer()
+        tree = self.parent.tree
+        item = tree.FindItemByData('maplayer', mapLayer)
         for key, val in self.geomAttrb.iteritems():
             checked = self.FindWindowById(val['check']).IsChecked()
             column  = self.FindWindowById(val['column']).GetValue()
-            UserSettings.Set(group = 'vdigit', key = 'geomAttrb',
-                             subkey = [key, 'enabled'], value = checked,
-                             internal = True)
-            UserSettings.Set(group = 'vdigit', key = 'geomAttrb',
-                             subkey = [key, 'column'], value = column,
-                             internal = True)
+            if not tree.GetPyData(item)[0]['vdigit']: 
+                tree.GetPyData(item)[0]['vdigit'] = { 'geomAttr' : dict() }
+            
+            if checked: # enable
+                tree.GetPyData(item)[0]['vdigit']['geomAttr'][key] = column
+            else:
+                if tree.GetPyData(item)[0]['vdigit']['geomAttr'].has_key(key):
+                    del tree.GetPyData(item)[0]['vdigit']['geomAttr'][key]
         
         # snapping threshold
         self.parent.digit.threshold = self.parent.digit.driver.GetThreshold()

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/workspace.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -166,8 +166,8 @@
                         "nviz"    : None})
                 
             elif item.tag == 'layer':
-                cmd, selected, nviz = self.__processLayer(item)
-                
+                cmd, selected, vdigit, nviz = self.__processLayer(item)
+
                 self.layers.append( {
                         "type"     : item.get('type', None),
                         "name"     : item.get('name', None),
@@ -177,8 +177,9 @@
                         "group"    : False, #### self.inTag['group'], # ???
                         "display"  : self.displayIndex,
                         "selected" : selected,
+                        "vdigit"   : vdigit,
                         "nviz"     : nviz } )
-        
+            
     def __processLayer(self, layer):
         """!Process layer item
 
@@ -210,6 +211,15 @@
             selected = False
         
         #
+        # Vector digitizer settings
+        #
+        node_vdigit = layer.find('vdigit')
+        if node_vdigit is not None:
+            vdigit = self.__processLayerVdigit(node_vdigit)
+        else:
+            vdigit = None
+        
+        #
         # Nviz (3D settings)
         #
         node_nviz = layer.find('nviz')
@@ -218,8 +228,22 @@
         else:
             nviz = None
         
-        return (cmd, selected, nviz)
+        return (cmd, selected, vdigit, nviz)
 
+    def __processLayerVdigit(self, node_vdigit):
+        """!Process vector digitizer layer settings
+
+        @param node_vdigit vdigit node
+        """
+        # init nviz layer properties
+        vdigit = dict()
+        for node in node_vdigit.findall('geometryAttribute'):
+            if not vdigit.has_key('geomAttr'):
+                vdigit['geomAttr'] = dict()
+            vdigit['geomAttr'][node.get('type')] = node.get('column')
+        
+        return vdigit
+    
     def __processLayerNviz(self, node_nviz):
         """!Process 3D layer settings
 
@@ -741,16 +765,28 @@
                         self.file.write('%s</parameter>\n' % (' ' * self.indent));
                 self.indent -= 4
                 self.file.write('%s</task>\n' % (' ' * self.indent));
+                # vector digitizer
+                vdigit = mapTree.GetPyData(item)[0]['vdigit']
+                if vdigit:
+                    self.file.write('%s<vdigit>\n' % (' ' * self.indent))
+                    if vdigit.has_key('geomAttr'):
+                        self.indent += 4
+                        for type, column in vdigit['geomAttr'].iteritems():
+                            self.file.write('%s<geometryAttribute type="%s" column="%s" />\n' % \
+                                                (' ' * self.indent, type, column))
+                        self.indent -= 4
+                    self.file.write('%s</vdigit>\n' % (' ' * self.indent))
+                # nviz
                 nviz = mapTree.GetPyData(item)[0]['nviz']
                 if nviz:
-                    self.file.write('%s<nviz>\n' % (' ' * self.indent));
+                    self.file.write('%s<nviz>\n' % (' ' * self.indent))
                     if maplayer.type == 'raster':
                         self.__writeNvizSurface(nviz['surface'])
                     elif maplayer.type == 'vector':
                         self.__writeNvizVector(nviz['vector'])
-                    self.file.write('%s</nviz>\n' % (' ' * self.indent));
+                    self.file.write('%s</nviz>\n' % (' ' * self.indent))
                 self.indent -= 4
-                self.file.write('%s</layer>\n' % (' ' * self.indent));
+                self.file.write('%s</layer>\n' % (' ' * self.indent))
             item = mapTree.GetNextSibling(item)
         self.indent -= 4
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -1,4 +1,4 @@
-"""
+"""!
 @package wxgui_utils.py
 
 @brief Utility classes for GRASS wxPython GUI. Main functions include
@@ -605,7 +605,7 @@
         self.EditLabel(self.layer_selected)
 
     def AddLayer(self, ltype, lname=None, lchecked=None,
-                 lopacity=1.0, lcmd=None, lgroup=None, lnviz=None):
+                 lopacity=1.0, lcmd=None, lgroup=None, lvdigit=None, lnviz=None):
         """!Add new item to the layer tree, create corresponding MapLayer instance.
         Launch property dialog if needed (raster, vector, etc.)
 
@@ -615,9 +615,9 @@
         @param lopacity layer opacity level
         @param lcmd command (given as a list)
         @param lgroup group name or None
+        @param lvdigit vector digitizer settings (eg. geometry attributes)
         @param lnviz layer Nviz properties
         """
-
         self.first = True
         params = {} # no initial options parameters
 
@@ -758,14 +758,15 @@
                 ctrlId = None
                 
             # add a data object to hold the layer's command (does not apply to generic command layers)
-            self.SetPyData(layer, ({'cmd': cmd,
-                                    'type' : ltype,
-                                    'ctrl' : ctrlId,
+            self.SetPyData(layer, ({'cmd'      : cmd,
+                                    'type'     : ltype,
+                                    'ctrl'     : ctrlId,
                                     'maplayer' : None,
-                                    'nviz' : lnviz,
-                                    'propwin' : None}, 
+                                    'vdigit'   : lvdigit,
+                                    'nviz'     : lnviz,
+                                    'propwin'  : None}, 
                                    None))
-
+            
             # find previous map layer instance 
             prevItem = self.GetFirstChild(self.root)[0]
             prevMapLayer = None 

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2009-06-18 22:06:26 UTC (rev 37938)
@@ -670,7 +670,8 @@
                                        lopacity=layer['opacity'],
                                        lcmd=layer['cmd'],
                                        lgroup=layer['group'],
-                                       lnviz=layer['nviz'])
+                                       lnviz=layer['nviz'],
+                                       lvdigit=layer['vdigit'])
             
             if layer.has_key('selected'):
                 if layer['selected']:

Modified: grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd	2009-06-18 21:57:16 UTC (rev 37937)
+++ grass/branches/develbranch_6/gui/wxpython/xml/grass-gxw.dtd	2009-06-18 22:06:26 UTC (rev 37938)
@@ -77,6 +77,18 @@
 <!ELEMENT flag          EMPTY>
 <!ATTLIST flag          name            CDATA #REQUIRED>
 
+<!-- *********************** Vector digitizer *********************** -->
+
+<!--    vdigit layer properties
+-->
+<!ELEMENT vdigit	    (geometryAttribute?)>
+
+<!--    geometry attribute parameter
+-->
+<!ELEMENT geometryAttribute EMPTY>
+<!ATTLIST parameter	type	(length | area | perimeter) #REQUIRED>
+<!ATTLIST parameter	column	CDATA                       #REQUIRED>
+
 <!-- *********************** Nviz *********************** -->
 
 <!--    nviz layer properties



More information about the grass-commit mailing list