[GRASS-SVN] r58533 - grass/trunk/gui/wxpython/mapwin
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Dec 26 18:24:42 PST 2013
Author: annakrat
Date: 2013-12-26 18:24:42 -0800 (Thu, 26 Dec 2013)
New Revision: 58533
Modified:
grass/trunk/gui/wxpython/mapwin/analysis.py
grass/trunk/gui/wxpython/mapwin/buffered.py
grass/trunk/gui/wxpython/mapwin/graphics.py
Log:
wxGUI/mapwin: DrawCircle added and specify which coordinate type is to be used for GraphicsSet
Modified: grass/trunk/gui/wxpython/mapwin/analysis.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/analysis.py 2013-12-26 22:22:29 UTC (rev 58532)
+++ grass/trunk/gui/wxpython/mapwin/analysis.py 2013-12-27 02:24:42 UTC (rev 58533)
@@ -125,7 +125,8 @@
self._oldMouseUse = self._mapWindow.mouse['use']
self._oldCursor = self._mapWindow.GetNamedCursor()
- self._registeredGraphics = self._mapWindow.RegisterGraphicsToDraw(graphicsType='line')
+ self._registeredGraphics = self._mapWindow.RegisterGraphicsToDraw(graphicsType='line',
+ mapCoords=False)
self._connectAll()
Modified: grass/trunk/gui/wxpython/mapwin/buffered.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/buffered.py 2013-12-26 22:22:29 UTC (rev 58532)
+++ grass/trunk/gui/wxpython/mapwin/buffered.py 2013-12-27 02:24:42 UTC (rev 58533)
@@ -322,7 +322,16 @@
y2 = max(ylist)
pdc.SetIdBounds(drawid, wx.Rect(x1,y1,x2,y2))
# self.ovlcoords[drawid] = [x1,y1,x2,y2]
-
+
+ elif pdctype == 'circle': # draw circle
+ if pen:
+ pdc.SetPen(pen)
+ pdc.SetBrush(wx.TRANSPARENT_BRUSH)
+ radius = abs(coords[2] - coords[0]) / 2
+ pdc.DrawCircle(max(coords[0], coords[2]) - radius,
+ max(coords[1], coords[3]) - radius, radius=radius)
+ pdc.SetIdBounds(drawid, wx.Rect(coords[0], coords[1], coords[2], coords[3]))
+
elif pdctype == 'point': # draw point
if pen:
pdc.SetPen(pen)
@@ -942,7 +951,7 @@
@todo implement rotation
@param pdc PseudoDC
- @param coords center coordinates
+ @param coords center coordinates (pixel coordinates)
@param rotation rotate symbol
@param text draw also text (text, font, color, rotation)
@param textAlign alignment (default 'lower-right')
@@ -978,18 +987,31 @@
"""!Draw rectangle (not filled) in PseudoDC
@param pdc PseudoDC
- @param point1 top left corner (map coordinates)
- @param point2 bottom right corner (map coordinates)
+ @param point1 top left corner (pixel coordinates)
+ @param point2 bottom right corner (pixel coordinates)
@param pen pen
"""
Debug.msg(4, "BufferedWindow.DrawRectangle(): pdc=%s, point1=%s, point2=%s" % \
(pdc, point1, point2))
- x1, y1 = self.Cell2Pixel(point1)
- x2, y2 = self.Cell2Pixel(point2)
- coords = [x1, y1, x2, y2]
+ coords = [point1[0], point1[1], point2[0], point2[1]]
self.lineid = self.Draw(pdc, drawid=None, pdctype='box', coords=coords, pen=pen)
return self.lineid
+ def DrawCircle(self, pdc, coords, radius, pen=None):
+ """!Draw circle (not filled) in PseudoDC
+
+ @param pdc PseudoDC
+ @param coords center (pixel coordinates)
+ @param radius radius
+ @param pen pen
+ """
+ Debug.msg(4, "BufferedWindow.DrawCircle(): pdc=%s, coords=%s, radius=%s" %
+ (pdc, coords, radius))
+ newcoords = [coords[0] - radius, coords[1] - radius,
+ coords[0] + radius, coords[1] + radius]
+ self.lineid = self.Draw(pdc, drawid=None, pdctype='circle', coords=newcoords, pen=pen)
+ return self.lineid
+
def _computeZoomToPointAndRecenter(self, position, zoomtype):
"""!Computes zoom parameters for recenter mode.
@@ -1805,7 +1827,8 @@
"""!Get render.Map() instance"""
return self.Map
- def RegisterGraphicsToDraw(self, graphicsType, setStatusFunc = None, drawFunc = None):
+ def RegisterGraphicsToDraw(self, graphicsType, setStatusFunc=None, drawFunc=None,
+ mapCoords=True):
"""! This method registers graphics to draw.
@param type (string) - graphics type: "point", "line" or "rectangle"
@@ -1817,13 +1840,15 @@
@param drawFunc (function reference) - defines own function for drawing
If function is not defined DrawCross method is used for type "point",
DrawLines method for type "line", DrawRectangle for "rectangle".
-
+ @param mapCoords True if map coordinates should be set by user, otherwise pixels
+
@return reference to GraphicsSet, which was added.
"""
- item = GraphicsSet(parentMapWin = self,
- graphicsType = graphicsType,
- setStatusFunc = setStatusFunc,
- drawFunc = drawFunc)
+ item = GraphicsSet(parentMapWin=self,
+ graphicsType=graphicsType,
+ setStatusFunc=setStatusFunc,
+ drawFunc=drawFunc,
+ mapCoords=mapCoords)
self.graphicsSetList.append(item)
return item
Modified: grass/trunk/gui/wxpython/mapwin/graphics.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/graphics.py 2013-12-26 22:22:29 UTC (rev 58532)
+++ grass/trunk/gui/wxpython/mapwin/graphics.py 2013-12-27 02:24:42 UTC (rev 58533)
@@ -26,7 +26,7 @@
class GraphicsSet:
def __init__(self, parentMapWin, graphicsType,
- setStatusFunc=None, drawFunc=None):
+ setStatusFunc=None, drawFunc=None, mapCoords=True):
"""!Class, which contains instances of GraphicsSetItem and
draws them For description of parameters look at method
RegisterGraphicsToDraw in BufferedWindow class.
@@ -45,6 +45,7 @@
self.graphicsType = graphicsType
self.parentMapWin = parentMapWin
self.setStatusFunc = setStatusFunc
+ self.mapCoords = mapCoords
if drawFunc:
self.drawFunc = drawFunc
@@ -87,7 +88,10 @@
else:
self.parentMapWin.pen = self.pens["default"]
- coords = self.parentMapWin.Cell2Pixel(item.GetCoords())
+ if self.mapCoords:
+ coords = self.parentMapWin.Cell2Pixel(item.GetCoords())
+ else:
+ coords = item.GetCoords()
size = self.properties["size"]
self.properties["text"]['coords'] = [coords[0] + size, coords[1] + size, size, size]
@@ -104,8 +108,12 @@
self.parentMapWin.polypen = self.pens[item.GetPropertyVal("penName")]
else:
self.parentMapWin.polypen = self.pens["default"]
- coords = item.GetCoords()
+ if self.mapCoords:
+ coords = [self.parentMapWin.Cell2Pixel(coords) for coords in item.GetCoords()]
+ else:
+ coords = item.GetCoords()
+
self.drawFunc(pdc=pdc,
polycoords=coords)
@@ -114,7 +122,10 @@
pen = self.pens[item.GetPropertyVal("penName")]
else:
pen = self.pens["default"]
- coords = item.GetCoords()
+ if self.mapCoords:
+ coords = [self.parentMapWin.Cell2Pixel(coords) for coords in item.GetCoords()]
+ else:
+ coords = item.GetCoords()
self.drawFunc(pdc=pdc, pen=pen,
point1=coords[0],
More information about the grass-commit
mailing list