[GRASS-SVN] r47223 - grass/trunk/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 22 06:05:36 EDT 2011
Author: annakrat
Date: 2011-07-22 03:05:36 -0700 (Fri, 22 Jul 2011)
New Revision: 47223
Modified:
grass/trunk/gui/wxpython/gui_modules/gdialogs.py
grass/trunk/gui/wxpython/gui_modules/mapdisp.py
grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxNviz: add text overlays, little changes in 2D text overlays
Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py 2011-07-22 07:56:40 UTC (rev 47222)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py 2011-07-22 10:05:36 UTC (rev 47223)
@@ -511,10 +511,10 @@
def _CreateOverlay(self):
if not self.parent.Map.GetOverlay(self.ovlId):
- overlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
+ self.newOverlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
command=self.cmd,
l_active=False, l_render=False, l_hidden=True)
- prop = { 'layer' : overlay,
+ prop = { 'layer' : self.newOverlay,
'params' : None,
'propwin' : None,
'cmd' : self.cmd,
@@ -551,7 +551,7 @@
def OnCancel(self, event):
"""!Cancel dialog"""
self.parent.dialogs['barscale'] = None
-
+ self.parent.Map.DeleteOverlay(self.newOverlay)
self.Destroy()
def OnOK(self, event):
@@ -613,12 +613,14 @@
self.currClr = self.parent.MapWindow.textdict[self.ovlId]['color']
self.currRot = self.parent.MapWindow.textdict[self.ovlId]['rotation']
self.currCoords = self.parent.MapWindow.textdict[self.ovlId]['coords']
+ self.currBB = self.parent.MapWindow.textdict[self.ovlId]['bbox']
else:
self.currClr = wx.BLACK
self.currText = ''
self.currFont = self.GetFont()
self.currRot = 0.0
- self.currCoords = [10, 10, 10, 10]
+ self.currCoords = [10, 10]
+ self.currBB = wx.Rect()
self.sizer = wx.BoxSizer(wx.VERTICAL)
box = wx.GridBagSizer(vgap=5, hgap=5)
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2011-07-22 07:56:40 UTC (rev 47222)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp.py 2011-07-22 10:05:36 UTC (rev 47223)
@@ -386,6 +386,7 @@
self.MapWindow = self.MapWindow3D
self.MapWindow.SetCursor(self.cursors["default"])
self.MapWindow3D.overlays = self.MapWindow2D.overlays
+ self.MapWindow3D.textdict = self.MapWindow2D.textdict
self.MapWindow3D.UpdateOverlays()
# add Nviz notebookpage
@@ -1679,6 +1680,13 @@
AddScale.SetBitmap(icons["addBarscale"].GetBitmap(self.iconsize))
decmenu.AppendItem(AddScale)
self.Bind(wx.EVT_MENU, self.OnAddBarscale, AddScale)
+ # temporary
+ if self.toolbars['nviz']:
+ AddScale.Enable(False)
+ AddArrow = wx.MenuItem(decmenu, wx.ID_ANY, _("Add north arrow"))
+ AddArrow.SetBitmap(icons["addBarscale"].GetBitmap(self.iconsize))
+ decmenu.AppendItem(AddArrow)
+ self.Bind(wx.EVT_MENU, self.OnAddArrow, AddArrow)
AddLegend = wx.MenuItem(decmenu, wx.ID_ANY, icons["addLegend"].GetLabel())
AddLegend.SetBitmap(icons["addLegend"].GetBitmap(self.iconsize))
@@ -1689,14 +1697,6 @@
AddText.SetBitmap(icons["addText"].GetBitmap(self.iconsize))
decmenu.AppendItem(AddText)
self.Bind(wx.EVT_MENU, self.OnAddText, AddText)
- # temporary
- if self.toolbars['nviz']:
- AddText.Enable(False)
- AddScale.Enable(False)
- AddArrow = wx.MenuItem(decmenu, wx.ID_ANY, _("Add north arrow"))
- AddArrow.SetBitmap(icons["addBarscale"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddArrow)
- self.Bind(wx.EVT_MENU, self.OnAddArrow, AddArrow)
# Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns.
@@ -1773,10 +1773,10 @@
else:
# index for overlay layer in render
if len(self.MapWindow.textdict.keys()) > 0:
- id = self.MapWindow.textdict.keys()[-1] + 1
+ id = max(self.MapWindow.textdict.keys()) + 1
else:
id = 101
-
+
self.dialogs['text'] = gdialogs.TextLayerDialog(parent = self, ovlId = id,
title = _('Add text layer'),
size = (400, 200))
@@ -1786,27 +1786,30 @@
if self.dialogs['text'].ShowModal() == wx.ID_OK:
text = self.dialogs['text'].GetValues()['text']
active = self.dialogs['text'].GetValues()['active']
- coords, w, h = self.MapWindow.TextBounds(self.dialogs['text'].GetValues())
# delete object if it has no text or is not active
if text == '' or active == False:
try:
- self.MapWindow.pdc.ClearId(id)
- self.MapWindow.pdc.RemoveId(id)
+ self.MapWindow2D.pdc.ClearId(id)
+ self.MapWindow2D.pdc.RemoveId(id)
del self.MapWindow.textdict[id]
+ if self.MapWindow3D:
+ self.MapWindow3D.UpdateOverlays()
except:
pass
return
- self.MapWindow.pdc.ClearId(id)
- self.MapWindow.pdc.SetId(id)
- self.MapWindow.textdict[id] = self.dialogs['text'].GetValues()
+ self.MapWindow2D.pdc.ClearId(id)
+ self.MapWindow2D.pdc.SetId(id)
+ self.MapWindow2D.textdict[id] = self.dialogs['text'].GetValues()
+ if self.MapWindow3D:
+ self.MapWindow3D.textdict[id] = self.dialogs['text'].GetValues()
+
- self.MapWindow.Draw(self.MapWindow.pdcDec, img = self.MapWindow.textdict[id],
- drawid = id, pdctype = 'text', coords = coords)
+ self.MapWindow2D.UpdateMap(render = False, renderVector = False)
+ if self.MapWindow3D:
+ self.MapWindow3D.UpdateOverlays()
- self.MapWindow.UpdateMap(render = False, renderVector = False)
-
self.MapWindow.mouse['use'] = 'pointer'
def OnAddArrow(self, event):
@@ -1815,8 +1818,8 @@
"""
self._layerManager.nviz.SetPage('decoration')
+ self.MapWindow3D.SetDrawArrow((70, 70))
-
def GetOptData(self, dcmd, type, params, propwin):
"""!Callback method for decoration overlay command generated by
dialog created in menuform.py
Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py 2011-07-22 07:56:40 UTC (rev 47222)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py 2011-07-22 10:05:36 UTC (rev 47223)
@@ -392,12 +392,12 @@
w, h = self.GetFullTextExtent(img['text'])[0:2]
pdc.SetFont(img['font'])
pdc.SetTextForeground(img['color'])
- coords, w, h = self.TextBounds(img)
+ coords, bbox = self.TextBounds(img)
if rotation == 0:
pdc.DrawText(img['text'], coords[0], coords[1])
else:
pdc.DrawRotatedText(img['text'], coords[0], coords[1], rotation)
- pdc.SetIdBounds(drawid, wx.Rect(coords[0], coords[1], w, h))
+ pdc.SetIdBounds(drawid, bbox)
pdc.EndDrawing()
@@ -405,11 +405,15 @@
return drawid
- def TextBounds(self, textinfo):
+ def TextBounds(self, textinfo, relcoords = False):
"""!Return text boundary data
@param textinfo text metadata (text, font, color, rotation)
@param coords reference point
+
+ @return coords of nonrotated text bbox (TL corner)
+ @return bbox of rotated text bbox (wx.Rect)
+ @return relCoords are text coord inside bbox
"""
if 'rotation' in textinfo:
rotation = float(textinfo['rotation'])
@@ -417,7 +421,8 @@
rotation = 0.0
coords = textinfo['coords']
-
+ bbox = wx.Rect(coords[0], coords[1], 0, 0)
+ relCoords = (0, 0)
Debug.msg (4, "BufferedWindow.TextBounds(): text=%s, rotation=%f" % \
(textinfo['text'], rotation))
@@ -428,15 +433,31 @@
w, h = self.GetTextExtent(textinfo['text'])
if rotation == 0:
- coords[2], coords[3] = coords[0] + w, coords[1] + h
- return coords, w, h
+ bbox[2], bbox[3] = w, h
+ if relcoords:
+ return coords, bbox, relCoords
+ else:
+ return coords, bbox
boxh = math.fabs(math.sin(math.radians(rotation)) * w) + h
boxw = math.fabs(math.cos(math.radians(rotation)) * w) + h
- coords[2] = coords[0] + boxw
- coords[3] = coords[1] + boxh
-
- return coords, boxw, boxh
+ if rotation > 0 and rotation < 90:
+ bbox[1] -= boxh
+ relCoords = (0, boxh)
+ elif rotation >= 90 and rotation < 180:
+ bbox[0] -= boxw
+ bbox[1] -= boxh
+ relCoords = (boxw, boxh)
+ elif rotation >= 180 and rotation < 270:
+ bbox[0] -= boxw
+ relCoords = (boxw, 0)
+ bbox[2] = boxw
+ bbox[3] = boxh
+ bbox.Inflate(h,h)
+ if relcoords:
+ return coords, bbox, relCoords
+ else:
+ return coords, bbox
def OnPaint(self, event):
"""!Draw PseudoDC's to buffered paint DC
@@ -862,6 +883,7 @@
dy = event.GetY() - y
self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
r = self.pdc.GetIdBounds(id)
+
if type(r) is list:
r = wx.Rect(r[0], r[1], r[2], r[3])
if id > 100: # text dragging
@@ -875,7 +897,9 @@
if type(r2) is list:
r2 = wx.Rect(r[0], r[1], r[2], r[3])
if id > 100: # text
- self.textdict[id]['coords'] = r2
+ self.textdict[id]['bbox'] = r2
+ self.textdict[id]['coords'][0] += dx
+ self.textdict[id]['coords'][1] += dy
r = r.Union(r2)
r.Inflate(4,4)
self.RefreshRect(r, False)
@@ -1265,7 +1289,7 @@
if self.dragid < 99 and self.dragid in self.overlays:
self.overlays[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
elif self.dragid > 100 and self.dragid in self.textdict:
- self.textdict[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
+ self.textdict[self.dragid]['bbox'] = self.pdc.GetIdBounds(self.dragid)
else:
pass
self.dragid = None
Modified: grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-22 07:56:40 UTC (rev 47222)
+++ grass/trunk/gui/wxpython/gui_modules/nviz_mapdisp.py 2011-07-22 10:05:36 UTC (rev 47223)
@@ -106,6 +106,8 @@
self.shapes = []
self.dragShape = None
self.dragImage = None
+ self.textdict = {}
+ self.dragid = None
#
# use display region instead of computational
@@ -268,10 +270,42 @@
# draw any active and defined overlays
if self.imagedict[img]['layer'].IsActive():
id = self.imagedict[img]['id']
+ if id == 0: # barscale
+ continue
coords = self.overlays[id]['coords']
bitmap = wx.BitmapFromImage(img)
self.shapes.append(DragShape(bitmap, id))
self.shapes[-1].pos = coords[:2]
+
+ for textId in self.textdict.keys():
+ text = self.textdict[textId]['text']
+ color = self.textdict[textId]['color']
+ bgcolor = self.view['background']['color']
+ font = self.textdict[textId]['font']
+ rot = self.textdict[textId]['rotation']
+ coords, bbox, relCoords = self.TextBounds(self.textdict[textId])
+ # create a bitmap the same size as our text
+ bmp = wx.EmptyBitmap(bbox[2], bbox[3])
+
+ # 'draw' the text onto the bitmap
+ dc = wx.MemoryDC()
+ dc.SelectObject(bmp)
+ dc.SetBackground(wx.Brush(bgcolor, wx.SOLID))
+ dc.Clear()
+ dc.SetTextForeground(color)
+ dc.SetFont(font)
+ if rot == 0:
+ dc.DrawText(text, 0, 0)
+ else:
+ dc.DrawRotatedText(text, relCoords[0], relCoords[1], rot)
+ # setbackgroundMode(wx.TRANSPARENT) doesn't work
+ dc.SelectObject(wx.NullBitmap)
+ mask = wx.Mask(bmp, bgcolor)
+ bmp.SetMask(mask)
+ shape = DragShape(bmp, textId)
+ shape.pos = bbox[:2]
+ self.shapes.append(shape)
+
self.Refresh(False)
def OnMouseAction(self, event):
@@ -357,15 +391,7 @@
if self.mouse['use'] == 'arrow':
pos = event.GetPosition()
size = self.GetClientSize()
- if self._display.SetArrow(pos[0], size[1] - pos[1],
- self.decoration['arrow']['size'],
- self.decoration['arrow']['color']):
- self._display.DrawArrow()
- # update
- self.decoration['arrow']['show'] = True
- self.decoration['arrow']['position']['x'] = pos[0]
- self.decoration['arrow']['position']['y'] = size[1] - pos[1]
- self.Refresh(False)
+ self.SetDrawArrow((pos[0], size[1] - pos[1]))
if self.mouse['use'] == 'pointer':
shape = self.FindShape(event.GetPosition())
@@ -482,7 +508,12 @@
self.dragShape.pos[0] + event.GetPosition()[0] - self.dragStartPos[0],
self.dragShape.pos[1] + event.GetPosition()[1] - self.dragStartPos[1]
)
- self.overlays[self.dragShape.id]['coords'] = tuple(self.dragShape.GetRect())
+ if self.dragShape.id in self.overlays:
+ self.overlays[self.dragShape.id]['coords'] = tuple(self.dragShape.GetRect())
+ else: # text
+ self.textdict[self.dragShape.id]['bbox'] = self.dragShape.GetRect()
+ self.textdict[self.dragShape.id]['coords'][0] += event.GetPosition()[0] - self.dragStartPos[0]
+ self.textdict[self.dragShape.id]['coords'][1] += event.GetPosition()[1] - self.dragStartPos[1]
self.dragShape.shown = True
self.RefreshRect(self.dragShape.GetRect())
self.dragShape = None
@@ -491,7 +522,10 @@
def OnDClick(self, event):
shape = self.FindShape(event.GetPosition())
if shape.id == 1:
- self.parent.OnAddLegend(None)
+ self.parent.OnAddLegend(None)
+ elif shape.id > 100:
+ self.dragid = shape.id
+ self.parent.OnAddText(None)
def OnQuerySurface(self, event):
"""!Query surface on given position"""
@@ -633,6 +667,18 @@
return shape
return None
+ def SetDrawArrow(self, pos):
+
+ if self._display.SetArrow(pos[0], pos[1],
+ self.decoration['arrow']['size'],
+ self.decoration['arrow']['color']):
+ self._display.DrawArrow()
+ # update
+ self.decoration['arrow']['show'] = True
+ self.decoration['arrow']['position']['x'] = pos[0]
+ self.decoration['arrow']['position']['y'] = pos[1]
+ self.Refresh(False)
+
def IsLoaded(self, item):
"""!Check if layer (item) is already loaded
@@ -1878,7 +1924,15 @@
"""!Reset view
"""
self.lmgr.nviz.OnResetView(None)
+
+ def TextBounds(self, textinfo):
+ """!Return text boundary data
+
+ @param textinfo text metadata (text, font, color, rotation)
+ """
+ return self.parent.MapWindow2D.TextBounds(textinfo, relcoords = True)
+
class DragShape:
"""!Class for drawing overlays (based on wxpython demo)"""
def __init__(self, bmp, id):
Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py 2011-07-22 07:56:40 UTC (rev 47222)
+++ grass/trunk/gui/wxpython/gui_modules/render.py 2011-07-22 10:05:36 UTC (rev 47223)
@@ -1295,7 +1295,7 @@
def DeleteOverlay(self, overlay):
"""!Delete overlay
- @param id overlay id
+ @param overlay overlay layer
@return removed overlay on success or None
"""
More information about the grass-commit
mailing list