[GRASS-SVN] r54354 - in grass-addons/grass7/gui/wxpython/wx.rdigit: . rdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 20 03:26:41 PST 2012


Author: rashadkm
Date: 2012-12-20 03:26:41 -0800 (Thu, 20 Dec 2012)
New Revision: 54354

Modified:
   grass-addons/grass7/gui/wxpython/wx.rdigit/frame.py
   grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/mapwindow.py
   grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/toolbars.py
   grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/wxdigit.py
   grass-addons/grass7/gui/wxpython/wx.rdigit/toolbars.py
Log:
add check for new layer; digitize toolbar added by default

Modified: grass-addons/grass7/gui/wxpython/wx.rdigit/frame.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.rdigit/frame.py	2012-12-20 08:58:40 UTC (rev 54353)
+++ grass-addons/grass7/gui/wxpython/wx.rdigit/frame.py	2012-12-20 11:26:41 UTC (rev 54354)
@@ -59,19 +59,17 @@
         SingleMapFrame.__init__(self, parent = parent, title = title, name = name, Map = Map(), **kwargs)
         self._giface = giface
         
-        self.MapWindow = BufferedWindow(parent = self,giface = self._giface, Map = self.Map, frame = self)
+        self.MapWindow = RDigitWindow(parent = self, giface = self._giface,
+                                                id = wx.ID_ANY, frame = self,
+                                                Map = self.Map)
         self.outMapName = None
         
-        self.mapManager = MapManager(self, mapWindow = self.GetWindow(),
+        self.mapManager = MapManager(self, mapWindow = self.MapWindow,
                                              Map = self.GetMap())
         self.SetSize(size)
-       
-        self.MapWindowRDigit = RDigitWindow(parent = self, giface = self._giface,
-                                                id = wx.ID_ANY, frame = self,
-                                                Map = self.Map)  
-        
+        #MapWindowRDigit
+
         # Add toolbars
-        
         toolbarsCopy = toolbars[:]
         if sys.platform == 'win32':
             self.AddToolbar(toolbarsCopy.pop(1))
@@ -83,10 +81,6 @@
             
         self.GetMapToolbar().Bind(wx.EVT_CHOICE, self.OnUpdateActive)
         
-        #
-        # Add statusbar
-        #
-        
         # items for choice
         self.statusbarItems = [sb.SbCoordinates,
                                sb.SbRegionExtent,
@@ -108,14 +102,10 @@
         self.statusbarManager.AddStatusbarItemsByClass(self.statusbarItems, mapframe = self, statusbar = statusbar)
         self.statusbarManager.AddStatusbarItem(sb.SbMask(self, statusbar = statusbar, position = 2))
         self.statusbarManager.AddStatusbarItem(sb.SbRender(self, statusbar = statusbar, position = 3))
-        
         self.statusbarManager.Update()
         
         self.changes = False
-        self.exportVector = None
-        self.MapWindowCopy = None
-
-                                   
+             
         self._addPanes()
         self._mgr.Update()
         
@@ -135,7 +125,6 @@
     def GetMap(self):
       return self.Map
      
-      
     def OnHelp(self, event):
         """!Show help page"""
         helpInProgress = True
@@ -162,7 +151,7 @@
                               BestSize((self.toolbars[name].GetBestSize())))
                               
         elif name == "rdigit":
-          self.toolbars[name] = RDigitToolbar(parent = self, MapWindow = self.MapWindowRDigit,
+          self.toolbars[name] = RDigitToolbar(parent = self, MapWindow = self.MapWindow,
                                              digitClass = RDigit, layerTree = self.mapManager)
                                                 
           self._mgr.AddPane(self.toolbars[name],
@@ -173,19 +162,15 @@
                           BottomDockable(False).TopDockable(True).
                           CloseButton(False).Layer(0).
                           BestSize((self.toolbars['rdigit'].GetBestSize())))                                                
-          self.MapWindowRDigit.SetToolbar(self.toolbars[name])
-          self._mgr.GetPane('rdigittoolbar').Hide()
-          
-
-                              
+          self.MapWindow.SetToolbar(self.toolbars[name])
+          #self._mgr.GetPane('rdigittoolbar').Hide()
+                           
     def _addPanes(self):
       """!Add mapwindows and toolbars to aui manager"""
 
       self._addPaneMapWindow()
       self._addPaneToolbar(name = 'digitMap')
-     
 
-        
     def _addPaneToolbar(self, name):
       
         self.toolbars[name] = RDigitMapManagerToolbar(self, self.mapManager)
@@ -202,18 +187,14 @@
                           CloseButton(False).DestroyOnClose(True).
                           Layer(0))
 
-        self._mgr.AddPane(self.MapWindowRDigit, wx.aui.AuiPaneInfo().CentrePane().
-                          Dockable(True).BestSize((-1,-1)).Name('rdigit').
-                          CloseButton(False).DestroyOnClose(True).
-                          Layer(0))
+#        self._mgr.AddPane(self.MapWindowRDigit, wx.aui.AuiPaneInfo().CentrePane().
+#                          Dockable(True).BestSize((-1,-1)).Name('rdigit').
+#                          CloseButton(False).DestroyOnClose(True).
+#                          Layer(0))
                           
-        
-
         self._mgr.GetPane('window').Show()
         self._mgr.GetPane('rdigit').Hide()
                                
-                    
-        
     def IsStandalone(self):
         """!Check if Map display is standalone"""
         return True
@@ -223,8 +204,7 @@
         @todo move to DoubleMapFrame?
         """
         self.StatusbarUpdate() 
-      
-        
+
     def GetMapToolbar(self):
         """!Returns toolbar with zooming tools"""
         return self.toolbars['digitMap']
@@ -255,36 +235,12 @@
       return self.outMapName
 
     def RemoveToolbar(self, name):
-    
         self.outMapName = self.toolbars['rdigit'].GetMapName()
         self.mapManager.AddLayer(name = self.outMapName)
         self._mgr.GetPane('window').Show()
-        self._mgr.GetPane('rdigit').Hide()
-        self._mgr.GetPane('rdigittoolbar').Hide()
-        self.MapWindow = self.MapWindowCopy
         self._mgr.Update()
         
-    def OnDrawArea(self, event):
 
-      if not self._mgr.GetPane('rdigit').IsShown():
-        self._mgr.GetPane('window').Hide()
-        self._mgr.GetPane('rdigit').Show()
-        self._mgr.GetPane('rdigittoolbar').Show()
-        self._mgr.Update()
-        self.MapWindowCopy = self.MapWindow
-        self.MapWindow = self.MapWindowRDigit
-        self.MapWindow.mouse['box'] = "point"
-        self.MapWindow.zoomtype     = 0
-        self.MapWindow.pen          = wx.Pen(colour = 'red',   width = 2, style = wx.SOLID)
-        self.MapWindow.polypen      = wx.Pen(colour = 'green', width = 2, style = wx.SOLID)  
-      else:
-        self.MapWindow = self.MapWindowCopy
-        self._mgr.GetPane('window').Show()
-        self._mgr.GetPane('rdigit').Hide()                     
- 
-
-
-        
 class MapManager:
     """! Class for managing map renderer.
     
@@ -294,7 +250,6 @@
         """!
         
         It is expected that \a mapWindow is conected with \a Map.
-        
         @param frame application main window
         @param mapWindow map window instance
         @param Map map renderer instance
@@ -303,10 +258,8 @@
         self.frame = frame
         self.mapWindow = mapWindow
         self.toolbar = None
-        
         self.layerName = {}
-        
-        
+  
     def SetToolbar(self, toolbar):
         self.toolbar = toolbar
         
@@ -337,9 +290,7 @@
             
         self.toolbar.choice.Insert(name, 0)
         self.toolbar.choice.SetSelection(0)
-        
 
-        
     def RemoveLayer(self, name, idx):
         """!Removes layer from Map and update toolbar"""
         name = self.layerName[name]

Modified: grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/mapwindow.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/mapwindow.py	2012-12-20 08:58:40 UTC (rev 54353)
+++ grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/mapwindow.py	2012-12-20 11:26:41 UTC (rev 54354)
@@ -1,7 +1,7 @@
 """!
 @package vdigit.mapwindow
 
- at brief Map display canvas for wxGUI vector digitizer
+ at brief Map display canvas for wxGUI raster digitizer
 
 Classes:
  - mapwindow::RDigitWindow
@@ -212,13 +212,11 @@
         
 
     def _onLeftDown(self, event):
-        """!Left mouse button donw - vector digitizer various actions
+        """!Left mouse button donw - raster digitizer various actions
         """
-        try:
-            mapLayer = self.toolbar.GetMapName()
-        except:
-            GMessage(parent = self,
-                     message = _("No vector map selected for editing.1"))
+        mapLayer = self.toolbar.GetMapName()
+        if not mapLayer:
+            GError(parent = self, message = _("No raster map selected for editing."))
             event.Skip()
             return
         
@@ -230,25 +228,15 @@
                                  "Choose appropriate tool from digitizer toolbar."))
             event.Skip()
             return
-        
-        if action not in ("moveVertex",
-                          "addVertex",
-                          "removeVertex",
-                          "editLine"):
-            # set pen
-            self.pen = wx.Pen(colour = UserSettings.Get(group = 'vdigit', key = 'symbol',
-                                                        subkey = ['newSegment', 'color']),
-                              width = 2, style = wx.SHORT_DASH)
-            self.polypen = wx.Pen(colour = UserSettings.Get(group = 'vdigit', key = 'symbol',
-                                                            subkey = ['newLine', 'color']),
-                                  width = 2, style = wx.SOLID)
-        
-        if action in ("addVertex",
-                      "removeVertex",
-                      "splitLines"):
-            # unselect
-            self.digit.GetDisplay().SetSelected([])
-        
+
+        # set pen
+        self.pen = wx.Pen(colour = UserSettings.Get(group = 'vdigit', key = 'symbol',
+                                                    subkey = ['newSegment', 'color']),
+                          width = 2, style = wx.SHORT_DASH)
+        self.polypen = wx.Pen(colour = UserSettings.Get(group = 'vdigit', key = 'symbol',
+                                                        subkey = ['newLine', 'color']),
+                              width = 2, style = wx.SOLID)
+  
         if action == "addLine":
             self.OnLeftDownAddLine(event)
             
@@ -271,7 +259,7 @@
             
 
     def OnLeftUpVarious(self, event):
-        """!Left mouse button released - vector digitizer various
+        """!Left mouse button released - raster digitizer various
         actions
         """
         pos1 = self.Pixel2Cell(self.mouse['begin'])
@@ -338,12 +326,10 @@
         if action == "addLine" and \
                 self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
             # -> add new line / boundary
-            try:
-                mapName = self.toolbar.GetMapName()
-            except:
-                mapName = None
-                GError(parent = self,
-                       message = _("No vector map selected for editing.2"))
+            mapName = self.toolbar.GetMapName()
+            if not mapName:
+                GError(parent = self, message = _("No raster map selected for editing."))
+                return
                                  
             if mapName:
                 if len(self.polycoords) < 2: # ignore 'one-point' lines
@@ -358,14 +344,12 @@
                         self.existingCoords.append(c)
                     
                     self.existingCoords.append(wx.Point(x0,y0))
-
                     coordIdx = dict()
                     coordIdx[self.idx] = self.existingCoords
                     self.polygons.append(coordIdx)
                     self.idx = self.idx+1
                     self.existingCoords = []
 
-
                 if self.toolbar.GetAction('type') == 'line':
                     for coord in self.polycoords:
                         x,y = coord #self.Cell2Pixel(coord)
@@ -377,8 +361,7 @@
                     self.polygons.append(coordIdx)
                     self.idx = self.idx+1
                     self.existingCoords = []
-                    
-                    
+
                 #Update Map 
                 self.polycoords = []
                 self.UpdateMap(render = False)
@@ -386,7 +369,7 @@
                 self.Refresh()                
 
         elif action in ["deleteArea", "deleteLine"]:
-            # -> delete selected vector features
+            # -> delete selected raster features
             x,y = event.GetPositionTuple()
             ids = self.pdcVector.FindObjectsByBBox(x,y)
             idx = ids[0]
@@ -402,7 +385,6 @@
                 if idx != id:
                     self.polygons.append(poly)            
 
-
         elif action == "deleteCircle":
             x,y = event.GetPositionTuple()
             ids = self.pdcVector.FindObjectsByBBox(x,y)
@@ -421,8 +403,7 @@
                 id = circle.keys()[0]
                 if idx != id:
                     self.circles.append(circle)                
- 
-        
+
     def _onMouseMoving(self, event):
         self.mouse['end'] = event.GetPositionTuple()[:]
         
@@ -434,7 +415,6 @@
                 self.toolbar.GetAction('type') in ["line", "boundary", "area"]:
             if len(self.polycoords) > 0:
                 self.MouseDraw(pdc = self.pdcTmp, begin = self.Cell2Pixel(self.polycoords[-1]))
-                
 
             self.Refresh() # TODO: use RefreshRect()
             self.mouse['begin'] = self.mouse['end']

Modified: grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/toolbars.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/toolbars.py	2012-12-20 08:58:40 UTC (rev 54353)
+++ grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/toolbars.py	2012-12-20 11:26:41 UTC (rev 54354)
@@ -203,7 +203,7 @@
     def OnTool(self, event):
         """!Tool selected -> untoggles previusly selected tool in
         toolbar"""
-        # set cursor
+        # set cursor  
         cursor = self.parent.cursors["cross"]
         self.MapWindow.SetCursor(cursor)
         

Modified: grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/wxdigit.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/wxdigit.py	2012-12-20 08:58:40 UTC (rev 54353)
+++ grass-addons/grass7/gui/wxpython/wx.rdigit/rdigit/wxdigit.py	2012-12-20 11:26:41 UTC (rev 54354)
@@ -1,5 +1,5 @@
 """!
- at package vdigit.wxdigit
+ at package rdigit.wxdigit
 
 @brief wxGUI raster digitizer (base class)
 
@@ -13,7 +13,6 @@
 (>=v2). Read the file COPYING that comes with GRASS for details.
 
 @author Mohammed Rashad <rashadkm gmail.com>
- at author Martin Landa <landa.martin gmail.com>(original wxvdigit)
 """
 
 import grass.script.core as grass
@@ -34,14 +33,12 @@
 except ImportError:
     pass
 
-
 class RasterObject:
   def __init__(self,cat,coords,ft):
     self.catId = cat
     self.coords = coords
     self.ftype = ft
-  
-        
+
 class IRDigit:
     def __init__(self, mapwindow):
         """!Base class for vector digitizer (ctypes interface)
@@ -49,27 +46,20 @@
         @param mapwindow reference for map window (BufferedWindow)
         """
         self.mapWindow = mapwindow
-        
         self.objects = list()
-
         self.toolbar = mapwindow.parent.toolbars['rdigit']
-   
         self.polyfile = tempfile.NamedTemporaryFile(delete=False)
         
         Debug.msg(2, "IRDigit.__init__() %s ", self.polyfile.name)
  
         self.cat = 1
         self.saveMap = True
-        
         self.outputName = None
-
         
-        
     def __del__(self):
-        Debug.msg(1, "IVDigit.__del__()")
+        Debug.msg(1, "IRDigit.__del__()")
         
         if self.saveMap == True:
-        
             for obj in self.objects:
                 if obj.ftype == GV_BOUNDARY:
                     self.polyfile.write("AREA\n");
@@ -89,14 +79,12 @@
                 self.polyfile.write(catbuf);
 
             self.polyfile.close()
-
             region_settings = grass.parse_command('g.region', flags = 'p', delimiter = ':')
             RunCommand('r.in.poly', input=self.polyfile.name, 
                                     rows=region_settings['rows'], output=self.getOutputName(),overwrite=True)
             
             os.unlink(self.polyfile.name)
 
-
     def setOutputName(self, name):
       if name:
         self.outputName = name
@@ -119,16 +107,10 @@
         
         @return tuple (number of added features, feature ids)
         """
-        
-        #layer = self._getNewFeaturesLayer()
-        #cat = self._getNewFeaturesCat()
-        
         if ftype == 'point':
             vtype = GV_POINT
         elif ftype == 'line':
             vtype = GV_LINE
-        elif ftype == 'centroid':
-            vtype = GV_CENTROID
         elif ftype == 'boundary':
             vtype = GV_BOUNDARY
         elif ftype == 'area':
@@ -139,17 +121,14 @@
             GError(parent = self.mapWindow,
                    message = _("Unknown feature type '%s'") % ftype)
             return (-1, None)
-            
-        Debug.msg(2, "IRRDigit1()")            
+         
         
         if vtype & GV_LINES and len(points) < 2:
             GError(parent = self.mapWindow,
                    message = _("Not enough points for line"))
             return (-1, None)
-        
+            
         self.toolbar.EnableUndo()
-        
-        
         return self._addFeature(vtype, points)
 
     def _checkMap(self):
@@ -176,26 +155,18 @@
 
         @param ftype feature type (GV_POINT, GV_LINE, GV_BOUNDARY, ...)
         @coords tuple of coordinates ((x, y), (x, y), ...)
-        @param layer layer number (-1 for no cat)
-        @param cat category number
-        @param snap snap to node/vertex
         @param threshold threshold for snapping
-        
-        @return tuple (number of added features, list of fids)
-        @return number of features -1 on error
         """
-
         if not self._checkMap():
             return (-1, None)
         
-        #is3D = bool(Vect_is_3d(self.poMapInfo))
-        
-        Debug.msg(2, "IVDigit._addFeature(): npoints=%d, ftype=%d",
-                  len(coords), ftype)
-        
         obj = RasterObject(self.cat, coords,ftype)
         self.objects.append(obj)
-        self.cat = self.cat + 1    
+        self.cat = self.cat + 1 
+
+        Debug.msg(2, "IRDigit._addFeature(): npoints=%d, ftype=%d, catId=%d",
+                  len(coords), ftype,self.cat)        
+           
         return self.cat - 1
     
 

Modified: grass-addons/grass7/gui/wxpython/wx.rdigit/toolbars.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.rdigit/toolbars.py	2012-12-20 08:58:40 UTC (rev 54353)
+++ grass-addons/grass7/gui/wxpython/wx.rdigit/toolbars.py	2012-12-20 11:26:41 UTC (rev 54354)
@@ -25,50 +25,29 @@
 
 import grass.script as grass
 
-iClassIcons = {
-        'opacity' : MetaIcon(img = 'layer-opacity',
-                             label = _('Set opacity level')),
-        'tools' : MetaIcon(img = 'tools',
-                                  label = _('Load Digitizer tools')),
-        'selectGroup' : MetaIcon(img = 'layer-group-add',
-                                 label = _('Select imagery group')),
-        'run' : MetaIcon(img = 'execute',
-                         label = _('Run analysis')),
-        'sigFile' : MetaIcon(img = 'script-save',
-                             label = _('Save signature file')),
+rdigitIcons = {
         'delCmd' : MetaIcon(img = 'layer-remove',
                             label = _('Delete selected map layer')),
-        'exportAreas' : MetaIcon(img = 'layer-export',
-                            label = _('Export training areas')),
-        'importAreas' : MetaIcon(img = 'layer-import',
-                            label = _('Import training areas')),
+
         }
         
 class RDigitMapToolbar(BaseToolbar):
-    """!IClass Map toolbar
-    """
+    """!RDigit Map toolbar """
     def __init__(self, parent):
-        """!IClass Map toolbar constructor
-        """
+        """!RDigit Map toolbar constructor"""
         BaseToolbar.__init__(self, parent)
         
         self.InitToolbar(self._toolbarData())
-        
 
-
         # realize the toolbar
         self.Realize()
         
         self.action = { 'id' : self.pan }
         self.defaultAction = { 'id' : self.pan,
                                'bind' : self.parent.OnPan }
-        
         self.OnTool(None)
-        
         self.EnableTool(self.zoomBack, False)
-        
-
-        
+ 
     def _toolbarData(self):
         """!Toolbar data"""
         icons = BaseIcons
@@ -94,16 +73,8 @@
                                      ("zoomBack", icons["zoomBack"],
                                       self.parent.OnZoomBack),
                                      ("zoomToMap", icons["zoomExtent"],
-                                      self.parent.OnZoomToMap),
-                                      
-                                     ("drawArea", iClassIcons["tools"],
-                                     self.parent.OnDrawArea),                                
-                                    ))
+                                      self.parent.OnZoomToMap) ))
 
-        
-
-
-        
 class RDigitMapManagerToolbar(BaseToolbar):
     """!IClass toolbar
     """
@@ -114,9 +85,7 @@
         
         self.InitToolbar(self._toolbarData())
         self.choice = wx.Choice(parent = self, id = wx.ID_ANY, size = (300, -1))
-        
         self.choiceid = self.AddControl(self.choice)
-        
         self.choice.Bind(wx.EVT_CHOICE, self.OnSelectLayer)
         
         self.mapManager = mapManager
@@ -127,10 +96,8 @@
         """!Toolbar data"""
         return self._getToolbarData((("addRast", BaseIcons['addRast'],
                                       self.OnAddRast),
-                                      ("delRast", iClassIcons['delCmd'],
-                                      self.OnDelRast),
-
-                                    ))
+                                      ("delRast", rdigitIcons['delCmd'],
+                                      self.OnDelRast)))
                                     
     def OnSelectLayer(self, event):
         layer = self.choice.GetStringSelection()



More information about the grass-commit mailing list