[GRASS-SVN] r33388 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 10 11:41:39 EDT 2008


Author: martinl
Date: 2008-09-10 11:41:39 -0400 (Wed, 10 Sep 2008)
New Revision: 33388

Modified:
   grass/trunk/gui/wxpython/gui_modules/dbm.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp.py
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
Log:
wxGUI: fix display attributes dialog to display duplicated features
(merge from devbr6, r33387)


Modified: grass/trunk/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-09-10 15:28:10 UTC (rev 33387)
+++ grass/trunk/gui/wxpython/gui_modules/dbm.py	2008-09-10 15:41:39 UTC (rev 33388)
@@ -2732,10 +2732,10 @@
         self.action = action
 
         # ids/cats of selected features
-        self.line = {}
-        self.line['id'] = None
-        self.line['cats'] = None
-
+        # fid : {layer : cats}
+        self.cats = {}
+        self.fid = -1 # feature id
+        
         # get layer/table/column information
         self.mapDBInfo = VectorDBInfo(self.map)
         
@@ -2769,8 +2769,17 @@
                                        label=_("Close dialog on submit"))
         self.closeDialog.SetValue(True)
 
-        self.UpdateDialog(query=query, cats=cats, line=line)
+        # feature id (text/choice for duplicates)
+        self.fidMulti = wx.Choice(parent=self, id=wx.ID_ANY,
+                                  size=(150, -1))
+        self.fidMulti.Bind(wx.EVT_CHOICE, self.OnFeature)
+        self.fidText = wx.StaticText(parent=self, id=wx.ID_ANY)
 
+        self.noFoundMsg = wx.StaticText(parent=self, id=wx.ID_ANY,
+                                        label=_("No attributes found"))
+        
+        self.UpdateDialog(query=query, cats=cats)
+
         # set title
         if self.action == "update":
             self.SetTitle(_("Update attributes"))
@@ -2792,7 +2801,21 @@
         btnSizer.AddButton(btnSubmit)
         btnSizer.Realize()
 
-        mainSizer.Add(item=self.notebook, proportion=1, flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item=self.noFoundMsg, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item=self.notebook, proportion=1,
+                      flag=wx.EXPAND | wx.ALL, border=5)
+        fidSizer = wx.BoxSizer(wx.HORIZONTAL)
+        fidSizer.Add(item=wx.StaticText(parent=self, id=wx.ID_ANY,
+                                        label=_("Feature id:")),
+                     proportion=0, border=5,
+                     flag=wx.ALIGN_CENTER_VERTICAL)
+        fidSizer.Add(item=self.fidMulti, proportion=0,
+                     flag=wx.EXPAND | wx.ALL,  border=5)
+        fidSizer.Add(item=self.fidText, proportion=0,
+                     flag=wx.EXPAND | wx.ALL,  border=5)
+        mainSizer.Add(item=fidSizer, proportion=0,
+                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5)
         mainSizer.Add(item=self.closeDialog, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT,
                       border=5)
         mainSizer.Add(item=btnSizer, proportion=0,
@@ -2943,17 +2966,25 @@
         if self.closeDialog.IsChecked():
             self.OnCancel(event)
 
-    def GetLine(self, id=True):
+    def OnFeature(self, event):
+        self.fid = int(event.GetString())
+        self.UpdateDialog(cats=self.cats, fid=self.fid)
+        
+    def GetCats(self):
         """Get id of selected vector object or 'None' if nothing selected
 
         @param id if true return ids otherwise cats
         """
-        if id:
-            return self.line['id']
+        if self.fid < 0:
+            return None
+        
+        return self.cats[self.fid]
 
-        return self.line['cats']
-
-    def UpdateDialog(self, map=None, query=None, cats=None, line=None):
+    def GetFid(self):
+        """Get selected feature id"""
+        return self.fid
+    
+    def UpdateDialog(self, map=None, query=None, cats=None, fid=-1):
         """Update dialog
 
         Return True if updated otherwise False
@@ -2962,9 +2993,6 @@
             self.map = map
             # get layer/table/column information
             self.mapDBInfo = VectorDBInfo(self.map)
-            
-        self.line['id'] = (line, )
-        self.line['cats'] = cats
         
         if not self.mapDBInfo:
             return False
@@ -2977,36 +3005,53 @@
         if query: # select by position
             data = self.mapDBInfo.SelectByPoint(query[0],
                                                 query[1])
+            self.cats = {}
             if data and data.has_key('Layer'):
-                self.line['id'] = (-1,)
-                self.line['cats'] = {}
                 idx = 0
-                for l in data['Layer']:
-                    layer = int(l)
-                    if not self.line['cats'].has_key(layer):
-                        self.line['cats'][layer] = []
-                        
-                    self.line['cats'][layer].append(int(data['Category'][idx]))
+                for layer in data['Layer']:
+                    layer = int(layer)
+                    tfid = int(data['Id'][idx])
+                    if not self.cats.has_key(tfid):
+                        self.cats[tfid] = {}
+                    if not self.cats[tfid].has_key(layer):
+                        self.cats[tfid][layer] = []
+                    cat = int(data['Category'][idx])
+                    self.cats[tfid][layer].append(cat)
                     idx += 1
-                
-                nselected = len(self.line['cats'].keys())
-                
-            else:
-                self.line['id'] = None
-                self.line['cats'] = None
-                nselected = 0
+        else:
+            self.cats = cats
+
+        if fid > 0:
+            self.fid = fid
+        elif len(self.cats.keys()) > 0:
+            self.fid = self.cats.keys()[0]
+        else:
+            self.fid = -1
         
+        if len(self.cats.keys()) == 1:
+            self.fidMulti.Show(False)
+            self.fidText.Show(True)
+            self.fidText.SetLabel("%d" % self.fid)
+        else:
+            self.fidMulti.Show(True)
+            self.fidText.Show(False)
+            choices = []
+            for tfid in self.cats.keys():
+                choices.append(str(tfid))
+            self.fidMulti.SetItems(choices)
+            self.fidMulti.SetStringSelection(str(self.fid))
+        
         # reset notebook
         self.notebook.DeleteAllPages()
 
         for layer in layers: # for each layer
             if not query: # select by layer/cat
-                if cats.has_key(layer): 
-                    for cat in cats[layer]:
+                if self.fid > 0 and self.cats[self.fid].has_key(layer): 
+                    for cat in self.cats[self.fid][layer]:
                         nselected = self.mapDBInfo.SelectFromTable(layer,
                                                                    where="%s=%d" % \
-                                                                       (self.mapDBInfo.layers[layer]['key'],
-                                                                        cat))
+                                                                   (self.mapDBInfo.layers[layer]['key'],
+                                                                    cat))
                 else:
                     nselected = 0
 
@@ -3015,13 +3060,13 @@
 
             if self.action == "add":
                 if nselected <= 0:
-                    if cats.has_key(layer):
+                    if self.cats[self.fid].has_key(layer):
                         table = self.mapDBInfo.layers[layer]["table"]
                         key = self.mapDBInfo.layers[layer]["key"]
                         columns = self.mapDBInfo.tables[table]
                         for name in columns.keys():
                             if name == key:
-                                for cat in cats[layer]:
+                                for cat in self.cats[self.fid][layer]:
                                     self.mapDBInfo.tables[table][name]['values'].append(cat)
                             else:
                                 self.mapDBInfo.tables[table][name]['values'].append(None)
@@ -3031,23 +3076,7 @@
             table   = self.mapDBInfo.layers[layer]["table"]
             key   = self.mapDBInfo.layers[layer]["key"]
             columns = self.mapDBInfo.tables[table]
-
-            # value
-            #             if len(columns[key]['values']) == 0: # no cats
-            #                 self.notebook.AddPage(page=panel, text=" %s %d / %s %d" % (_("Layer"), layer,
-            #                                                                            _("Category"), cat))
             
-            #                 sizer  = wx.BoxSizer(wx.VERTICAL)
-            #                 txt = wx.StaticText(parent=panel, id=wx.ID_ANY,
-            #                                     label=_("No database record available."))
-            #                 sizer.Add(txt, proportion=1,
-            #                           flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER | wx.EXPAND)
-            #                 border.Add(item=sizer, proportion=1,
-            #                            flag=wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
-            #                            border=10)
-            #                 panel.SetSizer(border)
-            #                 continue
-            
             for idx in range(len(columns[key]['values'])):
                 for name in columns.keys():
                     if name == key:
@@ -3108,17 +3137,15 @@
             # for each category END
         # for each layer END
 
+        if self.notebook.GetPageCount() == 0:
+            self.noFoundMsg.Show(True)
+        else:
+            self.noFoundMsg.Show(False)
+        
         self.Layout()
         
         return True
-
-    def IsFound(self):
-        """Check if attributes found"""
-        if self.notebook.GetPageCount() > 0:
-            return True
         
-        return False
-        
 class VectorDBInfo(gselect.VectorDBInfo):
     """Class providing information about attribute tables
     linked to the vector map"""

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-09-10 15:28:10 UTC (rev 33387)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py	2008-09-10 15:41:39 UTC (rev 33388)
@@ -1201,48 +1201,49 @@
             elif digitToolbar.GetAction() in ["displayAttrs", "displayCats"]:
                 qdist = digitClass.driver.GetThreshold(type='selectThresh')
                 coords = (east, north)
+                if digitClass.type == 'vdigit':
+                    # unselect
+                    digitClass.driver.SetSelected([])
+
+                    # select feature by point
+                    cats = {}
+                    if digitClass.driver.SelectLineByPoint(coords,
+                                                        digitClass.GetSelectType()) is not None:
+                        if UserSettings.Get(group='vdigit', key='checkForDupl',
+                                            subkey='enabled'):
+                            lines = digitClass.driver.GetSelected()
+                        else:
+                            lines = (digitClass.driver.GetSelected()[0],) # only first found
+                        
+                        for line in lines:
+                            cats[line] = digitClass.GetLineCats(line)
+                    
                 if digitToolbar.GetAction() == "displayAttrs":
                     # select attributes based on coordinates (all layers)
                     if self.parent.dialogs['attributes'] is None:
                         if digitClass.type == 'vedit':
                             self.parent.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self, map=map,
-                                                                                       query=(coords, qdist),
-                                                                                       pos=posWindow,
-                                                                                       action="update")
+                                                                                            query=(coords, qdist),
+                                                                                            pos=posWindow,
+                                                                                            action="update")
                         else:
-                            if digitClass.driver.SelectLineByPoint(coords,
-                                                                   digitClass.GetSelectType()) is not None:
-                                self.parent.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self, map=map,
-                                                                                                cats=digitClass.GetLineCats(),
-                                                                                                line=digitClass.driver.GetSelected()[0],
-                                                                                                action="update")
-
+                            self.parent.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self, map=map,
+                                                                                            cats=cats,
+                                                                                            action="update")
                     else:
                         # update currently open dialog
                         if digitClass.type == 'vedit':
                             self.parent.dialogs['attributes'].UpdateDialog(query=(coords, qdist))
                         else:
-                            # unselect
-                            digitClass.driver.SetSelected([])
-                            # select new feature
-                            if digitClass.driver.SelectLineByPoint(coords,
-                                                                   digitClass.GetSelectType()) is None:
-                                line = None
-                            else:
-                                line = digitClass.driver.GetSelected()[0]
                             # upgrade dialog
-                            self.parent.dialogs['attributes'].UpdateDialog(cats=digitClass.GetLineCats(),
-                                                                           line=line)
+                            self.parent.dialogs['attributes'].UpdateDialog(cats=cats)
 
                     if self.parent.dialogs['attributes']:
-                        if self.parent.dialogs['attributes'].IsFound():
+                        if len(cats.keys()) > 0:
                             # highlight feature & re-draw map
-                            line = self.parent.dialogs['attributes'].GetLine()
-                            digitClass.driver.SetSelected(line)
                             if not self.parent.dialogs['attributes'].IsShown():
                                 self.parent.dialogs['attributes'].Show()
                         else:
-                            digitClass.driver.SetSelected([])
                             if self.parent.dialogs['attributes'] and \
                                    self.parent.dialogs['attributes'].IsShown():
                                 self.parent.dialogs['attributes'].Hide()
@@ -1258,61 +1259,30 @@
                                                         title=_("Update categories"))
                             self.parent.dialogs['category'] = dlg
                         else:
-                            if digitClass.driver.SelectLineByPoint(coords,
-                                                                   digitClass.GetSelectType()) is not None:
-                                if UserSettings.Get(group='vdigit', key='checkForDupl',
-                                                    subkey='enabled'):
-                                    lines = digitClass.driver.GetSelected()
-                                else:
-                                    lines = (digitClass.driver.GetSelected()[0],) # only first found
-                                
-                                cats = {}
-                                for line in lines:
-                                    cats[line] = digitClass.GetLineCats(line)
-                                
-                                dlg = VDigitCategoryDialog(parent=self,
-                                                           map=map,
-                                                           cats=cats,
-                                                           pos=posWindow,
-                                                           title=_("Update categories"))
-                                self.parent.dialogs['category'] = dlg
+                            dlg = VDigitCategoryDialog(parent=self,
+                                                       map=map,
+                                                       cats=cats,
+                                                       pos=posWindow,
+                                                       title=_("Update categories"))
+                            self.parent.dialogs['category'] = dlg
                     else:
                         # update currently open dialog
                         if digitClass.type == 'vedit':
                             self.parent.dialogs['category'].UpdateDialog(query=(coords, qdist))
                         else:
-                            # unselect
-                            digitClass.driver.SetSelected([])
-                            # select new feature
-                            if digitClass.driver.SelectLineByPoint(coords,
-                                                                   digitClass.GetSelectType()):
-                                if UserSettings.Get(group='vdigit', key='checkForDupl',
-                                                    subkey='enabled'):
-                                    lines = digitClass.driver.GetSelected()
-                                else:
-                                    lines = (digitClass.driver.GetSelected()[0],) # only first found
-                                
-                                cats = {}
-                                for line in lines:
-                                    cats[line] = digitClass.GetLineCats(line)
-                                
-                                # upgrade dialog
-                                self.parent.dialogs['category'].UpdateDialog(cats=cats)
-                            else:
-                                line = None
+                            # upgrade dialog
+                            self.parent.dialogs['category'].UpdateDialog(cats=cats)
                             
                     if self.parent.dialogs['category']:
-                        line = self.parent.dialogs['category'].GetLine()
-                        if line:
+                        if len(cats.keys()) > 0:
                             # highlight feature & re-draw map
                             ### digitClass.driver.SetSelected(line)
                             if not self.parent.dialogs['category'].IsShown():
                                 self.parent.dialogs['category'].Show()
                         else:
-                            digitClass.driver.SetSelected([])
                             if self.parent.dialogs['category'].IsShown():
                                 self.parent.dialogs['category'].Hide()
-
+                
                 self.UpdateMap(render=False)
 
             elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
@@ -3459,7 +3429,7 @@
             else:
                 self.dialogs['attributes'].UpdateDialog(query=((east, north), qdist))
 
-        cats = self.dialogs['attributes'].GetLine(id=False)
+        cats = self.dialogs['attributes'].GetCats()
         try:
             qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)[0]
         except IndexError:
@@ -3475,7 +3445,6 @@
                 self.AddTmpVectorMapLayer(mapName, cats, useId=False)
 
             self.MapWindow.UpdateMap(render=False, renderVector=False)
-            # digitClass.driver.SetSelected([line])
             if not self.dialogs['attributes'].IsShown():
                 self.dialogs['attributes'].Show()
         else:

Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-09-10 15:28:10 UTC (rev 33387)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2008-09-10 15:41:39 UTC (rev 33388)
@@ -2474,7 +2474,7 @@
             catNew = int(event.GetLabel())
 
         try:
-            if layerNew not in self.cats.keys():
+            if layerNew not in self.cats[self.fid].keys():
                 self.cats[layerNew] = []
             self.cats[layerNew].append(catNew)
             self.cats[layerOld].remove(catOld)
@@ -2485,7 +2485,7 @@
             dlg = wx.MessageDialog(self, _("Unable to add new layer/category <%(layer)s/%(category)s>.\n"
                                            "Layer and category number must be integer.\n"
                                            "Layer number must be greater then zero.") %
-                                   { 'layer': str(self.layerNew.GetValue()),
+                                   { 'layer': self.layerNew.GetStringSelection(),
                                      'category' : str(self.catNew.GetValue()) },
                                    _("Error"), wx.OK | wx.ICON_ERROR)
             dlg.ShowModal()



More information about the grass-commit mailing list