[GRASS-SVN] r69161 - grass/branches/releasebranch_7_0/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 19 03:47:59 PDT 2016


Author: martinl
Date: 2016-08-19 03:47:59 -0700 (Fri, 19 Aug 2016)
New Revision: 69161

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py
   grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/model.py
Log:
g.gui.gmodeler - not possible to remove data from model (trac #2947)
 wxGUI/gmodeler: avoid recursive deletion when undefining module parameters
               (merge r68155 and r68201 from trunk)


Modified: grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py	2016-08-19 10:24:04 UTC (rev 69160)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/frame.py	2016-08-19 10:47:59 UTC (rev 69161)
@@ -789,9 +789,12 @@
             x = width/2 - 200 + self._randomShift()
             y = height/2 + self._randomShift()
             for p in params['params']:
-                if p.get('prompt', '') in ('raster', 'vector', 'raster_3d', 'dbtable') and \
-                        (p.get('value', None) or \
-                             (p.get('age', 'old') != 'old' and p.get('required', 'no') == 'yes')):
+                if p.get('prompt', '') not in ('raster', 'vector', 'raster_3d', 'dbtable'):
+                    continue
+
+                # add new data item if defined or required
+                if p.get('value', None) or \
+                   (p.get('age', 'old') != 'old' and p.get('required', 'no') == 'yes'):
                     data = layer.FindData(p.get('name', ''))
                     if data:
                         data.SetValue(p.get('value', ''))
@@ -830,7 +833,19 @@
                     data.AddRelation(rel)
                     self.AddLine(rel)
                     data.Update()
+
+                # remove dead data items
+                if not p.get('value', ''):
+                    data = layer.FindData(p.get('name', ''))
+                    if data:
+                        remList, upList = self.model.RemoveItem(data, layer)
+                        for item in remList:
+                            self.canvas.diagram.RemoveShape(item)
+                            item.__del__()
             
+                        for item in upList:
+                            item.Update()
+
             # valid / parameterized ?
             layer.SetValid(params)
             

Modified: grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/model.py	2016-08-19 10:24:04 UTC (rev 69160)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gmodeler/model.py	2016-08-19 10:47:59 UTC (rev 69161)
@@ -192,16 +192,18 @@
         """Reset model"""
         self.items = list()
 
-    def RemoveItem(self, item):
+    def RemoveItem(self, item, reference=None):
         """Remove item from model
         
+        :item: item to be removed
+        :reference: reference item valid for deletion
+
         :return: list of related items to remove/update
         """
         relList = list()
         upList = list()
-        
-        self.items.remove(item)
-        
+        doRemove = True
+
         if isinstance(item, ModelAction):
             for rel in item.GetRelations():
                 relList.append(rel)
@@ -213,17 +215,24 @@
             
         elif isinstance(item, ModelData):
             for rel in item.GetRelations():
+                otherItem = rel.GetTo() if rel.GetFrom() == item else rel.GetFrom()
+                if reference and reference != otherItem:
+                    doRemove = False
+                    continue # avoid recursive deletion
                 relList.append(rel)
-                if rel.GetFrom() == self:
-                    relList.append(rel.GetTo())
-                else:
-                    relList.append(rel.GetFrom())
-        
+                if reference and reference != otherItem:
+                    relList.append(otherItem)
+            if not doRemove:
+                upList.append(item)
+
         elif isinstance(item, ModelLoop):
             for rel in item.GetRelations():
                 relList.append(rel)
             for action in self.GetItems():
                 action.UnSetBlock(item)
+
+        if doRemove and item in self.items:
+            self.items.remove(item)
         
         return relList, upList
     



More information about the grass-commit mailing list