Browse Source

wxGUI/wxIClass: various improvements related to class manager

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50310 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 13 years ago
parent
commit
890f082347
3 changed files with 95 additions and 3 deletions
  1. 55 2
      gui/wxpython/iclass/dialogs.py
  2. 15 0
      gui/wxpython/iclass/digit.py
  3. 25 1
      gui/wxpython/iclass/frame.py

+ 55 - 2
gui/wxpython/iclass/dialogs.py

@@ -190,6 +190,8 @@ class IClassCategoryManagerDialog(wx.Dialog):
         self.catList.DeleteCategory()
         self.catList.DeleteCategory()
         
         
     def OnClose(self, event):
     def OnClose(self, event):
+        self.catList.DeselectAll()
+        
         self.catList.UpdateChoice()
         self.catList.UpdateChoice()
         if not isinstance(event, wx.CloseEvent):
         if not isinstance(event, wx.CloseEvent):
             self.Destroy()
             self.Destroy()
@@ -227,11 +229,17 @@ class CategoryListCtrl(wx.ListCtrl,
         self.statisticsList = statisticsList
         self.statisticsList = statisticsList
         self.SetItemCount(len(statisticsList))
         self.SetItemCount(len(statisticsList))
         
         
+        self.rightClickedItemIdx = wx.NOT_FOUND
+        
         listmix.ListCtrlAutoWidthMixin.__init__(self)
         listmix.ListCtrlAutoWidthMixin.__init__(self)
 
 
         listmix.TextEditMixin.__init__(self)
         listmix.TextEditMixin.__init__(self)
         
         
         self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnEdit)
         self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnEdit)
+        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnCategorySelected)
+        
+        self.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnClassRightUp) #wxMSW
+        self.Bind(wx.EVT_RIGHT_UP,            self.OnClassRightUp) #wxGTK
         
         
     def SetVirtualData(self, row, column, text):
     def SetVirtualData(self, row, column, text):
         attr = self.columns[column][1]
         attr = self.columns[column][1]
@@ -240,6 +248,7 @@ class CategoryListCtrl(wx.ListCtrl,
         self.UpdateChoice()
         self.UpdateChoice()
         toolbar = self.mapWindow.toolbars['iClass']
         toolbar = self.mapWindow.toolbars['iClass']
         toolbar.choice.SetSelection(row)
         toolbar.choice.SetSelection(row)
+        self.Select(row)
         
         
         if attr == 'name':
         if attr == 'name':
             self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
             self.mapWindow.UpdateRasterName(text, toolbar.GetSelectedCategoryIdx())
@@ -271,20 +280,22 @@ class CategoryListCtrl(wx.ListCtrl,
                 
                 
     def DeleteCategory(self):
     def DeleteCategory(self):
         indexList = sorted(self.GetSelectedIndices(), reverse = True)
         indexList = sorted(self.GetSelectedIndices(), reverse = True)
+        cats = []
         for i in indexList:
         for i in indexList:
             # remove temporary raster
             # remove temporary raster
             name = self.statisticsDict[self.statisticsList[i]].rasterName
             name = self.statisticsDict[self.statisticsList[i]].rasterName
             self.mapWindow.RemoveTempRaster(name)
             self.mapWindow.RemoveTempRaster(name)
             
             
+            cats.append(self.statisticsList[i])
             del self.statisticsDict[self.statisticsList[i]]
             del self.statisticsDict[self.statisticsList[i]]
             del self.statisticsList[i]
             del self.statisticsList[i]
+            
         self.SetItemCount(len(self.statisticsList))
         self.SetItemCount(len(self.statisticsList))
         
         
         self.UpdateChoice()
         self.UpdateChoice()
         self.mapWindow.UpdateChangeState(changes = True)
         self.mapWindow.UpdateChangeState(changes = True)
         
         
-        
-        # delete vector items!
+        self.mapWindow.DeleteAreas(cats = cats)
     
     
     def UpdateChoice(self):
     def UpdateChoice(self):
         toolbar = self.mapWindow.toolbars['iClass']
         toolbar = self.mapWindow.toolbars['iClass']
@@ -331,6 +342,48 @@ class CategoryListCtrl(wx.ListCtrl,
             
             
         event.Skip()
         event.Skip()
         
         
+    def OnCategorySelected(self, event):
+        """!Highlight selected areas"""
+        indexList = self.GetSelectedIndices()
+        cats = []
+        for i in indexList:
+            cats.append(self.statisticsList[i])
+        
+        self.mapWindow.HighlightCategory(cats)
+        if event:
+            event.Skip()
+        
+    def OnClassRightUp(self, event):
+        """!Show context menu on right click"""
+        item, flags = self.HitTest((event.GetX(), event.GetY()))
+        if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM:
+            self.rightClickedItemIdx = item
+            
+        self.popupZoomtoAreas = wx.NewId()
+
+        self.Bind(wx.EVT_MENU, self.OnZoomToAreasByCat, id = self.popupZoomtoAreas)
+
+        # generate popup-menu
+        menu = wx.Menu()
+        menu.Append(self.popupZoomtoAreas, _("Zoom to training areas of selected class"))
+        
+        self.PopupMenu(menu)
+        menu.Destroy()
+    
+    def OnZoomToAreasByCat(self, event):
+        """!Zoom to areas of given category"""
+        cat = self.statisticsList[self.rightClickedItemIdx]
+        self.mapWindow.ZoomToAreasByCat(cat)
+        
+    def DeselectAll(self):
+        """!Deselect all items"""
+        indexList = self.GetSelectedIndices()
+        for i in indexList:
+            self.Select(i, on = 0)
+         
+        # no highlight
+        self.OnCategorySelected(None)
+        
     def OnGetItemText(self, item, col):
     def OnGetItemText(self, item, col):
         cat = self.statisticsList[item]
         cat = self.statisticsList[item]
         return getattr(self.statisticsDict[cat], self.columns[col][1]) 
         return getattr(self.statisticsDict[cat], self.columns[col][1]) 

+ 15 - 0
gui/wxpython/iclass/digit.py

@@ -21,6 +21,11 @@ import wx
 from vdigit.mapwindow import VDigitWindow
 from vdigit.mapwindow import VDigitWindow
 from vdigit.wxdigit import IVDigit
 from vdigit.wxdigit import IVDigit
 
 
+try:
+    from grass.lib.vedit  import *
+except ImportError:
+    pass
+
 class IClassVDigitWindow(VDigitWindow):
 class IClassVDigitWindow(VDigitWindow):
     """! Class similar to VDigitWindow but specialized for wxIClass."""
     """! Class similar to VDigitWindow but specialized for wxIClass."""
     def __init__(self, parent, map):
     def __init__(self, parent, map):
@@ -86,3 +91,13 @@ class IClassVDigit(IVDigit):
     def _getNewFeaturesCat(self):
     def _getNewFeaturesCat(self):
         cat = self.mapWindow.GetCurrentCategory()
         cat = self.mapWindow.GetCurrentCategory()
         return cat
         return cat
+        
+    def DeleteAreasByCat(self, cats):
+        """!Delete areas (centroid+boundaries) by categories
+
+        @param cats list of categories
+        """
+        
+        for cat in cats:
+            Vedit_delete_areas_cat(self.poMapInfo, 1, cat)
+        

+ 25 - 1
gui/wxpython/iclass/frame.py

@@ -271,7 +271,7 @@ class IClassMapFrame(DoubleMapFrame):
                                                 digitClass = IClassVDigit,
                                                 digitClass = IClassVDigit,
                                                 tools = ['addArea', 'moveVertex', 'addVertex',
                                                 tools = ['addArea', 'moveVertex', 'addVertex',
                                                          'removeVertex', 'editLine',
                                                          'removeVertex', 'editLine',
-                                                         'moveLine', 'deleteLine'])
+                                                         'moveLine', 'deleteArea', 'undo', 'redo'])
             
             
             self._mgr.AddPane(self.toolbars[name],
             self._mgr.AddPane(self.toolbars[name],
                               wx.aui.AuiPaneInfo().
                               wx.aui.AuiPaneInfo().
@@ -437,6 +437,28 @@ class IClassMapFrame(DoubleMapFrame):
         if name:
         if name:
             self.previewMapManager.SelectLayer(name)
             self.previewMapManager.SelectLayer(name)
         
         
+    def DeleteAreas(self, cats):
+        """!Removes all training areas of given categories
+        
+        @param cats list of categories to be deleted
+        """
+        self.firstMapWindow.digit.DeleteAreasByCat(cats)
+        self.firstMapWindow.UpdateMap(render=False, renderVector=True)
+        
+    def HighlightCategory(self, cats):
+        """!Highlight araes given by category"""
+        self.firstMapWindow.digit.GetDisplay().SetSelected(cats, layer = 1)
+        self.firstMapWindow.UpdateMap(render=False, renderVector=True)
+        
+    def ZoomToAreasByCat(self, cat):
+        """!Zoom to areas given by category"""
+        n, s, w, e = self.GetFirstWindow().digit.GetDisplay().GetRegionSelected()
+        self.GetFirstMap().GetRegion(n = n, s = s, w = w, e = e, update = True)
+        self.GetFirstMap().AdjustRegion()
+        self.GetFirstMap().AlignExtentFromDisplay()
+        
+        self.GetFirstWindow().UpdateMap(render = True, renderVector = True)
+        
     def UpdateRasterName(self, newName, cat):
     def UpdateRasterName(self, newName, cat):
         """!Update alias of raster map when category name is changed"""
         """!Update alias of raster map when category name is changed"""
         origName = self.statisticsDict[cat].rasterName
         origName = self.statisticsDict[cat].rasterName
@@ -555,6 +577,8 @@ class IClassMapFrame(DoubleMapFrame):
                 # write statistics
                 # write statistics
                 I_iclass_add_signature(self.signatures, statistics)
                 I_iclass_add_signature(self.signatures, statistics)
             else:
             else:
+                GMessage(parent = self, message = _("Analysis failed. "
+                                                    "Check training areas and their categories."))
                 I_iclass_free_statistics(statistics)
                 I_iclass_free_statistics(statistics)
         
         
         self.UpdateChangeState(changes = False)
         self.UpdateChangeState(changes = False)