Browse Source

wxGUI/mapwin: DrawCircle added and specify which coordinate type is to be used for GraphicsSet

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58533 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 years ago
parent
commit
e4800a52a6
3 changed files with 55 additions and 18 deletions
  1. 2 1
      gui/wxpython/mapwin/analysis.py
  2. 38 13
      gui/wxpython/mapwin/buffered.py
  3. 15 4
      gui/wxpython/mapwin/graphics.py

+ 2 - 1
gui/wxpython/mapwin/analysis.py

@@ -125,7 +125,8 @@ class AnalysisControllerBase:
         self._oldMouseUse = self._mapWindow.mouse['use']
         self._oldMouseUse = self._mapWindow.mouse['use']
         self._oldCursor = self._mapWindow.GetNamedCursor()
         self._oldCursor = self._mapWindow.GetNamedCursor()
 
 
-        self._registeredGraphics = self._mapWindow.RegisterGraphicsToDraw(graphicsType='line')
+        self._registeredGraphics = self._mapWindow.RegisterGraphicsToDraw(graphicsType='line',
+                                                                          mapCoords=False)
 
 
         self._connectAll()
         self._connectAll()
 
 

+ 38 - 13
gui/wxpython/mapwin/buffered.py

@@ -322,7 +322,16 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
                     y2 = max(ylist)
                     y2 = max(ylist)
                     pdc.SetIdBounds(drawid, wx.Rect(x1,y1,x2,y2))
                     pdc.SetIdBounds(drawid, wx.Rect(x1,y1,x2,y2))
                     # self.ovlcoords[drawid] = [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
         elif pdctype == 'point': # draw point
             if pen:
             if pen:
                 pdc.SetPen(pen)
                 pdc.SetPen(pen)
@@ -942,7 +951,7 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
         @todo implement rotation
         @todo implement rotation
 
 
         @param pdc PseudoDC
         @param pdc PseudoDC
-        @param coords center coordinates
+        @param coords center coordinates (pixel coordinates)
         @param rotation rotate symbol
         @param rotation rotate symbol
         @param text draw also text (text, font, color, rotation)
         @param text draw also text (text, font, color, rotation)
         @param textAlign alignment (default 'lower-right')
         @param textAlign alignment (default 'lower-right')
@@ -978,18 +987,31 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
         """!Draw rectangle (not filled) in PseudoDC
         """!Draw rectangle (not filled) in PseudoDC
 
 
         @param pdc 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
         @param pen pen
         """
         """
         Debug.msg(4, "BufferedWindow.DrawRectangle(): pdc=%s, point1=%s, point2=%s" % \
         Debug.msg(4, "BufferedWindow.DrawRectangle(): pdc=%s, point1=%s, point2=%s" % \
                   (pdc, point1, point2))
                   (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)
         self.lineid = self.Draw(pdc, drawid=None, pdctype='box', coords=coords, pen=pen)
         return self.lineid
         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):
     def _computeZoomToPointAndRecenter(self, position, zoomtype):
         """!Computes zoom parameters for recenter mode.
         """!Computes zoom parameters for recenter mode.
 
 
@@ -1805,7 +1827,8 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
         """!Get render.Map() instance"""
         """!Get render.Map() instance"""
         return self.Map
         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.
         """! This method registers graphics to draw.
         
         
         @param type (string) - graphics type: "point", "line" or "rectangle"
         @param type (string) - graphics type: "point", "line" or "rectangle"
@@ -1817,13 +1840,15 @@ class BufferedMapWindow(MapWindowBase, wx.Window):
         @param drawFunc (function reference) - defines own function for drawing
         @param drawFunc (function reference) - defines own function for drawing
                             If function is not defined DrawCross method is used for type "point",
                             If function is not defined DrawCross method is used for type "point",
                             DrawLines method for type "line", DrawRectangle for "rectangle".
                             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.
         @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)
         self.graphicsSetList.append(item)
         
         
         return item
         return item

+ 15 - 4
gui/wxpython/mapwin/graphics.py

@@ -26,7 +26,7 @@ from core.utils import _
 class GraphicsSet:
 class GraphicsSet:
 
 
     def __init__(self, parentMapWin, graphicsType,
     def __init__(self, parentMapWin, graphicsType,
-                 setStatusFunc=None, drawFunc=None):
+                 setStatusFunc=None, drawFunc=None, mapCoords=True):
         """!Class, which contains instances of GraphicsSetItem and
         """!Class, which contains instances of GraphicsSetItem and
             draws them For description of parameters look at method
             draws them For description of parameters look at method
             RegisterGraphicsToDraw in BufferedWindow class.
             RegisterGraphicsToDraw in BufferedWindow class.
@@ -45,6 +45,7 @@ class GraphicsSet:
         self.graphicsType = graphicsType
         self.graphicsType = graphicsType
         self.parentMapWin = parentMapWin
         self.parentMapWin = parentMapWin
         self.setStatusFunc = setStatusFunc
         self.setStatusFunc = setStatusFunc
+        self.mapCoords = mapCoords
 
 
         if drawFunc:
         if drawFunc:
             self.drawFunc = drawFunc
             self.drawFunc = drawFunc
@@ -87,7 +88,10 @@ class GraphicsSet:
                 else:
                 else:
                     self.parentMapWin.pen = self.pens["default"]
                     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"]
                 size = self.properties["size"]
 
 
                 self.properties["text"]['coords'] = [coords[0] + size, coords[1] + size, size, size]
                 self.properties["text"]['coords'] = [coords[0] + size, coords[1] + size, size, size]
@@ -104,7 +108,11 @@ class GraphicsSet:
                     self.parentMapWin.polypen = self.pens[item.GetPropertyVal("penName")]
                     self.parentMapWin.polypen = self.pens[item.GetPropertyVal("penName")]
                 else:
                 else:
                     self.parentMapWin.polypen = self.pens["default"]
                     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,
                 self.drawFunc(pdc=pdc,
                               polycoords=coords)
                               polycoords=coords)
@@ -114,7 +122,10 @@ class GraphicsSet:
                     pen = self.pens[item.GetPropertyVal("penName")]
                     pen = self.pens[item.GetPropertyVal("penName")]
                 else:
                 else:
                     pen = self.pens["default"]
                     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, 
                 self.drawFunc(pdc=pdc, pen=pen, 
                               point1=coords[0],
                               point1=coords[0],