[GRASS-SVN] r70402 - in grass/branches/releasebranch_7_2/gui/wxpython: core gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 21 08:32:00 PST 2017


Author: martinl
Date: 2017-01-21 08:32:00 -0800 (Sat, 21 Jan 2017)
New Revision: 70402

Modified:
   grass/branches/releasebranch_7_2/gui/wxpython/core/settings.py
   grass/branches/releasebranch_7_2/gui/wxpython/gui_core/preferences.py
   grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py
Log:
wxGUI: 'Align computation region to selected map' add to the layer menu
       see discussion at https://lists.osgeo.org/pipermail/grass-dev/2017-January/083867.html
wxGUI: add 'Align region to resolution' option to preferences
       (merge r70365, r70243 from trunk)


Modified: grass/branches/releasebranch_7_2/gui/wxpython/core/settings.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/core/settings.py	2017-01-20 00:24:25 UTC (rev 70401)
+++ grass/branches/releasebranch_7_2/gui/wxpython/core/settings.py	2017-01-21 16:32:00 UTC (rev 70402)
@@ -11,7 +11,7 @@
 from core.settings import UserSettings
 @endcode
 
-(C) 2007-2016 by the GRASS Development Team
+(C) 2007-2017 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.
 
@@ -104,6 +104,12 @@
                         'enabled': False
                     },
                 },
+                # region
+                'region': {
+                    'resAlign': {
+                        'enabled' : False
+                    },
+                },
             },
             'manager': {
                 # show opacity level widget

Modified: grass/branches/releasebranch_7_2/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/gui_core/preferences.py	2017-01-20 00:24:25 UTC (rev 70401)
+++ grass/branches/releasebranch_7_2/gui/wxpython/gui_core/preferences.py	2017-01-21 16:32:00 UTC (rev 70402)
@@ -14,7 +14,7 @@
  - preferences::MapsetAccess
  - preferences::CheckListMapset
 
-(C) 2007-2014 by the GRASS Development Team
+(C) 2007-2017 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.
@@ -57,7 +57,7 @@
     """Base preferences dialog"""
 
     def __init__(self, parent, giface, settings, title=_("User settings"),
-                 size=(500, 475),
+                 size=(-1, 500),
                  style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER):
         self.parent = parent  # ModelerFrame
         self.title = title
@@ -453,6 +453,41 @@
             border=5)
         border.Add(item=sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
 
+        #
+        # region
+        #
+        box = wx.StaticBox(
+            parent=panel,
+            id=wx.ID_ANY,
+            label=" %s " %
+            _("Region settings"))
+        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
+
+        gridSizer = wx.GridBagSizer(hgap=3, vgap=3)
+
+        row = 0
+        resAlign = wx.CheckBox(parent=panel, id=wx.ID_ANY, label=_(
+            "Align region to resolution"), name='IsChecked')
+        resAlign.SetValue(
+            self.settings.Get(
+                group='general',
+                key='region',
+                subkey=[
+                    'resAlign',
+                    'enabled']))
+        self.winId['general:region:resAlign:enabled'] = resAlign.GetId()
+
+        gridSizer.Add(resAlign,
+                      pos=(row, 0), span=(1, 2))
+
+        gridSizer.AddGrowableCol(0)
+        sizer.Add(
+            gridSizer,
+            proportion=1,
+            flag=wx.ALL | wx.EXPAND,
+            border=5)
+        border.Add(sizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=3)
+
         panel.SetSizer(border)
 
         return panel

Modified: grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py	2017-01-20 00:24:25 UTC (rev 70401)
+++ grass/branches/releasebranch_7_2/gui/wxpython/lmgr/layertree.py	2017-01-21 16:32:00 UTC (rev 70402)
@@ -423,7 +423,7 @@
         if not hasattr(self, "popupID"):
             self.popupID = dict()
             for key in (
-                    'remove', 'rename', 'opacity', 'nviz', 'zoom', 'region',
+                    'remove', 'rename', 'opacity', 'nviz', 'zoom', 'region', 'align',
                     'export', 'attr', 'edit', 'save_ws', 'bgmap', 'topo', 'meta',
                     'null', 'zoom1', 'color', 'colori', 'hist', 'univar', 'prof',
                     'properties', 'sql', 'copy', 'report', 'export-pg',
@@ -534,6 +534,19 @@
                     wx.EVT_MENU,
                     self.OnSetCompRegFromMap,
                     id=self.popupID['region'])
+                
+                # raster align 
+                if ltype and ltype == "raster" and len(selected) == 1:
+                    item = wx.MenuItem(
+                        self.popupMenu,
+                        id=self.popupID['align'],
+                        text=_("Align computational region to selected map"))
+                    item.SetBitmap(MetaIcon(img='region').GetBitmap(self.bmpsize))
+                    self.popupMenu.AppendItem(item)
+                    self.Bind(
+                        wx.EVT_MENU,
+                        self.OnAlignCompRegToRaster,
+                        id=self.popupID['align'])
 
         # vector layers (specific items)
         if ltype and ltype == "vector" and numSelected == 1:
@@ -906,7 +919,7 @@
         self._giface.RunCmd(cmd)
 
     def OnSetCompRegFromMap(self, event):
-        """Set computational region from selected raster/vector map
+        """Set computational region from selected raster/vector map(s)
         """
         rast = []
         vect = []
@@ -933,8 +946,10 @@
         if rast3d:
             kwargs['raster_3d'] = ','.join(rast3d)
 
-        # print output to command log area
         if kwargs:
+            if UserSettings.Get(group='general',
+                                key='region', subkey=['resAlign', 'enabled']):
+                kwargs['flags'] = 'a'
             # command must run in main thread otherwise it can be
             # launched after rendering is done (region extent will
             # remain untouched)
@@ -943,6 +958,29 @@
         # re-render map display
         self._giface.GetMapWindow().UpdateMap(render=False)
 
+    def OnAlignCompRegToRaster(self, event):
+        """Align computational region to selected raster map
+        """
+        selected = self.GetSelections()
+        if len(selected) != 1 or \
+           self.GetLayerInfo(selected[0], key='type') != 'raster':
+            return
+
+        kwargs = {'align': self.GetLayerInfo(selected[0],
+                                             key='maplayer').GetName()
+        }
+
+        if UserSettings.Get(group='general',
+                            key='region', subkey=['resAlign', 'enabled']):
+            kwargs['flags'] = 'a'
+        # command must run in main thread otherwise it can be
+        # launched after rendering is done (region extent will
+        # remain untouched)
+        RunCommand('g.region', **kwargs)
+
+        # re-render map display
+        self._giface.GetMapWindow().UpdateMap(render=False)
+
     def OnProfile(self, event):
         """Plot profile of given raster map layer"""
         mapLayer = self.GetLayerInfo(self.layer_selected, key='maplayer')



More information about the grass-commit mailing list