Browse Source

wxGUI: optionally break added lines at each intersection

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32387 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 years ago
parent
commit
ccb6f3fb6d
2 changed files with 62 additions and 2 deletions
  1. 21 0
      gui/wxpython/gui_modules/vdigit.py
  2. 41 2
      gui/wxpython/vdigit/line.cpp

+ 21 - 0
gui/wxpython/gui_modules/vdigit.py

@@ -764,6 +764,10 @@ class VEdit(AbstractDigit):
                                                     "Use vdigit instead."),
                       caption=_("Message"), style=wx.ID_OK | wx.ICON_INFORMATION | wx.CENTRE)
 
+    def UpdateSettings(self):
+        """Update digit settigs"""
+        pass
+    
 class VDigit(AbstractDigit):
     """
     Prototype of digitization class based on v.digit reimplementation
@@ -785,6 +789,8 @@ class VDigit(AbstractDigit):
 
         self.toolbar = mapwindow.parent.toolbars['vdigit']
 
+        self.UpdateSettings()
+        
     def __del__(self):
         del self.digit
         
@@ -1189,6 +1195,11 @@ class VDigit(AbstractDigit):
     def GetUndoLevel(self):
         """Get undo level (number of active changesets)"""
         return self.digit.GetUndoLevel()
+
+    def UpdateSettings(self):
+        """Update digit settigs"""
+        self.digit.UpdateSettings(UserSettings.Get(group='vdigit', key='breakLines',
+                                                   subkey='enabled'))
         
     def __getSnapThreshold(self):
         """Get snap mode and threshold value
@@ -1788,6 +1799,9 @@ class VDigitSettingsDialog(wx.Dialog):
 
         self.intersect = wx.CheckBox(parent=panel, label=_("Break lines on 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)
+        
         sizer.Add(item=self.intersect, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
 
         border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
@@ -2176,10 +2190,17 @@ class VDigitSettingsDialog(wx.Dialog):
         # on-exit
         UserSettings.Set(group='vdigit', key="saveOnExit", subkey='enabled',
                          value=self.save.IsChecked())
+
+        # break lines
+        UserSettings.Set(group='vdigit', key="breakLines", subkey='enabled',
+                         value=self.intersect.IsChecked())
         
         # update driver settings
         self.parent.digit.driver.UpdateSettings()
 
+        # update digit settings
+        self.parent.digit.UpdateSettings()
+        
         # redraw map if auto-rendering is enabled
         if self.parent.autoRender.GetValue(): 
             self.parent.OnRender(None)

+ 41 - 2
gui/wxpython/vdigit/line.cpp

@@ -126,7 +126,46 @@ int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
 
     /* break on intersection */
     if (settings.breakLines) {
-	// TODO
+	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);
     }
     
     /* register changeset */
@@ -586,7 +625,7 @@ int Digit::BreakLines()
 	AddActionToChangeset(changeset, DELETE, display->selected->value[i]);
     }
 
-    ret = Vect_break_lines_list(display->mapInfo, display->selected,
+    ret = Vect_break_lines_list(display->mapInfo, display->selected, NULL,
 				GV_LINES, NULL, NULL);
 
     if (ret > 0) {