[GRASS-SVN] r33238 - in grass/trunk/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 3 12:56:18 EDT 2008


Author: martinl
Date: 2008-09-03 12:56:18 -0400 (Wed, 03 Sep 2008)
New Revision: 33238

Modified:
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
   grass/trunk/gui/wxpython/vdigit/digit.h
   grass/trunk/gui/wxpython/vdigit/line.cpp
   grass/trunk/gui/wxpython/vdigit/vertex.cpp
Log:
wxGUI: break lines at intersection also works for
       move vertex
       move line
       edit line
       copy lines from background map
(merge from devbr6, r33236)


Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-09-03 16:50:26 UTC (rev 33237)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-09-03 16:56:18 UTC (rev 33238)
@@ -1001,8 +1001,12 @@
 
         snap, thresh = self.__getSnapThreshold()
         
-        ret = self.digit.RewriteLine(lineid, listCoords,
-                                     str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')), snap, thresh)
+        try:
+            ret = self.digit.RewriteLine(lineid, listCoords,
+                                         str(UserSettings.Get(group='vdigit', key="backgroundMap", subkey='value')),
+                                         snap, thresh)
+        except SystemExit:
+            pass
 
         if ret > 0:
             self.toolbar.EnableUndo()
@@ -1836,7 +1840,7 @@
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Digitize line features"))
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
 
-        self.intersect = wx.CheckBox(parent=panel, label=_("Break lines on intersection"))
+        self.intersect = wx.CheckBox(parent=panel, label=_("Break lines at intersection"))
         self.intersect.SetValue(UserSettings.Get(group='vdigit', key='breakLines', subkey='enabled'))
         if UserSettings.Get(group='advanced', key='digitInterface', subkey='type') == 'vedit':
             self.intersect.Enable(False)

Modified: grass/trunk/gui/wxpython/vdigit/digit.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/digit.h	2008-09-03 16:50:26 UTC (rev 33237)
+++ grass/trunk/gui/wxpython/vdigit/digit.h	2008-09-03 16:56:18 UTC (rev 33238)
@@ -17,6 +17,12 @@
     
     int SetCategory(int, int);
     struct Map_info** OpenBackgroundVectorMap(const char *);
+    int BreakLineAtIntersection(int, struct line_pnts*);
+    
+    /* settings */
+    struct _settings {
+	bool breakLines;
+    } settings;
 
     /* undo/redo */
     enum action_type { ADD, DELETE, REWRITE };
@@ -29,11 +35,6 @@
 	struct line_cats *Cats;
     };
 
-    /* settings */
-    struct _settings {
-	bool breakLines;
-    } settings;
-
     std::map<int, std::vector<action_meta> > changesets;
     int changesetCurrent;  /* first changeset to apply */
     int changesetDead;     /* first dead changeset */

Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp	2008-09-03 16:50:26 UTC (rev 33237)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp	2008-09-03 16:56:18 UTC (rev 33238)
@@ -133,48 +133,9 @@
 	return -1;
     }
 
-    /* break on intersection */
+    /* break at intersection */
     if (settings.breakLines) {
-	int lineBreak;
-	BOUND_BOX lineBox;
-	struct ilist *list, *listBreak, *listRef;
-	struct line_pnts *points_check;
-
-	list = Vect_new_list();
-	listRef = Vect_new_list();
-	listBreak = Vect_new_list();
-	
-	points_check = Vect_new_line_struct();
-
-	/* find all relevant lines */
-	Vect_get_line_box(display->mapInfo, newline, &lineBox);
-	Vect_select_lines_by_box(display->mapInfo, &lineBox,
-				 GV_LINES, list);
-
-	/* check for intersection */
-	Vect_list_append(listBreak, newline);
-	Vect_list_append(listRef, newline);
-	for (int i = 0; i < list->n_values; i++) {
-	    lineBreak = list->value[i];
-	    if (lineBreak == newline)
-		continue;
-
-	    type = Vect_read_line(display->mapInfo, points_check, NULL, lineBreak);
-	    if (!(type & GV_LINES))
-		continue;
-
-	    if (Vect_line_check_intersection(Points, points_check,
-					     WITHOUT_Z))
-		Vect_list_append(listBreak, lineBreak);
-	}
-
-	Vect_break_lines_list(display->mapInfo, listBreak, listRef,
-			      GV_LINES, NULL, NULL);
-
-	Vect_destroy_line_struct(points_check);
-	Vect_destroy_list(list);
-	Vect_destroy_list(listBreak);
-	Vect_destroy_list(listRef);
+	BreakLineAtIntersection(newline, Points);
     }
     
     /* register changeset */
@@ -205,7 +166,7 @@
 int Digit::RewriteLine(int line, std::vector<double> coords,
 		       const char *bgmap, int snap, double threshold)
 {
-    int ret, type, dim;
+    int newline, type, dim;
     struct line_pnts *points;
     struct line_cats *cats;
 
@@ -236,16 +197,23 @@
 	}
     }
     
-    ret = 0;
-    points = Vect_new_line_struct();
     cats = Vect_new_cats_struct();
 
     /* read line */
     type = Vect_read_line(display->mapInfo, NULL, cats, line);
     if (type < 0) {
-	ret = -1;
+	Vect_destroy_cats_struct(cats);
+	if (BgMap && BgMap[0]) {
+	    Vect_close(BgMap[0]);
+	}
+	
+	ReadLineMsg(line);
+	
+	return -1;
     }
 
+    points = Vect_new_line_struct();
+
     /* define line geometry */
     if (Vect_is_3d(display->mapInfo)) {
 	dim = 3;
@@ -272,10 +240,14 @@
     // AddActionToChangeset(changesets.size(), REWRITE, line);
 
     /* rewrite line */
-    if (ret == 0) {
-	ret = Vect_rewrite_line(display->mapInfo, line, type, points, cats);
+    newline = Vect_rewrite_line(display->mapInfo, line, type, points, cats);
+    if (newline > 0 && settings.breakLines) {
+	BreakLineAtIntersection(newline, points);
     }
 
+    if (newline < 0)
+	WriteLineMsg();
+    
     /* TODO
     if (ret > 0) {
 	changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);
@@ -287,12 +259,12 @@
     
     Vect_destroy_line_struct(points);
     Vect_destroy_cats_struct(cats);
-
+    
     if (BgMap && BgMap[0]) {
 	Vect_close(BgMap[0]);
     }
 
-    return ret;
+    return newline;
 }
 
 /**
@@ -530,6 +502,11 @@
 			   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++) {
@@ -821,6 +798,11 @@
     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();
@@ -938,3 +920,70 @@
 
     return ret;
 }
+
+/*!
+  \brief Break given line at intersection
+
+  \param line line id
+  
+  \return number of modified lines
+*/
+int Digit::BreakLineAtIntersection(int line, struct line_pnts* points_line)
+{
+    int ret, type;
+    int lineBreak;
+    BOUND_BOX lineBox;
+    struct ilist *list, *listBreak, *listRef;
+    struct line_pnts *points_check, *points;
+    
+    if (!points_line) {
+	points = Vect_new_line_struct();
+	if (Vect_read_line(display->mapInfo, points, NULL, line) < 0) {
+	    ReadLineMsg(line);
+	    return -1;
+	}
+    }
+    else {
+	points = points_line;
+    }
+
+    list = Vect_new_list();
+    listRef = Vect_new_list();
+    listBreak = Vect_new_list();
+    
+    points_check = Vect_new_line_struct();
+    
+    /* find all relevant lines */
+    Vect_get_line_box(display->mapInfo, line, &lineBox);
+    Vect_select_lines_by_box(display->mapInfo, &lineBox,
+			     GV_LINES, list);
+    
+    /* check for intersection */
+    Vect_list_append(listBreak, line);
+    Vect_list_append(listRef, line);
+    for (int i = 0; i < list->n_values; i++) {
+	lineBreak = list->value[i];
+	if (lineBreak == line)
+		continue;
+	
+	type = Vect_read_line(display->mapInfo, points_check, NULL, lineBreak);
+	if (!(type & GV_LINES))
+	    continue;
+	
+	if (Vect_line_check_intersection(points, points_check,
+					 WITHOUT_Z))
+	    Vect_list_append(listBreak, lineBreak);
+    }
+
+    ret = Vect_break_lines_list(display->mapInfo, listBreak, listRef,
+				GV_LINES, NULL, NULL);
+    
+    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);
+
+    return ret;
+}

Modified: grass/trunk/gui/wxpython/vdigit/vertex.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/vertex.cpp	2008-09-03 16:50:26 UTC (rev 33237)
+++ grass/trunk/gui/wxpython/vdigit/vertex.cpp	2008-09-03 16:56:18 UTC (rev 33238)
@@ -76,8 +76,12 @@
 			    display->selected.values,
 			    point, thresh_coords, thresh_snap,
 			    move_x, move_y, move_z,
-			    1, snap); 
+			    1, snap);
 
+    if (settings.breakLines && ret > 0) {
+	BreakLineAtIntersection(Vect_get_num_lines(display->mapInfo), NULL);
+    }
+
     /* TODO
     if (ret > 0) {
 	changesets[changesets.size()-1][0].line = Vect_get_num_lines(display->mapInfo);



More information about the grass-commit mailing list