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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 16 11:45:58 EST 2008


Author: martinl
Date: 2008-01-16 11:45:58 -0500 (Wed, 16 Jan 2008)
New Revision: 29719

Modified:
   grass/trunk/gui/wxpython/Makefile
   grass/trunk/gui/wxpython/gui_modules/digit.py
   grass/trunk/gui/wxpython/gui_modules/render.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/vdigit/cats.cpp
   grass/trunk/gui/wxpython/vdigit/driver.cpp
   grass/trunk/gui/wxpython/vdigit/driver.h
   grass/trunk/gui/wxpython/vdigit/line.cpp
Log:
wxGUI: Some updates for digitization tool, to avoid calling v.edit on the background

Modified: grass/trunk/gui/wxpython/Makefile
===================================================================
--- grass/trunk/gui/wxpython/Makefile	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/Makefile	2008-01-16 16:45:58 UTC (rev 29719)
@@ -2,10 +2,12 @@
 
 PGM=wxgrass
 
-include $(MODULE_TOPDIR)/include/Make/Script.make
+SUBDIRS=vdigit
 
-default: install_scripts
+include $(MODULE_TOPDIR)/include/Make/Dir.make
 
+default: parsubdirs install_scripts
+
 install_scripts:
 	$(MKDIR) $(ETC)/wx/wx $(ETC)/wx/compat $(ETC)/wx/vdigit $(ETC)/wx/gui_modules $(ETC)/wx/icons $(ETC)/wx/icons/silk $(ETC)/wx/images  $(ETC)/wx/scripts
 	$(INSTALL_DATA) compat/* $(ETC)/wx/compat/
@@ -17,3 +19,5 @@
 	$(INSTALL_DATA) scripts/* $(ETC)/wx/scripts/
 	$(INSTALL_DATA) gis_set.py wxgui.py $(ETC)/wx/
 	$(INSTALL) -m 755 wxgrass $(GISBASE)/scripts/
+
+clean: cleansubdirs

Modified: grass/trunk/gui/wxpython/gui_modules/digit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/digit.py	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/gui_modules/digit.py	2008-01-16 16:45:58 UTC (rev 29719)
@@ -46,14 +46,17 @@
 from debug import Debug as Debug
 import gselect 
 try:
-    digitPath = os.path.join(os.getenv("GISBASE"), "etc","wx", "vdigit")
+    digitPath = os.path.join(os.getenv("GISBASE"), "etc", "wx", "vdigit")
     sys.path.append(digitPath)
-    from grass6_wxvdigit import DisplayDriver
+    import grass6_wxvdigit as vdigit
 except ImportError, err:
-    print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s).%s" \
+    print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s). " \
           "Detailed information in README file." % \
-          (os.linesep, err, os.linesep)
+          (os.linesep, err)
 
+#
+# Use v.edit on background or experimental C++ interface (not yet completed)
+#
 USEVEDIT = True
 
 class DigitError(Exception):
@@ -62,9 +65,12 @@
 
     def __str__(self):
         wx.MessageBox(parent=None,
+                      caption=_("Error in digitization tool"),
                       message=self.message,
                       style=wx.ICON_ERROR)
 
+        return ''
+
 class AbstractDigit:
     """
     Abstract digitization class
@@ -173,9 +179,19 @@
         Debug.msg (3, "AbstractDigit.SetMapName map=%s" % map)
         self.map = map
 
-        self.driver.Reset(self.map)
+        ret = self.driver.Reset(self.map)
+        if map and ret == -1:
+            raise DigitError(_('Unable to open vector map <%s> for editing. The vector map is probably broken. '
+                               'Try to run v.build for rebuilding the topology.') % map)
+        if not map and ret != 0:
+            raise 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:
-            self.digit.InitCats()
+            try:
+                self.digit.InitCats()
+            except:
+                pass
         
 class VEdit(AbstractDigit):
     """
@@ -192,7 +208,7 @@
         AbstractDigit.__init__(self, mapwindow, settings)
 
     def AddPoint (self, map, point, x, y, z=None):
-        """Add point/centroid to the vector map layer
+        """Add point/centroid
 
         @param map   map name
         @param point feature type (True for point, otherwise centroid)
@@ -226,7 +242,7 @@
         self.__AddFeature (map=map, input=addstring)
 
     def AddLine (self, map, line, coords):
-        """Add line/boundary to the vector map layer
+        """Add line/boundary
 
         @param map  map name
         @param line feature type (True for line, otherwise boundary)
@@ -267,7 +283,7 @@
         self.__AddFeature (map=map, input=addstring, flags=flags)
 
     def __AddFeature (self, map, input, flags=[]):
-        """General method for adding feature to the vector map layer
+        """Generic method to add new vector feature
 
         @param map   map name
         @param input feature definition in GRASS ASCII format
@@ -302,7 +318,7 @@
         self.driver.ReloadMap()
         
     def DeleteSelectedLines(self):
-        """Delete selected vector features from the vector map"""
+        """Delete selected features"""
         selected = self.driver.GetSelected() # grassId
 
         if len(selected) <= 0:
@@ -327,26 +343,28 @@
         return True
 
     def MoveSelectedLines(self, move):
-        """Move selected vector features
+        """Move selected features
 
         @param move X,Y direction
         """
         return self.__MoveFeature("move", None, move)
 
     def MoveSelectedVertex(self, coords, move):
-        """Move selected vertex of the line
+        """Move selected vertex
 
+        Feature geometry is changed.
+
         @param coords click coordinates
         @param move   X,Y direction
         """
         return self.__MoveFeature("vertexmove", coords, move)
 
     def __MoveFeature(self, tool, coords, move):
-        """Move selected vector feature or vertex
+        """Move selected vector feature (line, vertex)
 
         @param tool   tool for v.edit
         @param coords click coordinates
-        @param move   X,Y direction
+        @param move   direction (x, y)
         """
         selected = self.driver.GetSelected()
 
@@ -387,40 +405,15 @@
 
         return True
 
-    def SplitLine(self, coords):
-        """Split selected line on position 'coords'
-
-        @param coords coordinates to split line
-        """
-        try:
-            line = self.driver.GetSelected()[0]
-        except:
-            return False
-
-        command = ["v.edit", "--q",
-                   "map=%s" % self.map,
-                   "tool=break",
-                   "ids=%s" % line,
-                   "coords=%f,%f" % (float(coords[0]),float(coords[1])),
-                   "thresh=%f" % self.driver.GetThreshold()]
-
-        # run the command
-        vedit = gcmd.Command(cmd=command)
-
-        # redraw map
-        self.driver.ReloadMap()
-        
-        return True
-
     def AddVertex(self, coords):
-        """Add new vertex to the selected line on position 'coords'
+        """Add new vertex to the selected line/boundary on position 'coords'
 
         @param coords coordinates to add vertex
         """
         return self.__ModifyVertex(coords, "vertexadd")
 
     def RemoveVertex(self, coords):
-        """Remove vertex from the selected line on position 'coords'
+        """Remove vertex from the selected line/boundary on position 'coords'
 
         @param coords coordinates to remove vertex
         """
@@ -452,30 +445,33 @@
         
         return True
 
-    def CopyCats(self, cats, ids):
-        """Copy given categories to objects with id listed in ids
+    def SplitLine(self, coords):
+        """Split selected line/boundary on position 'coords'
 
-        @param cats list of cats to be copied
-        @param ids  ids of lines to be modified
+        @param coords coordinates to split line
         """
-        if len(cats) == 0 or len(ids) == 0:
+        try:
+            line = self.driver.GetSelected()[0]
+        except:
             return False
 
-        # collect cats
-        gcmd.Command(['v.edit',
-                     '--q',
-                     'map=%s' % self.map,
-                     'tool=catadd',
-                     'cats=%s' % ",".join(["%d" % v for v in cats]),
-                     'ids=%s' % ",".join(["%d" % v for v in ids])])
+        command = ["v.edit", "--q",
+                   "map=%s" % self.map,
+                   "tool=break",
+                   "ids=%s" % line,
+                   "coords=%f,%f" % (float(coords[0]),float(coords[1])),
+                   "thresh=%f" % self.driver.GetThreshold()]
+
+        # run the command
+        vedit = gcmd.Command(cmd=command)
+
+        # redraw map
+        self.driver.ReloadMap()
         
-        # reload map (needed for v.edit)
-        self.driver.ReloadMap()
-
         return True
 
     def EditLine(self, line, coords):
-        """Edit existing line
+        """Edit existing line/boundary
 
         @param line id of line to be modified
         @param coords list of coordinates of modified line
@@ -495,7 +491,7 @@
         self.driver.ReloadMap()
 
     def __ModifyLines(self, tool):
-        """Generic method to modify selected lines
+        """Generic method to modify selected lines/boundaries
 
         @param tool operation to be performed by v.edit
         """
@@ -521,25 +517,42 @@
         return True
 
     def FlipLine(self):
-        """Flip selected lines"""
+        """Flip selected lines/boundaries"""
         return self.__ModifyLines('flip')
 
     def MergeLine(self):
-        """Merge selected lines"""
+        """Merge selected lines/boundaries"""
         return self.__ModifyLines('merge')
 
     def BreakLine(self):
-        """Break selected lines"""
+        """Break selected lines/boundaries"""
         return self.__ModifyLines('break')
 
     def SnapLine(self):
-        """Snap selected lines"""
+        """Snap selected lines/boundaries"""
         return self.__ModifyLines('snap')
 
     def ConnectLine(self):
-        """Connect selected lines"""
+        """Connect selected lines/boundaries"""
         return self.__ModifyLines('connect')
 
+
+    def ZBulkLine(self, pos1, pos2, value, step):
+        """Provide z bulk-labeling (automated assigment of z coordinate
+        to 3d lines
+
+        @param pos1,pos2 bounding box definition for selecting lines to be labeled
+        @param value starting value
+        @param step  step value
+        """
+        gcmd.Command(['v.edit',
+                      '--q',
+                      'map=%s' % self.map,
+                      'tool=zbulk',
+                      'bbox=%f,%f,%f,%f' % (pos1[0], pos1[1], pos2[0], pos2[1]),
+                      'zbulk=%f,%f' % (value, step)])
+
+
     def CopyLine(self, ids=None):
         """Copy features from (background) vector map
 
@@ -567,6 +580,28 @@
                         
         return True
 
+    def CopyCats(self, cats, ids):
+        """Copy given categories to objects with id listed in ids
+
+        @param cats list of cats to be copied
+        @param ids  ids of lines to be modified
+        """
+        if len(cats) == 0 or len(ids) == 0:
+            return False
+
+        # collect cats
+        gcmd.Command(['v.edit',
+                     '--q',
+                     'map=%s' % self.map,
+                     'tool=catadd',
+                     'cats=%s' % ",".join(["%d" % v for v in cats]),
+                     'ids=%s' % ",".join(["%d" % v for v in ids])])
+        
+        # reload map (needed for v.edit)
+        self.driver.ReloadMap()
+
+        return True
+
     def SelectLinesFromBackgroundMap(self, pos1, pos2):
         """Select features from background map
 
@@ -657,21 +692,6 @@
         
         return ids
 
-    def ZBulkLine(self, pos1, pos2, value, step):
-        """Provide z bulk-labeling (automated assigment of z coordinate
-        to 3d lines
-
-        @param pos1,pos2 bounding box definition for selecting lines to be labeled
-        @param value starting value
-        @param step  step value
-        """
-        gcmd.Command(['v.edit',
-                      '--q',
-                      'map=%s' % self.map,
-                      'tool=zbulk',
-                      'bbox=%f,%f,%f,%f' % (pos1[0], pos1[1], pos2[0], pos2[1]),
-                      'zbulk=%f,%f' % (value, step)])
-
 class VDigit(AbstractDigit):
     """
     Prototype of digitization class based on v.digit reimplementation
@@ -687,43 +707,43 @@
         AbstractDigit.__init__(self, mapwindow, settings)
 
         try:
-            from grass6_wxvdigit import Digit as DigitClass
-            self.digit = DigitClass(self.driver.GetDevice())
-        except ImportError, err:
-            print >> sys.stderr, "%sWARNING: Digitization tool is disabled (%s).%s" \
-                  "Detailed information in README file." % \
-                  (os.linesep, err, os.linesep)
+            self.digit = vdigit.Digit(self.driver.GetDevice())
+        except (ImportError, NameError):
             self.digit = None
 
     def AddPoint (self, map, point, x, y, z=None):
-        """Add point/centroid to the vector map layer
+        """Add new point/centroid
 
-        @param map   map name (unused)
-        @param point  feature type (if True -> point otherwise centroid)
+        @param map   map name (unused, for compatability with VEdit)
+        @param point feature type (if true point otherwise centroid)
         @param x,y,z coordinates
         """
         layer = self.settings["layer"]
         cat   = self.SetCategory()
         
         if point:
-            type = 0x01 # point
+            type = vdigit.GV_POINT 
         else:
-            type = 0x08 # centroid
+            type = vdigit.GV_CENTROID 
 
+        snap, thresh = self.__getSnapThreshold()
+
         if z:
-            ret = self.digit.AddLine(type, [x, y, z], True, layer, cat)
+            ret = self.digit.AddLine(type, [x, y, z], layer, cat,
+                                     self.settings["backgroundMap"], snap, thresh)
         else:
-            ret = self.digit.AddLine(type, [x, y], False, layer, cat)
+            ret = self.digit.AddLine(type, [x, y], layer, cat,
+                                     self.settings["backgroundMap"], snap, thresh)
 
         if ret == -1:
             raise DigitError, _("Adding new feature to vector map <%s> failed") % map
         
     def AddLine (self, map, line, coords):
-        """Add line/boundary to the vector map layer
+        """Add line/boundary
 
-        @param map  map name
-        @param line feature type (True for line, otherwise boundary)
-        @param list of coordinates
+        @param map    map name (unused, for compatability with VEdit)
+        @param line   feature type (if True line, otherwise boundary)
+        @param coords list of coordinates
         """
         if len(coords) < 2:
             return
@@ -732,35 +752,151 @@
         cat   = self.SetCategory()
 
         if line:
-            type = 0x02
+            type = vdigit.GV_LINE
         else:
-            type = 0x04
+            type = vdigit.GV_BOUNDARY
 
         listCoords = []
         for c in coords:
             for x in c:
                 listCoords.append(x)
 
-        if len(coords[0]) == 3: # with_z
-            ret = self.digit.AddLine(type, listCoords, True, layer, cat)
-        else:
-            ret = self.digit.AddLine(type, listCoords, False, layer, cat)
+        snap, thresh = self.__getSnapThreshold()
 
+        ret = self.digit.AddLine(type, listCoords, layer, cat,
+                                 self.settings["backgroundMap"], snap, thresh)
+
         if ret == -1:
             raise DigitError, _("Adding new feature to vector map <%s> failed") % map
 
 
     def DeleteSelectedLines(self):
-        """Delete selected vector features from the vector map
+        """Delete selected features
 
         @return number of deleted lines
         """
+        nlines = self.digit.DeleteLines()
 
-        nlines = self.digit.DeleteSelectedLines()
-        #self.driver.DrawUpdatedLines()
+        return nlines
 
+    def MoveSelectedLines(self, move):
+        """Move selected features
+
+        @param move direction (x, y)
+        """
+        snap, thresh = self.__getSnapThreshold()
+
+        nlines = self.digit.MoveLines(move[0], move[1], 0.0, # TODO 3D
+                                      snap, thresh) 
+
         return nlines
 
+    def MoveSelectedVertex(self, coords, move):
+        """Move selected vertex of the line
+
+        @param coords click coordinates
+        @param move   X,Y direction
+
+        @return 1 vertex moved
+        @return 0 vertex not moved (not found, line is not selected)
+        """
+        snap, thresh = self.__getSnapThreshold()
+
+        return self.digit.MoveVertex(coords[0], coords[1], 0.0, # TODO 3D
+                                     move[0], move[1], 0.0,
+                                     snap, thresh)
+
+    def AddVertex(self, coords):
+        """Add new vertex to the selected line/boundary on position 'coords'
+
+        @param coords coordinates to add vertex
+        """
+        return self.digit.ModifyLineVertex(1, coords[0], coords[1], 0.0, # TODO 3D
+                                           self.driver.GetThreshold())
+
+    def RemoveVertex(self, coords):
+        """Remove vertex from the selected line/boundary on position 'coords'
+
+        @param coords coordinates to remove vertex
+        """
+        return self.digit.ModifyLineVertex(0, coords[0], coords[1], 0.0, # TODO 3D
+                                           self.driver.GetThreshold())
+
+    def SplitLine(self, coords):
+        """Split selected line/boundary on position 'coords'
+
+        @param coords coordinates to split line
+
+        @return 1 line splitted
+        @return 0 no action
+        @return -1 error
+        """
+        return self.digit.SplitLine(coords[0], coords[1], 0.0, # TODO 3D
+                                    self.driver.GetThreshold())
+
+    def EditLine(self, line, coords):
+        """Edit existing line/boundary
+
+        @param line id of line to be modified
+        @param coords list of coordinates of modified line
+        """
+        return self.digit.RewriteLine(line, coords)
+
+    def FlipLine(self):
+        """Flip selected lines/boundaries"""
+        return self.digit.FlipLines()
+
+    def MergeLine(self):
+        """Merge selected lines/boundaries"""
+        return self.digit.MergeLines()
+
+    def BreakLine(self):
+        """Break selected lines/boundaries"""
+        return self.digit.BreakLines()
+
+    def SnapLine(self):
+        """Snap selected lines/boundaries"""
+        return self.digit.SnapLines()
+
+    def ConnectLine(self):
+        """Connect selected lines/boundaries"""
+        return self.digit.ConnectLines()
+
+    def CopyLine(self, ids=None):
+        """Copy features from (background) vector map
+
+        @param ids list of line ids to be copied
+        """
+        return self.digit.CopyLines(ids, self.settings['backgroundMap'])
+
+    def CopyCats(self, cats, ids):
+        """Copy given categories to objects with id listed in ids
+
+        @param cats list of cats to be copied
+        @param ids  ids of lines to be modified
+        """
+        if len(cats) == 0 or len(ids) == 0:
+            return False
+
+        return self.digit.CopyCats(cats, ids)
+
+    def __getSnapThreshold(self):
+        """Get snap mode and threshold value
+
+        @return (snap, thresh)
+        """
+        thresh = self.driver.GetThreshold()
+
+        if thresh > 0.0:
+            if self.settings['snapToVertex']:
+                snap = vdigit.SNAPVERTEX
+            else:
+                snap = vdigit.SNAP
+        else:
+            snap = v.digit.NO_SNAP
+
+        return (snap, thresh)
+
 if USEVEDIT:
     class Digit(VEdit):
         """Default digit class"""
@@ -830,7 +966,7 @@
 
         # initialize wx display driver
         try:
-            self.__display = DisplayDriver(mapwindow.pdcVector)
+            self.__display = vdigit.DisplayDriver(mapwindow.pdcVector)
         except:
             self.__display = None
             
@@ -849,9 +985,16 @@
         self.__display.SetDevice(pdc)
             
     def Reset(self, map):
-        """Close map and open new one
+        """Reset map
 
-        map map name to be set up
+        Open or close the vector map by driver.
+
+        @param map map name or None to close the map
+
+        @return 0 on success (close map)
+        @return topo level on success (open map)
+        @return non-zero (close map)
+        @return -1 on error (open map)
         """
         if map:
             name, mapset = map.split('@')
@@ -860,7 +1003,9 @@
             else:
                 ret = self.__display.OpenMap(str(name), str(mapset), True)
         else:
-            self.__display.CloseMap()
+            ret = self.__display.CloseMap()
+
+        return ret
     
     def ReloadMap(self):
         """Reload map (close and re-open).
@@ -1052,8 +1197,7 @@
                                                 settings['symbolVertex'][1][1],
                                                 settings['symbolVertex'][1][2],
                                                 255).GetRGB(),
-                                       settings['lineWidth'][0],
-                                       self.GetThreshold())
+                                       settings['lineWidth'][0])
 
 class DigitSettingsDialog(wx.Dialog):
     """

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2008-01-16 16:45:58 UTC (rev 29719)
@@ -128,6 +128,7 @@
             return None
 
         runcmd = gcmd.Command(cmd=self.cmdlist + ['--q']) # run quiet
+        
         if runcmd.returncode != 0:
             self.mapfile = None
             self.maskfile = None

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2008-01-16 16:45:58 UTC (rev 29719)
@@ -26,6 +26,7 @@
 import gcmd as cmd
 import grassenv
 from digit import Digit as Digit
+from digit import DigitError as DigitError
 from digit import DigitSettingsDialog as DigitSettingsDialog
 from debug import Debug as Debug
 from icon import Icons as Icons
@@ -568,7 +569,10 @@
         """
         Start editing of selected vector map layer.
 
-        Return True on success or False if layer cannot be edited
+        @param layerSelectedId id of layer to be edited
+        
+        @return True on success
+        @return False on error
         """
         try:
             self.layerSelectedID = self.layers.index(layerSelected)
@@ -576,6 +580,13 @@
         except:
             return False
 
+        try:
+            self.parent.digit.SetMapName(mapLayer.name)
+        except DigitError, e:
+            self.layerSelectedID = None
+            print e # wxMessageBox
+            return False
+
         # update toolbar
         self.combo.SetValue (layerSelected.name)
         self.parent.maptoolbar.combo.SetValue ('Digitize')
@@ -584,7 +595,6 @@
         Debug.msg (4, "DigitToolbar.StartEditing(): layerSelectedID=%d layer=%s" % \
                    (self.layerSelectedID, mapLayer.name))
 
-        self.parent.digit.SetMapName(mapLayer.name)
 
         # deactive layer
         self.mapcontent.ChangeLayerActive(mapLayer, False)

Modified: grass/trunk/gui/wxpython/vdigit/cats.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/cats.cpp	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/vdigit/cats.cpp	2008-01-16 16:45:58 UTC (rev 29719)
@@ -30,7 +30,7 @@
 
     struct lcat lc;
 
-    G_debug(2, "vdigit.InitCats()");
+    G_debug(2, "wxDigit.InitCats()");
 
     if (!cats.empty()) {	
 	cats.clear();
@@ -55,7 +55,7 @@
 	lc.cat = max_cat;
 
 	cats.push_back(lc);
-	G_debug(3, "vdigit.InitCats(): layer=%d, cat=%d", lc.layer, lc.cat);
+	G_debug(3, "wxDigit.InitCats(): layer=%d, cat=%d", lc.layer, lc.cat);
     }
 
     return 0;
@@ -99,7 +99,7 @@
 	if (layer == (*i).layer) {
 	    old_cat = (*i).cat;
 	    (*i).cat = cat;
-	    G_debug(3, "vdigit.SetCategory(): layer=%d, cat=%d", layer, cat);
+	    G_debug(3, "wxDigit.SetCategory(): layer=%d, cat=%d", layer, cat);
 	}
     }
 

Modified: grass/trunk/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-01-16 16:45:58 UTC (rev 29719)
@@ -43,8 +43,8 @@
 
     drawSegments = false;
 
-    // avoid GUI crash
-    // Vect_set_fatal_error(GV_FATAL_PRINT);
+    // avoid GUI crash when G_fatal_error() is called (opening the vector map)
+    Vect_set_fatal_error(GV_FATAL_PRINT);
     // G_set_error_routine(print_error);
 }
 
@@ -111,7 +111,7 @@
      				      GV_POINTS | GV_LINES, // fixme
 				      listLines);
 
-    G_debug(3, "driver.DrawMap(): region: w=%f, e=%f, s=%f, n=%f",
+    G_debug(3, "wxDriver.DrawMap(): region: w=%f, e=%f, s=%f, n=%f",
 	    region.box.W, region.box.E, region.box.S, region.box.N);
 
     bool inBox;
@@ -426,22 +426,27 @@
 /*
   \brief Close vector map layer
   
-  \param
+  \param void
 
-  \return
+  \return 0 on success
+  \return non-zero on error
 */
-void DisplayDriver::CloseMap()
+int DisplayDriver::CloseMap()
 {
+    int ret;
+
+    ret = -1;
     if (mapInfo) {
 	if (mapInfo->mode == GV_MODE_RW) {
+	    /* rebuild topology */
 	    Vect_build(mapInfo, NULL);
 	}
-	Vect_close(mapInfo);
+	ret = Vect_close(mapInfo);
 	G_free ((void *) mapInfo);
 	mapInfo = NULL;
     }
     
-    return;
+    return ret;
 }
 
 /**
@@ -463,6 +468,9 @@
     // define open level (level 2: topology)
     Vect_set_open_level(2);
 
+    // avoid GUI crash when G_fatal_error() is called (opening the vector map)
+    Vect_set_fatal_error(GV_FATAL_PRINT);
+
     // open existing map
     if (!update) {
 	ret = Vect_open_old(mapInfo, (char*) mapname, (char *) mapset);
@@ -471,6 +479,11 @@
 	ret = Vect_open_update(mapInfo, (char*) mapname, (char *) mapset);
     }
 
+    if (ret == -1) { // error
+	G_free((void *) mapInfo);
+	mapInfo = NULL;
+    }
+
     return ret;
 }
 
@@ -1100,5 +1113,7 @@
 */
 int print_error(const char *msg, int type)
 {
+    fprintf(stderr, "%s", msg);
+    
     return 0;
 }

Modified: grass/trunk/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.h	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/vdigit/driver.h	2008-01-16 16:45:58 UTC (rev 29719)
@@ -167,8 +167,8 @@
     std::vector<int> GetSelectedVertex(double, double, double);
 
     /* general */
-    void CloseMap();
-    int  OpenMap(const char *, const char *, bool);
+    int CloseMap();
+    int OpenMap(const char *, const char *, bool);
     void ReloadMap();
     void SetDevice(void *);
 

Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-16 13:35:15 UTC (rev 29718)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-16 16:45:58 UTC (rev 29719)
@@ -55,7 +55,8 @@
 	return -1;
     }
 
-    G_debug(1, "Digit.AddLine(): npoints=%d", npoints);
+    G_debug(2, "wxDigit.AddLine(): npoints=%d, layer=%d, cat=%d, snap=%d",
+	    npoints, layer, cat, snap);
 
     /* TODO: 3D */
     if (!(type & GV_POINTS) && !(type & GV_LINES)) {
@@ -112,16 +113,18 @@
 	    Points->x[last] = Points->x[0];
 	    Points->y[last] = Points->y[0];
 	    Points->z[last] = Points->z[0];
-	    G_debug(3, "Digit.AddLine(): boundary closed");
+	    G_debug(3, "wxDigit.AddLine(): boundary closed");
 	}
     }
 
     newline = Vect_write_line(display->mapInfo, type, Points, Cats);
 
     if (snap != NO_SNAP) { /* apply snapping */
-	Vedit_snap_line(display->mapInfo, BgMap, nbgmaps, /* limited only to one background map */
+      /*
+	Vedit_snap_line(display->mapInfo, BgMap, nbgmaps,
 			newline,
-			threshold, (SNAP) ? 0 : 1); /* snap to vertex ? */
+			threshold, (SNAP) ? 0 : 1); 
+      */
     }
 
     Vect_destroy_line_struct(Points);
@@ -131,6 +134,8 @@
 	Vect_close(BgMap[0]);
     }
 
+    G_debug(2, "wxDigit.AddLine(): line=%d written", newline);
+
     return 1;
 }
 



More information about the grass-commit mailing list