[GRASS-SVN] r54405 - in grass/trunk/gui/wxpython: iclass vdigit
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Dec 26 03:00:13 PST 2012
Author: martinl
Date: 2012-12-26 03:00:12 -0800 (Wed, 26 Dec 2012)
New Revision: 54405
Modified:
grass/trunk/gui/wxpython/iclass/digit.py
grass/trunk/gui/wxpython/iclass/frame.py
grass/trunk/gui/wxpython/vdigit/wxdigit.py
Log:
wxGUI/iclass: colorize areas
Modified: grass/trunk/gui/wxpython/iclass/digit.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/digit.py 2012-12-25 21:58:50 UTC (rev 54404)
+++ grass/trunk/gui/wxpython/iclass/digit.py 2012-12-26 11:00:12 UTC (rev 54405)
@@ -19,9 +19,10 @@
import wx
from vdigit.mapwindow import VDigitWindow
-from vdigit.wxdigit import IVDigit
-
+from vdigit.wxdigit import IVDigit
+from vdigit.wxdisplay import DisplayDriver, TYPE_AREA
try:
+ from grass.lib.vector import *
from grass.lib.vedit import *
except ImportError:
pass
@@ -79,11 +80,16 @@
It is taken from parent's toolbar.
"""
return self.parent.GetToolbar("iClass").GetSelectedCategoryIdx()
+
+ def GetCategoryColor(self, cat):
+ """!Get color associated with given category"""
+ r, g, b = map(int, self.parent.GetClassColor(cat).split(':'))
+ return wx.Colour(r, g, b)
class IClassVDigit(IVDigit):
"""! Class similar to IVDigit but specialized for wxIClass."""
def __init__(self, mapwindow):
- IVDigit.__init__(self, mapwindow)
+ IVDigit.__init__(self, mapwindow, driver = IClassDisplayDriver)
self._settings['closeBoundary'] = True # snap to the first node
def _getNewFeaturesLayer(self):
@@ -98,7 +104,36 @@
@param cats list of categories
"""
-
for cat in cats:
Vedit_delete_areas_cat(self.poMapInfo, 1, cat)
+
+class IClassDisplayDriver(DisplayDriver):
+ """! Class similar to DisplayDriver but specialized for wxIClass
+
+ @todo needs refactoring (glog, gprogress)
+ """
+ def __init__(self, device, deviceTmp, mapObj, window, glog, gprogress):
+ DisplayDriver.__init__(self, device, deviceTmp, mapObj, window, glog, gprogress)
+ self._cat = -1
+ def _drawObject(self, robj):
+ """!Draw given object to the device
+
+ @param robj object to draw
+ """
+ if robj.type == TYPE_AREA:
+ self._cat = Vect_get_area_cat(self.poMapInfo, robj.fid, 1)
+ DisplayDriver._drawObject(self, robj)
+
+ def _definePen(self, rtype):
+ """!Define pen/brush based on rendered object)
+
+ @param rtype type of the object
+
+ @return pen, brush
+ """
+ pen, brush = DisplayDriver._definePen(self, rtype)
+ if self._cat > 0 and rtype == TYPE_AREA:
+ brush = wx.Brush(self.window.GetCategoryColor(self._cat), wx.SOLID)
+
+ return pen, brush
Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py 2012-12-25 21:58:50 UTC (rev 54404)
+++ grass/trunk/gui/wxpython/iclass/frame.py 2012-12-26 11:00:12 UTC (rev 54405)
@@ -374,6 +374,17 @@
"""!Returns toolbar with zooming tools"""
return self.toolbars['iClassMap']
+ def GetClassColor(self, cat):
+ """!Get class color as string
+
+ @param cat class category
+
+ @return 'R:G:B'
+ """
+ if cat in self.statisticsDict:
+ return self.statisticsDict[cat].color
+ return '0:0:0'
+
def OnZoomMenu(self, event):
"""!Popup Zoom menu """
zoommenu = wx.Menu()
Modified: grass/trunk/gui/wxpython/vdigit/wxdigit.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/wxdigit.py 2012-12-25 21:58:50 UTC (rev 54404)
+++ grass/trunk/gui/wxpython/vdigit/wxdigit.py 2012-12-26 11:00:12 UTC (rev 54405)
@@ -125,7 +125,7 @@
caption = self.caption)
class IVDigit:
- def __init__(self, mapwindow):
+ def __init__(self, mapwindow, driver = DisplayDriver):
"""!Base class for vector digitizer (ctypes interface)
@param mapwindow reference for map window (BufferedWindow)
@@ -150,12 +150,12 @@
self._error = VDigitError(parent = self.mapWindow)
- self._display = DisplayDriver(device = mapwindow.pdcVector,
- deviceTmp = mapwindow.pdcTmp,
- mapObj = mapwindow.Map,
- window = mapwindow,
- glog = log,
- gprogress = progress)
+ self._display = driver(device = mapwindow.pdcVector,
+ deviceTmp = mapwindow.pdcTmp,
+ mapObj = mapwindow.Map,
+ window = mapwindow,
+ glog = log,
+ gprogress = progress)
# GRASS lib
self.poPoints = Vect_new_line_struct()
More information about the grass-commit
mailing list