[GRASS-SVN] r57428 - in grass/trunk/gui/wxpython: gui_core mapdisp mapwin rlisetup
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 6 10:41:25 PDT 2013
Author: annakrat
Date: 2013-08-06 10:41:24 -0700 (Tue, 06 Aug 2013)
New Revision: 57428
Added:
grass/trunk/gui/wxpython/rlisetup/sampling_frame.py
Modified:
grass/trunk/gui/wxpython/gui_core/toolbars.py
grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py
grass/trunk/gui/wxpython/mapwin/buffered.py
grass/trunk/gui/wxpython/mapwin/graphics.py
grass/trunk/gui/wxpython/rlisetup/wizard.py
Log:
wxGUI/rlisetup: add option do draw sample frame (not fully implemented yet)
Modified: grass/trunk/gui/wxpython/gui_core/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/toolbars.py 2013-08-06 16:10:51 UTC (rev 57427)
+++ grass/trunk/gui/wxpython/gui_core/toolbars.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -94,9 +94,10 @@
))
@endcode
"""
- def __init__(self, parent):
+ def __init__(self, parent, style=wx.NO_BORDER|wx.TB_HORIZONTAL):
self.parent = parent
- wx.ToolBar.__init__(self, parent = self.parent, id = wx.ID_ANY)
+ wx.ToolBar.__init__(self, parent=self.parent, id=wx.ID_ANY,
+ style=style)
self.action = dict()
Modified: grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py 2013-08-06 16:10:51 UTC (rev 57427)
+++ grass/trunk/gui/wxpython/mapdisp/test_mapdisp.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -69,6 +69,7 @@
from mapwin.base import MapWindowProperties
from mapwin.buffered import BufferedMapWindow
from core.render import Map
+from rlisetup.sampling_frame import RLiSetupMapPanel
# TODO: same classes as in dmon
@@ -182,7 +183,6 @@
def testMapDisplay(self, giface, map_):
from mapdisp.frame import MapFrame
-
# known issues (should be similar with d.mon):
# * opening map in digitizer ends with: vdigit/toolbars.py:723: 'selection' referenced before assignment
# * nviz start fails (closes window? segfaults?) after mapdisp/frame.py:306: 'NoneType' object has no attribute 'GetLayerNotebook'
@@ -301,7 +301,14 @@
# the desired raster) is selected to be profiled
profileWindow.OnSelectRaster(None)
+ def testMapWindowRlisetup(self, map_):
+ self.frame = wx.Frame(parent=None,
+ title=_("Map window rlisetup test frame"))
+
+ RLiSetupMapPanel(parent=self.frame, map_=map_)
+ self.frame.Show()
+
def main():
"""!Sets the GRASS display driver
"""
@@ -352,6 +359,8 @@
tester.testMapWindowDistance(giface, map_)
elif test == 'profile':
tester.testMapWindowProfile(giface, map_)
+ elif test == 'rlisetup':
+ tester.testMapWindowRlisetup(map_)
else:
# TODO: this should not happen but happens
import grass.script as sgrass
Modified: grass/trunk/gui/wxpython/mapwin/buffered.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/buffered.py 2013-08-06 16:10:51 UTC (rev 57427)
+++ grass/trunk/gui/wxpython/mapwin/buffered.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -954,6 +954,22 @@
return self.lineid
+ def DrawRectangle(self, pdc, point1, point2, pen=None):
+ """!Draw rectangle (not filled) in PseudoDC
+
+ @param pdc PseudoDC
+ @param point1 top left corner (map coordinates)
+ @param point2 bottom right corner (map 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]
+ self.lineid = self.Draw(pdc, drawid=None, pdctype='box', coords=coords, pen=pen)
+ return self.lineid
+
def _computeZoomToPointAndRecenter(self, position, zoomtype):
"""!Computes zoom parameters for recenter mode.
@@ -1756,15 +1772,15 @@
def RegisterGraphicsToDraw(self, graphicsType, setStatusFunc = None, drawFunc = None):
"""! This method registers graphics to draw.
- @param type (string) - graphics type: "point" or "line"
+ @param type (string) - graphics type: "point", "line" or "rectangle"
@param setStatusFunc (function reference) - function called before drawing each item
Status function should be in this form: setStatusFunc(item, itemOrderNum)
item - passes instance of GraphicsSetItem which will be drawn
itemOrderNum - number of item in drawing order (from O)
Hidden items are also counted in drawing order.
@param drawFunc (function reference) - defines own function for drawing
- If function is not defined DrawCross method is used for type "point"
- or DrawLines method for type "line".
+ If function is not defined DrawCross method is used for type "point",
+ DrawLines method for type "line", DrawRectangle for "rectangle".
@return reference to GraphicsSet, which was added.
"""
Modified: grass/trunk/gui/wxpython/mapwin/graphics.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/graphics.py 2013-08-06 16:10:51 UTC (rev 57427)
+++ grass/trunk/gui/wxpython/mapwin/graphics.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -64,6 +64,9 @@
elif self.graphicsType == "line":
self.drawFunc = self.parentMapWin.DrawLines
+ elif self.graphicsType == "rectangle":
+ self.drawFunc = self.parentMapWin.DrawRectangle
+
def Draw(self, pdc):
"""!Draws all containing items.
@@ -105,6 +108,17 @@
self.drawFunc(pdc=pdc,
polycoords=coords)
+
+ elif self.graphicsType == "rectangle":
+ if item.GetPropertyVal("penName"):
+ pen = self.pens[item.GetPropertyVal("penName")]
+ else:
+ pen = self.pens["default"]
+ coords = item.GetCoords()
+
+ self.drawFunc(pdc=pdc, pen=pen,
+ point1=coords[0],
+ point2=coords[1])
itemOrderNum += 1
def AddItem(self, coords, penName=None, label=None, hide=False):
@@ -116,6 +130,7 @@
@param coords - list of east, north coordinates (double) of item
Example: point: [1023, 122]
line: [[10, 12],[20,40],[23, 2334]]
+ rectangle: [[10, 12], [33, 45]]
@param penName (string) the 'default' pen is used if is not defined
@param label (string) label, which will be drawn with point. It is
relavant just for 'point' type.
@@ -266,6 +281,7 @@
@param coords - list of coordinates (double) of item
Example: point: [1023, 122]
line: [[10, 12],[20,40],[23, 2334]]
+ rectangle: [[10, 12], [33, 45]]
@param penName (string) if it is not defined 'default' pen is used
@param label (string) label, which will be drawn with point. It is
relevant just for 'point' type
@@ -317,6 +333,7 @@
@param coords - list of east, north coordinates (double) of item
Example: point: [1023, 122]
line: [[10, 12],[20,40],[23, 2334]]
+ rectangle: [[10, 12], [33, 45]]
"""
self.coords = coords
Added: grass/trunk/gui/wxpython/rlisetup/sampling_frame.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/sampling_frame.py (rev 0)
+++ grass/trunk/gui/wxpython/rlisetup/sampling_frame.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -0,0 +1,211 @@
+# -*- coding: utf-8 -*-
+"""!
+ at package rlisetup.sampling_frame
+
+ at brief r.li.setup - draw sample frame
+
+Classes:
+ - sampling_frame::RLiSetupMapPanel
+ - sampling_frame::RLiSetupToolbar
+ - sampling_frame::GraphicsSetItem
+
+(C) 2013 by the GRASS Development Team
+
+This program is free software under the GNU General Public License
+(>=v2). Read the file COPYING that comes with GRASS for details.
+
+ at author Anna Petrasova <kratochanna gmail.com>
+"""
+
+import os
+import sys
+import wx
+import wx.aui
+
+# adding a path to wxGUI modules
+if __name__ == '__main__':
+ WXGUIBASE = os.path.join(os.getenv('GISBASE'), 'etc', 'gui', 'wxpython')
+ if WXGUIBASE not in sys.path:
+ sys.path.append(WXGUIBASE)
+
+from core.utils import _
+from core.giface import StandaloneGrassInterface
+from mapwin.base import MapWindowProperties
+from mapwin.buffered import BufferedMapWindow
+from core.render import Map
+from gui_core.toolbars import BaseToolbar, BaseIcons
+from icons.icon import MetaIcon
+
+from grass.pydispatch.signal import Signal
+from grass.pydispatch.errors import DispatcherKeyError
+
+
+class RLiSetupMapPanel(wx.Panel):
+ """!Panel with mapwindow used in r.li.setup"""
+ def __init__(self, parent, map_=None):
+ wx.Panel.__init__(self, parent=parent)
+ self.mapWindowProperties = MapWindowProperties()
+ self.mapWindowProperties.setValuesFromUserSettings()
+ giface = StandaloneGrassInterface()
+
+ self._region = {}
+ self.sampleFrameChanged = Signal('RLiSetupMapPanel.sampleFrameChanged')
+
+ if map_:
+ self.map_ = map_
+ else:
+ self.map_ = Map()
+ self.map_.region = self.map_.GetRegion()
+
+ self._mgr = wx.aui.AuiManager(self)
+ self.mapWindow = BufferedMapWindow(parent=self, giface=giface,
+ Map=self.map_,
+ properties=self.mapWindowProperties)
+ self._mgr.AddPane(self.mapWindow, wx.aui.AuiPaneInfo().CentrePane().
+ Dockable(True).BestSize((-1, -1)).Name('mapwindow').
+ CloseButton(False).DestroyOnClose(True).
+ Layer(0))
+ self.toolbar = RLiSetupToolbar(self)
+
+ self._mgr.AddPane(self.toolbar,
+ wx.aui.AuiPaneInfo().
+ Name("maptoolbar").Caption(_("Map Toolbar")).
+ ToolbarPane().Left().Name('mapToolbar').
+ CloseButton(False).Layer(1).Gripper(False).
+ BestSize((self.toolbar.GetBestSize())))
+ self._mgr.Update()
+
+ self._initTool()
+
+ self._registeredGraphics = self.mapWindow.RegisterGraphicsToDraw(graphicsType='rectangle')
+ self._registeredGraphics.AddPen('rlisetup', wx.Pen(wx.GREEN, width=3, style=wx.SOLID))
+ self._registeredGraphics.AddItem(coords=[[0, 0], [0, 0]], penName='rlisetup', hide=True)
+
+ def _initTool(self):
+ """!Initialize draw mode"""
+ self.toolbar.ToggleTool(self.toolbar.draw, True)
+ self.toolbar.action['id'] = self.toolbar.draw
+ self.OnDraw(None)
+
+ def GetMap(self):
+ return self.map_
+
+ def GetRegion(self):
+ """!Returns currently drawn region in a dict"""
+ return self._region
+
+ def OnZoomIn(self, event):
+ """!Zoom in the map.
+ """
+ self.SwitchTool(event)
+ self._prepareZoom(mapWindow=self.mapWindow, zoomType=1)
+
+ def OnZoomOut(self, event):
+ """!Zoom out the map.
+ """
+ self.SwitchTool(event)
+ self._prepareZoom(mapWindow=self.mapWindow, zoomType=-1)
+
+ def _prepareZoom(self, mapWindow, zoomType):
+ """!Prepares MapWindow for zoom
+
+ @param mapWindow MapWindow to prepare
+ @param zoomType 1 for zoom in, -1 for zoom out
+ """
+ mapWindow.mouse['use'] = "zoom"
+ mapWindow.mouse['box'] = "box"
+ mapWindow.zoomtype = zoomType
+ mapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
+
+ # change the cursor
+ mapWindow.SetNamedCursor('cross')
+
+ def SwitchTool(self, event):
+ """!Helper function to switch tools"""
+ self.toolbar.OnTool(event)
+ self.toolbar.action['desc'] = ''
+ try:
+ self.mapWindow.mouseLeftUp.disconnect(self._rectangleDrawn)
+ except DispatcherKeyError:
+ pass
+
+ def OnPan(self, event):
+ """!Panning, set mouse to drag
+ """
+ self.SwitchTool(event)
+
+ self.mapWindow.mouse['use'] = "pan"
+ self.mapWindow.mouse['box'] = "pan"
+ self.mapWindow.zoomtype = 0
+
+ # change the cursor
+ self.mapWindow.SetNamedCursor('hand')
+
+ def OnZoomToMap(self, event):
+ layers = self.map_.GetListOfLayers()
+ self.mapWindow.ZoomToMap(layers=layers, ignoreNulls=False, render=True)
+
+ def OnDraw(self, event):
+ """!Start draw mode"""
+ self.SwitchTool(event)
+
+ self.mapWindow.mouse['use'] = None
+ self.mapWindow.mouse['box'] = "box"
+ self.mapWindow.pen = wx.Pen(colour=wx.RED, width=2, style=wx.SHORT_DASH)
+ self.mapWindow.SetNamedCursor('cross')
+
+ self.mapWindow.mouseLeftUp.connect(self._rectangleDrawn)
+
+ def _rectangleDrawn(self):
+ """!When drawing finished, get region values"""
+ mouse = self.mapWindow.mouse
+ item = self._registeredGraphics.GetItem(0)
+ p1 = self.mapWindow.Pixel2Cell(mouse['begin'])
+ p2 = self.mapWindow.Pixel2Cell(mouse['end'])
+ item.SetCoords([p1, p2])
+ self._region = {'n': max(p1[1], p2[1]),
+ 's': min(p1[1], p2[1]),
+ 'w': min(p1[0], p2[0]),
+ 'e': max(p1[0], p2[0])}
+ item.SetPropertyVal('hide', False)
+ self.mapWindow.ClearLines()
+ self._registeredGraphics.Draw(self.mapWindow.pdcTmp)
+
+ self.sampleFrameChanged.emit()
+
+
+icons = {'draw': MetaIcon(img='edit',
+ label=_('Draw sampling frame'),
+ desc=_('Draw sampling frame by clicking and dragging'))}
+
+
+class RLiSetupToolbar(BaseToolbar):
+ """!IClass toolbar
+ """
+ def __init__(self, parent):
+ """!RLiSetup toolbar constructor
+ """
+ BaseToolbar.__init__(self, parent, style=wx.NO_BORDER | wx.TB_VERTICAL)
+
+ self.InitToolbar(self._toolbarData())
+ # realize the toolbar
+ self.Realize()
+
+ def _toolbarData(self):
+ """!Toolbar data"""
+ return self._getToolbarData((('draw', icons['draw'],
+ self.parent.OnDraw,
+ wx.ITEM_CHECK),
+ (None, ),
+ ('pan', BaseIcons['pan'],
+ self.parent.OnPan,
+ wx.ITEM_CHECK),
+ ('zoomIn', BaseIcons['zoomIn'],
+ self.parent.OnZoomIn,
+ wx.ITEM_CHECK),
+ ('zoomOut', BaseIcons['zoomOut'],
+ self.parent.OnZoomOut,
+ wx.ITEM_CHECK),
+ ('zoomExtent', BaseIcons['zoomExtent'],
+ self.parent.OnZoomToMap),
+ ))
Property changes on: grass/trunk/gui/wxpython/rlisetup/sampling_frame.py
___________________________________________________________________
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
Modified: grass/trunk/gui/wxpython/rlisetup/wizard.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/wizard.py 2013-08-06 16:10:51 UTC (rev 57427)
+++ grass/trunk/gui/wxpython/rlisetup/wizard.py 2013-08-06 17:41:24 UTC (rev 57428)
@@ -36,6 +36,7 @@
from core.utils import _
from location_wizard.wizard import TitledPage as TitledPage
from rlisetup.functions import checkValue, retRLiPath
+from rlisetup.sampling_frame import RLiSetupMapPanel
from grass.script import core as grass
from grass.script import raster as grast
@@ -58,6 +59,7 @@
self.rlipath = retRLiPath()
#pages
self.startpage = FirstPage(self.wizard, self)
+ self.drawsampleframepage = DrawSampleFramePage(self.wizard, self)
self.keyboardpage = KeybordPage(self.wizard, self)
self.samplingareapage = SamplingAreasPage(self.wizard, self)
self.summarypage = SummaryPage(self.wizard, self)
@@ -68,6 +70,8 @@
self.startpage.SetNext(self.samplingareapage)
self.keyboardpage.SetPrev(self.startpage)
self.keyboardpage.SetNext(self.samplingareapage)
+ self.drawsampleframepage.SetNext(self.samplingareapage)
+ self.drawsampleframepage.SetPrev(self.startpage)
self.samplingareapage.SetPrev(self.startpage)
self.samplingareapage.SetNext(self.summarypage)
self.units.SetPrev(self.samplingareapage)
@@ -78,6 +82,7 @@
#layout
self.startpage.DoLayout()
+ self.drawsampleframepage.DoLayout()
self.keyboardpage.DoLayout()
self.samplingareapage.DoLayout()
self.summarypage.DoLayout()
@@ -309,8 +314,8 @@
majorDimension=1,
style=wx.RA_SPECIFY_ROWS)
- self.sampling_reg.EnableItem(2, False) # disable 'draw' for now
- self.sampling_reg.SetItemToolTip(2, _("This option is not supported yet"))
+# self.sampling_reg.EnableItem(2, False) # disable 'draw' for now
+# self.sampling_reg.SetItemToolTip(2, _("This option is not supported yet"))
self.sizer.Add(item=self.sampling_reg,
flag=wx.ALIGN_CENTER | wx.ALL | wx.EXPAND, border=5,
pos=(4, 0), span=(1, 2))
@@ -337,6 +342,7 @@
self.SetNext(self.parent.keyboardpage)
elif event.GetInt() == 2: # currently disabled
self.region = 'draw'
+ self.SetNext(self.parent.drawsampleframepage)
def OnName(self, event):
"""!Sets the name of configuration file"""
@@ -375,7 +381,7 @@
def OnExitPage(self, event=None):
"""!Function during exiting"""
- if self.region == 'draw' or self.conf_name == '' or self.rast == '':
+ if self.conf_name == '' or self.rast == '':
wx.FindWindowById(wx.ID_FORWARD).Enable(False)
else:
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
@@ -387,12 +393,10 @@
self.SetNext(self.parent.samplingareapage)
self.parent.samplingareapage.SetPrev(self)
elif self.region == 'draw':
- gcmd.GMessage(parent=self,
- message=_("Function not supported yet"))
- event.Veto()
+ self.SetNext(self.parent.drawsampleframepage)
+ self.parent.samplingareapage.SetPrev(self.parent.drawsampleframepage)
return
-
class KeybordPage(TitledPage):
"""
Set name of configuration file, choose raster and optionally vector/sites
@@ -507,6 +511,51 @@
wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+class DrawSampleFramePage(TitledPage):
+ def __init__(self, wizard, parent):
+ TitledPage.__init__(self, wizard, _("Draw sampling frame"))
+ self.parent = parent
+ self.mapPanel = RLiSetupMapPanel(self)
+ self.mapPanel.sampleFrameChanged.connect(self.SampleFrameChanged)
+ self.sizer.Add(item=self.mapPanel, flag=wx.EXPAND, pos=(0, 0))
+ # TO BE REMOVED
+ warning = wx.StaticText(self, label=_("WARNING: this functionality is not supported yet"))
+ warning.SetForegroundColour(wx.RED)
+ self.sizer.Add(item=warning, pos=(1, 0), flag=wx.ALIGN_CENTRE)
+ self.sizer.AddGrowableCol(0)
+ self.sizer.AddGrowableRow(0)
+
+ self._raster = None
+
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGED, self.OnEnterPage)
+ self.Bind(wiz.EVT_WIZARD_PAGE_CHANGING, self.OnExitPage)
+
+ def SampleFrameChanged(self):
+ region = self.mapPanel.GetRegion()
+ if region:
+ wx.FindWindowById(wx.ID_FORWARD).Enable(True)
+ else:
+ wx.FindWindowById(wx.ID_FORWARD).Enable(False)
+ # TODO: calculate needed values here
+
+ def OnEnterPage(self, event):
+ self.SampleFrameChanged()
+ rast = self.parent.startpage.rast
+ if self._raster != rast:
+ map_ = self.mapPanel.GetMap()
+ map_.DeleteAllLayers()
+ cmdlist = ['d.rast', 'map=%s' % rast]
+ map_.AddLayer(ltype='raster', command=cmdlist, active=True,
+ name=rast, hidden=False, opacity=1.0,
+ render=True)
+
+ def OnExitPage(self, event=None):
+ """!Function during exiting"""
+ if event.GetDirection():
+ self.SetNext(self.parent.samplingareapage)
+ self.parent.samplingareapage.SetPrev(self)
+
+
class SamplingAreasPage(TitledPage):
"""
Set name of configuration file, choose raster and optionally vector/sites
More information about the grass-commit
mailing list