[GRASS-SVN] r30860 - grass/trunk/gui/wxpython/vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 4 10:56:27 EDT 2008
Author: martinl
Date: 2008-04-04 10:56:26 -0400 (Fri, 04 Apr 2008)
New Revision: 30860
Modified:
grass/trunk/gui/wxpython/vdigit/digit.h
grass/trunk/gui/wxpython/vdigit/line.cpp
grass/trunk/gui/wxpython/vdigit/undo.cpp
Log:
wxGUI (vdigit): Undo functionality updated (very basic prototype)
Modified: grass/trunk/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.h 2008-04-04 13:32:10 UTC (rev 30859)
+++ grass/trunk/gui/wxpython/vdigit/digit.h 2008-04-04 14:56:26 UTC (rev 30860)
@@ -34,6 +34,7 @@
int AddActionToChangeset(int, action_type, int);
int ApplyChangeset(int, bool);
void FreeChangeset(int);
+ int RemoveActionFromChangeset(int, action_type, int);
public:
Digit(DisplayDriver *);
Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp 2008-04-04 13:32:10 UTC (rev 30859)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp 2008-04-04 14:56:26 UTC (rev 30860)
@@ -525,40 +525,94 @@
*/
int Digit::MergeLines()
{
- int ret;
+ int ret, changeset, line;
if (!display->mapInfo) {
return -1;
}
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
+ }
+
ret = Vedit_merge_lines(display->mapInfo, display->selected);
+ if (ret > 0) {
+ /* update changeset */
+ for (int i = 0; i < display->selected->n_values; i++) {
+ line = display->selected->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);
+ }
+ for (int i = 0; i < display->selected->n_values; i++) {
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
return ret;
}
/**
\brief Breaks selected lines/boundaries
+ \todo undo
+
\return number of modified lines
\return -1 on error
*/
int Digit::BreakLines()
{
- int ret;
+ int ret, changeset, line;
if (!display->mapInfo) {
return -1;
}
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
+ }
+
ret = Vect_break_lines_list(display->mapInfo, display->selected,
GV_LINES, NULL, NULL);
+ if (ret > 0) {
+ /* update changeset */
+ for (int i = 0; i < display->selected->n_values; i++) {
+ line = display->selected->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);
+ }
+ for (int i = 0; i < display->selected->n_values; i++) {
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
return ret;
}
/**
\brief Snap selected lines/boundaries
+ \todo undo
+
\param thresh threshold value for snapping
\return 0 on success
@@ -585,15 +639,37 @@
*/
int Digit::ConnectLines(double thresh)
{
- int ret;
+ int ret, changeset;
+ long int nlines_diff;
if (!display->mapInfo) {
return -1;
}
+ if (display->selected->n_values != 2)
+ return 0;
+
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
+ }
+
+ nlines_diff = Vect_get_num_lines(display->mapInfo);
+
ret = Vedit_connect_lines(display->mapInfo, display->selected,
thresh);
+ if (ret == 1) {
+ 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);
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
return ret;
}
@@ -602,6 +678,8 @@
Modified vector map must be 3D.
+ \todo Undo
+
\param x1,y1,x2,y2 line nodes for intersection
\param start starting value
\param step step value for labeling
@@ -752,12 +830,34 @@
*/
int Digit::TypeConvLines()
{
+ int ret;
+ int npoints, nlines, ncentroids, nboundaries;
+ int changeset, nlines_diff;
+
if (!display->mapInfo) {
return -1;
}
- int npoints, nlines, ncentroids, nboundaries;
- return Vedit_chtype_lines (display->mapInfo, display->selected,
+ /* register changeset */
+ changeset = changesets.size();
+ for (int i = 0; i < display->selected->n_values; i++) {
+ AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
+ }
+
+ nlines_diff = Vect_get_num_lines(display->mapInfo);
+
+ ret = Vedit_chtype_lines (display->mapInfo, display->selected,
&npoints, &ncentroids,
&nlines, &nboundaries);
+
+ if(ret > 0) {
+ for(int i = Vect_get_num_lines(display->mapInfo); i > nlines_diff; i--) {
+ AddActionToChangeset(changeset, ADD, i);
+ }
+ }
+ else {
+ changesets.erase(changeset);
+ }
+
+ return ret;
}
Modified: grass/trunk/gui/wxpython/vdigit/undo.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/undo.cpp 2008-04-04 13:32:10 UTC (rev 30859)
+++ grass/trunk/gui/wxpython/vdigit/undo.cpp 2008-04-04 14:56:26 UTC (rev 30860)
@@ -201,3 +201,30 @@
return;
}
+
+/**
+ \brief Remove action from changeset
+
+ \param changeset changeset id
+ \param type action type (ADD, DELETE, REWRITE)
+ \param line line id
+
+ \return number of actions in changeset
+ \return -1 on error
+*/
+int Digit::RemoveActionFromChangeset(int changeset, Digit::action_type type, int line)
+{
+ if (changesets.find(changeset) == changesets.end())
+ return -1;
+
+ std::vector<action_meta>& action = changesets[changeset];
+ for (std::vector<action_meta>::iterator i = action.begin(); i != action.end(); ++i) {
+ if ((*i).type == type && (*i).line == line) {
+ G_debug (3, "Digit.RemoveActionFromChangeset(): changeset=%d, type=%d, line=%d",
+ changeset, type, line);
+ action.erase(i--);
+ }
+ }
+
+ return action.size();
+}
More information about the grass-commit
mailing list