[GRASS-SVN] r44985 - in grass/trunk/gui: icons/grass2 wxpython/gui_modules wxpython/icons

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 12 07:24:28 EST 2011


Author: martinl
Date: 2011-01-12 04:24:28 -0800 (Wed, 12 Jan 2011)
New Revision: 44985

Added:
   grass/trunk/gui/icons/grass2/boundary-create.png
Modified:
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/toolbars.py
   grass/trunk/gui/wxpython/gui_modules/vdigit.py
   grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
   grass/trunk/gui/wxpython/icons/grass2_icons.py
   grass/trunk/gui/wxpython/icons/grass_icons.py
   grass/trunk/gui/wxpython/icons/icon.py
   grass/trunk/gui/wxpython/icons/silk_icons.py
Log:
wxGUI/vdigit: digitize new area


Added: grass/trunk/gui/icons/grass2/boundary-create.png
===================================================================
(Binary files differ)


Property changes on: grass/trunk/gui/icons/grass2/boundary-create.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -1295,7 +1295,7 @@
                 if addRecordDlg.mapDBInfo:
                     self.__updateATM()
         
-        elif digitToolbar.GetAction('type') in ["line", "boundary"]:
+        elif digitToolbar.GetAction('type') in ["line", "boundary", "area"]:
             # add new point to the line
             self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
             self.DrawLines(pdc = self.pdcTmp)
@@ -2105,7 +2105,7 @@
             digitClass = self.parent.digit
             # digitization tool (confirm action)
             if digitToolbar.GetAction() == "addLine" and \
-                    digitToolbar.GetAction('type') in ["line", "boundary"]:
+                    digitToolbar.GetAction('type') in ["line", "boundary", "area"]:
                 # -> add new line / boundary
                 try:
                     map = digitToolbar.GetLayer().GetName()
@@ -2281,7 +2281,7 @@
         if self.mouse["use"] == "pointer" and digitToolbar:
             digitClass = self.parent.digit
             if (digitToolbar.GetAction() == "addLine" and \
-                    digitToolbar.GetAction('type') in ["line", "boundary"]) or \
+                    digitToolbar.GetAction('type') in ["line", "boundary", "area"]) or \
                     digitToolbar.GetAction() == "editLine":
                 # add line or boundary -> remove last point from the line
                 try:
@@ -2381,7 +2381,8 @@
             self.mouse['end'] = event.GetPositionTuple()[:]
             Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
                            (self.mouse['end'][0], self.mouse['end'][1]))
-            if digitToolbar.GetAction() == "addLine" and digitToolbar.GetAction('type') in ["line", "boundary"]:
+            if digitToolbar.GetAction() == "addLine" and \
+                    digitToolbar.GetAction('type') in ["line", "boundary", "area"]:
                 if len(self.polycoords) > 0:
                     self.MouseDraw(pdc = self.pdcTmp, begin = self.Cell2Pixel(self.polycoords[-1]))
             elif digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] \

Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -330,14 +330,6 @@
                 'delRecord' : {
                     'enabled' : True
                     },
-                # add centroid to left/right area
-                'addCentroid' : {
-                    'enabled' : False
-                    },
-                # do not attach category to boundary
-                'catBoundary' : {
-                    'enabled' : False
-                    },
                 # query tool
                 'query' : {
                     'selection' : 0,

Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -678,6 +678,7 @@
         self.addLine = wx.NewId()
         self.addBoundary = wx.NewId()
         self.addCentroid = wx.NewId()
+        self.addArea = wx.NewId()
         self.moveVertex = wx.NewId()
         self.addVertex = wx.NewId()
         self.removeVertex = wx.NewId()
@@ -706,6 +707,9 @@
                 (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
                  wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
                  self.OnAddCentroid),
+                (self.addArea, "digAddArea", Icons["digAddArea"].GetBitmap(),
+                 wx.ITEM_CHECK, Icons["digAddArea"].GetLabel(), Icons["digAddArea"].GetDesc(),
+                 self.OnAddArea),
                 (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
                  wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
                  self.OnMoveVertex),
@@ -829,6 +833,14 @@
                         'id'   : self.addCentroid }
         self.parent.MapWindow.mouse['box'] = 'point'
 
+    def OnAddArea(self, event):
+        """!Add area to the vector map layer"""
+        Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
+        self.action = { 'desc' : "addLine",
+                        'type' : "area",
+                        'id'   : self.addArea }
+        self.parent.MapWindow.mouse['box'] = 'line'
+
     def OnExit (self, event=None):
         """!Quit digitization tool"""
         # stop editing of the currently selected map layer
@@ -1777,7 +1789,7 @@
              self.parent.OnNewMenu),
             ('', '', '', '', '', '', ''),
             (self.workspaceLoad, 'workspaceLoad', Icons["workspaceLoad"].GetBitmap(),
-             wx.ITEM_NORMAL, _("Load (and import) map layers into workspace"), '',
+             wx.ITEM_NORMAL, _("Load / import map layers into workspace"), '',
              self.parent.OnLoadMenu),
             (self.workspaceOpen, 'workspaceOpen', Icons["workspaceOpen"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["workspaceOpen"].GetLabel(), Icons["workspaceOpen"].GetDesc(),

Modified: grass/trunk/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/vdigit.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/gui_modules/vdigit.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -70,8 +70,7 @@
         # notebook
         notebook = wx.Notebook(parent = self, id = wx.ID_ANY, style = wx.BK_DEFAULT)
         self.__CreateSymbologyPage(notebook)
-        if not UserSettings.Get(group = 'vdigit', key = 'categoryMode', subkey = 'selection'):
-            self.parent.digit.SetCategoryNextToUse()
+        self.parent.digit.SetCategory()
         self.__CreateGeneralPage(notebook)
         self.__CreateAttributesPage(notebook)
         self.__CreateQueryPage(notebook)
@@ -427,26 +426,6 @@
                    flag = wx.ALL | wx.EXPAND, border = 5)
 
         #
-        # digitize new area
-        #
-        box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Digitize new area"))
-        sizer = wx.StaticBoxSizer(box, wx.VERTICAL)
-        
-        # add centroid
-        self.addCentroid = wx.CheckBox(parent = panel, id = wx.ID_ANY,
-                                       label = _("Add centroid to left/right area"))
-        self.addCentroid.SetValue(UserSettings.Get(group = 'vdigit', key = "addCentroid", subkey = 'enabled'))
-        sizer.Add(item = self.addCentroid, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
-        
-        # attach category to boundary
-        self.catBoundary = wx.CheckBox(parent = panel, id = wx.ID_ANY,
-                                       label = _("Do not attach category to boundaries"))
-        self.catBoundary.SetValue(UserSettings.Get(group = 'vdigit', key = "catBoundary", subkey = 'enabled'))
-        sizer.Add(item = self.catBoundary, proportion = 0, flag = wx.ALL | wx.EXPAND, border = 1)
-        border.Add(item = sizer, proportion = 0,
-                   flag = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border = 5)
-        
-        #
         # delete existing record
         #
         box   = wx.StaticBox (parent = panel, id = wx.ID_ANY, label = " %s " % _("Delete existing feature(s)"))
@@ -605,10 +584,10 @@
             self.category.Enable(True)
         elif self.category.IsEnabled(): # disable
             self.category.Enable(False)
-
+        
         if mode == 2 and self.addRecord.IsChecked(): # no category
             self.addRecord.SetValue(False)
-
+        
         self.parent.digit.SetCategory()
         self.category.SetValue(UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value'))
 
@@ -752,12 +731,6 @@
         UserSettings.Set(group = 'vdigit', key = "categoryMode", subkey = 'selection',
                          value = self.categoryMode.GetSelection())
 
-        # digitize new area
-        UserSettings.Set(group = 'vdigit', key = "addCentroid", subkey = 'enabled',
-                         value = self.addCentroid.IsChecked())
-        UserSettings.Set(group = 'vdigit', key = "catBoundary", subkey = 'enabled',
-                         value = self.catBoundary.IsChecked())
-        
         # delete existing feature
         UserSettings.Set(group = 'vdigit', key = "delRecord", subkey = 'enabled',
                          value = self.deleteRecord.IsChecked())
@@ -825,7 +798,7 @@
         UserSettings.Set(group = 'vdigit', key = "breakLines", subkey = 'enabled',
                          value = self.intersect.IsChecked())
         
-        self.parent.digit.GetDisplay().UpdateSettings()
+        self.parent.digit.UpdateSettings()
         
         # redraw map if auto-rendering is enabled
         if self.parent.statusbarWin['render'].GetValue(): 

Modified: grass/trunk/gui/wxpython/gui_modules/wxvdigit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/gui_modules/wxvdigit.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -104,6 +104,14 @@
                parent  = self.parent,
                caption = self.caption)
 
+    def FeatureType(self, ftype):
+        """!Unknown feature type
+        """
+        GError(message = _("Unsupported feature type %d. "
+                           "Operation cancelled.") % ftype,
+               parent  = self.parent,
+               caption = self.caption)
+        
 class IVDigit:
     def __init__(self, mapwindow):
         """!Base class for vector digitizer (ctypes interface)
@@ -145,12 +153,8 @@
         # layer / max category
         self.cats = dict()
         
-        # settings
-        self.settings = {
-            'breakLines'  : False,
-            'addCentroid' : False,
-            'catBoundary' : True,
-            }
+        self._settings = dict()
+        self.UpdateSettings() # -> self._settings
         
         # undo/redo
         self.changesets = dict()
@@ -362,7 +366,7 @@
             cat   = -1
         else:
             layer = UserSettings.Get(group = 'vdigit', key = "layer", subkey = 'value')
-            cat   = self.cats.get(layer, 1)
+            cat   = self.SetCategory()
         
         if ftype == 'point':
             vtype = GV_POINT
@@ -372,6 +376,8 @@
             vtype = GV_CENTROID
         elif ftype == 'boundary':
             vtype = GV_BOUNDARY
+        elif ftype == 'area':
+            vtype = GV_AREA
         else:
             GError(parent = self.mapWindow,
                    message = _("Unknown feature type '%s'") % ftype)
@@ -505,7 +511,7 @@
         else:
             del self.changesets[changeset]
         
-        if nlines > 0 and self.settings['breakLines']:
+        if nlines > 0 and self._settings['breakLines']:
             for i in range(1, nlines):
                 self._breakLineAtIntersection(nlines + i, None, changeset)
         
@@ -552,7 +558,7 @@
         else:
             del self.changesets[changeset]
         
-        if moved > 0 and self.settings['breakLines']:
+        if moved > 0 and self._settings['breakLines']:
             self._breakLineAtIntersection(Vect_get_num_lines(self.poMapInfo),
                                           None, changeset)
         
@@ -812,7 +818,7 @@
         else:
             del self.changesets[changeset]
 
-        if ret > 0 and self.poBgMapInfo and self.settings['breakLines']:
+        if ret > 0 and self.poBgMapInfo and self._settings['breakLines']:
             for i in range(1, ret):
                 self._breakLineAtIntersection(nlines + i, None, changeset)
         
@@ -1167,10 +1173,10 @@
         
         return True
 
-    def _addFeature(self, type, coords, layer, cat, snap, threshold):
+    def _addFeature(self, ftype, coords, layer, cat, snap, threshold):
         """!Add new feature to the vector map
 
-        @param type feature type (GV_POINT, GV_LINE, GV_BOUNDARY, ...)
+        @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
@@ -1188,23 +1194,22 @@
         Debug.msg(2, "IVDigit._addFeature(): npoints=%d, layer=%d, cat=%d, snap=%d",
                   len(coords), layer, cat, snap)
         
-        if not (type & (GV_POINTS | GV_LINES)): # TODO: 3D
+        if not (ftype & (GV_POINTS | GV_LINES | GV_AREA)): # TODO: 3D
+            self._error.FeatureType(ftype)
             return -1
         
         # set category
         Vect_reset_cats(self.poCats)
-        if layer > 0 and \
-                (type != GV_BOUNDARY or \
-                     (type == GV_BOUNDARY and self.settings['catBoundary'])):
+        if layer > 0 and ftype != GV_AREA:
             Vect_cat_set(self.poCats, layer, cat)
-            self.cats[layer] = max(cat, self.cats.get(layer, 0))
+            self.cats[layer] = max(cat, self.cats.get(layer, 1))
         
         # append points
         Vect_reset_line(self.poPoints)
         for c in coords:
             Vect_append_point(self.poPoints, c[0], c[1], 0.0)
         
-        if type & GV_BOUNDARY:
+        if ftype & (GV_BOUNDARY | GV_AREA):
             # close boundary
             points = self.poPoints.contents
             last = points.n_points - 1
@@ -1215,19 +1220,23 @@
                 points.y[last] = points.y[0]
                 points.z[last] = points.z[0]
         
-        if snap != NO_SNAP and (type & (GV_POINT | GV_LINES)):
+        if snap != NO_SNAP:
             # apply snapping (node or vertex)
             modeSnap = not (snap == SNAP)
             Vedit_snap_line(self.poMapInfo, self.popoBgMapInfo, int(self.poBgMapInfo is not None),
                             -1, self.poPoints, threshold, modeSnap)
         
-        newline = Vect_write_line(self.poMapInfo, type, self.poPoints, self.poCats)
+        if ftype == GV_AREA:
+            ltype = GV_BOUNDARY
+        else:
+            ltype = ftype
+        newline = Vect_write_line(self.poMapInfo, ltype, self.poPoints, self.poCats)
         if newline < 0:
             self._error.WriteLine()
             return -1
         
         left = right = -1
-        if type & GV_BOUNDARY and self.settings['addCentroid']:
+        if ftype & GV_AREA:
             # add centroids for left/right area
             bpoints = Vect_new_line_struct()
             cleft = c_int()
@@ -1272,14 +1281,9 @@
         self._addActionToChangeset(len(self.changesets), newline, add = True)
         
         # break at intersection
-        if self.settings['breakLines']:
+        if self._settings['breakLines']:
             self._breakLineAtIntersection(newline, self.poPoints, changeset)
         
-        if type & GV_BOUNDARY and \
-                not self.settings['catBoundary'] and \
-        	left < 1 and right < 1:
-            newline = None # ?
-        
         return newline
     
     def _ModifyLineVertex(self, coords, add = True):
@@ -1323,7 +1327,7 @@
         else:
             del self.changesets[changeset]
         
-        if not add and ret > 0 and self.settings['breakLines']:
+        if not add and ret > 0 and self._settings['breakLines']:
             self._breakLineAtIntersection(Vect_get_num_lines(self.poMapInfo),
                                           None, changeset)
                 
@@ -1372,36 +1376,43 @@
         """
         return self.cats.keys()
     
-    def UpdateSettings(self, breakLines, addCentroid, catBoundary):
-        """!Update digit settings
-        
-        @param breakLines break lines on intersection
-        @param addCentroid add centroid to left/right area
-        @param catBoundary attach category to boundary
+    def UpdateSettings(self):
+        """!Update digit (and display) settings
         """
-        self._settings['breakLines']  = breakLines
-        self._settings['addCentroid'] = addCentroid
-        self._settings['catBoundary'] = None # !catBoundary # do not attach
-
-    def _getCategory(self):
-        """!Get current category number to be use"""
-        if not UserSettings.Get(group = 'vdigit', key = 'categoryMode', subkey = 'selection'):
-            self.SetCategoryNextToUse()
+        self._display.UpdateSettings()
         
-        return UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value')
-
-    def SetCategoryNextToUse(self):
+        self._settings['breakLines']  = bool(UserSettings.Get(group = 'vdigit', key = "breakLines",
+                                                              subkey = 'enabled'))
+        
+    def SetCategory(self):
+        """!Update self.cats based on settings"""
+        sel = UserSettings.Get(group = 'vdigit', key = 'categoryMode', subkey = 'selection')
+        cat = None
+        if sel == 0: # next to usep
+            cat = self._setCategoryNextToUse()
+        elif sel == 1:
+            cat = UserSettings.Get(group = 'vdigit', key = 'category', subkey = 'value')
+        
+        if cat:
+            layer = UserSettings.Get(group = 'vdigit', key = 'layer', subkey = 'value')
+            self.cats[layer] = cat
+        
+        return cat
+    
+    def _setCategoryNextToUse(self):
         """!Find maximum category number for the given layer and
         update the settings
+
+        @return category to be used
         """
-        # reset 'category' to '1' (for maps with no attributes)
-        UserSettings.Set(group = 'vdigit', key = 'category', subkey = 'value', value = 1)
-        
         # get max category number for given layer and update the settings
-        cat = self.cats.get(UserSettings.Get(group = 'vdigit', key = 'layer', subkey = 'value'), 0)
-        cat += 1
+        layer = UserSettings.Get(group = 'vdigit', key = 'layer', subkey = 'value')
+        cat = self.cats.get(layer, 0) + 1
         UserSettings.Set(group = 'vdigit', key = 'category', subkey = 'value',
                          value = cat)
+        Debug.msg(1, "IVDigit._setCategoryNextToUse(): cat=%d", cat)
+        
+        return cat
 
     def SelectLinesFromBackgroundMap(self, bbox):
         """!Select features from background map

Modified: grass/trunk/gui/wxpython/icons/grass2_icons.py
===================================================================
--- grass/trunk/gui/wxpython/icons/grass2_icons.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/icons/grass2_icons.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -43,8 +43,9 @@
     ## add feature
     "digAddPoint": 'point-create.png',
     "digAddLine" : 'line-create.png',
-    "digAddBoundary": 'polygon-create.png',
+    "digAddBoundary": 'boundary-create.png',
     "digAddCentroid": 'centroid-create.png',
+    "digAddArea": 'polygon-create.png',
     ## vertex
     "digAddVertex" : 'vertex-create.png',
     "digMoveVertex" : 'vertex-move.png',

Modified: grass/trunk/gui/wxpython/icons/grass_icons.py
===================================================================
--- grass/trunk/gui/wxpython/icons/grass_icons.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/icons/grass_icons.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -33,6 +33,7 @@
     "digAddLine" : 'new.line.gif',
     "digAddBoundary": 'new.boundary.gif',
     "digAddCentroid": 'new.centroid.gif',
+    "digAddArea": wx.ART_ERROR, # FIXME
     ## vertex
     "digAddVertex" : 'add.vertex.gif',
     "digMoveVertex" : 'move.vertex.gif',

Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/icons/icon.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -258,6 +258,9 @@
     "digAddCentroid": MetaIcon (img=Icons["digAddCentroid"],
                                 label=_("Digitize new centroid"),
                              desc=_("Left: new point")),
+    "digAddArea": MetaIcon (img=Icons["digAddArea"],
+                                label=_("Digitize new area (composition of bondaries without category and one centroid with category)"),
+                             desc=_("Left: new point")),
     "digAddVertex": MetaIcon (img=Icons["digAddVertex"],
                               label=_("Add new vertex"),
                               desc=_("Left: Select; Middle: Unselect; Right: Confirm")),

Modified: grass/trunk/gui/wxpython/icons/silk_icons.py
===================================================================
--- grass/trunk/gui/wxpython/icons/silk_icons.py	2011-01-12 10:43:50 UTC (rev 44984)
+++ grass/trunk/gui/wxpython/icons/silk_icons.py	2011-01-12 12:24:28 UTC (rev 44985)
@@ -48,6 +48,7 @@
     "digAddLine" : 'vector_add.png',
     "digAddBoundary": 'shape_handles.png',
     "digAddCentroid": 'shape_square_add.png',
+    "digAddArea": wx.ART_ERROR,
     ## vertex
     "digAddVertex" : 'chart_line_add.png',
     "digMoveVertex" : 'chart_line.png',



More information about the grass-commit mailing list