[GRASS-SVN] r29985 - in grass/trunk/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 6 17:04:40 EST 2008


Author: martinl
Date: 2008-02-06 17:04:40 -0500 (Wed, 06 Feb 2008)
New Revision: 29985

Modified:
   grass/trunk/gui/wxpython/gui_modules/digit.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/vdigit/line.cpp
Log:
wxGUI: load digit instance dynamically, the interface (vedit/vdigit) can be changed in preferences dialog.
Minor fix in vdigit component.


Modified: grass/trunk/gui/wxpython/gui_modules/digit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/digit.py	2008-02-06 21:43:37 UTC (rev 29984)
+++ grass/trunk/gui/wxpython/gui_modules/digit.py	2008-02-06 22:04:40 UTC (rev 29985)
@@ -45,6 +45,7 @@
 import dbm
 from debug import Debug as Debug
 import gselect 
+from preferences import globalSettings as UserSettings
 try:
     digitPath = os.path.join(os.getenv("GISBASE"), "etc", "wx", "vdigit")
     sys.path.append(digitPath)
@@ -56,19 +57,15 @@
           "Detailed information in README file." % \
           (os.linesep, err)
 
-#
-# Use v.edit on background or experimental C++ interface (not yet completed)
-#
-USEVEDIT = False
-if USEVEDIT is True and GV_LINES is not None:
-    print >> sys.stderr, "%sWARNING: Digitization tool uses v.edit interface by default. " \
+# which interface to use?
+if UserSettings.Get('digitInterface') == 'vedit' and GV_LINES is not None:
+    print >> sys.stderr, "%sWARNING: Digitization tool uses v.edit interface. " \
         "This can significantly slow down some operations especially for " \
         "middle-large vector maps. "\
-        "You can enable experimental vdigit interface by setting " \
-          "USEVEDIT to False in digit.py file." % \
+        "You can change the digitization interface in 'User preferences' " \
+        "(menu 'Config'->'Preferences')." % \
           os.linesep
 
-
 class AbstractDigit:
     """
     Abstract digitization class
@@ -146,7 +143,7 @@
         self.settings['category'] = 1
 
         if self.map:
-            if USEVEDIT:
+            if UserSettings.Get('digitInterface') == 'vedit':
                 categoryCmd = gcmd.Command(cmd=["v.category", "-g", "--q",
                                                 "input=%s" % self.map, 
                                                 "option=report"])
@@ -192,7 +189,7 @@
             raise gcmd.DigitError(_('Closing vector map <%s> failed. The vector map is probably broken. '
                                'Try to run v.build for rebuilding the topology.') % map)
             
-        if not USEVEDIT:
+        if UserSettings.Get('digitInterface') != 'v.edit':
             try:
                 self.digit.InitCats()
             except:
@@ -1034,7 +1031,7 @@
 
         return (snap, thresh)
 
-if USEVEDIT:
+if UserSettings.Get('digitInterface') == 'vedit':
     class Digit(VEdit):
         """Default digit class"""
         def __init__(self, mapwindow):
@@ -1138,7 +1135,7 @@
         if map:
             name, mapset = map.split('@')
             try:
-                if USEVEDIT:
+                if UserSettings.Get('digitInterface') == 'vedit':
                     ret = self.__display.OpenMap(str(name), str(mapset), False)
                 else:
                     ret = self.__display.OpenMap(str(name), str(mapset), True)
@@ -2150,7 +2147,7 @@
                             cat not in cats[1][layer]:
                         catList.append(cat)
                 if catList != []:
-                    if USEVEDIT is True:
+                    if UserSettings.Get('digitInterface') == 'vedit':
                         vEditCmd = ['v.edit', '--q',
                                     'map=%s' % self.map,
                                     'layer=%d' % layer,
@@ -2169,7 +2166,7 @@
                         if self.line < 0:
                             wx.MessageBox(parent=self, message=_("Unable to update vector map."),
                                           caption=_("Error"), style=wx.OK | wx.ICON_ERROR)
-        if USEVEDIT is True:           
+        if UserSettings.Get('digitInterface') == 'vedit':           
             # reload map (needed for v.edit)
             self.parent.parent.digit.driver.ReloadMap()
 

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-02-06 21:43:37 UTC (rev 29984)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-02-06 22:04:40 UTC (rev 29985)
@@ -63,7 +63,6 @@
 import profile
 import globalvar
 import utils
-from digit import Digit               as Digit
 from digit import DigitCategoryDialog as DigitCategoryDialog
 from digit import DigitZBulkDialog    as DigitZBulkDialog
 from digit import GV_LINES            as Digit_Lines_Type
@@ -2223,11 +2222,6 @@
         self.projinfo = self.Map.ProjInfo()
 
         #
-        # Initialization of digitization tool
-        #
-        self.digit = Digit(mapwindow=self.MapWindow)
-
-        #
         # Init zoom history
         #
         self.MapWindow.ZoomHistory(self.Map.region['n'],

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-02-06 21:43:37 UTC (rev 29984)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2008-02-06 22:04:40 UTC (rev 29985)
@@ -35,19 +35,36 @@
     """Generic class where to store settings"""
     def __init__(self):
         self.defaultSettings = {
+            # general
             'displayFont' : '',
-            'digitInterface' : 'v.edit',
+            # advanced
+            'settingsFile' : 'home', # home, location, mapset
+            'digitInterface' : 'vedit', # vedit, vdigit
             }
         
         self.userSettings = copy.deepcopy(self.defaultSettings)
 
     def Get(self, key):
-        """Get user settings"""
+        """Get value by key
+
+        @return value
+        @return None if key not found
+        """
         if self.userSettings.has_key(key):
             return self.userSettings[key]
         else:
             None
+    
+    def Set(self, key, value):
+        """Set value by key
 
+        Raise KeyError if key is not found
+        """
+        if self.userSettings.has_key(key):
+            self.userSettings[key] = value
+        else:
+            raise KeyError
+
 globalSettings = Settings()
 
 class PreferencesDialog(wx.Dialog):
@@ -117,7 +134,7 @@
                        wx.ALIGN_CENTER_VERTICAL,
                        pos=(0, 0))
         fontButton = wx.Button(parent=panel, id=wx.ID_ANY,
-                               label=_("Set font"))
+                               label=_("Set font"), size=(100, -1))
         gridSizer.Add(item=fontButton,
                       flag=wx.ALIGN_RIGHT |
                        wx.ALIGN_CENTER_VERTICAL,
@@ -151,25 +168,41 @@
         gridSizer.AddGrowableCol(0)
 
         #
-        # digitization interface
+        # place where to store settings
         #
         gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
-                                         label=_("Digitization interface:")),
+                                         label=_("Place where to store settings:")),
                        flag=wx.ALIGN_LEFT |
                        wx.ALIGN_CENTER_VERTICAL,
                        pos=(0, 0))
-        digitIF = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
-                            choices=['v.digit', 'v.edit'])
-        digitIF.SetStringSelection(self.settings.Get('digitInterface'))
-        gridSizer.Add(item=digitIF,
+        self.settingsFile = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
+                                      choices=['home', 'location', 'mapset'])
+        self.settingsFile.SetStringSelection(self.settings.Get('settingsFile'))
+        gridSizer.Add(item=self.settingsFile,
                       flag=wx.ALIGN_RIGHT |
                       wx.ALIGN_CENTER_VERTICAL,
                       pos=(0, 1))
 
+        #
+        # digitization interface
+        #
+        gridSizer.Add(item=wx.StaticText(parent=panel, id=wx.ID_ANY,
+                                         label=_("Digitization interface:")),
+                       flag=wx.ALIGN_LEFT |
+                       wx.ALIGN_CENTER_VERTICAL,
+                       pos=(1, 0))
+        self.digitInterface = wx.Choice(parent=panel, id=wx.ID_ANY, size=(125, -1),
+                                        choices=['vdigit', 'vedit'])
+        self.digitInterface.SetStringSelection(self.settings.Get('digitInterface'))
+        gridSizer.Add(item=self.digitInterface,
+                      flag=wx.ALIGN_RIGHT |
+                      wx.ALIGN_CENTER_VERTICAL,
+                      pos=(1, 1))
+
         digitNote = wordwrap(_("Note: User can choose from two interfaces for digitization. "
                                "The simple one uses v.edit command on the background. "
                                "Map topology is rebuild on each operation which can "
-                               "significantly slow-down response. The v.digit is a native "
+                               "significantly slow-down response. The vdigit is a native "
                                "interface which uses v.edit functionality, but doesn't "
                                "call the command itself."),
                              self.GetSize()[0]-50, wx.ClientDC(self))
@@ -178,7 +211,7 @@
                                          label=digitNote),
                       flag=wx.ALIGN_LEFT |
                       wx.ALIGN_CENTER_VERTICAL,
-                      pos=(1, 0), span=(1, 2))
+                      pos=(2, 0), span=(1, 2))
 
         sizer.Add(item=gridSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5)
         border.Add(item=sizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=3)
@@ -215,16 +248,28 @@
 
     def OnOK(self, event):
         """Button 'OK' clicked"""
+        self.__UpdateSettings()
         self.Close()
 
     def OnApply(self, event):
         """Button 'Apply' clicked"""
-        pass
-
+        self.__UpdateSettings()
+        
     def OnCancel(self, event):
         """Button 'Cancel' clicked"""
         self.Close()
 
+    def __UpdateSettings(self):
+        """Update user settings"""
+        # font
+        # TODO
+
+        # location
+        self.settings.Set('settingsFile', self.settingsFile.GetStringSelection())
+        
+        # digitization interface
+        self.settings.Set('digitInterface', self.digitInterface.GetStringSelection())
+
 class SetDefaultFont(wx.Dialog):
     """
     Opens a file selection dialog to select default font

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-02-06 21:43:37 UTC (rev 29984)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-02-06 22:04:40 UTC (rev 29985)
@@ -25,7 +25,7 @@
 
 import gcmd
 import grassenv
-from digit import Digit as Digit
+import digit
 from digit import DigitSettingsDialog as DigitSettingsDialog
 from debug import Debug as Debug
 from icon import Icons as Icons
@@ -593,6 +593,9 @@
         @return True on success
         @return False on error
         """
+        reload(digit)
+        from digit import Digit as Digit
+        self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
         try:
             self.layerSelectedID = self.layers.index(layerSelected)
             mapLayer = self.layers[self.layerSelectedID]
@@ -657,8 +660,11 @@
             self.parent.MapWindow.pdcVector = None
             self.parent.digit.driver.SetDevice(None)
 
+            self.parent.digit = None
+
             return True
 
+        
         return False
 
     def UpdateListOfLayers (self, updateTool=False):

Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp	2008-02-06 21:43:37 UTC (rev 29984)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp	2008-02-06 22:04:40 UTC (rev 29985)
@@ -258,7 +258,7 @@
 	for (int i = 0; i < display->selected->n_values; i++) {
 	    if (Vect_read_line(display->mapInfo, NULL, Cats, display->selected->value[i]) < 0) {
 		Vect_destroy_cats_struct(Cats_del);
-		Vect_destroy_list(List);
+		//Vect_destroy_list(List);
 		return -1;
 	    }
 	    for (int j = 0; j < Cats->n_cats; j++) {



More information about the grass-commit mailing list