Prechádzať zdrojové kódy

wxGUI/vdigit: some minor fixes in undo
(merge from devbr6, https://trac.osgeo.org/grass/changeset/34466)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34467 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 rokov pred
rodič
commit
c5621a2926

+ 1 - 1
gui/wxpython/vdigit/digit.cpp

@@ -32,7 +32,7 @@ Digit::Digit(DisplayDriver *ddriver, void *window)
 	InitCats();
     }
 
-    changesetCurrent = -1; // initial value for undo/redo
+    changesetEnd = changesetCurrent = -1; // initial value for undo/redo
 
     display->msgCaption = _("Digitization error");
     

+ 2 - 1
gui/wxpython/vdigit/digit.h

@@ -36,7 +36,8 @@ private:
 
     std::map<int, std::vector<action_meta> > changesets;
     int changesetCurrent;  /* first changeset to apply */
-
+    int changesetEnd;      /* last changeset to be applied */
+    
     int AddActionToChangeset(int, action_type, int);
     int ApplyChangeset(int, bool);
     void FreeChangeset(int);

+ 13 - 5
gui/wxpython/vdigit/undo.cpp

@@ -55,7 +55,7 @@ int Digit::Undo(int 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);
 	}
     }
@@ -69,9 +69,14 @@ int Digit::Undo(int level)
 
     changesetCurrent += level;
 
-    G_debug(2, "Digit.Undo(): changeset_current=%d",
-	    changesetCurrent);
-
+    G_debug(2, "Digit.Undo(): changeset_current=%d, changeset_last=%d, changeset_end=%d",
+	    changesetCurrent, changesetLast, changesetEnd);
+    
+    if (changesetCurrent == changesetEnd) {
+	changesetEnd = changesetLast;
+	return -1;
+    }
+    
     return changesetCurrent;
 }
 
@@ -92,13 +97,16 @@ int Digit::ApplyChangeset(int changeset, bool undo)
     if (changeset < 0 || changeset > (int) changesets.size())
 	return -1;
 
+    if (changesetEnd < 0)
+	changesetEnd = changeset;
+    
     ret = 0;
     std::vector<action_meta> action = changesets[changeset];
     for (std::vector<action_meta>::const_reverse_iterator i = action.rbegin(), e = action.rend();
 	 i != e; ++i) {
 	type = (*i).type;
 	line = (*i).line;
-
+	
 	if ((undo && type == ADD) ||
 	    (!undo && type == DEL)) {
 	    if (Vect_line_alive(display->mapInfo, line)) {