[GRASS-SVN] r58541 - grass/trunk/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 28 07:16:23 PST 2013


Author: martinl
Date: 2013-12-28 07:16:23 -0800 (Sat, 28 Dec 2013)
New Revision: 58541

Modified:
   grass/trunk/gui/wxpython/gmodeler/dialogs.py
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/modeler: fix loop item definition
               fix condition objects


Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-28 13:04:03 UTC (rev 58540)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-28 15:16:23 UTC (rev 58541)
@@ -534,10 +534,9 @@
         self.listBoxElse = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                         label=" %s " % _("List of items in 'else' block"))
         self.itemListElse = ItemCheckListCtrl(parent = self.panel,
-                                              window = self,
-                                              columns = [_("Name"),
+                                              columns = [_("Label"),
                                                          _("Command")],
-                                              shape = shape)
+                                              shape = shape, frame = parent)
         self.itemListElse.SetName('ElseBlockList')
         self.itemListElse.Populate(self.parent.GetModel().GetItems())
         
@@ -787,6 +786,8 @@
         self.disablePopup = disablePopup
 
         ModelListCtrl.__init__(self, parent, columns, frame, **kwargs)
+        self.itemIdMap = list()
+        
         self.SetColumnWidth(1, 100)
         self.SetColumnWidth(2, 65)
         
@@ -801,16 +802,17 @@
     def Populate(self, data):
         """!Populate the list"""
         self.itemDataMap = dict()
+        self.itemIdMap = list()
         
         if self.shape:
+            items = self.frame.GetModel().GetItems(objType=ModelAction)
             if isinstance(self.shape, ModelCondition):
-                if self.GetText() == 'ElseBlockList':
-                    shapeItems = map(lambda x: x.GetId(), self.shape.GetItems()['else'])
+                if self.GetLabel() == 'ElseBlockList':
+                    shapeItems = map(lambda x: x.GetId(), self.shape.GetItems(items)['else'])
                 else:
-                    shapeItems = map(lambda x: x.GetId(), self.shape.GetItems()['if'])
+                    shapeItems = map(lambda x: x.GetId(), self.shape.GetItems(items)['if'])
             else:
-                shapeItems = map(lambda x: x.GetId(),
-                                 self.shape.GetItems(self.frame.GetModel().GetItems(objType=ModelAction)))
+                shapeItems = map(lambda x: x.GetId(), self.shape.GetItems(items))
         else:
             shapeItems = list()
         
@@ -822,6 +824,8 @@
                     action == self.shape:
                 continue
             
+            self.itemIdMap.append(action.GetId())
+            
             if len(self.columns) == 2:
                 self.itemDataMap[i] = [action.GetLabel(),
                                        action.GetLog()]
@@ -993,12 +997,13 @@
         """!Get list of selected actions"""
         ids = { 'checked'   : list(),
                 'unchecked' : list() }
+        
         # action ids start at 1
         for i in range(self.GetItemCount()):
             if self.IsChecked(i):
-                ids['checked'].append(i+1)
+                ids['checked'].append(self.itemIdMap[i])
             else:
-                ids['unchecked'].append(i+1)
+                ids['unchecked'].append(self.itemIdMap[i])
             
         return ids
 

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-28 13:04:03 UTC (rev 58540)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-28 15:16:23 UTC (rev 58541)
@@ -959,11 +959,12 @@
 
     def DefineCondition(self, condition):
         """!Define if-else statement with given list of items"""
-        parent = condition
-        items = condition.GetItems()
+        items = condition.GetItems(self.model.GetItems(objType=ModelAction))
         if not items['if'] and not items['else']:
             return
         
+        parent = condition
+        
         # remove defined relations first
         for rel in condition.GetRelations():
             self.canvas.GetDiagram().RemoveShape(rel)
@@ -1136,11 +1137,12 @@
                 alist = list()
                 for aId in ids['unchecked']:
                     action = model.GetItem(aId, objType=ModelAction)
-                    action.UnSetBlock(shape)
+                    if action:
+                        action.UnSetBlock(shape)
                 for aId in ids['checked']:
                     action = model.GetItem(aId, objType=ModelAction)
-                    action.SetBlock(shape)
                     if action:
+                        action.SetBlock(shape)
                         alist.append(aId)
                 shape.SetItems(alist)
                 self.frame.DefineLoop(shape)

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-28 13:04:03 UTC (rev 58540)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-28 15:16:23 UTC (rev 58541)
@@ -1407,17 +1407,7 @@
         """!Abstract class for loops and conditions"""
         ModelObject.__init__(self, id, label)
         self.parent  = parent
-        self.itemIds = list() # unordered
         
-    def GetItems(self, items):
-        """!Get sorted items by id"""
-        result = list()
-        for item in items:
-            if item.GetId() in self.itemIds:
-                result.append(item)
-        
-        return result
-
     def SetId(self, id):
         """!Set loop id"""
         self.id = id
@@ -1447,7 +1437,8 @@
     def __init__(self, parent, x, y, id=-1, idx=-1, width = None, height = None, label = '', items = []):
         """!Defines a loop"""
         ModelItem.__init__(self, parent, x, y, id, width, height, label, items)
-        
+        self.itemIds = list() # unordered        
+
         if not width:
             width = UserSettings.Get(group='modeler', key='loop', subkey=('size', 'width'))
         if not height:
@@ -1488,7 +1479,16 @@
         
     def Update(self):
         self._setBrush()
+
+    def GetItems(self, items):
+        """!Get sorted items by id"""
+        result = list()
+        for item in items:
+            if item.GetId() in self.itemIds:
+                result.append(item)
         
+        return result
+
     def SetItems(self, items):
         """!Set items (id)"""
         self.itemIds = items
@@ -1500,10 +1500,11 @@
         ogl.RectangleShape.OnDraw(self, dc)
 
 class ModelCondition(ModelItem, ogl.PolygonShape):
-    def __init__(self, parent, x, y, id = -1, width = None, height = None, text = '',
+    def __init__(self, parent, x, y, id = -1, width = None, height = None, label = '',
                  items = { 'if' : [], 'else' : [] }):
         """!Defines a if-else condition"""
-        ModelItem.__init__(self, parent, x, y, id, width, height, text, items)
+        ModelItem.__init__(self, parent, x, y, id, width, height, label, items)
+        self.itemIds = {'if' : [], 'else': []}
         
         if not width:
             self.width = UserSettings.Get(group='modeler', key='if-else', subkey=('size', 'width'))
@@ -1527,8 +1528,8 @@
             self.SetX(x)
             self.SetY(y)
             self.SetPen(wx.BLACK_PEN)
-            if text:
-                self.AddText('(' + str(self.id) + ') ' + text)
+            if label:
+                self.AddText('(' + str(self.id) + ') ' + label)
             else:
                 self.AddText('(' + str(self.id) + ')')
 
@@ -1544,6 +1545,17 @@
         """!Get object height"""
         return self.height
 
+    def GetItems(self, items):
+        """!Get sorted items by id"""
+        result = {'if' : [], 'else': []}
+        for item in items:
+            if item.GetId() in self.itemIds['if']:
+                result['if'].append(item)
+            elif item.GetId() in self.itemIds['else']:
+                result['else'].append(item)
+        
+        return result
+
     def SetItems(self, items, branch = 'if'):
         """!Set items (id)
 
@@ -1551,7 +1563,7 @@
         @param branch 'if' / 'else'
         """
         if branch in ['if', 'else']:
-            self.items[branch] = items
+            self.itemIds[branch] = items
 
 class ProcessModelFile:
     """!Process GRASS model file (gxm)"""



More information about the grass-commit mailing list