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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 25 07:43:40 EDT 2008


Author: martinl
Date: 2008-09-25 07:43:39 -0400 (Thu, 25 Sep 2008)
New Revision: 33537

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
   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.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
   grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp
   grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp
Log:
wxGUI vector digitizer updates (undo, rendering optimalization)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/goutput.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -198,8 +198,8 @@
         """
         if Debug.get_level() == 0:
             # don't redirect when debugging is enabled
-            sys.stdout = self.cmd_stdout
-            sys.stderr = self.cmd_stderr
+            # sys.stdout = self.cmd_stdout
+            # sys.stderr = self.cmd_stderr
             
             return True
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -235,7 +235,7 @@
         self.lineid = None
         # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
         self.plineid = None
-
+        
         #
         # Event bindings
         #
@@ -334,8 +334,7 @@
             bg = wx.Brush(self.GetBackgroundColour())
 
         pdc.SetBackground(bg)
-        #pdc.Clear()
-        self.Refresh()
+        ### pdc.Clear()
 
         Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \
                        (drawid, pdctype, coords))
@@ -350,8 +349,9 @@
             pdc.SetBackground(bg)
             pdc.RemoveAll()
             pdc.Clear()
+            pdc.EndDrawing()
+            
             self.Refresh()
-            pdc.EndDrawing()
             return
 
         if pdctype == 'image': # draw selected image
@@ -428,8 +428,9 @@
             pdc.SetIdBounds(drawid, (coords[0], coords[1], w, h))
             
         pdc.EndDrawing()
+        
         self.Refresh()
-
+        
         return drawid
 
     def TextBounds(self, textinfo):
@@ -446,7 +447,7 @@
                    (textinfo['text'], rotation))
 
         self.Update()
-        self.Refresh()
+        ### self.Refresh()
 
         self.SetFont(textinfo['font'])
 
@@ -473,7 +474,6 @@
 
         If self.redrawAll is False on self.pdcTmp content is re-drawn
         """
-
         Debug.msg(4, "BufferedWindow.OnPaint(): redrawAll=%s" % self.redrawAll)
 
         dc = wx.BufferedPaintDC(self, self.buffer)
@@ -489,6 +489,11 @@
         rgn = self.GetUpdateRegion().GetBox()
         dc.SetClippingRect(rgn)
 
+        switchDraw = False
+        if self.redrawAll is None:
+            self.redrawAll = True
+            switchDraw = True
+
         if self.redrawAll: # redraw pdc and pdcVector
             # draw to the dc using the calculated clipping rect
             self.pdc.DrawToDCClipped(dc, rgn)
@@ -525,13 +530,18 @@
         # draw temporary object on the foreground
         ### self.pdcTmp.DrawToDCClipped(dc, rgn)
         self.pdcTmp.DrawToDC(dc)
+
+        if switchDraw:
+            self.redrawAll = False
         
+        print self.redrawAll
+        
     def OnSize(self, event):
         """
         Scale map image so that it is
         the same size as the Window
         """
-
+        print 's'
         Debug.msg(3, "BufferedWindow.OnSize():")
 
         # set size of the input image
@@ -995,8 +1005,8 @@
         if not self.processMouse:
             return
         
-        if self.redrawAll is False:
-            self.redrawAll = True
+        ### if self.redrawAll is False:
+        ###    self.redrawAll = True
         
         wheel = event.GetWheelRotation()
         # zoom with mouse wheel
@@ -1021,15 +1031,18 @@
             # redraw map
             self.UpdateMap()
 
-            self.OnPaint(None)
-            
+            ### self.OnPaint(None)
+           
             # update statusbar
             self.parent.StatusbarUpdate()
 
+            self.Refresh()
+            
             self.processMouse = True
             
         # left mouse button pressed
         elif event.LeftDown():
+            print 'l'
             self.OnLeftDown(event)
 
         # left mouse button released
@@ -1619,7 +1632,11 @@
             elif digitToolbar.GetAction() == "connectLine":
                 if len(digitClass.driver.GetSelected()) > 0:
                     self.UpdateMap(render=False)
-
+                    
+            if len(digitClass.driver.GetSelected()) > 0:
+                self.redrawAll = None
+                ### self.OnPaint(None)
+            
         elif self.dragid != None:
             # end drag of overlay decoration
             if self.overlays.has_key(self.dragid):
@@ -1644,7 +1661,7 @@
             self.mouse['use'] = 'pointer'
             self.mouse['box'] = 'point'
             self.mouse['end'] = [0, 0]
-            self.Refresh()
+            ### self.Refresh()
             self.SetCursor(self.parent.cursors["default"])
         elif self.mouse["use"] == "profile":
             # profile
@@ -1772,7 +1789,8 @@
                     position = self.Cell2Pixel(self.polycoords[-1])
                     self.polycoords = []
                     self.UpdateMap(render=False)
-
+                    self.redrawAll = True
+                    
                     # add new record into atribute table
                     if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
                         posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
@@ -1886,6 +1904,8 @@
                 self.polycoords = []
                 self.UpdateMap(render=False)
 
+            self.redrawAll = True
+            
         event.Skip()
 
     def OnMiddleDown(self, event):
@@ -1948,11 +1968,11 @@
                 self.polycoords = []
                 digitClass.driver.SetSelected([])
                 self.UpdateMap(render=False)
-
-
+            
+            self.redrawAll = True
+            
     def OnMouseMoving(self, event):
         """Motion event and no mouse buttons were pressed"""
-
         digitToolbar = self.parent.toolbars['vdigit']
         if self.mouse["use"] == "pointer" and digitToolbar:
             digitClass = self.parent.digit
@@ -1973,7 +1993,7 @@
                     if digitToolbar.GetAction() == "moveLine":
                         # move line
                         for id in self.moveIds:
-                            self.pdcVector.TranslateId(id, dx, dy)
+                            self.pdcTmp.TranslateId(id, dx, dy)
                     elif digitToolbar.GetAction() in ["moveVertex", "editLine"]:
                         # move vertex ->
                         # (vertex, left vertex, left line,
@@ -1982,7 +2002,7 @@
                         # do not draw static lines
                         if digitToolbar.GetAction() == "moveVertex":
                             self.polycoords = []
-                            self.pdcVector.TranslateId(self.moveIds[0], dx, dy)
+                            self.pdcTmp.TranslateId(self.moveIds[0], dx, dy)
                             if self.moveIds[1] > 0: # previous vertex
                                 x, y = self.Pixel2Cell(self.pdcVector.GetIdBounds(self.moveIds[1])[0:2])
                                 self.pdcVector.RemoveId(self.moveIds[1]+1)
@@ -2041,7 +2061,7 @@
         Debug.msg(4, "BufferedWindow.ClearLines(): lineid=%s, plineid=%s" %
                   (self.lineid, self.plineid))
 
-        self.Refresh()
+        ### self.Refresh()
 
         return exit
 
@@ -2890,12 +2910,13 @@
 
     def OnPointer(self, event):
         """Pointer button clicked"""
-        self.toolbars['map'].OnTool(event)
+        if event:
+            self.toolbars['map'].OnTool(event)
         self.toolbars['map'].action['desc'] = ''
         
         self.MapWindow.mouse['use'] = "pointer"
         self.MapWindow.mouse['box'] = "point"
-        
+
         # change the cursor
         if self.toolbars['vdigit']:
             # digitization tool activated
@@ -2913,8 +2934,10 @@
                 self.MapWindow.mouse['box'] = 'point'
             else: # moveLine, deleteLine
                 self.MapWindow.mouse['box'] = 'box'
+        
         elif self.gismanager.georectifying:
             self.MapWindow.SetCursor(self.cursors["cross"])
+        
         else:
             self.MapWindow.SetCursor(self.cursors["default"])
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_mapdisp.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -1213,15 +1213,27 @@
         layerName = []
         
         for item in self.layers:
-            layerName.append(self.tree.GetPyData(item)[0]['maplayer'].GetName())
+            mapLayer = self.tree.GetPyData(item)[0]['maplayer']
+            if type != mapLayer.GetType():
+                continue
+            
+            layerName.append(mapLayer.GetName())
         
         return layerName
     
     def GetLayerId(self, type, name):
         """Get layer object id or -1"""
+        if len(name) < 1:
+            return -1
+        
         for item in self.layers:
-            mapName = self.tree.GetPyData(item)[0]['maplayer'].GetName()
+            mapLayer = self.tree.GetPyData(item)[0]['maplayer']
+            if type != mapLayer.GetType() or \
+                    name != mapLayer.GetName():
+                continue
+
             data = self.tree.GetPyData(item)[0]['nviz']
+            
             if type == 'raster':
                 return data['surface']['object']['id']
             elif type == 'vpoint':

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/nviz_tools.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -2419,7 +2419,11 @@
         npoints = nprimitives = 0
         for line in vInfo.ReadStdOutput():
             if 'Map is 3D' in line:
-                mapIs3D = int(line.replace('|', '').split(':')[1].strip())
+                mapIs3D = line.replace('|', '').split(':')[1].strip()
+                if mapIs3D == 'Yes':
+                    mapIs3D = 1
+                else:
+                    mapIs3D = 0
             elif 'Number of points' in line:
                 npoints = int(line.replace('|', '').split(':')[1].strip().split(' ')[0])
                 nprimitives = npoints

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -326,7 +326,7 @@
                     },
                 # exit
                 'saveOnExit' : {
-                    'enabled' : True
+                    'enabled' : False,
                     },
                 # break lines on intersection
                 'breakLines' : {

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -213,6 +213,10 @@
         else:
             return self.cmdlist
 
+    def GetType(self):
+        """Get map layer type"""
+        return self.type
+    
     def GetOpacity(self, float=False):
         """
         Get layer opacity level

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -1,24 +1,24 @@
 """
-MODULE: toolbar
+ at package toolbar
 
-CLASSES:
-    * AbstractToolbar
-    * MapToolbar
-    * GRToolbar
-    * GCPToolbar
-    * VDigitToolbar
-    * ProfileToolbar
-    * NvizToolbar
+ at brief Toolbars for Map Display window
 
-PURPOSE: Toolbars for Map Display window
+Classes:
+ - AbstractToolbar
+ - MapToolbar
+ - GRToolbar
+ - GCPToolbar
+ - VDigitToolbar
+ - ProfileToolbar
+ - NvizToolbar
 
-AUTHORS: The GRASS Development Team
-         Michael Barton, Martin Landa, Jachym Cepicky
+(C) 2007-2008 by the GRASS Development Team This program is free
+software under the GNU General Public License (>=v2). Read the file
+COPYING that comes with GRASS for details.
 
-COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
-           This program is free software under the GNU General Public
-           License (>=v2). Read the file COPYING that comes with GRASS
-           for details.
+ at author Michael Barton
+ at author Jachym Cepicky
+ at author Martin Landa <landa.martin gmail.com>
 """
 
 import wx
@@ -531,11 +531,13 @@
         return data
 
     def OnTool(self, event):
-        """Tool selected -> toggle tool to pointer"""
-        id = self.parent.toolbars['map'].pointer
-        self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
-        self.parent.toolbars['map'].mapdisplay.OnPointer(event)
-
+        """Tool selected -> disable selected tool in map toolbar"""
+        id = self.parent.toolbars['map'].GetAction(type='id')
+        # update map toolbar
+        self.parent.toolbars['map'].toolbar.ToggleTool(id, False)
+        # set cursor
+        cursor = self.parent.cursors["cross"]
+        self.parent.MapWindow.SetCursor(cursor)
         
         if event:
             # deselect previously selected tool
@@ -730,16 +732,13 @@
 
         @param enable False for disable
         """
-        ### fix undo first...
-
-        #         if enable:
-        #             if self.toolbar[0].GetToolEnabled(self.undo) is False:
-        #                 self.toolbar[0].EnableTool(self.undo, True)
-        #         else:
-        #             if self.toolbar[0].GetToolEnabled(self.undo) is True:
-        #                 self.toolbar[0].EnableTool(self.undo, False)
-        pass
-
+        if enable:
+            if self.toolbar[0].GetToolEnabled(self.undo) is False:
+                self.toolbar[0].EnableTool(self.undo, True)
+        else:
+            if self.toolbar[0].GetToolEnabled(self.undo) is True:
+                self.toolbar[0].EnableTool(self.undo, False)
+        
     def OnSettings(self, event):
         """Show settings dialog"""
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -896,8 +896,12 @@
         """
         snap, thresh = self.__getSnapThreshold()
         
-        nlines = self.digit.MoveLines(move[0], move[1], 0.0, # TODO 3D
-                                      str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
+        bgmap = UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')
+        try:
+            nlines = self.digit.MoveLines(move[0], move[1], 0.0, # TODO 3D
+                                          str(bgmap), snap, thresh)
+        except SystemExit:
+            pass
         
         if nlines > 0:
             self.toolbar.EnableUndo()
@@ -1317,7 +1321,8 @@
 
         # initialize wx display driver
         try:
-            self.__display = wxvdigit.DisplayDriver(mapwindow.pdcVector)
+            self.__display = wxvdigit.DisplayDriver(mapwindow.pdcVector,
+                                                    mapwindow.pdcTmp)
         except:
             self.__display = None
             
@@ -1373,6 +1378,7 @@
 
         @return wx.Image instance
         """
+        print 'd'
         nlines = self.__display.DrawMap(True) # force
         Debug.msg(3, "CDisplayDriver.DrawMap(): nlines=%d" % nlines)
 

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/wxgui_utils.py	2008-09-25 11:43:39 UTC (rev 33537)
@@ -203,8 +203,7 @@
                 self.mapdisplay.MapWindow.UpdateMap(render=True)
 
         event.Skip()
-
-
+        
     def OnKeyUp(self, event):
         """Key pressed"""
         key = event.GetKeyCode()

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/digit.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -32,8 +32,7 @@
 	InitCats();
     }
 
-    changesetCurrent = -2; // initial value for undo/redo
-    changesetDead = -1;
+    changesetCurrent = -1; // initial value for undo/redo
 
     msgCaption = _("Digitization error");
     
@@ -64,3 +63,44 @@
 
     return;
 }
+
+/*!
+  \brief Register action before operation
+  
+  \return changeset id
+*/
+int Digit::AddActionsBefore(void)
+{
+    int changeset;
+
+    /* register changeset */
+    changeset = changesets.size();
+    for (int i = 0; i < display->selected.values->n_values; i++) {
+	int line = display->selected.values->value[i];
+	if (Vect_line_alive(display->mapInfo, line))
+	    AddActionToChangeset(changeset, DEL, line);
+    }
+    
+    return changeset;
+}
+
+/*!
+  \brief Register action after operation
+*/
+void Digit::AddActionsAfter(int changeset, int nlines)
+{
+    for (int i = 0; i < display->selected.values->n_values; i++) {
+	int line = display->selected.values->value[i];
+	if (Vect_line_alive(display->mapInfo, line)) {
+	    RemoveActionFromChangeset(changeset, DEL, line);
+	}
+    }
+
+    for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
+	if (Vect_line_alive(display->mapInfo, line)) {
+	    AddActionToChangeset(changeset, ADD, line);
+	}
+    }
+    
+    return;
+}

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/digit.h	2008-09-25 11:43:39 UTC (rev 33537)
@@ -17,27 +17,26 @@
     
     int SetCategory(int, int);
     struct Map_info** OpenBackgroundVectorMap(const char *);
-    int BreakLineAtIntersection(int, struct line_pnts*);
+    int BreakLineAtIntersection(int, struct line_pnts*, int);
     
+    int AddActionsBefore(void);
+    void AddActionsAfter(int, int);
+
     /* settings */
     struct _settings {
 	bool breakLines;
     } settings;
 
     /* undo/redo */
-    enum action_type { ADD, DELETE, REWRITE };
+    enum action_type { ADD, DEL };
     struct action_meta {
 	action_type type;
 	int line;
-	/* TODO: replace by new Vect_restore_line() */
-	int ltype; // line type
-	struct line_pnts *Points;
-	struct line_cats *Cats;
+	long offset;
     };
 
     std::map<int, std::vector<action_meta> > changesets;
     int changesetCurrent;  /* first changeset to apply */
-    int changesetDead;     /* first dead changeset */
 
     int AddActionToChangeset(int, action_type, int);
     int ApplyChangeset(int, bool);

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -26,16 +26,18 @@
    Allocate given structures.
    
    \param[in,out] PseudoDC device where to draw vector objects
+   \param[in,out] PseudoDC device where to draw vector objects (tmp, selected)
    
    \return
 */
-DisplayDriver::DisplayDriver(void *device)
+DisplayDriver::DisplayDriver(void *device, void *deviceTmp)
 {
     G_gisinit(""); /* GRASS functions */
 
     mapInfo = NULL;
 
     dc = (wxPseudoDC *) device;
+    dcTmp = (wxPseudoDC *) deviceTmp;
 
     points = Vect_new_line_struct();
     pointsScreen = new wxList();

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver.h	2008-09-25 11:43:39 UTC (rev 33537)
@@ -34,7 +34,7 @@
 {
 private:
     friend class Digit;
-    wxPseudoDC *dc;  // device content
+    wxPseudoDC *dc, *dcTmp;  // device content
 
     /* disabled due to expensive calling dc->SetId()
      *
@@ -134,7 +134,7 @@
 		     double *, double *, double *);
     double DistanceInPixels(double);
 
-    int DrawCross(int, const wxPoint *, int size=5);
+    int DrawCross(wxPseudoDC *, int, const wxPoint *, int size=5);
     int DrawArrow(double, double, double, double, double,
 		   int);
 
@@ -159,7 +159,7 @@
 
 public:
     /* constructor */
-    DisplayDriver(void *);
+    DisplayDriver(void *, void *);
     /* destructor */
     ~DisplayDriver();
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/driver_draw.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -28,7 +28,7 @@
  */
 int DisplayDriver::DrawMap(bool force)
 {
-    if (!mapInfo || !dc)
+    if (!mapInfo || !dc || !dcTmp)
 	return -1;
 
     int nlines;
@@ -53,6 +53,7 @@
 	    region.box.W, region.box.E, region.box.S, region.box.N);
 
     dc->BeginDrawing();
+    dcTmp->BeginDrawing();
 
     if (settings.area.enabled) {
 	/* draw area fills first */
@@ -165,8 +166,10 @@
     for (int i = 0; i < listLines->n_values; i++) {
 	DrawLine(listLines->value[i]);
     }
+
+    dcTmp->EndDrawing();
     dc->EndDrawing();
-
+    
     // PrintIds();
     
     Vect_destroy_list(listLines);
@@ -216,11 +219,12 @@
     double x, y, z; // screen coordinates
     bool draw;      // draw object ?
     wxPen *pen;
-    
+    wxPseudoDC *pdc;
+
     pen = NULL;
     draw = false;
 
-    if (!dc || !Vect_line_alive (mapInfo, line))
+    if (!dc || !dcTmp || !Vect_line_alive (mapInfo, line))
 	return -1;
 
     // read line
@@ -233,7 +237,11 @@
     // update id for next line
     // dcId += points->n_points * 2 - 1;
 
+    pdc = NULL;
+
     if (IsSelected(line)) { // line selected ?
+	pdc = dcTmp;
+
 	if (settings.highlightDupl.enabled && IsDuplicated(line)) {
 	    pen = new wxPen(settings.highlightDupl.color, settings.lineWidth, wxSOLID);
 	}
@@ -250,6 +258,8 @@
 	topology.highlight++;
     }
     else {
+	pdc = dc;
+	
 	dcId = 0;
 	if (type & GV_LINES) {
 	    switch (type) {
@@ -318,12 +328,12 @@
 	pointsScreen->Append((wxObject*) new wxPoint((int) x, (int) y)); /* TODO: 3D */
     }
     
-    dc->SetId(dcId); /* 0 | 1 (selected) */
+    pdc->SetId(dcId); /* 0 | 1 (selected) */
    
     if (draw) {
-	dc->SetPen(*pen);
+	pdc->SetPen(*pen);
 	if (type & GV_POINTS) {
-	    DrawCross(line, (const wxPoint *) pointsScreen->GetFirst()->GetData());
+	    DrawCross(pdc, line, (const wxPoint *) pointsScreen->GetFirst()->GetData());
 	}
 	else {
 	    // long int startId = ids[line].startId + 1;
@@ -337,12 +347,12 @@
 		    // wxRect rect (*point_beg, *point_end);
 		    // dc->SetIdBounds(startId, rect);
 		    
-		    dc->SetId(dcId); // set unique id & set bbox for each segment
-		    dc->SetPen(*pen);
+		    pdc->SetId(dcId); // set unique id & set bbox for each segment
+		    pdc->SetPen(*pen);
 		    wxRect rect (*point_beg, *point_end);
-		    dc->SetIdBounds(dcId, rect);
-		    dc->DrawLine(point_beg->x, point_beg->y,
-				 point_end->x, point_end->y);
+		    pdc->SetIdBounds(dcId, rect);
+		    pdc->DrawLine(point_beg->x, point_beg->y,
+				  point_end->x, point_end->y);
 		}
 	    }
 	    else {
@@ -352,12 +362,12 @@
 		    wxPoints[i] = *point_beg;
 		}
 		
-		dc->DrawLines(pointsScreen->GetCount(), wxPoints);
+		pdc->DrawLines(pointsScreen->GetCount(), wxPoints);
 
 		if (!IsSelected(line) && settings.direction.enabled) {
 		    DrawDirectionArrow();
 		    // restore pen
-		    dc->SetPen(*pen);
+		    pdc->SetPen(*pen);
 		}
 	    }
 	}
@@ -388,16 +398,23 @@
     int dcId;
     wxPoint *point;
     wxPen *pen;
+    wxPseudoDC *pdc;
 
     if (!IsSelected(line) && !settings.vertex.enabled)
 	return -1;
 
+    pdc = NULL;
+
     // determine color
     if (!IsSelected(line)) {
+	pdc = dc;
+
 	pen = new wxPen(settings.vertex.color, settings.lineWidth, wxSOLID);
 	dcId = 0;
     }
     else {
+	pdc = dcTmp;
+	
 	if (!drawSelected) {
 	    return -1;
 	}
@@ -415,21 +432,21 @@
 	}
     }
 
-    dc->SetId(dcId); /* 0 | 1 (selected) */
-    dc->SetPen(*pen);
+    pdc->SetId(dcId); /* 0 | 1 (selected) */
+    pdc->SetPen(*pen);
 
     for (size_t i = 1; i < pointsScreen->GetCount() - 1; i++, dcId += 2) {
 	point = (wxPoint*) pointsScreen->Item(i)->GetData();
 
 	if (IsSelected(line) && drawSegments) {
-	    dc->SetId(dcId);
-	    dc->SetPen(*pen);
+	    pdc->SetId(dcId);
+	    pdc->SetPen(*pen);
 	    wxRect rect (*point, *point);
-	    dc->SetIdBounds(dcId, rect);
+	    pdc->SetIdBounds(dcId, rect);
 	}
 	
 	if (settings.vertex.enabled) {
-	    DrawCross(line, (const wxPoint*) pointsScreen->Item(i)->GetData());
+	    DrawCross(pdc, line, (const wxPoint*) pointsScreen->Item(i)->GetData());
 	    topology.vertex++;
 	}
     }
@@ -457,7 +474,10 @@
     bool draw;
 
     wxPen *pen;
+    wxPseudoDC *pdc;
 
+    pdc = NULL;
+
     // draw nodes??
     if (!settings.nodeOne.enabled && !settings.nodeTwo.enabled)
 	return -1;
@@ -477,6 +497,8 @@
 
 	// determine color
 	if (IsSelected(line)) {
+	    pdc = dcTmp;
+	    
 	    if (!drawSelected) {
 		return -1;
 	    }
@@ -499,6 +521,8 @@
 	    }
 	}
 	else {
+	    pdc = dc;
+	    
 	    dcId = 0;
 	    if (Vect_get_node_n_lines(mapInfo, node) == 1) {
 		pen = new wxPen(settings.nodeOne.color, settings.lineWidth, wxSOLID);
@@ -515,14 +539,14 @@
 	wxPoint point((int) x, (int) y);
 	if (IsSelected(line) && drawSegments) {
 	    wxRect rect (point, point);
-	    dc->SetIdBounds(dcId, rect);
+	    pdc->SetIdBounds(dcId, rect);
 	}
 
 	// draw node if needed
 	if (draw) {
-	    dc->SetId(dcId);
-	    dc->SetPen(*pen);
-	    DrawCross(line, &point);
+	    pdc->SetId(dcId);
+	    pdc->SetPen(*pen);
+	    DrawCross(pdc, line, &point);
 	}
     }
     
@@ -535,19 +559,21 @@
    
    Used for points, nodes, vertices
 
+   \param[in,out] PseudoDC where to draw
    \param[in] point coordinates of center
    \param[in] size size of the cross symbol
    
    \return 1 on success
    \return -1 on failure
 */
-int DisplayDriver::DrawCross(int line, const wxPoint* point, int size)
+int DisplayDriver::DrawCross(wxPseudoDC *pdc, int line, const wxPoint* point, int size)
 {
-    if (!dc || !point)
+    if (!pdc || !point)
 	return -1;
 
-    dc->DrawLine(point->x - size, point->y, point->x + size, point->y);
-    dc->DrawLine(point->x, point->y - size, point->x, point->y + size);
+    pdc->DrawLine(point->x - size, point->y, point->x + size, point->y);
+    pdc->DrawLine(point->x, point->y - size, point->x, point->y + size);
+    
     return 1;
 }
 

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/line.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -1,7 +1,7 @@
 /**
    \file line.cpp
 
-   \brief Line manipulation
+   \brief Feature manipulation (add, delete, move)
 
    This program is free software under the GNU General Public
    License (>=v2). Read the file COPYING that comes with GRASS
@@ -42,6 +42,7 @@
     size_t npoints;
 
     int newline;
+    int changeset;
 
     struct line_pnts *Points;
     struct line_cats *Cats;
@@ -133,13 +134,14 @@
 	return -1;
     }
 
+    /* register changeset */
+    changeset = changesets.size();
+    AddActionToChangeset(changeset, ADD, newline);
+
     /* break at intersection */
     if (settings.breakLines) {
-	BreakLineAtIntersection(newline, Points);
+	BreakLineAtIntersection(newline, Points, changeset);
     }
-    
-    /* register changeset */
-    // AddActionToChangeset(changesets.size(), ADD, newline);
 
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);
@@ -167,6 +169,8 @@
 		       const char *bgmap, int snap, double threshold)
 {
     int newline, type, dim;
+    int nlines, changeset;
+
     struct line_pnts *points;
     struct line_cats *cats;
 
@@ -236,27 +240,24 @@
 			threshold, (snap == SNAP) ? 0 : 1); 
     }
 
+    nlines = Vect_get_num_lines(display->mapInfo);
+
     /* register changeset */
-    // AddActionToChangeset(changesets.size(), REWRITE, line);
+    changeset = changesets.size();
+    AddActionToChangeset(changeset, DEL, line);
 
     /* rewrite line */
     newline = Vect_rewrite_line(display->mapInfo, line, type, points, cats);
+
+    AddActionToChangeset(changeset, ADD, newline);
+
     if (newline > 0 && settings.breakLines) {
-	BreakLineAtIntersection(newline, points);
+	BreakLineAtIntersection(newline, points, changeset);
     }
 
     if (newline < 0)
 	WriteLineMsg();
     
-    /* TODO
-    if (ret > 0) {
-	changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
-    }
-    else {
-	changesets.erase(changesets.size()-1);
-    }
-    */
-    
     Vect_destroy_line_struct(points);
     Vect_destroy_cats_struct(cats);
     
@@ -281,7 +282,9 @@
 int Digit::SplitLine(double x, double y, double z,
 		     double thresh)
 {
-    int ret, changeset;
+    int ret;
+    int nlines, changeset;
+
     struct line_pnts *point;
     struct ilist *list;
 
@@ -295,22 +298,19 @@
 
     Vect_append_point(point, x, y, z);
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
+    nlines = Vect_get_num_lines(display->mapInfo);
+
+    changeset = AddActionsBefore();
     
     ret = Vedit_split_lines(display->mapInfo, display->selected.values,
 			    point, thresh, list);
 
-    /*
-    for (int i = 0; i < list->n_values; i++) {
-	AddActionToChangeset(changeset, ADD, list->value[i]);
+    if (ret > 0) {
+	AddActionsAfter(changeset, nlines);
     }
-    */
+    else {
+	changesets.erase(changeset);
+    }
     
     Vect_destroy_list(list);
     Vect_destroy_line_struct(point);
@@ -331,8 +331,8 @@
     int ret;
     int n_dblinks;
     int changeset;
+
     struct line_cats *Cats, *Cats_del;
-    // struct ilist *List;
 
     if (!display->mapInfo) {
 	DisplayMsg();
@@ -376,14 +376,10 @@
     }
 
     /* register changeset */
-    changeset = changesets.size();
-    /* 
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
-    ret = Vedit_delete_lines(display->mapInfo, display->selected.values);
+    changeset = AddActionsBefore();
 
+    ret = Vedit_delete_lines(display->mapInfo, display->selected.values);
+    
     if (ret > 0 && delete_records) {
 	struct field_info *fi;
 	char buf[GSQL_MAX];
@@ -465,8 +461,8 @@
 int Digit::MoveLines(double move_x, double move_y, double move_z,
 		     const char *bgmap, int snap, double thresh)
 {
-    int ret, changeset;
-    long int nlines;
+    int ret;
+    int nlines, changeset;
     struct Map_info **BgMap; /* backgroud vector maps */
     int nbgmaps;             /* number of registrated background maps */
 
@@ -488,36 +484,29 @@
 	}
     }
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, REWRITE, display->selected.values->value[i]);
-    }
-    */
     nlines = Vect_get_num_lines(display->mapInfo);
 
+    /* register changeset */
+    changeset = AddActionsBefore();
+    
     ret = Vedit_move_lines(display->mapInfo, BgMap, nbgmaps,
 			   display->selected.values,
 			   move_x, move_y, move_z,
 			   snap, thresh);
 
-    if (ret > 0 && settings.breakLines) {
-	for(int i = 1; i <= ret; i++)
-	    BreakLineAtIntersection(nlines+i, NULL);
-    }
-
-    /* TODO
     if (ret > 0) {
-	for (int i = 0; i < display->selected.values->n_values; i++) {
-	    changesets[changeset][i].line = nlines + i + 1;
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
 	changesets.erase(changeset);
     }
-    */
     
+    if (ret > 0 && settings.breakLines) {
+	for(int i = 1; i <= ret; i++) {
+	    BreakLineAtIntersection(nlines + i, NULL, changeset);
+	}
+    }
+    
     if (BgMap && BgMap[0]) {
 	Vect_close(BgMap[0]);
     }
@@ -533,35 +522,28 @@
 */
 int Digit::FlipLines()
 {
-    int ret, changeset;
-    long int nlines;
+    int ret;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, REWRITE, display->selected.values->value[i]);
-    }
-    */
+
     nlines = Vect_get_num_lines(display->mapInfo);
 
+    /* register changeset */
+    changeset = AddActionsBefore();
+    
     ret = Vedit_flip_lines(display->mapInfo, display->selected.values);
 
-    /*
     if (ret > 0) {
-	for (int i = 0; i < display->selected.values->n_values; i++) {
-	    changesets[changeset][i].line = nlines + i + 1;
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
 	changesets.erase(changeset);
     }
-    */
     
     return ret;
 }
@@ -574,37 +556,25 @@
 */
 int Digit::MergeLines()
 {
-    int ret, changeset, line;
+    int ret;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
+    nlines = Vect_get_num_lines(display->mapInfo);
+    
+    changeset = AddActionsBefore();
+
     ret = Vedit_merge_lines(display->mapInfo, display->selected.values);
 
     if (ret > 0) {
-	/* update changeset */
-	for (int i = 0; i < display->selected.values->n_values; i++) {
-	    line = display->selected.values->value[i];
-	    if (Vect_line_alive(display->mapInfo, line)) {
-		// RemoveActionFromChangeset(changeset, DELETE, line);
-	    }
-	}
-	for(int i = 0; i < Vect_get_num_updated_lines(display->mapInfo); i++) {
-	    line = Vect_get_updated_line(display->mapInfo, i);
-	    // AddActionToChangeset(changeset, ADD, line);
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
-	// changesets.erase(changeset);
+	changesets.erase(changeset);
     }
 
     return ret;
@@ -620,38 +590,26 @@
 */
 int Digit::BreakLines()
 {
-    int ret, changeset, line;
+    int ret;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
+    nlines = Vect_get_num_lines(display->mapInfo);
+    
+    changeset = AddActionsBefore();
+    
     ret = Vect_break_lines_list(display->mapInfo, display->selected.values, NULL,
 				GV_LINES, NULL, NULL);
 
     if (ret > 0) {
-	/* update changeset */
-	for (int i = 0; i < display->selected.values->n_values; i++) {
-	    line = display->selected.values->value[i];
-	    if (Vect_line_alive(display->mapInfo, line)) {
-		// RemoveActionFromChangeset(changeset, DELETE, line);
-	    }
-	}
-	for(int i = 0; i < Vect_get_num_updated_lines(display->mapInfo); i++) {
-	    line = Vect_get_updated_line(display->mapInfo, i);
-	    // AddActionToChangeset(changeset, ADD, line);
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
-	// changesets.erase(changeset);
+	changesets.erase(changeset);
     }
 
     return ret;
@@ -669,14 +627,27 @@
 */
 int Digit::SnapLines(double thresh)
 {
+    int changeset, nlines;
+    
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
+    nlines = Vect_get_num_lines(display->mapInfo);
+    
+    changeset = AddActionsBefore();
+    
     Vect_snap_lines_list (display->mapInfo, display->selected.values,
 			  thresh, NULL, NULL);
 
+    if (nlines < Vect_get_num_lines(display->mapInfo)) {
+	AddActionsAfter(changeset, nlines);
+    }
+    else {
+	changesets.erase(changeset);
+    }
+
     return 0;
 }
 
@@ -688,36 +659,29 @@
 */
 int Digit::ConnectLines(double thresh)
 {
-    int ret, changeset;
-    long int nlines_diff;
+    int ret;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
+    nlines = Vect_get_num_lines(display->mapInfo);
+
     /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
-    nlines_diff = Vect_get_num_lines(display->mapInfo);
+    changeset = AddActionsBefore();
 
     ret = Vedit_connect_lines(display->mapInfo, display->selected.values,
 			      thresh);
 
     if (ret > 0) {
-	nlines_diff = Vect_get_num_lines(display->mapInfo) - nlines_diff;
-	for(int i = Vect_get_num_lines(display->mapInfo); i > nlines_diff; i--) {
-	    // AddActionToChangeset(changeset, ADD, i);
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
-	// changesets.erase(changeset);
+	changesets.erase(changeset);
     }
-
+    
     return ret;
 }
 
@@ -739,15 +703,28 @@
 			 double start, double step)
 {
     int ret;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
+    nlines = Vect_get_num_lines(display->mapInfo);
+
+    /* register changeset */
+    changeset = AddActionsBefore();
+
     ret = Vedit_bulk_labeling (display->mapInfo, display->selected.values,
 			       x1, y1, x2, y2, start, step);
 
+    if (ret > 0) {
+	AddActionsAfter(changeset, nlines);
+    }
+    else {
+	changesets.erase(changeset);
+    }
+
     return ret;
 }
 
@@ -762,8 +739,8 @@
 */
 int Digit::CopyLines(std::vector<int> ids, const char* bgmap_name)
 {
-    int ret, changeset;
-    long int nlines;
+    int ret;
+    int changeset, nlines;
     struct Map_info *bgMap;
     struct ilist *list;
 
@@ -798,21 +775,21 @@
     ret = Vedit_copy_lines (display->mapInfo, bgMap,
 			    list);
 
-    if (ret > 0 && bgMap && settings.breakLines) {
-	for(int i = 1; i <= ret; i++)
-	    BreakLineAtIntersection(nlines+i, NULL);
-    }
-
     if (ret > 0) {
-	/* register changeset */
 	changeset = changesets.size();
-	/*
-	for (int i = 0; i < list->n_values; i++) {
-	    AddActionToChangeset(changeset, ADD, nlines + i + 1);
+	for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
+	    AddActionToChangeset(changeset, ADD, line);
 	}
-	*/
     }
+    else {
+	changesets.erase(changeset);
+    }
 
+    if (ret > 0 && bgMap && settings.breakLines) {
+	for(int i = 1; i <= ret; i++)
+	    BreakLineAtIntersection(nlines + i, NULL, changeset);
+    }
+
     if (list != display->selected.values) {
 	Vect_destroy_list(list);
     }
@@ -888,34 +865,28 @@
 int Digit::TypeConvLines()
 {
     int ret;
-    int npoints, nlines, ncentroids, nboundaries;
-    int changeset, nlines_diff;
+    int npoints, ncentroids, nboundaries;
+    int changeset, nlines;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
-    /* register changeset */
-    changeset = changesets.size();
-    /*
-    for (int i = 0; i < display->selected.values->n_values; i++) {
-	AddActionToChangeset(changeset, DELETE, display->selected.values->value[i]);
-    }
-    */
-    nlines_diff = Vect_get_num_lines(display->mapInfo);
+    nlines = Vect_get_num_lines(display->mapInfo);
 
+    /* register changeset */
+    changeset = AddActionsBefore();
+    
     ret = Vedit_chtype_lines (display->mapInfo, display->selected.values,
 			       &npoints, &ncentroids,
 			       &nlines, &nboundaries);
 
     if(ret > 0) {
-	for(int i = Vect_get_num_lines(display->mapInfo); i > nlines_diff; i--) {
-	    // AddActionToChangeset(changeset, ADD, i);
-	}
+	AddActionsAfter(changeset, nlines);
     }
     else {
-	// changesets.erase(changeset);
+	changesets.erase(changeset);
     }
 
     return ret;
@@ -928,13 +899,17 @@
   
   \return number of modified lines
 */
-int Digit::BreakLineAtIntersection(int line, struct line_pnts* points_line)
+int Digit::BreakLineAtIntersection(int line, struct line_pnts* points_line,
+				   int changeset)
 {
-    int ret, type;
+    int ret, type, nlines;
     int lineBreak;
     BOUND_BOX lineBox;
     struct ilist *list, *listBreak, *listRef;
     struct line_pnts *points_check, *points;
+
+    if (!Vect_line_alive(display->mapInfo, line))
+	return 0;
     
     if (!points_line) {
 	points = Vect_new_line_struct();
@@ -974,13 +949,30 @@
 					 WITHOUT_Z))
 	    Vect_list_append(listBreak, lineBreak);
     }
+    
+    nlines = Vect_get_num_lines(display->mapInfo);
 
+    for (int i = 0; i < listBreak->n_values; i++) {	
+	AddActionToChangeset(changeset, DEL, listBreak->value[i]);
+    }
+
     ret = Vect_break_lines_list(display->mapInfo, listBreak, listRef,
 				GV_LINES, NULL, NULL);
+
+    for (int i = 0; i < listBreak->n_values; i++) {	
+	if (Vect_line_alive(display->mapInfo, listBreak->value[i]))
+	    RemoveActionFromChangeset(changeset, DEL, listBreak->value[i]);
+    }
+
+    for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
+	AddActionToChangeset(changeset, ADD, line);
+    }
     
     Vect_destroy_line_struct(points_check);
+
     if (points != points_line)
 	Vect_destroy_line_struct(points);
+
     Vect_destroy_list(list);
     Vect_destroy_list(listBreak);
     Vect_destroy_list(listRef);

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/undo.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -3,8 +3,6 @@
 
    \brief Undo/Redo functionality
 
-   \todo Implement Vect_restore_line() in Vlib
-
    This program is free software under the GNU General Public
    License (>=v2). Read the file COPYING that comes with GRASS
    for details.
@@ -48,16 +46,16 @@
 
     if (level == 0) {
 	/* 0 -> undo all */
-	level = changesetDead - changesetCurrent;
+	level = -changesetLast;
     }
 
-    G_debug(2, "Digit.Undo(): changeset_last=%d changeset_dead=%d, changeset_current=%d, level=%d",
-	    changesetLast, changesetDead, changesetCurrent, level);
+    G_debug(2, "Digit.Undo(): changeset_last=%d, changeset_current=%d, level=%d",
+	    changesetLast, changesetCurrent, level);
     
     if (level < 0) { /* undo */
 	if (changesetCurrent + level < -1)
 	    return changesetCurrent;
-	for (int changeset = changesetCurrent; changeset > changesetCurrent + level; --changeset) {
+	for (int changeset = changesetCurrent; changeset >= changesetCurrent + level; --changeset) {
 	    ApplyChangeset(changeset, true);
 	}
     }
@@ -71,10 +69,10 @@
 
     changesetCurrent += level;
 
-    G_debug(2, "Digit.Undo(): changeset_dead=%d, changeset_current=%d",
-	    changesetDead, changesetCurrent);
+    G_debug(2, "Digit.Undo(): changeset_current=%d",
+	    changesetCurrent);
 
-    return (changesetDead >= changesetCurrent) ? -1 : changesetCurrent;
+    return changesetCurrent;
 }
 
 /**
@@ -89,21 +87,24 @@
 */
 int Digit::ApplyChangeset(int changeset, bool undo)
 { 
-    int ret;
+    int ret, line, type;
 
     if (changeset < 0 || changeset > (int) changesets.size())
 	return -1;
 
     ret = 0;
     std::vector<action_meta> action = changesets[changeset];
-    for (std::vector<action_meta>::const_iterator i = action.begin(), e = action.end();
+    for (std::vector<action_meta>::const_reverse_iterator i = action.rbegin(), e = action.rend();
 	 i != e; ++i) {
-	if ((undo && (*i).type == ADD) ||
-	    (!undo && (*i).type == DELETE)) {
-	    if (Vect_line_alive(display->mapInfo, (*i).line)) {
+	type = (*i).type;
+	line = (*i).line;
+
+	if ((undo && type == ADD) ||
+	    (!undo && type == DEL)) {
+	    if (Vect_line_alive(display->mapInfo, line)) {
 		G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=add, line=%d -> deleted",
-			changeset, (*i).line);
-		Vect_delete_line(display->mapInfo, (*i).line);
+			changeset, line);
+		Vect_delete_line(display->mapInfo, line);
 		if (!ret)
 		    ret = 1;
 	    }
@@ -112,79 +113,58 @@
 			changeset, (*i).line);
 	    }
 	}
-	else if ((*i).type == REWRITE) {
-	    if (Vect_line_alive(display->mapInfo, (*i).line)) {
-		G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=rewrite, line=%d",
-			changeset, (*i).line);
-		if (Vect_rewrite_line (display->mapInfo, (*i).line, (*i).ltype, (*i).Points, (*i).Cats) < 0)
-		    return -1;
-	    }
-	    else {
-		G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=rewrite, line=%d -> dead",
-			changeset, (*i).line);
-	    }
-	}
 	else { /* DELETE */
-	    if (!Vect_line_alive(display->mapInfo, (*i).line)) {
+	    long offset = (*i).offset;
+	    if (!Vect_line_alive(display->mapInfo, line)) {
 		G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=delete, line=%d -> added",
-			changeset, (*i).line);
-		if (Vect_write_line(display->mapInfo, (*i).ltype, (*i).Points, (*i).Cats) < 0)
+			changeset, line);
+		if (Vect_restore_line(display->mapInfo, line, offset) < 0)
 		    return -1;
 		if (!ret)
 		    ret = 1;
 	    }
 	    else {
 		G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=delete, line=%d alive",
-			changeset, (*i).line);
+			changeset, line);
 	    }
 	}
     }
     
-    if (changeset < (int) changesets.size() - 1)
-	changesetDead = changeset;
-
     return ret;
 }
 
 /**
    \brief Add action to changeset
 
-   \todo Use Vect_restore_line() (TODO) instead!
+   \param type action type (ADD, DEL)
 
-   \param type action type (ADD, DELETE)
-
    \return 0 on success
    \return -1 on error
 */
 int Digit::AddActionToChangeset(int changeset, Digit::action_type type, int line)
 {
-    int ltype;
-    struct line_pnts *Points;
-    struct line_cats *Cats;
+    long offset;
 
     if (!display->mapInfo) {
 	DisplayMsg();
 	return -1;
     }
 
-    Points = Vect_new_line_struct();
-    Cats = Vect_new_cats_struct(); 
-
-    /* do copy */
-    if (!Vect_line_alive(display->mapInfo, line))
-	DeadLineMsg(line);
+    if (!Vect_line_alive(display->mapInfo, line)) {
+	// DeadLineMsg(line);
 	return -1;
+    }
 
-    ltype = Vect_read_line(display->mapInfo, Points, Cats, line);
+    offset = Vect_get_line_offset(display->mapInfo, line);
 
-    action_meta data = { type, line, ltype, Points, Cats };
+    action_meta data = { type, line, offset };
     if (changesets.find(changeset) == changesets.end()) {
 	changesets[changeset] = std::vector<action_meta>();
 	changesetCurrent = changeset;
     }
     changesets[changeset].push_back(data);
-    G_debug (3, "Digit.AddActionToChangeset(): changeset=%d, type=%d, line=%d",
-	     changeset, type, line);
+    G_debug (3, "Digit.AddActionToChangeset(): changeset=%d, type=%d, line=%d, offset=%ld",
+	     changeset, type, line, offset);
 
     return 0;
 }
@@ -202,10 +182,7 @@
     std::vector<action_meta> action = changesets[changeset];
     for (std::vector<action_meta>::iterator i = action.begin(), e = action.end();
 	 i != e; ++i) {
-	Vect_destroy_line_struct((*i).Points);
-	Vect_destroy_cats_struct((*i).Cats);
-	(*i).Points = NULL;
-	(*i).Cats = NULL;
+	;
     }
 
     return;
@@ -215,7 +192,7 @@
    \brief Remove action from changeset
 
    \param changeset changeset id
-   \param type action type (ADD, DELETE, REWRITE)
+   \param type action type (ADD, DEL)
    \param line line id
 
    \return number of actions in changeset
@@ -245,5 +222,5 @@
 */
 int Digit::GetUndoLevel()
 {
-    return changesetCurrent - changesetDead;
+    return changesetCurrent;
 }

Modified: grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp	2008-09-25 11:41:09 UTC (rev 33536)
+++ grass/branches/develbranch_6/gui/wxpython/vdigit/vertex.cpp	2008-09-25 11:43:39 UTC (rev 33537)
@@ -79,7 +79,7 @@
 			    1, snap);
 
     if (settings.breakLines && ret > 0) {
-	BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL);
+	BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL, 1);
     }
 
     /* TODO



More information about the grass-commit mailing list