浏览代码

g.gui.vdigit added

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54382 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 12 年之前
父节点
当前提交
81c0cfe354

+ 1 - 1
gui/wxpython/Makefile

@@ -1,6 +1,6 @@
 MODULE_TOPDIR = ../..
 MODULE_TOPDIR = ../..
 
 
-SUBDIRS = docs animation mapswipe gmodeler rlisetup psmap dbmgr
+SUBDIRS = docs animation mapswipe gmodeler rlisetup psmap dbmgr vdigit
 EXTRA_CLEAN_FILES = menustrings.py build_ext.pyc
 EXTRA_CLEAN_FILES = menustrings.py build_ext.pyc
 
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 include $(MODULE_TOPDIR)/include/Make/Dir.make

+ 11 - 4
gui/wxpython/mapdisp/frame.py

@@ -35,7 +35,7 @@ sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
 sys.path.append(os.path.join(globalvar.ETCDIR,   "python"))
 sys.path.append(os.path.join(globalvar.ETCDIR,   "python"))
 
 
 from core               import globalvar
 from core               import globalvar
-from core.render        import EVT_UPDATE_PRGBAR
+from core.render        import EVT_UPDATE_PRGBAR, Map
 from vdigit.toolbars    import VDigitToolbar
 from vdigit.toolbars    import VDigitToolbar
 from mapdisp.toolbars   import MapToolbar, NvizIcons
 from mapdisp.toolbars   import MapToolbar, NvizIcons
 from mapdisp.gprint     import PrintOptions
 from mapdisp.gprint     import PrintOptions
@@ -64,7 +64,7 @@ class MapFrame(SingleMapFrame):
     """
     """
     def __init__(self, parent, giface, title = _("GRASS GIS - Map display"),
     def __init__(self, parent, giface, title = _("GRASS GIS - Map display"),
                  toolbars = ["map"], tree = None, notebook = None, lmgr = None,
                  toolbars = ["map"], tree = None, notebook = None, lmgr = None,
-                 page = None, Map = None, auimgr = None, name = 'MapWindow', **kwargs):
+                 page = None, Map = Map(), auimgr = None, name = 'MapWindow', **kwargs):
         """!Main map display window with toolbars, statusbar and
         """!Main map display window with toolbars, statusbar and
         BufferedWindow (map canvas)
         BufferedWindow (map canvas)
         
         
@@ -360,13 +360,16 @@ class MapFrame(SingleMapFrame):
         self.MapWindow.UpdateMap()
         self.MapWindow.UpdateMap()
         self._mgr.Update()
         self._mgr.Update()
         
         
-    def AddToolbar(self, name):
+    def AddToolbar(self, name, fixed = False):
         """!Add defined toolbar to the window
         """!Add defined toolbar to the window
         
         
         Currently known toolbars are:
         Currently known toolbars are:
          - 'map'     - basic map toolbar
          - 'map'     - basic map toolbar
          - 'vdigit'  - vector digitizer
          - 'vdigit'  - vector digitizer
-         - 'gcpdisp' - GCP Manager Display
+         - 'gcpdisp' - GCP Manager 
+         
+        @param name toolbar to add
+        @param fixed fixed toolbar
         """
         """
         # default toolbar
         # default toolbar
         if name == "map":
         if name == "map":
@@ -383,8 +386,12 @@ class MapFrame(SingleMapFrame):
             
             
         # vector digitizer
         # vector digitizer
         elif name == "vdigit":
         elif name == "vdigit":
+            self.toolbars['map'].combo.SetValue(_("Digitize"))
             self._addToolbarVDigit()
             self._addToolbarVDigit()
         
         
+        if fixed:
+            self.toolbars['map'].combo.Disable()
+         
         self._mgr.Update()
         self._mgr.Update()
         
         
     def RemoveToolbar (self, name):
     def RemoveToolbar (self, name):

+ 4 - 0
gui/wxpython/mapdisp/main.py

@@ -292,6 +292,10 @@ class MapApp(wx.App):
             grass.warning("%s" % e)
             grass.warning("%s" % e)
             self.timer.Stop()
             self.timer.Stop()
 
 
+    def GetMapFrame(self):
+        """!Get Map Frame instance"""
+        return self.mapFrm
+
 if __name__ == "__main__":
 if __name__ == "__main__":
     # set command variable
     # set command variable
     if len(sys.argv) < 5:
     if len(sys.argv) < 5:

+ 2 - 1
gui/wxpython/mapdisp/toolbars.py

@@ -261,7 +261,8 @@ class MapToolbar(BaseToolbar):
     def ExitToolbars(self):
     def ExitToolbars(self):
         if self.parent.GetToolbar('vdigit'):
         if self.parent.GetToolbar('vdigit'):
             self.parent.toolbars['vdigit'].OnExit()
             self.parent.toolbars['vdigit'].OnExit()
-        if self.parent.GetLayerManager().IsPaneShown('toolbarNviz'):
+        if self.parent.GetLayerManager() and \
+                self.parent.GetLayerManager().IsPaneShown('toolbarNviz'):
             self.parent.RemoveNviz()
             self.parent.RemoveNviz()
         
         
     def Enable2D(self, enabled):
     def Enable2D(self, enabled):

+ 5 - 0
gui/wxpython/vdigit/Makefile

@@ -0,0 +1,5 @@
+MODULE_TOPDIR = ../../..
+
+include $(MODULE_TOPDIR)/include/Make/GuiScript.make
+
+default: guiscript

+ 4 - 5
gui/wxpython/docs/wxGUI.Vector_Digitizer.html

@@ -2,9 +2,8 @@
 <!-- meta page index: wxGUI -->
 <!-- meta page index: wxGUI -->
 <h2>DESCRIPTION</h2>
 <h2>DESCRIPTION</h2>
 
 
-The <b>vector digitizer</b> is
-a <em><a href="wxGUI.html">wxGUI</a></em> component intended for
-interactive editing vector maps
+<b>Vector digitizer</b> is a <em><a href="wxGUI.html">wxGUI</a></em>
+component intended for interactive editing vector maps
 (see <em><a href="v.edit.html">v.edit</a></em> for non-interactive
 (see <em><a href="v.edit.html">v.edit</a></em> for non-interactive
 vector editing GRASS capabilities).
 vector editing GRASS capabilities).
 
 
@@ -14,7 +13,7 @@ boundaries, and area).
 
 
 Vector features can be selected using mouse or by query (e.g. minimal
 Vector features can be selected using mouse or by query (e.g. minimal
 vector line length). Vector features can be selected by bounding box
 vector line length). Vector features can be selected by bounding box
-or simply by mouse click (based on 'Settings-&gt;General-&gt;Select
+or simply by mouse click (based on 'Settings&rarr;General&rarr;Select
 threshold' value).
 threshold' value).
 
 
 <p>
 <p>
@@ -48,7 +47,7 @@ vector map" button in the "Additional Tools" menu on the Digitzer Toolbar.
 
 
 <center>
 <center>
 <br>
 <br>
-<img src="wxGUI_vector_digitizer_toolbar.jpg" border="1" alt="toolbar">
+<img src="vdigit_toolbar.jpg" border="1" alt="Vector Digitizer Toolbar">
 <br><br>
 <br><br>
 </center>
 </center>
 
 

+ 93 - 0
gui/wxpython/vdigit/g.gui.vdigit.py

@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:    g.gui.vdigit
+# AUTHOR(S): Martin Landa <landa.martin gmail.com>
+# PURPOSE:   wxGUI Vector Digitizer
+# COPYRIGHT: (C) 2007-2012 by Martin Landa, and the GRASS Development Team
+#
+#  This program is free software; you can 1redistribute it and/or
+#  modify it under the terms of the GNU General Public License as
+#  published by the Free Software Foundation; either version 2 of the
+#  License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful, but
+#  WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  General Public License for more details.
+#
+############################################################################
+
+#%module
+#% description: Interactive editing and digitization of vector maps.
+#% keywords: general
+#% keywords: gui
+#% keywords: vector
+#% keywords: editig
+#% keywords: digitization
+#%end
+#%option G_OPT_V_MAP
+#%label: Name of vector map to load
+#%end
+
+import os
+import sys
+import gettext
+
+import grass.script as grass
+
+import wx
+
+if __name__ == '__main__':
+    sys.path.append(os.path.join(os.environ['GISBASE'], "etc", "gui", "wxpython"))
+
+from mapdisp.frame import MapFrame
+from core.giface   import StandaloneGrassInterface
+from core.settings import UserSettings
+from vdigit.main   import haveVDigit, errorMsg
+
+class VDigitMapFrame(MapFrame):
+    def __init__(self, vectorMap):
+        MapFrame.__init__(self, parent = None,  giface = StandaloneGrassInterface(),
+                          size = (850, 600))
+
+        # load vector map
+        mapLayer = self.GetMap().AddLayer(type = 'vector',
+                                          command = ['d.vect', 'map=%s' % vectorMap],
+                                          l_active = True, name = vectorMap, l_hidden = False, l_opacity = 1.0,
+                                          l_render = True)
+        
+        # switch toolbar
+        self.AddToolbar('vdigit', fixed = True)
+        
+        # start editing
+        self.toolbars['vdigit'].StartEditing(mapLayer)
+
+def main():
+    if not haveVDigit:
+        grass.fatal(_("Vector digitizer not available. %s") % errorMsg)
+    
+    if not grass.find_file(name = options['map'], element = 'vector',
+                           mapset = grass.gisenv()['MAPSET'])['fullname']:
+        grass.fatal(_("Vector map <%s> not found in current mapset") % options['map'])
+
+    # allow immediate rendering
+    driver = UserSettings.Get(group = 'display', key = 'driver', subkey = 'type')
+    if driver == 'png':
+        os.environ['GRASS_RENDER_IMMEDIATE'] = 'png'
+    else:
+        os.environ['GRASS_RENDER_IMMEDIATE'] = 'cairo'
+    
+    app = wx.PySimpleApp()
+    wx.InitAllImageHandlers()
+    frame = VDigitMapFrame(options['map'])
+    frame.Show()
+
+    app.MainLoop()
+    
+if __name__ == "__main__":
+    gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode = True)
+    grass.set_raise_on_error(False)
+    options, flags = grass.parser()
+    
+    main()

+ 1 - 1
gui/wxpython/vdigit/main.py

@@ -6,7 +6,7 @@
 Classes:
 Classes:
  - main::VDigit
  - main::VDigit
 
 
-(C) 2007-2011 by the GRASS Development Team
+(C) 2007-2012 by the GRASS Development Team
 
 
 This program is free software under the GNU General Public License
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.

+ 3 - 0
gui/wxpython/vdigit/mapwindow.py

@@ -276,6 +276,9 @@ class VDigitWindow(BufferedWindow):
         
         
         @todo: use AddDataRow() instead
         @todo: use AddDataRow() instead
         """
         """
+        if not self.lmgr:
+            return
+        
         # update ATM
         # update ATM
         digitVector = self.toolbar.GetLayer().GetName()
         digitVector = self.toolbar.GetLayer().GetName()
                             
                             

+ 4 - 1
gui/wxpython/vdigit/preferences.py

@@ -425,7 +425,10 @@ class VDigitSettingsDialog(wx.Dialog):
         layer = UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value')
         layer = UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value')
         mapLayer = self.parent.toolbars['vdigit'].GetLayer()
         mapLayer = self.parent.toolbars['vdigit'].GetLayer()
         tree = self.parent.tree
         tree = self.parent.tree
-        item = tree.FindItemByData('maplayer', mapLayer)
+        if tree:
+            item = tree.FindItemByData('maplayer', mapLayer)
+        else:
+            item = None
         row = 0
         row = 0
         for attrb in ['length', 'area', 'perimeter']:
         for attrb in ['length', 'area', 'perimeter']:
             # checkbox
             # checkbox

+ 25 - 13
gui/wxpython/vdigit/toolbars.py

@@ -23,7 +23,7 @@ from gui_core.dialogs   import CreateNewVector
 from vdigit.preferences import VDigitSettingsDialog
 from vdigit.preferences import VDigitSettingsDialog
 from core.debug         import Debug
 from core.debug         import Debug
 from core.settings      import UserSettings
 from core.settings      import UserSettings
-from core.gcmd          import GError
+from core.gcmd          import GError, RunCommand
 from icons.icon         import MetaIcon
 from icons.icon         import MetaIcon
 from iclass.digit       import IClassVDigit
 from iclass.digit       import IClassVDigit
 
 
@@ -321,7 +321,7 @@ class VDigitToolbar(BaseToolbar):
                         'id'   : self.addArea }
                         'id'   : self.addArea }
         self.MapWindow.mouse['box'] = 'line'
         self.MapWindow.mouse['box'] = 'line'
 
 
-    def OnExit (self, event=None):
+    def OnExit (self, event = None):
         """!Quit digitization tool"""
         """!Quit digitization tool"""
         # stop editing of the currently selected map layer
         # stop editing of the currently selected map layer
         if self.mapLayer:
         if self.mapLayer:
@@ -330,15 +330,18 @@ class VDigitToolbar(BaseToolbar):
         # close dialogs if still open
         # close dialogs if still open
         if self.settingsDialog:
         if self.settingsDialog:
             self.settingsDialog.OnCancel(None)
             self.settingsDialog.OnCancel(None)
-            
+        
         # set default mouse settings
         # set default mouse settings
         self.MapWindow.mouse['use'] = "pointer"
         self.MapWindow.mouse['use'] = "pointer"
         self.MapWindow.mouse['box'] = "point"
         self.MapWindow.mouse['box'] = "point"
         self.MapWindow.polycoords = []
         self.MapWindow.polycoords = []
         
         
-        # disable the toolbar
-        self.parent.RemoveToolbar("vdigit")
-        
+        if not self.parent.IsStandalone():
+            # disable the toolbar
+            self.parent.RemoveToolbar("vdigit")
+        else:
+            self.parent.Close()
+                
     def OnMoveVertex(self, event):
     def OnMoveVertex(self, event):
         """!Move line vertex"""
         """!Move line vertex"""
         Debug.msg(2, "Digittoolbar.OnMoveVertex():")
         Debug.msg(2, "Digittoolbar.OnMoveVertex():")
@@ -454,10 +457,18 @@ class VDigitToolbar(BaseToolbar):
 
 
     def OnHelp(self, event):
     def OnHelp(self, event):
         """!Show digitizer help page in web browser"""
         """!Show digitizer help page in web browser"""
-        log = self.parent.GetLayerManager().GetLogWindow()
-        log.RunCmd(['g.manual',
-                    'entry=wxGUI.Vector_Digitizer'])
-
+        try:
+            log = self.parent.GetLayerManager().GetLogWindow()
+        except:
+            log = None
+        
+        if log:
+            log.RunCmd(['g.manual',
+                        'entry = wxGUI.vdigit'])
+        else:
+            RunCommand('g.manual',
+                       entry = 'wxGUI.vdigit')
+        
     def OnAdditionalToolMenu(self, event):
     def OnAdditionalToolMenu(self, event):
         """!Menu for additional tools"""
         """!Menu for additional tools"""
         point = wx.GetMousePosition()
         point = wx.GetMousePosition()
@@ -858,9 +869,10 @@ class VDigitToolbar(BaseToolbar):
                 lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
                 lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
                                                     self.mapLayer.GetName())
                                                     self.mapLayer.GetName())
             # re-active layer 
             # re-active layer 
-            item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
-            if item and self.parent.tree.IsItemChecked(item):
-                self.Map.ChangeLayerActive(self.mapLayer, True)
+            if self.parent.tree:
+                item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
+                if item and self.parent.tree.IsItemChecked(item):
+                    self.Map.ChangeLayerActive(self.mapLayer, True)
         
         
         # change cursor
         # change cursor
         self.MapWindow.SetCursor(self.parent.cursors["default"])
         self.MapWindow.SetCursor(self.parent.cursors["default"])

gui/wxpython/docs/wxGUI_vector_digitizer_toolbar.jpg → gui/wxpython/vdigit/vdigit_toolbar.jpg