[GRASS-SVN] r67751 - in grass/trunk/gui/wxpython: gui_core mapdisp

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 6 12:37:28 PST 2016


Author: martinl
Date: 2016-02-06 12:37:27 -0800 (Sat, 06 Feb 2016)
New Revision: 67751

Modified:
   grass/trunk/gui/wxpython/gui_core/vselect.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
Log:
wxGUI: hightlight queried features (patch by krejcmat)


Modified: grass/trunk/gui/wxpython/gui_core/vselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/vselect.py	2016-02-06 20:21:12 UTC (rev 67750)
+++ grass/trunk/gui/wxpython/gui_core/vselect.py	2016-02-06 20:37:27 UTC (rev 67751)
@@ -371,6 +371,9 @@
         self.data['Category'] = cats
 
     def Clear(self):
+        self.data['Category'] = list()
+        self.data['Map'] = None
+        self.data['Layer']= None
         self.mapdisp.RemoveQueryLayer()
         self.giface.GetMapWindow().UpdateMap(render = False)
 

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2016-02-06 20:21:12 UTC (rev 67750)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2016-02-06 20:37:27 UTC (rev 67751)
@@ -9,7 +9,7 @@
 Classes:
  - mapdisp::MapFrame
 
-(C) 2006-2014 by the GRASS Development Team
+(C) 2006-2016 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.
@@ -53,7 +53,7 @@
     MeasureAreaController
 from gui_core.forms import GUI
 from core.giface import Notification
-from gui_core.vselect import VectorSelectBase
+from gui_core.vselect import VectorSelectBase, VectorSelectHighlighter
 
 from mapdisp import statusbar as sb
 
@@ -203,6 +203,8 @@
         # initialize layers to query (d.what.vect/rast)
         self._vectQueryLayers = []
         self._rastQueryLayers = []
+        # initialize highlighter for vector features
+        self._highlighter_layer = None
 
         self.measureController = None
 
@@ -891,6 +893,8 @@
         """
         Debug.msg(1, "QueryMap(): raster=%s vector=%s" % (','.join(rast),
                                                           ','.join(vect)))
+        if self._highlighter_layer is None:
+            self._highlighter_layer = VectorSelectHighlighter(mapdisp=self._giface.GetMapDisplay(), giface=self._giface)
 
         # use display region settings instead of computation region settings
         self.tmpreg = os.getenv("GRASS_REGION")
@@ -910,7 +914,9 @@
                        message=_("Failed to query vector map(s) <{maps}>. "
                                  "Check database settings and topology.").format(maps=','.join(vect)))
         self._QueryMapDone()
-        if 'Id' in vectQuery:
+
+        self._highlighter_layer.Clear()
+        if 'Category' in vectQuery[0]:
             self._queryHighlight(vectQuery)
 
         result = rastQuery + vectQuery
@@ -928,6 +934,8 @@
         self.dialogs['query'] = None
         self._vectQueryLayers = []
         self._rastQueryLayers = []
+        self._highlighter_layer.Clear()
+        self._highlighter_layer = None
         event.Skip()
 
     def _onRedirectQueryOutput(self, output, style='log'):
@@ -939,37 +947,16 @@
 
     def _queryHighlight(self, vectQuery):
         """Highlight category from query."""
-        cats = name = None
-        for res in vectQuery:
-            cats = {res['Layer']: [res['Category']]}
-            name = res['Map']
-        try:
-            qlayer = self.Map.GetListOfLayers(name = globalvar.QUERYLAYER)[0]
-        except IndexError:
-            qlayer = None
+        if len(vectQuery) > 0:
+            self._highlighter_layer.SetLayer(vectQuery[0]['Layer'])
+            self._highlighter_layer.SetMap(vectQuery[0]['Map'])
+            tmp = list()
+            for i in vectQuery:
+                tmp.append(i['Category'])
 
-        if not (cats and name):
-            if qlayer:
-                self.Map.DeleteLayer(qlayer)
-                self.MapWindow.UpdateMap(render = False, renderVector = False)
-            return
+            self._highlighter_layer.SetCats(tmp)
+            self._highlighter_layer.DrawSelected()
 
-        if not self.IsPaneShown('3d') and self.IsAutoRendered():
-            # highlight feature & re-draw map
-            if qlayer:
-                qlayer.SetCmd(self.AddTmpVectorMapLayer(name, cats,
-                                                        useId = False,
-                                                        addLayer = False))
-            else:
-                qlayer = self.AddTmpVectorMapLayer(name, cats, useId = False)
-            
-            # set opacity based on queried layer
-            # TODO fix
-            # opacity = layer.maplayer.GetOpacity(float = True)
-            # qlayer.SetOpacity(opacity)
-            
-            self.MapWindow.UpdateMap(render = False, renderVector = False)
-
     def _QueryMapDone(self):
         """Restore settings after querying (restore GRASS_REGION)
         """



More information about the grass-commit mailing list