[GRASS-SVN] r33149 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 29 04:02:59 EDT 2008


Author: martinl
Date: 2008-08-29 04:02:58 -0400 (Fri, 29 Aug 2008)
New Revision: 33149

Added:
   grass/branches/develbranch_6/gui/wxpython/vdigit/message.cpp
Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/vdigit/cats.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/select.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
wxGUI: better error message handling in vdigit
initial support for copy categories/attributes in vdigit
some wxGUI fixes


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -443,6 +443,9 @@
 
     def GetError(self):
         """Get error message or ''"""
+        if not self.cmdThread.module:
+            return _("Unable to exectute command: '%s'") % ' '.join(self.cmd)
+
         for type, msg in self.__ProcessStdErr():
             if type == 'ERROR':
                 return msg

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -1119,7 +1119,8 @@
                     else:
                         point = False
 
-                    digitClass.AddPoint(map, point, east, north)
+                    if digitClass.AddPoint(map, point, east, north) < 0:
+                        return
 
                     self.UpdateMap(render=False) # redraw map
 
@@ -1741,8 +1742,9 @@
                     if len(self.polycoords) < 2: # ignore 'one-point' lines
                         return
                     
-                    digitClass.AddLine(map, line, self.polycoords)
-
+                    if digitClass.AddLine(map, line, self.polycoords) < 0:
+                        return
+                    
                     position = self.Cell2Pixel(self.polycoords[-1])
                     self.polycoords = []
                     self.UpdateMap(render=False)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -436,11 +436,7 @@
         
         # toogle to pointer by default
         self.OnTool(None)
-
-        if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vdigit':
-            self.toolbar[0].EnableTool(self.copyCats, False) # not implemented (TODO)
-            self.toolbar[0].SetToolShortHelp(self.copyCats, _("Not implemented yet"))
-            
+        
     def ToolbarData(self, row=None):
         """
         Toolbar data
@@ -502,7 +498,7 @@
                      self.OnDisplayCats),
                     (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
                      wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
-                     self.OnCopyCats),
+                     self.OnCopyCA),
                     (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
                      wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
                      self.OnDisplayAttr),
@@ -671,13 +667,60 @@
                         'id'   : self.displayAttr }
         self.parent.MapWindow.mouse['box'] = 'point'
 
+    def OnCopyCA(self, event):
+        """Copy categories/attributes menu"""
+        point = wx.GetMousePosition()
+        toolMenu = wx.Menu()
+        # Add items to the menu
+        cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+                           text=_('Copy categories'),
+                           kind=wx.ITEM_CHECK)
+        toolMenu.AppendItem(cats)
+        self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
+        if self.action['desc'] == "copyCats":
+            cats.Check(True)
+
+        attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+                            text=_('Duplicate attributes'),
+                            kind=wx.ITEM_CHECK)
+        toolMenu.AppendItem(attrb)
+        self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
+        if self.action['desc'] == "copyAttrs":
+            attrb.Check(True)
+
+        # Popup the menu.  If an item is selected then its handler
+        # will be called before PopupMenu returns.
+        self.parent.MapWindow.PopupMenu(toolMenu)
+        toolMenu.Destroy()
+        
+        if self.action['desc'] == "addPoint":
+            self.toolbar[0].ToggleTool(self.copyCats, False)
+        
     def OnCopyCats(self, event):
         """Copy categories"""
+        if self.action['desc'] == 'copyCats': # select previous action
+            self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.copyCats, False)
+            self.OnAddPoint(event)
+            return
+        
         Debug.msg(2, "Digittoolbar.OnCopyCats():")
         self.action = { 'desc' : "copyCats",
                         'id'   : self.copyCats }
         self.parent.MapWindow.mouse['box'] = 'point'
 
+    def OnCopyAttrb(self, event):
+        if self.action['desc'] == 'copyAttrs': # select previous action
+            self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.copyCats, False)
+            self.OnAddPoint(event)
+            return
+        
+        Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
+        self.action = { 'desc' : "copyAttrs",
+                        'id'   : self.copyCats }
+        self.parent.MapWindow.mouse['box'] = 'point'
+        
     def OnUndo(self, event):
         """Undo previous changes"""
         self.parent.digit.Undo()
@@ -795,12 +838,13 @@
         toolMenu.Destroy()
         
         if self.action['desc'] == 'addPoint':
-            self.toolbar[0].ToggleTool(self.additionalTools, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
         
     def OnCopy(self, event):
         """Copy selected features from (background) vector map"""
         if self.action['desc'] == 'copyLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -813,6 +857,7 @@
         """Flip selected lines/boundaries"""
         if self.action['desc'] == 'flipLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -825,6 +870,7 @@
         """Merge selected lines/boundaries"""
         if self.action['desc'] == 'mergeLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -837,6 +883,7 @@
         """Break selected lines/boundaries"""
         if self.action['desc'] == 'breakLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -849,6 +896,7 @@
         """Snap selected features"""
         if self.action['desc'] == 'snapLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -861,6 +909,7 @@
         """Connect selected lines/boundaries"""
         if self.action['desc'] == 'connectLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -873,6 +922,7 @@
         """Query selected lines/boundaries"""
         if self.action['desc'] == 'queryLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -886,6 +936,7 @@
         """Z bulk-labeling selected lines/boundaries"""
         if self.action['desc'] == 'zbulkLine': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         
@@ -903,6 +954,7 @@
         """
         if self.action['desc'] == 'typeConv': # select previous action
             self.toolbar[0].ToggleTool(self.addPoint, True)
+            self.toolbar[0].ToggleTool(self.additionalTools, False)
             self.OnAddPoint(event)
             return
         

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -98,7 +98,11 @@
                     break
             
         if idx < len(dcmd):
-            mapname = dcmd[idx].split('=')[1]
+            try:
+                mapname = dcmd[idx].split('=')[1]
+            except IndexError:
+                return ''
+            
             if fullyQualified and '@' not in mapname:
                 if layerType in ('raster', 'vector', '3d-raster'):
                     try:

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -37,6 +37,8 @@
 import string
 import copy
 
+from threading import Thread
+
 import wx
 import wx.lib.colourselect as csel
 import wx.lib.mixins.listctrl as listmix
@@ -686,6 +688,7 @@
             return False
 
         # collect cats
+        # FIXME: currently layer is ignored...
         gcmd.Command(['v.edit',
                      '--q',
                      'map=%s' % self.map,
@@ -789,7 +792,8 @@
         AbstractDigit.__init__(self, mapwindow)
 
         try:
-            self.digit = wxvdigit.Digit(self.driver.GetDevice())
+            self.digit = wxvdigit.Digit(self.driver.GetDevice(),
+                                        mapwindow)
         except (ImportError, NameError):
             self.digit = None
 
@@ -823,15 +827,15 @@
 
         if z:
             ret = self.digit.AddLine(type, [x, y, z], layer, cat,
-                                     str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
+                                     str(UserSettings.Get(group='vdigit', key="backgroundMap",
+                                                          subkey='value')), snap, thresh)
         else:
             ret = self.digit.AddLine(type, [x, y], layer, cat,
-                                     str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
+                                     str(UserSettings.Get(group='vdigit', key="backgroundMap",
+                                                          subkey='value')), snap, thresh)
+        self.toolbar.EnableUndo()
 
-        if ret == -1:
-            raise gcmd.DigitError, _("Adding new feature to vector map <%s> failed.") % map
-
-        self.toolbar.EnableUndo()
+        return ret
         
     def AddLine (self, map, line, coords):
         """Add line/boundary
@@ -864,12 +868,11 @@
         
         ret = self.digit.AddLine(type, listCoords, layer, cat,
                                  str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
-        
-        if ret == -1:
-            raise gcmd.DigitError, _("Adding new feature to vector map <%s> failed.") % map
-        
+
         self.toolbar.EnableUndo()
         
+        return ret
+    
     def DeleteSelectedLines(self):
         """Delete selected features
 
@@ -1090,19 +1093,19 @@
 
         return ret
 
-    def CopyCats(self, cats, ids):
+    def CopyCats(self, fromId, toId):
         """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
+        @param cats ids of 'from' feature
+        @param ids  ids of 'to' feature(s)
 
         @return number of modified features
         @return -1 on error
         """
-        if len(cats) == 0 or len(ids) == 0:
+        if len(fromId) == 0 or len(toId) == 0:
             return 0
 
-        ret = self.digit.CopyCats(cats, ids)
+        ret = self.digit.CopyCats(fromId, toId)
 
         if ret > 0:
             self.toolbar.EnableUndo()

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/cats.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/cats.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/cats.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -35,6 +35,7 @@
     }
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -158,10 +159,12 @@
     struct field_info *fi;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return lc;
     }
 
     if (line_id == -1 && display->selected.values->n_values < 1) {
+	GetLineCatsMsg(line_id);
 	return lc;
     }
 
@@ -171,6 +174,7 @@
     }
 
     if (!Vect_line_alive(display->mapInfo, line)) {
+	DeadLineMsg(line);
 	return lc;
     }
 
@@ -178,6 +182,7 @@
 
     if (Vect_read_line(display->mapInfo, NULL, Cats, line) < 0) {
 	Vect_destroy_cats_struct(Cats);
+	ReadLineMsg(line);
 	return lc;
     }
 
@@ -186,6 +191,7 @@
     for (int dblink = 0; dblink < n_dblinks; dblink++) {
 	fi = Vect_get_dblink(display->mapInfo, dblink);
 	if (fi == NULL) {
+	    DblinkMsg(dblink+1);
 	    continue;
 	}
 	std::vector<int> cats;
@@ -219,10 +225,12 @@
     struct line_cats *Cats;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
     if (line_id == -1 && display->selected.values->n_values < 1) {
+	GetLineCatsMsg(line_id);
 	return -1;
     }
     
@@ -232,6 +240,7 @@
     }
      
     if (!Vect_line_alive(display->mapInfo, line)) {
+	DeadLineMsg(line);
 	return -1;
     }
 
@@ -241,6 +250,7 @@
     if (type < 0) {
 	Vect_destroy_line_struct(Points);
 	Vect_destroy_cats_struct(Cats);
+	ReadLineMsg(line);
 	return -1;
     }
 
@@ -284,15 +294,68 @@
 /**
    \brief Copy categories from one vector feature to other
 
-   \param cats  list of layer/category to be copied			       
-   \param ids   list of line ids where to copy categories
+   \param fromId list of 'from' feature ids
+   \param toId   list of 'to' feature ids
 
    \return number of modified features
    \return -1 on error
 */
-int Digit::CopyCats(std::vector<std::vector<int> > cats, std::vector<int> ids)
+int Digit::CopyCats(std::vector<int> fromId, std::vector<int> toId)
 {
-  /* TODO */
+    int fline, tline, nlines, type;
+    bool error;
+    
+    struct line_pnts *Points;
+    struct line_cats *Cats_from, *Cats_to;
 
-  return 0;
+    Points = Vect_new_line_struct();
+    Cats_from = Vect_new_cats_struct();
+    Cats_to = Vect_new_cats_struct();
+
+    nlines = 0;
+    error = false;
+    for (std::vector<int>::const_iterator fi = fromId.begin(), fe = fromId.end();
+	 fi != fe && !error; ++fi) {
+	fline = *fi;
+	if (!Vect_line_alive(display->mapInfo, fline))
+	    continue;
+
+	type = Vect_read_line(display->mapInfo, NULL, Cats_from, fline);
+	if (type < 0) {
+	    nlines = -1;
+	    error = true;
+	}
+
+	for(std::vector<int>::const_iterator ti = toId.begin(), te = toId.end();
+	    ti != te && !error; ++ti) {
+	    tline = *ti;
+	    if (!Vect_line_alive(display->mapInfo, tline))
+		continue;
+	    type = Vect_read_line(display->mapInfo, Points, Cats_to, tline);
+	    if (type < 0) {
+		nlines = -1;
+		error = true;
+	    }
+
+	    for (int i = 0; Cats_from->n_cats; i++) {
+		if (Vect_cat_set(Cats_to, Cats_from->field[i], Cats_from->field[i]) < 1) {
+		    nlines = -1;
+		    error = true;
+		}
+	    }
+	    
+	    if (Vect_rewrite_line(display->mapInfo, tline, type, Points, Cats_to) < 0) {
+		nlines = -1;
+		error = true;
+	    }
+		
+	    nlines++;
+	}
+    }
+
+    Vect_destroy_line_struct(Points);
+    Vect_destroy_cats_struct(Cats_from);
+    Vect_destroy_cats_struct(Cats_to);
+
+    return nlines;
 }

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -21,10 +21,12 @@
    \brief Initialize digit interface used by SWIG
 
    \param driver display driver instance
+   \param window parent window for message dialog
 */
-Digit::Digit(DisplayDriver *ddriver)
+Digit::Digit(DisplayDriver *ddriver, void *window)
 {
     display = ddriver;
+    parentWin = (wxWindow *) window;
 
     if (display->mapInfo) {
 	InitCats();
@@ -33,6 +35,8 @@
     changesetCurrent = -2; // initial value for undo/redo
     changesetDead = -1;
 
+    msgCaption = _("Digitization error");
+    
     // avoid GUI crash
     // Vect_set_fatal_error(GV_FATAL_PRINT);
 }

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2008-08-29 08:02:58 UTC (rev 33149)
@@ -13,7 +13,8 @@
     std::map<int, int> cats;
 
     DisplayDriver *display;
-
+    wxWindow *parentWin;
+    
     int SetCategory(int, int);
     struct Map_info** OpenBackgroundVectorMap(const char *);
 
@@ -42,8 +43,22 @@
     void FreeChangeset(int);
     int RemoveActionFromChangeset(int, action_type, int);
 
+    /* message dialogs */
+    wxString msgCaption;
+    void DisplayMsg(void);
+    void Only2DMsg(void);
+    void ReadLineMsg(int);
+    void DeadLineMsg(int);
+    void WriteLineMsg(void);
+    void BackgroundMapMsg(const char *);
+    void DblinkMsg(int);
+    void DbDriverMsg(const char *);
+    void DbDatabaseMsg(const char *, const char *);
+    void DbExecuteMsg(const char *);
+    void GetLineCatsMsg(int);
+
 public:
-    Digit(DisplayDriver *);
+    Digit(DisplayDriver *, void *);
     ~Digit();
 
     int InitCats();
@@ -79,7 +94,7 @@
 					double, double, double, bool,
 					int, int, double);
 
-    int CopyCats(std::vector<std::vector<int> >, std::vector<int>);
+    int CopyCats(std::vector<int>, std::vector<int>);
     int GetCategory(int);
     std::map<int, std::vector<int> > GetLineCats(int);
     int SetLineCats(int, int, std::vector<int>, bool);
@@ -92,4 +107,3 @@
 };
 
 #endif /* WXVDIGIT_DIGIT_H */
-

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-08-29 08:02:58 UTC (rev 33149)
@@ -20,6 +20,7 @@
 
 #include <wx/dc.h>
 #include <wx/list.h>
+#include <wx/string.h>
 
 #include <Python.h>
 #include <wx/wxPython/pseudodc.h>

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -50,11 +50,17 @@
     int nbgmaps;             /* number of registrated background maps */
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
     npoints = coords.size() / (Vect_is_3d(display->mapInfo) ? 3 : 2);
     if (coords.size() != npoints * (Vect_is_3d(display->mapInfo) ? 3 : 2)) {
+	wxString msg;
+	msg.Printf(_("Incorrent number of points (%d)"), coords.size());
+	wxMessageDialog dlg(parentWin, msg,
+			    msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+	dlg.ShowModal();
 	return -1;
     }
 
@@ -63,6 +69,7 @@
 
     /* TODO: 3D */
     if (!(type & (GV_POINTS | GV_LINES))) {
+	Only2DMsg();
 	return -1;
     }
 
@@ -71,6 +78,7 @@
     if (bgmap && strlen(bgmap) > 0) {
 	BgMap = OpenBackgroundVectorMap(bgmap);
 	if (!BgMap) {
+	    BackgroundMapMsg(bgmap);
 	    return -1;
 	}
 	else {
@@ -121,6 +129,7 @@
 
     newline = Vect_write_line(display->mapInfo, type, Points, Cats);
     if (newline < 0) {
+	WriteLineMsg();
 	return -1;
     }
 
@@ -204,11 +213,13 @@
     int nbgmaps;             /* number of registrated background maps */
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
     /* line alive ? */
     if (!Vect_line_alive(display->mapInfo, line)) {
+	WriteLineMsg();
 	return -1;
     }
 
@@ -217,6 +228,7 @@
     if (bgmap && strlen(bgmap) > 0) {
 	BgMap = OpenBackgroundVectorMap(bgmap);
 	if (!BgMap) {
+	    BackgroundMapMsg(bgmap);
 	    return -1;
 	}
 	else {
@@ -301,6 +313,7 @@
     struct ilist *list;
 
     if (!display->mapInfo)
+	DisplayMsg();
 	return -1;
 
     point = Vect_new_line_struct();
@@ -344,22 +357,21 @@
     // struct ilist *List;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
     n_dblinks = Vect_get_num_dblinks(display->mapInfo);
     Cats_del = NULL;
-    // List = NULL;
-
+    
     /* collect categories if needed */
     if (delete_records) {
 	Cats = Vect_new_cats_struct();
-	// List = Vect_new_list();
 	Cats_del = Vect_new_cats_struct();
 	for (int i = 0; i < display->selected.values->n_values; i++) {
 	    if (Vect_read_line(display->mapInfo, NULL, Cats, display->selected.values->value[i]) < 0) {
 		Vect_destroy_cats_struct(Cats_del);
-		//Vect_destroy_list(List);
+		ReadLineMsg(display->selected.values->value[i]);
 		return -1;
 	    }
 	    for (int j = 0; j < Cats->n_cats; j++) {
@@ -403,17 +415,20 @@
 	for (int dblink = 0; dblink < n_dblinks; dblink++) {
 	    fi = Vect_get_dblink(display->mapInfo, dblink);
 	    if (fi == NULL) {
+		DblinkMsg(dblink+1);
 		return -1;
 	    }
 
 	    driver = db_start_driver(fi->driver);
 	    if (driver == NULL) {
+		DbDriverMsg(fi->driver);
 		return -1;
 	    }
 
 	    db_init_handle (&handle);
 	    db_set_handle (&handle, fi->database, NULL);
 	    if (db_open_database(driver, &handle) != DB_OK) {
+		DbDatabaseMsg(fi->driver, fi->database);
 		return -1;
 	    }
 
@@ -437,6 +452,7 @@
 
 	    if (n_cats &&
 		db_execute_immediate (driver, &stmt) != DB_OK ) {
+		DbExecuteMsg(db_get_string(&stmt));
 		return -1;
 	    }
 	    
@@ -451,12 +467,7 @@
     if (Cats_del) {
 	Vect_destroy_cats_struct(Cats_del);
     }
-
-    /*
-    if(List) {
-	Vect_destroy_list(List);
-    }
-    */
+    
     return ret;
 }
 
@@ -481,6 +492,7 @@
     int nbgmaps;             /* number of registrated background maps */
 
     if (!display->mapInfo)
+	DisplayMsg();
 	return -1;
 
     BgMap = NULL;
@@ -488,6 +500,7 @@
     if (bgmap && strlen(bgmap) > 0) {
 	BgMap = OpenBackgroundVectorMap(bgmap);
 	if (!BgMap) {
+	    BackgroundMapMsg(bgmap);
 	    return -1;
 	}
 	else {
@@ -535,6 +548,7 @@
     long int nlines;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -570,6 +584,7 @@
     int ret, changeset, line;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -616,6 +631,7 @@
     int ret, changeset, line;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -663,6 +679,7 @@
 int Digit::SnapLines(double thresh)
 {
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -684,6 +701,7 @@
     long int nlines_diff;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -731,6 +749,7 @@
     int ret;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -760,6 +779,7 @@
     list = NULL;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -873,6 +893,7 @@
     int changeset, nlines_diff;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 

Added: grass/branches/develbranch_6/gui/wxpython/vdigit/message.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/message.cpp	                        (rev 0)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/message.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -0,0 +1,186 @@
+/**
+   \file message.cpp
+
+   \brief Error message dialogs
+
+   This program is free software under the GNU General Public
+   License (>=v2). Read the file COPYING that comes with GRASS
+   for details.
+
+   (C) 2008 by The GRASS development team
+
+   \author Martin Landa <landa.martin gmail.com>
+
+   \date 2008 
+*/
+
+#include "driver.h"
+#include "digit.h"
+
+/**
+   \brief Error message - no display driver available
+*/
+void Digit::DisplayMsg(void)
+{
+    wxMessageDialog dlg(parentWin, _("Display driver not available."),
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+
+    return;
+}
+
+/**
+   \brief Error message - cannot edit 3d features
+*/
+void Digit::Only2DMsg(void)
+{
+    wxMessageDialog dlg(parentWin, _("3D vector features are not currently supported."),
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to write line
+*/
+void Digit::WriteLineMsg(void)
+{
+    wxMessageDialog dlg(parentWin, _("Unable to write new line"),
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to read line
+
+   \param line line id
+*/
+void Digit::ReadLineMsg(int line)
+{
+    wxString msg;
+    msg.Printf(_("Unable to read line %d"), line);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - trying to read dead line
+
+   \param line line id
+*/
+void Digit::DeadLineMsg(int line)
+{
+    wxString msg;
+    msg.Printf(_("Unable to read line %d, line is dead"), line);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to open background map
+
+   \param bgmap map name
+*/
+void Digit::BackgroundMapMsg(const char *bgmap)
+{
+    wxString msg;
+    msg.Printf(_("Unable to open background vector map <%s>. "
+		 "Please check digitizer settings."),
+	       wxString (bgmap, wxConvUTF8).c_str());
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - dblink not defined
+
+   \param layer layer id
+*/
+void Digit::DblinkMsg(int layer)
+{
+    wxString msg;
+    msg.Printf(_("Database connection not defined for layer %d"), layer);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to start driver
+
+   \param driver driver name
+*/
+void Digit::DbDriverMsg(const char *driver)
+{
+    wxString msg;
+    msg.Printf(_("Unable to start driver <%s>"), driver);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to open database
+
+   \param driver driver name
+   \param database database name
+*/
+void Digit::DbDatabaseMsg(const char *driver, const char *database)
+{
+    wxString msg;
+    msg.Printf(_("Unable to open database <%s> by driver <%s>"),
+	       database, driver);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+/**
+   \brief Error message - unable to execute SQL command
+
+   \param sql sql command
+*/
+void Digit::DbExecuteMsg(const char *sql)
+{
+    wxString msg;
+    msg.Printf(_("Unable to execute: '%s'"), sql);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}
+
+	wxString msg;
+/**
+   \brief Error message - unable to get line categories
+
+   \param line line id
+*/
+void Digit::GetLineCatsMsg(int line)
+{
+    msg.Printf(_("Unable to get feature categories"), line);
+    wxMessageDialog dlg(parentWin, msg,
+			msgCaption, wxOK | wxICON_ERROR | wxCENTRE);
+    dlg.ShowModal();
+    
+    return;
+}


Property changes on: grass/branches/develbranch_6/gui/wxpython/vdigit/message.cpp
___________________________________________________________________
Name: svn:mime-type
   + text/x-c++src
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/select.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/select.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/select.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -49,6 +49,7 @@
     struct line_pnts *bbox;
 
     if (!display->mapInfo) {
+	DisplayDriver();
 	return ids;
     }
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -163,6 +163,7 @@
     struct line_cats *Cats;
 
     if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
     }
 
@@ -171,6 +172,7 @@
 
     /* do copy */
     if (!Vect_line_alive(display->mapInfo, line))
+	DeadLineMsg(line);
 	return -1;
 
     ltype = Vect_read_line(display->mapInfo, Points, Cats, line);

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp	2008-08-29 08:02:58 UTC (rev 33149)
@@ -44,8 +44,10 @@
     struct Map_info **BgMap; /* backgroud vector maps */
     int nbgmaps;             /* number of registrated background maps */
 
-    if (!display->mapInfo)
+    if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
+    }
 
     if (display->selected.values->n_values != 1)
 	return 0;
@@ -55,6 +57,7 @@
     if (bgmap && strlen(bgmap) > 0) {
 	BgMap = OpenBackgroundVectorMap(bgmap);
 	if (!BgMap) {
+	    BackgroundMapMsg(bgmap);
 	    return -1;
 	}
 	else {
@@ -111,8 +114,10 @@
     int ret;
     struct line_pnts *point;
 
-    if (!display->mapInfo)
+    if (!display->mapInfo) {
+	DisplayMsg();
 	return -1;
+    }
 
     if (display->selected.values->n_values != 1)
 	return 0;

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-08-29 07:10:14 UTC (rev 33148)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-08-29 08:02:58 UTC (rev 33149)
@@ -962,8 +962,8 @@
         Init histogram display canvas and tools
         """
         self.histogram = histogram.HistFrame(self,
-                                           id=wx.ID_ANY, pos=wx.DefaultPosition, size=(400,300),
-                                           style=wx.DEFAULT_FRAME_STYLE)
+                                             id=wx.ID_ANY, pos=wx.DefaultPosition, size=(400,300),
+                                             style=wx.DEFAULT_FRAME_STYLE)
 
         #show new display
         self.histogram.Show()



More information about the grass-commit mailing list