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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 2 14:27:18 PST 2018


Author: martinl
Date: 2018-03-02 14:27:18 -0800 (Fri, 02 Mar 2018)
New Revision: 72308

Modified:
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gmodeler/giface.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/gmodeler: implement display data functionality (work in progress)

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2018-03-02 22:22:33 UTC (rev 72307)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2018-03-02 22:27:18 UTC (rev 72308)
@@ -11,7 +11,7 @@
  - frame::ItemPanel
  - frame::PythonPanel
 
-(C) 2010-2014 by the GRASS Development Team
+(C) 2010-2018 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.
@@ -1467,7 +1467,7 @@
         if not hasattr(self, "popupID"):
             self.popupID = dict()
             for key in ('remove', 'enable', 'addPoint',
-                        'delPoint', 'intermediate', 'props', 'id',
+                        'delPoint', 'intermediate', 'display', 'props', 'id',
                         'label', 'comment'):
                 self.popupID[key] = wx.NewId()
 
@@ -1529,20 +1529,38 @@
             if len(shape.GetLineControlPoints()) == 2:
                 popupMenu.Enable(self.popupID['delPoint'], False)
 
-        if isinstance(shape, ModelData) and '@' not in shape.GetValue():
+        if isinstance(shape, ModelData):
             popupMenu.AppendSeparator()
-            popupMenu.Append(
-                self.popupID['intermediate'],
-                text=_('Intermediate'),
-                kind=wx.ITEM_CHECK)
-            if self.GetShape().IsIntermediate():
-                popupMenu.Check(self.popupID['intermediate'], True)
+            if '@' not in shape.GetValue() and \
+               len(self.GetShape().GetRelations('from')) > 0:
+                popupMenu.Append(
+                    self.popupID['intermediate'],
+                    text=_('Intermediate'),
+                    kind=wx.ITEM_CHECK)
+                if self.GetShape().IsIntermediate():
+                    popupMenu.Check(self.popupID['intermediate'], True)
 
-            self.frame.Bind(
-                wx.EVT_MENU,
-                self.OnIntermediate,
-                id=self.popupID['intermediate'])
+                self.frame.Bind(
+                    wx.EVT_MENU,
+                    self.OnIntermediate,
+                    id=self.popupID['intermediate'])
 
+            if self.frame._giface.GetMapDisplay():
+                popupMenu.Append(
+                    self.popupID['display'],
+                    text=_('Display'),
+                    kind=wx.ITEM_CHECK)
+                if self.GetShape().HasDisplay():
+                    popupMenu.Check(self.popupID['display'], True)
+
+                self.frame.Bind(
+                    wx.EVT_MENU,
+                    self.OnHasDisplay,
+                    id=self.popupID['display'])
+
+                if self.GetShape().IsIntermediate():
+                    popupMenu.Enable(self.popupID['display'], False)
+
         if isinstance(shape, ModelData) or \
                 isinstance(shape, ModelAction) or \
                 isinstance(shape, ModelLoop):
@@ -1647,6 +1665,28 @@
         shape.SetIntermediate(event.IsChecked())
         self.frame.canvas.Refresh()
 
+    def OnHasDisplay(self, event):
+        """Mark data to be displayed"""
+        self.frame.ModelChanged()
+        shape = self.GetShape()
+        shape.SetHasDisplay(event.IsChecked())
+        self.frame.canvas.Refresh()
+
+        try:
+            if event.IsChecked():
+                # add map layer to display
+                self.frame._giface.GetLayerList().AddLayer(
+                    ltype=shape.GetPrompt(), name=shape.GetValue(), checked=True,
+                    cmd=shape.GetDisplayCmd())
+            else:
+                # remove map layer(s) from display
+                layers = self.frame._giface.GetLayerList().GetLayersByName(shape.GetValue())
+                for layer in layers:
+                    self.frame._giface.GetLayerList().DeleteLayer(layer)
+        except GException as e:
+            GError(parent=self,
+                   message='{}'.format(e))
+
     def OnRemove(self, event):
         """Remove shape
         """

Modified: grass/trunk/gui/wxpython/gmodeler/giface.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/giface.py	2018-03-02 22:22:33 UTC (rev 72307)
+++ grass/trunk/gui/wxpython/gmodeler/giface.py	2018-03-02 22:27:18 UTC (rev 72308)
@@ -6,7 +6,7 @@
 Classes:
  - giface::GraphicalModelerGrassInterface
 
-(C) 2013-2014 by the GRASS Development Team
+(C) 2013-2018 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.

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2018-03-02 22:22:33 UTC (rev 72307)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2018-03-02 22:27:18 UTC (rev 72308)
@@ -18,7 +18,7 @@
  - model::WritePythonFile
  - model::ModelParamDialog
 
-(C) 2010-2016 by the GRASS Development Team
+(C) 2010-2018 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.
@@ -1346,6 +1346,7 @@
         self.value = value
         self.prompt = prompt
         self.intermediate = False
+        self.display = False
         self.propWin = None
         if not width:
             width = UserSettings.Get(
@@ -1374,6 +1375,14 @@
         """Set intermediate flag"""
         self.intermediate = im
 
+    def HasDisplay(self):
+        """Checks if data item is marked to be displayed"""
+        return self.display
+
+    def SetHasDisplay(self, tbd):
+        """Set to-be-displayed flag"""
+        self.display = tbd
+
     def OnDraw(self, dc):
         self._setPen()
 
@@ -1506,7 +1515,21 @@
         self._setPen()
         self.SetLabel()
 
+    def GetDisplayCmd(self):
+        """Get display command as list"""
+        cmd = []
+        if self.prompt == 'raster':
+            cmd.append('d.rast')
+        elif self.prompt == 'vector':
+            cmd.append('d.vect')
+        else:
+            raise GException("Unsupported display prompt: {}".format(
+                self.prompt))
 
+        cmd.append('map=' + self.value)
+
+        return cmd
+
 class ModelRelation(ogl.LineShape):
     """Data - action relation"""
 



More information about the grass-commit mailing list