[GRASS-SVN] r30853 - grass/trunk/gui/wxpython/vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Apr 3 10:54:19 EDT 2008
Author: martinl
Date: 2008-04-03 10:54:19 -0400 (Thu, 03 Apr 2008)
New Revision: 30853
Modified:
grass/trunk/gui/wxpython/vdigit/cats.cpp
grass/trunk/gui/wxpython/vdigit/digit.h
grass/trunk/gui/wxpython/vdigit/line.cpp
grass/trunk/gui/wxpython/vdigit/undo.cpp
grass/trunk/gui/wxpython/vdigit/vertex.cpp
Log:
wxGUI (vdigit): undo updated for selected tools (rewrite line)
Modified: grass/trunk/gui/wxpython/vdigit/cats.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/cats.cpp 2008-04-03 12:45:00 UTC (rev 30852)
+++ grass/trunk/gui/wxpython/vdigit/cats.cpp 2008-04-03 14:54:19 UTC (rev 30853)
@@ -256,8 +256,20 @@
layer, *c, add);
}
+ /* register changeset */
+ AddActionToChangeset(changesets.size(), REWRITE, display->selected->value[0]);
+
ret = Vect_rewrite_line(display->mapInfo, line, type,
Points, Cats);
+
+ if (ret > 0) {
+ /* updates feature id (id is changed since line has been rewriten) */
+ changesets[changesets.size()-1][0].line = ret;
+ }
+ else {
+ changesets.erase(changesets.size()-1);
+ }
+
if (line_id == -1) {
/* update line id since the line was rewritten */
display->selected->value[0] = ret;
Modified: grass/trunk/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.h 2008-04-03 12:45:00 UTC (rev 30852)
+++ grass/trunk/gui/wxpython/vdigit/digit.h 2008-04-03 14:54:19 UTC (rev 30853)
@@ -18,7 +18,7 @@
struct Map_info** OpenBackgroundVectorMap(const char *);
/* undo/redo */
- enum action_type { ADD, DELETE };
+ enum action_type { ADD, DELETE, REWRITE };
struct action_meta {
action_type type;
int line;
Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp 2008-04-03 12:45:00 UTC (rev 30852)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp 2008-04-03 14:54:19 UTC (rev 30853)
@@ -214,13 +214,22 @@
threshold, (snap == SNAP) ? 0 : 1);
}
+ /* register changeset */
+ AddActionToChangeset(changesets.size(), REWRITE, line);
+
/* rewrite line */
if (ret == 0) {
- if (Vect_rewrite_line(display->mapInfo, line, type, points, cats) < 0) {
- ret = -1;
- }
+ ret = Vect_rewrite_line(display->mapInfo, line, type, points, cats);
}
+ if (ret > 0) {
+ /* updates feature id (id is changed since line has been rewriten) */
+ 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);
@@ -238,22 +247,39 @@
\param x,y,z coordinates (z is used only if map is 3d)
\param thresh threshold value to find a point on line
+
+ \return number of modified lines
+ \return -1 on error
*/
int Digit::SplitLine(double x, double y, double z,
double thresh)
{
- int ret;
+ int ret, changeset;
struct line_pnts *point;
+ struct ilist *list;
if (!display->mapInfo)
return -1;
point = Vect_new_line_struct();
+ list = Vect_new_list();
+
Vect_append_point(point, x, y, z);
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
+ }
+
ret = Vedit_split_lines(display->mapInfo, display->selected,
- point, thresh, NULL);
+ point, thresh, list);
+ for (int i = 0; i < list->n_values; i++) {
+ AddActionToChangeset(changeset, ADD, list->value[i]);
+ }
+
+ Vect_destroy_list(list);
Vect_destroy_line_struct(point);
return ret;
@@ -407,7 +433,8 @@
int Digit::MoveLines(double move_x, double move_y, double move_z,
const char *bgmap, int snap, double thresh)
{
- int ret;
+ int ret, changeset;
+ long int nlines;
struct Map_info **BgMap; /* backgroud vector maps */
int nbgmaps; /* number of registrated background maps */
@@ -426,11 +453,27 @@
}
}
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, REWRITE, display->selected->value[i]);
+ }
+ nlines = Vect_get_num_lines(display->mapInfo);
+
ret = Vedit_move_lines(display->mapInfo, BgMap, nbgmaps,
display->selected,
move_x, move_y, move_z,
snap, thresh);
+ if (ret > 0) {
+ for (int i = 0; i < display->selected->n_values; i++) {
+ changesets[changeset][i].line = nlines + i + 1;
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
if (BgMap && BgMap[0]) {
Vect_close(BgMap[0]);
}
@@ -446,14 +489,31 @@
*/
int Digit::FlipLines()
{
- int ret;
+ int ret, changeset;
+ long int nlines;
if (!display->mapInfo) {
return -1;
}
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, REWRITE, display->selected->value[i]);
+ }
+ nlines = Vect_get_num_lines(display->mapInfo);
+
ret = Vedit_flip_lines(display->mapInfo, display->selected);
+ if (ret > 0) {
+ for (int i = 0; i < display->selected->n_values; i++) {
+ changesets[changeset][i].line = nlines + i + 1;
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
return ret;
}
@@ -575,7 +635,8 @@
*/
int Digit::CopyLines(std::vector<int> ids, const char* bgmap_name)
{
- int ret;
+ int ret, changeset;
+ long int nlines;
struct Map_info *bgMap;
struct ilist *list;
@@ -586,7 +647,6 @@
return -1;
}
-
if (bgmap_name) {
const char *mapset;
bgMap = (struct Map_info *) G_malloc(sizeof (struct Map_info));
@@ -605,9 +665,19 @@
list = display->selected;
}
+ nlines = Vect_get_num_lines(display->mapInfo);
+
ret = Vedit_copy_lines (display->mapInfo, bgMap,
list);
+ if (ret > 0) {
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < list->n_values; i++) {
+ AddActionToChangeset(changeset, ADD, nlines + i + 1);
+ }
+ }
+
if (list != display->selected) {
Vect_destroy_list(list);
}
Modified: grass/trunk/gui/wxpython/vdigit/undo.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/undo.cpp 2008-04-03 12:45:00 UTC (rev 30852)
+++ grass/trunk/gui/wxpython/vdigit/undo.cpp 2008-04-03 14:54:19 UTC (rev 30853)
@@ -72,7 +72,7 @@
/**
\brief Apply changeset (undo/redo changeset)
-
+
\param changeset changeset id
\param undo if true -> undo otherwise redo
@@ -105,6 +105,18 @@
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)) {
G_debug(3, "Digit.ApplyChangeset(): changeset=%d, action=delete, line=%d -> added",
Modified: grass/trunk/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/vertex.cpp 2008-04-03 12:45:00 UTC (rev 30852)
+++ grass/trunk/gui/wxpython/vdigit/vertex.cpp 2008-04-03 14:54:19 UTC (rev 30853)
@@ -47,6 +47,9 @@
if (!display->mapInfo)
return -1;
+ if (display->selected->n_values != 1)
+ return 0;
+
BgMap = NULL;
nbgmaps = 0;
if (bgmap && strlen(bgmap) > 0) {
@@ -62,6 +65,9 @@
point = Vect_new_line_struct();
Vect_append_point(point, x, y, z);
+ /* register changeset */
+ AddActionToChangeset(changesets.size(), REWRITE, display->selected->value[0]);
+
/* move only first found vertex in bbox */
ret = Vedit_move_vertex(display->mapInfo, BgMap, nbgmaps,
display->selected,
@@ -69,6 +75,14 @@
move_x, move_y, move_z,
1, snap);
+ if (ret > 0) {
+ /* updates feature id (id is changed since line has been rewriten) */
+ changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
+ }
+ else {
+ changesets.erase(changesets.size()-1);
+ }
+
if (BgMap && BgMap[0]) {
Vect_close(BgMap[0]);
}
@@ -97,12 +111,18 @@
int ret;
struct line_pnts *point;
- if (!display->mapInfo || display->selected->n_values != 1)
+ if (!display->mapInfo)
return -1;
+ if (display->selected->n_values != 1)
+ return 0;
+
point = Vect_new_line_struct();
Vect_append_point(point, x, y, z);
+ /* register changeset */
+ AddActionToChangeset(changesets.size(), REWRITE, display->selected->value[0]);
+
if (add) {
ret = Vedit_add_vertex(display->mapInfo, display->selected,
point, thresh);
@@ -112,6 +132,14 @@
point, thresh);
}
+ if (ret > 0) {
+ /* updates feature id (id is changed since line has been rewriten) */
+ changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
+ }
+ else {
+ changesets.erase(changesets.size()-1);
+ }
+
Vect_destroy_line_struct(point);
return ret;
More information about the grass-commit
mailing list