Browse Source

wxGUI/datacatalog: add reprojection when copying

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@68949 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 9 years ago
parent
commit
08dec112b8

+ 1 - 1
gui/wxpython/core/giface.py

@@ -285,7 +285,7 @@ class StandaloneGrassInterface():
         os.environ["GRASS_MESSAGE_FORMAT"] = orig
         os.environ["GRASS_MESSAGE_FORMAT"] = orig
 
 
     def GetLayerList(self):
     def GetLayerList(self):
-        raise NotImplementedError()
+        return []
 
 
     def GetLayerTree(self):
     def GetLayerTree(self):
         return None
         return None

+ 1 - 0
gui/wxpython/datacatalog/__init__.py

@@ -2,4 +2,5 @@ all = [
     'catalog',
     'catalog',
     'frame',
     'frame',
     'tree',
     'tree',
+    'dialogs'
 ]
 ]

+ 31 - 34
gui/wxpython/datacatalog/tree.py

@@ -30,6 +30,7 @@ from gui_core.dialogs import TextEntryDialog
 from core.giface import StandaloneGrassInterface
 from core.giface import StandaloneGrassInterface
 from core.treemodel import TreeModel, DictNode
 from core.treemodel import TreeModel, DictNode
 from gui_core.treeview import TreeView
 from gui_core.treeview import TreeView
+from datacatalog.dialogs import CatalogReprojectionDialog
 
 
 from grass.pydispatch.signal import Signal
 from grass.pydispatch.signal import Signal
 
 
@@ -97,25 +98,11 @@ def cleanUpTree(model):
     for node in reversed(nodesToRemove):
     for node in reversed(nodesToRemove):
         model.RemoveNode(node)
         model.RemoveNode(node)
 
 
-def getEnvironment(gisdbase, location, mapset):
-    """Creates environment to be passed in run_command for example.
-    Returns tuple with temporary file path and the environment. The user
-    of this function is responsile for deleting the file."""
-    tmp_gisrc_file = gscript.tempfile()
-    with open(tmp_gisrc_file, 'w') as f:
-        f.write('MAPSET: {mapset}\n'.format(mapset=mapset))
-        f.write('GISDBASE: {g}\n'.format(g=gisdbase))
-        f.write('LOCATION_NAME: {l}\n'.format(l=location))
-        f.write('GUI: text\n')
-    env = os.environ.copy()
-    env['GISRC'] = tmp_gisrc_file
-    return tmp_gisrc_file, env
-
 
 
 def getLocationTree(gisdbase, location, queue, mapsets=None):
 def getLocationTree(gisdbase, location, queue, mapsets=None):
     """Creates dictionary with mapsets, elements, layers for given location.
     """Creates dictionary with mapsets, elements, layers for given location.
     Returns tuple with the dictionary and error (or None)"""
     Returns tuple with the dictionary and error (or None)"""
-    tmp_gisrc_file, env = getEnvironment(gisdbase, location, 'PERMANENT')
+    tmp_gisrc_file, env = gscript.create_environment(gisdbase, location, 'PERMANENT')
     env['GRASS_SKIP_MAPSET_OWNER_CHECK'] = '1'
     env['GRASS_SKIP_MAPSET_OWNER_CHECK'] = '1'
 
 
     maps_dict = {}
     maps_dict = {}
@@ -176,7 +163,7 @@ def map_exists(name, element, env, mapset=None):
 
 
     :param name: name of the map
     :param name: name of the map
     :param element: data type ('raster', 'raster_3d', and 'vector')
     :param element: data type ('raster', 'raster_3d', and 'vector')
-    :param env environment created by function getEnvironment
+    :param env environment created by function gscript.create_environment
     """
     """
     if not mapset:
     if not mapset:
         mapset = gscript.run_command('g.mapset', flags='p', env=env).strip()
         mapset = gscript.run_command('g.mapset', flags='p', env=env).strip()
@@ -591,7 +578,7 @@ class DataCatalogTree(LocationMapTree):
     def OnRenameMap(self, event):
     def OnRenameMap(self, event):
         """Rename layer with dialog"""
         """Rename layer with dialog"""
         old_name = self.selected_layer.label
         old_name = self.selected_layer.label
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             gisenv()['GISDBASE'],
             self.selected_location.label, mapset=self.selected_mapset.label)
             self.selected_location.label, mapset=self.selected_mapset.label)
         new_name = self._getNewMapName(
         new_name = self._getNewMapName(
@@ -624,7 +611,7 @@ class DataCatalogTree(LocationMapTree):
     def Rename(self, old, new):
     def Rename(self, old, new):
         """Rename layer"""
         """Rename layer"""
         string = old + ',' + new
         string = old + ',' + new
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             gisenv()['GISDBASE'],
             self.selected_location.label, self.selected_mapset.label)
             self.selected_location.label, self.selected_mapset.label)
         label = _("Renaming map <{name}>...").format(name=string)
         label = _("Renaming map <{name}>...").format(name=string)
@@ -652,7 +639,7 @@ class DataCatalogTree(LocationMapTree):
             GMessage(_("No map selected for copying."), parent=self)
             GMessage(_("No map selected for copying."), parent=self)
             return
             return
         if self.selected_location == self.copy_location:
         if self.selected_location == self.copy_location:
-            gisrc, env = getEnvironment(
+            gisrc, env = gscript.create_environment(
                 gisenv()['GISDBASE'], self.selected_location.label, mapset=self.selected_mapset.label)
                 gisenv()['GISDBASE'], self.selected_location.label, mapset=self.selected_mapset.label)
             new_name = self._getNewMapName(
             new_name = self._getNewMapName(
                 _('New name'),
                 _('New name'),
@@ -725,9 +712,15 @@ class DataCatalogTree(LocationMapTree):
                     message=_("g.copy completed").format(cmd=cmd))
                     message=_("g.copy completed").format(cmd=cmd))
             gscript.try_remove(gisrc)
             gscript.try_remove(gisrc)
         else:
         else:
-            GError(
-                _("Failed to copy map: action is allowed only within the same location."),
-                parent=self)
+            if self.copy_type.label == 'raster_3d':
+                 GError(_("Reprojection is not implemented for 3D rasters"), parent=self)
+                 return
+            gisdbase = gisenv()['GISDBASE']
+            dlg = CatalogReprojectionDialog(self, self._giface, gisdbase, self.copy_location.label,
+                                            self.copy_mapset.label, self.copy_layer.label,
+                                            gisdbase, self.selected_location.label, self.selected_mapset.label,
+                                            etype=self.copy_type.label)
+            dlg.Show()
 
 
         # expand selected mapset
         # expand selected mapset
         self.ExpandNode(self.selected_mapset, recursive=True)
         self.ExpandNode(self.selected_mapset, recursive=True)
@@ -752,7 +745,7 @@ class DataCatalogTree(LocationMapTree):
     def OnDeleteMap(self, event):
     def OnDeleteMap(self, event):
         """Delete layer or mapset"""
         """Delete layer or mapset"""
         name = self.selected_layer.label
         name = self.selected_layer.label
-        gisrc, env = getEnvironment(
+        gisrc, env = gscript.create_environment(
             gisenv()['GISDBASE'],
             gisenv()['GISDBASE'],
             self.selected_location.label, self.selected_mapset.label)
             self.selected_location.label, self.selected_mapset.label)
         if self._confirmDialog(
         if self._confirmDialog(
@@ -894,30 +887,31 @@ class DataCatalogTree(LocationMapTree):
         dlg.Destroy()
         dlg.Destroy()
         return res
         return res
 
 
-    def _popupMenuLayer(self):
-        """Create popup menu for layers"""
-        menu = wx.Menu()
-        genv = gisenv()
+    def _isCurrent(self, genv):
         if self._restricted:
         if self._restricted:
             currentMapset = currentLocation = False
             currentMapset = currentLocation = False
             if self.selected_location.label == genv['LOCATION_NAME']:
             if self.selected_location.label == genv['LOCATION_NAME']:
                 currentLocation = True
                 currentLocation = True
                 if self.selected_mapset.label == genv['MAPSET']:
                 if self.selected_mapset.label == genv['MAPSET']:
                     currentMapset = True
                     currentMapset = True
+            return currentLocation, currentMapset
         else:
         else:
-            currentMapset = currentLocation = True
+            return True, True
+
+    def _popupMenuLayer(self):
+        """Create popup menu for layers"""
+        menu = wx.Menu()
+        genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
 
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Copy"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Copy"))
         menu.AppendItem(item)
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnCopyMap, item)
         self.Bind(wx.EVT_MENU, self.OnCopyMap, item)
-        item.Enable(currentLocation)
 
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not(
-                currentLocation and self.copy_layer and self.selected_location ==
-                self.copy_location):
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
             item.Enable(False)
 
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Delete"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Delete"))
@@ -944,11 +938,12 @@ class DataCatalogTree(LocationMapTree):
         """Create popup menu for mapsets"""
         """Create popup menu for mapsets"""
         menu = wx.Menu()
         menu = wx.Menu()
         genv = gisenv()
         genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
 
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not (self.copy_layer and self.selected_location == self.copy_location):
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
             item.Enable(False)
 
 
         item = wx.MenuItem(menu, wx.NewId(), _("&Switch mapset"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Switch mapset"))
@@ -966,7 +961,9 @@ class DataCatalogTree(LocationMapTree):
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         item = wx.MenuItem(menu, wx.NewId(), _("&Paste"))
         menu.AppendItem(item)
         menu.AppendItem(item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
         self.Bind(wx.EVT_MENU, self.OnPasteMap, item)
-        if not (self.copy_layer and self.selected_location == self.copy_location):
+        genv = gisenv()
+        currentLocation, currentMapset = self._isCurrent(genv)
+        if not(currentLocation and self.copy_layer):
             item.Enable(False)
             item.Enable(False)
 
 
         self.PopupMenu(menu)
         self.PopupMenu(menu)

+ 3 - 0
gui/wxpython/gui_core/forms.py

@@ -2076,6 +2076,9 @@ class CmdPanel(wx.Panel):
         pLocation = None
         pLocation = None
         pMapset = None
         pMapset = None
         for p in self.task.params:
         for p in self.task.params:
+            if self.task.blackList['enabled'] and self.task.get_name() in self.task.blackList['items'] and \
+               p.get('name', '') in self.task.blackList['items'][self.task.get_name()]['params']:
+                continue
             guidep = p.get('guidependency', '')
             guidep = p.get('guidependency', '')
 
 
             if guidep:
             if guidep:

+ 15 - 0
lib/python/script/core.py

@@ -1570,6 +1570,21 @@ def legal_name(s):
     return True
     return True
 
 
 
 
+def create_environment(gisdbase, location, mapset):
+    """Creates environment to be passed in run_command for example.
+    Returns tuple with temporary file path and the environment. The user
+    of this function is responsile for deleting the file."""
+    tmp_gisrc_file = tempfile()
+    with open(tmp_gisrc_file, 'w') as f:
+        f.write('MAPSET: {mapset}\n'.format(mapset=mapset))
+        f.write('GISDBASE: {g}\n'.format(g=gisdbase))
+        f.write('LOCATION_NAME: {l}\n'.format(l=location))
+        f.write('GUI: text\n')
+    env = os.environ.copy()
+    env['GISRC'] = tmp_gisrc_file
+    return tmp_gisrc_file, env
+
+
 if __name__ == '__main__':
 if __name__ == '__main__':
     import doctest
     import doctest
     doctest.testmod()
     doctest.testmod()