浏览代码

wxGUI/vdigit: update connect lines tool

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@32289 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 16 年之前
父节点
当前提交
87f90c0a3e

+ 5 - 11
gui/wxpython/gui_modules/mapdisp.py

@@ -1285,13 +1285,6 @@ class BufferedWindow(MapWindow, wx.Window):
                     begin = self.Pixel2Cell(self.mouse['begin'])
                     begin = self.Pixel2Cell(self.mouse['begin'])
 
 
                     self.DrawLines(self.pdcTmp, begin, end)
                     self.DrawLines(self.pdcTmp, begin, end)
-            elif digitToolbar.action == "connectLine":
-                if len(digitClass.driver.GetSelected()) > 1:
-                    # if two line selected -> reset
-                    digitClass.driver.SetSelected([])
-                digitClass.driver.SelectLineByPoint(self.Pixel2Cell(self.mouse['begin']),
-                                                    digitClass.GetSelectType())
-
         else:
         else:
             # get decoration id
             # get decoration id
             self.lastpos = self.mouse['begin']
             self.lastpos = self.mouse['begin']
@@ -1385,7 +1378,7 @@ class BufferedWindow(MapWindow, wx.Window):
             if digitToolbar.action in ["deleteLine", "moveLine", "moveVertex",
             if digitToolbar.action in ["deleteLine", "moveLine", "moveVertex",
                                        "copyCats", "editLine", "flipLine",
                                        "copyCats", "editLine", "flipLine",
                                        "mergeLine", "snapLine",
                                        "mergeLine", "snapLine",
-                                       "queryLine", "breakLine", "typeConv"]:
+                                       "queryLine", "breakLine", "typeConv", "connectLine"]:
                 nselected = 0
                 nselected = 0
                 # -> delete line || move line || move vertex
                 # -> delete line || move line || move vertex
                 if digitToolbar.action in ["moveVertex", "editLine"]:
                 if digitToolbar.action in ["moveVertex", "editLine"]:
@@ -1469,11 +1462,12 @@ class BufferedWindow(MapWindow, wx.Window):
                     else:
                     else:
                         nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
                         nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
                                                                        digitClass.GetSelectType())
                                                                        digitClass.GetSelectType())
+                        
                         if nselected == 0:
                         if nselected == 0:
                             if digitClass.driver.SelectLineByPoint(pos1,
                             if digitClass.driver.SelectLineByPoint(pos1,
                                                                    digitClass.GetSelectType()) is not None:
                                                                    digitClass.GetSelectType()) is not None:
                                 nselected = 1
                                 nselected = 1
-
+                        
                 if nselected > 0:
                 if nselected > 0:
                     if digitToolbar.action in ["moveLine", "moveVertex"]:
                     if digitToolbar.action in ["moveLine", "moveVertex"]:
                         # get pseudoDC id of objects which should be redrawn
                         # get pseudoDC id of objects which should be redrawn
@@ -1797,7 +1791,7 @@ class BufferedWindow(MapWindow, wx.Window):
             elif digitToolbar.action == "snapLine":
             elif digitToolbar.action == "snapLine":
                 digitClass.SnapLine()
                 digitClass.SnapLine()
             elif digitToolbar.action == "connectLine":
             elif digitToolbar.action == "connectLine":
-                if len(digitClass.driver.GetSelected()) == 2:
+                if len(digitClass.driver.GetSelected()) > 1:
                     digitClass.ConnectLine()
                     digitClass.ConnectLine()
             elif digitToolbar.action == "copyLine":
             elif digitToolbar.action == "copyLine":
                 digitClass.CopyLine(self.copyIds)
                 digitClass.CopyLine(self.copyIds)
@@ -2829,7 +2823,7 @@ class MapFrame(wx.Frame):
                     self.MapWindow.mouse['box'] = 'line'
                     self.MapWindow.mouse['box'] = 'line'
             elif self.toolbars['vdigit'].action in ['addVertex', 'removeVertex', 'splitLine',
             elif self.toolbars['vdigit'].action in ['addVertex', 'removeVertex', 'splitLine',
                                          'editLine', 'displayCats', 'displayAttrs',
                                          'editLine', 'displayCats', 'displayAttrs',
-                                         'copyCats', 'connectLine']:
+                                         'copyCats']:
                 self.MapWindow.mouse['box'] = 'point'
                 self.MapWindow.mouse['box'] = 'point'
             else: # moveLine, deleteLine
             else: # moveLine, deleteLine
                 self.MapWindow.mouse['box'] = 'box'
                 self.MapWindow.mouse['box'] = 'box'

+ 4 - 0
gui/wxpython/gui_modules/preferences.py

@@ -284,6 +284,10 @@ class Settings:
                 'saveOnExit' : {
                 'saveOnExit' : {
                     'enabled' : False
                     'enabled' : False
                     },
                     },
+                # break lines on intersection
+                'breakLines' : {
+                    'enabled' : False,
+                    },
                 },
                 },
             'profile': {
             'profile': {
                 'raster0' : {
                 'raster0' : {

+ 2 - 2
gui/wxpython/gui_modules/toolbars.py

@@ -672,7 +672,7 @@ class VDigitToolbar(AbstractToolbar):
         toolMenu.AppendItem(snap)
         toolMenu.AppendItem(snap)
         self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
         self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
 
 
-        connect = wx.MenuItem(toolMenu, wx.ID_ANY, _('Connect two selected lines/boundaries'))
+        connect = wx.MenuItem(toolMenu, wx.ID_ANY, _('Connect selected lines/boundaries'))
         toolMenu.AppendItem(connect)
         toolMenu.AppendItem(connect)
         self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
         self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
 
 
@@ -727,7 +727,7 @@ class VDigitToolbar(AbstractToolbar):
         """Connect selected lines/boundaries"""
         """Connect selected lines/boundaries"""
         Debug.msg(2, "Digittoolbar.OnConnect():")
         Debug.msg(2, "Digittoolbar.OnConnect():")
         self.action="connectLine"
         self.action="connectLine"
-        self.parent.MapWindow.mouse['box'] = 'point'
+        self.parent.MapWindow.mouse['box'] = 'box'
 
 
     def OnQuery(self, event):
     def OnQuery(self, event):
         """Query selected lines/boundaries"""
         """Query selected lines/boundaries"""

+ 45 - 33
gui/wxpython/gui_modules/vdigit.py

@@ -1,35 +1,34 @@
 """
 """
-MODULE: vdigit
-
-CLASSES:
- * AbstractDigit 
- * VEdit
- * VDigit
- * AbstractDisplayDriver
- * CDisplayDriver
- * VDigitSettingsDialog
- * VDigitCategoryDialog
- * VDigitZBulkDialog
- * VDigitDuplicatesDialog
-
-PURPOSE: Vector digitization tool for wxPython GUI
-
-         Note: Initial version under development
-
-         Progress:
-          (1) v.edit called on the background (class VEdit)
-          (2) Reimplentation of v.digit (VDigit)
-
-         Import:
-          from vdigit import VDigit as VDigit
-          
-AUTHORS: The GRASS Development Team
-         Martin Landa <landa.martin gmail.com>
-
-COPYRIGHT: (C) 2007-2008 by the GRASS Development Team
-           This program is free software under the GNU General Public
-           License (>=v2). Read the file COPYING that comes with GRASS
-           for details.
+@package vdigit
+
+@brief Vector digitizer extension
+
+Progress:
+ (1) v.edit called on the background (class VEdit)
+ (2) Reimplentation of v.digit (VDigit)
+
+Import:
+
+  from vdigit import VDigit as VDigit
+
+Classes:
+ - AbstractDigit 
+ - VEdit
+ - VDigit
+ - AbstractDisplayDriver
+ - CDisplayDriver
+ - VDigitSettingsDialog
+ - VDigitCategoryDialog
+ - VDigitZBulkDialog
+ - VDigitDuplicatesDialog
+
+(C) 2007-2008 by the GRASS Development Team
+
+This program is free software under the GNU General Public
+License (>=v2). Read the file COPYING that comes with GRASS
+for details.
+
+@author Martin Landa <landa.martin gmail.com>
 """
 """
 
 
 import os
 import os
@@ -1576,7 +1575,8 @@ class CDisplayDriver(AbstractDisplayDriver):
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[1],
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[2],
                                                 UserSettings.Get(group='vdigit', key='symbolDirection', subkey='color')[2],
                                                 255).GetRGB(),
                                                 255).GetRGB(),
-                                       UserSettings.Get(group='vdigit', key='lineWidth', subkey='value'))
+                                       UserSettings.Get(group='vdigit', key='lineWidth', subkey='value'),
+                                       UserSettings.Get(group='vdigit', key='breakLines', subkey='enabled'))
 
 
 class VDigitSettingsDialog(wx.Dialog):
 class VDigitSettingsDialog(wx.Dialog):
     """
     """
@@ -1781,12 +1781,24 @@ class VDigitSettingsDialog(wx.Dialog):
         border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
         border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
 
 
         #
         #
+        # digitize lines box
+        #
+        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.SetValue(UserSettings.Get(group='vdigit', key='breakLines', subkey='enabled'))
+        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)
+
+        #
         # save-on-exit box
         # save-on-exit box
         #
         #
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Save changes"))
         box   = wx.StaticBox (parent=panel, id=wx.ID_ANY, label=" %s " % _("Save changes"))
         # save changes on exit?
         # save changes on exit?
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
         sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-        self.save = wx.CheckBox(parent=panel, label=_("Save changes on exit automatically"))
+        self.save = wx.CheckBox(parent=panel, label=_("Save changes on exit"))
         self.save.SetValue(UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled'))
         self.save.SetValue(UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled'))
         sizer.Add(item=self.save, proportion=0, flag=wx.ALL | wx.EXPAND, border=1)
         sizer.Add(item=self.save, 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)
         border.Add(item=sizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)

+ 5 - 1
gui/wxpython/vdigit/driver.cpp

@@ -818,7 +818,7 @@ void DisplayDriver::UpdateSettings(unsigned long highlight,
 				   bool eVertex,      unsigned long cVertex,
 				   bool eVertex,      unsigned long cVertex,
 				   bool eArea,        unsigned long cArea,
 				   bool eArea,        unsigned long cArea,
 				   bool eDirection,   unsigned long cDirection,
 				   bool eDirection,   unsigned long cDirection,
-				   int lineWidth)
+				   int lineWidth, bool breakLines)
 {
 {
     settings.highlight.Set(highlight);
     settings.highlight.Set(highlight);
     
     
@@ -865,6 +865,10 @@ void DisplayDriver::UpdateSettings(unsigned long highlight,
     settings.direction.color.Set(cDirection);
     settings.direction.color.Set(cDirection);
 
 
     settings.lineWidth = lineWidth;
     settings.lineWidth = lineWidth;
+    
+    settings.breakLines = breakLines;
+
+    return;
 }
 }
 
 
 /**
 /**

+ 3 - 1
gui/wxpython/vdigit/driver.h

@@ -112,6 +112,8 @@ private:
 	symbol direction;
 	symbol direction;
 
 
 	int lineWidth;    // screen units 
 	int lineWidth;    // screen units 
+
+	bool breakLines;
     } settings;
     } settings;
 
 
     struct _topology {
     struct _topology {
@@ -212,7 +214,7 @@ public:
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
 			bool, unsigned long,
-			int);
+			int, bool);
 };
 };
 
 
 int print_error(const char *, int);
 int print_error(const char *, int);

+ 13 - 12
gui/wxpython/vdigit/line.cpp

@@ -82,11 +82,11 @@ int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
     Cats = Vect_new_cats_struct();
     Cats = Vect_new_cats_struct();
 
 
     if (layer > 0) {
     if (layer > 0) {
-      Vect_cat_set(Cats, layer, cat);
-
-      if (cat > GetCategory(layer)) {
-	  SetCategory(layer, cat); /* set up max category for layer */
-      }
+	Vect_cat_set(Cats, layer, cat);
+	
+	if (cat > GetCategory(layer)) {
+	    SetCategory(layer, cat); /* set up max category for layer */
+	}
     }
     }
 
 
     i = 0;
     i = 0;
@@ -124,6 +124,11 @@ int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
 	return -1;
 	return -1;
     }
     }
 
 
+    /* break on intersection */
+    if (settings.breakLines) {
+	// TODO
+    }
+    
     /* register changeset */
     /* register changeset */
     AddActionToChangeset(changesets.size(), ADD, newline);
     AddActionToChangeset(changesets.size(), ADD, newline);
 
 
@@ -629,10 +634,9 @@ int Digit::SnapLines(double thresh)
 }
 }
 
 
 /**
 /**
-   \brief Connect two selected lines/boundaries
+   \brief Connect selected lines/boundaries
 
 
-   \return 1 lines connected
-   \return 0 lines not connected
+   \return number of modified lines
    \return -1 on error
    \return -1 on error
 */
 */
 int Digit::ConnectLines(double thresh)
 int Digit::ConnectLines(double thresh)
@@ -644,9 +648,6 @@ int Digit::ConnectLines(double thresh)
 	return -1;
 	return -1;
     }
     }
 
 
-    if (display->selected->n_values != 2)
-	return 0;
-
     /* register changeset */
     /* register changeset */
     changeset = changesets.size();
     changeset = changesets.size();
     for (int i = 0; i < display->selected->n_values; i++) {
     for (int i = 0; i < display->selected->n_values; i++) {
@@ -658,7 +659,7 @@ int Digit::ConnectLines(double thresh)
     ret = Vedit_connect_lines(display->mapInfo, display->selected,
     ret = Vedit_connect_lines(display->mapInfo, display->selected,
 			      thresh);
 			      thresh);
 
 
-    if (ret == 1) {
+    if (ret > 0) {
 	nlines_diff = Vect_get_num_lines(display->mapInfo) - nlines_diff;
 	nlines_diff = Vect_get_num_lines(display->mapInfo) - nlines_diff;
 	for(int i = Vect_get_num_lines(display->mapInfo); i > nlines_diff; i--) {
 	for(int i = Vect_get_num_lines(display->mapInfo); i > nlines_diff; i--) {
 	    AddActionToChangeset(changeset, ADD, i);
 	    AddActionToChangeset(changeset, ADD, i);