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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 3 11:16:24 EDT 2008


Author: martinl
Date: 2008-07-03 11:16:24 -0400 (Thu, 03 Jul 2008)
New Revision: 31982

Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
   grass/trunk/gui/wxpython/vdigit/driver.cpp
   grass/trunk/gui/wxpython/vdigit/driver.h
Log:
wxGUI/vdigit:
* 'edit line' tool fixed, trac #214
* avoid adding lines with number of vertices < 2 


Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-03 10:35:45 UTC (rev 31981)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-07-03 15:16:24 UTC (rev 31982)
@@ -234,7 +234,8 @@
         self.Bind(wx.EVT_IDLE,         self.OnIdle)
         self.Bind(wx.EVT_MOTION,       self.MouseActions)
         self.Bind(wx.EVT_MOUSE_EVENTS, self.MouseActions)
-
+        self.processMouse = True
+        
         #
         # Render output objects
         #
@@ -695,6 +696,7 @@
             self.Draw(self.pdc, img=self.textdict[id], drawid=id,
                       pdctype='text', coords=[10, 10, 10, 10])
 
+        # optionally draw computational extent box
         self.DrawCompRegionExtent()
 
         #
@@ -831,7 +833,7 @@
 
         """
         self.redrawAll = False
-
+        
         if not pdc:
             return
 
@@ -948,12 +950,16 @@
         """
         Mouse motion and button click notifier
         """
+        if not self.processMouse:
+            return
+        
         if self.redrawAll is False:
             self.redrawAll = True
-
+        
         wheel = event.GetWheelRotation()
         # zoom with mouse wheel
         if wheel != 0:
+            self.processMouse = False
             current  = event.GetPositionTuple()[:]
             Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
             # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
@@ -974,10 +980,12 @@
             self.UpdateMap()
 
             self.OnPaint(None)
-
+            
             # update statusbar
             self.parent.StatusbarUpdate()
 
+            self.processMouse = True
+            
         # left mouse button pressed
         elif event.LeftDown():
             self.OnLeftDown(event)
@@ -1029,6 +1037,7 @@
 
         elif event.Moving():
             self.OnMouseMoving(event)
+
         event.Skip()
 
     def OnLeftDown(self, event):
@@ -1374,24 +1383,37 @@
                     if len(digitClass.driver.GetSelected()) == 0:
                         nselected = digitClass.driver.SelectLineByPoint(pos1, type=VDigit_Lines_Type)
                         if digitToolbar.action == "editLine":
+                            try:
+                                selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
+                            except IndexError:
+                                selVertex = None
+
+                            if selVertex:
+                                # self.UpdateMap(render=False)
+                                ids = digitClass.driver.GetSelected(grassId=False)
+                                # move this line to tmp layer
+                                self.polycoords = []
+                                for id in ids:
+                                    if id % 2: # register only vertices
+                                        self.moveIds.append(id)
+                                        e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
+                                        self.polycoords.append((e, n))
+                                    # self.pdcVector.RemoveId(id)
+                                digitClass.driver.DrawSelected(False) 
+                                
+                                if selVertex < ids[-1] / 2:
+                                    # choose first or last node of line
+                                    self.moveIds.reverse()
+                                    self.polycoords.reverse()
+                            else:
+                                # unselect
+                                digitClass.driver.SetSelected([])
+                                del self.moveBegin
+                                del self.moveCoords
+                                del self.moveIds
+
                             self.UpdateMap(render=False)
-                            selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
-                            ids = digitClass.driver.GetSelected(grassId=False)
-                            # move this line to tmp layer
-                            self.polycoords = []
-                            for id in ids:
-                                if id % 2: # register only vertices
-                                    self.moveIds.append(id)
-                                    e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
-                                    self.polycoords.append((e, n))
-                                self.pdcVector.RemoveId(id)
-                            if selVertex < ids[-1] / 2:
-                                # choose first or last node of line
-                                self.moveIds.reverse()
-                                self.polycoords.reverse()
 
-                            self.UpdateMap(render=False, renderVector=False)
-
                 elif digitToolbar.action == "copyCats":
                     if not hasattr(self, "copyCatsIds"):
                         # collect categories
@@ -1698,6 +1720,10 @@
                         line = True
                     else:
                         line = False
+
+                    if len(self.polycoords) < 2: # ignore 'one-point' lines
+                        return
+                    
                     digitClass.AddLine(map, line, self.polycoords)
 
                     position = self.Cell2Pixel(self.polycoords[-1])
@@ -1817,7 +1843,8 @@
 
                 if digitToolbar.action == "editLine":
                     # remove last vertex & line
-                    self.moveIds.pop()
+                    if len(self.moveIds) > 1:
+                        self.moveIds.pop()
 
                 self.UpdateMap(render=False, renderVector=False)
 

Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-07-03 10:35:45 UTC (rev 31981)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-07-03 15:16:24 UTC (rev 31982)
@@ -970,6 +970,10 @@
         except:
             lineid = -1
 
+        if len(coords) < 2:
+            self.DeleteSelectedLines()
+            return 0
+            
         listCoords = []
         for c in coords:
             for x in c:
@@ -1483,7 +1487,11 @@
         """
 
         return self.__display.GetMapBoundingBox()
-    
+
+    def DrawSelected(self, draw=True):
+        """Show/hide selected features"""
+        self.__display.DrawSelected(draw)
+        
     def UpdateSettings(self):
         """Update display driver settings"""
         # TODO map units

Modified: grass/trunk/gui/wxpython/vdigit/driver.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-07-03 10:35:45 UTC (rev 31981)
+++ grass/trunk/gui/wxpython/vdigit/driver.cpp	2008-07-03 15:16:24 UTC (rev 31982)
@@ -168,7 +168,12 @@
 	else {
 	    pen = new wxPen(settings.highlight, settings.lineWidth, wxSOLID);
 	}
-	draw = true;
+	if (drawSelected) {
+	    draw = true;
+	}
+	else {
+	    draw = false;
+	}
 	dcId = 1;
 	topology.highlight++;
     }
@@ -314,6 +319,9 @@
 	dcId = 0;
     }
     else {
+	if (!drawSelected) {
+	    return -1;
+	}
 	if (settings.highlightDupl.enabled && IsDuplicated(line)) {
 	    pen = new wxPen(settings.highlightDupl.color, settings.lineWidth, wxSOLID);
 	}
@@ -390,6 +398,9 @@
 
 	// determine color
 	if (IsSelected(line)) {
+	    if (!drawSelected) {
+		return -1;
+	    }
 	    if (settings.highlightDupl.enabled && IsDuplicated(line)) {
 		pen = new wxPen(settings.highlightDupl.color, settings.lineWidth, wxSOLID);
 	    }
@@ -767,6 +778,7 @@
     struct line_pnts *bbox;
 
     drawSegments = false;
+    drawSelected = true;
 
     list = Vect_new_list();
     bbox = Vect_new_line_struct();
@@ -818,6 +830,8 @@
 
     std::vector<double> p;
 
+    drawSelected = true;
+
     line = Vect_find_line(mapInfo, x, y, z,
 			  type, thresh, with_z, 0);
 
@@ -965,6 +979,8 @@
 */
 int DisplayDriver::SetSelected(std::vector<int> id)
 {
+    drawSelected = true;
+
     VectorToList(selected, id);
 
     if (selected->n_values <= 0)
@@ -1205,3 +1221,15 @@
     
     return 0;
 }
+
+/**
+   \brief Draw selected features
+
+   \param draw if true draw selected features
+*/
+void DisplayDriver::DrawSelected(bool draw)
+{
+    drawSelected = draw;
+
+    return;
+}

Modified: grass/trunk/gui/wxpython/vdigit/driver.h
===================================================================
--- grass/trunk/gui/wxpython/vdigit/driver.h	2008-07-03 10:35:45 UTC (rev 31981)
+++ grass/trunk/gui/wxpython/vdigit/driver.h	2008-07-03 15:16:24 UTC (rev 31982)
@@ -57,6 +57,7 @@
 
     struct ilist *selected;
     struct ilist *selectedDupl;
+    bool drawSelected;
 
     bool drawSegments;         // draw segments of selected line
 
@@ -169,6 +170,7 @@
     int SetSelected(std::vector<int>);
     int UnSelect(std::vector<int>);
     std::vector<int> GetSelectedVertex(double, double, double);
+    void DrawSelected(bool);
 
     /* general */
     int CloseMap();



More information about the grass-commit mailing list