[GRASS-SVN] r42005 - grass-addons/gui/wxpython/data_catalog
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Apr 23 11:54:46 EDT 2010
Author: rashadkm
Date: 2010-04-23 11:54:46 -0400 (Fri, 23 Apr 2010)
New Revision: 42005
Removed:
grass-addons/gui/wxpython/data_catalog/LayerTree.py
grass-addons/gui/wxpython/data_catalog/README
grass-addons/gui/wxpython/data_catalog/gmconsole.py
grass-addons/gui/wxpython/data_catalog/mapdisp_window.py
grass-addons/gui/wxpython/data_catalog/mapdisplay.py
grass-addons/gui/wxpython/data_catalog/mapframe.py
grass-addons/gui/wxpython/data_catalog/mapwindow.py
grass-addons/gui/wxpython/data_catalog/newprompt.py
grass-addons/gui/wxpython/data_catalog/toolbars.py
grass-addons/gui/wxpython/data_catalog/units.py
grass-addons/gui/wxpython/data_catalog/wx_utils.py
Modified:
grass-addons/gui/wxpython/data_catalog/catalog.py
Log:
fixed display for different location and mapsets
Deleted: grass-addons/gui/wxpython/data_catalog/LayerTree.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/LayerTree.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/LayerTree.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,366 +0,0 @@
-import os
-import sys
-import wx
-import glob
-import render
-from threading import Thread
-
-
-#To run DataCatalog from any directory set this pathname for access to gui_modules
-gbase = os.getenv("GISBASE")
-pypath = os.path.join(gbase,'etc','wxpython','gui_modules')
-sys.path.append(pypath)
-
-
-import globalvar
-if not os.getenv("GRASS_WXBUNDLED"):
- globalvar.CheckForWx()
-import gcmd
-
-
-
-
-class LayerTree(wx.TreeCtrl):
-
- def __init__(self, parent, id,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize,
- style= wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS,gisdbase=None):
-
- wx.TreeCtrl.__init__(self, parent, id, pos, size, style)
- self.itemFont = wx.Font(pointSize=9,weight=0, family=wx.FONTFAMILY_DEFAULT ,style=wx.FONTSTYLE_ITALIC)
-
- self.gisdbase = gisdbase
- self.Map = None
- #if self.Map is not None:
- # print self.Map.width
-
- self.ID_REN= wx.NewId()
- self.ID_COPY = wx.NewId()
- self.ID_DEL = wx.NewId()
- self.ID_OSSIM = wx.NewId()
-
- acel = wx.AcceleratorTable([
- (wx.ACCEL_CTRL, ord('R'), self.ID_REN ) ,
- (wx.ACCEL_CTRL, ord('C'), self.ID_COPY) ,
- (wx.ACCEL_NORMAL, wx.WXK_DELETE, self.ID_DEL) ])
-
-
- self.SetAcceleratorTable(acel)
-
- self.dict = {}
-
- self.layer = []
- self.maplayer = None
-
-
-
- def AddTreeNodes(self,location,mapset):
- """
- Adds tree nodes. raster,vector and dbf files are identified using
- their directory structure.
- """
-
- root = self.AddRoot('root')
- node_raster = self.AppendItem(root, "Raster Map")
- node_vector = self.AppendItem(root, "Vector Map")
- node_dbf = self.AppendItem(root, "DBF")
- treeNodes = [node_raster,node_vector,node_dbf]
-
- glocs = glob.glob(os.path.join(self.gisdbase,location, mapset,"*"))
- for gloc in glocs:
- if not os.path.isfile(gloc) and os.path.isdir(gloc):
- if(os.path.basename(gloc)=='cellhd'):
- for rast in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
- self.AppendItem(node_raster, os.path.basename(rast))
- elif(os.path.basename(gloc)=='vector'):
- for vect in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
- self.AppendItem(node_vector, os.path.basename(vect))
- elif(os.path.basename(gloc)=='dbf'):
- for dfile in glob.glob(os.path.join(self.gisdbase,location, mapset,gloc, "*")):
- self.AppendItem(node_dbf, os.path.basename(dfile))
-
- #Nodes with no children are given an italic type font
- for node in treeNodes:
- if not self.ItemHasChildren(node):
- if self.GetItemText(node) == 'Raster Map':
- tmp_item = self.AppendItem(node, "No raster maps found.")
- elif self.GetItemText(node) == 'Vector Map':
- tmp_item = self.AppendItem(node, "No vector maps found.")
- elif self.GetItemText(node) == 'DBF':
- tmp_item = self.AppendItem(node, "No DBF files found.")
- self.SetItemFont(tmp_item,self.itemFont)
-
-
-
-
- def OnToggleExpand(self,event):
- if self.treeExpand.GetValue() == True:
- self.ExpandAll()
- else:
- self.CollapseAll()
-
-
- def OnBeginRename(self,event):
-
- item = self.GetItemText(event.GetItem())
- if type(item) == str and item in ("Raster Map", "Vector Map" , "DBF"):
- event.Veto() #disable editing of parent items
-
- def OnEndRename(self,event):
- """
- Rename mapset using grass commands
- """
- item = event.GetItem()
- oldName = self.GetItemText(item)
- try:
- newName = self.GetEditControl().GetValue()
- except:
- return
- parent =self.GetItemParent(item)
- if self.GetItemText(parent) == "Raster Map" :
- cmdflag = 'rast=' + oldName + ',' + newName
- elif self.GetItemText(parent) == "Vector Map" :
- cmdflag = 'vect=' + oldName + ',' + newName
-
- if cmdflag:
- command = ["g.rename", cmdflag]
- gcmd.CommandThread(command,stdout=None,stderr=None).run()
-
-
-
- def OnTreePopUp(self,event):
- """
- Display a popupMenu for copy,rename & delete operations
- """
- item = event.GetItem()
- if not self.ItemHasChildren(item) and \
- self.GetItemFont(item) != self.itemFont:
-
- self.popupmenu = wx.Menu()
- mnuCopy = self.popupmenu.Append(self.ID_COPY,'&Copy\tCtrl+C')
- mnuRename = self.popupmenu.Append(self.ID_REN,'&Rename\tCtrl-R')
- mnuDel = self.popupmenu.Append(self.ID_DEL,'&Delete\tDEL')
- mnuOssim = self.popupmenu.Append(self.ID_OSSIM,'&send to OssimPlanet')
- self.PopupMenu(self.popupmenu)
-
-
- def OnCopy( self,event ):
- #print "copy"
- item = self.GetSelection()
- parent = self.GetItemParent(item)
- pText = self.GetItemText(parent)
- name = self.GetCopyName(item)
- if pText == "Raster Map" :
- cmdflag = 'rast=' + self.GetItemText(item) + ',' + name
- self.InsertItem(parent,item, name)
- elif pText == "Vector Map" :
- cmdflag = 'vect=' + self.GetItemText(item) + ',' + name
- self.InsertItem(parent,item, name)
-
- if cmdflag:
- command = ["g.copy", cmdflag]
- gcmd.CommandThread(command,stdout=None,stderr=None).run()
-
-
- def GetCopyName(self, item):
- """
- Returns unique name depending on the mapname to be copied.
- """
-
- def GetPrefix(prefix):
- """
- This returns a prefix to the given map name
- prefix applied here is _copy_x.
- """
-
- prefix = "_copy_" + str(self.count)
- self.count = self.count + 1
- return prefix
-
- #end of GetPrefix
-
- def CheckName(parent,prefix,name):
- """
- Checks all silbings of the parent wheather the name
- already exists.
- """
- ncount = self.GetChildrenCount(parent, False)
- ck = 1
- current , ck = self.GetFirstChild(parent)
- for i in range(ncount):
- if str(self.GetItemText(current)) == str(name + prefix):
- return False
- else:
- current,ck = self.GetNextChild(parent,ck)
- return True
-
- #End of CheckName
-
- #GetCopyName function starts here
- ext = None
- self.count = 1
- ext = GetPrefix(ext)
- name = str(self.GetItemText(item))
- parent = self.GetItemParent(item)
- while CheckName(parent,ext,name) == False:
- ext = GetPrefix(ext)
- CheckName(parent,ext,name)
-
- name = str(name + ext)
- return name
-
-
- def OnRename( self,event ):
-
- item = self.GetSelection()
- self.EditLabel( self.GetSelection())
-
-
- def OnDelete( self,event ):
- """
- Performs grass command for deleting a map
- """
- item = self.GetSelection()
- dlg = wx.MessageDialog(self, message=_( "Do you want to delete selected map ?"),
- caption=_("Delete Map"),
- style=wx.YES_NO | wx.YES_DEFAULT | \
- wx.CANCEL | wx.ICON_QUESTION)
- ret = dlg.ShowModal()
- if ret == wx.ID_YES:
- dlg.Destroy()
- parent =self.GetItemParent(item)
- if self.GetItemText(parent) == "Raster Map" :
- cmdflag = 'rast=' + str(self.GetItemText(item))
- elif self.GetItemText(parent) == "Vector Map" :
- cmdflag = 'vect=' + str(self.GetItemText(item))
-
- if cmdflag:
- command = ["g.remove", cmdflag]
- gcmd.CommandThread(command,stdout=None,stderr=None).run()
- select = self.GetPrevSibling(item)
- self.Delete(item)
- self.SelectItem(select)
-
- elif ret == wx.ID_CANCEL:
- dlg.Destroy()
- return
-
- def OnOssim( self,event ):
- """
- Performs grass command for deleting a map
- """
- item = self.GetSelection()
-
- parent =self.GetItemParent(item)
- if self.GetItemText(parent) == "Raster Map" :
- cmdflag = 'r.planet.py -a map=' + str(self.GetItemText(item))
- elif self.GetItemText(parent) == "Vector Map" :
- cmdflag = 'v.planet.py -a map=' + str(self.GetItemText(item))
-
- if cmdflag:
-
- #command = ["r.planet.py", cmdflag]
- #gcmd.CommandThread(command,stdout=None,stderr=None).run()
- current = OssimPlanet(cmdflag)
- current.start()
-
-
-
- def OnDisplay(self, event):
-
- item = event.GetItem()
- pText = self.GetItemText(self.GetItemParent(item))
-
-
- leftpanel=self.GetParent()
- splitter = leftpanel.GetParent()
- frame = splitter.GetParent()
- window2 = splitter.GetWindow2()
-
- winlist = window2.GetChildren()
- for win in winlist:
- if type(win) == wx.lib.flatnotebook.FlatNotebook:
- #win.SetSelection(0)
- child=win.GetChildren()
- for panel in child:
- #print panel.GetName()
- if panel.GetName() == "pg_panel":
- mapframe = panel
-
-
-
- # mtree = mapframe.maptree
- #print mtree.GetName()
-
-
-
-
- if not self.ItemHasChildren(item):
- self.mapname = self.GetItemText(item) + "@" + frame.cmbMapset.GetValue()
- #for f in frames:
- # print f.GetName()
- maptree = mapframe.maptree
-
- if pText == "Raster Map" :
- self.cmd= ['d.rast', str("map=" + self.mapname)]
- l_type="raster"
-
- self.maplayer = mapframe.Map.AddLayer(type=l_type, name=self.mapname, command=self.cmd)
-
- #mapframe.maptree.AddLayer(ltype="raster", lname=self.mapname, lchecked=True,lcmd=self.cmd)
- maptree.ltype = 'raster'
-
- mapframe.Map.region = mapframe.Map.GetRegion()
- mapframe.MapWindow2D.flag = True
- mapframe.MapWindow2D.UpdateMap(render=True)
- mapframe.MapWindow2D.flag = False
-
- layer = maptree.PrependItem(parent=maptree.root, text=self.mapname, ct_type=1)
- maptree.first = True
- maptree.layer_selected = layer
- maptree.CheckItem(layer)
- #self.layer.append(self.maplayer)
- maptree.PlusLayer(self.maplayer)
-
-
-
- #update new layer
-# mapframe.maptree.SetPyData(newItem, mapframe.maptree.GetPyData(dragItem))
-
-
-# mapframe.maptree.CheckItem(newItem, checked=True) # causes a new render
-# mapframe.maptree.SelectItem(newItem, select=True)
-
-
-
-
-
-
-
- #self.infocmd = ["r.info", str(self.mapname)]
- elif pText == "Vector Map" :
- self.cmd= ['d.vect', str("map=" + self.mapname)]
- mapframe.maptree.AddLayer(ltype="vector", lname=self.mapname, lchecked=True,lcmd=self.cmd)
- l_type="vector"
- #self.infocmd = ["r.info", str(self.mapname)]
-
-
-
- # if self.cmd:
- # mapframe.Map.Clean()
- # mapframe.Map.__init__() #to update projection and region
- # mapframe.Map.AddLayer(type=l_type, name='layer1', command=self.cmd)
- # mapframe.Map.region = panel.Map.GetRegion()
- # mapframe.MapWindow2D.flag = True
- # mapframe.MapWindow2D.UpdateMap(render=True)
-
-class OssimPlanet(Thread):
- def __init__ (self,cmd):
- Thread.__init__(self)
- self.cmd = cmd
- def run(self):
- os.system(self.cmd)
-
-
-
Deleted: grass-addons/gui/wxpython/data_catalog/README
===================================================================
--- grass-addons/gui/wxpython/data_catalog/README 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/README 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,6 +0,0 @@
-To run DataCatalog
-from grass shell type:
-
-python catalog.py
-
-To send files to ossimplanet please download r.planet and v.planet and copy it in application directory
Modified: grass-addons/gui/wxpython/data_catalog/catalog.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/catalog.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/catalog.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -86,8 +86,14 @@
import gui_modules.dbm as dbm
import gui_modules.workspace as workspace
import gui_modules.colorrules as colorrules
+
+version = os.getenv("GRASS_VERSION")
+if version == "6.5.svn":
+ import gui_modules.menu as menu
+ import gui_modules.gmodeler as gmodeler
+
#import gui_modules.ogc_services as ogc_services
-import newprompt as prompt
+
#from gui_modules.help import MenuTreeWindow
#from gui_modules.help import AboutWindow
from icons.icon import Icons
@@ -122,7 +128,7 @@
self.gisbase = os.getenv("GISBASE")
self.gisrc = self.read_gisrc()
self.viewInfo = True #to display v/r.info on mapdisplay
- self.gisdbase = self.gisrc['GISDBASE']
+ self.gisdbase = self.gisrc['GISDBASE']
#backup location and mapset from gisrc which may be modified by datacatalog
self.iLocation = self.gisrc['LOCATION_NAME']
@@ -152,6 +158,7 @@
self.mapfile = []
self.mapname = None
self.cmd = None
+ self.newmap = None
#creating sizers
@@ -167,23 +174,19 @@
self.loclist.sort()
#self.pg_panel4 = None
-
- self.menubar, self.menudata = self.__createMenuBar()
+ version = os.getenv("GRASS_VERSION")
+ if version == "6.5.svn":
+ self.menubar = menu.Menu(parent = self, data = menudata.ManagerData())
+ else:
+ self.menubar, self.menudata = self.__createMenuBar()
#self.statusbar = self.CreateStatusBar(number=1)
#self.cmdprompt, self.cmdinput = self.__createCommandPrompt()
self.toolbar = self.__createToolBar()
#setting splitter window
- self.win = wx.SplitterWindow(self)
- self.pLeft = wx.Panel(self.win, style=wx.SUNKEN_BORDER,name="leftpanel")
- self.pRight = wx.Panel(self.win, style=wx.SUNKEN_BORDER,name="rightpanel")
+
self.cmbPanel = wx.Panel(self,name="cmbpanel")
- self.rightPanel = wx.Panel(self.pRight)
- self.pRight.SetBackgroundColour("white")
- self.pLeft.Hide()
- self.pRight.Hide()
- self.win.Initialize(self.pLeft)
- self.win.SplitVertically(self.pLeft, self.pRight, 310)
+
self.maptree = None
self.pg_panel = None
@@ -199,8 +202,8 @@
self.cmbMapset = wx.ComboBox(self.cmbPanel, value = "Select Mapset", size=wx.DefaultSize)
#self.tree = wx.TreeCtrl(self.pLeft, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_HIDE_ROOT|wx.TR_HAS_BUTTONS|wx.TR_EDIT_LABELS)
- self.ltree = LayerTree(self.pLeft,wx.ID_ANY,gisdbase=self.gisdbase)
+
self.itemFont = wx.Font(pointSize=9,weight=0, family=wx.FONTFAMILY_DEFAULT ,style=wx.FONTSTYLE_ITALIC)
@@ -218,8 +221,8 @@
self.goutput.Hide()
+ # self.ltree = LayerTree(self.pLeft,wx.ID_ANY,gisdbase=self.gisdbase,frame=self.pg_panel)
-
self.doBindings()
self.doLayout()
@@ -233,28 +236,19 @@
def GetMapDisplay(self):
- self.winlist = self.GetChildren()
- for win in self.winlist:
- if win.GetName()== "splitter":
- self.splitter = win.GetWindow2()
-
- self.books = self.splitter.GetChildren()
- for self.book in self.books:
- if type(self.book) == wx.lib.flatnotebook.FlatNotebook:
- ##self.book.SetSelection(self.book.GetCurrentPage())
- self.panel = self.book.GetChildren()
- for self.subpanel in self.panel:
- if self.subpanel.GetName() == "pg_panel":
- self.newmap = self.subpanel.Map
- break
- return self.newmap
+ self.panel = self.notebook.GetCurrentPage()
+ return self.panel.Map
def __createMenuBar(self):
"""!Creates menubar"""
self.menubar = wx.MenuBar()
- self.menudata = menudata.Data()
+ version = os.getenv("GRASS_VERSION")
+ if version == "6.5.svn":
+ self.menudata = menudata.ManagerData()
+ else:
+ self.menudata = menudata.Data()
for eachMenuData in self.menudata.GetMenu():
for eachHeading in eachMenuData:
menuLabel = eachHeading[0]
@@ -506,7 +500,7 @@
# create displays notebook widget and add it to main notebook page
cbStyle = globalvar.FNPageStyle
- self.notebook = FN.FlatNotebook(parent=self.pRight, id=wx.ID_ANY, style=cbStyle)
+ self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, style=cbStyle)
self.notebook.SetTabAreaColour(globalvar.FNPageColor)
@@ -542,6 +536,7 @@
Page of notebook closed
Also close associated map display
"""
+ self.curr_page = self.notebook.GetCurrentPage()
if UserSettings.Get(group='manager', key='askOnQuit', subkey='enabled'):
maptree = self.curr_page.maptree
@@ -592,28 +587,7 @@
self.curr_pagenum = self.notebook.GetSelection()
- self.ltree.DeleteAllItems()
- count = self.notebook.GetPageCount()
- for index in range(0,count):
- page = self.notebook.GetPage(index)
- maptree = page.maptree
- maptree.DeleteAllItems()
-
- maptree.root = maptree.AddRoot("Map Layers")
- maptree.SetPyData(maptree.root, (None,None))
- for i in range(0,len(maptree.layer)):
-
- maptree.Map.DeleteLayer(maptree.layer[i])
- maptree.mapdict[str(maptree.layer[i].name)]=maptree.layer[i].type
- #page.MapWindow2D.EraseMap()
-
-
- self.mapfile.append(maptree.layer[i].name)
-# self.oldpage.MapWindow2D.EraseMap()
-
- print maptree.mapdict
-
# self.cmbMapset.SetValue(self.cb_loclist[self.disp_idx])
# self.cmbLocation.SetValue(self.cb_loclist[self.disp_idx])
# self.disp_idx
@@ -644,120 +618,71 @@
self.cmbLocation.SetValue(a_loc)
self.cmbMapset.SetValue(a_map)
- self.ltree.AddTreeNodes(a_loc,a_map)
-
+
try:
self.gisrc['LOCATION_NAME'] = self.cb_loclist[index]
self.gisrc['MAPSET'] = self.cb_maplist[index]
- #self.page.Map = self.cb_mapfile[index]
+
except:
pass
#self.page.Map.Region = self.page.Map.GetRegion()
self.update_grassrc(self.gisrc)
- # self.page.Map.GetWindow()
- # self.page.Map.InitGisEnv()
- page=self.notebook.GetCurrentPage()
- maptree = page.maptree
- for key, val in maptree.mapdict.iteritems():
- self.mapname = key
-
- if val == "raster":
- l_type="raster"
- maptree.ltype = 'raster'
- self.cmd= ['d.rast', str("map=" + self.mapname)]
- else:
- l_type = "vector"
- maptree.ltype = 'vector'
- self.cmd= ['d.vect', str("map=" + self.mapname)]
-
- layer = maptree.PrependItem(parent=maptree.root, text=self.mapname, ct_type=1)
-
- #page.MapWindow2D.flag = False
- maptree.first = True
- maptree.layer_selected = layer
- maptree.CheckItem(layer)
- #self.layer.append(self.maplayer)
- #maptree.PlusLayer(self.maplayer)
-
+
- # try:
- maptree.Map.AddLayer(type=l_type, name=self.mapname, command=self.cmd)
- page.MapWindow2D.flag = True
- page.MapWindow2D.UpdateMap(render=True)
- page.MapWindow2D.flag = False
- maptree.Map.region = self.page.maptree.Map.GetRegion()
- # except:
- # pass
+ event.Skip()
- #mapframe.maptree.AddLayer(ltype="raster", lname=self.mapname, lchecked=True,lcmd=self.cmd)
-
+ def OnGeorectify(self, event):
+ """
+ Launch georectifier module
+ """
+ georect.GeorectWizard(self)
- #page.MapWindow2D.flag = False
- #page.MapWindow2D.EraseMap()
-
+ def OnGModeler(self, event):
+ """!Launch Graphical Modeler"""
+ win = gmodeler.ModelFrame(parent = self)
+ win.CentreOnScreen()
+ win.Show()
- count = self.notebook.GetPageCount()
- for index in range(0,count):
- page = self.notebook.GetPage(index)
- # page.MapWindow2D.flag = False
-
- page.MapWindow2D.flag = False
-
- #self.layer.append(self.maplayer)
- #maptree.PlusLayer(self.maplayer)
-
-
- # self.page.maptree.AddLayer(ltype=l_type, lname=self.mapname, lchecked=True,lcmd=self.cmd)
- #item1 = self.page.maptree.FindItem(idParent=self.page.maptree.root,prefixOrig=self.mapname)
-
-
- # print self.page.maptree.GetItemText(item1)
- #self.page.maptree.Delete(item1)
-
- #print self.page.maptree.mapdict
-
-
- # self.page.MapWindow.UpdateMap(render=True)
- #self.oldpage.Map.region = self.oldpage.Map.GetRegion()
- #self.page.Map.region = self.page.Map.GetRegion()
-
-
-
-# print self.region
-# print self.page.Map.region
-# print self.cmbLocation.GetValue()
- #self.gisrc['LOCATION_NAME'] = str(self.cmbLocation.GetValue())
- #self.gisrc['MAPSET'] = str(self.cmbMapset.GetValue())
- #self.update_grassrc(self.gisrc)
-
- # self.curr_page.Map.__init__()
- # self.curr_page.Map.region = self.curr_page.Map.GetRegion()
-
-
+ def OnRunModel(self, event):
+ """!Run model"""
+ filename = ''
+ dlg = wx.FileDialog(parent = self, message=_("Choose model to run"),
+ defaultDir = os.getcwd(),
+ wildcard=_("GRASS Model File (*.gxm)|*.gxm"))
+ if dlg.ShowModal() == wx.ID_OK:
+ filename = dlg.GetPath()
- # try:
- #self.curr_page.maptree.mapdisplay.SetFocus()
- #self.curr_page.maptree.mapdisplay.Raise()
- # except:
- # pass
+ if not filename:
+ return
- event.Skip()
+ self.model = gmodeler.Model()
+ self.model.LoadModel(filename)
+ self.SetStatusText(_('Validating model...'), 0)
+ result = self.model.Validate()
+ if result:
+ dlg = wx.MessageDialog(parent = self,
+ message = _('Model is not valid. Do you want to '
+ 'run the model anyway?\n\n%s') % '\n'.join(errList),
+ caption=_("Run model?"),
+ style = wx.YES_NO | wx.NO_DEFAULT |
+ wx.ICON_QUESTION | wx.CENTRE)
+ ret = dlg.ShowModal()
+ if ret != wx.ID_YES:
+ return
+
+ self.SetStatusText(_('Running model...'), 0)
+ self.model.Run(log = self.goutput,
+ onDone = self.OnDone)
-
- def OnGeorectify(self, event):
- """
- Launch georectifier module
- """
- georect.GeorectWizard(self)
def OnMapsets(self, event):
"""
@@ -935,21 +860,65 @@
self.PopupMenu(menu)
menu.Destroy()
- def OnWorkspaceNew(self, event=None):
- """!Create new workspace file
+# def OnWorkspaceNew(self, event=None):
+# """!Create new workspace file
+#
+# Erase current workspace settings first"""
+#
+# Debug.msg(4, "GMFrame.OnWorkspaceNew():")
+#
+# # start new map display if no display is available
+# if not self.current:
+# self.NewDisplay()
+#
+# maptree = self.current.maptree
+#
+# # ask user to save current settings
+# if maptree.GetCount() > 0:
+# dlg = wx.MessageDialog(self, message=_("Current workspace is not empty. "
+# "Do you want to store current settings "
+# "to workspace file?"),
+# caption=_("Create new workspace?"),
+# style=wx.YES_NO | wx.YES_DEFAULT | \
+# wx.CANCEL | wx.ICON_QUESTION)
+# ret = dlg.ShowModal()
+# if ret == wx.ID_YES:
+# self.OnWorkspaceSaveAs()
+# elif ret == wx.ID_CANCEL:
+# dlg.Destroy()
+# return
+#
+# dlg.Destroy()
+#
+# # delete all items
+# maptree.DeleteAllItems()
+#
+# # add new root element
+# maptree.root = maptree.AddRoot("Map Layers")
+# self.current.maptree.SetPyData(maptree.root, (None,None))
+#
+# # no workspace file loaded
+# self.workspaceFile = None
+# self.SetTitle(self.baseTitle)
- Erase current workspace settings first"""
+ def OnWorkspaceNew(self, event = None):
+ """!Create new workspace file
+
+ Erase current workspace settings first
+ """
Debug.msg(4, "GMFrame.OnWorkspaceNew():")
# start new map display if no display is available
- if not self.current:
+ if not self.curr_page:
self.NewDisplay()
- maptree = self.current.maptree
+ maptree = self.curr_page.maptree
# ask user to save current settings
- if maptree.GetCount() > 0:
+ if self.workspaceFile and self.workspaceChanged:
+ self.OnWorkspaceSave()
+ elif self.workspaceFile is None and maptree.GetCount() > 0:
dlg = wx.MessageDialog(self, message=_("Current workspace is not empty. "
"Do you want to store current settings "
"to workspace file?"),
@@ -970,11 +939,13 @@
# add new root element
maptree.root = maptree.AddRoot("Map Layers")
- self.current.maptree.SetPyData(maptree.root, (None,None))
+ self.curr_page.maptree.SetPyData(maptree.root, (None,None))
# no workspace file loaded
self.workspaceFile = None
+ self.workspaceChanged = False
self.SetTitle(self.baseTitle)
+
def OnWorkspaceOpen(self, event=None):
"""!Open file with workspace definition"""
@@ -1962,8 +1933,10 @@
Create the tree nodes based on selected location and mapset.
Also update gisrc and grassrc files.
"""
- self.ltree.DeleteAllItems()
- self.ltree.AddTreeNodes(self.cmbLocation.GetValue(),self.cmbMapset.GetValue())
+
+ self.page = self.notebook.GetCurrentPage()
+
+ self.page.maptree.AddTreeNodes(self.cmbLocation.GetValue(),self.cmbMapset.GetValue())
self.gisrc['LOCATION_NAME'] = str(self.cmbLocation.GetValue())
self.gisrc['MAPSET'] = str(self.cmbMapset.GetValue())
self.update_grassrc(self.gisrc)
@@ -1972,7 +1945,11 @@
self.page = self.notebook.GetPage(self.notebook.GetSelection())
self.page.Map.__init__()
self.page.Map.region = self.page.Map.GetRegion()
- self.page.Map.projinfo = self.page.Map.ProjInfo()
+ if version == "6.5.svn":
+ self.page.Map.projinfo = self.page.Map._projInfo()
+ else:
+ self.page.Map.projinfo = self.page.Map.ProjInfo()
+
self.page.Map.wind = self.page.Map.GetWindow()
if self.locationchange == True:
@@ -2001,18 +1978,12 @@
"""
Populate mapset combobox with selected location.
"""
- count = self.current.maptree.GetCount()
- firstitem = self.current.maptree.GetFirstVisibleItem()
- for i in range(1, count):
- nextitem = self.current.maptree.GetNext(firstitem);
- self.current.maptree.Delete(nextitem)
- if firstitem:
- self.current.maptree.Delete(firstitem)
+
self.cmbMapset.Clear()
self.cmbMapset.SetValue("Select Mapset")
- self.ltree.DeleteAllItems()
+ #self.ltree.DeleteAllItems()
maplists = self.GetMapsets(self.cmbLocation.GetValue())
@@ -2048,16 +2019,16 @@
self.Bind(wx.EVT_COMBOBOX,self.OnLocationChange,self.cmbLocation)
#Event bindings for tree -(display,popup,label edit.)
- self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.ltree.OnDisplay,self.ltree)
- self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK,self.ltree.OnTreePopUp,self.ltree)
- self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.ltree.OnEndRename,self.ltree)
- self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.ltree.OnBeginRename,self.ltree)
+ #self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.ltree.OnDisplay,self.ltree)
+ #self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK,self.ltree.OnTreePopUp,self.ltree)
+ #self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.ltree.OnEndRename,self.ltree)
+ # self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.ltree.OnBeginRename,self.ltree)
#Event bindings for tree menu
- self.Bind(wx.EVT_MENU,self.ltree.OnCopy,id=self.ltree.ID_COPY)
- self.Bind(wx.EVT_MENU,self.ltree.OnRename,id=self.ltree.ID_REN)
- self.Bind(wx.EVT_MENU,self.ltree.OnDelete,id=self.ltree.ID_DEL)
- self.Bind(wx.EVT_MENU,self.ltree.OnOssim,id=self.ltree.ID_OSSIM)
+ #self.Bind(wx.EVT_MENU,self.ltree.OnCopy,id=self.ltree.ID_COPY)
+ #self.Bind(wx.EVT_MENU,self.ltree.OnRename,id=self.ltree.ID_REN)
+ #self.Bind(wx.EVT_MENU,self.ltree.OnDelete,id=self.ltree.ID_DEL)
+ #self.Bind(wx.EVT_MENU,self.ltree.OnOssim,id=self.ltree.ID_OSSIM)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
@@ -2085,14 +2056,14 @@
self.cmbSizer.Add(self.treeExpand)
#splitter window sizers
self.mSizer.Add(self.cmbPanel,flag=wx.EXPAND)
- self.mSizer.Add(self.win, 1, wx.EXPAND)
- self.leftSizer.Add(self.ltree,1,wx.EXPAND)
- self.rightSizer.Add(self.notebook,1,wx.EXPAND)
+ #self.mSizer.Add(self.win, 1, wx.EXPAND)
+ #self.leftSizer.Add(self.ltree,1,wx.EXPAND)
+ self.mSizer.Add(self.notebook,1,wx.EXPAND)
self.cmbPanel.SetSizer(self.cmbSizer)
self.SetSizer(self.mSizer)
- self.pLeft.SetSizer(self.leftSizer)
- self.pRight.SetSizer(self.rightSizer)
+ # self.pLeft.SetSizer(self.leftSizer)
+ #self.pRight.SetSizer(self.rightSizer)
Deleted: grass-addons/gui/wxpython/data_catalog/gmconsole.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/gmconsole.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/gmconsole.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,120 +0,0 @@
-"""
- at package gmconsole.py
-
- at brief window to ouptut grass command ouput.
-
-Classes:
- - GLog
-
-
-(C) 2006-2009 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 Michael Barton (Arizona State University)
- at author Jachym Cepicky (Mendel University of Agriculture)
- at author Martin Landa <landa.martin gmail.com>
- at author Mohammed Rashad K.M <rashadkm at gmail dot com> (modified for DataCatalog)
-"""
-
-import sys
-import os
-import time
-import traceback
-import re
-import string
-import getopt
-import platform
-
-### XML
-try:
- import xml.etree.ElementTree as etree
-except ImportError:
- import elementtree.ElementTree as etree # Python <= 2.4
-
-### i18N
-import gettext
-gettext.install('grasswxpy', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
-
-pypath = "/usr/local/grass-7.0.svn/etc/wxpython"
-sys.path.append(pypath)
-
-import gui_modules
-gmpath = gui_modules.__path__[0]
-sys.path.append(gmpath)
-
-import images
-imagepath = images.__path__[0]
-sys.path.append(imagepath)
-
-import icons
-gmpath = icons.__path__[0]
-sys.path.append(gmpath)
-
-import gui_modules.globalvar as globalvar
-if not os.getenv("GRASS_WXBUNDLED"):
- globalvar.CheckForWx()
-
-import wx
-import wx.aui
-import wx.combo
-import wx.html
-import wx.stc
-import wx.lib.customtreectrl as CT
-import wx.lib.flatnotebook as FN
-
-grassPath = os.path.join(globalvar.ETCDIR, "python")
-sys.path.append(grassPath)
-
-import gui_modules.preferences as preferences
-
-
-UserSettings = preferences.globalSettings
-
-class GLog(wx.Frame):
- """
- GIS Manager frame with notebook widget for controlling
- GRASS GIS. Includes command console page for typing GRASS
- (and other) commands, tree widget page for managing GIS map layers.
- """
- def __init__(self, parent=None, id=wx.ID_ANY, title=_("Command Output")):
-
-
- wx.Frame.__init__(self, parent=parent, id=id, size=(550, 450),
- style=wx.DEFAULT_FRAME_STYLE,title="Command Output")
-
-
- self.SetName("LayerManager")
- self.notebook = self.__createNoteBook()
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.Show()
- self.SetBackgroundColour("white")
- self.goutput.Redirect()
-
-
- def OnCloseWindow(self,event):
- self.Destroy()
-
- def __createNoteBook(self):
- """!Creates notebook widgets"""
- nbStyle = FN.FNB_FANCY_TABS | \
- FN.FNB_BOTTOM | \
- FN.FNB_NO_NAV_BUTTONS | \
- FN.FNB_NO_X_BUTTON
-
- self.notebook = FN.FlatNotebook(parent=self, id=wx.ID_ANY, style=nbStyle)
- self.goutput = goutput.GMConsole(self, pageid=1)
- self.outpage = self.notebook.AddPage(self.goutput, text=_("Command output"))
- sizer = wx.BoxSizer(wx.VERTICAL)
- self.notebook.SetSize(wx.Size(600,600))
- sizer.Add(item=self.goutput, proportion=1,flag=wx.EXPAND | wx.ALL, border=10)
- self.SetSizer(sizer)
- self.Layout()
- self.Centre()
- return self.notebook
-
-
-
-
-
Deleted: grass-addons/gui/wxpython/data_catalog/mapdisp_window.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/mapdisp_window.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/mapdisp_window.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,2767 +0,0 @@
-"""!
- at package mapdisp_window.py
-
- at brief GIS map display canvas, buffered window.
-
-Classes:
- - MapWindow
- - BufferedWindow
-
-(C) 2006-2009 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 Michael Barton
- at author Jachym Cepicky
- at author Martin Landa <landa.martin gmail.com>
-"""
-
-import os
-import time
-import math
-import sys
-import tempfile
-
-import wx
-gbase = os.getenv("GISBASE")
-pypath = os.path.join(gbase,'etc','wxpython','gui_modules')
-sys.path.append(pypath)
-
-pypath = os.path.join(gbase,'etc','wxpython')
-sys.path.append(pypath)
-
-
-import grass.script as grass
-
-import dbm
-import dbm_dialogs
-import gdialogs
-import gcmd
-import utils
-import globalvar
-import gselect
-from debug import Debug
-from preferences import globalSettings as UserSettings
-from units import ConvertValue as UnitsConvertValue
-from vdigit import GV_LINES as VDigit_Lines_Type
-from vdigit import VDigitCategoryDialog
-from vdigit import VDigitZBulkDialog
-from vdigit import VDigitDuplicatesDialog
-from vdigit import PseudoDC as VDigitPseudoDC
-
-class MapWindow(object):
- """!
- Abstract map window class
-
- Parent for BufferedWindow class (2D display mode) and
- GLWindow (3D display mode)
- """
- def __init__(self, parent, id=wx.ID_ANY,
- pos=wx.DefaultPosition,
- size=wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, lmgr=None):
- self.parent = parent # MapFrame
-
- #
- # mouse attributes -- position on the screen, begin and end of
- # dragging, and type of drawing
- #
- self.mouse = {
- 'begin': [0, 0], # screen coordinates
- 'end' : [0, 0],
- 'use' : "pointer",
- 'box' : "point"
- }
-
- def EraseMap(self):
- """!
- Erase the canvas (virtual method)
- """
- pass
-
- def UpdateMap(self):
- """!
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
- """
- pass
-
- def OnLeftDown(self, event):
- pass
-
- def OnLeftUp(self, event):
- pass
-
- def OnMouseMotion(self, event):
- pass
-
- def OnZoomToMap(self, event):
- pass
-
- def OnZoomToRaster(self, event):
- pass
-
- def GetSelectedLayer(self, type = 'layer', multi = False):
- """!
- Get selected layer from layer tree
-
- @param type 'item' / 'layer' / 'nviz'
- @param multi return first selected layer or all
-
- @return layer / map layer properties / nviz properties
- @return None / [] on failure
- """
- ret = []
- if not self.tree or \
- not self.tree.GetSelection():
- if multi:
- return []
- else:
- return None
-
- if multi and \
- type == 'item':
- return self.tree.GetSelections()
-
- for item in self.tree.GetSelections():
- if not item.IsChecked():
- if multi:
- continue
- else:
- return None
-
- if type == 'item': # -> multi = False
- return item
-
- try:
- if type == 'nviz':
- layer = self.tree.GetPyData(item)[0]['nviz']
- else:
- layer = self.tree.GetPyData(item)[0]['maplayer']
- except:
- layer = None
-
- if multi:
- ret.append(layer)
- else:
- return layer
-
- return ret
-
-class BufferedWindow(MapWindow, wx.Window):
- """!
- A Buffered window class.
-
- When the drawing needs to change, you app needs to call the
- UpdateMap() method. Since the drawing is stored in a bitmap, you
- can also save the drawing to file by calling the
- SaveToFile(self,file_name,file_type) method.
- """
-
- def __init__(self, parent, id,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, lmgr=None):
-
- MapWindow.__init__(self, parent, id, pos, size, style,
- Map, tree, lmgr)
- wx.Window.__init__(self, parent, id, pos, size, style)
-
- self.Map = Map
- self.tree = tree
- self.lmgr = lmgr # Layer Manager
-
- #
- # Flags
- #
- self.resize = False # indicates whether or not a resize event has taken place
- self.dragimg = None # initialize variable for map panning
-
- #
- # Variable for drawing on DC
- #
- self.pen = None # pen for drawing zoom boxes, etc.
- self.polypen = None # pen for drawing polylines (measurements, profiles, etc)
- # List of wx.Point tuples defining a polyline (geographical coordinates)
- self.polycoords = []
- # ID of rubber band line
- self.lineid = None
- # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
- self.plineid = None
-
- #
- # Event bindings
- #
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.Bind(wx.EVT_SIZE, self.OnSize)
- self.Bind(wx.EVT_IDLE, self.OnIdle)
- self.Bind(wx.EVT_MOTION, self.MouseActions)
- self.Bind(wx.EVT_MOUSE_EVENTS, self.MouseActions)
- self.processMouse = True
-
- #
- # Render output objects
- #
- self.mapfile = None # image file to be rendered
- self.img = "" # wx.Image object (self.mapfile)
- # used in digitization tool (do not redraw vector map)
- self.imgVectorMap = None
- # decoration overlays
- self.overlays = {}
- # images and their PseudoDC ID's for painting and dragging
- self.imagedict = {}
- self.select = {} # selecting/unselecting decorations for dragging
- self.textdict = {} # text, font, and color indexed by id
- self.currtxtid = None # PseudoDC id for currently selected text
-
- #
- # Zoom objects
- #
- self.zoomhistory = [] # list of past zoom extents
- self.currzoom = 0 # current set of extents in zoom history being used
-
- self.zoomtype = 1 # 1 zoom in, 0 no zoom, -1 zoom out
- self.hitradius = 10 # distance for selecting map decorations
- self.dialogOffset = 5 # offset for dialog (e.g. DisplayAttributesDialog)
-
- # OnSize called to make sure the buffer is initialized.
- # This might result in OnSize getting called twice on some
- # platforms at initialization, but little harm done.
- ### self.OnSize(None)
-
- self.DefinePseudoDC()
- # redraw all pdc's, pdcTmp layer is redrawn always (speed issue)
- self.redrawAll = True
-
- # will store an off screen empty bitmap for saving to file
- self._buffer = ''
-
- self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None)
-
- # vars for handling mouse clicks
- self.dragid = -1
- self.lastpos = (0, 0)
-
- def DefinePseudoDC(self, vdigit = False):
- """!Define PseudoDC class to use
-
- @vdigit True to use PseudoDC from vdigit
- """
- # create PseudoDC used for background map, map decorations like scales and legends
- self.pdc = self.PseudoDC(vdigit)
- # used for digitization tool
- self.pdcVector = None
- # decorations (region box, etc.)
- self.pdcDec = self.PseudoDC(vdigit)
- # pseudoDC for temporal objects (select box, measurement tool, etc.)
- self.pdcTmp = self.PseudoDC(vdigit)
-
- def PseudoDC(self, vdigit = False):
- """!Create PseudoDC instance"""
- if vdigit:
- PseudoDC = VDigitPseudoDC
- else:
- PseudoDC = wx.PseudoDC
-
- return PseudoDC()
-
- def CheckPseudoDC(self):
- """!Try to draw background
-
- @return True on success
- @return False on failure
- """
- try:
- self.pdc.BeginDrawing()
- self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- self.pdc.BeginDrawing()
- except:
- return False
-
- return True
-
- def Draw(self, pdc, img=None, drawid=None, pdctype='image', coords=[0, 0, 0, 0]):
- """!
- Draws map and overlay decorations
- """
- if drawid == None:
- if pdctype == 'image' and img:
- drawid = self.imagedict[img]
- elif pdctype == 'clear':
- drawid == None
- else:
- drawid = wx.NewId()
-
- if img and pdctype == 'image':
- # self.imagedict[img]['coords'] = coords
- self.select[self.imagedict[img]['id']] = False # ?
-
- pdc.BeginDrawing()
-
- if drawid != 99:
- bg = wx.TRANSPARENT_BRUSH
- else:
- bg = wx.Brush(self.GetBackgroundColour())
-
- pdc.SetBackground(bg)
-
- ### pdc.Clear()
-
- Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \
- (drawid, pdctype, coords))
-
- # set PseudoDC id
- if drawid is not None:
- pdc.SetId(drawid)
-
- if pdctype == 'clear': # erase the display
- bg = wx.WHITE_BRUSH
- # bg = wx.Brush(self.GetBackgroundColour())
- pdc.SetBackground(bg)
- pdc.RemoveAll()
- pdc.Clear()
- pdc.EndDrawing()
-
- self.Refresh()
- return
-
- if pdctype == 'image': # draw selected image
- bitmap = wx.BitmapFromImage(img)
- w,h = bitmap.GetSize()
- pdc.DrawBitmap(bitmap, coords[0], coords[1], True) # draw the composite map
- pdc.SetIdBounds(drawid, wx.Rect(coords[0],coords[1], w, h))
-
- elif pdctype == 'box': # draw a box on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- x2 = max(coords[0],coords[2])
- x1 = min(coords[0],coords[2])
- y2 = max(coords[1],coords[3])
- y1 = min(coords[1],coords[3])
- rwidth = x2-x1
- rheight = y2-y1
- rect = wx.Rect(x1, y1, rwidth, rheight)
- pdc.DrawRectangleRect(rect)
- pdc.SetIdBounds(drawid, rect)
-
- elif pdctype == 'line': # draw a line on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- pdc.DrawLine(wx.Point(coords[0], coords[1]),
- wx.Point(coords[2], coords[3]))
- pdc.SetIdBounds(drawid, wx.Rect(coords[0], coords[1], coords[2], coords[3]))
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'polyline': # draw a polyline on top of the map
- if self.polypen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.polypen)
- ### pdc.DrawLines(coords)
- if (len(coords) < 2):
- return
- i = 1
- while i < len(coords):
- pdc.DrawLinePoint(wx.Point(coords[i-1][0], coords[i-1][1]),
- wx.Point(coords[i][0], coords[i][1]))
- i += 1
-
- # get bounding rectangle for polyline
- xlist = []
- ylist = []
- if len(coords) > 0:
- for point in coords:
- x,y = point
- xlist.append(x)
- ylist.append(y)
- x1=min(xlist)
- x2=max(xlist)
- y1=min(ylist)
- y2=max(ylist)
- pdc.SetIdBounds(drawid, wx.Rect(x1,y1,x2,y2))
- # self.ovlcoords[drawid] = [x1,y1,x2,y2]
-
- elif pdctype == 'point': # draw point
- if self.pen:
- pdc.SetPen(self.pen)
- pdc.DrawPoint(coords[0], coords[1])
- coordsBound = (coords[0] - 5,
- coords[1] - 5,
- coords[0] + 5,
- coords[1] + 5)
- pdc.SetIdBounds(drawid, wx.Rect(coordsBound))
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'text': # draw text on top of map
- if not img['active']:
- return #only draw active text
- if img.has_key('rotation'):
- rotation = float(img['rotation'])
- else:
- rotation = 0.0
- w, h = self.GetFullTextExtent(img['text'])[0:2]
- pdc.SetFont(img['font'])
- pdc.SetTextForeground(img['color'])
- coords, w, h = 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.EndDrawing()
-
- self.Refresh()
-
- return drawid
-
- def TextBounds(self, textinfo):
- """!
- Return text boundary data
-
- @param textinfo text metadata (text, font, color, rotation)
- @param coords reference point
- """
- if textinfo.has_key('rotation'):
- rotation = float(textinfo['rotation'])
- else:
- rotation = 0.0
-
- coords = textinfo['coords']
-
- Debug.msg (4, "BufferedWindow.TextBounds(): text=%s, rotation=%f" % \
- (textinfo['text'], rotation))
-
- self.Update()
- ### self.Refresh()
-
- self.SetFont(textinfo['font'])
-
- w, h = self.GetTextExtent(textinfo['text'])
-
- if rotation == 0:
- coords[2], coords[3] = coords[0] + w, coords[1] + h
- return coords, w, h
-
- 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
-
- def OnPaint(self, event):
- """!
- Draw PseudoDC's to buffered paint DC
-
- self.pdc for background and decorations
- self.pdcVector for vector map which is edited
- self.pdcTmp for temporaly drawn objects (self.polycoords)
-
- If self.redrawAll is False on self.pdcTmp content is re-drawn
- """
- Debug.msg(4, "BufferedWindow.OnPaint(): redrawAll=%s" % self.redrawAll)
-
- dc = wx.BufferedPaintDC(self, self.buffer)
-
- ### dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- # use PrepareDC to set position correctly
- self.PrepareDC(dc)
-
- # create a clipping rect from our position and size
- # and update region
- rgn = self.GetUpdateRegion().GetBox()
- dc.SetClippingRect(rgn)
-
- switchDraw = False
- if self.redrawAll is None:
- self.redrawAll = True
- switchDraw = True
-
- if self.redrawAll: # redraw pdc and pdcVector
- # draw to the dc using the calculated clipping rect
- self.pdc.DrawToDCClipped(dc, rgn)
-
- # draw vector map layer
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDCClipped(gcdc, rgn)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDCClipped(dc, rgn)
-
- self.bufferLast = None
- else: # do not redraw pdc and pdcVector
- if self.bufferLast is None:
- # draw to the dc
- self.pdc.DrawToDC(dc)
-
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDC(dc)
-
- # store buffered image
- # self.bufferLast = wx.BitmapFromImage(self.buffer.ConvertToImage())
- self.bufferLast = dc.GetAsBitmap(wx.Rect(0, 0, self.Map.width, self.Map.height))
-
- pdcLast = self.PseudoDC(vdigit = False)
- pdcLast.DrawBitmap(self.bufferLast, 0, 0, False)
- pdcLast.DrawToDC(dc)
-
- # draw decorations (e.g. region box)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcDec.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcDec.DrawToDC(dc)
-
- # draw temporary object on the foreground
- ### self.pdcTmp.DrawToDCClipped(dc, rgn)
- self.pdcTmp.DrawToDC(dc)
-
- if switchDraw:
- self.redrawAll = False
-
- def OnSize(self, event):
- """!
- Scale map image so that it is
- the same size as the Window
- """
- Debug.msg(3, "BufferedWindow.OnSize():")
-
- # set size of the input image
- self.Map.ChangeMapSize(self.GetClientSize())
- # align extent based on center point and display resolution
- # this causes that image is not resized when display windows is resized
- # self.Map.AlignExtentFromDisplay()
-
- # Make new off screen bitmap: this bitmap will always have the
- # current drawing in it, so it can be used to save the image to
- # a file, or whatever.
- self.buffer = wx.EmptyBitmap(max(1, self.Map.width), max(1, self.Map.height))
-
- # get the image to be rendered
- self.img = self.GetImage()
-
- # update map display
- if self.img and self.Map.width + self.Map.height > 0: # scale image during resize
- self.img = self.img.Scale(self.Map.width, self.Map.height)
- if len(self.Map.GetListOfLayers()) > 0:
- self.UpdateMap()
-
- # re-render image on idle
- self.resize = True
-
- # reposition checkbox in statusbar
- self.parent.StatusbarReposition()
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- def OnIdle(self, event):
- """!
- Only re-render a composite map image from GRASS during
- idle time instead of multiple times during resizing.
- """
- if self.resize:
- self.UpdateMap(render=True)
-
- event.Skip()
-
- def SaveToFile(self, FileName, FileType):
- """!
- This draws the psuedo DC to a buffer that
- can be saved to a file.
- """
- dc = wx.BufferedPaintDC(self, self.buffer)
- self.pdc.DrawToDC(dc)
- if self.pdcVector:
- self.pdcVector.DrawToDC(dc)
- self.buffer.SaveFile(FileName, FileType)
-
- def GetOverlay(self):
- """!
- Converts rendered overlay files to wx.Image
-
- Updates self.imagedict
-
- @return list of images
- """
- imgs = []
- for overlay in self.Map.GetListOfLayers(l_type="overlay", l_active=True):
- if os.path.isfile(overlay.mapfile) and os.path.getsize(overlay.mapfile):
- img = wx.Image(overlay.mapfile, wx.BITMAP_TYPE_ANY)
- self.imagedict[img] = { 'id' : overlay.id,
- 'layer' : overlay }
- imgs.append(img)
-
- return imgs
-
- def GetImage(self):
- """!
- Converts redered map files to wx.Image
-
- Updates self.imagedict (id=99)
-
- @return wx.Image instance (map composition)
- """
- imgId = 99
- if self.Map.mapfile and os.path.isfile(self.Map.mapfile) and \
- os.path.getsize(self.Map.mapfile):
- img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
- else:
- img = None
-
- self.imagedict[img] = { 'id': imgId }
-
- return img
-
- def UpdateMap(self, render=True, renderVector=True):
- """!
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
-
- @param render re-render map composition
- @param renderVector re-render vector map layer enabled for editing (used for digitizer)
- """
- start = time.clock()
-
- self.resize = False
-
- # if len(self.Map.GetListOfLayers()) == 0:
- # return False
-
- if self.img is None:
- render = True
-
- #
- # initialize process bar (only on 'render')
- #
- if render is True or renderVector is True:
- self.parent.statusbarWin['progress'].Show()
- if self.parent.statusbarWin['progress'].GetRange() > 0:
- self.parent.statusbarWin['progress'].SetValue(1)
-
- #
- # render background image if needed
- #
-
- # update layer dictionary if there has been a change in layers
- if self.tree and self.tree.reorder == True:
- self.tree.ReorderLayers()
-
- # reset flag for auto-rendering
- if self.tree:
- self.tree.rerender = False
-
- if render:
- # update display size
- self.Map.ChangeMapSize(self.GetClientSize())
- if self.parent.statusbarWin['resolution'].IsChecked():
- # use computation region resolution for rendering
- windres = True
- else:
- windres = False
- self.mapfile = self.Map.Render(force=True, mapWindow=self.parent,
- windres=windres)
- else:
- self.mapfile = self.Map.Render(force=False, mapWindow=self.parent)
-
- self.img = self.GetImage() # id=99
-
- #
- # clear pseudoDcs
- #
- for pdc in (self.pdc,
- self.pdcDec,
- self.pdcTmp):
- pdc.Clear()
- pdc.RemoveAll()
-
- #
- # draw background map image to PseudoDC
- #
- if not self.img:
- self.Draw(self.pdc, pdctype='clear')
- else:
- try:
- id = self.imagedict[self.img]['id']
- except:
- return False
-
- self.Draw(self.pdc, self.img, drawid=id)
-
- #
- # render vector map layer
- #
- digitToolbar = self.parent.toolbars['vdigit']
- if renderVector and digitToolbar and \
- digitToolbar.GetLayer():
- # set region
- self.parent.digit.driver.UpdateRegion()
- # re-calculate threshold for digitization tool
- self.parent.digit.driver.GetThreshold()
- # draw map
- if self.pdcVector:
- self.pdcVector.Clear()
- self.pdcVector.RemoveAll()
- try:
- item = self.tree.FindItemByData('maplayer', digitToolbar.GetLayer())
- except TypeError:
- item = None
-
- if item and self.tree.IsItemChecked(item):
- self.parent.digit.driver.DrawMap()
-
- # translate tmp objects (pointer position)
- if digitToolbar.GetAction() == 'moveLine':
- if hasattr(self, "vdigitMove") and \
- self.vdigitMove.has_key('beginDiff'):
- # move line
- for id in self.vdigitMove['id']:
- self.pdcTmp.TranslateId(id,
- self.vdigitMove['beginDiff'][0],
- self.vdigitMove['beginDiff'][1])
- del self.vdigitMove['beginDiff']
-
- #
- # render overlays
- #
- for img in self.GetOverlay():
- # draw any active and defined overlays
- if self.imagedict[img]['layer'].IsActive():
- id = self.imagedict[img]['id']
- self.Draw(self.pdc, img=img, drawid=id,
- pdctype=self.overlays[id]['pdcType'], coords=self.overlays[id]['coords'])
-
- for id in self.textdict.keys():
- self.Draw(self.pdc, img=self.textdict[id], drawid=id,
- pdctype='text', coords=[10, 10, 10, 10])
-
- # optionally draw computational extent box
- self.DrawCompRegionExtent()
-
- #
- # redraw pdcTmp if needed
- #
- if len(self.polycoords) > 0:
- self.DrawLines(self.pdcTmp)
-
- if not self.parent.IsStandalone() and \
- self.parent.GetLayerManager().georectifying:
- # -> georectifier (redraw GCPs)
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
- self.parent.GetLayerManager().georectifying.DrawGCP(coordtype)
-
- #
- # clear measurement
- #
- if self.mouse["use"] == "measure":
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.SetCursor(self.parent.cursors["default"])
-
- stop = time.clock()
-
- #
- # hide process bar
- #
- self.parent.statusbarWin['progress'].Hide()
-
- #
- # update statusbar
- #
- ### self.Map.SetRegion()
- self.parent.StatusbarUpdate()
- if grass.find_file(name = 'MASK', element = 'cell')['name']:
- # mask found
- self.parent.statusbarWin['mask'].SetLabel(_('MASK'))
- else:
- self.parent.statusbarWin['mask'].SetLabel('')
-
- Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%g" % \
- (render, renderVector, (stop-start)))
-
- return True
-
- def DrawCompRegionExtent(self):
- """!
- Draw computational region extent in the display
-
- Display region is drawn as a blue box inside the computational region,
- computational region inside a display region as a red box).
- """
- if hasattr(self, "regionCoords"):
- compReg = self.Map.GetRegion()
- dispReg = self.Map.GetCurrentRegion()
- reg = None
- if self.IsInRegion(dispReg, compReg):
- self.polypen = wx.Pen(colour=wx.Colour(0, 0, 255, 128), width=3, style=wx.SOLID)
- reg = dispReg
- else:
- self.polypen = wx.Pen(colour=wx.Colour(255, 0, 0, 128),
- width=3, style=wx.SOLID)
- reg = compReg
-
- self.regionCoords = []
- self.regionCoords.append((reg['w'], reg['n']))
- self.regionCoords.append((reg['e'], reg['n']))
- self.regionCoords.append((reg['e'], reg['s']))
- self.regionCoords.append((reg['w'], reg['s']))
- self.regionCoords.append((reg['w'], reg['n']))
- # draw region extent
- self.DrawLines(pdc=self.pdcDec, polycoords=self.regionCoords)
-
- def IsInRegion(self, region, refRegion):
- """!
- Test if 'region' is inside of 'refRegion'
-
- @param region input region
- @param refRegion reference region (e.g. computational region)
-
- @return True if region is inside of refRegion
- @return False
- """
- if region['s'] >= refRegion['s'] and \
- region['n'] <= refRegion['n'] and \
- region['w'] >= refRegion['w'] and \
- region['e'] <= refRegion['e']:
- return True
-
- return False
-
- def EraseMap(self):
- """!
- Erase the canvas
- """
- self.Draw(self.pdc, pdctype='clear')
-
- if self.pdcVector:
- self.Draw(self.pdcVector, pdctype='clear')
-
- self.Draw(self.pdcDec, pdctype='clear')
- self.Draw(self.pdcTmp, pdctype='clear')
-
- def DragMap(self, moveto):
- """!
- Drag the entire map image for panning.
- """
-
- dc = wx.BufferedDC(wx.ClientDC(self))
- dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- self.dragimg = wx.DragImage(self.buffer)
- self.dragimg.BeginDrag((0, 0), self)
- self.dragimg.GetImageRect(moveto)
- self.dragimg.Move(moveto)
-
- self.dragimg.DoDrawImage(dc, moveto)
- self.dragimg.EndDrag()
-
- return True
-
- def DragItem(self, id, event):
- """!
- Drag an overlay decoration item
- """
- if id == 99 or id == '' or id == None: return
- Debug.msg (5, "BufferedWindow.DragItem(): id=%d" % id)
- x, y = self.lastpos
- dx = event.GetX() - x
- dy = event.GetY() - y
- self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- r = self.pdc.GetIdBounds(id)
- ### FIXME in vdigit/pseudodc.i
- if type(r) is list:
- r = wx.Rect(r[0], r[1], r[2], r[3])
- if id > 100: # text dragging
- rtop = (r[0],r[1]-r[3],r[2],r[3])
- r = r.Union(rtop)
- rleft = (r[0]-r[2],r[1],r[2],r[3])
- r = r.Union(rleft)
- self.pdc.TranslateId(id, dx, dy)
-
- r2 = self.pdc.GetIdBounds(id)
- 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
- r = r.Union(r2)
- r.Inflate(4,4)
- self.RefreshRect(r, False)
- self.lastpos = (event.GetX(), event.GetY())
-
- def MouseDraw(self, pdc=None, begin=None, end=None):
- """!
- Mouse box or line from 'begin' to 'end'
-
- If not given from self.mouse['begin'] to self.mouse['end'].
-
- """
- self.redrawAll = False
-
- if not pdc:
- return
-
- if begin is None:
- begin = self.mouse['begin']
- if end is None:
- end = self.mouse['end']
-
- Debug.msg (5, "BufferedWindow.MouseDraw(): use=%s, box=%s, begin=%f,%f, end=%f,%f" % \
- (self.mouse['use'], self.mouse['box'],
- begin[0], begin[1], end[0], end[1]))
-
- if self.mouse['box'] == "box":
- boxid = wx.ID_NEW
- mousecoords = [begin[0], begin[1],
- end[0], end[1]]
- r = pdc.GetIdBounds(boxid)
- if type(r) is list:
- r = wx.Rect(r[0], r[1], r[2], r[3])
- r.Inflate(4, 4)
- try:
- pdc.ClearId(boxid)
- except:
- pass
- self.RefreshRect(r, False)
- pdc.SetId(boxid)
- self.Draw(pdc, drawid=boxid, pdctype='box', coords=mousecoords)
- elif self.mouse['box'] == "line" or self.mouse['box'] == 'point':
- self.lineid = wx.ID_NEW
- mousecoords = [begin[0], begin[1], \
- end[0], end[1]]
- x1=min(begin[0],end[0])
- x2=max(begin[0],end[0])
- y1=min(begin[1],end[1])
- y2=max(begin[1],end[1])
- r = wx.Rect(x1,y1,x2-x1,y2-y1)
- r.Inflate(4,4)
- try:
- pdc.ClearId(self.lineid)
- except:
- pass
- self.RefreshRect(r, False)
- pdc.SetId(self.lineid)
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=mousecoords)
-
- def DrawLines(self, pdc=None, polycoords=None):
- """!
- Draw polyline in PseudoDC
-
- Set self.pline to wx.NEW_ID + 1
-
- polycoords - list of polyline vertices, geographical coordinates
- (if not given, self.polycoords is used)
-
- """
- if not pdc:
- pdc = self.pdcTmp
-
- if not polycoords:
- polycoords = self.polycoords
-
- if len(polycoords) > 0:
- self.plineid = wx.ID_NEW + 1
- # convert from EN to XY
- coords = []
- for p in polycoords:
- coords.append(self.Cell2Pixel(p))
-
- self.Draw(pdc, drawid=self.plineid, pdctype='polyline', coords=coords)
-
- Debug.msg (4, "BufferedWindow.DrawLines(): coords=%s, id=%s" % \
- (coords, self.plineid))
-
- return self.plineid
-
- return -1
-
- def DrawCross(self, pdc, coords, size, rotation=0,
- text=None, textAlign='lr', textOffset=(5, 5)):
- """!Draw cross in PseudoDC
-
- @todo implement rotation
-
- @param pdc PseudoDC
- @param coord center coordinates
- @param rotation rotate symbol
- @param text draw also text (text, font, color, rotation)
- @param textAlign alignment (default 'lower-right')
- @textOffset offset for text (from center point)
- """
- Debug.msg(4, "BufferedWindow.DrawCross(): pdc=%s, coords=%s, size=%d" % \
- (pdc, coords, size))
- coordsCross = ((coords[0] - size, coords[1], coords[0] + size, coords[1]),
- (coords[0], coords[1] - size, coords[0], coords[1] + size))
-
- self.lineid = wx.NewId()
- for lineCoords in coordsCross:
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=lineCoords)
-
- if not text:
- return self.lineid
-
- if textAlign == 'ul':
- coord = [coords[0] - textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'ur':
- coord = [coords[0] + textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'lr':
- coord = [coords[0] + textOffset[0], coords[1] + textOffset[1], 0, 0]
- else:
- coord = [coords[0] - textOffset[0], coords[1] + textOffset[1], 0, 0]
-
- self.Draw(pdc, img=text,
- pdctype='text', coords=coord)
-
- return self.lineid
-
- def MouseActions(self, event):
- """!
- Mouse motion and button click notifier
- """
- if not self.processMouse:
- return
-
- ### if self.redrawAll is False:
- ### self.redrawAll = True
-
- # zoom with mouse wheel
- if event.GetWheelRotation() != 0:
- self.OnMouseWheel(event)
-
- # left mouse button pressed
- elif event.LeftDown():
- self.OnLeftDown(event)
-
- # left mouse button released
- elif event.LeftUp():
- self.OnLeftUp(event)
-
- # dragging
- elif event.Dragging():
- self.OnDragging(event)
-
- # double click
- elif event.ButtonDClick():
- self.OnButtonDClick(event)
-
- # middle mouse button pressed
- elif event.MiddleDown():
- self.OnMiddleDown(event)
-
- # right mouse button pressed
- elif event.RightDown():
- self.OnRightDown(event)
-
- # right mouse button released
- elif event.RightUp():
- self.OnRightUp(event)
-
- elif event.Moving():
- self.OnMouseMoving(event)
-
-# event.Skip()
-
- def OnMouseWheel(self, event):
- """!
- Mouse wheel moved
- """
- self.processMouse = False
- current = event.GetPositionTuple()[:]
- wheel = event.GetWheelRotation()
- Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
- # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
- begin = (current[0] - self.Map.width / 4,
- current[1] - self.Map.height / 4)
- end = (current[0] + self.Map.width / 4,
- current[1] + self.Map.height / 4)
-
- if wheel > 0:
- zoomtype = 1
- else:
- zoomtype = -1
-
- # zoom
- self.Zoom(begin, end, zoomtype)
-
- # redraw map
- self.UpdateMap()
-
- ### self.OnPaint(None)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- self.Refresh()
- self.processMouse = True
-# event.Skip()
-
- def OnDragging(self, event):
- """!
- Mouse dragging with left button down
- """
- Debug.msg (5, "BufferedWindow.MouseAction(): Dragging")
- current = event.GetPositionTuple()[:]
- previous = self.mouse['begin']
- move = (current[0] - previous[0],
- current[1] - previous[1])
-
- digitToolbar = self.parent.toolbars['vdigit']
-
- # dragging or drawing box with left button
- if self.mouse['use'] == 'pan':
- self.DragMap(move)
-
- # dragging decoration overlay item
- elif (self.mouse['use'] == 'pointer' and
- not digitToolbar and
- self.dragid != None):
- self.DragItem(self.dragid, event)
-
- # dragging anything else - rubber band box or line
- else:
- if (self.mouse['use'] == 'pointer' and
- not digitToolbar): return
- self.mouse['end'] = event.GetPositionTuple()[:]
- digitClass = self.parent.digit
- if (event.LeftIsDown() and
- not (digitToolbar and
- digitToolbar.GetAction() in ("moveLine",) and
- digitClass.driver.GetSelected() > 0)):
- # draw box only when left mouse button is pressed
- self.MouseDraw(pdc=self.pdcTmp)
-
-# event.Skip()
-
- def OnLeftDownVDigitAddLine(self, event):
- """!
- Left mouse button down - vector digitizer add new line
- action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- return
-
- if digitToolbar.GetAction('type') in ["point", "centroid"]:
- # add new point
- if digitToolbar.GetAction('type') == 'point':
- point = True
- else:
- point = False
-
- east, north = self.Pixel2Cell(self.mouse['begin'])
- fid = digitClass.AddPoint(mapLayer, point, east, north)
- if fid < 0:
- return
-
- self.UpdateMap(render=False) # redraw map
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
-
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent=self, map=mapLayer,
- cats=cats,
- pos=posWindow,
- action="add")
-
- if not point:
- self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
- digitToolbar.GetLayer())
- self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
- digitToolbar.GetLayer())
-
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
-
- gcmd.RunCommand('db.execute',
- parent = self,
- quiet = True,
- input = sqlfile.name)
-
- if addRecordDlg.mapDBInfo:
- self.__updateATM()
-
- elif digitToolbar.GetAction('type') in ["line", "boundary"]:
- # add new point to the line
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- self.DrawLines(pdc=self.pdcTmp)
-
- def __geomAttrb(self, fid, dialog, attrb, digit, mapLayer):
- """!Trac geometry attributes?"""
- item = self.tree.FindItemByData('maplayer', mapLayer)
- vdigit = self.tree.GetPyData(item)[0]['vdigit']
- if vdigit and \
- vdigit.has_key('geomAttr') and \
- vdigit['geomAttr'].has_key(attrb):
- val = -1
- if attrb == 'length':
- val = digit.GetLineLength(fid)
- type = attrb
- elif attrb == 'area':
- val = digit.GetAreaSize(fid)
- type = attrb
- elif attrb == 'perimeter':
- val = digit.GetAreaPerimeter(fid)
- type = 'length'
-
- if val > 0:
- layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
- column = vdigit['geomAttr'][attrb]['column']
- val = UnitsConvertValue(val, type, vdigit['geomAttr'][attrb]['units'])
- dialog.SetColumnValue(layer, column, val)
- dialog.OnReset()
-
- def __geomAttrbUpdate(self, fids):
- """!Update geometry atrributes of currently selected features
-
- @param fid list feature id
- """
- mapLayer = self.parent.toolbars['vdigit'].GetLayer()
- vectorName = mapLayer.GetName()
- digit = self.parent.digit
- item = self.tree.FindItemByData('maplayer', mapLayer)
- vdigit = self.tree.GetPyData(item)[0]['vdigit']
-
- if vdigit is None or not vdigit.has_key('geomAttr'):
- return
-
- dbInfo = gselect.VectorDBInfo(vectorName)
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for fid in fids:
- for layer, cats in digit.GetLineCats(fid).iteritems():
- table = dbInfo.GetTable(layer)
- for attrb, item in vdigit['geomAttr'].iteritems():
- val = -1
- if attrb == 'length':
- val = digit.GetLineLength(fid)
- type = attrb
- elif attrb == 'area':
- val = digit.GetAreaSize(fid)
- type = attrb
- elif attrb == 'perimeter':
- val = digit.GetAreaPerimeter(fid)
- type = 'length'
-
- if val < 0:
- continue
- val = UnitsConvertValue(val, type, item['units'])
-
- for cat in cats:
- sqlfile.write('UPDATE %s SET %s = %f WHERE %s = %d;\n' % \
- (table, item['column'], val,
- dbInfo.GetKeyColumn(layer), cat))
- sqlfile.file.flush()
- gcmd.RunCommand('db.execute',
- parent = True,
- quiet = True,
- input = sqlfile.name)
-
- def __updateATM(self):
- """!Update open Attribute Table Manager
-
- @todo: use AddDataRow() instead
- """
- # update ATM
- digitToolbar = self.parent.toolbars['vdigit']
- digitVector = digitToolbar.GetLayer().GetName()
-
- for atm in self.lmgr.dialogs['atm']:
- atmVector = atm.GetVectorName()
- if atmVector == digitVector:
- layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
- # TODO: use AddDataRow instead
- atm.LoadData(layer)
-
- def OnLeftDownVDigitEditLine(self, event):
- """!
- Left mouse button down - vector digitizer edit linear feature
- - add new vertex.
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.vdigitMove['id'].append(wx.NewId())
- self.DrawLines(pdc=self.pdcTmp)
-
- def OnLeftDownVDigitMoveLine(self, event):
- """!
- Left mouse button down - vector digitizer move feature/vertex,
- edit linear feature
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- self.vdigitMove = {}
- # geographic coordinates of initial position (left-down)
- self.vdigitMove['begin'] = None
- # list of ids to modify
- self.vdigitMove['id'] = []
- # ids geographic coordinates
- self.vdigitMove['coord'] = {}
-
- if digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # set pen
- pcolor = UserSettings.Get(group='vdigit', key="symbol",
- subkey=["highlight", "color"])
- self.pen = self.polypen = wx.Pen(colour=pcolor,
- width=2, style=wx.SHORT_DASH)
- self.pdcTmp.SetPen(self.polypen)
-
- def OnLeftDownVDigitDisplayCA(self, event):
- """!
- Left mouse button down - vector digitizer display categories
- or attributes action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- return
-
- coords = self.Pixel2Cell(self.mouse['begin'])
-
- # unselect
- digitClass.driver.SetSelected([])
-
- # select feature by point
- cats = {}
- if digitClass.driver.SelectLineByPoint(coords,
- digitClass.GetSelectType()) is None:
- return
-
- if UserSettings.Get(group='vdigit', key='checkForDupl',
- subkey='enabled'):
- lines = digitClass.driver.GetSelected()
- else:
- lines = (digitClass.driver.GetSelected()[0],) # only first found
-
- for line in lines:
- cats[line] = digitClass.GetLineCats(line)
-
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- if digitToolbar.GetAction() == "displayAttrs":
- # select attributes based on coordinates (all layers)
- if self.parent.dialogs['attributes'] is None:
- self.parent.dialogs['attributes'] = \
- dbm_dialogs.DisplayAttributesDialog(parent=self, map=mapLayer,
- cats=cats,
- action="update")
- else:
- # upgrade dialog
- self.parent.dialogs['attributes'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['attributes']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- if not self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Show()
- else:
- if self.parent.dialogs['attributes'] and \
- self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Hide()
-
- else: # displayCats
- if self.parent.dialogs['category'] is None:
- # open new dialog
- dlg = VDigitCategoryDialog(parent=self,
- map=mapLayer,
- cats=cats,
- pos=posWindow,
- title=_("Update categories"))
- self.parent.dialogs['category'] = dlg
- else:
- # update currently open dialog
- self.parent.dialogs['category'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['category']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- if not self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Show()
- else:
- if self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Hide()
-
- self.UpdateMap(render=False)
-
- def OnLeftDownVDigitCopyCA(self, event):
- """!
- Left mouse button down - vector digitizer copy categories
- or attributes action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if not hasattr(self, "copyCatsList"):
- self.copyCatsList = []
- else:
- self.copyCatsIds = []
- self.mouse['box'] = 'box'
-
- def OnLeftDownVDigitCopyLine(self, event):
- """!
- Left mouse button down - vector digitizer copy lines action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if not hasattr(self, "copyIds"):
- self.copyIds = []
- self.layerTmp = None
-
- def OnLeftDownVDigitBulkLine(self, event):
- """!
- Left mouse button down - vector digitizer label 3d vector
- lines
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if len(self.polycoords) > 1: # start new line
- self.polycoords = []
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- if len(self.polycoords) == 1:
- begin = self.Pixel2Cell(self.polycoords[-1])
- end = self.Pixel2Cell(self.mouse['end'])
- else:
- end = self.Pixel2Cell(self.polycoords[-1])
- begin = self.Pixel2Cell(self.mouse['begin'])
-
- self.DrawLines(self.pdcTmp, polycoords = (begin, end))
-
- def OnLeftDown(self, event):
- """!
- Left mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnLeftDown(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['begin'] = event.GetPositionTuple()[:]
-
- if self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if len(self.polycoords) == 0:
- self.mouse['end'] = self.mouse['begin']
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.ClearLines(pdc=self.pdcTmp)
- else:
- self.mouse['begin'] = self.mouse['end']
- elif self.mouse['use'] == 'zoom':
- pass
-
- #
- # vector digizer
- #
- elif self.mouse["use"] == "pointer" and \
- self.parent.toolbars['vdigit']:
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Vector digitizer"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- event.Skip()
- return
-
- if digitToolbar.GetAction() not in ("moveVertex",
- "addVertex",
- "removeVertex",
- "editLine"):
- # set pen
- self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
- self.polypen = wx.Pen(colour='dark green', width=2, style=wx.SOLID)
-
- if digitToolbar.GetAction() in ("addVertex",
- "removeVertex",
- "splitLines"):
- # unselect
- digitClass.driver.SetSelected([])
-
- if digitToolbar.GetAction() == "addLine":
- self.OnLeftDownVDigitAddLine(event)
-
- elif digitToolbar.GetAction() == "editLine" and \
- hasattr(self, "vdigitMove"):
- self.OnLeftDownVDigitEditLine(event)
-
- elif digitToolbar.GetAction() in ("moveLine",
- "moveVertex",
- "editLine") and \
- not hasattr(self, "vdigitMove"):
- self.OnLeftDownVDigitMoveLine(event)
-
- elif digitToolbar.GetAction() in ("displayAttrs"
- "displayCats"):
- self.OnLeftDownVDigitDisplayCA(event)
-
- elif digitToolbar.GetAction() in ("copyCats",
- "copyAttrs"):
- self.OnLeftDownVDigitCopyCA(event)
-
- elif digitToolbar.GetAction() == "copyLine":
- self.OnLeftDownVDigitCopyLine(event)
-
- elif digitToolbar.GetAction() == "zbulkLine":
- self.OnLeftDownVDigitBulkLine(event)
-
- elif self.mouse['use'] == 'pointer':
- # get decoration or text id
- self.idlist = []
- self.dragid = ''
- self.lastpos = self.mouse['begin']
- idlist = self.pdc.FindObjects(self.lastpos[0], self.lastpos[1],
- self.hitradius)
- if 99 in idlist:
- idlist.remove(99)
- if idlist != []:
- self.dragid = idlist[0] #drag whatever is on top
- else:
- pass
-
- event.Skip()
-
- def OnLeftUpVDigitVarious(self, event):
- """!
- Left mouse button up - vector digitizer various actions
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
- pos2 = self.Pixel2Cell(self.mouse['end'])
-
- nselected = 0
- # -> delete line || move line || move vertex
- if digitToolbar.GetAction() in ("moveVertex",
- "editLine"):
- if len(digitClass.driver.GetSelected()) == 0:
- nselected = digitClass.driver.SelectLineByPoint(pos1, type=VDigit_Lines_Type)
-
- if digitToolbar.GetAction() == "editLine":
- try:
- selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- selVertex = None
-
- if selVertex:
- # self.UpdateMap(render=False)
- ids = digitClass.driver.GetSelected(grassId=False)
- # move this line to tmp layer
- self.polycoords = []
- for id in ids:
- if id % 2: # register only vertices
- e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
- self.polycoords.append((e, n))
- digitClass.driver.DrawSelected(False)
-
- if selVertex < ids[-1] / 2:
- # choose first or last node of line
- self.vdigitMove['id'].reverse()
- self.polycoords.reverse()
- else:
- # unselect
- digitClass.driver.SetSelected([])
- del self.vdigitMove
-
- self.UpdateMap(render=False)
-
- elif digitToolbar.GetAction() in ("copyCats",
- "copyAttrs"):
- if not hasattr(self, "copyCatsIds"):
- # 'from' -> select by point
- nselected = digitClass.driver.SelectLineByPoint(pos1, digitClass.GetSelectType())
- if nselected:
- self.copyCatsList = digitClass.driver.GetSelected()
- else:
- # -> 'to' -> select by bbox
- digitClass.driver.SetSelected([])
- # return number of selected features (by box/point)
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- self.copyCatsIds = digitClass.driver.GetSelected()
-
- elif digitToolbar.GetAction() == "queryLine":
- selected = digitClass.SelectLinesByQuery(pos1, pos2)
- nselected = len(selected)
- if nselected > 0:
- digitClass.driver.SetSelected(selected)
-
- else:
- # -> moveLine || deleteLine, etc. (select by point/box)
- if digitToolbar.GetAction() == 'moveLine' and \
- len(digitClass.driver.GetSelected()) > 0:
- nselected = 0
- else:
- if digitToolbar.GetAction() == 'moveLine':
- drawSeg = True
- else:
- drawSeg = False
-
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType(),
- drawSeg)
-
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- if digitToolbar.GetAction() in ("moveLine",
- "moveVertex"):
- # get pseudoDC id of objects which should be redrawn
- if digitToolbar.GetAction() == "moveLine":
- # -> move line
- self.vdigitMove['id'] = digitClass.driver.GetSelected(grassId=False)
- self.vdigitMove['coord'] = digitClass.driver.GetSelectedCoord()
- else: # moveVertex
- self.vdigitMove['id'] = digitClass.driver.GetSelectedVertex(pos1)
- if len(self.vdigitMove['id']) == 0: # no vertex found
- digitClass.driver.SetSelected([])
-
- #
- # check for duplicates
- #
- if UserSettings.Get(group='vdigit', key='checkForDupl', subkey='enabled') is True:
- dupl = digitClass.driver.GetDuplicates()
- self.UpdateMap(render=False)
-
- if dupl:
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- dlg = VDigitDuplicatesDialog(parent=self, data=dupl, pos=posWindow)
-
- if dlg.ShowModal() == wx.ID_OK:
- digitClass.driver.UnSelect(dlg.GetUnSelected())
- # update selected
- self.UpdateMap(render=False)
-
- if digitToolbar.GetAction() != "editLine":
- # -> move line || move vertex
- self.UpdateMap(render=False)
-
- else: # no vector object found
- if not (digitToolbar.GetAction() in ("moveLine",
- "moveVertex") and \
- len(self.vdigitMove['id']) > 0):
- # avoid left-click when features are already selected
- self.UpdateMap(render=False, renderVector=False)
-
- def OnLeftUpVDigitModifyLine(self, event):
- """!
- Left mouse button up - vector digitizer split line, add/remove
- vertex action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
-
- pointOnLine = digitClass.driver.SelectLineByPoint(pos1,
- type=VDigit_Lines_Type)
-
- if not pointOnLine:
- return
-
- if digitToolbar.GetAction() in ["splitLine", "addVertex"]:
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=self.Cell2Pixel(pointOnLine),
- size=5)
- else: # removeVertex
- # get only id of vertex
- try:
- id = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- id = None
-
- if id:
- x, y = self.pdcVector.GetIdBounds(id)[0:2]
- self.pdcVector.RemoveId(id)
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=(x, y),
- size=5)
- else:
- # unselect
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- def OnLeftUpVDigitCopyLine(self, event):
- """!
- Left mouse button up - vector digitizer copy feature action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
- pos2 = self.Pixel2Cell(self.mouse['end'])
-
- if UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True) == '':
- # no background map -> copy from current vector map layer
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
- else:
- # copy features from background map
- self.copyIds += digitClass.SelectLinesFromBackgroundMap(pos1, pos2)
- if len(self.copyIds) > 0:
- color = UserSettings.Get(group='vdigit', key='symbol',
- subkey=['highlight', 'color'])
- colorStr = str(color[0]) + ":" + \
- str(color[1]) + ":" + \
- str(color[2])
- dVectTmp = ['d.vect',
- 'map=%s' % UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True),
- 'cats=%s' % utils.ListOfCatsToRange(self.copyIds),
- '-i',
- 'color=%s' % colorStr,
- 'fcolor=%s' % colorStr,
- 'type=point,line,boundary,centroid',
- 'width=2']
-
- if not self.layerTmp:
- self.layerTmp = self.Map.AddLayer(type='vector',
- name=globalvar.QUERYLAYER,
- command=dVectTmp)
- else:
- self.layerTmp.SetCmd(dVectTmp)
-
- self.UpdateMap(render=True, renderVector=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
-
- self.redrawAll = None
-
- def OnLeftUpVDigitBulkLine(self, event):
- """!
- Left mouse button up - vector digitizer z-bulk line action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- # select lines to be labeled
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- self.DrawLines(pdc=self.pdcTmp) # redraw temp line
- else:
- self.UpdateMap(render=False, renderVector=False)
-
- def OnLeftUpVDigitConnectLine(self, event):
- """!
- Left mouse button up - vector digitizer connect line action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if len(digitClass.driver.GetSelected()) > 0:
- self.UpdateMap(render=False)
-
- def OnLeftUp(self, event):
- """!
- Left mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['end'] = event.GetPositionTuple()[:]
-
- if self.mouse['use'] in ["zoom", "pan"]:
- # set region in zoom or pan
- begin = self.mouse['begin']
- end = self.mouse['end']
- if self.mouse['use'] == 'zoom':
- # set region for click (zero-width box)
- if begin[0] - end[0] == 0 or \
- begin[1] - end[1] == 0:
- # zoom 1/2 of the screen (TODO: settings)
- begin = (end[0] - self.Map.width / 4,
- end[1] - self.Map.height / 4)
- end = (end[0] + self.Map.width / 4,
- end[1] + self.Map.height / 4)
-
- self.Zoom(begin, end, self.zoomtype)
-
- # redraw map
- self.UpdateMap(render=True)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- elif self.mouse["use"] == "query":
- # querying
- self.parent.QueryMap(self.mouse['begin'][0],self.mouse['begin'][1])
-
- elif self.mouse["use"] == "queryVector":
- # editable mode for vector map layers
- self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])
-
- # clear temp canvas
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if self.mouse["use"] == "measure":
- self.parent.MeasureDist(self.mouse['begin'], self.mouse['end'])
-
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- elif self.mouse["use"] == "pointer" and \
- self.parent.GetLayerManager().georectifying:
- # -> georectifying
- coord = self.Pixel2Cell(self.mouse['end'])
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
-
- self.parent.GetLayerManager().georectifying.SetGCPData(coordtype, coord, self)
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] == "pointer" and self.parent.toolbars['vdigit']:
- # digitization tool active
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if hasattr(self, "vdigitMove"):
- if len(digitClass.driver.GetSelected()) == 0:
- self.vdigitMove['begin'] = self.Pixel2Cell(self.mouse['begin']) # left down
-
- # eliminate initial mouse moving efect
- self.mouse['begin'] = self.mouse['end']
-
- if digitToolbar.GetAction() in ("deleteLine",
- "moveLine",
- "moveVertex",
- "copyCats",
- "copyAttrs",
- "editLine",
- "flipLine",
- "mergeLine",
- "snapLine",
- "queryLine",
- "breakLine",
- "typeConv",
- "connectLine"):
- self.OnLeftUpVDigitVarious(event)
-
- elif digitToolbar.GetAction() in ("splitLine",
- "addVertex",
- "removeVertex"):
- self.OnLeftUpVDigitModifyLine(event)
-
- elif digitToolbar.GetAction() == "copyLine":
- self.OnLeftUpVDigitCopyLine(event)
-
- elif digitToolbar.GetAction() == "zbulkLine" and \
- len(self.polycoords) == 2:
- self.OnLeftUpVDigitBulkLine(event)
-
- elif digitToolbar.GetAction() == "connectLine":
- self.OnLeftUpConnectLine(event)
-
- if len(digitClass.driver.GetSelected()) > 0:
- self.redrawAll = None
-
- elif (self.mouse['use'] == 'pointer' and
- self.dragid >= 0):
- # end drag of overlay decoration
-
- if self.dragid < 99 and self.overlays.has_key(self.dragid):
- self.overlays[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- elif self.dragid > 100 and self.textdict.has_key(self.dragid):
- self.textdict[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- else:
- pass
- self.dragid = None
- self.currtxtid = None
-
- def OnButtonDClick(self, event):
- """!
- Mouse button double click
- """
- Debug.msg (5, "BufferedWindow.OnButtonDClick(): use=%s" % \
- self.mouse["use"])
-
- if self.mouse["use"] == "measure":
- # measure
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.Refresh()
- self.SetCursor(self.parent.cursors["default"])
-
- elif self.mouse["use"] == "profile":
- pass
-
- elif self.mouse['use'] == 'pointer' and \
- self.parent.toolbars['vdigit']:
- # vector digitizer
- pass
-
- else:
- # select overlay decoration options dialog
- clickposition = event.GetPositionTuple()[:]
- idlist = self.pdc.FindObjects(clickposition[0], clickposition[1], self.hitradius)
- if idlist == []:
- return
- self.dragid = idlist[0]
-
- # self.ovlcoords[self.dragid] = self.pdc.GetIdBounds(self.dragid)
- if self.dragid > 100:
- self.currtxtid = self.dragid
- self.parent.OnAddText(None)
- elif self.dragid == 0:
- self.parent.OnAddBarscale(None)
- elif self.dragid == 1:
- self.parent.OnAddLegend(None)
-
- def OnRightDown(self, event):
- """!
- Right mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnRightDown(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() in ("moveLine",
- "moveVertex") and \
- hasattr(self, "vdigitMove"):
-
- pFrom = self.vdigitMove['begin']
- pTo = self.Pixel2Cell(event.GetPositionTuple())
-
- move = (pTo[0] - pFrom[0],
- pTo[1] - pFrom[1])
-
- if digitToolbar.GetAction() == "moveLine":
- # move line
- if digitClass.MoveSelectedLines(move) < 0:
- return
- elif digitToolbar.GetAction() == "moveVertex":
- # move vertex
- fid = digitClass.MoveSelectedVertex(pFrom, move)
- if fid < 0:
- return
-
- self.__geomAttrbUpdate([fid,])
-
- del self.vdigitMove
-
- event.Skip()
-
- def OnRightUp(self, event):
- """!
- Right mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnRightUp(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]:
- # -> add new line / boundary
- try:
- map = digitToolbar.GetLayer().GetName()
- except:
- map = None
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-
- if map:
- # mapcoords = []
- # xy -> EN
- # for coord in self.polycoords:
- # mapcoords.append(self.Pixel2Cell(coord))
- if digitToolbar.GetAction('type') == 'line':
- line = True
- else:
- line = False
-
- if len(self.polycoords) < 2: # ignore 'one-point' lines
- return
-
- fid = digitClass.AddLine(map, line, self.polycoords)
- if fid < 0:
- return
-
- position = self.Cell2Pixel(self.polycoords[-1])
- self.polycoords = []
- self.UpdateMap(render=False)
- self.redrawAll = True
- self.Refresh()
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') and \
- (line is True or \
- (not line and fid > 0)):
- posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
- position[1] + self.dialogOffset))
-
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
-
- addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent=self, map=map,
- cats=cats,
- pos=posWindow,
- action="add")
-
- self.__geomAttrb(fid, addRecordDlg, 'length', digitClass,
- digitToolbar.GetLayer())
- # auto-placing centroid
- self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
- digitToolbar.GetLayer())
- self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
- digitToolbar.GetLayer())
-
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
- gcmd.RunCommand('db.execute',
- parent = True,
- quiet = True,
- input = sqlfile.name)
-
- if addRecordDlg.mapDBInfo:
- self.__updateATM()
-
- elif digitToolbar.GetAction() == "deleteLine":
- # -> delete selected vector features
- if digitClass.DeleteSelectedLines() < 0:
- return
- self.__updateATM()
- elif digitToolbar.GetAction() == "splitLine":
- # split line
- if digitClass.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
- return
- elif digitToolbar.GetAction() == "addVertex":
- # add vertex
- fid = digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin']))
- if fid < 0:
- return
- elif digitToolbar.GetAction() == "removeVertex":
- # remove vertex
- fid = digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
- if fid < 0:
- return
- self.__geomAttrbUpdate([fid,])
- elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
- try:
- if digitToolbar.GetAction() == 'copyCats':
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=False) < 0:
- return
- else:
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=True) < 0:
- return
-
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
-
- self.__updateATM()
-
- elif digitToolbar.GetAction() == "editLine" and \
- hasattr(self, "vdigitMove"):
- line = digitClass.driver.GetSelected()
- if digitClass.EditLine(line, self.polycoords) < 0:
- return
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "flipLine":
- if digitClass.FlipLine() < 0:
- return
- elif digitToolbar.GetAction() == "mergeLine":
- if digitClass.MergeLine() < 0:
- return
- elif digitToolbar.GetAction() == "breakLine":
- if digitClass.BreakLine() < 0:
- return
- elif digitToolbar.GetAction() == "snapLine":
- if digitClass.SnapLine() < 0:
- return
- elif digitToolbar.GetAction() == "connectLine":
- if len(digitClass.driver.GetSelected()) > 1:
- if digitClass.ConnectLine() < 0:
- return
- elif digitToolbar.GetAction() == "copyLine":
- if digitClass.CopyLine(self.copyIds) < 0:
- return
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- elif digitToolbar.GetAction() == "zbulkLine" and len(self.polycoords) == 2:
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
-
- selected = digitClass.driver.GetSelected()
- dlg = VDigitZBulkDialog(parent=self, title=_("Z bulk-labeling dialog"),
- nselected=len(selected))
- if dlg.ShowModal() == wx.ID_OK:
- if digitClass.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
- dlg.step.GetValue()) < 0:
- return
- self.UpdateMap(render=False, renderVector=True)
- elif digitToolbar.GetAction() == "typeConv":
- # -> feature type conversion
- # - point <-> centroid
- # - line <-> boundary
- if digitClass.TypeConvForSelectedLines() < 0:
- return
-
- if digitToolbar.GetAction() != "addLine":
- # unselect and re-render
- digitClass.driver.SetSelected([])
- self.polycoords = []
- self.UpdateMap(render=False)
-
- self.redrawAll = True
- self.Refresh()
-
- event.Skip()
-
- def OnMiddleDown(self, event):
- """!
- Middle mouse button pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- # digitization tool
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- if (digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]) or \
- digitToolbar.GetAction() == "editLine":
- # add line or boundary -> remove last point from the line
- try:
- removed = self.polycoords.pop()
- Debug.msg(4, "BufferedWindow.OnMiddleDown(): polycoords_poped=%s" % \
- [removed,])
-
- self.mouse['begin'] = self.Cell2Pixel(self.polycoords[-1])
- except:
- pass
-
- if digitToolbar.GetAction() == "editLine":
- # remove last vertex & line
- if len(self.vdigitMove['id']) > 1:
- self.vdigitMove['id'].pop()
-
- self.UpdateMap(render=False, renderVector=False)
-
- elif digitToolbar.GetAction() in ["deleteLine", "moveLine", "splitLine",
- "addVertex", "removeVertex", "moveVertex",
- "copyCats", "flipLine", "mergeLine",
- "snapLine", "connectLine", "copyLine",
- "queryLine", "breakLine", "typeConv"]:
- # varios tools -> unselected selected features
- digitClass.driver.SetSelected([])
- if digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] and \
- hasattr(self, "vdigitMove"):
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "copyCats":
- try:
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
-
- elif digitToolbar.GetAction() == "copyLine":
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- self.polycoords = []
- self.UpdateMap(render=False) # render vector
-
- elif digitToolbar.GetAction() == "zbulkLine":
- # reset polyline
- self.polycoords = []
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- self.redrawAll = True
-
- def OnMouseMoving(self, event):
- """!
- Motion event and no mouse buttons were pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- self.mouse['end'] = event.GetPositionTuple()[:]
- Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
- (self.mouse['end'][0], self.mouse['end'][1]))
- if digitToolbar.GetAction() == "addLine" and digitToolbar.GetAction('type') in ["line", "boundary"]:
- if len(self.polycoords) > 0:
- self.MouseDraw(pdc=self.pdcTmp, begin=self.Cell2Pixel(self.polycoords[-1]))
- elif digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] \
- and hasattr(self, "vdigitMove"):
- dx = self.mouse['end'][0] - self.mouse['begin'][0]
- dy = self.mouse['end'][1] - self.mouse['begin'][1]
-
- if len(self.vdigitMove['id']) > 0:
- # draw lines on new position
- if digitToolbar.GetAction() == "moveLine":
- # move line
- for id in self.vdigitMove['id']:
- self.pdcTmp.TranslateId(id, dx, dy)
- elif digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # move vertex ->
- # (vertex, left vertex, left line,
- # right vertex, right line)
-
- # do not draw static lines
- if digitToolbar.GetAction() == "moveVertex":
- self.polycoords = []
- ### self.pdcTmp.TranslateId(self.vdigitMove['id'][0], dx, dy)
- self.pdcTmp.RemoveId(self.vdigitMove['id'][0])
- if self.vdigitMove['id'][1] > 0: # previous vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][1])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][1]+1)
- self.polycoords.append((x, y))
- ### x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][0])[0:2])
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- if self.vdigitMove['id'][2] > 0: # next vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][2])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][2]-1)
- self.polycoords.append((x, y))
-
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- else: # edit line
- try:
- if self.vdigitMove['id'][-1] > 0: # previous vertex
- self.MouseDraw(pdc=self.pdcTmp,
- begin=self.Cell2Pixel(self.polycoords[-1]))
- except: # no line
- self.vdigitMove['id'] = []
- self.polycoords = []
-
- self.Refresh() # TODO: use RefreshRect()
- self.mouse['begin'] = self.mouse['end']
-
- elif digitToolbar.GetAction() == "zbulkLine":
- if len(self.polycoords) == 1:
- # draw mouse moving
- self.MouseDraw(self.pdcTmp)
-
- event.Skip()
-
- def ClearLines(self, pdc=None):
- """!
- Clears temporary drawn lines from PseudoDC
- """
- if not pdc:
- pdc=self.pdcTmp
- try:
- pdc.ClearId(self.lineid)
- pdc.RemoveId(self.lineid)
- except:
- pass
-
- try:
- pdc.ClearId(self.plineid)
- pdc.RemoveId(self.plineid)
- except:
- pass
-
- Debug.msg(4, "BufferedWindow.ClearLines(): lineid=%s, plineid=%s" %
- (self.lineid, self.plineid))
-
- ### self.Refresh()
-
- return True
-
- def Pixel2Cell(self, (x, y)):
- """!
- Convert image coordinates to real word coordinates
-
- Input : int x, int y
- Output: float x, float y
- """
-
- try:
- x = int(x)
- y = int(y)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- east = w + x * res
- north = n - y * res
-
- # extent does not correspond with whole map canvas area...
- # east = self.Map.region['w'] + x * self.Map.region["ewres"]
- # north = self.Map.region['n'] - y * self.Map.region["nsres"]
-
- return (east, north)
-
- def Cell2Pixel(self, (east, north)):
- """!
- Convert real word coordinates to image coordinates
- """
-
- try:
- east = float(east)
- north = float(north)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- # x = int((east - w) / res)
- # y = int((n - north) / res)
-
- x = (east - w) / res
- y = (n - north) / res
-
- return (x, y)
-
- def Zoom(self, begin, end, zoomtype):
- """!
- Calculates new region while (un)zoom/pan-ing
- """
- x1, y1 = begin
- x2, y2 = end
- newreg = {}
-
- # threshold - too small squares do not make sense
- # can only zoom to windows of > 5x5 screen pixels
- if abs(x2-x1) > 5 and abs(y2-y1) > 5 and zoomtype != 0:
-
- if x1 > x2:
- x1, x2 = x2, x1
- if y1 > y2:
- y1, y2 = y2, y1
-
- # zoom in
- if zoomtype > 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((x1, y1))
- newreg['e'], newreg['s'] = self.Pixel2Cell((x2, y2))
-
- # zoom out
- elif zoomtype < 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((-x1 * 2, -y1 * 2))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + 2 * \
- (self.Map.width - x2),
- self.Map.height + 2 * \
- (self.Map.height - y2)))
- # pan
- elif zoomtype == 0:
- dx = x1 - x2
- dy = y1 - y2
- newreg['w'], newreg['n'] = self.Pixel2Cell((dx, dy))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + dx,
- self.Map.height + dy))
-
- # if new region has been calculated, set the values
- if newreg != {}:
- # LL locations
- if self.parent.Map.projinfo['proj'] == 'll':
- if newreg['n'] > 90.0:
- newreg['n'] = 90.0
- if newreg['s'] < -90.0:
- newreg['s'] = -90.0
-
- ce = newreg['w'] + (newreg['e'] - newreg['w']) / 2
- cn = newreg['s'] + (newreg['n'] - newreg['s']) / 2
-
- if hasattr(self, "vdigitMove"):
- # xo = self.Cell2Pixel((self.Map.region['center_easting'], self.Map.region['center_northing']))
- # xn = self.Cell2Pixel(ce, cn))
- tmp = self.Pixel2Cell(self.mouse['end'])
-
- # calculate new center point and display resolution
- self.Map.region['center_easting'] = ce
- self.Map.region['center_northing'] = cn
- self.Map.region["ewres"] = (newreg['e'] - newreg['w']) / self.Map.width
- self.Map.region["nsres"] = (newreg['n'] - newreg['s']) / self.Map.height
- self.Map.AlignExtentFromDisplay()
-
- if hasattr(self, "vdigitMove"):
- tmp1 = self.mouse['end']
- tmp2 = self.Cell2Pixel(self.vdigitMove['begin'])
- dx = tmp1[0] - tmp2[0]
- dy = tmp1[1] - tmp2[1]
- self.vdigitMove['beginDiff'] = (dx, dy)
- for id in self.vdigitMove['id']:
- self.pdcTmp.RemoveId(id)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- if self.redrawAll is False:
- self.redrawAll = True
-
- def ZoomBack(self):
- """!
- Zoom to previous extents in zoomhistory list
- """
- zoom = list()
-
- if len(self.zoomhistory) > 1:
- self.zoomhistory.pop()
- zoom = self.zoomhistory[-1]
-
- if len(self.zoomhistory) < 2: # disable tool
- self.parent.toolbars['map'].Enable('zoomback', enable = False)
-
- # zoom to selected region
- self.Map.GetRegion(n = zoom[0], s = zoom[1],
- e = zoom[2], w = zoom[3],
- update = True)
- # update map
- self.UpdateMap()
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- def ZoomHistory(self, n, s, e, w):
- """!
- Manages a list of last 10 zoom extents
-
- Return removed history item if exists
- """
- removed = None
- self.zoomhistory.append((n,s,e,w))
-
- if len(self.zoomhistory) > 10:
- removed = self.zoomhistory.pop(0)
-
- if removed:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s, removed=%s" %
- (self.zoomhistory, removed))
- else:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s" %
- (self.zoomhistory))
-
- if len(self.zoomhistory) > 1:
- self.parent.toolbars['map'].Enable('zoomback')
-
- return removed
-
- def OnZoomToMap(self, event):
- """!
- Set display extents to match selected raster (including NULLs)
- or vector map.
- """
- self.ZoomToMap()
-
- def OnZoomToRaster(self, event):
- """!
- Set display extents to match selected raster map (ignore NULLs)
- """
- self.ZoomToMap(ignoreNulls = True)
-
- def ZoomToMap(self, layers = None, ignoreNulls = False, render = True):
- """!
- Set display extents to match selected raster
- or vector map(s).
-
- @param layer list of layers to be zoom to
- @param ignoreNulls True to ignore null-values
- @param render True to re-render display
- """
- zoomreg = {}
-
- if not layers:
- layers = self.GetSelectedLayer(multi = True)
-
- if not layers:
- return
-
- rast = []
- vect = []
- updated = False
- for l in layers:
- # only raster/vector layers are currently supported
- if l.type == 'raster':
- rast.append(l.name)
- elif l.type == 'vector':
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar and digitToolbar.GetLayer() == l:
- w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
- self.Map.GetRegion(n=n, s=s, w=w, e=e,
- update=True)
- updated = True
- else:
- vect.append(l.name)
-
- if not updated:
- self.Map.GetRegion(rast = rast,
- vect = vect,
- update = True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- if render:
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToWind(self, event):
- """!
- Set display geometry to match computational
- region settings (set with g.region)
- """
- self.Map.region = self.Map.GetRegion()
- ### self.Map.SetRegion(windres=True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToDefault(self, event):
- """!
- Set display geometry to match default region settings
- """
- self.Map.region = self.Map.GetRegion(default=True)
- self.Map.AdjustRegion() # aling region extent to the display
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def DisplayToWind(self, event):
- """!
- Set computational region (WIND file) to
- match display extents
- """
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- # We ONLY want to set extents here. Don't mess with resolution. Leave that
- # for user to set explicitly with g.region
- new = self.Map.AlignResolution()
- gcmd.RunCommand('g.region',
- parent = self,
- overwrite = True,
- n = new['n'],
- s = new['s'],
- e = new['e'],
- w = new['w'],
- rows = int(new['rows']),
- cols = int(new['cols']))
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def ZoomToSaved(self, event):
- """!Set display geometry to match extents in
- saved region file
- """
- dlg = gdialogs.SavedRegion(parent = self,
- title = _("Zoom to saved region extents"),
- loadsave='load')
-
- if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
- dlg.Destroy()
- return
-
- if not grass.find_file(name = dlg.wind, element = 'windows')['name']:
- wx.MessageBox(parent = self,
- message = _("Region <%s> not found. Operation canceled.") % dlg.wind,
- caption = _("Error"), style = wx.ICON_ERROR | wx.OK | wx.CENTRE)
- dlg.Destroy()
- return
-
- self.Map.GetRegion(regionName = dlg.wind,
- update = True)
-
- dlg.Destroy()
-
- self.ZoomHistory(self.Map.region['n'],
- self.Map.region['s'],
- self.Map.region['e'],
- self.Map.region['w'])
-
- self.UpdateMap()
-
- def SaveDisplayRegion(self, event):
- """!
- Save display extents to named region file.
- """
-
- dlg = gdialogs.SavedRegion(parent = self,
- title = _("Save display extents to region file"),
- loadsave='save')
-
- if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
- dlg.Destroy()
- return
-
- # test to see if it already exists and ask permission to overwrite
- if grass.find_file(name = dlg.wind, element = 'windows')['name']:
- overwrite = wx.MessageBox(parent = self,
- message = _("Region file <%s> already exists. "
- "Do you want to overwrite it?") % (dlg.wind),
- caption = _("Warning"), style = wx.YES_NO | wx.CENTRE)
- if (overwrite == wx.YES):
- self.SaveRegion(dlg.wind)
- else:
- self.SaveRegion(dlg.wind)
-
- dlg.Destroy()
-
- def SaveRegion(self, wind):
- """!Save region settings
-
- @param wind region name
- """
- new = self.Map.GetCurrentRegion()
-
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- gcmd.RunCommand('g.region',
- overwrite = True,
- parent = self,
- flags = 'u',
- n = new['n'],
- s = new['s'],
- e = new['e'],
- w = new['w'],
- rows = int(new['rows']),
- cols = int(new['cols']),
- save = wind)
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def Distance(self, beginpt, endpt, screen=True):
- """!Calculete distance
-
- LL-locations not supported
-
- @todo Use m.distance
-
- @param beginpt first point
- @param endpt second point
- @param screen True for screen coordinates otherwise EN
- """
- x1, y1 = beginpt
- x2, y2 = endpt
- if screen:
- dEast = (x2 - x1) * self.Map.region["ewres"]
- dNorth = (y2 - y1) * self.Map.region["nsres"]
- else:
- dEast = (x2 - x1)
- dNorth = (y2 - y1)
-
- return (math.sqrt(math.pow((dEast),2) + math.pow((dNorth),2)), (dEast, dNorth))
Deleted: grass-addons/gui/wxpython/data_catalog/mapdisplay.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/mapdisplay.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/mapdisplay.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,2114 +0,0 @@
-"""!
- at package mapdisp.py
-
- at brief GIS map display canvas, with toolbar for various display
-management functions, and additional toolbars (vector digitizer, 3d
-view).
-
-Can be used either from Layer Manager or as p.mon backend.
-
-Classes:
-- MapFrame
-- MapApp
-
-Usage:
-python mapdisp.py monitor-identifier /path/to/command/file
-
-(C) 2006-2009 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 Michael Barton
- at author Jachym Cepicky
- at author Martin Landa <landa.martin gmail.com>
- at author Mohammed Rashad K.M <rashadkm at gmail dot com> (only modified for DataCatalog)
-"""
-
-import os
-import sys
-import glob
-import math
-import tempfile
-import copy
-
-gbase = os.getenv("GISBASE")
-pypath = os.path.join(gbase,'etc','wxpython','gui_modules')
-sys.path.append(pypath)
-
-import globalvar
-if not os.getenv("GRASS_WXBUNDLED"):
- globalvar.CheckForWx()
-import wx
-import wx.aui
-import wx_utils as wx_utils
-
-try:
- import subprocess
-except:
- CompatPath = os.path.join(globalvar.ETCWXDIR)
- sys.path.append(CompatPath)
- from compat import subprocess
-
-gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
-sys.path.append(gmpath)
-
-grassPath = os.path.join(globalvar.ETCDIR, "python")
-sys.path.append(grassPath)
-
-import render
-import toolbars
-import menuform
-import gselect
-import disp_print
-import gcmd
-import dbm
-import histogram
-import profile
-import globalvar
-import utils
-import gdialogs
-import goutput
-from grass.script import core as grass
-from debug import Debug
-from preferences import globalSettings as UserSettings
-
-
-from mapframe import BufferedWindow
-
-
-
-import images
-imagepath = images.__path__[0]
-sys.path.append(imagepath)
-
-###
-### global variables
-###
-# for standalone app
-cmdfilename = None
-
-class MapFrame(wx.Panel):
- """
- Main frame for map display window. Drawing takes place in child double buffered
- drawing window.
- """
-
- def __init__(self, parent=None, id=wx.ID_ANY, title=_("GRASS GIS - Map display"),
- pos=wx.DefaultPosition, size=wx.DefaultSize,
- style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"],
- tree=None, notebook=None, gismgr=None, page=None,
- Map=None, auimgr=None,frame=None,flag=False):
- """
- Main map display window with toolbars, statusbar and
- DrawWindow
-
- @param toolbars array of activated toolbars, e.g. ['map', 'digit']
- @param tree reference to layer tree
- @param notebook control book ID in Layer Manager
- @param mgr Layer Manager
- @param page notebook page with layer tree
- @param Map instance of render.Map
- """
- self.gismanager = gismgr # Layer Manager object
- self._layerManager = gismgr
- self.Map = Map # instance of render.Map
- self.tree = tree # Layer Manager layer tree object
- self.page = page # Notebook page holding the layer tree
- self.layerbook = notebook # Layer Manager layer tree notebook
- self.parent = parent
- self.frame = frame
- self.statusFlag = flag
- self.statusbar = None
-
- #FIX THIS
-
-
- #
- # available cursors
- #
- self.cursors = {
- # default: cross
- # "default" : wx.StockCursor(wx.CURSOR_DEFAULT),
- "default" : wx.StockCursor(wx.CURSOR_ARROW),
- "cross" : wx.StockCursor(wx.CURSOR_CROSS),
- "hand" : wx.StockCursor(wx.CURSOR_HAND),
- "pencil" : wx.StockCursor(wx.CURSOR_PENCIL),
- "sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
- }
-
- #wx.Frame.__init__(self, parent, id, title, pos, size, style)
-
-
- wx.Panel.__init__(self, parent, id, pos, size, style,name="pg_panel")
- #self.SetName("MapWindow")
-
- #
- # set the size & system icon
- #
- #self.SetClientSize(size)
- self.iconsize = (16, 16)
-
-
-
-
- #self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO))
-
- #
- # Fancy gui
- #
- # self._mgr = auimgr
-
-
-
- self._mgr = wx.aui.AuiManager(self)
-
- #self._layerManager.goutput = goutput.GMConsole(self.parent.GetParent(), pageid=1)
- #self._layerManager.goutput.Hide()
-
- #
- # Add toolbars
- #
- self.toolbars = { 'map' : None,
- 'vdigit' : None,
- 'georect' : None,
- 'nviz' : None }
- for toolb in toolbars:
- self.AddToolbar(toolb)
-
- #
- # Add statusbar
- #
- if self.statusFlag:
- self.statusbar = self.frame.CreateStatusBar(number=4, style=0)
- self.statusbar.SetStatusWidths([-5, -2, -1, -1])
- else:
- self.statusbar = self.frame.GetStatusBar()
-
-
-
- self.statusbarWin = dict()
- self.statusbarWin['toggle'] = wx.Choice(self.statusbar, wx.ID_ANY,
- choices = globalvar.MAP_DISPLAY_STATUSBAR_MODE)
- self.statusbarWin['toggle'].SetSelection(UserSettings.Get(group='display',
- key='statusbarMode',
- subkey='selection'))
-
- self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.statusbarWin['toggle'])
-
- # auto-rendering checkbox
- self.statusbarWin['render'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Render"))
-
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleRender, self.statusbarWin['render'])
-
- self.statusbarWin['render'].SetValue(UserSettings.Get(group='display',
- key='autoRendering',
- subkey='enabled'))
- self.statusbarWin['render'].SetToolTip(wx.ToolTip (_("Enable/disable auto-rendering")))
- # show region
- self.statusbarWin['region'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Show computational extent"))
-
-
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.statusbarWin['region'])
-
- self.statusbarWin['region'].SetValue(False)
- self.statusbarWin['region'].Hide()
- self.statusbarWin['region'].SetToolTip(wx.ToolTip (_("Show/hide computational "
- "region extent (set with g.region). "
- "Display region drawn as a blue box inside the "
- "computational region, "
- "computational region inside a display region "
- "as a red box).")))
- # set resolution
- self.statusbarWin['resolution'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Constrain display resolution to computational settings"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.statusbarWin['resolution'])
- self.statusbarWin['resolution'].SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
- self.statusbarWin['resolution'].Hide()
- self.statusbarWin['resolution'].SetToolTip(wx.ToolTip (_("Constrain display resolution "
- "to computational region settings. "
- "Default value for new map displays can "
- "be set up in 'User GUI settings' dialog.")))
- # map scale
- self.statusbarWin['mapscale'] = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
- value="", style=wx.TE_PROCESS_ENTER,
- size=(150, -1))
- self.statusbarWin['mapscale'].Hide()
- self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.statusbarWin['mapscale'])
-
- # go to
- self.statusbarWin['goto'] = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
- value="", style=wx.TE_PROCESS_ENTER,
- size=(300, -1))
- self.statusbarWin['goto'].Hide()
- self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnGoTo, self.statusbarWin['goto'])
-
- # projection
- self.statusbarWin['projection'] = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Use defined projection"))
- self.statusbarWin['projection'].SetValue(False)
- size = self.statusbarWin['projection'].GetSize()
- self.statusbarWin['projection'].SetMinSize((size[0] + 150, size[1]))
- self.statusbarWin['projection'].SetToolTip(wx.ToolTip (_("Reproject coordinates displayed "
- "in the statusbar. Projection can be "
- "defined in GUI preferences dialog "
- "(tab 'Display')")))
- self.statusbarWin['projection'].Hide()
-
- # mask
- self.statusbarWin['mask'] = wx.StaticText(parent = self.statusbar, id = wx.ID_ANY,
- label = '')
- self.statusbarWin['mask'].SetForegroundColour(wx.Colour(255, 0, 0))
-
- # on-render gauge
- self.statusbarWin['progress'] = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
- range=0, style=wx.GA_HORIZONTAL)
- self.statusbarWin['progress'].Hide()
-
- self.StatusbarReposition() # reposition statusbar
-
- self.maskInfo = wx.StaticText(parent = self.statusbar, id = wx.ID_ANY,
- label = '')
- self.maskInfo.SetForegroundColour(wx.Colour(255, 0, 0))
-
- #
- # Init map display (buffered DC & set default cursor)
- #
-
- self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY, Map=self.Map, tree=self.tree, gismgr=self._layerManager)
- # default is 2D display mode
- self.MapWindow = self.MapWindow2D
- #self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
- self.MapWindow.SetCursor(self.cursors["default"])
- # used by Nviz (3D display mode)
- self.MapWindow3D = None
-
- #
- # initialize region values
- #
- self.__InitDisplay()
-
- #
- # Bind various events
- #
- self.Bind(wx.EVT_ACTIVATE, self.OnFocus)
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.Bind(render.EVT_UPDATE_PRGBAR, self.OnUpdateProgress)
-
- #
- # Update fancy gui style
- #
- self._mgr.AddPane(self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
-
-
- self._mgr.Update()
-
- #
- # Init print module and classes
- #
- self.printopt = disp_print.PrintOptions(self, self.MapWindow)
-
- #
- # Initialization of digitization tool
- #
- self.digit = None
-
- #
- # Init zoom history
- #
- self.MapWindow.ZoomHistory(self.Map.region['n'],
- self.Map.region['s'],
- self.Map.region['e'],
- self.Map.region['w'])
-
- #
- # Re-use dialogs
- #
- self.dialogs = {}
- self.dialogs['attributes'] = None
- self.dialogs['category'] = None
- self.dialogs['barscale'] = None
- self.dialogs['legend'] = None
-
- self.decorationDialog = None # decoration/overlays
-
- pos = wx.Point(700,10)
-
-
-
- parent1 = self.GetParent()
- rightpanel = parent1.GetParent()
- splitter= rightpanel.GetParent()
- self.lmgr= splitter.GetParent()
-
- self.onRenderGauge = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
- range=0, style=wx.GA_HORIZONTAL)
-
- self.compResolution = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Constrain display resolution to computational settings"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.compResolution)
- self.compResolution.SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
- self.compResolution.Hide()
- self.compResolution.SetToolTip(wx.ToolTip (_("Constrain display resolution "
- "to computational region settings. "
- "Default value for new map displays can "
- "be set up in 'User GUI settings' dialog.")))
-
- self.maptree = wx_utils.AddLayerTree(self, id=wx.ID_ANY, pos=wx.DefaultPosition,
- size=wx.DefaultSize, style=wx.TR_HAS_BUTTONS
- |wx.TR_LINES_AT_ROOT|wx.TR_HIDE_ROOT
- |wx.TR_DEFAULT_STYLE|wx.NO_BORDER|wx.FULL_REPAINT_ON_RESIZE,
- frame=parent,Map=self.Map,lmgr=self.lmgr)
- #self.maptree.SetBackgroundColour("red")
-
- self._mgr.AddPane(self.maptree, wx.aui.AuiPaneInfo().Right().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0).Caption("Layers"))
-
- self._mgr.Update()
-
- #r.rightSizer.Add(self.maptree)
-
- def AddToolbar(self, name):
- """
- Add defined toolbar to the window
-
- Currently known toolbars are:
- - map basic map toolbar
- - digit vector digitizer
- - georect georectifier
- """
- # default toolbar
- if name == "map":
- self.toolbars['map'] = toolbars.MapToolbar(self, self.Map)
-
- self._mgr.AddPane(self.toolbars['map'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("maptoolbar").Caption(_("Map Toolbar")).
- ToolbarPane().Top().
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2).
- BestSize((self.toolbars['map'].GetToolbar().GetSize())))
-
- # vector digitizer
- elif name == "vdigit":
- from vdigit import haveVDigit
- if not haveVDigit:
- from vdigit import errorMsg
- msg = _("Unable to start vector digitizer.\nThe VDigit python extension "
- "was not found or loaded properly.\n"
- "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg)
-
- self.toolbars['map'].combo.SetValue (_("2D view"))
- wx.MessageBox(parent=self,
- message=msg,
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- if self._layerManager:
- log = self._layerManager.goutput
- else:
- log = None
- self.toolbars['vdigit'] = toolbars.VDigitToolbar(parent=self, map=self.Map,
- layerTree=self.tree,
- log=log)
-
- for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
- self._mgr.AddPane(self.toolbars['vdigit'].toolbar[toolRow],
- wx.aui.AuiPaneInfo().
- Name("vdigittoolbar" + str(toolRow)).Caption(_("Vector digitizer toolbar")).
- ToolbarPane().Top().Row(toolRow + 1).
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2).
- BestSize((self.toolbars['vdigit'].GetToolbar().GetSize())))
-
- # change mouse to draw digitized line
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.zoomtype = 0
- self.MapWindow.pen = wx.Pen(colour='red', width=2, style=wx.SOLID)
- self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SOLID)
- # georectifier
- elif name == "georect":
- self.toolbars['georect'] = toolbars.GRToolbar(self, self.Map)
-
- self._mgr.AddPane(self.toolbars['georect'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("georecttoolbar").Caption(_("Georectification toolbar")).
- ToolbarPane().Top().
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2))
- # nviz
- elif name == "nviz":
- import nviz
-
- # check for GLCanvas and OpenGL
- msg = None
- if not nviz.haveGLCanvas:
- msg = _("Unable to switch to 3D display mode.\nThe GLCanvas class has not been "
- "included with this build "
- "of wxPython!\nSwitching back to "
- "2D display mode.\n\nDetails: %s" % nviz.errorMsg)
- if not nviz.haveNviz:
- msg = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
- "was not found or loaded properly.\n"
- "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg)
-
- if msg:
- self.toolbars['map'].combo.SetValue (_("2D view"))
- wx.MessageBox(parent=self,
- message=msg,
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- #
- # add Nviz toolbar and disable 2D display mode tools
- #
- self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
- self.toolbars['map'].Enable2D(False)
-
- #
- # update layer tree (-> enable 3d-rasters)
- #
- if self.tree:
- self.tree.EnableItemType(type='3d-raster', enable=True)
-
- #
- # update status bar
- #
- self.statusbarWin['toggle'].Enable(False)
-
- #
- # erase map window
- #
- self.MapWindow.EraseMap()
-
- self.statusbar.SetStatusText(_("Please wait, loading data..."), 0)
-
- #
- # create GL window & NVIZ toolbar
- #
- if not self.MapWindow3D:
- print "xx " + self.GetName()
- self.MapWindow3D = nviz.GLWindow(self, id=wx.ID_ANY, Map=self.Map, tree=self.maptree, gismgr=self._layerManager)
- # -> show after paint
- self.nvizToolWin = nviz.NvizToolWindow(self, id=wx.ID_ANY,
- mapWindow=self.MapWindow3D)
- self.MapWindow3D.OnPaint(None) # -> LoadData
- self.MapWindow3D.Show()
- self.MapWindow3D.UpdateView(None)
-
- self.nvizToolWin.Show()
-
- #
- # switch from MapWindow to MapWindowGL
- # add nviz toolbar
- #
- self._mgr.DetachPane(self.MapWindow2D)
- self.MapWindow2D.Hide()
- self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
- self._mgr.AddPane(self.toolbars['nviz'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("nviztoolbar").Caption(_("Nviz toolbar")).
- ToolbarPane().Top().Row(1).
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2))
-
- self.MapWindow = self.MapWindow3D
- self.frame.SetStatusText("", 0)
-
- self._mgr.Update()
-
- def RemoveToolbar (self, name):
- """
- Removes toolbar from the window
-
- TODO: Only hide, activate by calling AddToolbar()
- """
-
- # cannot hide main toolbar
- if name == "map":
- return
- elif name == "vdigit":
- # TODO: not destroy only hide
- for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
- self._mgr.DetachPane (self.toolbars['vdigit'].toolbar[toolRow])
- self.toolbars['vdigit'].toolbar[toolRow].Destroy()
- else:
- self._mgr.DetachPane (self.toolbars[name].toolbar)
- self.toolbars[name].toolbar.Destroy()
-
- self.toolbars[name] = None
-
- if name == 'nviz':
- # hide nviz tools
- self.nvizToolWin.Hide()
- # unload data
- # self.MapWindow3D.Reset()
- # switch from MapWindowGL to MapWindow
- self._mgr.DetachPane(self.MapWindow3D)
- self.MapWindow3D.Hide()
- self.MapWindow2D.Show()
- self._mgr.AddPane(self.MapWindow2D, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
- self.MapWindow = self.MapWindow2D
-
- #
- # update layer tree (-> disable 3d-rasters)
- #
- if self.tree:
- self.tree.EnableItemType(type='3d-raster', enable=False)
- self.MapWindow.UpdateMap()
-
- self.toolbars['map'].combo.SetValue (_("2D view"))
- self.toolbars['map'].Enable2D(True)
- self.statusbarWin['toggle'].Enable(True)
-
- self._mgr.Update()
-
- def __InitDisplay(self):
- """
- Initialize map display, set dimensions and map region
- """
- self.width, self.height = self.GetClientSize()
-
- Debug.msg(2, "MapFrame.__InitDisplay():")
- self.Map.ChangeMapSize(self.GetClientSize())
- self.Map.region = self.Map.GetRegion() # g.region -upgc
- # self.Map.SetRegion() # adjust region to match display window
-
- def OnUpdateProgress(self, event):
- """
- Update progress bar info
- """
- self.statusbarWin['progress'].SetValue(event.value)
-
- event.Skip()
-
- def OnFocus(self, event):
- """
- Change choicebook page to match display.
- Or set display for georectifying
- """
- if self._layerManager and \
- self._layerManager.georectifying:
- # in georectifying session; display used to get get geographic
- # coordinates for GCPs
- self.OnPointer(event)
- else:
- # change bookcontrol page to page associated with display
- if self.page:
- pgnum = self.layerbook.GetPageIndex(self.page)
- if pgnum > -1:
- self.layerbook.SetSelection(pgnum)
-
- event.Skip()
-
- def OnMotion(self, event):
- """
- Mouse moved
- Track mouse motion and update status bar
- """
- # update statusbar if required
- if self.statusbarWin['toggle'].GetSelection() == 0: # Coordinates
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
- format = UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'll')
- e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
- if self.toolbars['vdigit'] and \
- self.toolbars['vdigit'].GetAction() == 'addLine' and \
- self.toolbars['vdigit'].GetAction('type') in ('line', 'boundary') and \
- len(self.MapWindow.polycoords) > 0:
- # for linear feature show segment and total length
- distance_seg = self.MapWindow.Distance(self.MapWindow.polycoords[-1],
- (e, n), screen=False)[0]
- distance_tot = distance_seg
- for idx in range(1, len(self.MapWindow.polycoords)):
- distance_tot += self.MapWindow.Distance(self.MapWindow.polycoords[idx-1],
- self.MapWindow.polycoords[idx],
- screen=False )[0]
- self.statusbar.SetStatusText("%.*f, %.*f (seg: %.*f; tot: %.*f)" % \
- (precision, e, precision, n,
- precision, distance_seg,
- precision, distance_tot), 0)
- else:
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- proj, coord = utils.ReprojectCoordinates(coord = (e, n),
- projOut = UserSettings.Get(group='projection',
- key='statusbar',
- subkey='proj4'),
- flags = 'd')
-
- if coord:
- e, n = coord
- if proj in ('ll', 'latlong', 'longlat') and format == 'DMS':
- self.statusbar.SetStatusText("%s" % \
- utils.Deg2DMS(e, n, precision = precision),
- 0)
- else:
- self.statusbar.SetStatusText("%.*f; %.*f" % \
- (precision, e, precision, n), 0)
- else:
- self.statusbar.SetStatusText(_("Error in projection (check the settings)"), 0)
- else:
- if self.Map.projinfo['proj'] == 'll' and format == 'DMS':
- self.statusbar.SetStatusText("%s" % \
- utils.Deg2DMS(e, n, precision = precision),
- 0)
- else:
- self.statusbar.SetStatusText("%.*f; %.*f" % \
- (precision, e, precision, n), 0)
-
- event.Skip()
-
- def OnDraw(self, event):
- """
- Re-display current map composition
- """
- self.MapWindow.UpdateMap(render=False)
-
- def OnRender(self, event):
- """
- Re-render map composition (each map layer)
- """
- # delete tmp map layers (queries)
- qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)
- for layer in qlayer:
- self.Map.DeleteLayer(layer)
-
- # delete tmp lines
- if self.MapWindow.mouse["use"] in ("measure",
- "profile"):
- self.MapWindow.polycoords = []
- self.MapWindow.ClearLines()
-
- # deselect features in vdigit
- if self.toolbars['vdigit'] and self.digit:
- self.digit.driver.SetSelected([])
- self.MapWindow.UpdateMap(render=True, renderVector=True)
- else:
- self.MapWindow.UpdateMap(render=True)
-
- # update statusbar
- self.StatusbarUpdate()
-
- def OnPointer(self, event):
- """
- Pointer button clicked
- """
- if self.toolbars['map']:
- if event:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "pointer"
- self.MapWindow.mouse['box'] = "point"
-
- # change the cursor
- if self.toolbars['vdigit']:
- # digitization tool activated
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- # reset mouse['box'] if needed
- if self.toolbars['vdigit'].GetAction() in ['addLine']:
- if self.toolbars['vdigit'].GetAction('type') in ['point', 'centroid']:
- self.MapWindow.mouse['box'] = 'point'
- else: # line, boundary
- self.MapWindow.mouse['box'] = 'line'
- elif self.toolbars['vdigit'].GetAction() in ['addVertex', 'removeVertex', 'splitLine',
- 'editLine', 'displayCats', 'displayAttrs',
- 'copyCats']:
- self.MapWindow.mouse['box'] = 'point'
- else: # moveLine, deleteLine
- self.MapWindow.mouse['box'] = 'box'
-
- elif self._layerManager and self._layerManager.georectifying:
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- else:
- self.MapWindow.SetCursor(self.cursors["default"])
-
- def OnZoomIn(self, event):
- """
- Zoom in the map.
- Set mouse cursor, zoombox attributes, and zoom direction
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "zoom"
- self.MapWindow.mouse['box'] = "box"
- self.MapWindow.zoomtype = 1
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnZoomOut(self, event):
- """
- Zoom out the map.
- Set mouse cursor, zoombox attributes, and zoom direction
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "zoom"
- self.MapWindow.mouse['box'] = "box"
- self.MapWindow.zoomtype = -1
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnZoomBack(self, event):
- """
- Zoom last (previously stored position)
- """
- self.MapWindow.ZoomBack()
-
- def OnPan(self, event):
- """
- Panning, set mouse to drag
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "pan"
- self.MapWindow.mouse['box'] = "pan"
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["hand"])
-
- def OnErase(self, event):
- """
- Erase the canvas
- """
- self.MapWindow.EraseMap()
-
- def OnZoomRegion(self, event):
- """
- Zoom to region
- """
- self.Map.getRegion()
- self.Map.getResolution()
- self.UpdateMap()
- # event.Skip()
-
- def OnAlignRegion(self, event):
- """
- Align region
- """
- if not self.Map.alignRegion:
- self.Map.alignRegion = True
- else:
- self.Map.alignRegion = False
- # event.Skip()
-
- def OnToggleRender(self, event):
- """
- Enable/disable auto-rendering
- """
- if self.statusbarWin['render'].GetValue():
- self.OnRender(None)
-
- def OnToggleShowRegion(self, event):
- """
- Show/Hide extent in map canvas
- """
- if self.statusbarWin['region'].GetValue():
- # show extent
- self.MapWindow.regionCoords = []
- else:
- del self.MapWindow.regionCoords
-
- # redraw map if auto-rendering is enabled
- if self.statusbarWin['render'].GetValue():
- self.OnRender(None)
-
- def OnToggleResolution(self, event):
- """
- Use resolution of computation region settings
- for redering image instead of display resolution
- """
- # redraw map if auto-rendering is enabled
- if self.statusbarWin['render'].GetValue():
- self.OnRender(None)
-
- def OnToggleStatus(self, event):
- """
- Toggle status text
- """
- self.StatusbarUpdate()
-
- def OnChangeMapScale(self, event):
- """
- Map scale changed by user
- """
- scale = event.GetString()
-
- try:
- if scale[:2] != '1:':
- raise ValueError
- value = int(scale[2:])
- except ValueError:
- self.statusbarWin['mapscale'].SetValue('1:%ld' % int(self.mapScaleValue))
- return
-
- dEW = value * (self.Map.region['cols'] / self.ppm[0])
- dNS = value * (self.Map.region['rows'] / self.ppm[1])
- self.Map.region['n'] = self.Map.region['center_northing'] + dNS / 2.
- self.Map.region['s'] = self.Map.region['center_northing'] - dNS / 2.
- self.Map.region['w'] = self.Map.region['center_easting'] - dEW / 2.
- self.Map.region['e'] = self.Map.region['center_easting'] + dEW / 2.
-
- # add to zoom history
- self.MapWindow.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- # redraw a map
- self.MapWindow.UpdateMap()
- self.statusbarWin['mapscale'].SetFocus()
-
- def OnGoTo(self, event):
- """
- Go to position
- """
- try:
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- # reproject values
- projIn = UserSettings.Get(group='projection',
- key='statusbar',
- subkey='proj4')
- projOut = gcmd.RunCommand('g.proj',
- flags = 'jf',
- read = True)
- proj = projIn.split(' ')[0].split('=')[1]
- if proj in ('ll', 'latlong', 'longlat'):
- e, n = self.statusbarWin['goto'].GetValue().split(';')
- e, n = utils.DMS2Deg(e, n)
- proj, coord1 = utils.ReprojectCoordinates(coord = (e, n),
- projIn = projIn,
- projOut = projOut, flags = 'd')
- e, n = coord1
- else:
- e, n = map(float, self.statusbarWin['goto'].GetValue().split(';'))
- proj, coord1 = utils.ReprojectCoordinates(coord = (e, n),
- projIn = projIn,
- projOut = projOut, flags = 'd')
- e, n = coord1
- else:
- if self.Map.projinfo['proj'] == 'll':
- e, n = self.statusbarWin['goto'].GetValue().split(';')
- else:
- e, n = map(float, self.statusbarWin['goto'].GetValue().split(';'))
-
- region = self.Map.GetCurrentRegion()
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- region['center_easting'], region['center_northing'] = e, n
- else:
- if self.Map.projinfo['proj'] == 'll':
- region['center_easting'], region['center_northing'] = utils.DMS2Deg(e, n)
- else:
- region['center_easting'], region['center_northing'] = e, n
- except ValueError:
- region = self.Map.GetCurrentRegion()
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
- format = UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'll')
- if self.Map.projinfo['proj'] == 'll' and format == 'DMS':
- self.statusbarWin['goto'].SetValue("%s" % utils.Deg2DMS(region['center_easting'],
- region['center_northing'],
- precision = precision))
- else:
- self.statusbarWin['goto'].SetValue("%.*f; %.*f" % \
- (precision, region['center_easting'],
- precision, region['center_northing']))
- return
-
-
- dn = (region['nsres'] * region['rows']) / 2.
- region['n'] = region['center_northing'] + dn
- region['s'] = region['center_northing'] - dn
- de = (region['ewres'] * region['cols']) / 2.
- region['e'] = region['center_easting'] + de
- region['w'] = region['center_easting'] - de
-
- self.Map.AdjustRegion()
-
- # add to zoom history
- self.MapWindow.ZoomHistory(region['n'], region['s'],
- region['e'], region['w'])
-
- # redraw a map
- self.MapWindow.UpdateMap()
- self.statusbarWin['goto'].SetFocus()
-
- def StatusbarUpdate(self):
- """!Update statusbar content"""
-
- self.statusbarWin['region'].Hide()
- self.statusbarWin['resolution'].Hide()
- self.statusbarWin['mapscale'].Hide()
- self.statusbarWin['goto'].Hide()
- self.statusbarWin['projection'].Hide()
- self.mapScaleValue = self.ppm = None
-
- if self.statusbarWin['toggle'].GetSelection() == 0: # Coordinates
- self.statusbar.SetStatusText("", 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.statusbarWin['toggle'].GetSelection() in (1, 2): # Extent
- sel = self.statusbarWin['toggle'].GetSelection()
- if sel == 1:
- region = self.Map.region
- else:
- region = self.Map.GetRegion() # computation region
-
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
- format = UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'll')
-
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- projOut = UserSettings.Get(group='projection',
- key='statusbar',
- subkey='proj4')
- proj, coord1 = utils.ReprojectCoordinates(coord = (region["w"], region["s"]),
- projOut = projOut, flags = 'd')
- proj, coord2 = utils.ReprojectCoordinates(coord = (region["e"], region["n"]),
- projOut = projOut, flags = 'd')
- if sel == 2:
- proj, coord3 = utils.ReprojectCoordinates(coord = (0.0, 0.0),
- projOut = projOut, flags = 'd')
- proj, coord4 = utils.ReprojectCoordinates(coord = (region["ewres"], region["nsres"]),
- projOut = projOut, flags = 'd')
- if coord1 and coord2:
- if proj in ('ll', 'latlong', 'longlat') and format == 'DMS':
- w, s = utils.Deg2DMS(coord1[0], coord1[1], string = False,
- precision = precision)
- e, n = utils.Deg2DMS(coord2[0], coord2[1], string = False,
- precision = precision)
- if sel == 1:
- self.statusbar.SetStatusText("%s - %s, %s - %s" %
- (w, e, s, n), 0)
- else:
- ewres, nsres = utils.Deg2DMS(abs(coord3[0]) - abs(coord4[0]),
- abs(coord3[1]) - abs(coord4[1]),
- string = False, hemisphere = False,
- precision = precision)
- self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
- (w, e, s, n, ewres, nsres), 0)
- else:
- w, s = coord1
- e, n = coord2
- if sel == 1:
- self.statusbar.SetStatusText("%.*f - %.*f, %.*f - %.*f" %
- (precision, w, precision, e,
- precision, s, precision, n), 0)
- else:
- ewres, nsres = coord3
- self.statusbar.SetStatusText("%.*f - %.*f, %.*f - %.*f (%.*f, %.*f)" %
- (precision, w, precision, e,
- precision, s, precision, n,
- precision, ewres, precision, nsres), 0)
- else:
- self.statusbar.SetStatusText(_("Error in projection (check the settings)"), 0)
- else:
- if self.Map.projinfo['proj'] == 'll' and format == 'DMS':
- w, s = utils.Deg2DMS(region["w"], region["s"],
- string = False, precision = precision)
- e, n = utils.Deg2DMS(region["e"], region["n"],
- string = False, precision = precision)
- if sel == 1:
- self.statusbar.SetStatusText("%s - %s, %s - %s" %
- (w, e, s, n), 0)
- else:
- ewres, nsres = utils.Deg2DMS(region['ewres'], region['nsres'],
- string = False, precision = precision)
- self.statusbar.SetStatusText("%s - %s, %s - %s (%s, %s)" %
- (w, e, s, n, ewres, nsres), 0)
- else:
- w, s = region["w"], region["s"]
- e, n = region["e"], region["n"]
- if sel == 1:
- self.statusbar.SetStatusText("%.*f - %.*f, %.*f - %.*f" %
- (precision, w, precision, e,
- precision, s, precision, n), 0)
- else:
- ewres, nsres = region['ewres'], region['nsres']
- self.statusbar.SetStatusText("%.*f - %.*f, %.*f - %.*f (%.*f, %.*f)" %
- (precision, w, precision, e,
- precision, s, precision, n,
- precision, ewres, precision, nsres), 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.statusbarWin['toggle'].GetSelection() == 3: # Show comp. extent
- self.statusbar.SetStatusText("", 0)
- self.statusbarWin['region'].Show()
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.statusbarWin['toggle'].GetSelection() == 4: # Display mode
- self.statusbar.SetStatusText("", 0)
- self.statusbarWin['resolution'].Show()
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.statusbarWin['toggle'].GetSelection() == 5: # Display geometry
- self.statusbar.SetStatusText("rows=%d; cols=%d; nsres=%.2f; ewres=%.2f" %
- (self.Map.region["rows"], self.Map.region["cols"],
- self.Map.region["nsres"], self.Map.region["ewres"]), 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.statusbarWin['toggle'].GetSelection() == 6: # Map scale
- # TODO: need to be fixed...
- ### screen X region problem
- ### user should specify ppm
- dc = wx.ScreenDC()
- dpSizePx = wx.DisplaySize() # display size in pixels
- dpSizeMM = wx.DisplaySizeMM() # display size in mm (system)
- dpSizeIn = (dpSizeMM[0] / 25.4, dpSizeMM[1] / 25.4) # inches
- sysPpi = dc.GetPPI()
- comPpi = (dpSizePx[0] / dpSizeIn[0],
- dpSizePx[1] / dpSizeIn[1])
-
- ppi = comPpi # pixel per inch
- self.ppm = ((ppi[0] / 2.54) * 100, # pixel per meter
- (ppi[1] / 2.54) * 100)
-
- Debug.msg(4, "MapFrame.StatusbarUpdate(mapscale): size: px=%d,%d mm=%f,%f "
- "in=%f,%f ppi: sys=%d,%d com=%d,%d; ppm=%f,%f" % \
- (dpSizePx[0], dpSizePx[1], dpSizeMM[0], dpSizeMM[1],
- dpSizeIn[0], dpSizeIn[1],
- sysPpi[0], sysPpi[1], comPpi[0], comPpi[1],
- self.ppm[0], self.ppm[1]))
-
- region = self.Map.region
-
- heightCm = region['rows'] / self.ppm[1] * 100
- widthCm = region['cols'] / self.ppm[0] * 100
-
- Debug.msg(4, "MapFrame.StatusbarUpdate(mapscale): width_cm=%f, height_cm=%f" %
- (widthCm, heightCm))
-
- xscale = (region['e'] - region['w']) / (region['cols'] / self.ppm[0])
- yscale = (region['n'] - region['s']) / (region['rows'] / self.ppm[1])
- scale = (xscale + yscale) / 2.
-
- Debug.msg(3, "MapFrame.StatusbarUpdate(mapscale): xscale=%f, yscale=%f -> scale=%f" % \
- (xscale, yscale, scale))
-
- self.statusbar.SetStatusText("")
- try:
- self.statusbarWin['mapscale'].SetValue("1:%ld" % (scale + 0.5))
- except TypeError:
- pass
- self.mapScaleValue = scale
- self.statusbarWin['mapscale'].Show()
-
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.statusbarWin['toggle'].GetSelection() == 7: # go to
- self.statusbar.SetStatusText("")
- region = self.Map.GetCurrentRegion()
- precision = int(UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'precision'))
- format = UserSettings.Get(group = 'projection', key = 'format',
- subkey = 'll')
-
- if self.statusbarWin['projection'].IsChecked():
- if not UserSettings.Get(group='projection', key='statusbar', subkey='proj4'):
- self.statusbar.SetStatusText(_("Projection not defined (check the settings)"), 0)
- else:
- proj, coord = utils.ReprojectCoordinates(coord = (region['center_easting'],
- region['center_northing']),
- projOut = UserSettings.Get(group='projection',
- key='statusbar',
- subkey='proj4'),
- flags = 'd')
- if coord:
- if proj in ('ll', 'latlong', 'longlat') and format == 'DMS':
- self.statusbarWin['goto'].SetValue("%s" % utils.Deg2DMS(coord[0],
- coord[1],
- precision = precision))
- else:
- self.statusbarWin['goto'].SetValue("%.*f; %.*f" % (precision, coord[0],
- precision, coord[1]))
- else:
- self.statusbar.SetStatusText(_("Error in projection (check the settings)"), 0)
- else:
- if self.Map.projinfo['proj'] == 'll' and format == 'DMS':
- self.statusbarWin['goto'].SetValue("%s" % utils.Deg2DMS(region['center_easting'],
- region['center_northing'],
- precision = precision))
- else:
- self.statusbarWin['goto'].SetValue("%.*f; %.*f" % (precision, region['center_easting'],
- precision, region['center_northing']))
- self.statusbarWin['goto'].Show()
-
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.statusbarWin['toggle'].GetSelection() == 8: # projection
- self.statusbar.SetStatusText("")
- epsg = UserSettings.Get(group='projection', key='statusbar', subkey='epsg')
- if epsg:
- label = '%s (EPSG: %s)' % (_("Use defined projection"), epsg)
- self.statusbarWin['projection'].SetLabel(label)
- else:
- self.statusbarWin['projection'].SetLabel(_("Use defined projection"))
- self.statusbarWin['projection'].Show()
-
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- else:
- self.statusbar.SetStatusText("", 1)
-
- def StatusbarEnableLongHelp(self, enable=True):
- """!Enable/disable toolbars long help"""
- for toolbar in self.toolbars.itervalues():
- if toolbar:
- toolbar.EnableLongHelp(enable)
-
- def StatusbarReposition(self):
- """!Reposition checkbox in statusbar"""
- # reposition checkbox
- widgets = [(0, self.statusbarWin['region']),
- (0, self.statusbarWin['resolution']),
- (0, self.statusbarWin['mapscale']),
- (0, self.statusbarWin['progress']),
- (0, self.statusbarWin['projection']),
- (1, self.statusbarWin['toggle']),
- (2, self.statusbarWin['mask']),
- (3, self.statusbarWin['render'])]
- for idx, win in widgets:
- rect = self.statusbar.GetFieldRect(idx)
- if idx == 0: # show region / mapscale / process bar
- # -> size
- wWin, hWin = win.GetBestSize()
- if win == self.statusbarWin['progress']:
- wWin = rect.width - 6
- # -> position
- # if win == self.statusbarWin['region']:
- # x, y = rect.x + rect.width - wWin, rect.y - 1
- # align left
- # else:
- x, y = rect.x + 3, rect.y - 1
- w, h = wWin, rect.height + 2
- else: # choice || auto-rendering
- x, y = rect.x, rect.y - 1
- w, h = rect.width, rect.height + 2
- if idx == 2: # mask
- x += 5
- y += 4
- elif idx == 3: # render
- x += 5
- win.SetPosition((x, y))
- win.SetSize((w, h))
-
- def SaveToFile(self, event):
- """
- Save image to file
- """
- lext = []
- for h in self.MapWindow.img.GetHandlers():
- lext.append(h.GetExtension())
-
- filetype = "BMP file (*.bmp)|*.bmp|"
- if 'gif' in lext:
- filetype += "GIF file (*.gif)|*.gif|"
- if 'jpg' in lext:
- filetype += "JPG file (*.jpg)|*.jpg|"
- if 'pcx' in lext:
- filetype += "PCX file (*.pcx)|*.pcx|"
- if 'png' in lext:
- filetype += "PNG file (*.png)|*.png|"
- if 'pnm' in lext:
- filetype += "PNM file (*.pnm)|*.pnm|"
- if 'tif' in lext:
- filetype += "TIF file (*.tif)|*.tif|"
- if 'xpm' in lext:
- filetype += "XPM file (*.xpm)|*.xpm"
-
- dlg = wx.FileDialog(self, _("Choose a file name to save the image (no need to add extension)"),
- defaultDir = "",
- defaultFile = "",
- wildcard = filetype,
- style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
- if dlg.ShowModal() == wx.ID_OK:
- path = dlg.GetPath()
- if path == None: return
- base = os.path.splitext(dlg.GetPath())[0]
- ext = os.path.splitext(dlg.GetPath())[1]
- if dlg.GetFilterIndex() == 0:
- type = wx.BITMAP_TYPE_BMP
- if ext != '.bmp': path = base+'.bmp'
- if dlg.GetFilterIndex() == 1:
- type = wx.BITMAP_TYPE_GIF
- if ext != '.gif': path = base+'.gif'
- elif dlg.GetFilterIndex() == 2:
- type = wx.BITMAP_TYPE_JPEG
- if ext != '.jpg': path = base+'.jpg'
- elif dlg.GetFilterIndex() == 3:
- type = wx.BITMAP_TYPE_GIF
- if ext != '.pcx': path = base+'.pcx'
- elif dlg.GetFilterIndex() == 4:
- type = wx.BITMAP_TYPE_PNG
- if ext != '.png': path = base+'.png'
- elif dlg.GetFilterIndex() == 5:
- type = wx.BITMAP_TYPE_PNM
- if ext != '.pnm': path = base+'.pnm'
- elif dlg.GetFilterIndex() == 6:
- type = wx.BITMAP_TYPE_TIF
- if ext != '.tif': path = base+'.tif'
- elif dlg.GetFilterIndex() == 7:
- type = wx.BITMAP_TYPE_XPM
- if ext != '.xpm': path = base+'.xpm'
- self.MapWindow.SaveToFile(path, type)
-
- dlg.Destroy()
-
- def PrintMenu(self, event):
- """
- Print options and output menu for map display
- """
- point = wx.GetMousePosition()
- printmenu = wx.Menu()
- # Add items to the menu
- setup = wx.MenuItem(printmenu, wx.ID_ANY, _('Page setup'))
- printmenu.AppendItem(setup)
- self.Bind(wx.EVT_MENU, self.printopt.OnPageSetup, setup)
-
- preview = wx.MenuItem(printmenu, wx.ID_ANY, _('Print preview'))
- printmenu.AppendItem(preview)
- self.Bind(wx.EVT_MENU, self.printopt.OnPrintPreview, preview)
-
- doprint = wx.MenuItem(printmenu, wx.ID_ANY, _('Print display'))
- printmenu.AppendItem(doprint)
- self.Bind(wx.EVT_MENU, self.printopt.OnDoPrint, doprint)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(printmenu)
- printmenu.Destroy()
-
- def OnCloseWindow(self, event):
- """
- Window closed.
- Also close associated layer tree page
- """
- pgnum = None
- self.Map.Clean()
-
- # close edited map and 3D tools properly
- if self.toolbars['vdigit']:
- maplayer = self.toolbars['vdigit'].GetLayer()
- if maplayer:
- self.toolbars['vdigit'].OnExit()
- self.imgVectorMap = None
-
- if self.toolbars['nviz']:
- self.toolbars['nviz'].OnExit()
-
- if not self._layerManager:
- self.Destroy()
- elif self.page:
- pgnum = self.layerbook.GetPageIndex(self.page)
- if pgnum > -1:
- self.layerbook.DeletePage(pgnum)
-
- def GetRender(self):
- """
- Returns the current instance of render.Map()
- """
- return self.Map
-
- def OnQueryDisplay(self, event):
- """
- Query currrent raster/vector map layers (display mode)
- """
- if self.toolbars['map'].GetAction() == 'displayAttrb': # select previous action
- self.toolbars['map'].SelectDefault(event)
- return
-
- self.toolbars['map'].action['desc'] = 'displayAttrb'
-
- # switch GIS Manager to output console to show query results
- self._layerManager.notebook.SetSelection(1)
-
- self.MapWindow.mouse['use'] = "query"
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnQueryModify(self, event):
- """
- Query vector map layer (edit mode)
- """
- if self.toolbars['map'].GetAction() == 'modifyAttrb': # select previous action
- self.toolbars['map'].SelectDefault(event)
- return
-
- self.toolbars['map'].action['desc'] = 'modifyAttrb'
-
- self.MapWindow.mouse['use'] = "queryVector"
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def QueryMap(self, x, y):
- """!Query map layer features
-
- Currently only raster and vector map layers are supported.
-
- @param x,y coordinates
- """
- #set query snap distance for v.what at mapunit equivalent of 10 pixels
- qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / self.Map.width)
- east, north = self.MapWindow.Pixel2Cell((x, y))
-
- num = 0
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- if type in ('raster', 'rgb', 'his',
- 'vector', 'thememap', 'themechart'):
- num += 1
-
- if num < 1:
- dlg = wx.MessageDialog(parent=self,
- message=_('No raster or vector map layer selected for querying.'),
- caption=_('No map layer selected'),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- dlg.ShowModal()
- dlg.Destroy()
- return
-
- mapname = None
- raststr = ''
- vectstr = ''
- rcmd = ['r.what', '--q']
- vcmd = ['v.what', '--q']
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- dcmd = self.tree.GetPyData(layer)[0]['cmd']
- name = utils.GetLayerNameFromCmd(dcmd)
- if name == '':
- continue
- if type in ('raster', 'rgb', 'his'):
- raststr += "%s," % name
- elif type in ('vector', 'thememap', 'themechart'):
- vectstr += "%s," % name
-
- # use display region settings instead of computation region settings
- self.tmpreg = os.getenv("GRASS_REGION")
- os.environ["GRASS_REGION"] = self.Map.SetRegion(windres=False)
-
- # build query commands for any selected rasters and vectors
- if raststr != '':
- rcmd.append('-f')
- rcmd.append('input=%s' % raststr.rstrip(','))
- rcmd.append('east_north=%f,%f' % (float(east), float(north)))
-
- if vectstr != '':
- # check for vector maps open to be edited
- digitToolbar = self.toolbars['vdigit']
- if digitToolbar:
- map = digitToolbar.GetLayer().GetName()
- vect = []
- for vector in vectstr.split(','):
- if map == vector:
- self._layerManager.goutput.WriteWarning("Vector map <%s> "
- "opened for editing - skipped." % map)
- continue
- vect.append(vector)
- vectstr = ','.join(vect)
-
- if len(vectstr) <= 1:
- self._layerManager.goutput.WriteCmdLog("Nothing to query.")
- return
-
- vcmd.append('-a')
- vcmd.append('map=%s' % vectstr.rstrip(','))
- vcmd.append('east_north=%f,%f' % (float(east), float(north)))
- vcmd.append('distance=%f' % float(qdist))
-
- # parse query command(s)
- if self._layerManager:
- if raststr:
- self._layerManager.goutput.RunCmd(rcmd,
- compReg=False,
- onDone = self._QueryMapDone)
- if vectstr:
- self._layerManager.goutput.RunCmd(vcmd,
- onDone = self._QueryMapDone)
- else:
- if raststr:
- gcmd.RunCommand(rcmd)
- if vectstr:
- gcmd.RunCommand(vcmd)
-
- def _QueryMapDone(self, returncode):
- """!Restore settings after querying (restore GRASS_REGION)
-
- @param returncode command return code
- """
- if hasattr(self, "tmpreg"):
- if self.tmpreg:
- os.environ["GRASS_REGION"] = self.tmpreg
- elif os.environ.has_key('GRASS_REGION'):
- del os.environ["GRASS_REGION"]
- elif os.environ.has_key('GRASS_REGION'):
- del os.environ["GRASS_REGION"]
-
- if hasattr(self, "tmpreg"):
- del self.tmpreg
-
- def QueryVector(self, x, y):
- """
- Query vector map layer features
-
- Attribute data of selected vector object are displayed in GUI dialog.
- Data can be modified (On Submit)
- """
- if not self.tree.layer_selected or \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] != 'vector':
- wx.MessageBox(parent=self,
- message=_("No vector map selected for querying."),
- caption=_("Vector querying"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- return
-
- if self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetMapset() != \
- grass.gisenv()['MAPSET']:
- wx.MessageBox(parent=self,
- message=_("Only vector map from the current mapset can be modified."),
- caption=_("Vector querying"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- return
-
- posWindow = self.ClientToScreen((x + self.MapWindow.dialogOffset,
- y + self.MapWindow.dialogOffset))
-
- qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) /
- self.Map.width)
-
- east, north = self.MapWindow.Pixel2Cell((x, y))
-
- mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
-
- if self.dialogs['attributes'] is None:
- self.dialogs['attributes'] = \
- dbm_dialogs.DisplayAttributesDialog(parent=self.MapWindow,
- map=mapName,
- query=((east, north), qdist),
- pos=posWindow,
- action="update")
- else:
- # selection changed?
- if not self.dialogs['attributes'].mapDBInfo or \
- self.dialogs['attributes'].mapDBInfo.map != mapName:
- self.dialogs['attributes'].UpdateDialog(map=mapName, query=((east, north), qdist))
- else:
- self.dialogs['attributes'].UpdateDialog(query=((east, north), qdist))
-
- cats = self.dialogs['attributes'].GetCats()
-
- try:
- qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)[0]
- except IndexError:
- qlayer = None
-
- if self.dialogs['attributes'].mapDBInfo and cats:
- # highlight feature & re-draw map
- if qlayer:
- qlayer.SetCmd(self.AddTmpVectorMapLayer(mapName, cats,
- useId=False,
- addLayer=False))
- else:
- qlayer = self.AddTmpVectorMapLayer(mapName, cats, useId=False)
-
- # set opacity based on queried layer
- opacity = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetOpacity(float=True)
- qlayer.SetOpacity(opacity)
-
- self.MapWindow.UpdateMap(render=False, renderVector=False)
- if not self.dialogs['attributes'].IsShown():
- self.dialogs['attributes'].Show()
- else:
- if qlayer:
- self.Map.DeleteLayer(qlayer)
- self.MapWindow.UpdateMap(render=False, renderVector=False)
- if self.dialogs['attributes'].IsShown():
- self.dialogs['attributes'].Hide()
-
- def OnQuery(self, event):
- """!Query tools menu"""
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- action = self.toolbars['map'].GetAction()
-
- point = wx.GetMousePosition()
- toolsmenu = wx.Menu()
- # Add items to the menu
- display = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
- text=_("Query raster/vector map(s) (display mode)"),
- kind=wx.ITEM_CHECK)
- toolsmenu.AppendItem(display)
- self.Bind(wx.EVT_MENU, self.OnQueryDisplay, display)
- numLayers = 0
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- if type in ('raster', 'rgb', 'his',
- 'vector', 'thememap', 'themechart'):
- numLayers += 1
- if numLayers < 1:
- display.Enable(False)
-
- if action == "displayAttrb":
- display.Check(True)
-
- modify = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
- text=_("Query vector map (edit mode)"),
- kind=wx.ITEM_CHECK)
- toolsmenu.AppendItem(modify)
- self.Bind(wx.EVT_MENU, self.OnQueryModify, modify)
- digitToolbar = self.toolbars['vdigit']
- if self.tree.layer_selected:
- layer_selected = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer']
- if layer_selected.GetType() != 'vector' or \
- (digitToolbar and \
- digitToolbar.GetLayer() == layer_selected):
- modify.Enable(False)
- else:
- if action == "modifyAttrb":
- modify.Check(True)
-
- self.PopupMenu(toolsmenu)
- toolsmenu.Destroy()
-
- def AddTmpVectorMapLayer(self, name, cats, useId=False, addLayer=True):
- """
- Add temporal vector map layer to map composition
-
- @param name name of map layer
- @param useId use feature id instead of category
- """
- # color settings from ATM
- color = UserSettings.Get(group='atm', key='highlight', subkey='color')
- colorStr = str(color[0]) + ":" + \
- str(color[1]) + ":" + \
- str(color[2])
-
- pattern = ["d.vect",
- "map=%s" % name,
- "color=%s" % colorStr,
- "fcolor=%s" % colorStr,
- "width=%d" % UserSettings.Get(group='atm', key='highlight', subkey='width')]
-
- if useId:
- cmd = pattern
- cmd.append('-i')
- cmd.append('cats=%s' % str(cats))
- else:
- cmd = []
- for layer in cats.keys():
- cmd.append(copy.copy(pattern))
- lcats = cats[layer]
- cmd[-1].append("layer=%d" % layer)
- cmd[-1].append("cats=%s" % utils.ListOfCatsToRange(lcats))
-
- # if self.icon:
- # cmd.append("icon=%s" % (self.icon))
- # if self.pointsize:
- # cmd.append("size=%s" % (self.pointsize))
-
- if addLayer:
- if useId:
- return self.Map.AddLayer(type='vector', name=globalvar.QUERYLAYER, command=cmd,
- l_active=True, l_hidden=True, l_opacity=1.0)
- else:
- return self.Map.AddLayer(type='command', name=globalvar.QUERYLAYER, command=cmd,
- l_active=True, l_hidden=True, l_opacity=1.0)
- else:
- return cmd
-
- def OnAnalyze(self, event):
- """
- Analysis tools menu
- """
- point = wx.GetMousePosition()
- toolsmenu = wx.Menu()
- # Add items to the menu
- measure = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["measure"].GetLabel())
- measure.SetBitmap(Icons["measure"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(measure)
- self.Bind(wx.EVT_MENU, self.OnMeasure, measure)
-
- profile = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["profile"].GetLabel())
- profile.SetBitmap(Icons["profile"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(profile)
- self.Bind(wx.EVT_MENU, self.Profile, profile)
-
- histogram = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["histogram"].GetLabel())
- histogram.SetBitmap(Icons["histogram"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(histogram)
- self.Bind(wx.EVT_MENU, self.Histogram, histogram)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(toolsmenu)
- toolsmenu.Destroy()
-
- def OnMeasure(self, event):
- """
- Init measurement routine that calculates
- map distance along transect drawn on
- map display
- """
-
- self.totaldist = 0.0 # total measured distance
-
- # switch GIS Manager to output console to show measure results
- self._layerManager.notebook.SetSelection(1)
-
- # change mouse to draw line for measurement
- self.MapWindow.mouse['use'] = "measure"
- self.MapWindow.mouse['box'] = "line"
- self.MapWindow.zoomtype = 0
- self.MapWindow.pen = wx.Pen(colour='red', width=2, style=wx.SHORT_DASH)
- self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["pencil"])
-
- # initiating output
- style = self._layerManager.goutput.cmd_output.StyleWarning
- self._layerManager.goutput.WriteLog(_('Click and drag with left mouse button '
- 'to measure.%s'
- 'Double click with left button to clear.') % \
- (os.linesep), style)
- if self.Map.projinfo['proj'] != 'xy':
- units = self.Map.projinfo['units']
- style = self._layerManager.goutput.cmd_output.StyleCommand
- self._layerManager.goutput.WriteLog(_('Measuring distance') + ' ('
- + units + '):',
- style)
- else:
- self._layerManager.goutput.WriteLog(_('Measuring distance:'),
- style)
-
- def MeasureDist(self, beginpt, endpt):
- """
- Calculate map distance from screen distance
- and print to output window
- """
-
- if self._layerManager.notebook.GetSelection() != 1:
- self._layerManager.notebook.SetSelection(1)
-
- dist, (north, east) = self.MapWindow.Distance(beginpt, endpt)
-
- dist = round(dist, 3)
- d, dunits = self.FormatDist(dist)
-
- self.totaldist += dist
- td, tdunits = self.FormatDist(self.totaldist)
-
- strdist = str(d)
- strtotdist = str(td)
-
- if self.Map.projinfo['proj'] == 'xy' or 'degree' not in self.Map.projinfo['unit']:
- angle = int(math.degrees(math.atan2(north,east)) + 0.5)
- angle = 180 - angle
- if angle < 0:
- angle = 360+angle
-
- mstring = 'segment = %s %s\ttotal distance = %s %s\tbearing = %d deg' \
- % (strdist,dunits,strtotdist,tdunits,angle)
- else:
- mstring = 'segment = %s %s\ttotal distance = %s %s' \
- % (strdist,dunits,strtotdist,tdunits)
-
- self.gismanager.goutput.WriteLog(mstring)
-
- return dist
-
- def Profile(self, event):
- """
- Init profile canvas and tools
- """
- raster = []
- if self.tree.layer_selected and \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
- raster.append(self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
-
- self.profile = profile.ProfileFrame(self,
- id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
- style=wx.DEFAULT_FRAME_STYLE, rasterList=raster)
- self.profile.Show()
- # Open raster select dialog to make sure that a raster (and the desired raster)
- # is selected to be profiled
- self.profile.OnSelectRaster(None)
-
- def FormatDist(self, dist):
- """!Format length numbers and units in a nice way,
- as a function of length. From code by Hamish Bowman
- Grass Development Team 2006"""
-
- mapunits = self.Map.projinfo['units']
- if mapunits == 'metres': mapunits = 'meters'
- outunits = mapunits
- dist = float(dist)
- divisor = 1.0
-
- # figure out which units to use
- if mapunits == 'meters':
- if dist > 2500.0:
- outunits = 'km'
- divisor = 1000.0
- else: outunits = 'm'
- elif mapunits == 'feet':
- # nano-bug: we match any "feet", but US Survey feet is really
- # 5279.9894 per statute mile, or 10.6' per 1000 miles. As >1000
- # miles the tick markers are rounded to the nearest 10th of a
- # mile (528'), the difference in foot flavours is ignored.
- if dist > 5280.0:
- outunits = 'miles'
- divisor = 5280.0
- else:
- outunits = 'ft'
- elif 'degree' in mapunits:
- if dist < 1:
- outunits = 'min'
- divisor = (1/60.0)
- else:
- outunits = 'deg'
-
- # format numbers in a nice way
- if (dist/divisor) >= 2500.0:
- outdist = round(dist/divisor)
- elif (dist/divisor) >= 1000.0:
- outdist = round(dist/divisor,1)
- elif (dist/divisor) > 0.0:
- outdist = round(dist/divisor,int(math.ceil(3-math.log10(dist/divisor))))
- else:
- outdist = float(dist/divisor)
-
- return (outdist, outunits)
-
-
- def Histogram(self, event):
- """
- Init histogram display canvas and tools
- """
- self.histogram = histogram.HistFrame(self,
- id=wx.ID_ANY, size=globalvar.HIST_WINDOW_SIZE,
- style=wx.DEFAULT_FRAME_STYLE)
-
- #show new display
- self.histogram.Show()
- self.histogram.Refresh()
- self.histogram.Update()
-
-
- def OnDecoration(self, event):
- """
- Decorations overlay menu
- """
- point = wx.GetMousePosition()
- decmenu = wx.Menu()
- # Add items to the menu
- AddScale = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addbarscale"].GetLabel())
- AddScale.SetBitmap(Icons["addbarscale"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddScale)
- self.Bind(wx.EVT_MENU, self.OnAddBarscale, AddScale)
-
- AddLegend = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addlegend"].GetLabel())
- AddLegend.SetBitmap(Icons["addlegend"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddLegend)
- self.Bind(wx.EVT_MENU, self.OnAddLegend, AddLegend)
-
- AddText = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addtext"].GetLabel())
- AddText.SetBitmap(Icons["addtext"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddText)
- self.Bind(wx.EVT_MENU, self.OnAddText, AddText)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(decmenu)
- decmenu.Destroy()
-
- def OnAddBarscale(self, event):
- """
- Handler for scale/arrow map decoration menu selection.
- """
- if self.dialogs['barscale']:
- return
-
- id = 0 # unique index for overlay layer
-
- # If location is latlon, only display north arrow (scale won't work)
- # proj = self.Map.projinfo['proj']
- # if proj == 'll':
- # barcmd = 'd.barscale -n'
- # else:
- # barcmd = 'd.barscale'
-
- # decoration overlay control dialog
- self.dialogs['barscale'] = \
- gdialogs.DecorationDialog(parent=self, title=_('Scale and North arrow'),
- size=(350, 200),
- style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE,
- cmd=['d.barscale', 'at=0,5'],
- ovlId=id,
- name='barscale',
- checktxt = _("Show/hide scale and North arrow"),
- ctrltxt = _("scale object"))
-
- self.dialogs['barscale'].CentreOnParent()
- ### dialog cannot be show as modal - in the result d.barscale is not selectable
- ### self.dialogs['barscale'].ShowModal()
- self.dialogs['barscale'].Show()
- self.MapWindow.mouse['use'] = 'pointer'
-
- def OnAddLegend(self, event):
- """
- Handler for legend map decoration menu selection.
- """
- if self.dialogs['legend']:
- return
-
- id = 1 # index for overlay layer in render
-
- cmd = ['d.legend', 'at=5,50,2,5']
- if self.tree.layer_selected and \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
- cmd.append('map=%s' % self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
-
- # Decoration overlay control dialog
- self.dialogs['legend'] = \
- gdialogs.DecorationDialog(parent=self, title=('Legend'),
- size=(350, 200),
- style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE,
- cmd=cmd,
- ovlId=id,
- name='legend',
- checktxt = _("Show/hide legend"),
- ctrltxt = _("legend object"))
-
- self.dialogs['legend'].CentreOnParent()
- ### dialog cannot be show as modal - in the result d.legend is not selectable
- ### self.dialogs['legend'].ShowModal()
- self.dialogs['legend'].Show()
- self.MapWindow.mouse['use'] = 'pointer'
-
- def OnAddText(self, event):
- """
- Handler for text decoration menu selection.
- """
- if self.MapWindow.dragid > -1:
- id = self.MapWindow.dragid
- else:
- # index for overlay layer in render
- if len(self.MapWindow.textdict.keys()) > 0:
- id = self.MapWindow.textdict.keys()[-1] + 1
- else:
- id = 101
-
- self.dialogs['text'] = gdialogs.TextLayerDialog(parent=self, ovlId=id,
- title=_('Add text layer'),
- size=(400, 200))
- self.dialogs['text'].CenterOnParent()
-
- # If OK button pressed in decoration control dialog
- 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)
- del self.MapWindow.textdict[id]
- except:
- pass
- return
-
- self.MapWindow.pdc.ClearId(id)
- self.MapWindow.pdc.SetId(id)
- self.MapWindow.textdict[id] = self.dialogs['text'].GetValues()
-
- self.MapWindow.Draw(self.MapWindow.pdcDec, img=self.MapWindow.textdict[id],
- drawid=id, pdctype='text', coords=coords)
-
- self.MapWindow.UpdateMap(render=False, renderVector=False)
-
- self.MapWindow.mouse['use'] = 'pointer'
-
- def GetOptData(self, dcmd, type, params, propwin):
- """
- Callback method for decoration overlay command generated by
- dialog created in menuform.py
- """
- # Reset comand and rendering options in render.Map. Always render decoration.
- # Showing/hiding handled by PseudoDC
- self.Map.ChangeOverlay(ovltype=type, type='overlay', name='', command=dcmd,
- l_active=True, l_render=False)
- self.params[type] = params
- self.propwin[type] = propwin
-
- def OnZoomMenu(self, event):
- """
- Zoom menu
- """
- point = wx.GetMousePosition()
- zoommenu = wx.Menu()
- # Add items to the menu
- zoommap = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to selected map(s)'))
- zoommenu.AppendItem(zoommap)
- self.Bind(wx.EVT_MENU, self.MapWindow.OnZoomToMap, zoommap)
-
- zoomwind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to computational region (set with g.region)'))
- zoommenu.AppendItem(zoomwind)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToWind, zoomwind)
-
- zoomdefault = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to default region'))
- zoommenu.AppendItem(zoomdefault)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToDefault, zoomdefault)
-
- zoomsaved = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to saved region'))
- zoommenu.AppendItem(zoomsaved)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToSaved, zoomsaved)
-
- savewind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Set computational region from display'))
- zoommenu.AppendItem(savewind)
- self.Bind(wx.EVT_MENU, self.MapWindow.DisplayToWind, savewind)
-
- savezoom = wx.MenuItem(zoommenu, wx.ID_ANY, _('Save display geometry to named region'))
- zoommenu.AppendItem(savezoom)
- self.Bind(wx.EVT_MENU, self.MapWindow.SaveDisplayRegion, savezoom)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(zoommenu)
- zoommenu.Destroy()
-
- def SetProperties(self, render=False, mode=0, showCompExtent=False,
- constrainRes=False, projection=False):
- """!Set properies of map display window"""
- self.statusbarWin['render'].SetValue(render)
- self.statusbarWin['toggle'].SetSelection(mode)
- self.StatusbarUpdate()
- self.statusbarWin['region'].SetValue(showCompExtent)
- self.statusbarWin['resolution'].SetValue(constrainRes)
- self.statusbarWin['projection'].SetValue(projection)
- if showCompExtent:
- self.MapWindow.regionCoords = []
-
- def IsStandalone(self):
- """!Check if Map display is standalone"""
- if self.gismanager:
- return False
-
- return True
-
- def GetLayerManager(self):
- """!Get reference to Layer Manager
-
- @return window reference
- @return None (if standalone)
- """
- return self.gismanager
-
-# end of class MapFrame
-
-class MapApp(wx.App):
- """
- MapApp class
- """
-
- def OnInit(self):
-
- wx.InitAllImageHandlers()
- if __name__ == "__main__":
- Map = render.Map() # instance of Map class to render GRASS display output to PPM file
- else:
- Map = None
-
- self.mapFrm = MapFrame(parent=None, id=wx.ID_ANY, Map=Map,
- size=globalvar.MAP_WINDOW_SIZE)
- #self.SetTopWindow(Map)
- self.mapFrm.Show()
-
- if __name__ == "__main__":
- # redraw map, if new command appears
- self.redraw = False
-
-
- return 1
-
-
-# end of class MapApp
-
-if __name__ == "__main__":
-
- ###### SET command variable
-
-
- title = "title"
- cmdfilename = "cmdfilename"
-
-
-
- gm_map = MapApp(0)
- # set title
- gm_map.mapFrm.SetTitle(_("GRASS GIS Map Display: " + title + " - Location: " + grass.gisenv()["LOCATION_NAME"]))
-
- gm_map.MainLoop()
- sys.exit(0)
Deleted: grass-addons/gui/wxpython/data_catalog/mapframe.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/mapframe.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/mapframe.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,4248 +0,0 @@
-"""
- at package mapdisp.py
-
- at brief GIS map display canvas, with toolbar for various display
-management functions, and second toolbar for vector
-digitizing.
-
-Can be used either from GIS Manager or as p.mon backend.
-
-Classes:
- - Command
- - MapWindow
- - BufferedWindow
- - MapFrame
- - MapApp
-
-Usage:
- python mapdisp.py monitor-identifier /path/to/command/file
-
-(C) 2006-2008 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 Michael Barton
- at author Jachym Cepicky
- at author Martin Landa <landa.martin gmail.com>
-"""
-
-import os
-import sys
-import time
-import glob
-import math
-import tempfile
-import copy
-
-import globalvar
-if not os.getenv("GRASS_WXBUNDLED"):
- globalvar.CheckForWx()
-import wx
-import wx.aui
-
-from threading import Thread
-try:
- import subprocess
-except:
- CompatPath = os.path.join(globalvar.ETCWXDIR)
- sys.path.append(CompatPath)
- from compat import subprocess
-
-gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
-sys.path.append(gmpath)
-
-import render
-import toolbars
-
-
-version = os.getenv("GRASS_VERSION")
-if version == "6.4.0svn":
- import track
-
-import menuform
-import gselect
-import disp_print
-import gcmd
-import dbm
-import histogram
-import profile
-import globalvar
-import utils
-import gdialogs
-from grass.script import core as grass
-from vdigit import VDigitCategoryDialog as VDigitCategoryDialog
-from vdigit import VDigitZBulkDialog as VDigitZBulkDialog
-from vdigit import VDigitDuplicatesDialog as VDigitDuplicatesDialog
-from vdigit import GV_LINES as VDigit_Lines_Type
-from debug import Debug as Debug
-from icon import Icons as Icons
-from preferences import globalSettings as UserSettings
-
-import images
-imagepath = images.__path__[0]
-sys.path.append(imagepath)
-
-###
-### global variables
-###
-# for standalone app
-cmdfilename = None
-
-class Command(Thread):
- """
- Creates thread which will observe the command file and see, if
- there is new command to be executed
- """
- def __init__ (self, parent, Map):
- Thread.__init__(self)
-
- global cmdfilename
-
- self.parent = parent
- self.map = Map
- self.cmdfile = open(cmdfilename, "r")
-
- def run(self):
- """
- Run this in thread
- """
- dispcmd = []
- while 1:
- self.parent.redraw = False
- line = self.cmdfile.readline().strip()
- if line == "quit":
- break
-
- if line:
- try:
- Debug.msg (3, "Command.run(): cmd=%s" % (line))
-
- self.map.AddLayer(item=None, type="raster",
- name='',
- command=line,
- l_opacity=1)
-
- self.parent.redraw =True
-
- except Exception, e:
- print "Command Thread: ",e
-
- time.sleep(0.1)
-
- sys.exit()
-
-class MapWindow(object):
- """
- Abstract map window class
-
- Parent for BufferedWindow class (2D display mode) and
- GLWindow (3D display mode)
- """
- def __init__(self, parent, id=wx.ID_ANY,
- pos=wx.DefaultPosition,
- size=wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, gismgr=None):
- self.parent = parent # MapFrame
-
- #
- # mouse attributes like currently pressed buttons, position on
- # the screen, begin and end of dragging, and type of drawing
- #
- self.mouse = {
- 'l' : False,
- 'r' : False,
- 'm' : False,
- 'begin': [0, 0], # screen coordinates
- 'end' : [0, 0],
- 'use' : "pointer",
- 'box' : "point"
- }
-
- def EraseMap(self):
- """
- Erase the canvas (virtual method)
- """
- pass
-
- def UpdateMap(self):
- """
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
- """
- pass
-
- def OnLeftDown(self, event):
- pass
-
- def OnLeftUp(self, event):
- pass
-
- def OnMouseMotion(self, event):
- pass
-
- def OnZoomToMap(self, event):
- pass
-
- def OnZoomToRaster(self, event):
- pass
-
- def GetSelectedLayer(self, type = 'layer', multi = False):
- """
- Get selected layer from layer tree
-
- @param type 'item' / 'layer' / 'nviz'
- @param multi return first selected layer or all
-
- @return layer / map layer properties / nviz properties
- @return None / [] on failure
- """
- ret = []
- if not self.tree or \
- not self.tree.GetSelection():
- if multi:
- return []
- else:
- return None
-
- if multi and \
- type == 'item':
- return self.tree.GetSelections()
-
- for item in self.tree.GetSelections():
- if not item.IsChecked():
- if multi:
- continue
- else:
- return None
-
- if type == 'item': # -> multi = False
- return item
-
- try:
- if type == 'nviz':
- layer = self.tree.GetPyData(item)[0]['nviz']
- else:
- layer = self.tree.GetPyData(item)[0]['maplayer']
- except:
- layer = None
-
- if multi:
- ret.append(layer)
- else:
- return layer
-
- return ret
-
-class BufferedWindow(MapWindow, wx.Window):
- """
- A Buffered window class.
-
- When the drawing needs to change, you app needs to call the
- UpdateMap() method. Since the drawing is stored in a bitmap, you
- can also save the drawing to file by calling the
- SaveToFile(self,file_name,file_type) method.
- """
-
- def __init__(self, parent, id,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, gismgr=None):
-
- MapWindow.__init__(self, parent, id, pos, size, style,
- Map, tree, gismgr)
- wx.Window.__init__(self, parent, id, pos, size, style)
-
- self.Map = Map
- self.tree = tree
- self.gismanager = gismgr
-
- book= self.GetParent()
- q=book.GetParent()
- r=q.GetParent()
- splitter=r.GetParent()
- self.gframe=splitter.GetParent()
-
- #
- # Flags
- #
- self.resize = False # indicates whether or not a resize event has taken place
- self.dragimg = None # initialize variable for map panning
- self.flag = False
-
- #
- # Variable for drawing on DC
- #
- self.pen = None # pen for drawing zoom boxes, etc.
- self.polypen = None # pen for drawing polylines (measurements, profiles, etc)
- # List of wx.Point tuples defining a polyline (geographical coordinates)
- self.polycoords = []
- # ID of rubber band line
- self.lineid = None
- # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
- self.plineid = None
-
- #
- # Event bindings
- #
- self.Bind(wx.EVT_PAINT, self.OnPaint)
- self.Bind(wx.EVT_SIZE, self.OnSize)
- self.Bind(wx.EVT_IDLE, self.OnIdle)
- self.Bind(wx.EVT_MOTION, self.MouseActions)
- self.Bind(wx.EVT_MOUSE_EVENTS, self.MouseActions)
- self.processMouse = True
-
- #
- # Render output objects
- #
- self.mapfile = None # image file to be rendered
- self.img = "" # wx.Image object (self.mapfile)
- # used in digitization tool (do not redraw vector map)
- self.imgVectorMap = None
- # decoration overlays
- self.overlays = {}
- # images and their PseudoDC ID's for painting and dragging
- self.imagedict = {}
- self.select = {} # selecting/unselecting decorations for dragging
- self.textdict = {} # text, font, and color indexed by id
- self.currtxtid = None # PseudoDC id for currently selected text
-
- #
- # Zoom objects
- #
- self.zoomhistory = [] # list of past zoom extents
- self.currzoom = 0 # current set of extents in zoom history being used
-
- self.zoomtype = 1 # 1 zoom in, 0 no zoom, -1 zoom out
- self.hitradius = 10 # distance for selecting map decorations
- self.dialogOffset = 5 # offset for dialog (e.g. DisplayAttributesDialog)
-
- # OnSize called to make sure the buffer is initialized.
- # This might result in OnSize getting called twice on some
- # platforms at initialization, but little harm done.
- ### self.OnSize(None)
-
- # create PseudoDC used for background map, map decorations like scales and legends
- self.pdc = wx.PseudoDC()
- # used for digitization tool
- self.pdcVector = None
- # decorations (region box, etc.)
- self.pdcDec = wx.PseudoDC()
- # pseudoDC for temporal objects (select box, measurement tool, etc.)
- self.pdcTmp = wx.PseudoDC()
- # redraw all pdc's, pdcTmp layer is redrawn always (speed issue)
- self.redrawAll = True
-
- # will store an off screen empty bitmap for saving to file
- self._buffer = ''
-
- self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None)
-
- # vars for handling mouse clicks
- self.dragid = -1
- self.lastpos = (0, 0)
-
- def Draw(self, pdc, img=None, drawid=None, pdctype='image', coords=[0, 0, 0, 0]):
- """
- Draws map and overlay decorations
- """
-
- if drawid == None:
- if pdctype == 'image' and img:
- drawid = self.imagedict[img]
- elif pdctype == 'clear':
- drawid == None
- else:
- drawid = wx.NewId()
-
- if img and pdctype == 'image':
- # self.imagedict[img]['coords'] = coords
- self.select[self.imagedict[img]['id']] = False # ?
-
- pdc.BeginDrawing()
-
- if drawid != 99:
- bg = wx.TRANSPARENT_BRUSH
- else:
- bg = wx.Brush(self.GetBackgroundColour())
-
- pdc.SetBackground(bg)
- ### pdc.Clear()
-
- Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \
- (drawid, pdctype, coords))
-
- # set PseudoDC id
- if drawid is not None:
- pdc.SetId(drawid)
-
- if pdctype == 'clear': # erase the display
- bg = wx.WHITE_BRUSH
- # bg = wx.Brush(self.GetBackgroundColour())
- pdc.SetBackground(bg)
- pdc.RemoveAll()
- pdc.Clear()
- pdc.EndDrawing()
-
- self.Refresh()
- return
-
- if pdctype == 'image': # draw selected image
- bitmap = wx.BitmapFromImage(img)
- w,h = bitmap.GetSize()
- pdc.DrawBitmap(bitmap, coords[0], coords[1], True) # draw the composite map
- pdc.SetIdBounds(drawid, (coords[0],coords[1], w, h))
-
- elif pdctype == 'box': # draw a box on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- x2 = max(coords[0],coords[2])
- x1 = min(coords[0],coords[2])
- y2 = max(coords[1],coords[3])
- y1 = min(coords[1],coords[3])
- rwidth = x2-x1
- rheight = y2-y1
- rect = wx.Rect(x1,y1,rwidth,rheight)
- pdc.DrawRectangleRect(rect)
- pdc.SetIdBounds(drawid,rect)
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'line': # draw a line on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- pdc.DrawLine(coords[0], coords[1], coords[2], coords[3])
- pdc.SetIdBounds(drawid,(coords[0], coords[1], coords[2], coords[3]))
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'polyline': # draw a polyline on top of the map
- if self.polypen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.polypen)
- pdc.DrawLines(coords)
-
- # get bounding rectangle for polyline
- xlist = []
- ylist = []
- if len(coords) > 0:
- for point in coords:
- x,y = point
- xlist.append(x)
- ylist.append(y)
- x1=min(xlist)
- x2=max(xlist)
- y1=min(ylist)
- y2=max(ylist)
- pdc.SetIdBounds(drawid,(x1,y1,x2,y2))
- # self.ovlcoords[drawid] = [x1,y1,x2,y2]
-
- elif pdctype == 'point': # draw point
- if self.pen:
- pdc.SetPen(self.pen)
- pdc.DrawPoint(coords[0], coords[1])
- coordsBound = (coords[0] - 5,
- coords[1] - 5,
- coords[0] + 5,
- coords[1] + 5)
- pdc.SetIdBounds(drawid, coordsBound)
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'text': # draw text on top of map
- if not img['active']:
- return #only draw active text
- if img.has_key('rotation'):
- rotation = float(img['rotation'])
- else:
- rotation = 0.0
- w, h = self.GetFullTextExtent(img['text'])[0:2]
- pdc.SetFont(img['font'])
- pdc.SetTextForeground(img['color'])
- coords, w, h = 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, (coords[0], coords[1], w, h))
-
- pdc.EndDrawing()
-
- self.Refresh()
-
- return drawid
-
- def TextBounds(self, textinfo):
- """
- Return text boundary data
-
- @param textinfo text metadata (text, font, color, rotation)
- @param coords reference point
- """
- if textinfo.has_key('rotation'):
- rotation = float(textinfo['rotation'])
- else:
- rotation = 0.0
-
- coords = textinfo['coords']
-
- Debug.msg (4, "BufferedWindow.TextBounds(): text=%s, rotation=%f" % \
- (textinfo['text'], rotation))
-
- self.Update()
- ### self.Refresh()
-
- self.SetFont(textinfo['font'])
-
- w, h = self.GetTextExtent(textinfo['text'])
-
- if rotation == 0:
- coords[2], coords[3] = coords[0] + w, coords[1] + h
- return coords, w, h
-
- 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
-
- def OnPaint(self, event):
- """
- Draw PseudoDC's to buffered paint DC
-
- self.pdc for background and decorations
- self.pdcVector for vector map which is edited
- self.pdcTmp for temporaly drawn objects (self.polycoords)
-
- If self.redrawAll is False on self.pdcTmp content is re-drawn
- """
- Debug.msg(4, "BufferedWindow.OnPaint(): redrawAll=%s" % self.redrawAll)
-
- dc = wx.BufferedPaintDC(self, self.buffer)
-
- ### dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- # use PrepareDC to set position correctly
- self.PrepareDC(dc)
-
- # create a clipping rect from our position and size
- # and update region
- rgn = self.GetUpdateRegion().GetBox()
- dc.SetClippingRect(rgn)
-
- switchDraw = False
- if self.redrawAll is None:
- self.redrawAll = True
- switchDraw = True
-
- if self.redrawAll: # redraw pdc and pdcVector
- # draw to the dc using the calculated clipping rect
- self.pdc.DrawToDCClipped(dc, rgn)
-
- # draw vector map layer
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDCClipped(gcdc, rgn)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDCClipped(dc, rgn)
-
- self.bufferLast = None
- else: # do not redraw pdc and pdcVector
- if self.bufferLast is None:
- # draw to the dc
- self.pdc.DrawToDC(dc)
-
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDC(dc)
-
- # store buffered image
- # self.bufferLast = wx.BitmapFromImage(self.buffer.ConvertToImage())
- self.bufferLast = dc.GetAsBitmap(wx.Rect(0, 0, self.Map.width, self.Map.height))
-
- pdcLast = wx.PseudoDC()
- pdcLast.DrawBitmap(bmp=self.bufferLast, x=0, y=0)
- pdcLast.DrawToDC(dc)
-
- # draw decorations (e.g. region box)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcDec.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcDec.DrawToDC(dc)
-
- # draw temporary object on the foreground
- ### self.pdcTmp.DrawToDCClipped(dc, rgn)
- self.pdcTmp.DrawToDC(dc)
-
- if switchDraw:
- self.redrawAll = False
-
- def OnSize(self, event):
- """
- Scale map image so that it is
- the same size as the Window
- """
- Debug.msg(3, "BufferedWindow.OnSize():")
-
- # set size of the input image
- self.Map.ChangeMapSize(self.GetClientSize())
- # align extent based on center point and display resolution
- # this causes that image is not resized when display windows is resized
- # self.Map.AlignExtentFromDisplay()
-
- # Make new off screen bitmap: this bitmap will always have the
- # current drawing in it, so it can be used to save the image to
- # a file, or whatever.
- self.buffer = wx.EmptyBitmap(max(1, self.Map.width), max(1, self.Map.height))
-
- # get the image to be rendered
- self.img = self.GetImage()
-
- # update map display
- if self.img and self.Map.width + self.Map.height > 0: # scale image during resize
- self.img = self.img.Scale(self.Map.width, self.Map.height)
- if len(self.Map.GetListOfLayers()) > 0:
- self.UpdateMap()
-
- # re-render image on idle
- self.resize = True
-
- # reposition checkbox in statusbar
- self.parent.StatusbarReposition()
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- def OnIdle(self, event):
- """
- Only re-render a composite map image from GRASS during
- idle time instead of multiple times during resizing.
- """
- if self.resize:
- self.UpdateMap(render=True)
-
- event.Skip()
-
- def SaveToFile(self, FileName, FileType):
- """
- This draws the psuedo DC to a buffer that
- can be saved to a file.
- """
- dc = wx.BufferedPaintDC(self, self.buffer)
- self.pdc.DrawToDC(dc)
- if self.pdcVector:
- self.pdcVector.DrawToDC(dc)
- self.buffer.SaveFile(FileName, FileType)
-
- def GetOverlay(self):
- """
- Converts rendered overlay files to wx.Image
-
- Updates self.imagedict
-
- @return list of images
- """
- imgs = []
- for overlay in self.Map.GetListOfLayers(l_type="overlay", l_active=True):
- if os.path.isfile(overlay.mapfile) and os.path.getsize(overlay.mapfile):
- img = wx.Image(overlay.mapfile, wx.BITMAP_TYPE_ANY)
- self.imagedict[img] = { 'id' : overlay.id,
- 'layer' : overlay }
- imgs.append(img)
-
- return imgs
-
- def GetImage(self):
- """
- Converts redered map files to wx.Image
-
- Updates self.imagedict (id=99)
-
- @return wx.Image instance (map composition)
- """
- imgId = 99
- if self.Map.mapfile and os.path.isfile(self.Map.mapfile) and \
- os.path.getsize(self.Map.mapfile):
- img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
- else:
- img = None
-
- self.imagedict[img] = { 'id': imgId }
-
- return img
-
- def UpdateMap(self, render=True, renderVector=True):
- """
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
-
- @param render re-render map composition
- @param renderVector re-render vector map layer enabled for editing (used for digitizer)
- """
- if self.flag == True:
- start = time.clock()
-
-
- self.resize = False
-
- if len(self.Map.GetListOfLayers()) == 0:
- return False
-
- if self.img is None:
- render = True
-
- #
- # initialize process bar (only on 'render')
- #
- if render is True or renderVector is True:
- self.parent.onRenderGauge.Show()
- if self.parent.onRenderGauge.GetRange() > 0:
- self.parent.onRenderGauge.SetValue(1)
-
- #
- # render background image if needed
- #
-
- # update layer dictionary if there has been a change in layers
- if self.tree and self.tree.reorder == True:
- self.tree.ReorderLayers()
-
- # reset flag for auto-rendering
- if self.tree:
- self.tree.rerender = False
-
- if render:
- # update display size
- self.Map.ChangeMapSize(self.GetClientSize())
- if self.parent.compResolution.IsChecked():
- # use computation region resolution for rendering
- windres = True
- else:
- windres = False
- self.mapfile = self.Map.Render(force=True, mapWindow=self.parent,
- windres=windres)
- else:
- self.mapfile = self.Map.Render(force=False, mapWindow=self.parent)
-
- self.img = self.GetImage() # id=99
-
- #
- # clear pseudoDcs
- #
- for pdc in (self.pdc,
- self.pdcDec,
- self.pdcTmp):
- pdc.Clear()
- pdc.RemoveAll()
-
- #
- # draw background map image to PseudoDC
- #
- if not self.img:
- self.Draw(self.pdc, pdctype='clear')
- else:
- try:
- id = self.imagedict[self.img]['id']
- except:
- return False
-
- self.Draw(self.pdc, self.img, drawid=id)
-
- #
- # render vector map layer
- #
- digitToolbar = self.parent.toolbars['vdigit']
- if renderVector and digitToolbar and \
- digitToolbar.GetLayer():
- # set region
- self.parent.digit.driver.UpdateRegion()
- # re-calculate threshold for digitization tool
- self.parent.digit.driver.GetThreshold()
- # draw map
- self.pdcVector.Clear()
- self.pdcVector.RemoveAll()
- try:
- item = self.tree.FindItemByData('maplayer', digitToolbar.GetLayer())
- except TypeError:
- item = None
-
- if item and self.tree.IsItemChecked(item):
- self.parent.digit.driver.DrawMap()
-
- # translate tmp objects (pointer position)
- if digitToolbar.GetAction() == 'moveLine':
- if hasattr(self, "vdigitMove") and \
- self.vdigitMove.has_key('beginDiff'):
- # move line
- for id in self.vdigitMove['id']:
- # print self.pdcTmp.GetIdBounds(id)
- self.pdcTmp.TranslateId(id,
- self.vdigitMove['beginDiff'][0],
- self.vdigitMove['beginDiff'][1])
- del self.vdigitMove['beginDiff']
-
- #
- # render overlays
- #
- for img in self.GetOverlay():
- # draw any active and defined overlays
- if self.imagedict[img]['layer'].IsActive():
- id = self.imagedict[img]['id']
- self.Draw(self.pdc, img=img, drawid=id,
- pdctype=self.overlays[id]['pdcType'], coords=self.overlays[id]['coords'])
-
- for id in self.textdict.keys():
- self.Draw(self.pdc, img=self.textdict[id], drawid=id,
- pdctype='text', coords=[10, 10, 10, 10])
-
- # optionally draw computational extent box
- self.DrawCompRegionExtent()
-
- #
- # redraw pdcTmp if needed
- #
- if len(self.polycoords) > 0:
- self.DrawLines(self.pdcTmp)
-
-
- if self.gframe.georectifying:
- # -> georectifier (redraw GCPs)
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
- self.gframe.georectifying.DrawGCP(coordtype)
-
- #
- # clear measurement
- #
-
- if self.mouse["use"] == "measure":
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.SetCursor(self.parent.cursors["default"])
-
- stop = time.clock()
-
- #
- # hide process bar
- #
- self.parent.onRenderGauge.Hide()
-
- #
- # update statusbar
- #
- ### self.Map.SetRegion()
- self.parent.StatusbarUpdate()
- if grass.find_file(name = 'MASK', element = 'cell')['name']:
- # mask found
- self.parent.maskInfo.SetLabel(_('MASK'))
- else:
- self.parent.maskInfo.SetLabel('')
-
- Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%g" % \
- (render, renderVector, (stop-start)))
-
- return True
-
- def DrawCompRegionExtent(self):
- """
- Draw computational region extent in the display
-
- Display region is drawn as a blue box inside the computational region,
- computational region inside a display region as a red box).
- """
- if hasattr(self, "regionCoords"):
- compReg = self.Map.GetRegion()
- dispReg = self.Map.GetCurrentRegion()
- reg = None
- if self.IsInRegion(dispReg, compReg):
- self.polypen = wx.Pen(colour=wx.Colour(0, 0, 255, 128), width=3, style=wx.SOLID)
- reg = dispReg
- else:
- self.polypen = wx.Pen(colour=wx.Colour(255, 0, 0, 128),
- width=3, style=wx.SOLID)
- reg = compReg
-
- self.regionCoords = []
- self.regionCoords.append((reg['w'], reg['n']))
- self.regionCoords.append((reg['e'], reg['n']))
- self.regionCoords.append((reg['e'], reg['s']))
- self.regionCoords.append((reg['w'], reg['s']))
- self.regionCoords.append((reg['w'], reg['n']))
- # draw region extent
- self.DrawLines(pdc=self.pdcDec, polycoords=self.regionCoords)
-
- def IsInRegion(self, region, refRegion):
- """
- Test if 'region' is inside of 'refRegion'
-
- @param region input region
- @param refRegion reference region (e.g. computational region)
-
- @return True if region is inside of refRegion
- @return False
- """
- if region['s'] >= refRegion['s'] and \
- region['n'] <= refRegion['n'] and \
- region['w'] >= refRegion['w'] and \
- region['e'] <= refRegion['e']:
- return True
-
- return False
-
- def EraseMap(self):
- """
- Erase the canvas
- """
- self.Draw(self.pdc, pdctype='clear')
-
- if self.pdcVector:
- self.Draw(self.pdcVector, pdctype='clear')
-
- self.Draw(self.pdcDec, pdctype='clear')
- self.Draw(self.pdcTmp, pdctype='clear')
-
- def DragMap(self, moveto):
- """
- Drag the entire map image for panning.
- """
-
- dc = wx.BufferedDC(wx.ClientDC(self))
- dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- self.dragimg = wx.DragImage(self.buffer)
- self.dragimg.BeginDrag((0, 0), self)
- self.dragimg.GetImageRect(moveto)
- self.dragimg.Move(moveto)
-
- self.dragimg.DoDrawImage(dc, moveto)
- self.dragimg.EndDrag()
-
- return True
-
- def DragItem(self, id, event):
- """
- Drag an overlay decoration item
- """
- if id == 99 or id == '' or id == None: return
- Debug.msg (5, "BufferedWindow.DragItem(): id=%d" % id)
- x, y = self.lastpos
- dx = event.GetX() - x
- dy = event.GetY() - y
- self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- r = self.pdc.GetIdBounds(id)
- if id > 100: # text dragging
- rtop = (r[0],r[1]-r[3],r[2],r[3])
- r = r.Union(rtop)
- rleft = (r[0]-r[2],r[1],r[2],r[3])
- r = r.Union(rleft)
- self.pdc.TranslateId(id, dx, dy)
-
- r2 = self.pdc.GetIdBounds(id)
- if id > 100: # text
- self.textdict[id]['coords'] = r2
- r = r.Union(r2)
- r.Inflate(4,4)
- self.RefreshRect(r, False)
- self.lastpos = (event.GetX(), event.GetY())
-
- def MouseDraw(self, pdc=None, begin=None, end=None):
- """
- Mouse box or line from 'begin' to 'end'
-
- If not given from self.mouse['begin'] to self.mouse['end'].
-
- """
- self.redrawAll = False
-
- if not pdc:
- return
-
- if begin is None:
- begin = self.mouse['begin']
- if end is None:
- end = self.mouse['end']
-
- Debug.msg (5, "BufferedWindow.MouseDraw(): use=%s, box=%s, begin=%f,%f, end=%f,%f" % \
- (self.mouse['use'], self.mouse['box'],
- begin[0], begin[1], end[0], end[1]))
-
- if self.mouse['box'] == "box":
- boxid = wx.ID_NEW
- mousecoords = [begin[0], begin[1],
- end[0], end[1]]
- r = pdc.GetIdBounds(boxid)
- r.Inflate(4,4)
- pdc.ClearId(boxid)
- self.RefreshRect(r, False)
- pdc.SetId(boxid)
- self.Draw(pdc, drawid=boxid, pdctype='box', coords=mousecoords)
- elif self.mouse['box'] == "line" or self.mouse['box'] == 'point':
- self.lineid = wx.ID_NEW
- mousecoords = [begin[0], begin[1], \
- end[0], end[1]]
- x1=min(begin[0],end[0])
- x2=max(begin[0],end[0])
- y1=min(begin[1],end[1])
- y2=max(begin[1],end[1])
- r = wx.Rect(x1,y1,x2-x1,y2-y1)
- r.Inflate(4,4)
- try:
- pdc.ClearId(self.lineid)
- except:
- pass
- self.RefreshRect(r, False)
- pdc.SetId(self.lineid)
-
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=mousecoords)
-
- def DrawLines(self, pdc=None, polycoords=None):
- """
- Draw polyline in PseudoDC
-
- Set self.pline to wx.NEW_ID + 1
-
- polycoords - list of polyline vertices, geographical coordinates
- (if not given, self.polycoords is used)
-
- """
- if not pdc:
- pdc = self.pdcTmp
-
- if not polycoords:
- polycoords = self.polycoords
-
- if len(polycoords) > 0:
- self.plineid = wx.ID_NEW + 1
- # convert from EN to XY
- coords = []
- for p in polycoords:
- coords.append(self.Cell2Pixel(p))
-
- self.Draw(pdc, drawid=self.plineid, pdctype='polyline', coords=coords)
-
- Debug.msg (4, "BufferedWindow.DrawLines(): coords=%s, id=%s" % \
- (coords, self.plineid))
-
- return self.plineid
-
- return -1
-
- def DrawCross(self, pdc, coords, size, rotation=0,
- text=None, textAlign='lr', textOffset=(5, 5)):
- """Draw cross in PseudoDC
-
- @todo implement rotation
-
- @param pdc PseudoDC
- @param coord center coordinates
- @param rotation rotate symbol
- @param text draw also text (text, font, color, rotation)
- @param textAlign alignment (default 'lower-right')
- @textOffset offset for text (from center point)
- """
- Debug.msg(4, "BufferedWindow.DrawCross(): pdc=%s, coords=%s, size=%d" % \
- (pdc, coords, size))
- coordsCross = ((coords[0] - size, coords[1], coords[0] + size, coords[1]),
- (coords[0], coords[1] - size, coords[0], coords[1] + size))
-
- self.lineid = wx.NewId()
- for lineCoords in coordsCross:
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=lineCoords)
-
- if not text:
- return self.lineid
-
- if textAlign == 'ul':
- coord = [coords[0] - textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'ur':
- coord = [coords[0] + textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'lr':
- coord = [coords[0] + textOffset[0], coords[1] + textOffset[1], 0, 0]
- else:
- coord = [coords[0] - textOffset[0], coords[1] + textOffset[1], 0, 0]
-
- self.Draw(pdc, img=text,
- pdctype='text', coords=coord)
-
- return self.lineid
-
- def MouseActions(self, event):
- """
- Mouse motion and button click notifier
- """
- if not self.processMouse:
- return
-
- ### if self.redrawAll is False:
- ### self.redrawAll = True
-
- # zoom with mouse wheel
- if event.GetWheelRotation() != 0:
- self.OnMouseWheel(event)
-
- # left mouse button pressed
- elif event.LeftDown():
- self.OnLeftDown(event)
-
- # left mouse button released
- elif event.LeftUp():
- self.OnLeftUp(event)
-
- # dragging
- elif event.Dragging():
- self.OnDragging(event)
-
- # double click
- elif event.ButtonDClick():
- self.OnButtonDClick(event)
-
- # middle mouse button pressed
- elif event.MiddleDown():
- self.OnMiddleDown(event)
-
- # right mouse button pressed
- elif event.RightDown():
- self.OnRightDown(event)
-
- # right mouse button released
- elif event.RightUp():
- self.OnRightUp(event)
-
- elif event.Moving():
- self.OnMouseMoving(event)
-
-# event.Skip()
-
- def OnMouseWheel(self, event):
- """
- Mouse wheel moved
- """
- self.processMouse = False
- current = event.GetPositionTuple()[:]
- wheel = event.GetWheelRotation()
- Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
- # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
- begin = (current[0] - self.Map.width / 4,
- current[1] - self.Map.height / 4)
- end = (current[0] + self.Map.width / 4,
- current[1] + self.Map.height / 4)
-
- if wheel > 0:
- zoomtype = 1
- else:
- zoomtype = -1
-
- # zoom
- self.Zoom(begin, end, zoomtype)
-
- # redraw map
- self.UpdateMap()
-
- ### self.OnPaint(None)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- self.Refresh()
- self.processMouse = True
-# event.Skip()
-
- def OnDragging(self, event):
- """
- Mouse dragging with left button down
- """
- Debug.msg (5, "BufferedWindow.MouseAction(): Dragging")
- current = event.GetPositionTuple()[:]
- previous = self.mouse['begin']
- move = (current[0] - previous[0],
- current[1] - previous[1])
-
- digitToolbar = self.parent.toolbars['vdigit']
-
- # dragging or drawing box with left button
- if self.mouse['use'] == 'pan':
- self.DragMap(move)
-
- # dragging decoration overlay item
- elif (self.mouse['use'] == 'pointer' and
- not digitToolbar and
- self.dragid != None):
- self.DragItem(self.dragid, event)
-
- # dragging anything else - rubber band box or line
- else:
- if (self.mouse['use'] == 'pointer' and
- not digitToolbar): return
- self.mouse['end'] = event.GetPositionTuple()[:]
- digitClass = self.parent.digit
- if (event.LeftIsDown() and
- not (digitToolbar and
- digitToolbar.GetAction() in ("moveLine",) and
- digitClass.driver.GetSelected() > 0)):
- # draw box only when left mouse button is pressed
- self.MouseDraw(pdc=self.pdcTmp)
-
-# event.Skip()
-
- def OnLeftDown(self, event):
- """
- Left mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnLeftDown(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['begin'] = event.GetPositionTuple()[:]
-
- if self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if len(self.polycoords) == 0:
- self.mouse['end'] = self.mouse['begin']
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.ClearLines(pdc=self.pdcTmp)
- else:
- self.mouse['begin'] = self.mouse['end']
- elif self.mouse['use'] == 'zoom':
- pass
- elif self.mouse["use"] == "pointer" and self.parent.toolbars['vdigit']:
- # digitization
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
- east, north = self.Pixel2Cell(self.mouse['begin'])
-
- try:
- map = digitToolbar.GetLayer().GetName()
- except:
- map = None
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- event.Skip()
- return
-
- # calculate position of 'update record' dialog
- position = self.mouse['begin']
- posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
- position[1] + self.dialogOffset))
-
- if digitToolbar.GetAction() not in ("moveVertex", "addVertex",
- "removeVertex", "editLine"):
- # set pen
- self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
- self.polypen = wx.Pen(colour='dark green', width=2, style=wx.SOLID)
-
- if digitToolbar.GetAction() in ("addVertex", "removeVertex"):
- # unselect
- digitClass.driver.SetSelected([])
-
- if digitToolbar.GetAction() == "addLine":
- if digitToolbar.GetAction('type') in ["point", "centroid"]:
- # add new point
- if digitToolbar.GetAction('type') == 'point':
- point = True
- else:
- point = False
-
- fid = digitClass.AddPoint(map, point, east, north)
- if fid < 0:
- return
-
- self.UpdateMap(render=False) # redraw map
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
- addRecordDlg = dbm.DisplayAttributesDialog(parent=self, map=map,
- cats=cats,
- pos=posWindow,
- action="add")
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
- executeCommand = gcmd.Command(cmd=["db.execute",
- "--q",
- "input=%s" % sqlfile.name])
-
- elif digitToolbar.GetAction('type') in ["line", "boundary"]:
- # add new point to the line
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- self.DrawLines(pdc=self.pdcTmp)
-
- elif digitToolbar.GetAction() == "editLine" and hasattr(self, "vdigitMove"):
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.vdigitMove['id'].append(wx.NewId())
- self.DrawLines(pdc=self.pdcTmp)
-
- elif digitToolbar.GetAction() == "deleteLine":
- pass
-
- elif digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] and \
- not hasattr(self, "vdigitMove"):
- self.vdigitMove = {}
- # geographic coordinates of initial position (left-down)
- self.vdigitMove['begin'] = None
- # list of ids to modify
- self.vdigitMove['id'] = []
- # ids geographic coordinates
- self.vdigitMove['coord'] = {}
-
- if digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # set pen
- pcolor = UserSettings.Get(group='vdigit', key="symbol",
- subkey=["highlight", "color"])
- self.pen = self.polypen = wx.Pen(colour=pcolor,
- width=2, style=wx.SHORT_DASH)
- self.pdcTmp.SetPen(self.polypen)
-
- elif digitToolbar.GetAction() == "splitLine":
- # unselect
- digitClass.driver.SetSelected([])
-
- elif digitToolbar.GetAction() in ["displayAttrs", "displayCats"]:
- qdist = digitClass.driver.GetThreshold(type='selectThresh')
- coords = (east, north)
- if digitClass.type == 'vdigit':
- # unselect
- digitClass.driver.SetSelected([])
-
- # select feature by point
- cats = {}
- if digitClass.driver.SelectLineByPoint(coords,
- digitClass.GetSelectType()) is not None:
- if UserSettings.Get(group='vdigit', key='checkForDupl',
- subkey='enabled'):
- lines = digitClass.driver.GetSelected()
- else:
- lines = (digitClass.driver.GetSelected()[0],) # only first found
-
- for line in lines:
- cats[line] = digitClass.GetLineCats(line)
-
- if digitToolbar.GetAction() == "displayAttrs":
- # select attributes based on coordinates (all layers)
- if self.parent.dialogs['attributes'] is None:
- if digitClass.type == 'vedit':
- self.parent.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self, map=map,
- query=(coords, qdist),
- pos=posWindow,
- action="update")
- else:
- self.parent.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self, map=map,
- cats=cats,
- action="update")
- else:
- # update currently open dialog
- if digitClass.type == 'vedit':
- self.parent.dialogs['attributes'].UpdateDialog(query=(coords, qdist))
- else:
- # upgrade dialog
- self.parent.dialogs['attributes'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['attributes']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- if not self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Show()
- else:
- if self.parent.dialogs['attributes'] and \
- self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Hide()
-
- else: # displayCats
- if self.parent.dialogs['category'] is None:
- # open new dialog
- if digitClass.type == 'vedit':
- dlg = VDigitCategoryDialog(parent=self,
- map=map,
- query=(coords, qdist),
- pos=posWindow,
- title=_("Update categories"))
- self.parent.dialogs['category'] = dlg
- else:
- dlg = VDigitCategoryDialog(parent=self,
- map=map,
- cats=cats,
- pos=posWindow,
- title=_("Update categories"))
- self.parent.dialogs['category'] = dlg
- else:
- # update currently open dialog
- if digitClass.type == 'vedit':
- self.parent.dialogs['category'].UpdateDialog(query=(coords, qdist))
- else:
- # upgrade dialog
- self.parent.dialogs['category'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['category']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- ### digitClass.driver.SetSelected(line)
- if not self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Show()
- else:
- if self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Hide()
-
- self.UpdateMap(render=False)
-
- elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
- if not hasattr(self, "copyCatsList"):
- self.copyCatsList = []
- else:
- self.copyCatsIds = []
- self.mouse['box'] = 'box'
-
- elif digitToolbar.GetAction() == "copyLine":
- self.copyIds = []
- self.layerTmp = None
-
- elif digitToolbar.GetAction() == "zbulkLine":
- if len(self.polycoords) > 1: # start new line
- self.polycoords = []
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- if len(self.polycoords) == 1:
- begin = self.Pixel2Cell(self.polycoords[-1])
- end = self.Pixel2Cell(self.mouse['end'])
- else:
- end = self.Pixel2Cell(self.polycoords[-1])
- begin = self.Pixel2Cell(self.mouse['begin'])
-
- self.DrawLines(self.pdcTmp, polycoords = [begin, end])
- elif self.mouse['use'] == 'pointer':
- # get decoration or text id
- self.idlist = []
- self.dragid = ''
- self.lastpos = self.mouse['begin']
- idlist = self.pdc.FindObjects(x=self.lastpos[0], y=self.lastpos[1],
- radius=self.hitradius)
-
- if 99 in idlist: idlist.remove(99)
- if idlist != [] :
- self.dragid = idlist[0] #drag whatever is on top
- else:
- pass
-
- event.Skip()
-
- def OnLeftUp(self, event):
- """
- Left mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['end'] = event.GetPositionTuple()[:]
-
- if self.mouse['use'] in ["zoom", "pan"]:
- # set region in zoom or pan
- begin = self.mouse['begin']
- end = self.mouse['end']
- if self.mouse['use'] == 'zoom':
- # set region for click (zero-width box)
- if begin[0] - end[0] == 0 or \
- begin[1] - end[1] == 0:
- # zoom 1/2 of the screen (TODO: settings)
- begin = (end[0] - self.Map.width / 4,
- end[1] - self.Map.height / 4)
- end = (end[0] + self.Map.width / 4,
- end[1] + self.Map.height / 4)
-
- self.Zoom(begin, end, self.zoomtype)
-
- # redraw map
- self.UpdateMap(render=True)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- elif self.mouse["use"] == "query":
- # querying
- self.parent.QueryMap(self.mouse['begin'][0],self.mouse['begin'][1])
-
- elif self.mouse["use"] == "queryVector":
- # editable mode for vector map layers
- self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])
-
- # clear temp canvas
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if self.mouse["use"] == "measure":
- self.parent.MeasureDist(self.mouse['begin'], self.mouse['end'])
-
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- elif self.mouse["use"] == "pointer" and self.parent.gismanager.georectifying:
- # -> georectifying
- coord = self.Pixel2Cell(self.mouse['end'])
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
-
- self.parent.gismanager.georectifying.SetGCPData(coordtype, coord, self)
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] == "pointer" and self.parent.toolbars['vdigit']:
- # digitization tool active
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
- pos2 = self.Pixel2Cell(self.mouse['end'])
-
- if hasattr(self, "vdigitMove"):
- if len(digitClass.driver.GetSelected()) == 0:
- self.vdigitMove['begin'] = pos1 # left down
- ### else:
- ### dx = pos2[0] - pos1[0] ### ???
- ### dy = pos2[1] - pos1[1]
- ### self.vdigitMove = (self.vdigitMove['begin'][0] + dx,
- ### self.vdigitMove['begin'][1] + dy)
-
- # eliminate initial mouse moving efect
- self.mouse['begin'] = self.mouse['end']
-
- if digitToolbar.GetAction() in ["deleteLine", "moveLine", "moveVertex",
- "copyCats", "copyAttrs", "editLine", "flipLine",
- "mergeLine", "snapLine",
- "queryLine", "breakLine", "typeConv", "connectLine"]:
- nselected = 0
- # -> delete line || move line || move vertex
- if digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- if len(digitClass.driver.GetSelected()) == 0:
- nselected = digitClass.driver.SelectLineByPoint(pos1, type=VDigit_Lines_Type)
- if digitToolbar.GetAction() == "editLine":
- try:
- selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- selVertex = None
-
- if selVertex:
- # self.UpdateMap(render=False)
- ids = digitClass.driver.GetSelected(grassId=False)
- # move this line to tmp layer
- self.polycoords = []
- for id in ids:
- if id % 2: # register only vertices
- e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
- self.polycoords.append((e, n))
- # self.pdcVector.RemoveId(id)
- digitClass.driver.DrawSelected(False)
-
- if selVertex < ids[-1] / 2:
- # choose first or last node of line
- self.vdigitMove['id'].reverse()
- self.polycoords.reverse()
- else:
- # unselect
- digitClass.driver.SetSelected([])
- del self.vdigitMove
-
- self.UpdateMap(render=False)
-
-
- elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
- if not hasattr(self, "copyCatsIds"):
- # 'from' -> select by point
- nselected = digitClass.driver.SelectLineByPoint(pos1, digitClass.GetSelectType())
- if nselected:
- self.copyCatsList = digitClass.driver.GetSelected()
- else:
- # -> 'to' -> select by bbox
- digitClass.driver.SetSelected([])
- # return number of selected features (by box/point)
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- self.copyCatsIds = digitClass.driver.GetSelected()
-
- elif digitToolbar.GetAction() == "queryLine":
- selected = digitClass.SelectLinesByQuery(pos1, pos2)
- nselected = len(selected)
- if nselected > 0:
- digitClass.driver.SetSelected(selected)
-
- else:
- # -> moveLine || deleteLine, etc. (select by point/box)
- if digitToolbar.GetAction() == 'moveLine' and \
- len(digitClass.driver.GetSelected()) > 0:
- nselected = 0
- else:
- if digitToolbar.GetAction() == 'moveLine':
- drawSeg = True
- else:
- drawSeg = False
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType(),
- drawSeg)
-
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- if digitToolbar.GetAction() in ["moveLine", "moveVertex"]:
- # get pseudoDC id of objects which should be redrawn
- if digitToolbar.GetAction() == "moveLine":
- # -> move line
- self.vdigitMove['id'] = digitClass.driver.GetSelected(grassId=False)
- self.vdigitMove['coord'] = digitClass.driver.GetSelectedCoord()
- elif digitToolbar.GetAction() == "moveVertex":
- # -> move vertex
- self.vdigitMove['id'] = digitClass.driver.GetSelectedVertex(pos1)
- if len(self.vdigitMove['id']) == 0: # no vertex found
- digitClass.driver.SetSelected([])
-
-
- #
- # check for duplicates
- #
- if UserSettings.Get(group='vdigit', key='checkForDupl', subkey='enabled') is True:
- dupl = digitClass.driver.GetDuplicates()
- self.UpdateMap(render=False)
-
- if dupl:
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- dlg = VDigitDuplicatesDialog(parent=self, data=dupl, pos=posWindow)
-
- if dlg.ShowModal() == wx.ID_OK:
- digitClass.driver.UnSelect(dlg.GetUnSelected())
- # update selected
- self.UpdateMap(render=False)
-
- if digitToolbar.GetAction() != "editLine":
- # -> move line || move vertex
- self.UpdateMap(render=False)
-
- else: # no vector object found
- if not (digitToolbar.GetAction() in ["moveLine", "moveVertex"] and \
- len(self.vdigitMove['id']) > 0):
- # avoid left-click when features are already selected
- self.UpdateMap(render=False, renderVector=False)
-
- elif digitToolbar.GetAction() in ["splitLine", "addVertex", "removeVertex"]:
- pointOnLine = digitClass.driver.SelectLineByPoint(pos1,
- type=VDigit_Lines_Type)
- if pointOnLine:
- if digitToolbar.GetAction() in ["splitLine", "addVertex"]:
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=self.Cell2Pixel(pointOnLine),
- size=5)
- elif digitToolbar.GetAction() == "removeVertex":
- # get only id of vertex
- try:
- id = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- id = None
-
- if id:
- x, y = self.pdcVector.GetIdBounds(id)[0:2]
- self.pdcVector.RemoveId(id)
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=(x, y),
- size=5)
- else:
- # unselect
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- elif digitToolbar.GetAction() == "copyLine":
- if UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True) == '':
- # no background map -> copy from current vector map layer
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
- else:
- # copy features from background map
- self.copyIds = digitClass.SelectLinesFromBackgroundMap(pos1, pos2)
- if len(self.copyIds) > 0:
- color = UserSettings.Get(group='vdigit', key='symbol',
- subkey=['highlight', 'color'])
- colorStr = str(color[0]) + ":" + \
- str(color[1]) + ":" + \
- str(color[2])
- dVectTmp = ['d.vect',
- 'map=%s' % UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True),
- 'cats=%s' % utils.ListOfCatsToRange(self.copyIds),
- '-i',
- 'color=%s' % colorStr,
- 'fcolor=%s' % colorStr,
- 'type=point,line,boundary,centroid',
- 'width=2']
-
- self.layerTmp = self.Map.AddLayer(type='vector',
- name=globalvar.QUERYLAYER,
- command=dVectTmp)
- self.UpdateMap(render=True, renderVector=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
- self.redrawAll = None
-
- elif digitToolbar.GetAction() == "zbulkLine" and len(self.polycoords) == 2:
- # select lines to be labeled
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- self.DrawLines(pdc=self.pdcTmp) # redraw temp line
- else:
- self.UpdateMap(render=False, renderVector=False)
-
- elif digitToolbar.GetAction() == "connectLine":
- if len(digitClass.driver.GetSelected()) > 0:
- self.UpdateMap(render=False)
-
- if len(digitClass.driver.GetSelected()) > 0:
- self.redrawAll = None
- ### self.OnPaint(None)
-
- elif (self.mouse['use'] == 'pointer' and
- self.dragid >= 0):
- # end drag of overlay decoration
-
- if self.dragid < 99 and self.overlays.has_key(self.dragid):
- self.overlays[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- elif self.dragid > 100 and self.textdict.has_key(self.dragid):
- self.textdict[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- else:
- pass
- self.dragid = None
- self.currtxtid = None
-# self.UpdateMap(render=True)
-
- else:
- pass
-
-# event.Skip()
-
- def OnButtonDClick(self, event):
- """
- Mouse button double click
- """
- Debug.msg (5, "BufferedWindow.OnButtonDClick(): use=%s" % \
- self.mouse["use"])
-
- if self.mouse["use"] == "measure":
- # measure
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.Refresh()
- self.SetCursor(self.parent.cursors["default"])
- elif self.mouse["use"] == "profile":
- # profile
- pass
- # self.pdc.ClearId(self.lineid)
- # self.pdc.ClearId(self.plineid)
- # print 'coordinates: ',self.polycoords
- # self.polycoords = []
- # self.mouse['begin'] = self.mouse['end'] = [0, 0]
- # self.Refresh()
- elif self.mouse['use'] == 'pointer' and self.parent.toolbars['vdigit']:
- # digitization tool
- pass
- else:
- # select overlay decoration options dialog
- clickposition = event.GetPositionTuple()[:]
- idlist = self.pdc.FindObjects(clickposition[0], clickposition[1], self.hitradius)
- if idlist == []:
- return
- self.dragid = idlist[0]
-
- # self.ovlcoords[self.dragid] = self.pdc.GetIdBounds(self.dragid)
- if self.dragid > 100:
- self.currtxtid = self.dragid
- self.parent.OnAddText(None)
- elif self.dragid == 0:
- self.parent.OnAddBarscale(None)
- elif self.dragid == 1:
- self.parent.OnAddLegend(None)
-
-# event.Skip()
-
- def OnRightDown(self, event):
- """
- Right mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnRightDown(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() in ["moveLine", "moveVertex"] and \
- hasattr(self, "vdigitMove"):
-
- pFrom = self.vdigitMove['begin']
- pTo = self.Pixel2Cell(event.GetPositionTuple())
-
- move = (pTo[0] - pFrom[0],
- pTo[1] - pFrom[1])
-
- if digitToolbar.GetAction() == "moveLine":
- # move line
- if digitClass.MoveSelectedLines(move) < 0:
- return
- elif digitToolbar.GetAction() == "moveVertex":
- # move vertex
- if digitClass.MoveSelectedVertex(pFrom, move) < 0:
- return
-
- del self.vdigitMove
-
- event.Skip()
-
- def OnRightUp(self, event):
- """
- Right mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnRightUp(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]:
- # -> add new line / boundary
- try:
- map = digitToolbar.GetLayer().GetName()
- except:
- map = None
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-
- if map:
- # mapcoords = []
- # xy -> EN
- # for coord in self.polycoords:
- # mapcoords.append(self.Pixel2Cell(coord))
- if digitToolbar.GetAction('type') == 'line':
- line = True
- else:
- line = False
-
- if len(self.polycoords) < 2: # ignore 'one-point' lines
- return
-
- fid = digitClass.AddLine(map, line, self.polycoords)
- if fid < 0:
- return
-
- position = self.Cell2Pixel(self.polycoords[-1])
- self.polycoords = []
- self.UpdateMap(render=False)
- self.redrawAll = True
- self.Refresh()
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
- posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
- position[1] + self.dialogOffset))
-
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
-
- addRecordDlg = dbm.DisplayAttributesDialog(parent=self, map=map,
- cats=cats,
- pos=posWindow,
- action="add")
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
- executeCommand = gcmd.Command(cmd=["db.execute",
- "--q",
- "input=%s" % sqlfile.name])
- elif digitToolbar.GetAction() == "deleteLine":
- # -> delete selected vector features
- if digitClass.DeleteSelectedLines() < 0:
- return
- elif digitToolbar.GetAction() == "splitLine":
- # split line
- if digitClass.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
- return
- elif digitToolbar.GetAction() == "addVertex":
- # add vertex
- if digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
- return
- elif digitToolbar.GetAction() == "removeVertex":
- # remove vertex
- if digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin'])) < 0:
- return
- elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
- try:
- if digitToolbar.GetAction() == 'copyCats':
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=False) < 0:
- return
- else:
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=True) < 0:
- return
-
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
- elif digitToolbar.GetAction() == "editLine" and \
- hasattr(self, "vdigitMove"):
- line = digitClass.driver.GetSelected()
- if digitClass.EditLine(line, self.polycoords) < 0:
- return
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "flipLine":
- if digitClass.FlipLine() < 0:
- return
- elif digitToolbar.GetAction() == "mergeLine":
- if digitClass.MergeLine() < 0:
- return
- elif digitToolbar.GetAction() == "breakLine":
- if digitClass.BreakLine() < 0:
- return
- elif digitToolbar.GetAction() == "snapLine":
- if digitClass.SnapLine() < 0:
- return
- elif digitToolbar.GetAction() == "connectLine":
- if len(digitClass.driver.GetSelected()) > 1:
- if digitClass.ConnectLine() < 0:
- return
- elif digitToolbar.GetAction() == "copyLine":
- if digitClass.CopyLine(self.copyIds) < 0:
- return
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- elif digitToolbar.GetAction() == "zbulkLine" and len(self.polycoords) == 2:
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
-
- selected = digitClass.driver.GetSelected()
- dlg = VDigitZBulkDialog(parent=self, title=_("Z bulk-labeling dialog"),
- nselected=len(selected))
- if dlg.ShowModal() == wx.ID_OK:
- if digitClass.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
- dlg.step.GetValue()) < 0:
- return
- self.UpdateMap(render=False, renderVector=True)
- elif digitToolbar.GetAction() == "typeConv":
- # -> feature type conversion
- # - point <-> centroid
- # - line <-> boundary
- if digitClass.TypeConvForSelectedLines() < 0:
- return
-
- if digitToolbar.GetAction() != "addLine":
- # unselect and re-render
- digitClass.driver.SetSelected([])
- self.polycoords = []
- self.UpdateMap(render=False)
-
- self.redrawAll = True
- self.Refresh()
-
- event.Skip()
-
- def OnMiddleDown(self, event):
- """
- Middle mouse button pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- # digitization tool
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- if (digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]) or \
- digitToolbar.GetAction() == "editLine":
- # add line or boundary -> remove last point from the line
- try:
- removed = self.polycoords.pop()
- Debug.msg(4, "BufferedWindow.OnMiddleDown(): polycoords_poped=%s" % \
- [removed,])
-
- self.mouse['begin'] = self.Cell2Pixel(self.polycoords[-1])
- except:
- pass
-
- if digitToolbar.GetAction() == "editLine":
- # remove last vertex & line
- if len(self.vdigitMove['id']) > 1:
- self.vdigitMove['id'].pop()
-
- self.UpdateMap(render=False, renderVector=False)
-
- elif digitToolbar.GetAction() in ["deleteLine", "moveLine", "splitLine",
- "addVertex", "removeVertex", "moveVertex",
- "copyCats", "flipLine", "mergeLine",
- "snapLine", "connectLine", "copyLine",
- "queryLine", "breakLine", "typeConv"]:
- # varios tools -> unselected selected features
- digitClass.driver.SetSelected([])
- if digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] and \
- hasattr(self, "vdigitMove"):
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "copyCats":
- try:
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
-
- elif digitToolbar.GetAction() == "copyLine":
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- self.polycoords = []
- self.UpdateMap(render=False) # render vector
-
- elif digitToolbar.GetAction() == "zbulkLine":
- # reset polyline
- self.polycoords = []
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- self.redrawAll = True
-
- def OnMouseMoving(self, event):
- """
- Motion event and no mouse buttons were pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- self.mouse['end'] = event.GetPositionTuple()[:]
- Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
- (self.mouse['end'][0], self.mouse['end'][1]))
- if digitToolbar.GetAction() == "addLine" and digitToolbar.GetAction('type') in ["line", "boundary"]:
- if len(self.polycoords) > 0:
- self.MouseDraw(pdc=self.pdcTmp, begin=self.Cell2Pixel(self.polycoords[-1]))
- elif digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] \
- and hasattr(self, "vdigitMove"):
- dx = self.mouse['end'][0] - self.mouse['begin'][0]
- dy = self.mouse['end'][1] - self.mouse['begin'][1]
-
- if len(self.vdigitMove['id']) > 0:
- # draw lines on new position
- if digitToolbar.GetAction() == "moveLine":
- # move line
- for id in self.vdigitMove['id']:
- self.pdcTmp.TranslateId(id, dx, dy)
- elif digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # move vertex ->
- # (vertex, left vertex, left line,
- # right vertex, right line)
-
- # do not draw static lines
- if digitToolbar.GetAction() == "moveVertex":
- self.polycoords = []
- ### self.pdcTmp.TranslateId(self.vdigitMove['id'][0], dx, dy)
- self.pdcTmp.RemoveId(self.vdigitMove['id'][0])
- if self.vdigitMove['id'][1] > 0: # previous vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][1])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][1]+1)
- self.polycoords.append((x, y))
- ### x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][0])[0:2])
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- if self.vdigitMove['id'][2] > 0: # next vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][2])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][2]-1)
- self.polycoords.append((x, y))
-
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- else: # edit line
- try:
- if self.vdigitMove['id'][-1] > 0: # previous vertex
- self.MouseDraw(pdc=self.pdcTmp,
- begin=self.Cell2Pixel(self.polycoords[-1]))
- except: # no line
- self.vdigitMove['id'] = []
- self.polycoords = []
-
- self.Refresh() # TODO: use RefreshRect()
- self.mouse['begin'] = self.mouse['end']
-
- elif digitToolbar.GetAction() == "zbulkLine":
- if len(self.polycoords) == 1:
- # draw mouse moving
- self.MouseDraw(self.pdcTmp)
-
- event.Skip()
-
- def ClearLines(self, pdc=None):
- """
- Clears temporary drawn lines from PseudoDC
- """
- if not pdc:
- pdc=self.pdcTmp
- try:
- pdc.ClearId(self.lineid)
- pdc.RemoveId(self.lineid)
- except:
- pass
-
- try:
- pdc.ClearId(self.plineid)
- pdc.RemoveId(self.plineid)
- except:
- pass
-
- Debug.msg(4, "BufferedWindow.ClearLines(): lineid=%s, plineid=%s" %
- (self.lineid, self.plineid))
-
- ### self.Refresh()
-
- return True
-
- def Pixel2Cell(self, (x, y)):
- """
- Convert image coordinates to real word coordinates
-
- Input : int x, int y
- Output: float x, float y
- """
-
- try:
- x = int(x)
- y = int(y)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- east = w + x * res
- north = n - y * res
-
- # extent does not correspond with whole map canvas area...
- # east = self.Map.region['w'] + x * self.Map.region["ewres"]
- # north = self.Map.region['n'] - y * self.Map.region["nsres"]
-
- return (east, north)
-
- def Cell2Pixel(self, (east, north)):
- """
- Convert real word coordinates to image coordinates
- """
-
- try:
- east = float(east)
- north = float(north)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- # x = int((east - w) / res)
- # y = int((n - north) / res)
-
- x = (east - w) / res
- y = (n - north) / res
-
- return (x, y)
-
- def Zoom(self, begin, end, zoomtype):
- """
- Calculates new region while (un)zoom/pan-ing
- """
- x1, y1 = begin
- x2, y2 = end
- newreg = {}
-
- # threshold - too small squares do not make sense
- # can only zoom to windows of > 5x5 screen pixels
- if abs(x2-x1) > 5 and abs(y2-y1) > 5 and zoomtype != 0:
-
- if x1 > x2:
- x1, x2 = x2, x1
- if y1 > y2:
- y1, y2 = y2, y1
-
- # zoom in
- if zoomtype > 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((x1, y1))
- newreg['e'], newreg['s'] = self.Pixel2Cell((x2, y2))
-
- # zoom out
- elif zoomtype < 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((-x1 * 2, -y1 * 2))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + 2 * \
- (self.Map.width - x2),
- self.Map.height + 2 * \
- (self.Map.height - y2)))
- # pan
- elif zoomtype == 0:
- dx = x1 - x2
- dy = y1 - y2
- newreg['w'], newreg['n'] = self.Pixel2Cell((dx, dy))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + dx,
- self.Map.height + dy))
-
- # if new region has been calculated, set the values
- if newreg != {}:
- # LL locations
- if self.parent.Map.projinfo['proj'] == 'll':
- if newreg['n'] > 90.0:
- newreg['n'] = 90.0
- if newreg['s'] < -90.0:
- newreg['s'] = -90.0
-
- ce = newreg['w'] + (newreg['e'] - newreg['w']) / 2
- cn = newreg['s'] + (newreg['n'] - newreg['s']) / 2
-
- if hasattr(self, "vdigitMove"):
- # xo = self.Cell2Pixel((self.Map.region['center_easting'], self.Map.region['center_northing']))
- # xn = self.Cell2Pixel(ce, cn))
- tmp = self.Pixel2Cell(self.mouse['end'])
-
- # calculate new center point and display resolution
- self.Map.region['center_easting'] = ce
- self.Map.region['center_northing'] = cn
- self.Map.region["ewres"] = (newreg['e'] - newreg['w']) / self.Map.width
- self.Map.region["nsres"] = (newreg['n'] - newreg['s']) / self.Map.height
- self.Map.AlignExtentFromDisplay()
-
- if hasattr(self, "vdigitMove"):
- tmp1 = self.mouse['end']
- tmp2 = self.Cell2Pixel(self.vdigitMove['begin'])
- dx = tmp1[0] - tmp2[0]
- dy = tmp1[1] - tmp2[1]
- self.vdigitMove['beginDiff'] = (dx, dy)
- for id in self.vdigitMove['id']:
- self.pdcTmp.RemoveId(id)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- if self.redrawAll is False:
- self.redrawAll = True
-
- def ZoomBack(self):
- """
- Zoom to previous extents in zoomhistory list
- """
-
- zoom = []
- if len(self.zoomhistory) > 1:
- self.zoomhistory.pop()
- zoom = self.zoomhistory[len(self.zoomhistory)-1]
- # (n, s, e, w)
- if zoom:
- # zoom to selected region
- self.Map.region['center_easting'] = zoom[3] + \
- (zoom[2] - zoom[3]) / 2
- self.Map.region['center_northing'] = zoom[1] + \
- (zoom[0] - zoom[1]) / 2
- self.Map.region["ewres"] = (zoom[2] - zoom[3]) / self.Map.width
- self.Map.region["nsres"] = (zoom[0] - zoom[1]) / self.Map.height
- self.Map.AlignExtentFromDisplay()
-
- # update map
- self.UpdateMap()
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- def ZoomHistory(self, n, s, e, w):
- """
- Manages a list of last 10 zoom extents
-
- Return removed history item if exists
- """
- removed = None
- self.zoomhistory.append((n,s,e,w))
-
- if len(self.zoomhistory) > 10:
- removed = self.zoomhistory.pop(0)
-
- if removed:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s, removed=%s" %
- (self.zoomhistory, removed))
- else:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s" %
- (self.zoomhistory))
-
- return removed
-
- def OnZoomToMap(self, event):
- """
- Set display extents to match selected raster (including NULLs)
- or vector map.
- """
- self.ZoomToMap()
-
- def OnZoomToRaster(self, event):
- """
- Set display extents to match selected raster map (ignore NULLs)
- """
- self.ZoomToMap(zoom=True)
-
- def ZoomToMap(self, layer = None, zoom = False):
- """
- Set display extents to match selected raster
- or vector map.
- """
- zoomreg = {}
-
- if not layer:
- layer = self.GetSelectedLayer(multi = True)
-
- if not layer:
- return
-
- rast = []
- vect = []
- updated = False
- for l in layer:
- # only raster/vector layers are currently supported
- if l.type == 'raster':
- rast.append(l.name)
- elif l.type == 'vector':
- if self.parent.digit and l.name == self.parent.digit.map and \
- self.parent.digit.type == 'vdigit':
- w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
- self.Map.GetRegion(n=n, s=s, w=w, e=e,
- update=True)
- updated = True
- else:
- vect.append(l.name)
-
- if not updated:
- self.Map.GetRegion(rast = rast,
- vect = vect,
- update = True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToWind(self, event):
- """
- Set display geometry to match computational
- region settings (set with g.region)
- """
- self.Map.region = self.Map.GetRegion()
- ### self.Map.SetRegion(windres=True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToDefault(self, event):
- """
- Set display geometry to match default region settings
- """
- self.Map.region = self.Map.GetRegion(default=True)
- self.Map.AdjustRegion() # aling region extent to the display
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def DisplayToWind(self, event):
- """
- Set computational region (WIND file) to
- match display extents
- """
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- # We ONLY want to set extents here. Don't mess with resolution. Leave that
- # for user to set explicitly with g.region
- new = self.Map.AlignResolution()
-
- cmdRegion = ["g.region", "--o",
- "n=%f" % new['n'],
- "s=%f" % new['s'],
- "e=%f" % new['e'],
- "w=%f" % new['w'],
- "rows=%d" % int(new['rows']),
- "cols=%d" % int(new['cols'])]
-
- p = gcmd.Command(cmdRegion)
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def ZoomToSaved(self, event):
- """!Set display geometry to match extents in
- saved region file
- """
- dlg = gdialogs.SavedRegion(parent = self, id = wx.ID_ANY,
- title = _("Zoom to saved region extents"),
- pos=wx.DefaultPosition, size=wx.DefaultSize,
- style=wx.DEFAULT_DIALOG_STYLE,
- loadsave='load')
-
- if dlg.ShowModal() == wx.ID_CANCEL:
- dlg.Destroy()
- return
-
- wind = dlg.wind
-
- self.Map.GetRegion(regionName = wind,
- update = True)
-
- dlg.Destroy()
-
- self.ZoomHistory(self.Map.region['n'],
- self.Map.region['s'],
- self.Map.region['e'],
- self.Map.region['w'])
-
- self.UpdateMap()
-
- def SaveDisplayRegion(self, event):
- """
- Save display extents to named region file.
- """
-
- dlg = gdialogs.SavedRegion(parent = self, id = wx.ID_ANY,
- title = _("Save display extents to region file"),
- pos=wx.DefaultPosition, size=wx.DefaultSize,
- style=wx.DEFAULT_DIALOG_STYLE,
- loadsave='save')
- if dlg.ShowModal() == wx.ID_CANCEL:
- dlg.Destroy()
- return
-
- wind = dlg.wind
-
- # test to see if it already exists and ask permission to overwrite
- windpath = os.path.join(self.Map.env["GISDBASE"], self.Map.env["LOCATION_NAME"],
- self.Map.env["MAPSET"], "windows", wind)
-
- if windpath and not os.path.exists(windpath):
- self.SaveRegion(wind)
- elif windpath and os.path.exists(windpath):
- overwrite = wx.MessageBox(_("Region file <%s> already exists. "
- "Do you want to overwrite it?") % (wind),
- _("Warning"), wx.YES_NO | wx.CENTRE)
- if (overwrite == wx.YES):
- self.SaveRegion(wind)
- else:
- pass
-
- dlg.Destroy()
-
- def SaveRegion(self, wind):
- """
- Save region settings
- """
- ### new = self.Map.AlignResolution()
- new = self.Map.GetCurrentRegion()
-
- cmdRegion = ["g.region",
- "-u",
- "n=%f" % new['n'],
- "s=%f" % new['s'],
- "e=%f" % new['e'],
- "w=%f" % new['w'],
- "rows=%d" % new['rows'],
- "cols=%d" % new['cols'],
- "save=%s" % wind,
- "--o"]
-
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- p = gcmd.Command(cmdRegion)
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def Distance(self, beginpt, endpt, screen=True):
- """Calculete distance
-
- LL-locations not supported
-
- @todo Use m.distance
-
- @param beginpt first point
- @param endpt second point
- @param screen True for screen coordinates otherwise EN
- """
- x1, y1 = beginpt
- x2, y2 = endpt
- if screen:
- dEast = (x2 - x1) * self.Map.region["ewres"]
- dNorth = (y2 - y1) * self.Map.region["nsres"]
- else:
- dEast = (x2 - x1)
- dNorth = (y2 - y1)
-
-
- return (math.sqrt(math.pow((dEast),2) + math.pow((dNorth),2)), (dEast, dNorth))
-
-class MapFrame(wx.Frame):
- """
- Main frame for map display window. Drawing takes place in child double buffered
- drawing window.
- """
-
- def __init__(self, parent=None, id=wx.ID_ANY, title=_("GRASS GIS - Map display"),
- pos=wx.DefaultPosition, size=wx.DefaultSize,
- style=wx.DEFAULT_FRAME_STYLE, toolbars=["map"],
- tree=None, notebook=None, gismgr=None, page=None,
- Map=None, auimgr=None):
- """
- Main map display window with toolbars, statusbar and
- DrawWindow
-
- @param toolbars array of activated toolbars, e.g. ['map', 'digit']
- @param tree reference to layer tree
- @param notebook control book ID in Layer Manager
- @param gismgr Layer Manager panel
- @param page notebook page with layer tree
- @param Map instance of render.Map
- """
- self.gismanager = gismgr # GIS Manager object
- self.Map = Map # instance of render.Map
- self.tree = tree # GIS Manager layer tree object
- self.page = page # Notebook page holding the layer tree
- self.layerbook = notebook # GIS Manager layer tree notebook
- self.parent = parent
-
- self.layers = {}
-
- #
- # available cursors
- #
- self.cursors = {
- # default: cross
- # "default" : wx.StockCursor(wx.CURSOR_DEFAULT),
- "default" : wx.StockCursor(wx.CURSOR_ARROW),
- "cross" : wx.StockCursor(wx.CURSOR_CROSS),
- "hand" : wx.StockCursor(wx.CURSOR_HAND),
- "pencil" : wx.StockCursor(wx.CURSOR_PENCIL),
- "sizenwse": wx.StockCursor(wx.CURSOR_SIZENWSE)
- }
-
- wx.Frame.__init__(self, parent, id, title, pos, size, style)
- self.SetName("MapWindow")
-
- #
- # set the size & system icon
- #
- self.SetClientSize(size)
- self.iconsize = (16, 16)
-
- self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass_map.ico'), wx.BITMAP_TYPE_ICO))
-
- #
- # Fancy gui
- #
- # self._mgr = auimgr
- self._mgr = wx.aui.AuiManager(self)
-
- #
- # Add toolbars
- #
- self.toolbars = { 'map' : None,
- 'vdigit' : None,
- 'georect' : None,
- 'nviz' : None }
- for toolb in toolbars:
- self.AddToolbar(toolb)
-
- #
- # Add statusbar
- #
- self.statusbar = self.CreateStatusBar(number=4, style=0)
- self.statusbar.SetStatusWidths([-5, -2, -1, -1])
- self.toggleStatus = wx.Choice(self.statusbar, wx.ID_ANY,
- choices = globalvar.MAP_DISPLAY_STATUSBAR_MODE)
- self.toggleStatus.SetSelection(UserSettings.Get(group='display', key='statusbarMode', subkey='selection'))
- self.statusbar.Bind(wx.EVT_CHOICE, self.OnToggleStatus, self.toggleStatus)
- # auto-rendering checkbox
- self.autoRender = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Render"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleRender, self.autoRender)
- self.autoRender.SetValue(UserSettings.Get(group='display', key='autoRendering', subkey='enabled'))
- self.autoRender.SetToolTip(wx.ToolTip (_("Enable/disable auto-rendering")))
- # show region
- self.showRegion = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Show computational extent"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleShowRegion, self.showRegion)
-
- self.showRegion.SetValue(False)
- self.showRegion.Hide()
- self.showRegion.SetToolTip(wx.ToolTip (_("Show/hide computational "
- "region extent (set with g.region). "
- "Display region drawn as a blue box inside the "
- "computational region, "
- "computational region inside a display region "
- "as a red box).")))
- # set resolution
- self.compResolution = wx.CheckBox(parent=self.statusbar, id=wx.ID_ANY,
- label=_("Constrain display resolution to computational settings"))
- self.statusbar.Bind(wx.EVT_CHECKBOX, self.OnToggleResolution, self.compResolution)
- self.compResolution.SetValue(UserSettings.Get(group='display', key='compResolution', subkey='enabled'))
- self.compResolution.Hide()
- self.compResolution.SetToolTip(wx.ToolTip (_("Constrain display resolution "
- "to computational region settings. "
- "Default value for new map displays can "
- "be set up in 'User GUI settings' dialog.")))
- # map scale
- self.mapScale = wx.TextCtrl(parent=self.statusbar, id=wx.ID_ANY,
- value="", style=wx.TE_PROCESS_ENTER,
- size=(150, -1))
- self.mapScale.Hide()
- self.statusbar.Bind(wx.EVT_TEXT_ENTER, self.OnChangeMapScale, self.mapScale)
-
- # mask
- self.maskInfo = wx.StaticText(parent = self.statusbar, id = wx.ID_ANY,
- label = '')
- self.maskInfo.SetForegroundColour(wx.Colour(255, 0, 0))
-
-
- # on-render gauge
- self.onRenderGauge = wx.Gauge(parent=self.statusbar, id=wx.ID_ANY,
- range=0, style=wx.GA_HORIZONTAL)
- self.onRenderGauge.Hide()
-
- self.StatusbarReposition() # reposition statusbar
-
- #
- # Init map display (buffered DC & set default cursor)
- #
- self.MapWindow2D = BufferedWindow(self, id=wx.ID_ANY,
- Map=self.Map, tree=self.tree, gismgr=self.gismanager)
- # default is 2D display mode
- self.MapWindow = self.MapWindow2D
- self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
- self.MapWindow.SetCursor(self.cursors["default"])
- # used by Nviz (3D display mode)
- self.MapWindow3D = None
-
- #
- # initialize region values
- #
- self.__InitDisplay()
-
- #
- # Bind various events
- #
- self.Bind(wx.EVT_ACTIVATE, self.OnFocus)
- self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.Bind(render.EVT_UPDATE_PRGBAR, self.OnUpdateProgress)
-
- #
- # Update fancy gui style
- #
- self._mgr.AddPane(self.MapWindow, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
- self._mgr.Update()
-
- #
- # Init print module and classes
- #
- self.printopt = disp_print.PrintOptions(self, self.MapWindow)
-
- #
- # Initialization of digitization tool
- #
- self.digit = None
-
- #
- # Init zoom history
- #
- self.MapWindow.ZoomHistory(self.Map.region['n'],
- self.Map.region['s'],
- self.Map.region['e'],
- self.Map.region['w'])
-
- #
- # Re-use dialogs
- #
- self.dialogs = {}
- self.dialogs['attributes'] = None
- self.dialogs['category'] = None
- self.dialogs['barscale'] = None
- self.dialogs['legend'] = None
-
- self.decorationDialog = None # decoration/overlays
-
- def AddToolbar(self, name):
- """
- Add defined toolbar to the window
-
- Currently known toolbars are:
- - map basic map toolbar
- - digit vector digitizer
- - georect georectifier
- """
- # default toolbar
- if name == "map":
- self.toolbars['map'] = toolbars.MapToolbar(self, self.Map)
-
- self._mgr.AddPane(self.toolbars['map'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("maptoolbar").Caption(_("Map Toolbar")).
- ToolbarPane().Top().
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2).
- BestSize((self.toolbars['map'].GetToolbar().GetSize())))
-
- # vector digitizer
- elif name == "vdigit":
- from vdigit import haveVDigit
- if not haveVDigit:
- from vdigit import errorMsg
- msg = _("Unable to start vector digitizer.\nThe VDigit python extension "
- "was not found or loaded properly.\n"
- "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg)
-
- self.toolbars['map'].combo.SetValue (_("2D view"))
- wx.MessageBox(parent=self,
- message=msg,
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- self.toolbars['vdigit'] = toolbars.VDigitToolbar(parent=self, map=self.Map,
- layerTree=self.tree,
- log=self.gismanager.goutput)
-
- for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
- self._mgr.AddPane(self.toolbars['vdigit'].toolbar[toolRow],
- wx.aui.AuiPaneInfo().
- Name("vdigittoolbar" + str(toolRow)).Caption(_("Vector digitizer toolbar")).
- ToolbarPane().Top().Row(toolRow + 1).
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2).
- BestSize((self.toolbars['vdigit'].GetToolbar().GetSize())))
-
- # change mouse to draw digitized line
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.zoomtype = 0
- self.MapWindow.pen = wx.Pen(colour='red', width=2, style=wx.SOLID)
- self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SOLID)
- # georectifier
- elif name == "georect":
- self.toolbars['georect'] = toolbars.GRToolbar(self, self.Map)
-
- self._mgr.AddPane(self.toolbars['georect'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("georecttoolbar").Caption(_("Georectification toolbar")).
- ToolbarPane().Top().
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2))
- # nviz
- elif name == "nviz":
- import nviz
-
- # check for GLCanvas and OpenGL
- msg = None
- if not nviz.haveGLCanvas:
- msg = _("Unable to switch to 3D display mode.\nThe GLCanvas class has not been "
- "included with this build "
- "of wxPython!\nSwitching back to "
- "2D display mode.\n\nDetails: %s" % nviz.errorMsg)
- if not nviz.haveNviz:
- msg = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
- "was not found or loaded properly.\n"
- "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg)
-
- if msg:
- self.toolbars['map'].combo.SetValue (_("2D view"))
- wx.MessageBox(parent=self,
- message=msg,
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- #
- # add Nviz toolbar and disable 2D display mode tools
- #
- self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
- self.toolbars['map'].Enable2D(False)
-
- #
- # update layer tree (-> enable 3d-rasters)
- #
- self.tree.EnableItemType(type='3d-raster', enable=True)
-
- #
- # update status bar
- #
- self.toggleStatus.Enable(False)
-
- #
- # erase map window
- #
- self.MapWindow.EraseMap()
-
- busy = wx.BusyInfo(message=_("Please wait, loading data..."),
- parent=self)
- wx.Yield()
-
- #
- # create GL window & NVIZ toolbar
- #
- if not self.MapWindow3D:
- self.MapWindow3D = nviz.GLWindow(self, id=wx.ID_ANY,
- Map=self.Map, tree=self.tree, gismgr=self.gismanager)
- self.nvizToolWin = nviz.NvizToolWindow(self, id=wx.ID_ANY,
- mapWindow=self.MapWindow3D)
- self.MapWindow3D.OnPaint(None) # -> LoadData
- self.MapWindow3D.Show()
- self.MapWindow3D.UpdateView(None)
-
- busy.Destroy()
-
- self.nvizToolWin.Show()
-
- #
- # switch from MapWindow to MapWindowGL
- # add nviz toolbar
- #
- self._mgr.DetachPane(self.MapWindow2D)
- self.MapWindow2D.Hide()
- self._mgr.AddPane(self.MapWindow3D, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
- self._mgr.AddPane(self.toolbars['nviz'].toolbar,
- wx.aui.AuiPaneInfo().
- Name("nviztoolbar").Caption(_("Nviz toolbar")).
- ToolbarPane().Top().Row(1).
- LeftDockable(False).RightDockable(False).
- BottomDockable(False).TopDockable(True).
- CloseButton(False).Layer(2))
-
- self.MapWindow = self.MapWindow3D
- self.SetStatusText("", 0)
-
- self._mgr.Update()
-
- def RemoveToolbar (self, name):
- """
- Removes toolbar from the window
-
- TODO: Only hide, activate by calling AddToolbar()
- """
-
- # cannot hide main toolbar
- if name == "map":
- return
- elif name == "vdigit":
- # TODO: not destroy only hide
- for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
- self._mgr.DetachPane (self.toolbars['vdigit'].toolbar[toolRow])
- self.toolbars['vdigit'].toolbar[toolRow].Destroy()
- else:
- self._mgr.DetachPane (self.toolbars[name].toolbar)
- self.toolbars[name].toolbar.Destroy()
-
- self.toolbars[name] = None
-
- if name == 'nviz':
- # hide nviz tools
- self.nvizToolWin.Hide()
- # unload data
-# self.MapWindow3D.Reset()
- # switch from MapWindowGL to MapWindow
- self._mgr.DetachPane(self.MapWindow3D)
- self.MapWindow3D.Hide()
- self.MapWindow2D.Show()
- self._mgr.AddPane(self.MapWindow2D, wx.aui.AuiPaneInfo().CentrePane().
- Dockable(False).BestSize((-1,-1)).
- CloseButton(False).DestroyOnClose(True).
- Layer(0))
- self.MapWindow = self.MapWindow2D
-
- #
- # update layer tree (-> disable 3d-rasters)
- #
- self.tree.EnableItemType(type='3d-raster', enable=False)
- self.MapWindow.UpdateMap()
-
- self.toolbars['map'].combo.SetValue (_("2D view"))
- self.toolbars['map'].Enable2D(True)
- self.toggleStatus.Enable(True)
-
- self._mgr.Update()
-
- def __InitDisplay(self):
- """
- Initialize map display, set dimensions and map region
- """
- self.width, self.height = self.GetClientSize()
-
- Debug.msg(2, "MapFrame.__InitDisplay():")
- self.Map.ChangeMapSize(self.GetClientSize())
- self.Map.region = self.Map.GetRegion() # g.region -upgc
- # self.Map.SetRegion() # adjust region to match display window
-
- def OnUpdateProgress(self, event):
- """
- Update progress bar info
- """
- self.onRenderGauge.SetValue(event.value)
-
- event.Skip()
-
- def OnFocus(self, event):
- """
- Change choicebook page to match display.
- Or set display for georectifying
- """
- if self.gismanager.georectifying:
- # in georectifying session; display used to get get geographic
- # coordinates for GCPs
- self.OnPointer(event)
- else:
- # change bookcontrol page to page associated with display
- if self.page:
- pgnum = self.layerbook.GetPageIndex(self.page)
- if pgnum > -1:
- self.layerbook.SetSelection(pgnum)
-
- event.Skip()
-
- def OnMotion(self, event):
- """
- Mouse moved
- Track mouse motion and update status bar
- """
- # update statusbar if required
- if self.toggleStatus.GetSelection() == 0: # Coordinates
- e, n = self.MapWindow.Pixel2Cell(event.GetPositionTuple())
- if self.toolbars['vdigit'] and \
- self.toolbars['vdigit'].GetAction() == 'addLine' and \
- self.toolbars['vdigit'].GetAction('type') in ('line', 'boundary') and \
- len(self.MapWindow.polycoords) > 0:
- # for linear feature show segment and total length
- distance_seg = self.MapWindow.Distance(self.MapWindow.polycoords[-1],
- (e, n), screen=False)[0]
- distance_tot = distance_seg
- for idx in range(1, len(self.MapWindow.polycoords)):
- distance_tot += self.MapWindow.Distance(self.MapWindow.polycoords[idx-1],
- self.MapWindow.polycoords[idx],
- screen=False )[0]
- self.statusbar.SetStatusText("%.2f, %.2f (seg: %.2f; tot: %.2f)" % \
- (e, n, distance_seg, distance_tot), 0)
- else:
- if self.Map.projinfo['proj'] == 'll':
- self.statusbar.SetStatusText("%s" % utils.Deg2DMS(e, n), 0)
- else:
- self.statusbar.SetStatusText("%.2f, %.2f" % (e, n), 0)
-
- event.Skip()
-
- def OnDraw(self, event):
- """
- Re-display current map composition
- """
- self.MapWindow.UpdateMap(render=False)
-
- def OnRender(self, event):
- """
- Re-render map composition (each map layer)
- """
- # delete tmp map layers (queries)
- qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)
- for layer in qlayer:
- self.Map.DeleteLayer(layer)
-
- # delete tmp lines
- if self.MapWindow.mouse["use"] in ["measure", "profile"]:
- self.MapWindow.polycoords = []
- self.MapWindow.ClearLines()
-
- # deselect features in vdigit
- if self.toolbars['vdigit'] and self.digit:
- self.digit.driver.SetSelected([])
- self.MapWindow.UpdateMap(render=True, renderVector=True)
- else:
- self.MapWindow.UpdateMap(render=True)
-
- # update statusbar
- self.StatusbarUpdate()
-
- def OnPointer(self, event):
- """
- Pointer button clicked
- """
- if self.toolbars['map']:
- if event:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "pointer"
- self.MapWindow.mouse['box'] = "point"
-
- # change the cursor
- if self.toolbars['vdigit']:
- # digitization tool activated
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- # reset mouse['box'] if needed
- if self.toolbars['vdigit'].GetAction() in ['addLine']:
- if self.toolbars['vdigit'].GetAction('type') in ['point', 'centroid']:
- self.MapWindow.mouse['box'] = 'point'
- else: # line, boundary
- self.MapWindow.mouse['box'] = 'line'
- elif self.toolbars['vdigit'].GetAction() in ['addVertex', 'removeVertex', 'splitLine',
- 'editLine', 'displayCats', 'displayAttrs',
- 'copyCats']:
- self.MapWindow.mouse['box'] = 'point'
- else: # moveLine, deleteLine
- self.MapWindow.mouse['box'] = 'box'
-
- elif self.gismanager.georectifying:
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- else:
- self.MapWindow.SetCursor(self.cursors["default"])
-
- def OnZoomIn(self, event):
- """
- Zoom in the map.
- Set mouse cursor, zoombox attributes, and zoom direction
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "zoom"
- self.MapWindow.mouse['box'] = "box"
- self.MapWindow.zoomtype = 1
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnZoomOut(self, event):
- """
- Zoom out the map.
- Set mouse cursor, zoombox attributes, and zoom direction
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "zoom"
- self.MapWindow.mouse['box'] = "box"
- self.MapWindow.zoomtype = -1
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnZoomBack(self, event):
- """
- Zoom last (previously stored position)
- """
- self.MapWindow.ZoomBack()
-
- def OnPan(self, event):
- """
- Panning, set mouse to drag
- """
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- self.toolbars['map'].action['desc'] = ''
-
- self.MapWindow.mouse['use'] = "pan"
- self.MapWindow.mouse['box'] = "pan"
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["hand"])
-
- def OnErase(self, event):
- """
- Erase the canvas
- """
- self.MapWindow.EraseMap()
-
- def OnZoomRegion(self, event):
- """
- Zoom to region
- """
- self.Map.getRegion()
- self.Map.getResolution()
- self.UpdateMap()
- # event.Skip()
-
- def OnAlignRegion(self, event):
- """
- Align region
- """
- if not self.Map.alignRegion:
- self.Map.alignRegion = True
- else:
- self.Map.alignRegion = False
- # event.Skip()
-
- def OnToggleRender(self, event):
- """
- Enable/disable auto-rendering
- """
- if self.autoRender.GetValue():
- self.OnRender(None)
-
- def OnToggleShowRegion(self, event):
- """
- Show/Hide extent in map canvas
- """
- if self.showRegion.GetValue():
- # show extent
- self.MapWindow.regionCoords = []
- else:
- del self.MapWindow.regionCoords
-
- # redraw map if auto-rendering is enabled
- if self.autoRender.GetValue():
- self.OnRender(None)
-
- def OnToggleResolution(self, event):
- """
- Use resolution of computation region settings
- for redering image instead of display resolution
- """
- # redraw map if auto-rendering is enabled
- if self.autoRender.GetValue():
- self.OnRender(None)
-
- def OnToggleStatus(self, event):
- """
- Toggle status text
- """
- self.StatusbarUpdate()
-
- def OnChangeMapScale(self, event):
- """
- Map scale changed by user
- """
- scale = event.GetString()
-
- try:
- if scale[:2] != '1:':
- raise ValueError
- value = int(scale[2:])
- except ValueError:
- self.mapScale.SetValue('1:%ld' % int(self.mapScaleValue))
- return
-
- dEW = value * (self.Map.region['cols'] / self.ppm[0])
- dNS = value * (self.Map.region['rows'] / self.ppm[1])
- self.Map.region['n'] = self.Map.region['center_northing'] + dNS / 2.
- self.Map.region['s'] = self.Map.region['center_northing'] - dNS / 2.
- self.Map.region['w'] = self.Map.region['center_easting'] - dEW / 2.
- self.Map.region['e'] = self.Map.region['center_easting'] + dEW / 2.
-
- # add to zoom history
- self.MapWindow.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- # redraw a map
- self.MapWindow.UpdateMap()
- self.mapScale.SetFocus()
-
- def StatusbarUpdate(self):
- """Update statusbar content"""
-
- self.showRegion.Hide()
- self.compResolution.Hide()
- self.mapScale.Hide()
- self.mapScaleValue = self.ppm = None
-
- if self.toggleStatus.GetSelection() == 0: # Coordinates
- self.statusbar.SetStatusText("", 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.toggleStatus.GetSelection() == 1: # Extent
- self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f" %
- (self.Map.region["w"], self.Map.region["e"],
- self.Map.region["s"], self.Map.region["n"]), 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.toggleStatus.GetSelection() == 2: # Comp. region
- compregion = self.Map.GetRegion()
- self.statusbar.SetStatusText("%.2f - %.2f, %.2f - %.2f (%.2f, %.2f)" %
- (compregion["w"], compregion["e"],
- compregion["s"], compregion["n"],
- compregion["ewres"], compregion["nsres"]), 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.toggleStatus.GetSelection() == 3: # Show comp. extent
- self.statusbar.SetStatusText("", 0)
- self.showRegion.Show()
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.toggleStatus.GetSelection() == 4: # Display mode
- self.statusbar.SetStatusText("", 0)
- self.compResolution.Show()
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- elif self.toggleStatus.GetSelection() == 5: # Display geometry
- self.statusbar.SetStatusText("rows=%d; cols=%d; nsres=%.2f; ewres=%.2f" %
- (self.Map.region["rows"], self.Map.region["cols"],
- self.Map.region["nsres"], self.Map.region["ewres"]), 0)
- # enable long help
- self.StatusbarEnableLongHelp()
-
- elif self.toggleStatus.GetSelection() == 6: # Map scale
- # TODO: need to be fixed...
- ### screen X region problem
- ### user should specify ppm
- dc = wx.ScreenDC()
- dpSizePx = wx.DisplaySize() # display size in pixels
- dpSizeMM = wx.DisplaySizeMM() # display size in mm (system)
- dpSizeIn = (dpSizeMM[0] / 25.4, dpSizeMM[1] / 25.4) # inches
- sysPpi = dc.GetPPI()
- comPpi = (dpSizePx[0] / dpSizeIn[0],
- dpSizePx[1] / dpSizeIn[1])
-
- ppi = comPpi # pixel per inch
- self.ppm = ((ppi[0] / 2.54) * 100, # pixel per meter
- (ppi[1] / 2.54) * 100)
-
- Debug.msg(4, "MapFrame.StatusbarUpdate(mapscale): size: px=%d,%d mm=%f,%f "
- "in=%f,%f ppi: sys=%d,%d com=%d,%d; ppm=%f,%f" % \
- (dpSizePx[0], dpSizePx[1], dpSizeMM[0], dpSizeMM[1],
- dpSizeIn[0], dpSizeIn[1],
- sysPpi[0], sysPpi[1], comPpi[0], comPpi[1],
- self.ppm[0], self.ppm[1]))
-
- region = self.Map.region
-
- heightCm = region['rows'] / self.ppm[1] * 100
- widthCm = region['cols'] / self.ppm[0] * 100
-
- Debug.msg(4, "MapFrame.StatusbarUpdate(mapscale): width_cm=%f, height_cm=%f" %
- (widthCm, heightCm))
-
- xscale = (region['e'] - region['w']) / (region['cols'] / self.ppm[0])
- yscale = (region['n'] - region['s']) / (region['rows'] / self.ppm[1])
- scale = (xscale + yscale) / 2.
-
- Debug.msg(3, "MapFrame.StatusbarUpdate(mapscale): xscale=%f, yscale=%f -> scale=%f" % \
- (xscale, yscale, scale))
-
- self.statusbar.SetStatusText("")
- try:
- self.mapScale.SetValue("1:%ld" % (scale + 0.5))
- except TypeError:
- pass
- self.mapScaleValue = scale
- self.mapScale.Show()
-
- # disable long help
- self.StatusbarEnableLongHelp(False)
-
- else:
- self.statusbar.SetStatusText("", 1)
-
- def StatusbarEnableLongHelp(self, enable=True):
- """Enable/disable toolbars long help"""
- for toolbar in self.toolbars.itervalues():
- if toolbar:
- toolbar.EnableLongHelp(enable)
-
- def StatusbarReposition(self):
- """Reposition checkbox in statusbar"""
- # reposition checkbox
- widgets = [(0, self.showRegion),
- (0, self.compResolution),
- (0, self.mapScale),
- (0, self.onRenderGauge),
- (1, self.toggleStatus),
- (2, self.maskInfo),
- (3, self.autoRender)]
- for idx, win in widgets:
- rect = self.statusbar.GetFieldRect(idx)
- if idx == 0: # show region / mapscale / process bar
- # -> size
- wWin, hWin = win.GetBestSize()
- if win == self.onRenderGauge:
- wWin = rect.width - 6
- # -> position
- # if win == self.showRegion:
- # x, y = rect.x + rect.width - wWin, rect.y - 1
- # align left
- # else:
- x, y = rect.x + 3, rect.y - 1
- w, h = wWin, rect.height + 2
- else: # choice || auto-rendering
- x, y = rect.x, rect.y - 1
- w, h = rect.width, rect.height + 2
- if idx == 2: # mask
- x += 5
- y += 4
- elif idx == 3: # render
- x += 5
-
- win.SetPosition((x, y))
- win.SetSize((w, h))
-
- def SaveToFile(self, event):
- """
- Save image to file
- """
- filetype = "PNG file (*.png)|*.png|"\
- "TIF file (*.tif)|*.tif|"\
- "GIF file (*.gif)|*.gif"
-
- dlg = wx.FileDialog(self, "Choose a file name to save the image as a PNG to",
- defaultDir = "",
- defaultFile = "",
- wildcard = filetype,
- style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
- if dlg.ShowModal() == wx.ID_OK:
- base = os.path.splitext(dlg.GetPath())[0]
- ext = os.path.splitext(dlg.GetPath())[1]
- if dlg.GetFilterIndex() == 0:
- type = wx.BITMAP_TYPE_PNG
- path = dlg.GetPath()
- if ext != '.png': path = base+'.png'
- elif dlg.GetFilterIndex() == 1:
- type = wx.BITMAP_TYPE_TIF
- if ext != '.tif': path = base+'.tif'
- elif dlg.GetFilterIndex() == 2:
- type = wx.BITMAP_TYPE_TIF
- if ext != '.gif': path = base+'.gif'
- self.MapWindow.SaveToFile(path, type)
-
- dlg.Destroy()
-
- def PrintMenu(self, event):
- """
- Print options and output menu for map display
- """
- point = wx.GetMousePosition()
- printmenu = wx.Menu()
- # Add items to the menu
- setup = wx.MenuItem(printmenu, wx.ID_ANY, _('Page setup'))
- printmenu.AppendItem(setup)
- self.Bind(wx.EVT_MENU, self.printopt.OnPageSetup, setup)
-
- preview = wx.MenuItem(printmenu, wx.ID_ANY, _('Print preview'))
- printmenu.AppendItem(preview)
- self.Bind(wx.EVT_MENU, self.printopt.OnPrintPreview, preview)
-
- doprint = wx.MenuItem(printmenu, wx.ID_ANY, _('Print display'))
- printmenu.AppendItem(doprint)
- self.Bind(wx.EVT_MENU, self.printopt.OnDoPrint, doprint)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(printmenu)
- printmenu.Destroy()
-
- def OnCloseWindow(self, event):
- """
- Window closed.
- Also close associated layer tree page
- """
- pgnum = None
- self.Map.Clean()
-
- # close edited map and 3D tools properly
- if self.toolbars['vdigit']:
- maplayer = self.toolbars['vdigit'].GetLayer()
- if maplayer:
- self.toolbars['vdigit'].OnExit()
- self.imgVectorMap = None
-
- if self.toolbars['nviz']:
- self.toolbars['nviz'].OnExit()
-
- if self.page:
- pgnum = self.layerbook.GetPageIndex(self.page)
- if pgnum > -1:
- self.layerbook.DeletePage(pgnum)
-
- ### self.Destroy()
- # if event:
- # event.Skip() <- causes application crash
-
- def GetRender(self):
- """
- Returns the current instance of render.Map()
- """
- return self.Map
-
- def OnQueryDisplay(self, event):
- """
- Query currrent raster/vector map layers (display mode)
- """
- if self.toolbars['map'].GetAction() == 'displayAttrb': # select previous action
- self.toolbars['map'].SelectDefault(event)
- return
-
- self.toolbars['map'].action['desc'] = 'displayAttrb'
-
- # switch GIS Manager to output console to show query results
- self.gismanager.notebook.SetSelection(1)
-
- self.MapWindow.mouse['use'] = "query"
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def OnQueryModify(self, event):
- """
- Query vector map layer (edit mode)
- """
- if self.toolbars['map'].GetAction() == 'modifyAttrb': # select previous action
- self.toolbars['map'].SelectDefault(event)
- return
-
- self.toolbars['map'].action['desc'] = 'modifyAttrb'
-
- self.MapWindow.mouse['use'] = "queryVector"
- self.MapWindow.mouse['box'] = "point"
- self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
- self.MapWindow.zoomtype = 0
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["cross"])
-
- def QueryMap(self, x, y):
- """!Query map layer features
-
- Currently only raster and vector map layers are supported.
-
- @param x,y coordinates
- """
- #set query snap distance for v.what at mapunit equivalent of 10 pixels
- qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / self.Map.width)
- east, north = self.MapWindow.Pixel2Cell((x, y))
-
- num = 0
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- if type in ('raster', 'rgb', 'his',
- 'vector', 'thememap', 'themechart'):
- num += 1
-
- if num < 1:
- dlg = wx.MessageDialog(parent=self,
- message=_('No raster or vector map layer selected for querying.'),
- caption=_('No map layer selected'),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- dlg.ShowModal()
- dlg.Destroy()
- return
-
- mapname = None
- raststr = ''
- vectstr = ''
- rcmd = []
- vcmd = []
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- dcmd = self.tree.GetPyData(layer)[0]['cmd']
- name = utils.GetLayerNameFromCmd(dcmd)
- if name == '':
- continue
- if type in ('raster', 'rgb', 'his'):
- raststr += "%s," % name
- elif type in ('vector', 'thememap', 'themechart'):
- vectstr += "%s," % name
-
- # use display region settings instead of computation region settings
- self.tmpreg = os.getenv("GRASS_REGION")
- os.environ["GRASS_REGION"] = self.Map.SetRegion(windres=False)
-
- # build query commands for any selected rasters and vectors
- if raststr != '':
- rcmd = ['r.what', '--q',
- '-f',
- 'input=%s' % raststr.rstrip(','),
- 'east_north=%f,%f' % (float(east), float(north))]
-
- if vectstr != '':
- # check for vector maps open to be edited
- digitToolbar = self.toolbars['vdigit']
- if digitToolbar:
- map = digitToolbar.GetLayer().GetName()
- vect = []
- for vector in vectstr.split(','):
- if map == vector:
- self.gismanager.goutput.WriteWarning("Vector map <%s> "
- "opened for editing - skipped." % map)
- continue
- vect.append(vector)
- vectstr = ','.join(vect)
-
- if len(vectstr) <= 1:
- self.gismanager.goutput.WriteCmdLog("Nothing to query.")
- return
-
- vcmd = ['v.what', '--q',
- '-a',
- 'map=%s' % vectstr.rstrip(','),
- 'east_north=%f,%f' % (float(east), float(north)),
- 'distance=%f' % qdist]
-
- # parse query command(s)
- if self.gismanager:
- if rcmd:
- self.gismanager.goutput.RunCmd(rcmd, compReg=False,
- onDone = self._QueryMapDone)
- if vcmd:
- self.gismanager.goutput.RunCmd(vcmd,
- onDone = self._QueryMapDone)
- else:
- if rcmd:
- gcmd.Command(rcmd)
- if vcmd:
- gcmd.Command(vcmd)
-
- def _QueryMapDone(self, returncode):
- """!Restore settings after querying (restore GRASS_REGION)
-
- @param returncode command return code
- """
- if hasattr(self, "tmpreg"):
- if self.tmpreg:
- os.environ["GRASS_REGION"] = self.tmpreg
- elif os.environ.has_key('GRASS_REGION'):
- del os.environ["GRASS_REGION"]
- elif os.environ.has_key('GRASS_REGION'):
- del os.environ["GRASS_REGION"]
-
- if hasattr(self, "tmpreg"):
- del self.tmpreg
-
- def QueryVector(self, x, y):
- """
- Query vector map layer features
-
- Attribute data of selected vector object are displayed in GUI dialog.
- Data can be modified (On Submit)
- """
- if not self.tree.layer_selected or \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] != 'vector':
- wx.MessageBox(parent=self,
- message=_("No vector map selected for querying."),
- caption=_("Vector querying"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- return
-
- if self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetMapset() != \
- grass.gisenv()['MAPSET']:
- wx.MessageBox(parent=self,
- message=_("Only vector map from the current mapset can be modified."),
- caption=_("Vector querying"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- return
-
- posWindow = self.ClientToScreen((x + self.MapWindow.dialogOffset,
- y + self.MapWindow.dialogOffset))
-
- qdist = 10.0 * ((self.Map.region['e'] - self.Map.region['w']) / \
- self.Map.width)
- east, north = self.MapWindow.Pixel2Cell((x, y))
-
- mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
-
- if self.dialogs['attributes'] is None:
- self.dialogs['attributes'] = dbm.DisplayAttributesDialog(parent=self.MapWindow,
- map=mapName,
- query=((east, north), qdist),
- pos=posWindow,
- action="update")
- else:
- # selection changed?
- if not self.dialogs['attributes'].mapDBInfo or \
- self.dialogs['attributes'].mapDBInfo.map != mapName:
- self.dialogs['attributes'].UpdateDialog(map=mapName, query=((east, north), qdist))
- else:
- self.dialogs['attributes'].UpdateDialog(query=((east, north), qdist))
-
- cats = self.dialogs['attributes'].GetCats()
- try:
- qlayer = self.Map.GetListOfLayers(l_name=globalvar.QUERYLAYER)[0]
- except IndexError:
- qlayer = None
-
- if self.dialogs['attributes'].mapDBInfo and cats:
- # highlight feature & re-draw map
- if qlayer:
- qlayer.SetCmd(self.AddTmpVectorMapLayer(mapName, cats,
- useId=False,
- addLayer=False))
- else:
- qlayer = self.AddTmpVectorMapLayer(mapName, cats, useId=False)
-
- # set opacity based on queried layer
- opacity = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].GetOpacity(float=True)
- qlayer.SetOpacity(opacity)
-
- self.MapWindow.UpdateMap(render=False, renderVector=False)
- if not self.dialogs['attributes'].IsShown():
- self.dialogs['attributes'].Show()
- else:
- if qlayer:
- self.Map.DeleteLayer(qlayer)
- self.MapWindow.UpdateMap(render=False, renderVector=False)
- if self.dialogs['attributes'].IsShown():
- self.dialogs['attributes'].Hide()
-
- def OnQuery(self, event):
- """Query tools menu"""
- if self.toolbars['map']:
- self.toolbars['map'].OnTool(event)
- action = self.toolbars['map'].GetAction()
-
- point = wx.GetMousePosition()
- toolsmenu = wx.Menu()
- # Add items to the menu
- display = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
- text=_("Query raster/vector map(s) (display mode)"),
- kind=wx.ITEM_CHECK)
- toolsmenu.AppendItem(display)
- self.Bind(wx.EVT_MENU, self.OnQueryDisplay, display)
- numLayers = 0
- for layer in self.tree.GetSelections():
- type = self.tree.GetPyData(layer)[0]['maplayer'].GetType()
- if type in ('raster', 'rgb', 'his',
- 'vector', 'thememap', 'themechart'):
- numLayers += 1
- if numLayers < 1:
- display.Enable(False)
-
- if action == "displayAttrb":
- display.Check(True)
-
- modify = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
- text=_("Query vector map (edit mode)"),
- kind=wx.ITEM_CHECK)
- toolsmenu.AppendItem(modify)
- self.Bind(wx.EVT_MENU, self.OnQueryModify, modify)
- digitToolbar = self.toolbars['vdigit']
- if self.tree.layer_selected:
- layer_selected = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer']
- if layer_selected.GetType() != 'vector' or \
- (digitToolbar and \
- digitToolbar.GetLayer() == layer_selected):
- modify.Enable(False)
- else:
- if action == "modifyAttrb":
- modify.Check(True)
-
- self.PopupMenu(toolsmenu)
- toolsmenu.Destroy()
-
- def AddTmpVectorMapLayer(self, name, cats, useId=False, addLayer=True):
- """
- Add temporal vector map layer to map composition
-
- @param name name of map layer
- @param useId use feature id instead of category
- """
- # color settings from ATM
- color = UserSettings.Get(group='atm', key='highlight', subkey='color')
- colorStr = str(color[0]) + ":" + \
- str(color[1]) + ":" + \
- str(color[2])
-
- pattern = ["d.vect",
- "map=%s" % name,
- "color=%s" % colorStr,
- "fcolor=%s" % colorStr,
- "width=%d" % UserSettings.Get(group='atm', key='highlight', subkey='width')]
-
- if useId:
- cmd = pattern
- cmd.append('-i')
- cmd.append('cats=%s' % str(cats))
- else:
- cmd = []
- for layer in cats.keys():
- cmd.append(copy.copy(pattern))
- lcats = cats[layer]
- cmd[-1].append("layer=%d" % layer)
- cmd[-1].append("cats=%s" % utils.ListOfCatsToRange(lcats))
-
- # if self.icon:
- # cmd.append("icon=%s" % (self.icon))
- # if self.pointsize:
- # cmd.append("size=%s" % (self.pointsize))
-
- if addLayer:
- if useId:
- return self.Map.AddLayer(type='vector', name=globalvar.QUERYLAYER, command=cmd,
- l_active=True, l_hidden=True, l_opacity=1.0)
- else:
- return self.Map.AddLayer(type='command', name=globalvar.QUERYLAYER, command=cmd,
- l_active=True, l_hidden=True, l_opacity=1.0)
- else:
- return cmd
-
- def OnAnalyze(self, event):
- """
- Analysis tools menu
- """
- point = wx.GetMousePosition()
- toolsmenu = wx.Menu()
- # Add items to the menu
- measure = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["measure"].GetLabel())
- measure.SetBitmap(Icons["measure"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(measure)
- self.Bind(wx.EVT_MENU, self.OnMeasure, measure)
-
- profile = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["profile"].GetLabel())
- profile.SetBitmap(Icons["profile"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(profile)
- self.Bind(wx.EVT_MENU, self.Profile, profile)
-
- histogram = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["histogram"].GetLabel())
- histogram.SetBitmap(Icons["histogram"].GetBitmap(self.iconsize))
- toolsmenu.AppendItem(histogram)
- self.Bind(wx.EVT_MENU, self.Histogram, histogram)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(toolsmenu)
- toolsmenu.Destroy()
-
- def OnMeasure(self, event):
- """
- Init measurement routine that calculates
- map distance along transect drawn on
- map display
- """
-
- self.totaldist = 0.0 # total measured distance
-
- # switch GIS Manager to output console to show measure results
- self.gismanager.notebook.SetSelection(1)
-
- # change mouse to draw line for measurement
- self.MapWindow.mouse['use'] = "measure"
- self.MapWindow.mouse['box'] = "line"
- self.MapWindow.zoomtype = 0
- self.MapWindow.pen = wx.Pen(colour='red', width=2, style=wx.SHORT_DASH)
- self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SHORT_DASH)
-
- # change the cursor
- self.MapWindow.SetCursor(self.cursors["pencil"])
-
- # initiating output
- style = self.gismanager.goutput.cmd_output.StyleWarning
- self.gismanager.goutput.WriteLog(_('Click and drag with left mouse button '
- 'to measure.%s'
- 'Double click with left button to clear.') % \
- (os.linesep), style)
- if self.Map.projinfo['proj'] != 'xy':
- units = self.Map.projinfo['units']
- style = self.gismanager.goutput.cmd_output.StyleCommand
- self.gismanager.goutput.WriteLog(_('Measuring distance') + ' ('
- + units + '):',
- style)
- else:
- self.gismanager.goutput.WriteLog(_('Measuring distance:'),
- style)
-
- def MeasureDist(self, beginpt, endpt):
- """
- Calculate map distance from screen distance
- and print to output window
- """
-
- if self.gismanager.notebook.GetSelection() != 1:
- self.gismanager.notebook.SetSelection(1)
-
- dist, (north, east) = self.MapWindow.Distance(beginpt, endpt)
-
- dist = round(dist, 3)
- d, dunits = self.FormatDist(dist)
-
- self.totaldist += dist
- td, tdunits = self.FormatDist(self.totaldist)
-
- strdist = str(d)
- strtotdist = str(td)
-
- if self.Map.projinfo['proj'] == 'xy' or 'degree' not in self.Map.projinfo['unit']:
- angle = int(math.degrees(math.atan2(north,east)) + 0.5)
- angle = 180 - angle
- if angle < 0:
- angle = 360+angle
-
- mstring = 'segment = %s %s\ttotal distance = %s %s\tbearing = %d deg' \
- % (strdist,dunits,strtotdist,tdunits,angle)
- else:
- mstring = 'segment = %s %s\ttotal distance = %s %s' \
- % (strdist,dunits,strtotdist,tdunits)
-
- self.gismanager.goutput.WriteLog(mstring)
-
- return dist
-
- def Profile(self, event):
- """
- Init profile canvas and tools
- """
- raster = []
- if self.tree.layer_selected and \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
- raster.append(self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
-
- self.profile = profile.ProfileFrame(self,
- id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
- style=wx.DEFAULT_FRAME_STYLE, rasterList=raster)
- self.profile.Show()
- # Open raster select dialog to make sure that a raster (and the desired raster)
- # is selected to be profiled
- self.profile.OnSelectRaster(None)
-
- def FormatDist(self, dist):
- """Format length numbers and units in a nice way,
- as a function of length. From code by Hamish Bowman
- Grass Development Team 2006"""
-
- mapunits = self.Map.projinfo['units']
- if mapunits == 'metres': mapunits = 'meters'
- outunits = mapunits
- dist = float(dist)
- divisor = 1.0
-
- # figure out which units to use
- if mapunits == 'meters':
- if dist > 2500.0:
- outunits = 'km'
- divisor = 1000.0
- else: outunits = 'm'
- elif mapunits == 'feet':
- # nano-bug: we match any "feet", but US Survey feet is really
- # 5279.9894 per statute mile, or 10.6' per 1000 miles. As >1000
- # miles the tick markers are rounded to the nearest 10th of a
- # mile (528'), the difference in foot flavours is ignored.
- if dist > 5280.0:
- outunits = 'miles'
- divisor = 5280.0
- else:
- outunits = 'ft'
- elif 'degree' in mapunits:
- if dist < 1:
- outunits = 'min'
- divisor = (1/60.0)
- else:
- outunits = 'deg'
-
- # format numbers in a nice way
- if (dist/divisor) >= 2500.0:
- outdist = round(dist/divisor)
- elif (dist/divisor) >= 1000.0:
- outdist = round(dist/divisor,1)
- elif (dist/divisor) > 0.0:
- outdist = round(dist/divisor,int(math.ceil(3-math.log10(dist/divisor))))
- else:
- outdist = float(dist/divisor)
-
- return (outdist, outunits)
-
-
- def Histogram(self, event):
- """
- Init histogram display canvas and tools
- """
- self.histogram = histogram.HistFrame(self,
- id=wx.ID_ANY, size=globalvar.HIST_WINDOW_SIZE,
- style=wx.DEFAULT_FRAME_STYLE)
-
- #show new display
- self.histogram.Show()
- self.histogram.Refresh()
- self.histogram.Update()
-
-
- def OnDecoration(self, event):
- """
- Decorations overlay menu
- """
- point = wx.GetMousePosition()
- decmenu = wx.Menu()
- # Add items to the menu
- AddScale = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addbarscale"].GetLabel())
- AddScale.SetBitmap(Icons["addbarscale"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddScale)
- self.Bind(wx.EVT_MENU, self.OnAddBarscale, AddScale)
-
- AddLegend = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addlegend"].GetLabel())
- AddLegend.SetBitmap(Icons["addlegend"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddLegend)
- self.Bind(wx.EVT_MENU, self.OnAddLegend, AddLegend)
-
- AddText = wx.MenuItem(decmenu, wx.ID_ANY, Icons["addtext"].GetLabel())
- AddText.SetBitmap(Icons["addtext"].GetBitmap(self.iconsize))
- decmenu.AppendItem(AddText)
- self.Bind(wx.EVT_MENU, self.OnAddText, AddText)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(decmenu)
- decmenu.Destroy()
-
- def OnAddBarscale(self, event):
- """
- Handler for scale/arrow map decoration menu selection.
- """
- if self.dialogs['barscale']:
- return
-
- id = 0 # unique index for overlay layer
-
- # If location is latlon, only display north arrow (scale won't work)
- # proj = self.Map.projinfo['proj']
- # if proj == 'll':
- # barcmd = 'd.barscale -n'
- # else:
- # barcmd = 'd.barscale'
-
- # decoration overlay control dialog
- self.dialogs['barscale'] = \
- gdialogs.DecorationDialog(parent=self, title=_('Scale and North arrow'),
- size=(350, 200),
- style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE,
- cmd=['d.barscale', 'at=0,5'],
- ovlId=id,
- name='barscale',
- checktxt = _("Show/hide scale and North arrow"),
- ctrltxt = _("scale object"))
-
- self.dialogs['barscale'].CentreOnParent()
- ### dialog cannot be show as modal - in the result d.barscale is not selectable
- ### self.dialogs['barscale'].ShowModal()
- self.dialogs['barscale'].Show()
- self.MapWindow.mouse['use'] = 'pointer'
-
- def OnAddLegend(self, event):
- """
- Handler for legend map decoration menu selection.
- """
- if self.dialogs['legend']:
- return
-
- id = 1 # index for overlay layer in render
-
- cmd = ['d.legend', 'at=5,50,2,5']
- if self.tree.layer_selected and \
- self.tree.GetPyData(self.tree.layer_selected)[0]['type'] == 'raster':
- cmd.append('map=%s' % self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name)
-
- # Decoration overlay control dialog
- self.dialogs['legend'] = \
- gdialogs.DecorationDialog(parent=self, title=('Legend'),
- size=(350, 200),
- style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE,
- cmd=cmd,
- ovlId=id,
- name='legend',
- checktxt = _("Show/hide legend"),
- ctrltxt = _("legend object"))
-
- self.dialogs['legend'].CentreOnParent()
- ### dialog cannot be show as modal - in the result d.legend is not selectable
- ### self.dialogs['legend'].ShowModal()
- self.dialogs['legend'].Show()
- self.MapWindow.mouse['use'] = 'pointer'
-
- def OnAddText(self, event):
- """
- Handler for text decoration menu selection.
- """
- if self.MapWindow.dragid > -1:
- id = self.MapWindow.dragid
- else:
- # index for overlay layer in render
- if len(self.MapWindow.textdict.keys()) > 0:
- id = self.MapWindow.textdict.keys()[-1] + 1
- else:
- id = 101
-
- self.dialogs['text'] = gdialogs.TextLayerDialog(parent=self, ovlId=id,
- title=_('Add text layer'),
- size=(400, 200))
- self.dialogs['text'].CenterOnParent()
-
- # If OK button pressed in decoration control dialog
- 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)
- del self.MapWindow.textdict[id]
- except:
- pass
- return
-
- self.MapWindow.pdc.ClearId(id)
- self.MapWindow.pdc.SetId(id)
- self.MapWindow.textdict[id] = self.dialogs['text'].GetValues()
-
- self.MapWindow.Draw(self.MapWindow.pdcDec, img=self.MapWindow.textdict[id],
- drawid=id, pdctype='text', coords=coords)
-
- self.MapWindow.UpdateMap(render=False, renderVector=False)
-
- self.MapWindow.mouse['use'] = 'pointer'
-
- def GetOptData(self, dcmd, type, params, propwin):
- """
- Callback method for decoration overlay command generated by
- dialog created in menuform.py
- """
- # Reset comand and rendering options in render.Map. Always render decoration.
- # Showing/hiding handled by PseudoDC
- self.Map.ChangeOverlay(ovltype=type, type='overlay', name='', command=dcmd,
- l_active=True, l_render=False)
- self.params[type] = params
- self.propwin[type] = propwin
-
- def OnZoomMenu(self, event):
- """
- Zoom menu
- """
- point = wx.GetMousePosition()
- zoommenu = wx.Menu()
- # Add items to the menu
- zoommap = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to selected map(s)'))
- zoommenu.AppendItem(zoommap)
- self.Bind(wx.EVT_MENU, self.MapWindow.OnZoomToMap, zoommap)
-
- zoomwind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to computational region (set with g.region)'))
- zoommenu.AppendItem(zoomwind)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToWind, zoomwind)
-
- zoomdefault = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to default region'))
- zoommenu.AppendItem(zoomdefault)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToDefault, zoomdefault)
-
- zoomsaved = wx.MenuItem(zoommenu, wx.ID_ANY, _('Zoom to saved region'))
- zoommenu.AppendItem(zoomsaved)
- self.Bind(wx.EVT_MENU, self.MapWindow.ZoomToSaved, zoomsaved)
-
- savewind = wx.MenuItem(zoommenu, wx.ID_ANY, _('Set computational region from display'))
- zoommenu.AppendItem(savewind)
- self.Bind(wx.EVT_MENU, self.MapWindow.DisplayToWind, savewind)
-
- savezoom = wx.MenuItem(zoommenu, wx.ID_ANY, _('Save display geometry to named region'))
- zoommenu.AppendItem(savezoom)
- self.Bind(wx.EVT_MENU, self.MapWindow.SaveDisplayRegion, savezoom)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.PopupMenu(zoommenu)
- zoommenu.Destroy()
-
- def SetProperties(self, render=False, mode=0, showCompExtent=False,
- constrainRes=False):
- """Set properies of map display window"""
- self.autoRender.SetValue(render)
- self.toggleStatus.SetSelection(mode)
- self.StatusbarUpdate()
- self.showRegion.SetValue(showCompExtent)
- self.compResolution.SetValue(constrainRes)
- if showCompExtent:
- self.MapWindow.regionCoords = []
-
- def IsStandalone(self):
- """!Check if Map display is standalone"""
- if self.gismanager:
- return False
-
- return True
-
- def GetLayerManager(self):
- """!Get reference to Layer Manager
-
- @return window reference
- @return None (if standalone)
- """
- return self.gismanager
-
-# end of class MapFrame
-
-class MapApp(wx.App):
- """
- MapApp class
- """
-
- def OnInit(self):
- wx.InitAllImageHandlers()
- if __name__ == "__main__":
- Map = render.Map() # instance of Map class to render GRASS display output to PPM file
- else:
- Map = None
-
- self.mapFrm = MapFrame(parent=None, id=wx.ID_ANY, Map=Map, size=(640,480))
- #self.SetTopWindow(Map)
- self.mapFrm.Show()
-
- if __name__ == "__main__":
- # redraw map, if new command appears
- self.redraw = False
- status = Command(self, Map)
- status.start()
- self.timer = wx.PyTimer(self.watcher)
- # check each 0.1s
- self.timer.Start(100)
-
- return 1
-
- def OnExit(self):
- if __name__ == "__main__":
- # stop the timer
- self.timer.Stop()
- # terminate thread (a bit ugly)
- os.system("""echo "quit" >> %s""" % (cmdfilename))
-
- def watcher(self):
- """Redraw, if new layer appears"""
- if self.redraw:
- self.mapFrm.OnDraw(None)
- self.redraw = False
- return
-# end of class MapApp
-
-
-
-
-if __name__ == "__main__":
-
- ###### SET command variable
- if len(sys.argv) != 3:
- print __doc__
- sys.exit()
-
- title = sys.argv[1]
- cmdfilename = sys.argv[2]
-
- import gettext
- gettext.install("gm_map") # replace with the appropriate catalog name
-
- print "Starting monitor <%s>" % (title)
-
- gm_map = MapApp(0)
- # set title
- gm_map.mapFrm.SetTitle ("GRASS GIS - Map Display: " + title + " - Location: " + \
- grass.gisenv()['LOCATION_NAME'])
- gm_map.MainLoop()
-
- if grass.gisenv().has_key("MONITOR"):
- os.system("d.mon sel=%s" % grass.gisenv()["MONITOR"])
-
- os.remove(cmdfilename)
- os.system("""g.gisenv set="GRASS_PYCMDFILE" """)
-
- print "Stoping monitor <%s>" % (title)
-
- sys.exit()
Deleted: grass-addons/gui/wxpython/data_catalog/mapwindow.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/mapwindow.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/mapwindow.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,2773 +0,0 @@
-"""!
- at package mapdisp_window.py
-
- at brief GIS map display canvas, buffered window.
-
-Classes:
- - MapWindow
- - BufferedWindow
-
-(C) 2006-2009 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 Michael Barton
- at author Jachym Cepicky
- at author Martin Landa <landa.martin gmail.com>
-
-"""
-
-import os
-import time
-import math
-import sys
-import tempfile
-
-gbase = os.getenv("GISBASE")
-pypath = os.path.join(gbase,'etc','wxpython','gui_modules')
-sys.path.append(pypath)
-
-import globalvar
-if not os.getenv("GRASS_WXBUNDLED"):
- globalvar.CheckForWx()
-
-import wx
-
-import grass.script as grass
-
-import dbm
-
-
-import dbm_dialogs
-import gdialogs
-import gcmd
-import utils
-import globalvar
-import gselect
-from debug import Debug
-from preferences import globalSettings as UserSettings
-from units import ConvertValue as UnitsConvertValue
-from vdigit import GV_LINES as VDigit_Lines_Type
-from vdigit import VDigitCategoryDialog
-from vdigit import VDigitZBulkDialog
-from vdigit import VDigitDuplicatesDialog
-from vdigit import PseudoDC as VDigitPseudoDC
-
-class MapWindow(object):
- """!
- Abstract map window class
-
- Parent for BufferedWindow class (2D display mode) and
- GLWindow (3D display mode)
- """
- def __init__(self, parent, id=wx.ID_ANY,
- pos=wx.DefaultPosition,
- size=wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, lmgr=None):
- self.parent = parent # MapFrame
-
- #
- # mouse attributes -- position on the screen, begin and end of
- # dragging, and type of drawing
- #
- self.mouse = {
- 'begin': [0, 0], # screen coordinates
- 'end' : [0, 0],
- 'use' : "pointer",
- 'box' : "point"
- }
-
- def EraseMap(self):
- """!
- Erase the canvas (virtual method)
- """
- pass
-
- def UpdateMap(self):
- """!
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
- """
- pass
-
- def OnLeftDown(self, event):
- pass
-
- def OnLeftUp(self, event):
- pass
-
- def OnMouseMotion(self, event):
- pass
-
- def OnZoomToMap(self, event):
- pass
-
- def OnZoomToRaster(self, event):
- pass
-
- def GetSelectedLayer(self, type = 'layer', multi = False):
- """!
- Get selected layer from layer tree
-
- @param type 'item' / 'layer' / 'nviz'
- @param multi return first selected layer or all
-
- @return layer / map layer properties / nviz properties
- @return None / [] on failure
- """
- ret = []
- if not self.tree or \
- not self.tree.GetSelection():
- if multi:
- return []
- else:
- return None
-
- if multi and \
- type == 'item':
- return self.tree.GetSelections()
-
- for item in self.tree.GetSelections():
- if not item.IsChecked():
- if multi:
- continue
- else:
- return None
-
- if type == 'item': # -> multi = False
- return item
-
- try:
- if type == 'nviz':
- layer = self.tree.GetPyData(item)[0]['nviz']
- else:
- layer = self.tree.GetPyData(item)[0]['maplayer']
- except:
- layer = None
-
- if multi:
- ret.append(layer)
- else:
- return layer
-
- return ret
-
-class BufferedWindow(MapWindow, wx.Window):
- """!
- A Buffered window class.
-
- When the drawing needs to change, you app needs to call the
- UpdateMap() method. Since the drawing is stored in a bitmap, you
- can also save the drawing to file by calling the
- SaveToFile(self,file_name,file_type) method.
- """
-
- def __init__(self, parent, id,
- pos = wx.DefaultPosition,
- size = wx.DefaultSize,
- style=wx.NO_FULL_REPAINT_ON_RESIZE,
- Map=None, tree=None, lmgr=None):
-
- MapWindow.__init__(self, parent, id, pos, size, style,
- Map, tree, lmgr)
- wx.Window.__init__(self, parent, id, pos, size, style)
-
- self.Map = Map
- self.tree = tree
- self.lmgr = lmgr # Layer Manager
-
- #
- # Flags
- #
- self.resize = False # indicates whether or not a resize event has taken place
- self.dragimg = None # initialize variable for map panning
-
- #
- # Variable for drawing on DC
- #
- self.pen = None # pen for drawing zoom boxes, etc.
- self.polypen = None # pen for drawing polylines (measurements, profiles, etc)
- # List of wx.Point tuples defining a polyline (geographical coordinates)
- self.polycoords = []
- # ID of rubber band line
- self.lineid = None
- # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
- self.plineid = None
-
- #
- # Event bindings
- #
-
- self.Bind(wx.EVT_PAINT, self.OnPaint)
-
- #self.Bind(wx.EVT_SIZE, self.OnSize)
- self.Bind(wx.EVT_IDLE, self.OnIdle)
- self.Bind(wx.EVT_MOTION, self.MouseActions)
- self.Bind(wx.EVT_MOUSE_EVENTS, self.MouseActions)
- self.processMouse = True
-
- #
- # Render output objects
- #
- self.mapfile = None # image file to be rendered
- self.img = "" # wx.Image object (self.mapfile)
- # used in digitization tool (do not redraw vector map)
- self.imgVectorMap = None
- # decoration overlays
- self.overlays = {}
- # images and their PseudoDC ID's for painting and dragging
- self.imagedict = {}
- self.select = {} # selecting/unselecting decorations for dragging
- self.textdict = {} # text, font, and color indexed by id
- self.currtxtid = None # PseudoDC id for currently selected text
-
- #
- # Zoom objects
- #
- self.zoomhistory = [] # list of past zoom extents
- self.currzoom = 0 # current set of extents in zoom history being used
-
- self.zoomtype = 1 # 1 zoom in, 0 no zoom, -1 zoom out
- self.hitradius = 10 # distance for selecting map decorations
- self.dialogOffset = 5 # offset for dialog (e.g. DisplayAttributesDialog)
-
- # OnSize called to make sure the buffer is initialized.
- # This might result in OnSize getting called twice on some
- # platforms at initialization, but little harm done.
- ### self.OnSize(None)
-
- self.DefinePseudoDC()
- # redraw all pdc's, pdcTmp layer is redrawn always (speed issue)
- self.redrawAll = True
-
- # will store an off screen empty bitmap for saving to file
- self._buffer = ''
-
- self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x:None)
-
- # vars for handling mouse clicks
- self.dragid = -1
- self.lastpos = (0, 0)
-
- def DefinePseudoDC(self, vdigit = False):
- """!Define PseudoDC class to use
-
- @vdigit True to use PseudoDC from vdigit
- """
- # create PseudoDC used for background map, map decorations like scales and legends
- self.pdc = self.PseudoDC(vdigit)
- # used for digitization tool
- self.pdcVector = None
- # decorations (region box, etc.)
- self.pdcDec = self.PseudoDC(vdigit)
- # pseudoDC for temporal objects (select box, measurement tool, etc.)
- self.pdcTmp = self.PseudoDC(vdigit)
-
- def PseudoDC(self, vdigit = False):
- """!Create PseudoDC instance"""
- if vdigit:
- PseudoDC = VDigitPseudoDC
- else:
- PseudoDC = wx.PseudoDC
-
- return PseudoDC()
-
- def CheckPseudoDC(self):
- """!Try to draw background
-
- @return True on success
- @return False on failure
- """
- try:
- self.pdc.BeginDrawing()
- self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- self.pdc.BeginDrawing()
- except:
- return False
-
- return True
-
- def Draw(self, pdc, img=None, drawid=None, pdctype='image', coords=[0, 0, 0, 0]):
- """!
- Draws map and overlay decorations
- """
- if drawid == None:
- if pdctype == 'image' and img:
- drawid = self.imagedict[img]
- elif pdctype == 'clear':
- drawid == None
- else:
- drawid = wx.NewId()
-
- if img and pdctype == 'image':
- # self.imagedict[img]['coords'] = coords
- self.select[self.imagedict[img]['id']] = False # ?
-
- pdc.BeginDrawing()
-
- if drawid != 99:
- bg = wx.TRANSPARENT_BRUSH
- else:
- bg = wx.Brush(self.GetBackgroundColour())
-
- pdc.SetBackground(bg)
-
- ### pdc.Clear()
-
- Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \
- (drawid, pdctype, coords))
-
- # set PseudoDC id
- if drawid is not None:
- pdc.SetId(drawid)
-
- if pdctype == 'clear': # erase the display
- bg = wx.WHITE_BRUSH
- # bg = wx.Brush(self.GetBackgroundColour())
- pdc.SetBackground(bg)
- pdc.RemoveAll()
- pdc.Clear()
- pdc.EndDrawing()
-
- self.Refresh()
- return
-
- if pdctype == 'image': # draw selected image
- bitmap = wx.BitmapFromImage(img)
- w,h = bitmap.GetSize()
- pdc.DrawBitmap(bitmap, coords[0], coords[1], True) # draw the composite map
- pdc.SetIdBounds(drawid, wx.Rect(coords[0],coords[1], w, h))
-
- elif pdctype == 'box': # draw a box on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- x2 = max(coords[0],coords[2])
- x1 = min(coords[0],coords[2])
- y2 = max(coords[1],coords[3])
- y1 = min(coords[1],coords[3])
- rwidth = x2-x1
- rheight = y2-y1
- rect = wx.Rect(x1, y1, rwidth, rheight)
- pdc.DrawRectangleRect(rect)
- pdc.SetIdBounds(drawid, rect)
-
- elif pdctype == 'line': # draw a line on top of the map
- if self.pen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.pen)
- pdc.DrawLine(wx.Point(coords[0], coords[1]),
- wx.Point(coords[2], coords[3]))
- pdc.SetIdBounds(drawid, wx.Rect(coords[0], coords[1], coords[2], coords[3]))
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'polyline': # draw a polyline on top of the map
- if self.polypen:
- pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
- pdc.SetPen(self.polypen)
- ### pdc.DrawLines(coords)
- if (len(coords) < 2):
- return
- i = 1
- while i < len(coords):
- pdc.DrawLinePoint(wx.Point(coords[i-1][0], coords[i-1][1]),
- wx.Point(coords[i][0], coords[i][1]))
- i += 1
-
- # get bounding rectangle for polyline
- xlist = []
- ylist = []
- if len(coords) > 0:
- for point in coords:
- x,y = point
- xlist.append(x)
- ylist.append(y)
- x1=min(xlist)
- x2=max(xlist)
- y1=min(ylist)
- y2=max(ylist)
- pdc.SetIdBounds(drawid, wx.Rect(x1,y1,x2,y2))
- # self.ovlcoords[drawid] = [x1,y1,x2,y2]
-
- elif pdctype == 'point': # draw point
- if self.pen:
- pdc.SetPen(self.pen)
- pdc.DrawPoint(coords[0], coords[1])
- coordsBound = (coords[0] - 5,
- coords[1] - 5,
- coords[0] + 5,
- coords[1] + 5)
- pdc.SetIdBounds(drawid, wx.Rect(coordsBound))
- # self.ovlcoords[drawid] = coords
-
- elif pdctype == 'text': # draw text on top of map
- if not img['active']:
- return #only draw active text
- if img.has_key('rotation'):
- rotation = float(img['rotation'])
- else:
- rotation = 0.0
- w, h = self.GetFullTextExtent(img['text'])[0:2]
- pdc.SetFont(img['font'])
- pdc.SetTextForeground(img['color'])
- coords, w, h = 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.EndDrawing()
-
- self.Refresh()
-
- return drawid
-
- def TextBounds(self, textinfo):
- """!
- Return text boundary data
-
- @param textinfo text metadata (text, font, color, rotation)
- @param coords reference point
- """
- if textinfo.has_key('rotation'):
- rotation = float(textinfo['rotation'])
- else:
- rotation = 0.0
-
- coords = textinfo['coords']
-
- Debug.msg (4, "BufferedWindow.TextBounds(): text=%s, rotation=%f" % \
- (textinfo['text'], rotation))
-
- self.Update()
- ### self.Refresh()
-
- self.SetFont(textinfo['font'])
-
- w, h = self.GetTextExtent(textinfo['text'])
-
- if rotation == 0:
- coords[2], coords[3] = coords[0] + w, coords[1] + h
- return coords, w, h
-
- 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
-
- def OnPaint(self, event):
- """!
- Draw PseudoDC's to buffered paint DC
-
- self.pdc for background and decorations
- self.pdcVector for vector map which is edited
- self.pdcTmp for temporaly drawn objects (self.polycoords)
-
- If self.redrawAll is False on self.pdcTmp content is re-drawn
- """
- Debug.msg(4, "BufferedWindow.OnPaint(): redrawAll=%s" % self.redrawAll)
-
- dc = wx.BufferedPaintDC(self, self.buffer)
-
- ### dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- # use PrepareDC to set position correctly
- self.PrepareDC(dc)
-
- # create a clipping rect from our position and size
- # and update region
- rgn = self.GetUpdateRegion().GetBox()
- dc.SetClippingRect(rgn)
-
- switchDraw = False
- if self.redrawAll is None:
- self.redrawAll = True
- switchDraw = True
-
- if self.redrawAll: # redraw pdc and pdcVector
- # draw to the dc using the calculated clipping rect
- self.pdc.DrawToDCClipped(dc, rgn)
-
- # draw vector map layer
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDCClipped(gcdc, rgn)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDCClipped(dc, rgn)
-
- self.bufferLast = None
- else: # do not redraw pdc and pdcVector
- if self.bufferLast is None:
- # draw to the dc
- self.pdc.DrawToDC(dc)
-
- if self.pdcVector:
- # decorate with GDDC (transparency)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcVector.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcVector.DrawToDC(dc)
-
- # store buffered image
- # self.bufferLast = wx.BitmapFromImage(self.buffer.ConvertToImage())
- self.bufferLast = dc.GetAsBitmap(wx.Rect(0, 0, self.Map.width, self.Map.height))
-
- pdcLast = self.PseudoDC(vdigit = False)
- pdcLast.DrawBitmap(self.bufferLast, 0, 0, False)
- pdcLast.DrawToDC(dc)
-
- # draw decorations (e.g. region box)
- try:
- gcdc = wx.GCDC(dc)
- self.pdcDec.DrawToDC(gcdc)
- except NotImplementedError, e:
- print >> sys.stderr, e
- self.pdcDec.DrawToDC(dc)
-
- # draw temporary object on the foreground
- ### self.pdcTmp.DrawToDCClipped(dc, rgn)
- self.pdcTmp.DrawToDC(dc)
-
- if switchDraw:
- self.redrawAll = False
-
- def OnSize(self, event):
- """!
- Scale map image so that it is
- the same size as the Window
- """
- Debug.msg(3, "BufferedWindow.OnSize():")
-
- # set size of the input image
- self.Map.ChangeMapSize(self.GetClientSize())
- # align extent based on center point and display resolution
- # this causes that image is not resized when display windows is resized
- # self.Map.AlignExtentFromDisplay()
-
- # Make new off screen bitmap: this bitmap will always have the
- # current drawing in it, so it can be used to save the image to
- # a file, or whatever.
- self.buffer = wx.EmptyBitmap(max(1, self.Map.width), max(1, self.Map.height))
-
- # get the image to be rendered
- self.img = self.GetImage()
-
- # update map display
- if self.img and self.Map.width + self.Map.height > 0: # scale image during resize
- self.img = self.img.Scale(self.Map.width, self.Map.height)
- if len(self.Map.GetListOfLayers()) > 0:
- self.UpdateMap()
-
- # re-render image on idle
- self.resize = True
-
- # reposition checkbox in statusbar
- #self.parent.StatusbarReposition()
-
- # update statusbar
- #self.parent.StatusbarUpdate()
-
- def OnIdle(self, event):
- """!
- Only re-render a composite map image from GRASS during
- idle time instead of multiple times during resizing.
- """
- if self.resize:
- self.UpdateMap(render=True)
-
- event.Skip()
-
- def SaveToFile(self, FileName, FileType):
- """!
- This draws the psuedo DC to a buffer that
- can be saved to a file.
- """
- dc = wx.BufferedPaintDC(self, self.buffer)
- self.pdc.DrawToDC(dc)
- if self.pdcVector:
- self.pdcVector.DrawToDC(dc)
- self.buffer.SaveFile(FileName, FileType)
-
- def GetOverlay(self):
- """!
- Converts rendered overlay files to wx.Image
-
- Updates self.imagedict
-
- @return list of images
- """
- imgs = []
- for overlay in self.Map.GetListOfLayers(l_type="overlay", l_active=True):
- if os.path.isfile(overlay.mapfile) and os.path.getsize(overlay.mapfile):
- img = wx.Image(overlay.mapfile, wx.BITMAP_TYPE_ANY)
- self.imagedict[img] = { 'id' : overlay.id,
- 'layer' : overlay }
- imgs.append(img)
-
- return imgs
-
- def GetImage(self):
- """!
- Converts redered map files to wx.Image
-
- Updates self.imagedict (id=99)
-
- @return wx.Image instance (map composition)
- """
- imgId = 99
- if self.Map.mapfile and os.path.isfile(self.Map.mapfile) and \
- os.path.getsize(self.Map.mapfile):
- img = wx.Image(self.Map.mapfile, wx.BITMAP_TYPE_ANY)
- else:
- img = None
-
- self.imagedict[img] = { 'id': imgId }
-
- return img
-
- def UpdateMap(self, render=True, renderVector=True):
- """!
- Updates the canvas anytime there is a change to the
- underlaying images or to the geometry of the canvas.
-
- @param render re-render map composition
- @param renderVector re-render vector map layer enabled for editing (used for digitizer)
- """
- start = time.clock()
-
- self.resize = False
-
- # if len(self.Map.GetListOfLayers()) == 0:
- # return False
-
- if self.img is None:
- render = True
-
- #
- # initialize process bar (only on 'render')
- #
- if render is True or renderVector is True:
- self.parent.statusbarWin['progress'].Show()
- if self.parent.statusbarWin['progress'].GetRange() > 0:
- self.parent.statusbarWin['progress'].SetValue(1)
-
- #
- # render background image if needed
- #
-
- # update layer dictionary if there has been a change in layers
- if self.tree and self.tree.reorder == True:
- self.tree.ReorderLayers()
-
- # reset flag for auto-rendering
- if self.tree:
- self.tree.rerender = False
-
- if render:
- # update display size
- self.Map.ChangeMapSize(self.GetClientSize())
- if self.parent.statusbarWin['resolution'].IsChecked():
- # use computation region resolution for rendering
- windres = True
- else:
- windres = False
- self.mapfile = self.Map.Render(force=True, mapWindow=self.parent,
- windres=windres)
- else:
- self.mapfile = self.Map.Render(force=False, mapWindow=self.parent)
-
- self.img = self.GetImage() # id=99
-
- #
- # clear pseudoDcs
- #
- for pdc in (self.pdc,
- self.pdcDec,
- self.pdcTmp):
- pdc.Clear()
- pdc.RemoveAll()
-
- #
- # draw background map image to PseudoDC
- #
- if not self.img:
- self.Draw(self.pdc, pdctype='clear')
- else:
- try:
- id = self.imagedict[self.img]['id']
- except:
- return False
-
- self.Draw(self.pdc, self.img, drawid=id)
-
- #
- # render vector map layer
- #
- digitToolbar = self.parent.toolbars['vdigit']
- if renderVector and digitToolbar and \
- digitToolbar.GetLayer():
- # set region
- self.parent.digit.driver.UpdateRegion()
- # re-calculate threshold for digitization tool
- self.parent.digit.driver.GetThreshold()
- # draw map
- if self.pdcVector:
- self.pdcVector.Clear()
- self.pdcVector.RemoveAll()
- try:
- item = self.tree.FindItemByData('maplayer', digitToolbar.GetLayer())
- except TypeError:
- item = None
-
- if item and self.tree.IsItemChecked(item):
- self.parent.digit.driver.DrawMap()
-
- # translate tmp objects (pointer position)
- if digitToolbar.GetAction() == 'moveLine':
- if hasattr(self, "vdigitMove") and \
- self.vdigitMove.has_key('beginDiff'):
- # move line
- for id in self.vdigitMove['id']:
- self.pdcTmp.TranslateId(id,
- self.vdigitMove['beginDiff'][0],
- self.vdigitMove['beginDiff'][1])
- del self.vdigitMove['beginDiff']
-
- #
- # render overlays
- #
- for img in self.GetOverlay():
- # draw any active and defined overlays
- if self.imagedict[img]['layer'].IsActive():
- id = self.imagedict[img]['id']
- self.Draw(self.pdc, img=img, drawid=id,
- pdctype=self.overlays[id]['pdcType'], coords=self.overlays[id]['coords'])
-
- for id in self.textdict.keys():
- self.Draw(self.pdc, img=self.textdict[id], drawid=id,
- pdctype='text', coords=[10, 10, 10, 10])
-
- # optionally draw computational extent box
- self.DrawCompRegionExtent()
-
- #
- # redraw pdcTmp if needed
- #
- if len(self.polycoords) > 0:
- self.DrawLines(self.pdcTmp)
-
- if not self.parent.IsStandalone() and \
- self.parent.GetLayerManager().georectifying:
- # -> georectifier (redraw GCPs)
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
- self.parent.GetLayerManager().georectifying.DrawGCP(coordtype)
-
- #
- # clear measurement
- #
- if self.mouse["use"] == "measure":
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.SetCursor(self.parent.cursors["default"])
-
- stop = time.clock()
-
- #
- # hide process bar
- #
- self.parent.statusbarWin['progress'].Hide()
-
- #
- # update statusbar
- #
- ### self.Map.SetRegion()
- self.parent.StatusbarUpdate()
- if grass.find_file(name = 'MASK', element = 'cell')['name']:
- # mask found
- self.parent.statusbarWin['mask'].SetLabel(_('MASK'))
- else:
- self.parent.statusbarWin['mask'].SetLabel('')
-
- Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%g" % \
- (render, renderVector, (stop-start)))
-
- return True
-
- def DrawCompRegionExtent(self):
- """!
- Draw computational region extent in the display
-
- Display region is drawn as a blue box inside the computational region,
- computational region inside a display region as a red box).
- """
- if hasattr(self, "regionCoords"):
- compReg = self.Map.GetRegion()
- dispReg = self.Map.GetCurrentRegion()
- reg = None
- if self.IsInRegion(dispReg, compReg):
- self.polypen = wx.Pen(colour=wx.Colour(0, 0, 255, 128), width=3, style=wx.SOLID)
- reg = dispReg
- else:
- self.polypen = wx.Pen(colour=wx.Colour(255, 0, 0, 128),
- width=3, style=wx.SOLID)
- reg = compReg
-
- self.regionCoords = []
- self.regionCoords.append((reg['w'], reg['n']))
- self.regionCoords.append((reg['e'], reg['n']))
- self.regionCoords.append((reg['e'], reg['s']))
- self.regionCoords.append((reg['w'], reg['s']))
- self.regionCoords.append((reg['w'], reg['n']))
- # draw region extent
- self.DrawLines(pdc=self.pdcDec, polycoords=self.regionCoords)
-
- def IsInRegion(self, region, refRegion):
- """!
- Test if 'region' is inside of 'refRegion'
-
- @param region input region
- @param refRegion reference region (e.g. computational region)
-
- @return True if region is inside of refRegion
- @return False
- """
- if region['s'] >= refRegion['s'] and \
- region['n'] <= refRegion['n'] and \
- region['w'] >= refRegion['w'] and \
- region['e'] <= refRegion['e']:
- return True
-
- return False
-
- def EraseMap(self):
- """!
- Erase the canvas
- """
- self.Draw(self.pdc, pdctype='clear')
-
- if self.pdcVector:
- self.Draw(self.pdcVector, pdctype='clear')
-
- self.Draw(self.pdcDec, pdctype='clear')
- self.Draw(self.pdcTmp, pdctype='clear')
-
- def DragMap(self, moveto):
- """!
- Drag the entire map image for panning.
- """
-
- dc = wx.BufferedDC(wx.ClientDC(self))
- dc.SetBackground(wx.Brush("White"))
- dc.Clear()
-
- self.dragimg = wx.DragImage(self.buffer)
- self.dragimg.BeginDrag((0, 0), self)
- self.dragimg.GetImageRect(moveto)
- self.dragimg.Move(moveto)
-
- self.dragimg.DoDrawImage(dc, moveto)
- self.dragimg.EndDrag()
-
- return True
-
- def DragItem(self, id, event):
- """!
- Drag an overlay decoration item
- """
- if id == 99 or id == '' or id == None: return
- Debug.msg (5, "BufferedWindow.DragItem(): id=%d" % id)
- x, y = self.lastpos
- dx = event.GetX() - x
- dy = event.GetY() - y
- self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
- r = self.pdc.GetIdBounds(id)
- ### FIXME in vdigit/pseudodc.i
- if type(r) is list:
- r = wx.Rect(r[0], r[1], r[2], r[3])
- if id > 100: # text dragging
- rtop = (r[0],r[1]-r[3],r[2],r[3])
- r = r.Union(rtop)
- rleft = (r[0]-r[2],r[1],r[2],r[3])
- r = r.Union(rleft)
- self.pdc.TranslateId(id, dx, dy)
-
- r2 = self.pdc.GetIdBounds(id)
- 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
- r = r.Union(r2)
- r.Inflate(4,4)
- self.RefreshRect(r, False)
- self.lastpos = (event.GetX(), event.GetY())
-
- def MouseDraw(self, pdc=None, begin=None, end=None):
- """!
- Mouse box or line from 'begin' to 'end'
-
- If not given from self.mouse['begin'] to self.mouse['end'].
-
- """
- self.redrawAll = False
-
- if not pdc:
- return
-
- if begin is None:
- begin = self.mouse['begin']
- if end is None:
- end = self.mouse['end']
-
- Debug.msg (5, "BufferedWindow.MouseDraw(): use=%s, box=%s, begin=%f,%f, end=%f,%f" % \
- (self.mouse['use'], self.mouse['box'],
- begin[0], begin[1], end[0], end[1]))
-
- if self.mouse['box'] == "box":
- boxid = wx.ID_NEW
- mousecoords = [begin[0], begin[1],
- end[0], end[1]]
- r = pdc.GetIdBounds(boxid)
- if type(r) is list:
- r = wx.Rect(r[0], r[1], r[2], r[3])
- r.Inflate(4, 4)
- try:
- pdc.ClearId(boxid)
- except:
- pass
- self.RefreshRect(r, False)
- pdc.SetId(boxid)
- self.Draw(pdc, drawid=boxid, pdctype='box', coords=mousecoords)
- elif self.mouse['box'] == "line" or self.mouse['box'] == 'point':
- self.lineid = wx.ID_NEW
- mousecoords = [begin[0], begin[1], \
- end[0], end[1]]
- x1=min(begin[0],end[0])
- x2=max(begin[0],end[0])
- y1=min(begin[1],end[1])
- y2=max(begin[1],end[1])
- r = wx.Rect(x1,y1,x2-x1,y2-y1)
- r.Inflate(4,4)
- try:
- pdc.ClearId(self.lineid)
- except:
- pass
- self.RefreshRect(r, False)
- pdc.SetId(self.lineid)
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=mousecoords)
-
- def DrawLines(self, pdc=None, polycoords=None):
- """!
- Draw polyline in PseudoDC
-
- Set self.pline to wx.NEW_ID + 1
-
- polycoords - list of polyline vertices, geographical coordinates
- (if not given, self.polycoords is used)
-
- """
- if not pdc:
- pdc = self.pdcTmp
-
- if not polycoords:
- polycoords = self.polycoords
-
- if len(polycoords) > 0:
- self.plineid = wx.ID_NEW + 1
- # convert from EN to XY
- coords = []
- for p in polycoords:
- coords.append(self.Cell2Pixel(p))
-
- self.Draw(pdc, drawid=self.plineid, pdctype='polyline', coords=coords)
-
- Debug.msg (4, "BufferedWindow.DrawLines(): coords=%s, id=%s" % \
- (coords, self.plineid))
-
- return self.plineid
-
- return -1
-
- def DrawCross(self, pdc, coords, size, rotation=0,
- text=None, textAlign='lr', textOffset=(5, 5)):
- """!Draw cross in PseudoDC
-
- @todo implement rotation
-
- @param pdc PseudoDC
- @param coord center coordinates
- @param rotation rotate symbol
- @param text draw also text (text, font, color, rotation)
- @param textAlign alignment (default 'lower-right')
- @textOffset offset for text (from center point)
- """
- Debug.msg(4, "BufferedWindow.DrawCross(): pdc=%s, coords=%s, size=%d" % \
- (pdc, coords, size))
- coordsCross = ((coords[0] - size, coords[1], coords[0] + size, coords[1]),
- (coords[0], coords[1] - size, coords[0], coords[1] + size))
-
- self.lineid = wx.NewId()
- for lineCoords in coordsCross:
- self.Draw(pdc, drawid=self.lineid, pdctype='line', coords=lineCoords)
-
- if not text:
- return self.lineid
-
- if textAlign == 'ul':
- coord = [coords[0] - textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'ur':
- coord = [coords[0] + textOffset[0], coords[1] - textOffset[1], 0, 0]
- elif textAlign == 'lr':
- coord = [coords[0] + textOffset[0], coords[1] + textOffset[1], 0, 0]
- else:
- coord = [coords[0] - textOffset[0], coords[1] + textOffset[1], 0, 0]
-
- self.Draw(pdc, img=text,
- pdctype='text', coords=coord)
-
- return self.lineid
-
- def MouseActions(self, event):
- """!
- Mouse motion and button click notifier
- """
- if not self.processMouse:
- return
-
- ### if self.redrawAll is False:
- ### self.redrawAll = True
-
- # zoom with mouse wheel
- if event.GetWheelRotation() != 0:
- self.OnMouseWheel(event)
-
- # left mouse button pressed
- elif event.LeftDown():
- self.OnLeftDown(event)
-
- # left mouse button released
- elif event.LeftUp():
- self.OnLeftUp(event)
-
- # dragging
- elif event.Dragging():
- self.OnDragging(event)
-
- # double click
- elif event.ButtonDClick():
- self.OnButtonDClick(event)
-
- # middle mouse button pressed
- elif event.MiddleDown():
- self.OnMiddleDown(event)
-
- # right mouse button pressed
- elif event.RightDown():
- self.OnRightDown(event)
-
- # right mouse button released
- elif event.RightUp():
- self.OnRightUp(event)
-
- elif event.Moving():
- self.OnMouseMoving(event)
-
-# event.Skip()
-
- def OnMouseWheel(self, event):
- """!
- Mouse wheel moved
- """
- self.processMouse = False
- current = event.GetPositionTuple()[:]
- wheel = event.GetWheelRotation()
- Debug.msg (5, "BufferedWindow.MouseAction(): wheel=%d" % wheel)
- # zoom 1/2 of the screen, centered to current mouse position (TODO: settings)
- begin = (current[0] - self.Map.width / 4,
- current[1] - self.Map.height / 4)
- end = (current[0] + self.Map.width / 4,
- current[1] + self.Map.height / 4)
-
- if wheel > 0:
- zoomtype = 1
- else:
- zoomtype = -1
-
- # zoom
- self.Zoom(begin, end, zoomtype)
-
- # redraw map
- self.UpdateMap()
-
- ### self.OnPaint(None)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- self.Refresh()
- self.processMouse = True
-# event.Skip()
-
- def OnDragging(self, event):
- """!
- Mouse dragging with left button down
- """
- Debug.msg (5, "BufferedWindow.MouseAction(): Dragging")
- current = event.GetPositionTuple()[:]
- previous = self.mouse['begin']
- move = (current[0] - previous[0],
- current[1] - previous[1])
-
- digitToolbar = self.parent.toolbars['vdigit']
-
- # dragging or drawing box with left button
- if self.mouse['use'] == 'pan':
- self.DragMap(move)
-
- # dragging decoration overlay item
- elif (self.mouse['use'] == 'pointer' and
- not digitToolbar and
- self.dragid != None):
- self.DragItem(self.dragid, event)
-
- # dragging anything else - rubber band box or line
- else:
- if (self.mouse['use'] == 'pointer' and
- not digitToolbar): return
- self.mouse['end'] = event.GetPositionTuple()[:]
- digitClass = self.parent.digit
- if (event.LeftIsDown() and
- not (digitToolbar and
- digitToolbar.GetAction() in ("moveLine",) and
- digitClass.driver.GetSelected() > 0)):
- # draw box only when left mouse button is pressed
- self.MouseDraw(pdc=self.pdcTmp)
-
-# event.Skip()
-
- def OnLeftDownVDigitAddLine(self, event):
- """!
- Left mouse button down - vector digitizer add new line
- action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- return
-
- if digitToolbar.GetAction('type') in ["point", "centroid"]:
- # add new point
- if digitToolbar.GetAction('type') == 'point':
- point = True
- else:
- point = False
-
- east, north = self.Pixel2Cell(self.mouse['begin'])
- fid = digitClass.AddPoint(mapLayer, point, east, north)
- if fid < 0:
- return
-
- self.UpdateMap(render=False) # redraw map
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') is True:
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
-
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent=self, map=mapLayer,
- cats=cats,
- pos=posWindow,
- action="add")
-
- if not point:
- self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
- digitToolbar.GetLayer())
- self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
- digitToolbar.GetLayer())
-
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
-
- gcmd.RunCommand('db.execute',
- parent = self,
- quiet = True,
- input = sqlfile.name)
-
- if addRecordDlg.mapDBInfo:
- self.__updateATM()
-
- elif digitToolbar.GetAction('type') in ["line", "boundary"]:
- # add new point to the line
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- self.DrawLines(pdc=self.pdcTmp)
-
- def __geomAttrb(self, fid, dialog, attrb, digit, mapLayer):
- """!Trac geometry attributes?"""
- item = self.tree.FindItemByData('maplayer', mapLayer)
- vdigit = self.tree.GetPyData(item)[0]['vdigit']
- if vdigit and \
- vdigit.has_key('geomAttr') and \
- vdigit['geomAttr'].has_key(attrb):
- val = -1
- if attrb == 'length':
- val = digit.GetLineLength(fid)
- type = attrb
- elif attrb == 'area':
- val = digit.GetAreaSize(fid)
- type = attrb
- elif attrb == 'perimeter':
- val = digit.GetAreaPerimeter(fid)
- type = 'length'
-
- if val > 0:
- layer = int(UserSettings.Get(group='vdigit', key="layer", subkey='value'))
- column = vdigit['geomAttr'][attrb]['column']
- val = UnitsConvertValue(val, type, vdigit['geomAttr'][attrb]['units'])
- dialog.SetColumnValue(layer, column, val)
- dialog.OnReset()
-
- def __geomAttrbUpdate(self, fids):
- """!Update geometry atrributes of currently selected features
-
- @param fid list feature id
- """
- mapLayer = self.parent.toolbars['vdigit'].GetLayer()
- vectorName = mapLayer.GetName()
- digit = self.parent.digit
- item = self.tree.FindItemByData('maplayer', mapLayer)
- vdigit = self.tree.GetPyData(item)[0]['vdigit']
-
- if vdigit is None or not vdigit.has_key('geomAttr'):
- return
-
- dbInfo = gselect.VectorDBInfo(vectorName)
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for fid in fids:
- for layer, cats in digit.GetLineCats(fid).iteritems():
- table = dbInfo.GetTable(layer)
- for attrb, item in vdigit['geomAttr'].iteritems():
- val = -1
- if attrb == 'length':
- val = digit.GetLineLength(fid)
- type = attrb
- elif attrb == 'area':
- val = digit.GetAreaSize(fid)
- type = attrb
- elif attrb == 'perimeter':
- val = digit.GetAreaPerimeter(fid)
- type = 'length'
-
- if val < 0:
- continue
- val = UnitsConvertValue(val, type, item['units'])
-
- for cat in cats:
- sqlfile.write('UPDATE %s SET %s = %f WHERE %s = %d;\n' % \
- (table, item['column'], val,
- dbInfo.GetKeyColumn(layer), cat))
- sqlfile.file.flush()
- gcmd.RunCommand('db.execute',
- parent = True,
- quiet = True,
- input = sqlfile.name)
-
- def __updateATM(self):
- """!Update open Attribute Table Manager
-
- @todo: use AddDataRow() instead
- """
- # update ATM
- digitToolbar = self.parent.toolbars['vdigit']
- digitVector = digitToolbar.GetLayer().GetName()
-
- for atm in self.lmgr.dialogs['atm']:
- atmVector = atm.GetVectorName()
- if atmVector == digitVector:
- layer = UserSettings.Get(group='vdigit', key="layer", subkey='value')
- # TODO: use AddDataRow instead
- atm.LoadData(layer)
-
- def OnLeftDownVDigitEditLine(self, event):
- """!
- Left mouse button down - vector digitizer edit linear feature
- - add new vertex.
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.vdigitMove['id'].append(wx.NewId())
- self.DrawLines(pdc=self.pdcTmp)
-
- def OnLeftDownVDigitMoveLine(self, event):
- """!
- Left mouse button down - vector digitizer move feature/vertex,
- edit linear feature
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- self.vdigitMove = {}
- # geographic coordinates of initial position (left-down)
- self.vdigitMove['begin'] = None
- # list of ids to modify
- self.vdigitMove['id'] = []
- # ids geographic coordinates
- self.vdigitMove['coord'] = {}
-
- if digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # set pen
- pcolor = UserSettings.Get(group='vdigit', key="symbol",
- subkey=["highlight", "color"])
- self.pen = self.polypen = wx.Pen(colour=pcolor,
- width=2, style=wx.SHORT_DASH)
- self.pdcTmp.SetPen(self.polypen)
-
- def OnLeftDownVDigitDisplayCA(self, event):
- """!
- Left mouse button down - vector digitizer display categories
- or attributes action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- return
-
- coords = self.Pixel2Cell(self.mouse['begin'])
-
- # unselect
- digitClass.driver.SetSelected([])
-
- # select feature by point
- cats = {}
- if digitClass.driver.SelectLineByPoint(coords,
- digitClass.GetSelectType()) is None:
- return
-
- if UserSettings.Get(group='vdigit', key='checkForDupl',
- subkey='enabled'):
- lines = digitClass.driver.GetSelected()
- else:
- lines = (digitClass.driver.GetSelected()[0],) # only first found
-
- for line in lines:
- cats[line] = digitClass.GetLineCats(line)
-
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- if digitToolbar.GetAction() == "displayAttrs":
- # select attributes based on coordinates (all layers)
- if self.parent.dialogs['attributes'] is None:
- self.parent.dialogs['attributes'] = \
- dbm_dialogs.DisplayAttributesDialog(parent=self, map=mapLayer,
- cats=cats,
- action="update")
- else:
- # upgrade dialog
- self.parent.dialogs['attributes'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['attributes']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- if not self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Show()
- else:
- if self.parent.dialogs['attributes'] and \
- self.parent.dialogs['attributes'].IsShown():
- self.parent.dialogs['attributes'].Hide()
-
- else: # displayCats
- if self.parent.dialogs['category'] is None:
- # open new dialog
- dlg = VDigitCategoryDialog(parent=self,
- map=mapLayer,
- cats=cats,
- pos=posWindow,
- title=_("Update categories"))
- self.parent.dialogs['category'] = dlg
- else:
- # update currently open dialog
- self.parent.dialogs['category'].UpdateDialog(cats=cats)
-
- if self.parent.dialogs['category']:
- if len(cats.keys()) > 0:
- # highlight feature & re-draw map
- if not self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Show()
- else:
- if self.parent.dialogs['category'].IsShown():
- self.parent.dialogs['category'].Hide()
-
- self.UpdateMap(render=False)
-
- def OnLeftDownVDigitCopyCA(self, event):
- """!
- Left mouse button down - vector digitizer copy categories
- or attributes action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if not hasattr(self, "copyCatsList"):
- self.copyCatsList = []
- else:
- self.copyCatsIds = []
- self.mouse['box'] = 'box'
-
- def OnLeftDownVDigitCopyLine(self, event):
- """!
- Left mouse button down - vector digitizer copy lines action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if not hasattr(self, "copyIds"):
- self.copyIds = []
- self.layerTmp = None
-
- def OnLeftDownVDigitBulkLine(self, event):
- """!
- Left mouse button down - vector digitizer label 3d vector
- lines
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if len(self.polycoords) > 1: # start new line
- self.polycoords = []
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords.append(self.Pixel2Cell(event.GetPositionTuple()[:]))
- if len(self.polycoords) == 1:
- begin = self.Pixel2Cell(self.polycoords[-1])
- end = self.Pixel2Cell(self.mouse['end'])
- else:
- end = self.Pixel2Cell(self.polycoords[-1])
- begin = self.Pixel2Cell(self.mouse['begin'])
-
- self.DrawLines(self.pdcTmp, polycoords = (begin, end))
-
- def OnLeftDown(self, event):
- """!
- Left mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnLeftDown(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['begin'] = event.GetPositionTuple()[:]
-
- if self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if len(self.polycoords) == 0:
- self.mouse['end'] = self.mouse['begin']
- self.polycoords.append(self.Pixel2Cell(self.mouse['begin']))
- self.ClearLines(pdc=self.pdcTmp)
- else:
- self.mouse['begin'] = self.mouse['end']
- elif self.mouse['use'] == 'zoom':
- pass
-
- #
- # vector digizer
- #
- elif self.mouse["use"] == "pointer" and \
- self.parent.toolbars['vdigit']:
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- try:
- mapLayer = digitToolbar.GetLayer().GetName()
- except:
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Vector digitizer"),
- style=wx.OK | wx.ICON_INFORMATION | wx.CENTRE)
- event.Skip()
- return
-
- if digitToolbar.GetAction() not in ("moveVertex",
- "addVertex",
- "removeVertex",
- "editLine"):
- # set pen
- self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
- self.polypen = wx.Pen(colour='dark green', width=2, style=wx.SOLID)
-
- if digitToolbar.GetAction() in ("addVertex",
- "removeVertex",
- "splitLines"):
- # unselect
- digitClass.driver.SetSelected([])
-
- if digitToolbar.GetAction() == "addLine":
- self.OnLeftDownVDigitAddLine(event)
-
- elif digitToolbar.GetAction() == "editLine" and \
- hasattr(self, "vdigitMove"):
- self.OnLeftDownVDigitEditLine(event)
-
- elif digitToolbar.GetAction() in ("moveLine",
- "moveVertex",
- "editLine") and \
- not hasattr(self, "vdigitMove"):
- self.OnLeftDownVDigitMoveLine(event)
-
- elif digitToolbar.GetAction() in ("displayAttrs"
- "displayCats"):
- self.OnLeftDownVDigitDisplayCA(event)
-
- elif digitToolbar.GetAction() in ("copyCats",
- "copyAttrs"):
- self.OnLeftDownVDigitCopyCA(event)
-
- elif digitToolbar.GetAction() == "copyLine":
- self.OnLeftDownVDigitCopyLine(event)
-
- elif digitToolbar.GetAction() == "zbulkLine":
- self.OnLeftDownVDigitBulkLine(event)
-
- elif self.mouse['use'] == 'pointer':
- # get decoration or text id
- self.idlist = []
- self.dragid = ''
- self.lastpos = self.mouse['begin']
- idlist = self.pdc.FindObjects(self.lastpos[0], self.lastpos[1],
- self.hitradius)
- if 99 in idlist:
- idlist.remove(99)
- if idlist != []:
- self.dragid = idlist[0] #drag whatever is on top
- else:
- pass
-
- event.Skip()
-
- def OnLeftUpVDigitVarious(self, event):
- """!
- Left mouse button up - vector digitizer various actions
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
- pos2 = self.Pixel2Cell(self.mouse['end'])
-
- nselected = 0
- # -> delete line || move line || move vertex
- if digitToolbar.GetAction() in ("moveVertex",
- "editLine"):
- if len(digitClass.driver.GetSelected()) == 0:
- nselected = digitClass.driver.SelectLineByPoint(pos1, type=VDigit_Lines_Type)
-
- if digitToolbar.GetAction() == "editLine":
- try:
- selVertex = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- selVertex = None
-
- if selVertex:
- # self.UpdateMap(render=False)
- ids = digitClass.driver.GetSelected(grassId=False)
- # move this line to tmp layer
- self.polycoords = []
- for id in ids:
- if id % 2: # register only vertices
- e, n = self.Pixel2Cell(self.pdcVector.GetIdBounds(id)[0:2])
- self.polycoords.append((e, n))
- digitClass.driver.DrawSelected(False)
-
- if selVertex < ids[-1] / 2:
- # choose first or last node of line
- self.vdigitMove['id'].reverse()
- self.polycoords.reverse()
- else:
- # unselect
- digitClass.driver.SetSelected([])
- del self.vdigitMove
-
- self.UpdateMap(render=False)
-
- elif digitToolbar.GetAction() in ("copyCats",
- "copyAttrs"):
- if not hasattr(self, "copyCatsIds"):
- # 'from' -> select by point
- nselected = digitClass.driver.SelectLineByPoint(pos1, digitClass.GetSelectType())
- if nselected:
- self.copyCatsList = digitClass.driver.GetSelected()
- else:
- # -> 'to' -> select by bbox
- digitClass.driver.SetSelected([])
- # return number of selected features (by box/point)
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- self.copyCatsIds = digitClass.driver.GetSelected()
-
- elif digitToolbar.GetAction() == "queryLine":
- selected = digitClass.SelectLinesByQuery(pos1, pos2)
- nselected = len(selected)
- if nselected > 0:
- digitClass.driver.SetSelected(selected)
-
- else:
- # -> moveLine || deleteLine, etc. (select by point/box)
- if digitToolbar.GetAction() == 'moveLine' and \
- len(digitClass.driver.GetSelected()) > 0:
- nselected = 0
- else:
- if digitToolbar.GetAction() == 'moveLine':
- drawSeg = True
- else:
- drawSeg = False
-
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType(),
- drawSeg)
-
- if nselected == 0:
- if digitClass.driver.SelectLineByPoint(pos1,
- digitClass.GetSelectType()) is not None:
- nselected = 1
-
- if nselected > 0:
- if digitToolbar.GetAction() in ("moveLine",
- "moveVertex"):
- # get pseudoDC id of objects which should be redrawn
- if digitToolbar.GetAction() == "moveLine":
- # -> move line
- self.vdigitMove['id'] = digitClass.driver.GetSelected(grassId=False)
- self.vdigitMove['coord'] = digitClass.driver.GetSelectedCoord()
- else: # moveVertex
- self.vdigitMove['id'] = digitClass.driver.GetSelectedVertex(pos1)
- if len(self.vdigitMove['id']) == 0: # no vertex found
- digitClass.driver.SetSelected([])
-
- #
- # check for duplicates
- #
- if UserSettings.Get(group='vdigit', key='checkForDupl', subkey='enabled') is True:
- dupl = digitClass.driver.GetDuplicates()
- self.UpdateMap(render=False)
-
- if dupl:
- posWindow = self.ClientToScreen((self.mouse['end'][0] + self.dialogOffset,
- self.mouse['end'][1] + self.dialogOffset))
-
- dlg = VDigitDuplicatesDialog(parent=self, data=dupl, pos=posWindow)
-
- if dlg.ShowModal() == wx.ID_OK:
- digitClass.driver.UnSelect(dlg.GetUnSelected())
- # update selected
- self.UpdateMap(render=False)
-
- if digitToolbar.GetAction() != "editLine":
- # -> move line || move vertex
- self.UpdateMap(render=False)
-
- else: # no vector object found
- if not (digitToolbar.GetAction() in ("moveLine",
- "moveVertex") and \
- len(self.vdigitMove['id']) > 0):
- # avoid left-click when features are already selected
- self.UpdateMap(render=False, renderVector=False)
-
- def OnLeftUpVDigitModifyLine(self, event):
- """!
- Left mouse button up - vector digitizer split line, add/remove
- vertex action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
-
- pointOnLine = digitClass.driver.SelectLineByPoint(pos1,
- type=VDigit_Lines_Type)
-
- if not pointOnLine:
- return
-
- if digitToolbar.GetAction() in ["splitLine", "addVertex"]:
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=self.Cell2Pixel(pointOnLine),
- size=5)
- else: # removeVertex
- # get only id of vertex
- try:
- id = digitClass.driver.GetSelectedVertex(pos1)[0]
- except IndexError:
- id = None
-
- if id:
- x, y = self.pdcVector.GetIdBounds(id)[0:2]
- self.pdcVector.RemoveId(id)
- self.UpdateMap(render=False) # highlight object
- self.DrawCross(pdc=self.pdcTmp, coords=(x, y),
- size=5)
- else:
- # unselect
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- def OnLeftUpVDigitCopyLine(self, event):
- """!
- Left mouse button up - vector digitizer copy feature action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- pos1 = self.Pixel2Cell(self.mouse['begin'])
- pos2 = self.Pixel2Cell(self.mouse['end'])
-
- if UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True) == '':
- # no background map -> copy from current vector map layer
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
- else:
- # copy features from background map
- self.copyIds += digitClass.SelectLinesFromBackgroundMap(pos1, pos2)
- if len(self.copyIds) > 0:
- color = UserSettings.Get(group='vdigit', key='symbol',
- subkey=['highlight', 'color'])
- colorStr = str(color[0]) + ":" + \
- str(color[1]) + ":" + \
- str(color[2])
- dVectTmp = ['d.vect',
- 'map=%s' % UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True),
- 'cats=%s' % utils.ListOfCatsToRange(self.copyIds),
- '-i',
- 'color=%s' % colorStr,
- 'fcolor=%s' % colorStr,
- 'type=point,line,boundary,centroid',
- 'width=2']
-
- if not self.layerTmp:
- self.layerTmp = self.Map.AddLayer(type='vector',
- name=globalvar.QUERYLAYER,
- command=dVectTmp)
- else:
- self.layerTmp.SetCmd(dVectTmp)
-
- self.UpdateMap(render=True, renderVector=False)
- else:
- self.UpdateMap(render=False, renderVector=False)
-
- self.redrawAll = None
-
- def OnLeftUpVDigitBulkLine(self, event):
- """!
- Left mouse button up - vector digitizer z-bulk line action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- # select lines to be labeled
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
- nselected = digitClass.driver.SelectLinesByBox(pos1, pos2,
- digitClass.GetSelectType())
-
- if nselected > 0:
- # highlight selected features
- self.UpdateMap(render=False)
- self.DrawLines(pdc=self.pdcTmp) # redraw temp line
- else:
- self.UpdateMap(render=False, renderVector=False)
-
- def OnLeftUpVDigitConnectLine(self, event):
- """!
- Left mouse button up - vector digitizer connect line action
- """
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if len(digitClass.driver.GetSelected()) > 0:
- self.UpdateMap(render=False)
-
- def OnLeftUp(self, event):
- """!
- Left mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
- self.mouse["use"])
-
- self.mouse['end'] = event.GetPositionTuple()[:]
-
- if self.mouse['use'] in ["zoom", "pan"]:
- # set region in zoom or pan
- begin = self.mouse['begin']
- end = self.mouse['end']
- if self.mouse['use'] == 'zoom':
- # set region for click (zero-width box)
- if begin[0] - end[0] == 0 or \
- begin[1] - end[1] == 0:
- # zoom 1/2 of the screen (TODO: settings)
- begin = (end[0] - self.Map.width / 4,
- end[1] - self.Map.height / 4)
- end = (end[0] + self.Map.width / 4,
- end[1] + self.Map.height / 4)
-
- self.Zoom(begin, end, self.zoomtype)
-
- # redraw map
- self.UpdateMap(render=True)
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- elif self.mouse["use"] == "query":
- # querying
- self.parent.QueryMap(self.mouse['begin'][0],self.mouse['begin'][1])
-
- elif self.mouse["use"] == "queryVector":
- # editable mode for vector map layers
- self.parent.QueryVector(self.mouse['begin'][0], self.mouse['begin'][1])
-
- # clear temp canvas
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] in ["measure", "profile"]:
- # measure or profile
- if self.mouse["use"] == "measure":
- self.parent.MeasureDist(self.mouse['begin'], self.mouse['end'])
-
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- elif self.mouse["use"] == "pointer" and \
- self.parent.GetLayerManager().georectifying:
- # -> georectifying
- coord = self.Pixel2Cell(self.mouse['end'])
- if self.parent.toolbars['georect']:
- coordtype = 'gcpcoord'
- else:
- coordtype = 'mapcoord'
-
- self.parent.GetLayerManager().georectifying.SetGCPData(coordtype, coord, self)
- self.UpdateMap(render=False, renderVector=False)
-
- elif self.mouse["use"] == "pointer" and self.parent.toolbars['vdigit']:
- # digitization tool active
- digitToolbar = self.parent.toolbars['vdigit']
- digitClass = self.parent.digit
-
- if hasattr(self, "vdigitMove"):
- if len(digitClass.driver.GetSelected()) == 0:
- self.vdigitMove['begin'] = self.Pixel2Cell(self.mouse['begin']) # left down
-
- # eliminate initial mouse moving efect
- self.mouse['begin'] = self.mouse['end']
-
- if digitToolbar.GetAction() in ("deleteLine",
- "moveLine",
- "moveVertex",
- "copyCats",
- "copyAttrs",
- "editLine",
- "flipLine",
- "mergeLine",
- "snapLine",
- "queryLine",
- "breakLine",
- "typeConv",
- "connectLine"):
- self.OnLeftUpVDigitVarious(event)
-
- elif digitToolbar.GetAction() in ("splitLine",
- "addVertex",
- "removeVertex"):
- self.OnLeftUpVDigitModifyLine(event)
-
- elif digitToolbar.GetAction() == "copyLine":
- self.OnLeftUpVDigitCopyLine(event)
-
- elif digitToolbar.GetAction() == "zbulkLine" and \
- len(self.polycoords) == 2:
- self.OnLeftUpVDigitBulkLine(event)
-
- elif digitToolbar.GetAction() == "connectLine":
- self.OnLeftUpConnectLine(event)
-
- if len(digitClass.driver.GetSelected()) > 0:
- self.redrawAll = None
-
- elif (self.mouse['use'] == 'pointer' and
- self.dragid >= 0):
- # end drag of overlay decoration
-
- if self.dragid < 99 and self.overlays.has_key(self.dragid):
- self.overlays[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- elif self.dragid > 100 and self.textdict.has_key(self.dragid):
- self.textdict[self.dragid]['coords'] = self.pdc.GetIdBounds(self.dragid)
- else:
- pass
- self.dragid = None
- self.currtxtid = None
-
- def OnButtonDClick(self, event):
- """!
- Mouse button double click
- """
- Debug.msg (5, "BufferedWindow.OnButtonDClick(): use=%s" % \
- self.mouse["use"])
-
- if self.mouse["use"] == "measure":
- # measure
- self.ClearLines(pdc=self.pdcTmp)
- self.polycoords = []
- self.mouse['use'] = 'pointer'
- self.mouse['box'] = 'point'
- self.mouse['end'] = [0, 0]
- self.Refresh()
- self.SetCursor(self.parent.cursors["default"])
-
- elif self.mouse["use"] == "profile":
- pass
-
- elif self.mouse['use'] == 'pointer' and \
- self.parent.toolbars['vdigit']:
- # vector digitizer
- pass
-
- else:
- # select overlay decoration options dialog
- clickposition = event.GetPositionTuple()[:]
- idlist = self.pdc.FindObjects(clickposition[0], clickposition[1], self.hitradius)
- if idlist == []:
- return
- self.dragid = idlist[0]
-
- # self.ovlcoords[self.dragid] = self.pdc.GetIdBounds(self.dragid)
- if self.dragid > 100:
- self.currtxtid = self.dragid
- self.parent.OnAddText(None)
- elif self.dragid == 0:
- self.parent.OnAddBarscale(None)
- elif self.dragid == 1:
- self.parent.OnAddLegend(None)
-
- def OnRightDown(self, event):
- """!
- Right mouse button pressed
- """
- Debug.msg (5, "BufferedWindow.OnRightDown(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() in ("moveLine",
- "moveVertex") and \
- hasattr(self, "vdigitMove"):
-
- pFrom = self.vdigitMove['begin']
- pTo = self.Pixel2Cell(event.GetPositionTuple())
-
- move = (pTo[0] - pFrom[0],
- pTo[1] - pFrom[1])
-
- if digitToolbar.GetAction() == "moveLine":
- # move line
- if digitClass.MoveSelectedLines(move) < 0:
- return
- elif digitToolbar.GetAction() == "moveVertex":
- # move vertex
- fid = digitClass.MoveSelectedVertex(pFrom, move)
- if fid < 0:
- return
-
- self.__geomAttrbUpdate([fid,])
-
- del self.vdigitMove
-
- event.Skip()
-
- def OnRightUp(self, event):
- """!
- Right mouse button released
- """
- Debug.msg (5, "BufferedWindow.OnRightUp(): use=%s" % \
- self.mouse["use"])
-
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar:
- digitClass = self.parent.digit
- # digitization tool (confirm action)
- if digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]:
- # -> add new line / boundary
- try:
- map = digitToolbar.GetLayer().GetName()
- except:
- map = None
- wx.MessageBox(parent=self,
- message=_("No vector map selected for editing."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-
- if map:
- # mapcoords = []
- # xy -> EN
- # for coord in self.polycoords:
- # mapcoords.append(self.Pixel2Cell(coord))
- if digitToolbar.GetAction('type') == 'line':
- line = True
- else:
- line = False
-
- if len(self.polycoords) < 2: # ignore 'one-point' lines
- return
-
- fid = digitClass.AddLine(map, line, self.polycoords)
- if fid < 0:
- return
-
- position = self.Cell2Pixel(self.polycoords[-1])
- self.polycoords = []
- self.UpdateMap(render=False)
- self.redrawAll = True
- self.Refresh()
-
- # add new record into atribute table
- if UserSettings.Get(group='vdigit', key="addRecord", subkey='enabled') and \
- (line is True or \
- (not line and fid > 0)):
- posWindow = self.ClientToScreen((position[0] + self.dialogOffset,
- position[1] + self.dialogOffset))
-
- # select attributes based on layer and category
- cats = { fid : {
- UserSettings.Get(group='vdigit', key="layer", subkey='value') :
- (UserSettings.Get(group='vdigit', key="category", subkey='value'), )
- }}
-
- addRecordDlg = dbm_dialogs.DisplayAttributesDialog(parent=self, map=map,
- cats=cats,
- pos=posWindow,
- action="add")
-
- self.__geomAttrb(fid, addRecordDlg, 'length', digitClass,
- digitToolbar.GetLayer())
- # auto-placing centroid
- self.__geomAttrb(fid, addRecordDlg, 'area', digitClass,
- digitToolbar.GetLayer())
- self.__geomAttrb(fid, addRecordDlg, 'perimeter', digitClass,
- digitToolbar.GetLayer())
-
- if addRecordDlg.mapDBInfo and \
- addRecordDlg.ShowModal() == wx.ID_OK:
- sqlfile = tempfile.NamedTemporaryFile(mode="w")
- for sql in addRecordDlg.GetSQLString():
- sqlfile.file.write(sql + ";\n")
- sqlfile.file.flush()
- gcmd.RunCommand('db.execute',
- parent = True,
- quiet = True,
- input = sqlfile.name)
-
- if addRecordDlg.mapDBInfo:
- self.__updateATM()
-
- elif digitToolbar.GetAction() == "deleteLine":
- # -> delete selected vector features
- if digitClass.DeleteSelectedLines() < 0:
- return
- self.__updateATM()
- elif digitToolbar.GetAction() == "splitLine":
- # split line
- if digitClass.SplitLine(self.Pixel2Cell(self.mouse['begin'])) < 0:
- return
- elif digitToolbar.GetAction() == "addVertex":
- # add vertex
- fid = digitClass.AddVertex(self.Pixel2Cell(self.mouse['begin']))
- if fid < 0:
- return
- elif digitToolbar.GetAction() == "removeVertex":
- # remove vertex
- fid = digitClass.RemoveVertex(self.Pixel2Cell(self.mouse['begin']))
- if fid < 0:
- return
- self.__geomAttrbUpdate([fid,])
- elif digitToolbar.GetAction() in ("copyCats", "copyAttrs"):
- try:
- if digitToolbar.GetAction() == 'copyCats':
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=False) < 0:
- return
- else:
- if digitClass.CopyCats(self.copyCatsList,
- self.copyCatsIds, copyAttrb=True) < 0:
- return
-
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
-
- self.__updateATM()
-
- elif digitToolbar.GetAction() == "editLine" and \
- hasattr(self, "vdigitMove"):
- line = digitClass.driver.GetSelected()
- if digitClass.EditLine(line, self.polycoords) < 0:
- return
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "flipLine":
- if digitClass.FlipLine() < 0:
- return
- elif digitToolbar.GetAction() == "mergeLine":
- if digitClass.MergeLine() < 0:
- return
- elif digitToolbar.GetAction() == "breakLine":
- if digitClass.BreakLine() < 0:
- return
- elif digitToolbar.GetAction() == "snapLine":
- if digitClass.SnapLine() < 0:
- return
- elif digitToolbar.GetAction() == "connectLine":
- if len(digitClass.driver.GetSelected()) > 1:
- if digitClass.ConnectLine() < 0:
- return
- elif digitToolbar.GetAction() == "copyLine":
- if digitClass.CopyLine(self.copyIds) < 0:
- return
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- elif digitToolbar.GetAction() == "zbulkLine" and len(self.polycoords) == 2:
- pos1 = self.polycoords[0]
- pos2 = self.polycoords[1]
-
- selected = digitClass.driver.GetSelected()
- dlg = VDigitZBulkDialog(parent=self, title=_("Z bulk-labeling dialog"),
- nselected=len(selected))
- if dlg.ShowModal() == wx.ID_OK:
- if digitClass.ZBulkLines(pos1, pos2, dlg.value.GetValue(),
- dlg.step.GetValue()) < 0:
- return
- self.UpdateMap(render=False, renderVector=True)
- elif digitToolbar.GetAction() == "typeConv":
- # -> feature type conversion
- # - point <-> centroid
- # - line <-> boundary
- if digitClass.TypeConvForSelectedLines() < 0:
- return
-
- if digitToolbar.GetAction() != "addLine":
- # unselect and re-render
- digitClass.driver.SetSelected([])
- self.polycoords = []
- self.UpdateMap(render=False)
-
- self.redrawAll = True
- self.Refresh()
-
- event.Skip()
-
- def OnMiddleDown(self, event):
- """!
- Middle mouse button pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- # digitization tool
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- if (digitToolbar.GetAction() == "addLine" and \
- digitToolbar.GetAction('type') in ["line", "boundary"]) or \
- digitToolbar.GetAction() == "editLine":
- # add line or boundary -> remove last point from the line
- try:
- removed = self.polycoords.pop()
- Debug.msg(4, "BufferedWindow.OnMiddleDown(): polycoords_poped=%s" % \
- [removed,])
-
- self.mouse['begin'] = self.Cell2Pixel(self.polycoords[-1])
- except:
- pass
-
- if digitToolbar.GetAction() == "editLine":
- # remove last vertex & line
- if len(self.vdigitMove['id']) > 1:
- self.vdigitMove['id'].pop()
-
- self.UpdateMap(render=False, renderVector=False)
-
- elif digitToolbar.GetAction() in ["deleteLine", "moveLine", "splitLine",
- "addVertex", "removeVertex", "moveVertex",
- "copyCats", "flipLine", "mergeLine",
- "snapLine", "connectLine", "copyLine",
- "queryLine", "breakLine", "typeConv"]:
- # varios tools -> unselected selected features
- digitClass.driver.SetSelected([])
- if digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] and \
- hasattr(self, "vdigitMove"):
-
- del self.vdigitMove
-
- elif digitToolbar.GetAction() == "copyCats":
- try:
- del self.copyCatsList
- del self.copyCatsIds
- except AttributeError:
- pass
-
- elif digitToolbar.GetAction() == "copyLine":
- del self.copyIds
- if self.layerTmp:
- self.Map.DeleteLayer(self.layerTmp)
- self.UpdateMap(render=True, renderVector=False)
- del self.layerTmp
-
- self.polycoords = []
- self.UpdateMap(render=False) # render vector
-
- elif digitToolbar.GetAction() == "zbulkLine":
- # reset polyline
- self.polycoords = []
- digitClass.driver.SetSelected([])
- self.UpdateMap(render=False)
-
- self.redrawAll = True
-
- def OnMouseMoving(self, event):
- """!
- Motion event and no mouse buttons were pressed
- """
- digitToolbar = self.parent.toolbars['vdigit']
- if self.mouse["use"] == "pointer" and digitToolbar:
- digitClass = self.parent.digit
- self.mouse['end'] = event.GetPositionTuple()[:]
- Debug.msg (5, "BufferedWindow.OnMouseMoving(): coords=%f,%f" % \
- (self.mouse['end'][0], self.mouse['end'][1]))
- if digitToolbar.GetAction() == "addLine" and digitToolbar.GetAction('type') in ["line", "boundary"]:
- if len(self.polycoords) > 0:
- self.MouseDraw(pdc=self.pdcTmp, begin=self.Cell2Pixel(self.polycoords[-1]))
- elif digitToolbar.GetAction() in ["moveLine", "moveVertex", "editLine"] \
- and hasattr(self, "vdigitMove"):
- dx = self.mouse['end'][0] - self.mouse['begin'][0]
- dy = self.mouse['end'][1] - self.mouse['begin'][1]
-
- if len(self.vdigitMove['id']) > 0:
- # draw lines on new position
- if digitToolbar.GetAction() == "moveLine":
- # move line
- for id in self.vdigitMove['id']:
- self.pdcTmp.TranslateId(id, dx, dy)
- elif digitToolbar.GetAction() in ["moveVertex", "editLine"]:
- # move vertex ->
- # (vertex, left vertex, left line,
- # right vertex, right line)
-
- # do not draw static lines
- if digitToolbar.GetAction() == "moveVertex":
- self.polycoords = []
- ### self.pdcTmp.TranslateId(self.vdigitMove['id'][0], dx, dy)
- self.pdcTmp.RemoveId(self.vdigitMove['id'][0])
- if self.vdigitMove['id'][1] > 0: # previous vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][1])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][1]+1)
- self.polycoords.append((x, y))
- ### x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][0])[0:2])
- self.polycoords.append(self.Pixel2Cell(self.mouse['end']))
- if self.vdigitMove['id'][2] > 0: # next vertex
- x, y = self.Pixel2Cell(self.pdcTmp.GetIdBounds(self.vdigitMove['id'][2])[0:2])
- self.pdcTmp.RemoveId(self.vdigitMove['id'][2]-1)
- self.polycoords.append((x, y))
-
- self.ClearLines(pdc=self.pdcTmp)
- self.DrawLines(pdc=self.pdcTmp)
-
- else: # edit line
- try:
- if self.vdigitMove['id'][-1] > 0: # previous vertex
- self.MouseDraw(pdc=self.pdcTmp,
- begin=self.Cell2Pixel(self.polycoords[-1]))
- except: # no line
- self.vdigitMove['id'] = []
- self.polycoords = []
-
- self.Refresh() # TODO: use RefreshRect()
- self.mouse['begin'] = self.mouse['end']
-
- elif digitToolbar.GetAction() == "zbulkLine":
- if len(self.polycoords) == 1:
- # draw mouse moving
- self.MouseDraw(self.pdcTmp)
-
- event.Skip()
-
- def ClearLines(self, pdc=None):
- """!
- Clears temporary drawn lines from PseudoDC
- """
- if not pdc:
- pdc=self.pdcTmp
- try:
- pdc.ClearId(self.lineid)
- pdc.RemoveId(self.lineid)
- except:
- pass
-
- try:
- pdc.ClearId(self.plineid)
- pdc.RemoveId(self.plineid)
- except:
- pass
-
- Debug.msg(4, "BufferedWindow.ClearLines(): lineid=%s, plineid=%s" %
- (self.lineid, self.plineid))
-
- ### self.Refresh()
-
- return True
-
- def Pixel2Cell(self, (x, y)):
- """!
- Convert image coordinates to real word coordinates
-
- Input : int x, int y
- Output: float x, float y
- """
-
- try:
- x = int(x)
- y = int(y)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- east = w + x * res
- north = n - y * res
-
- # extent does not correspond with whole map canvas area...
- # east = self.Map.region['w'] + x * self.Map.region["ewres"]
- # north = self.Map.region['n'] - y * self.Map.region["nsres"]
-
- return (east, north)
-
- def Cell2Pixel(self, (east, north)):
- """!
- Convert real word coordinates to image coordinates
- """
-
- try:
- east = float(east)
- north = float(north)
- except:
- return None
-
- if self.Map.region["ewres"] > self.Map.region["nsres"]:
- res = self.Map.region["ewres"]
- else:
- res = self.Map.region["nsres"]
-
- w = self.Map.region["center_easting"] - (self.Map.width / 2) * res
- n = self.Map.region["center_northing"] + (self.Map.height / 2) * res
-
- # x = int((east - w) / res)
- # y = int((n - north) / res)
-
- x = (east - w) / res
- y = (n - north) / res
-
- return (x, y)
-
- def Zoom(self, begin, end, zoomtype):
- """!
- Calculates new region while (un)zoom/pan-ing
- """
- x1, y1 = begin
- x2, y2 = end
- newreg = {}
-
- # threshold - too small squares do not make sense
- # can only zoom to windows of > 5x5 screen pixels
- if abs(x2-x1) > 5 and abs(y2-y1) > 5 and zoomtype != 0:
-
- if x1 > x2:
- x1, x2 = x2, x1
- if y1 > y2:
- y1, y2 = y2, y1
-
- # zoom in
- if zoomtype > 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((x1, y1))
- newreg['e'], newreg['s'] = self.Pixel2Cell((x2, y2))
-
- # zoom out
- elif zoomtype < 0:
- newreg['w'], newreg['n'] = self.Pixel2Cell((-x1 * 2, -y1 * 2))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + 2 * \
- (self.Map.width - x2),
- self.Map.height + 2 * \
- (self.Map.height - y2)))
- # pan
- elif zoomtype == 0:
- dx = x1 - x2
- dy = y1 - y2
- newreg['w'], newreg['n'] = self.Pixel2Cell((dx, dy))
- newreg['e'], newreg['s'] = self.Pixel2Cell((self.Map.width + dx,
- self.Map.height + dy))
-
- # if new region has been calculated, set the values
- if newreg != {}:
- # LL locations
- if self.parent.Map.projinfo['proj'] == 'll':
- if newreg['n'] > 90.0:
- newreg['n'] = 90.0
- if newreg['s'] < -90.0:
- newreg['s'] = -90.0
-
- ce = newreg['w'] + (newreg['e'] - newreg['w']) / 2
- cn = newreg['s'] + (newreg['n'] - newreg['s']) / 2
-
- if hasattr(self, "vdigitMove"):
- # xo = self.Cell2Pixel((self.Map.region['center_easting'], self.Map.region['center_northing']))
- # xn = self.Cell2Pixel(ce, cn))
- tmp = self.Pixel2Cell(self.mouse['end'])
-
- # calculate new center point and display resolution
- self.Map.region['center_easting'] = ce
- self.Map.region['center_northing'] = cn
- self.Map.region["ewres"] = (newreg['e'] - newreg['w']) / self.Map.width
- self.Map.region["nsres"] = (newreg['n'] - newreg['s']) / self.Map.height
- self.Map.AlignExtentFromDisplay()
-
- if hasattr(self, "vdigitMove"):
- tmp1 = self.mouse['end']
- tmp2 = self.Cell2Pixel(self.vdigitMove['begin'])
- dx = tmp1[0] - tmp2[0]
- dy = tmp1[1] - tmp2[1]
- self.vdigitMove['beginDiff'] = (dx, dy)
- for id in self.vdigitMove['id']:
- self.pdcTmp.RemoveId(id)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- if self.redrawAll is False:
- self.redrawAll = True
-
- def ZoomBack(self):
- """!
- Zoom to previous extents in zoomhistory list
- """
- zoom = list()
-
- if len(self.zoomhistory) > 1:
- self.zoomhistory.pop()
- zoom = self.zoomhistory[-1]
-
- if len(self.zoomhistory) < 2: # disable tool
- self.parent.toolbars['map'].Enable('zoomback', enable = False)
-
- # zoom to selected region
- self.Map.GetRegion(n = zoom[0], s = zoom[1],
- e = zoom[2], w = zoom[3],
- update = True)
- # update map
- self.UpdateMap()
-
- # update statusbar
- self.parent.StatusbarUpdate()
-
- def ZoomHistory(self, n, s, e, w):
- """!
- Manages a list of last 10 zoom extents
-
- Return removed history item if exists
- """
- removed = None
- self.zoomhistory.append((n,s,e,w))
-
- if len(self.zoomhistory) > 10:
- removed = self.zoomhistory.pop(0)
-
- if removed:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s, removed=%s" %
- (self.zoomhistory, removed))
- else:
- Debug.msg(4, "BufferedWindow.ZoomHistory(): hist=%s" %
- (self.zoomhistory))
-
- if len(self.zoomhistory) > 1:
- self.parent.toolbars['map'].Enable('zoomback')
-
- return removed
-
- def OnZoomToMap(self, event):
- """!
- Set display extents to match selected raster (including NULLs)
- or vector map.
- """
- self.ZoomToMap()
-
- def OnZoomToRaster(self, event):
- """!
- Set display extents to match selected raster map (ignore NULLs)
- """
- self.ZoomToMap(ignoreNulls = True)
-
- def ZoomToMap(self, layers = None, ignoreNulls = False, render = True):
- """!
- Set display extents to match selected raster
- or vector map(s).
-
- @param layer list of layers to be zoom to
- @param ignoreNulls True to ignore null-values
- @param render True to re-render display
- """
- zoomreg = {}
-
- if not layers:
- layers = self.GetSelectedLayer(multi = True)
-
- if not layers:
- return
-
- rast = []
- vect = []
- updated = False
- for l in layers:
- # only raster/vector layers are currently supported
- if l.type == 'raster':
- rast.append(l.name)
- elif l.type == 'vector':
- digitToolbar = self.parent.toolbars['vdigit']
- if digitToolbar and digitToolbar.GetLayer() == l:
- w, s, b, e, n, t = self.parent.digit.driver.GetMapBoundingBox()
- self.Map.GetRegion(n=n, s=s, w=w, e=e,
- update=True)
- updated = True
- else:
- vect.append(l.name)
-
- if not updated:
- self.Map.GetRegion(rast = rast,
- vect = vect,
- update = True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- if render:
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToWind(self, event):
- """!
- Set display geometry to match computational
- region settings (set with g.region)
- """
- self.Map.region = self.Map.GetRegion()
- ### self.Map.SetRegion(windres=True)
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def ZoomToDefault(self, event):
- """!
- Set display geometry to match default region settings
- """
- self.Map.region = self.Map.GetRegion(default=True)
- self.Map.AdjustRegion() # aling region extent to the display
-
- self.ZoomHistory(self.Map.region['n'], self.Map.region['s'],
- self.Map.region['e'], self.Map.region['w'])
-
- self.UpdateMap()
-
- self.parent.StatusbarUpdate()
-
- def DisplayToWind(self, event):
- """!
- Set computational region (WIND file) to
- match display extents
- """
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- # We ONLY want to set extents here. Don't mess with resolution. Leave that
- # for user to set explicitly with g.region
- new = self.Map.AlignResolution()
- gcmd.RunCommand('g.region',
- parent = self,
- overwrite = True,
- n = new['n'],
- s = new['s'],
- e = new['e'],
- w = new['w'],
- rows = int(new['rows']),
- cols = int(new['cols']))
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def ZoomToSaved(self, event):
- """!Set display geometry to match extents in
- saved region file
- """
- dlg = gdialogs.SavedRegion(parent = self,
- title = _("Zoom to saved region extents"),
- loadsave='load')
-
- if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
- dlg.Destroy()
- return
-
- if not grass.find_file(name = dlg.wind, element = 'windows')['name']:
- wx.MessageBox(parent = self,
- message = _("Region <%s> not found. Operation canceled.") % dlg.wind,
- caption = _("Error"), style = wx.ICON_ERROR | wx.OK | wx.CENTRE)
- dlg.Destroy()
- return
-
- self.Map.GetRegion(regionName = dlg.wind,
- update = True)
-
- dlg.Destroy()
-
- self.ZoomHistory(self.Map.region['n'],
- self.Map.region['s'],
- self.Map.region['e'],
- self.Map.region['w'])
-
- self.UpdateMap()
-
- def SaveDisplayRegion(self, event):
- """!
- Save display extents to named region file.
- """
-
- dlg = gdialogs.SavedRegion(parent = self,
- title = _("Save display extents to region file"),
- loadsave='save')
-
- if dlg.ShowModal() == wx.ID_CANCEL or not dlg.wind:
- dlg.Destroy()
- return
-
- # test to see if it already exists and ask permission to overwrite
- if grass.find_file(name = dlg.wind, element = 'windows')['name']:
- overwrite = wx.MessageBox(parent = self,
- message = _("Region file <%s> already exists. "
- "Do you want to overwrite it?") % (dlg.wind),
- caption = _("Warning"), style = wx.YES_NO | wx.CENTRE)
- if (overwrite == wx.YES):
- self.SaveRegion(dlg.wind)
- else:
- self.SaveRegion(dlg.wind)
-
- dlg.Destroy()
-
- def SaveRegion(self, wind):
- """!Save region settings
-
- @param wind region name
- """
- new = self.Map.GetCurrentRegion()
-
- tmpreg = os.getenv("GRASS_REGION")
- if tmpreg:
- del os.environ["GRASS_REGION"]
-
- gcmd.RunCommand('g.region',
- overwrite = True,
- parent = self,
- flags = 'u',
- n = new['n'],
- s = new['s'],
- e = new['e'],
- w = new['w'],
- rows = int(new['rows']),
- cols = int(new['cols']),
- save = wind)
-
- if tmpreg:
- os.environ["GRASS_REGION"] = tmpreg
-
- def Distance(self, beginpt, endpt, screen=True):
- """!Calculete distance
-
- LL-locations not supported
-
- @todo Use m.distance
-
- @param beginpt first point
- @param endpt second point
- @param screen True for screen coordinates otherwise EN
- """
- x1, y1 = beginpt
- x2, y2 = endpt
- if screen:
- dEast = (x2 - x1) * self.Map.region["ewres"]
- dNorth = (y2 - y1) * self.Map.region["nsres"]
- else:
- dEast = (x2 - x1)
- dNorth = (y2 - y1)
-
- return (math.sqrt(math.pow((dEast),2) + math.pow((dNorth),2)), (dEast, dNorth))
Deleted: grass-addons/gui/wxpython/data_catalog/newprompt.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/newprompt.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/newprompt.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,604 +0,0 @@
-"""!
- at package prompt.py
-
- at brief GRASS prompt
-
-Classes:
- - GPrompt
- - PromptListCtrl
- - TextCtrlAutoComplete
-
- at todo: fix TextCtrlAutoComplete to work also on Macs (missing
-wx.PopupWindow())
-
-(C) 2009 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 Martin Landa <landa.martin gmail.com>
- at author Mohammed Rashad K.M <rashadkm at gmail dot com> (only modified for DataCatalog)
-"""
-
-import os
-import sys
-import shlex
-
-import wx
-import wx.lib.mixins.listctrl as listmix
-
-from grass.script import core as grass
-
-import globalvar
-import utils
-import menuform
-import menudata
-import goutput
-
-class GPrompt:
- """!Interactive GRASS prompt"""
- def __init__(self, parent):
- # self.parent = parent # GMFrame
-
- # dictionary of modules (description, keywords, ...)
-
-
-
- self.parent=parent.GetParent()
- winlist = self.parent.GetChildren()
- for win in winlist:
- if type(win) == wx._windows.StatusBar:
- self.statusbar=win
- self.modules = self.parent.menudata.GetModules()
-
- self.panel, self.input = self.__create()
- #self.goutput = goutput
- self.goutput = goutput.GMConsole(self.parent, pageid=1)
- self.goutput.Hide()
- self.goutput.Redirect()
-
- def __create(self):
- """!Create widget"""
- cmdprompt = wx.Panel(self.parent)
-
- #
- # search
- #
- #searchTxt = wx.StaticText(parent = cmdprompt, id = wx.ID_ANY, label = _("Search:"))
-
- #self.searchBy = wx.Choice(parent = cmdprompt, id = wx.ID_ANY, choices = [_("description"), _("keywords")])
- winHeight =30
-
- #self.search = wx.TextCtrl(parent = cmdprompt, id = wx.ID_ANY, value = "", size = (-1, 25))
-
- label = wx.Button(parent = cmdprompt, id = wx.ID_ANY,
- label = _("Cmd >"), size = (-1, winHeight))
- label.SetToolTipString(_("Click for erasing command prompt"))
-
- ### todo: fix TextCtrlAutoComplete to work also on Macs
- ### reason: missing wx.PopupWindow()
-
- try:
- cmdinput = TextCtrlAutoComplete(parent = cmdprompt, id = wx.ID_ANY,
- value = "",
- style = wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
- size = (-1, winHeight),
- statusbar = self.statusbar)
- except NotImplementedError:
- # wx.PopupWindow may be not available in wxMac
- # see http://trac.wxwidgets.org/ticket/9377
- cmdinput = wx.TextCtrl(parent = cmdprompt, id = wx.ID_ANY,
- value = "",
- style=wx.TE_LINEWRAP | wx.TE_PROCESS_ENTER,
- size = (-1, 25))
-# self.searchBy.Enable(False)
- #self.search.Enable(False)
-
- cmdinput.SetFont(wx.Font(10, wx.FONTFAMILY_MODERN, wx.NORMAL, wx.NORMAL, 0, ''))
-
- wx.CallAfter(cmdinput.SetInsertionPoint, 0)
-
- # bidnings
- label.Bind(wx.EVT_BUTTON, self.OnCmdErase)
- cmdinput.Bind(wx.EVT_TEXT_ENTER, self.OnRunCmd)
- cmdinput.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar)
- #self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
-
- # layout
- sizer = wx.GridBagSizer(hgap=5, vgap=5)
- sizer.AddGrowableCol(2)
-
-
-
- sizer.Add(item = label,
- flag = wx.LEFT | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_CENTER,
- border = 5,
- pos = (0, 1))
-
- sizer.Add(item = cmdinput,
- flag = wx.EXPAND | wx.RIGHT,
- border = 5,
- pos = (0, 2))
-
- cmdprompt.SetSizer(sizer)
- sizer.Fit(cmdprompt)
- cmdprompt.Layout()
-
- return cmdprompt, cmdinput
-
- def __checkKey(self, text, keywords):
- """!Check if text is in keywords"""
- found = 0
- keys = text.split(',')
- if len(keys) > 1: # -> multiple keys
- for k in keys[:-1]:
- k = k.strip()
- for key in keywords:
- if k == key: # full match
- found += 1
- break
- k = keys[-1].strip()
- for key in keywords:
- if k in key: # partial match
- found +=1
- break
- else:
- for key in keywords:
- if text in key: # partial match
- found +=1
- break
-
- if found == len(keys):
- return True
-
- return False
-
- def GetPanel(self):
- """!Get main widget panel"""
- return self.panel
-
- def GetInput(self):
- """!Get main prompt widget"""
- return self.input
-
- def OnCmdErase(self, event):
- """!Erase command prompt"""
- self.input.SetValue('')
-
- def OnRunCmd(self, event):
- """!Run command"""
- cmdString = event.GetString()
-
- #if self.parent.GetName() != "LayerManager":
- # return
-
- if cmdString[:2] == 'd.' and not self.parent.current:
- self.parent.NewDisplay()
-
- cmd = shlex.split(str(cmdString))
- if len(cmd) > 1:
- self.goutput.RunCmd(cmd, switchPage = True)
- else:
- self.goutput.RunCmd(cmd, switchPage = False)
-
- self.OnUpdateStatusBar(None)
-
- def OnUpdateStatusBar(self, event):
- """!Update Layer Manager status bar"""
- if self.parent.GetName() != "LayerManager":
- return
-
- if event is None:
- self.parent.statusbar.SetStatusText("")
- else:
- self.parent.statusbar.SetStatusText(_("Type GRASS command and run by pressing ENTER"))
- event.Skip()
-
-# def OnSearchModule(self, event):
-# """!Search module by metadata"""
-# print "here"
-# text = event.GetString()
-# if not text:
-# self.input.SetChoices(globalvar.grassCmd['all'])
-# return
-#
-# modules = []
-# for module, data in self.modules.iteritems():
-#
-# if self.searchBy.GetSelection() == 0: # -> description
-# if text in data['desc']:
-# modules.append(module)
-# else: # -> keywords
-# if self.__checkKey(text, data['keywords']):
-# modules.append(module)
-#
-# self.statusbar.SetStatusText(_("%d modules found") % len(modules))
-# self.input.SetChoices(modules)
-
-class PromptListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
- def __init__(self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition,
- size = wx.DefaultSize, style = 0):
- wx.ListCtrl.__init__(self, parent, id, pos, size, style)
- listmix.ListCtrlAutoWidthMixin.__init__(self)
-
-class TextCtrlAutoComplete(wx.ComboBox, listmix.ColumnSorterMixin):
- def __init__ (self, parent, statusbar,
- id = wx.ID_ANY, choices = [], **kwargs):
- """!Constructor works just like wx.TextCtrl except you can pass in a
- list of choices. You can also change the choice list at any time
- by calling setChoices.
-
- Inspired by http://wiki.wxpython.org/TextCtrlAutoComplete
- """
- self.statusbar = statusbar
-
- if kwargs.has_key('style'):
- kwargs['style'] = wx.TE_PROCESS_ENTER | kwargs['style']
- else:
- kwargs['style'] = wx.TE_PROCESS_ENTER
-
- wx.ComboBox.__init__(self, parent, id, **kwargs)
-
- # some variables
- self._choices = choices
- self._hideOnNoMatch = True
- self._module = None # currently selected module
- self._choiceType = None # type of choice (module, params, flags, raster, vector ...)
- self._screenheight = wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y)
-
- # sort variable needed by listmix
- self.itemDataMap = dict()
-
- # widgets
- try:
- self.dropdown = wx.PopupWindow(self)
- except NotImplementedError:
- self.Destroy()
- raise NotImplementedError
-
- # create the list and bind the events
- self.dropdownlistbox = PromptListCtrl(parent = self.dropdown,
- style = wx.LC_REPORT | wx.LC_SINGLE_SEL | \
- wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER,
- pos = wx.Point(0, 0))
-
- listmix.ColumnSorterMixin.__init__(self, 1)
-
- # set choices (list of GRASS modules)
- self._choicesCmd = globalvar.grassCmd['all']
- self._choicesMap = dict()
- for type in ('raster', 'vector'):
- self._choicesMap[type] = grass.list_strings(type = type[:4])
- # first search for GRASS module
- self.SetChoices(self._choicesCmd)
-
- self.SetMinSize(self.GetSize())
- # read history
- self.SetHistoryItems()
-
- # bindings...
- self.Bind(wx.EVT_KILL_FOCUS, self.OnControlChanged)
- self.Bind(wx.EVT_TEXT, self.OnEnteredText)
- self.Bind(wx.EVT_KEY_DOWN , self.OnKeyDown)
- ### self.Bind(wx.EVT_LEFT_DOWN, self.OnClick)
-
- # if need drop down on left click
- self.dropdown.Bind(wx.EVT_LISTBOX , self.OnListItemSelected, self.dropdownlistbox)
- self.dropdownlistbox.Bind(wx.EVT_LEFT_DOWN, self.OnListClick)
- self.dropdownlistbox.Bind(wx.EVT_LEFT_DCLICK, self.OnListDClick)
- self.dropdownlistbox.Bind(wx.EVT_LIST_COL_CLICK, self.OnListColClick)
-
- self.Bind(wx.EVT_COMBOBOX, self.OnCommandSelect)
-
- def _updateDataList(self, choices):
- """!Update data list"""
- # delete, if need, all the previous data
- if self.dropdownlistbox.GetColumnCount() != 0:
- self.dropdownlistbox.DeleteAllColumns()
- self.dropdownlistbox.DeleteAllItems()
- # and update the dict
- if choices:
- for numVal, data in enumerate(choices):
- self.itemDataMap[numVal] = data
- else:
- numVal = 0
- self.SetColumnCount(numVal)
-
- def _setListSize(self):
- """!Set list size"""
- choices = self._choices
- longest = 0
- for choice in choices:
- longest = max(len(choice), longest)
- longest += 3
- itemcount = min(len( choices ), 7) + 2
- charheight = self.dropdownlistbox.GetCharHeight()
- charwidth = self.dropdownlistbox.GetCharWidth()
- self.popupsize = wx.Size(charwidth*longest, charheight*itemcount)
- self.dropdownlistbox.SetSize(self.popupsize)
- self.dropdown.SetClientSize(self.popupsize)
-
- def _showDropDown(self, show = True):
- """!Either display the drop down list (show = True) or hide it
- (show = False).
- """
- if show:
- size = self.dropdown.GetSize()
- width, height = self.GetSizeTuple()
- x, y = self.ClientToScreenXY(0, height)
- if size.GetWidth() != width:
- size.SetWidth(width)
- self.dropdown.SetSize(size)
- self.dropdownlistbox.SetSize(self.dropdown.GetClientSize())
- if (y + size.GetHeight()) < self._screenheight:
- self.dropdown.SetPosition(wx.Point(x, y))
- else:
- self.dropdown.SetPosition(wx.Point(x, y - height - size.GetHeight()))
-
- self.dropdown.Show(show)
-
- def _listItemVisible(self):
- """!Moves the selected item to the top of the list ensuring it is
- always visible.
- """
- toSel = self.dropdownlistbox.GetFirstSelected()
- if toSel == -1:
- return
- self.dropdownlistbox.EnsureVisible(toSel)
-
- def _setValueFromSelected(self):
- """!Sets the wx.TextCtrl value from the selected wx.ListCtrl item.
- Will do nothing if no item is selected in the wx.ListCtrl.
- """
- sel = self.dropdownlistbox.GetFirstSelected()
- if sel > -1:
- if self._colFetch != -1:
- col = self._colFetch
- else:
- col = self._colSearch
- itemtext = self.dropdownlistbox.GetItem(sel, col).GetText()
-
- cmd = shlex.split(str(self.GetValue()))
- if len(cmd) > 1:
- # -> append text (skip last item)
- if self._choiceType == 'param':
- self.SetValue(' '.join(cmd[:-1]) + ' ' + itemtext + '=')
- optType = self._module.get_param(itemtext)['prompt']
- if optType in ('raster', 'vector'):
- # -> raster/vector map
- self.SetChoices(self._choicesMap[optType], optType)
- elif self._choiceType == 'flag':
- if len(itemtext) > 1:
- prefix = '--'
- else:
- prefix = '-'
- self.SetValue(' '.join(cmd[:-1]) + ' ' + prefix + itemtext)
- elif self._choiceType in ('raster', 'vector'):
- self.SetValue(' '.join(cmd[:-1]) + ' ' + cmd[-1].split('=', 1)[0] + '=' + itemtext)
- else:
- # -> reset text
- self.SetValue(itemtext + ' ')
- self.SetInsertionPointEnd()
-
- self._showDropDown(False)
-
- def GetListCtrl(self):
- """!Method required by listmix.ColumnSorterMixin"""
- return self.dropdownlistbox
-
- def SetHistoryItems(self):
- """!Read history file and update combobox items"""
- env = grass.gisenv()
- try:
- fileHistory = open(os.path.join(env['GISDBASE'],
- env['LOCATION_NAME'],
- env['MAPSET'],
- '.bash_history'), 'r')
- except IOError:
- self.SetItems([])
- return
-
- try:
- hist = []
- for line in fileHistory.readlines():
- hist.append(line.replace('\n', ''))
-
- self.SetItems(hist)
- finally:
- fileHistory.close()
- return
-
- self.SetItems([])
-
- def SetChoices(self, choices, type = 'module'):
- """!Sets the choices available in the popup wx.ListBox.
- The items will be sorted case insensitively.
- """
- self._choices = choices
- self._choiceType = type
-
- self.dropdownlistbox.SetWindowStyleFlag(wx.LC_REPORT | wx.LC_SINGLE_SEL | \
- wx.LC_SORT_ASCENDING | wx.LC_NO_HEADER)
- if not isinstance(choices, list):
- self._choices = [ x for x in choices ]
- if self._choiceType not in ('raster', 'vector'):
- # do not sort raster/vector maps
- utils.ListSortLower(self._choices)
-
- self._updateDataList(self._choices)
-
- self.dropdownlistbox.InsertColumn(0, "")
- for num, colVal in enumerate(self._choices):
- index = self.dropdownlistbox.InsertImageStringItem(sys.maxint, colVal, -1)
- self.dropdownlistbox.SetStringItem(index, 0, colVal)
- self.dropdownlistbox.SetItemData(index, num)
- self._setListSize()
-
- # there is only one choice for both search and fetch if setting a single column:
- self._colSearch = 0
- self._colFetch = -1
-
- def OnClick(self, event):
- """Left mouse button pressed"""
- sel = self.dropdownlistbox.GetFirstSelected()
- if not self.dropdown.IsShown():
- if sel > -1:
- self.dropdownlistbox.Select(sel)
- else:
- self.dropdownlistbox.Select(0)
- self._listItemVisible()
- self._showDropDown()
- else:
- self.dropdown.Hide()
-
- def OnCommandSelect(self, event):
- """!Command selected from history"""
- self.SetFocus()
-
- def OnListClick(self, evt):
- """!Left mouse button pressed"""
- toSel, flag = self.dropdownlistbox.HitTest( evt.GetPosition() )
- #no values on poition, return
- if toSel == -1: return
- self.dropdownlistbox.Select(toSel)
-
- def OnListDClick(self, evt):
- """!Mouse button double click"""
- self._setValueFromSelected()
-
- def OnListColClick(self, evt):
- """!Left mouse button pressed on column"""
- col = evt.GetColumn()
- # reverse the sort
- if col == self._colSearch:
- self._ascending = not self._ascending
- self.SortListItems( evt.GetColumn(), ascending=self._ascending )
- self._colSearch = evt.GetColumn()
- evt.Skip()
-
- def OnListItemSelected(self, event):
- """!Item selected"""
- self._setValueFromSelected()
- event.Skip()
-
- def OnEnteredText(self, event):
- """!Text entered"""
- text = event.GetString()
-
- if not text:
- # control is empty; hide dropdown if shown:
- if self.dropdown.IsShown():
- self._showDropDown(False)
- event.Skip()
- return
-
- try:
- cmd = shlex.split(str(text))
- except ValueError, e:
- self.statusbar.SetStatusText(str(e))
- cmd = text.split(' ')
-
- pattern = str(text)
- if len(cmd) > 1:
- # search for module's options
- if cmd[0] in self._choicesCmd and not self._module:
- try:
- self._module = menuform.GUI().ParseInterface(cmd = cmd)
- except IOError:
- self._module = None
-
- if self._module:
- if len(cmd[-1].split('=', 1)) == 1:
- # new option
- if cmd[-1][0] == '-':
- # -> flags
- self.SetChoices(self._module.get_list_flags(), type = 'flag')
- pattern = cmd[-1].lstrip('-')
- else:
- # -> options
- self.SetChoices(self._module.get_list_params(), type = 'param')
- pattern = cmd[-1]
- else:
- # value
- pattern = cmd[-1].split('=', 1)[1]
- else:
- # search for GRASS modules
- if self._module:
- # -> switch back to GRASS modules list
- self.SetChoices(self._choicesCmd)
- self._module = None
- self._choiceType = None
-
- found = False
- choices = self._choices
- for numCh, choice in enumerate(choices):
- if choice.lower().startswith(pattern):
- found = True
- if found:
- self._showDropDown(True)
- item = self.dropdownlistbox.GetItem(numCh)
- toSel = item.GetId()
- self.dropdownlistbox.Select(toSel)
- break
-
- if not found:
- self.dropdownlistbox.Select(self.dropdownlistbox.GetFirstSelected(), False)
- if self._hideOnNoMatch:
- self._showDropDown(False)
- if self._module and '=' not in cmd[-1]:
- message = ''
- if cmd[-1][0] == '-': # flag
- message = "Warning: flag <%s> not found in '%s'" % \
- (cmd[-1][1:], self._module.name)
- else: # option
- message = "Warning: option <%s> not found in '%s'" % \
- (cmd[-1], self._module.name)
- self.statusbar.SetStatusText(message)
-
- if self._module and len(cmd[-1]) == 2 and cmd[-1][-2] == '=':
- optType = self._module.get_param(cmd[-1][:-2])['prompt']
- if optType in ('raster', 'vector'):
- # -> raster/vector map
- self.SetChoices(self._choicesMap[optType], optType)
-
- self._listItemVisible()
-
- event.Skip()
-
- def OnKeyDown (self, event):
- """!Do some work when the user press on the keys: up and down:
- move the cursor left and right: move the search
- """
- skip = True
- sel = self.dropdownlistbox.GetFirstSelected()
- visible = self.dropdown.IsShown()
- KC = event.GetKeyCode()
- if KC == wx.WXK_DOWN:
- if sel < (self.dropdownlistbox.GetItemCount() - 1):
- self.dropdownlistbox.Select(sel + 1)
- self._listItemVisible()
- self._showDropDown()
- skip = False
- elif KC == wx.WXK_UP:
- if sel > 0:
- self.dropdownlistbox.Select(sel - 1)
- self._listItemVisible()
- self._showDropDown()
- skip = False
-
- if visible:
- if event.GetKeyCode() == wx.WXK_RETURN:
- self._setValueFromSelected()
- skip = False
- if event.GetKeyCode() == wx.WXK_ESCAPE:
- self._showDropDown(False)
- skip = False
- if skip:
- event.Skip()
-
- def OnControlChanged(self, event):
- """!Control changed"""
- if self.IsShown():
- self._showDropDown(False)
-
- event.Skip()
Deleted: grass-addons/gui/wxpython/data_catalog/toolbars.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/toolbars.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/toolbars.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,1380 +0,0 @@
-"""
- at package toolbar
-
- at brief Toolbars for Map Display window
-
-Classes:
- - AbstractToolbar
- - MapToolbar
- - GRToolbar
- - GCPToolbar
- - VDigitToolbar
- - ProfileToolbar
- - NvizToolbar
-
-(C) 2007-2008 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 Michael Barton
- at author Jachym Cepicky
- at author Martin Landa <landa.martin gmail.com>
-"""
-
-import wx
-import os, sys
-import platform
-
-import globalvar
-import gcmd
-version = os.getenv("GRASS_VERSION")
-if version == "6.4.0svn":
- import grassenv
-
-import gdialogs
-import vdigit
-from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
-from debug import Debug as Debug
-from icon import Icons as Icons
-from preferences import globalSettings as UserSettings
-
-gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
-sys.path.append(gmpath)
-
-class AbstractToolbar(object):
- """Abstract toolbar class"""
- def __init__(self):
- pass
-
- def InitToolbar(self, parent, toolbar, toolData):
- """Initialize toolbar, i.e. add tools to the toolbar
-
- @return list of ids (of added tools)
- """
-
- for tool in toolData:
- self.CreateTool(parent, toolbar, *tool)
-
- self._toolbar = toolbar
- self._data = toolData
-
- self.parent = parent
-
- def ToolbarData(self):
- """Toolbar data"""
- return None
-
- def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
- shortHelp, longHelp, handler):
- """Add tool to the toolbar
-
- @return id of tool
- """
-
- bmpDisabled=wx.NullBitmap
-
- if label:
- Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
- (tool, label, bitmap))
- toolWin = toolbar.AddLabelTool(tool, label, bitmap,
- bmpDisabled, kind,
- shortHelp, longHelp)
- parent.Bind(wx.EVT_TOOL, handler, toolWin)
- else: # add separator
- toolbar.AddSeparator()
-
- return tool
-
- def GetToolbar(self):
- """Get toolbar widget reference"""
- return self._toolbar
-
- def EnableLongHelp(self, enable=True):
- """Enable/disable long help
-
- @param enable True for enable otherwise disable
- """
- for tool in self._data:
- if tool[0] == '': # separator
- continue
-
- if enable:
- self._toolbar.SetToolLongHelp(tool[0], tool[5])
- else:
- self._toolbar.SetToolLongHelp(tool[0], "")
-
- def OnTool(self, event):
- """Tool selected"""
- if self.parent.toolbars['vdigit']:
- # update vdigit toolbar (unselect currently selected tool)
- id = self.parent.toolbars['vdigit'].GetAction(type='id')
- self.parent.toolbars['vdigit'].GetToolbar().ToggleTool(id, False)
-
- if event:
- # deselect previously selected tool
- id = self.action.get('id', -1)
- if id != event.GetId():
- self._toolbar.ToggleTool(self.action['id'], False)
- else:
- self._toolbar.ToggleTool(self.action['id'], True)
-
- self.action['id'] = event.GetId()
-
- event.Skip()
- else:
- # initialize toolbar
- self._toolbar.ToggleTool(self.action['id'], True)
-
- def GetAction(self, type='desc'):
- """Get current action info"""
- return self.action.get(type, '')
-
- def SelectDefault(self, event):
- """Select default tool"""
- self._toolbar.ToggleTool(self.defaultAction['id'], True)
- self.defaultAction['bind'](event)
- self.action = { 'id' : self.defaultAction['id'],
- 'desc' : self.defaultAction.get('desc', '') }
-
- def FixSize(self, width):
- """Fix toolbar width on Windows
-
- @todo Determine why combobox causes problems here
- """
- if platform.system() == 'Windows':
- size = self._toolbar.GetBestSize()
- self._toolbar.SetSize((size[0] + width, size[1]))
-
-class MapToolbar(AbstractToolbar):
- """
- Main Map Display toolbar
- """
-
- def __init__(self, mapdisplay, map):
- AbstractToolbar.__init__(self)
-
- self.mapcontent = map
- self.mapdisplay = mapdisplay
-
- self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
- self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
-
- self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
-
- # optional tools
- self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value=_('2D view'),
- choices=[_('2D view'), _('3D view'), _('Digitize')],
- style=wx.CB_READONLY, size=(90, -1))
-
- self.comboid = self.toolbar.AddControl(self.combo)
- self.mapdisplay.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
-
- # realize the toolbar
- self.toolbar.Realize()
-
- # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
- self.combo.Hide()
- self.combo.Show()
-
- # default action
- self.action = { 'id' : self.pointer }
- self.defaultAction = { 'id' : self.pointer,
- 'bind' : self.mapdisplay.OnPointer }
- self.OnTool(None)
-
- self.FixSize(width = 90)
-
- def ToolbarData(self):
- """Toolbar data"""
-
- self.displaymap = wx.NewId()
- self.rendermap = wx.NewId()
- self.erase = wx.NewId()
- self.pointer = wx.NewId()
- self.query = wx.NewId()
- self.pan = wx.NewId()
- self.zoomin = wx.NewId()
- self.zoomout = wx.NewId()
- self.zoomback = wx.NewId()
- self.zoommenu = wx.NewId()
- self.analyze = wx.NewId()
- self.dec = wx.NewId()
- self.savefile = wx.NewId()
- self.printmap = wx.NewId()
-
- # tool, label, bitmap, kind, shortHelp, longHelp, handler
- return (
- (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
- self.mapdisplay.OnDraw),
- (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
- self.mapdisplay.OnRender),
- (self.erase, "erase", Icons["erase"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
- self.mapdisplay.OnErase),
- ("", "", "", "", "", "", ""),
- (self.pointer, "pointer", Icons["pointer"].GetBitmap(),
- wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
- self.mapdisplay.OnPointer),
- (self.query, "query", Icons["query"].GetBitmap(),
- wx.ITEM_CHECK, Icons["query"].GetLabel(), Icons["query"].GetDesc(),
- self.mapdisplay.OnQuery),
- (self.pan, "pan", Icons["pan"].GetBitmap(),
- wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
- self.mapdisplay.OnPan),
- (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
- wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
- self.mapdisplay.OnZoomIn),
- (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
- wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
- self.mapdisplay.OnZoomOut),
- (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
- self.mapdisplay.OnZoomBack),
- (self.zoommenu, "zoommenu", Icons["zoommenu"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoommenu"].GetLabel(), Icons["zoommenu"].GetDesc(),
- self.mapdisplay.OnZoomMenu),
- ("", "", "", "", "", "", ""),
- (self.analyze, "analyze", Icons["analyze"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["analyze"].GetLabel(), Icons["analyze"].GetDesc(),
- self.mapdisplay.OnAnalyze),
- ("", "", "", "", "", "", ""),
- (self.dec, "overlay", Icons["overlay"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["overlay"].GetLabel(), Icons["overlay"].GetDesc(),
- self.mapdisplay.OnDecoration),
- ("", "", "", "", "", "", ""),
- (self.savefile, "savefile", Icons["savefile"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
- self.mapdisplay.SaveToFile),
- (self.printmap, "printmap", Icons["printmap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
- self.mapdisplay.PrintMenu),
- ("", "", "", "", "", "", "")
- )
-
- def OnSelectTool(self, event):
- """
- Select / enable tool available in tools list
- """
- tool = event.GetSelection()
-
- if tool == 0:
- self.ExitToolbars()
- self.Enable2D(True)
-
- elif tool == 1 and not self.mapdisplay.toolbars['nviz']:
- self.ExitToolbars()
- self.mapdisplay.AddToolbar("nviz")
-
- elif tool == 2 and not self.mapdisplay.toolbars['vdigit']:
- self.ExitToolbars()
- self.mapdisplay.AddToolbar("vdigit")
-
- def ExitToolbars(self):
- if self.mapdisplay.toolbars['vdigit']:
- self.mapdisplay.toolbars['vdigit'].OnExit()
- if self.mapdisplay.toolbars['nviz']:
- self.mapdisplay.toolbars['nviz'].OnExit()
-
- def Enable2D(self, enabled):
- """Enable/Disable 2D display mode specific tools"""
- for tool in (self.pointer,
- self.query,
- self.pan,
- self.zoomin,
- self.zoomout,
- self.zoomback,
- self.zoommenu,
- self.analyze,
- self.dec,
- self.savefile,
- self.printmap):
- self.toolbar.EnableTool(tool, enabled)
-
-class GRToolbar(AbstractToolbar):
- """
- Georectification Display toolbar
- """
-
- def __init__(self, mapdisplay, map):
- self.mapcontent = map
- self.mapdisplay = mapdisplay
-
- self.toolbar = wx.ToolBar(parent=self.mapdisplay, id=wx.ID_ANY)
-
- # self.SetToolBar(self.toolbar)
- self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
-
- self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
-
- # realize the toolbar
- self.toolbar.Realize()
-
- def ToolbarData(self):
- """Toolbar data"""
-
- self.displaymap = wx.NewId()
- self.rendermap = wx.NewId()
- self.erase = wx.NewId()
- self.gcpset = wx.NewId()
- self.pan = wx.NewId()
- self.zoomin = wx.NewId()
- self.zoomout = wx.NewId()
- self.zoomback = wx.NewId()
- self.zoomtomap = wx.NewId()
-
- # tool, label, bitmap, kind, shortHelp, longHelp, handler
- return (
- (self.displaymap, "displaymap", Icons["displaymap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["displaymap"].GetLabel(), Icons["displaymap"].GetDesc(),
- self.mapdisplay.OnDraw),
- (self.rendermap, "rendermap", Icons["rendermap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["rendermap"].GetLabel(), Icons["rendermap"].GetDesc(),
- self.mapdisplay.OnRender),
- (self.erase, "erase", Icons["erase"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
- self.mapdisplay.OnErase),
- ("", "", "", "", "", "", ""),
- (self.gcpset, "grGcpSet", Icons["grGcpSet"].GetBitmap(),
- wx.ITEM_RADIO, Icons["grGcpSet"].GetLabel(), Icons["grGcpSet"].GetDesc(),
- self.mapdisplay.OnPointer),
- (self.pan, "pan", Icons["pan"].GetBitmap(),
- wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
- self.mapdisplay.OnPan),
- (self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
- wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
- self.mapdisplay.OnZoomIn),
- (self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
- wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
- self.mapdisplay.OnZoomOut),
- (self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
- self.mapdisplay.OnZoomBack),
- (self.zoomtomap, "zoomtomap", Icons["zoommenu"].GetBitmap(),
- wx.ITEM_NORMAL, _("Zoom to map"), _("Zoom to displayed map"),
- self.OnZoomMap),
- ("", "", "", "", "", "", ""),
- )
-
- def OnZoomMap(self, event):
- """Zoom to selected map"""
- layer = self.mapcontent.GetListOfLayers()[0]
-
- self.mapdisplay.MapWindow.ZoomToMap(layer=layer)
-
- event.Skip()
-
-class GCPToolbar(AbstractToolbar):
- """
- Toolbar for managing ground control points during georectification
- """
- def __init__(self, parent, tbframe):
- self.parent = parent # GCP
- self.tbframe = tbframe
-
- self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
-
- # self.SetToolBar(self.toolbar)
- self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
-
- self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
-
- # realize the toolbar
- self.toolbar.Realize()
-
- def ToolbarData(self):
-
- self.gcpSave = wx.NewId()
- self.gcpAdd = wx.NewId()
- self.gcpDelete = wx.NewId()
- self.gcpClear = wx.NewId()
- self.gcpReload = wx.NewId()
- self.rms = wx.NewId()
- self.georect = wx.NewId()
- self.settings = wx.NewId()
- self.quit = wx.NewId()
-
- return (
- (self.gcpSave, 'grGcpSave', Icons["grGcpSave"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpSave"].GetLabel(), Icons["grGcpSave"].GetDesc(),
- self.parent.SaveGCPs),
- (self.gcpAdd, 'grGrGcpAdd', Icons["grGcpAdd"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpAdd"].GetLabel(), Icons["grGcpAdd"].GetDesc(),
- self.parent.AddGCP),
- (self.gcpDelete, 'grGrGcpDelete', Icons["grGcpDelete"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpDelete"].GetLabel(), Icons["grGcpDelete"].GetDesc(),
- self.parent.DeleteGCP),
- (self.gcpClear, 'grGcpClear', Icons["grGcpClear"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpClear"].GetLabel(), Icons["grGcpClear"].GetDesc(),
- self.parent.ClearGCP),
- (self.gcpReload, 'grGcpReload', Icons["grGcpReload"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpReload"].GetLabel(), Icons["grGcpReload"].GetDesc(),
- self.parent.ReloadGCPs),
-
- ("", "", "", "", "", "", ""),
- (self.rms, 'grGcpRms', Icons["grGcpRms"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpRms"].GetLabel(), Icons["grGcpRms"].GetDesc(),
- self.parent.OnRMS),
- (self.georect, 'grGeorect', Icons["grGeorect"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGeorect"].GetLabel(), Icons["grGeorect"].GetDesc(),
- self.parent.OnGeorect),
- ("", "", "", "", "", "", ""),
- (self.settings, 'grSettings', Icons["grSettings"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grSettings"].GetLabel(), Icons["grSettings"].GetDesc(),
- self.parent.OnSettings),
- (self.quit, 'grGcpQuit', Icons["grGcpQuit"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["grGcpQuit"].GetLabel(), Icons["grGcpQuit"].GetDesc(),
- self.parent.OnQuit)
- )
-
-class VDigitToolbar(AbstractToolbar):
- """
- Toolbar for digitization
- """
-
- def __init__(self, parent, map, layerTree=None, log=None):
- self.mapcontent = map # Map class instance
- self.parent = parent # MapFrame
- self.layerTree = layerTree # reference to layer tree associated to map display
- self.log = log # log area
-
- # currently selected map layer for editing (reference to MapLayer instance)
- self.mapLayer = None
- # list of vector layers from Layer Manager (only in the current mapset)
- self.layers = []
-
- self.comboid = None
-
- # only one dialog can be open
- self.settingsDialog = None
-
- # create toolbars (two rows optionally)
- self.toolbar = []
- self.numOfRows = 1 # number of rows for toolbar
- for row in range(0, self.numOfRows):
- self.toolbar.append(wx.ToolBar(parent=self.parent, id=wx.ID_ANY))
- self.toolbar[row].SetToolBitmapSize(globalvar.toolbarSize)
- self.toolbar[row].Bind(wx.EVT_TOOL, self.OnTool)
-
- # create toolbar
- if self.numOfRows == 1:
- rowdata=None
- else:
- rowdata = row
- self.InitToolbar(self.parent, self.toolbar[row], self.ToolbarData(rowdata))
-
- # default action (digitize new point, line, etc.)
- self.action = { 'desc' : 'addLine',
- 'type' : 'point',
- 'id' : self.addPoint }
-
- # list of available vector maps
- self.UpdateListOfLayers(updateTool=True)
-
- # realize toolbar
- for row in range(0, self.numOfRows):
- self.toolbar[row].Realize()
- # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
- self.combo.Hide()
- self.combo.Show()
-
-
- # disable undo/redo
- self.toolbar[0].EnableTool(self.undo, False)
-
- # toogle to pointer by default
- self.OnTool(None)
-
- self.FixSize(width = 105)
-
- def ToolbarData(self, row=None):
- """
- Toolbar data
- """
- data = []
- if row is None or row == 0:
- self.addPoint = wx.NewId()
- self.addLine = wx.NewId()
- self.addBoundary = wx.NewId()
- self.addCentroid = wx.NewId()
- self.moveVertex = wx.NewId()
- self.addVertex = wx.NewId()
- self.removeVertex = wx.NewId()
- self.splitLine = wx.NewId()
- self.editLine = wx.NewId()
- self.moveLine = wx.NewId()
- self.deleteLine = wx.NewId()
- self.additionalTools = wx.NewId()
- self.displayCats = wx.NewId()
- self.displayAttr = wx.NewId()
- self.copyCats = wx.NewId()
-
- data = [("", "", "", "", "", "", ""),
- (self.addPoint, "digAddPoint", Icons["digAddPoint"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAddPoint"].GetLabel(), Icons["digAddPoint"].GetDesc(),
- self.OnAddPoint),
- (self.addLine, "digAddLine", Icons["digAddLine"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAddLine"].GetLabel(), Icons["digAddLine"].GetDesc(),
- self.OnAddLine),
- (self.addBoundary, "digAddBoundary", Icons["digAddBoundary"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAddBoundary"].GetLabel(), Icons["digAddBoundary"].GetDesc(),
- self.OnAddBoundary),
- (self.addCentroid, "digAddCentroid", Icons["digAddCentroid"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAddCentroid"].GetLabel(), Icons["digAddCentroid"].GetDesc(),
- self.OnAddCentroid),
- (self.moveVertex, "digMoveVertex", Icons["digMoveVertex"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digMoveVertex"].GetLabel(), Icons["digMoveVertex"].GetDesc(),
- self.OnMoveVertex),
- (self.addVertex, "digAddVertex", Icons["digAddVertex"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAddVertex"].GetLabel(), Icons["digAddVertex"].GetDesc(),
- self.OnAddVertex),
- (self.removeVertex, "digRemoveVertex", Icons["digRemoveVertex"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digRemoveVertex"].GetLabel(), Icons["digRemoveVertex"].GetDesc(),
- self.OnRemoveVertex),
- (self.splitLine, "digSplitLine", Icons["digSplitLine"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digSplitLine"].GetLabel(), Icons["digSplitLine"].GetDesc(),
- self.OnSplitLine),
- (self.editLine, "digEditLine", Icons["digEditLine"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digEditLine"].GetLabel(), Icons["digEditLine"].GetDesc(),
- self.OnEditLine),
- (self.moveLine, "digMoveLine", Icons["digMoveLine"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digMoveLine"].GetLabel(), Icons["digMoveLine"].GetDesc(),
- self.OnMoveLine),
- (self.deleteLine, "digDeleteLine", Icons["digDeleteLine"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digDeleteLine"].GetLabel(), Icons["digDeleteLine"].GetDesc(),
- self.OnDeleteLine),
- (self.displayCats, "digDispCats", Icons["digDispCats"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digDispCats"].GetLabel(), Icons["digDispCats"].GetDesc(),
- self.OnDisplayCats),
- (self.copyCats, "digCopyCats", Icons["digCopyCats"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digCopyCats"].GetLabel(), Icons["digCopyCats"].GetDesc(),
- self.OnCopyCA),
- (self.displayAttr, "digDispAttr", Icons["digDispAttr"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digDispAttr"].GetLabel(), Icons["digDispAttr"].GetDesc(),
- self.OnDisplayAttr),
- (self.additionalTools, "digAdditionalTools", Icons["digAdditionalTools"].GetBitmap(),
- wx.ITEM_CHECK, Icons["digAdditionalTools"].GetLabel(),
- Icons["digAdditionalTools"].GetDesc(),
- self.OnAdditionalToolMenu)]
-
- if row is None or row == 1:
- self.undo = wx.NewId()
- self.settings = wx.NewId()
- self.exit = wx.NewId()
-
- data.append(("", "", "", "", "", "", ""))
- data.append((self.undo, "digUndo", Icons["digUndo"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["digUndo"].GetLabel(), Icons["digUndo"].GetDesc(),
- self.OnUndo))
- # data.append((self.undo, "digRedo", Icons["digRedo"].GetBitmap(),
- # wx.ITEM_NORMAL, Icons["digRedo"].GetLabel(), Icons["digRedo"].GetDesc(),
- # self.OnRedo))
- data.append((self.settings, "digSettings", Icons["digSettings"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["digSettings"].GetLabel(), Icons["digSettings"].GetDesc(),
- self.OnSettings))
- data.append((self.exit, "digExit", Icons["quit"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["digExit"].GetLabel(), Icons["digExit"].GetDesc(),
- self.OnExit))
-
- return data
-
- def OnTool(self, event):
- """Tool selected -> disable selected tool in map toolbar"""
- # update map toolbar (unselect currently selected tool)
- id = self.parent.toolbars['map'].GetAction(type='id')
- self.parent.toolbars['map'].toolbar.ToggleTool(id, False)
-
- # set cursor
- cursor = self.parent.cursors["cross"]
- self.parent.MapWindow.SetCursor(cursor)
-
- # pointer
- self.parent.OnPointer(None)
-
- if event:
- # deselect previously selected tool
- id = self.action.get('id', -1)
- if id != event.GetId():
- self.toolbar[0].ToggleTool(self.action['id'], False)
- else:
- self.toolbar[0].ToggleTool(self.action['id'], True)
-
- self.action['id'] = event.GetId()
- event.Skip()
- else:
- # initialize toolbar
- self.toolbar[0].ToggleTool(self.action['id'], True)
-
- # clear tmp canvas
- if self.action['id'] != id:
- self.parent.MapWindow.ClearLines(pdc=self.parent.MapWindow.pdcTmp)
- if self.parent.digit and \
- len(self.parent.digit.driver.GetSelected()) > 0:
- # cancel action
- self.parent.MapWindow.OnMiddleDown(None)
-
- def OnAddPoint(self, event):
- """Add point to the vector map Laier"""
- Debug.msg (2, "VDigitToolbar.OnAddPoint()")
- self.action = { 'desc' : "addLine",
- 'type' : "point",
- 'id' : self.addPoint }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnAddLine(self, event):
- """Add line to the vector map layer"""
- Debug.msg (2, "VDigitToolbar.OnAddLine()")
- self.action = { 'desc' : "addLine",
- 'type' : "line",
- 'id' : self.addLine }
- self.parent.MapWindow.mouse['box'] = 'line'
- ### self.parent.MapWindow.polycoords = [] # reset temp line
-
- def OnAddBoundary(self, event):
- """Add boundary to the vector map layer"""
- Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
- if self.action['desc'] != 'addLine' or \
- self.action['type'] != 'boundary':
- self.parent.MapWindow.polycoords = [] # reset temp line
- self.action = { 'desc' : "addLine",
- 'type' : "boundary",
- 'id' : self.addBoundary }
- self.parent.MapWindow.mouse['box'] = 'line'
-
- def OnAddCentroid(self, event):
- """Add centroid to the vector map layer"""
- Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
- self.action = { 'desc' : "addLine",
- 'type' : "centroid",
- 'id' : self.addCentroid }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnExit (self, event=None):
- """Quit digitization tool"""
- # stop editing of the currently selected map layer
- if self.mapLayer:
- self.StopEditing()
-
- # close dialogs if still open
- if self.settingsDialog:
- self.settingsDialog.OnCancel(None)
-
- # disable the toolbar
- self.parent.RemoveToolbar ("vdigit")
-
- # set default mouse settings
- self.parent.MapWindow.mouse['use'] = "pointer"
- self.parent.MapWindow.mouse['box'] = "point"
- self.parent.MapWindow.polycoords = []
-
- def OnMoveVertex(self, event):
- """Move line vertex"""
- Debug.msg(2, "Digittoolbar.OnMoveVertex():")
- self.action = { 'desc' : "moveVertex",
- 'id' : self.moveVertex }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnAddVertex(self, event):
- """Add line vertex"""
- Debug.msg(2, "Digittoolbar.OnAddVertex():")
- self.action = { 'desc' : "addVertex",
- 'id' : self.addVertex }
- self.parent.MapWindow.mouse['box'] = 'point'
-
-
- def OnRemoveVertex(self, event):
- """Remove line vertex"""
- Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
- self.action = { 'desc' : "removeVertex",
- 'id' : self.removeVertex }
- self.parent.MapWindow.mouse['box'] = 'point'
-
-
- def OnSplitLine(self, event):
- """Split line"""
- Debug.msg(2, "Digittoolbar.OnSplitLine():")
- self.action = { 'desc' : "splitLine",
- 'id' : self.splitLine }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnEditLine(self, event):
- """Edit line"""
- Debug.msg(2, "Digittoolbar.OnEditLine():")
- self.action = { 'desc' : "editLine",
- 'id' : self.editLine }
- self.parent.MapWindow.mouse['box'] = 'line'
-
- def OnMoveLine(self, event):
- """Move line"""
- Debug.msg(2, "Digittoolbar.OnMoveLine():")
- self.action = { 'desc' : "moveLine",
- 'id' : self.moveLine }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnDeleteLine(self, event):
- """Delete line"""
- Debug.msg(2, "Digittoolbar.OnDeleteLine():")
- self.action = { 'desc' : "deleteLine",
- 'id' : self.deleteLine }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnDisplayCats(self, event):
- """Display/update categories"""
- Debug.msg(2, "Digittoolbar.OnDisplayCats():")
- self.action = { 'desc' : "displayCats",
- 'id' : self.displayCats }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnDisplayAttr(self, event):
- """Display/update attributes"""
- Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
- self.action = { 'desc' : "displayAttrs",
- 'id' : self.displayAttr }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnCopyCA(self, event):
- """Copy categories/attributes menu"""
- point = wx.GetMousePosition()
- toolMenu = wx.Menu()
- # Add items to the menu
- cats = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Copy categories'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(cats)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyCats, cats)
- if self.action['desc'] == "copyCats":
- cats.Check(True)
-
- attrb = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Duplicate attributes'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(attrb)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopyAttrb, attrb)
- if self.action['desc'] == "copyAttrs":
- attrb.Check(True)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.parent.MapWindow.PopupMenu(toolMenu)
- toolMenu.Destroy()
-
- if self.action['desc'] == "addPoint":
- self.toolbar[0].ToggleTool(self.copyCats, False)
-
- def OnCopyCats(self, event):
- """Copy categories"""
- if self.action['desc'] == 'copyCats': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.copyCats, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnCopyCats():")
- self.action = { 'desc' : "copyCats",
- 'id' : self.copyCats }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnCopyAttrb(self, event):
- if self.action['desc'] == 'copyAttrs': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.copyCats, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
- self.action = { 'desc' : "copyAttrs",
- 'id' : self.copyCats }
- self.parent.MapWindow.mouse['box'] = 'point'
-
- def OnUndo(self, event):
- """Undo previous changes"""
- self.parent.digit.Undo()
-
- event.Skip()
-
- def EnableUndo(self, enable=True):
- """Enable 'Undo' in toolbar
-
- @param enable False for disable
- """
- if enable:
- if self.toolbar[0].GetToolEnabled(self.undo) is False:
- self.toolbar[0].EnableTool(self.undo, True)
- else:
- if self.toolbar[0].GetToolEnabled(self.undo) is True:
- self.toolbar[0].EnableTool(self.undo, False)
-
- def OnSettings(self, event):
- """Show settings dialog"""
-
- if self.parent.digit is None:
- reload(vdigit)
- from vdigit import Digit as Digit
- self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
-
- if not self.settingsDialog:
- self.settingsDialog = VDigitSettingsDialog(parent=self.parent, title=_("Digitization settings"),
- style=wx.DEFAULT_DIALOG_STYLE)
- self.settingsDialog.Show()
-
- def OnAdditionalToolMenu(self, event):
- """Menu for additional tools"""
- point = wx.GetMousePosition()
- toolMenu = wx.Menu()
- # Add items to the menu
- copy = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Copy features from (background) vector map'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(copy)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
- if self.action['desc'] == "copyLine":
- copy.Check(True)
-
- flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Flip selected lines/boundaries'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(flip)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
- if self.action['desc'] == "flipLine":
- flip.Check(True)
-
- merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Merge selected lines/boundaries'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(merge)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnMerge, merge)
- if self.action['desc'] == "mergeLine":
- merge.Check(True)
-
- breakL = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Break selected lines/boundaries at intersection'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(breakL)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnBreak, breakL)
- if self.action['desc'] == "breakLine":
- breakL.Check(True)
-
- snap = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Snap selected lines/boundaries (only to nodes)'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(snap)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnSnap, snap)
- if self.action['desc'] == "snapLine":
- snap.Check(True)
-
- connect = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Connect selected lines/boundaries'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(connect)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnConnect, connect)
- if self.action['desc'] == "connectLine":
- connect.Check(True)
-
- query = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Query features'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(query)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnQuery, query)
- if self.action['desc'] == "queryLine":
- query.Check(True)
-
- zbulk = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Z bulk-labeling of 3D lines'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(zbulk)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnZBulk, zbulk)
- if self.action['desc'] == "zbulkLine":
- zbulk.Check(True)
-
- typeconv = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
- text=_('Feature type conversion'),
- kind=wx.ITEM_CHECK)
- toolMenu.AppendItem(typeconv)
- self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnTypeConversion, typeconv)
- if self.action['desc'] == "typeConv":
- typeconv.Check(True)
-
- # Popup the menu. If an item is selected then its handler
- # will be called before PopupMenu returns.
- self.parent.MapWindow.PopupMenu(toolMenu)
- toolMenu.Destroy()
-
- if self.action['desc'] == 'addPoint':
- self.toolbar[0].ToggleTool(self.additionalTools, False)
-
- def OnCopy(self, event):
- """Copy selected features from (background) vector map"""
- if self.action['desc'] == 'copyLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnCopy():")
- self.action = { 'desc' : "copyLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnFlip(self, event):
- """Flip selected lines/boundaries"""
- if self.action['desc'] == 'flipLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnFlip():")
- self.action = { 'desc' : "flipLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnMerge(self, event):
- """Merge selected lines/boundaries"""
- if self.action['desc'] == 'mergeLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnMerge():")
- self.action = { 'desc' : "mergeLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnBreak(self, event):
- """Break selected lines/boundaries"""
- if self.action['desc'] == 'breakLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnBreak():")
- self.action = { 'desc' : "breakLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnSnap(self, event):
- """Snap selected features"""
- if self.action['desc'] == 'snapLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnSnap():")
- self.action = { 'desc' : "snapLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnConnect(self, event):
- """Connect selected lines/boundaries"""
- if self.action['desc'] == 'connectLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnConnect():")
- self.action = { 'desc' : "connectLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnQuery(self, event):
- """Query selected lines/boundaries"""
- if self.action['desc'] == 'queryLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
- UserSettings.Get(group='vdigit', key='query', subkey='selection'))
- self.action = { 'desc' : "queryLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnZBulk(self, event):
- """Z bulk-labeling selected lines/boundaries"""
- if not self.parent.digit.driver.Is3D():
- wx.MessageBox(parent=self.parent,
- message=_("Vector map is not 3D. Operation canceled."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- if self.action['desc'] == 'zbulkLine': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnZBulk():")
- self.action = { 'desc' : "zbulkLine",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'line'
-
- def OnTypeConversion(self, event):
- """Feature type conversion
-
- Supported conversions:
- - point <-> centroid
- - line <-> boundary
- """
- if self.action['desc'] == 'typeConv': # select previous action
- self.toolbar[0].ToggleTool(self.addPoint, True)
- self.toolbar[0].ToggleTool(self.additionalTools, False)
- self.OnAddPoint(event)
- return
-
- Debug.msg(2, "Digittoolbar.OnTypeConversion():")
- self.action = { 'desc' : "typeConv",
- 'id' : self.additionalTools }
- self.parent.MapWindow.mouse['box'] = 'box'
-
- def OnSelectMap (self, event):
- """
- Select vector map layer for editing
-
- If there is a vector map layer already edited, this action is
- firstly terminated. The map layer is closed. After this the
- selected map layer activated for editing.
- """
- if event.GetSelection() == 0: # create new vector map layer
- if self.mapLayer:
- openVectorMap = self.mapLayer.GetName(fullyQualified=False)['name']
- else:
- openVectorMap = None
- mapName = gdialogs.CreateNewVector(self.parent,
- exceptMap=openVectorMap, log=self.log,
- cmdDef=(['v.edit', 'tool=create'], "map"),
- disableAdd=True)[0]
- if mapName:
- # add layer to map layer tree
- if self.layerTree:
- self.layerTree.AddLayer(ltype='vector',
- lname=mapName,
- lchecked=True,
- lopacity=1.0,
- lcmd=['d.vect', 'map=%s' % mapName])
-
- vectLayers = self.UpdateListOfLayers(updateTool=True)
- selection = vectLayers.index(mapName)
- else:
- pass # TODO (no Layer Manager)
- else:
- self.combo.SetValue(_('Select vector map'))
- return
- else:
- selection = event.GetSelection() - 1 # first option is 'New vector map'
-
- # skip currently selected map
- if self.layers[selection] == self.mapLayer:
- return False
-
- if self.mapLayer:
- # deactive map layer for editing
- self.StopEditing()
-
- # select the given map layer for editing
- self.StartEditing(self.layers[selection])
-
- event.Skip()
-
- return True
-
- def StartEditing (self, mapLayer):
- """
- Start editing selected vector map layer.
-
- @param mapLayer reference to MapLayer instance
- """
- # deactive layer
- self.mapcontent.ChangeLayerActive(mapLayer, False)
-
- # clean map canvas
- ### self.parent.MapWindow.EraseMap()
-
- # unset background map if needed
- if UserSettings.Get(group='vdigit', key='bgmap',
- subkey='value', internal=True) == mapLayer.GetName():
- UserSettings.Set(group='vdigit', key='bgmap',
- subkey='value', value='', internal=True)
-
- self.parent.statusbar.SetStatusText(_("Please wait, "
- "opening vector map <%s> for editing...") % \
- mapLayer.GetName(),
- 0)
-
- # reload vdigit module
- reload(vdigit)
- from vdigit import Digit as Digit
- self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
-
- self.mapLayer = mapLayer
-
- # open vector map
- try:
- self.parent.digit.SetMapName(mapLayer.GetName())
- except gcmd.DigitError, e:
- self.mapLayer = None
- print >> sys.stderr, e # wxMessageBox
- return False
-
- # update toolbar
- self.combo.SetValue(mapLayer.GetName())
- self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
-
- Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
-
- # change cursor
- if self.parent.MapWindow.mouse['use'] == 'pointer':
- self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
-
- # create pseudoDC for drawing the map
- self.parent.MapWindow.pdcVector = vdigit.PseudoDC()
- self.parent.digit.driver.SetDevice(self.parent.MapWindow.pdcVector)
-
- if not self.parent.MapWindow.resize:
- self.parent.MapWindow.UpdateMap(render=True)
-
- opacity = mapLayer.GetOpacity(float=True)
- if opacity < 1.0:
- alpha = int(opacity * 255)
- self.parent.digit.driver.UpdateSettings(alpha)
-
- return True
-
- def StopEditing (self):
- """Stop editing of selected vector map layer.
-
- @return True on success
- @return False on failure
- """
- if not self.mapLayer:
- return False
-
- Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
- self.combo.SetValue (_('Select vector map'))
-
- # save changes
- if UserSettings.Get(group='vdigit', key='saveOnExit', subkey='enabled') is False:
- if self.parent.digit.GetUndoLevel() > 0:
- dlg = wx.MessageDialog(parent=self.parent,
- message=_("Do you want to save changes "
- "in vector map <%s>?") % self.mapLayer.GetName(),
- caption=_("Save changes?"),
- style=wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
- if dlg.ShowModal() == wx.ID_NO:
- # revert changes
- self.parent.digit.Undo(0)
- dlg.Destroy()
-
- self.parent.statusbar.SetStatusText(_("Please wait, "
- "closing and rebuilding topology of "
- "vector map <%s>...") % self.mapLayer.GetName(),
- 0)
-
- self.parent.digit.SetMapName(None) # -> close map
-
- # re-active layer
- item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
- if item and self.parent.tree.IsItemChecked(item):
- self.mapcontent.ChangeLayerActive(self.mapLayer, True)
-
- # change cursor
- self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
-
- # disable pseudodc for vector map layer
- self.parent.MapWindow.pdcVector = None
- self.parent.digit.driver.SetDevice(None)
-
- # close dialogs
- for dialog in ('attributes', 'category'):
- if self.parent.dialogs[dialog]:
- self.parent.dialogs[dialog].Close()
- self.parent.dialogs[dialog] = None
-
- self.parent.digit.__del__() # FIXME: destructor is not called here (del)
- self.parent.digit = None
-
- self.mapLayer = None
-
- self.parent.MapWindow.redrawAll = True
-
- return True
-
- def UpdateListOfLayers (self, updateTool=False):
- """
- Update list of available vector map layers.
- This list consists only editable layers (in the current mapset)
-
- Optionally also update toolbar
- """
-
- Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
- updateTool)
-
- layerNameSelected = None
- # name of currently selected layer
- if self.mapLayer:
- layerNameSelected = self.mapLayer.GetName()
-
- # select vector map layer in the current mapset
- layerNameList = []
- self.layers = self.mapcontent.GetListOfLayers(l_type="vector",
- l_mapset=grassenv.GetGRASSVariable('MAPSET'))
- for layer in self.layers:
- if not layer.name in layerNameList: # do not duplicate layer
- layerNameList.append (layer.GetName())
-
- if updateTool: # update toolbar
- if not self.mapLayer:
- value = _('Select vector map')
- else:
- value = layerNameSelected
-
- if not self.comboid:
- self.combo = wx.ComboBox(self.toolbar[self.numOfRows-1], id=wx.ID_ANY, value=value,
- choices=[_('New vector map'), ] + layerNameList, size=(85, -1),
- style=wx.CB_READONLY)
- self.comboid = self.toolbar[self.numOfRows-1].InsertControl(0, self.combo)
- self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
- else:
- self.combo.SetItems([_('New vector map'), ] + layerNameList)
-
- self.toolbar[self.numOfRows-1].Realize()
-
- return layerNameList
-
- def GetLayer(self):
- """Get selected layer for editing -- MapLayer instance"""
- return self.mapLayer
-
-class ProfileToolbar(AbstractToolbar):
- """
- Toolbar for profiling raster map
- """
- def __init__(self, parent, tbframe):
- self.parent = parent # GCP
- self.tbframe = tbframe
-
- self.toolbar = wx.ToolBar(parent=self.tbframe, id=wx.ID_ANY)
-
- # self.SetToolBar(self.toolbar)
- self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
-
- self.InitToolbar(self.tbframe, self.toolbar, self.ToolbarData())
-
- # realize the toolbar
- self.toolbar.Realize()
-
- def ToolbarData(self):
- """Toolbar data"""
-
- self.transect = wx.NewId()
- self.addraster = wx.NewId()
- self.draw = wx.NewId()
- self.options = wx.NewId()
- self.drag = wx.NewId()
- self.zoom = wx.NewId()
- self.unzoom = wx.NewId()
- self.erase = wx.NewId()
- self.save = wx.NewId()
- self.printer = wx.NewId()
- self.quit = wx.NewId()
-
- # tool, label, bitmap, kind, shortHelp, longHelp, handler
- return (
- (self.addraster, 'raster', Icons["addrast"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["addrast"].GetLabel(), Icons["addrast"].GetDesc(),
- self.parent.OnSelectRaster),
- (self.transect, 'transect', Icons["transect"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["transect"].GetLabel(), Icons["transect"].GetDesc(),
- self.parent.OnDrawTransect),
- (self.draw, 'profiledraw', Icons["profiledraw"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["profiledraw"].GetLabel(), Icons["profiledraw"].GetDesc(),
- self.parent.OnCreateProfile),
- (self.options, 'options', Icons["profileopt"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["profileopt"].GetLabel(), Icons["profileopt"].GetDesc(),
- self.parent.ProfileOptionsMenu),
- (self.drag, 'drag', Icons['pan'].GetBitmap(),
- wx.ITEM_NORMAL, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
- self.parent.OnDrag),
- (self.zoom, 'zoom', Icons['zoom_in'].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
- self.parent.OnZoom),
- (self.unzoom, 'unzoom', Icons['zoom_back'].GetBitmap(),
- wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
- self.parent.OnRedraw),
- (self.erase, 'erase', Icons["erase"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["erase"].GetLabel(), Icons["erase"].GetDesc(),
- self.parent.OnErase),
- ("", "", "", "", "", "", ""),
- (self.save, 'save', Icons["savefile"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["savefile"].GetLabel(), Icons["savefile"].GetDesc(),
- self.parent.SaveToFile),
- (self.printer, 'print', Icons["printmap"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["printmap"].GetLabel(), Icons["printmap"].GetDesc(),
- self.parent.PrintMenu),
- (self.quit, 'quit', Icons["quit"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
- self.parent.OnQuit),
- )
-
-class NvizToolbar(AbstractToolbar):
- """
- Nviz toolbar
- """
- def __init__(self, parent, map):
- self.parent = parent
- self.mapcontent = map
-
- self.toolbar = wx.ToolBar(parent=self.parent, id=wx.ID_ANY)
-
- # self.SetToolBar(self.toolbar)
- self.toolbar.SetToolBitmapSize(globalvar.toolbarSize)
-
- self.InitToolbar(self.parent, self.toolbar, self.ToolbarData())
-
- # realize the toolbar
- self.toolbar.Realize()
-
- def ToolbarData(self):
- """Toolbar data"""
-
- self.settings = wx.NewId()
- self.quit = wx.NewId()
-
- # tool, label, bitmap, kind, shortHelp, longHelp, handler
- return (
- (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
- self.OnSettings),
- (self.quit, 'quit', Icons["quit"].GetBitmap(),
- wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
- self.OnExit),
- )
-
- def OnSettings(self, event):
- win = self.parent.nvizToolWin
- if not win.IsShown():
- self.parent.nvizToolWin.Show()
- else:
- self.parent.nvizToolWin.Hide()
-
- def OnExit (self, event=None):
- """Quit nviz tool (swith to 2D mode)"""
-
- # hide dialogs if still open
- if self.parent.nvizToolWin:
- self.parent.nvizToolWin.Hide()
-
- # disable the toolbar
- self.parent.RemoveToolbar ("nviz")
-
- # set default mouse settings
- self.parent.MapWindow.mouse['use'] = "pointer"
- self.parent.MapWindow.mouse['box'] = "point"
- self.parent.MapWindow.polycoords = []
-
Deleted: grass-addons/gui/wxpython/data_catalog/units.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/units.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/units.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,118 +0,0 @@
-"""!
- at package units
-
- at brief Units management
-
-Probably will be replaced by Python SWIG fns in the near future(?)
-
-Usage:
-
- at code
-from units import Units
- at endcode
-
-Classes:
- - BaseUnits
-
-(C) 2009 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 Martin Landa <landa.martin gmail.com>
-"""
-
-class BaseUnits:
- def __init__(self):
- self._units = dict()
- self._units['length'] = { 0 : { 'key' : 'mu', 'label' : _('map units') },
- 1 : { 'key' : 'me', 'label' : _('meters') },
- 2 : { 'key' : 'km', 'label' : _('kilometers') },
- 3 : { 'key' : 'mi', 'label' : _('miles') },
- 4 : { 'key' : 'ft', 'label' : _('feet') } }
-
- self._units['area'] = { 0 : { 'key' : 'mu', 'label' : _('sq map units') },
- 1 : { 'key' : 'me', 'label' : _('sq meters') },
- 2 : { 'key' : 'km', 'label' : _('sq kilometers') },
- 3 : { 'key' : 'ar', 'label' : _('acres') },
- 4 : { 'key' : 'ht', 'label' : _('hectares') } }
-
- def GetUnitsList(self, type):
- """!Get list of units (their labels)
-
- @param type units type ('length' or 'area')
-
- @return list of units labels
- """
- result = list()
- try:
- keys = self._units[type].keys()
- keys.sort()
- for idx in keys:
- result.append(self._units[type][idx]['label'])
- except KeyError:
- pass
-
- return result
-
- def GetUnitsKey(self, type, index):
- """!Get units key based on index
-
- @param type units type ('length' or 'area')
- @param index units index
- """
- return self._units[type][index]['key']
-
- def GetUnitsIndex(self, type, key):
- """!Get units index based on key
-
- @param type units type ('length' or 'area')
- @param key units key, e.g. 'me' for meters
-
- @return index
- """
- for k, u in self._units[type].iteritems():
- if u['key'] == key:
- return k
- return 0
-
-Units = BaseUnits()
-
-def ConvertValue(value, type, units):
- """!Convert value from map units to given units
-
- Inspired by vector/v.to.db/units.c
-
- @param value value to be converted
- @param type units type ('length', 'area')
- @param unit destination units
- """
- # get map units
- # TODO
-
- f = 1
- if type == 'length':
- if units == 'me':
- f = 1.0
- elif units == 'km':
- f = 1.0e-3
- elif units == 'mi':
- f = 6.21371192237334e-4
- elif units == 'ft':
- f = 3.28083989501312
- else: # -> area
- if units == 'me':
- f = 1.0
- elif units == 'km':
- f = 1.0e-6
- elif units == 'mi':
- f = 3.86102158542446e-7
- elif units == 'ft':
- f = 10.7639104167097
- elif units == 'ar':
- f = 2.47105381467165e-4
- elif units == 'ht':
- f = 1.0e-4
-
- return f * value
Deleted: grass-addons/gui/wxpython/data_catalog/wx_utils.py
===================================================================
--- grass-addons/gui/wxpython/data_catalog/wx_utils.py 2010-04-23 15:48:30 UTC (rev 42004)
+++ grass-addons/gui/wxpython/data_catalog/wx_utils.py 2010-04-23 15:54:46 UTC (rev 42005)
@@ -1,1520 +0,0 @@
-"""!
- at package wxgui_utils.py
-
- at brief Utility classes for GRASS wxPython GUI. Main functions include
-tree control for GIS map layer management, command console, and
-command parsing.
-
-Classes:
- - AbstractLayer
- - Layer
- - LayerTree
-
-(C) 2007-2009 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 Michael Barton (Arizona State University)
- at author Jachym Cepicky (Mendel University of Agriculture)
- at author Martin Landa <landa.martin gmail.com>
- at author Mohammed Rashad K.M <rashadkm at gmail dot com> (only modified for DataCatalog)
-"""
-
-import os
-import sys
-import string
-
-import wx
-import wx.lib.customtreectrl as CT
-import wx.combo
-import wx.lib.newevent
-import wx.lib.buttons as buttons
-
-from grass.script import core as grass
-
-import gdialogs
-import globalvar
-import menuform
-import toolbars
-import mapdisp
-import render
-import histogram
-import utils
-import profile
-from debug import Debug as Debug
-from icon import Icons as Icons
-from preferences import globalSettings as UserSettings
-from vdigit import haveVDigit
-
-
-
-
-
-try:
- import subprocess
-except:
- from compat import subprocess
-
-try:
- import treemixin
-except ImportError:
- from wx.lib.mixins import treemixin
-
-
-TREE_ITEM_HEIGHT = 25
-
-class AddLayerTree(treemixin.DragAndDrop, CT.CustomTreeCtrl):
- """
- Creates layer tree structure
- """
- def __init__(self, parent,
- id=wx.ID_ANY, pos=wx.DefaultPosition,
- size=(300,300), style=wx.SUNKEN_BORDER,
- ctstyle=CT.TR_HAS_BUTTONS | CT.TR_HAS_VARIABLE_ROW_HEIGHT |
- CT.TR_HIDE_ROOT | CT.TR_ROW_LINES | CT.TR_FULL_ROW_HIGHLIGHT |
- CT.TR_MULTIPLE,mapdisplay=None,frame=None,panel=None,Map=None,lmgr=None):
- self.items = []
- self.itemCounter = 0
-
- super(AddLayerTree, self).__init__(parent, id, pos, size, style=style, ctstyle=ctstyle)
- self.SetName("AddLayerTree")
-
- ### SetAutoLayout() causes that no vertical scrollbar is displayed
- ### when some layers are not visible in layer tree
- # self.SetAutoLayout(True)
- self.SetGradientStyle(1)
- self.EnableSelectionGradient(True)
- self.SetFirstGradientColour(wx.Colour(100, 100, 100))
- self.SetSecondGradientColour(wx.Colour(150, 150, 150))
-
- self.mapdict = {}
-
- self.item = None
-
- self.layer = []
-
- self.ltype = None
-
-
-
- self.mapdisplay = self.GetParent()
-
- if self.mapdisplay.toolbars['vdigit']:
- self.mapdisplay.toolbars['vdigit'].UpdateListOfLayers(updateTool=True)
-
- self.Map = Map # instance of render.Map to be associated with display
-
- self.root = None # ID of layer tree root node
- self.groupnode = 0 # index value for layers
- self.optpage = {} # dictionary of notebook option pages for each map layer
- self.layer_selected = None # ID of currently selected layer
- self.saveitem = {} # dictionary to preserve layer attributes for drag and drop
- self.first = True # indicates if a layer is just added or not
- self.flag = '' # flag for drag and drop hittest
- self.parent = parent
- #self.disp_idx = kargs['idx']
- self.lmgr = lmgr
-#FIX
- # self.notebook = kargs['notebook'] # GIS Manager notebook for layer tree
-#FIX this
- #self.treepg = parent # notebook page holding layer tree
- #self.auimgr = kargs['auimgr'] # aui manager
- self.rerender = False # layer change requires a rerendering if auto render
- self.reorder = False # layer change requires a reordering
-
- # init associated map display
- # pos = wx.Point((self.disp_idx + 1) * 25, (self.disp_idx + 1) * 25)
-# self.mapdisplay = mapdisp.MapFrame(self, id=wx.ID_ANY, pos=pos, size=globalvar.MAP_WINDOW_SIZE,style=wx.DEFAULT_FRAME_STYLE, tree=self, notebook=self.notebook,
-
-
- self.frame = frame
- self.panel = panel
-
- self.SetSize(wx.Size(340,640))
- #lmgr=self.lmgr, page=self.treepg,Map=self.Map, auimgr=self.auimgr)
-
- # title
- # self.mapdisplay.SetTitle(_("GRASS GIS Map Display: %(id)d - Location: %(loc)s") % \
- # { 'id' : self.disp_idx + 1,
- # 'loc' : grass.gisenv()["LOCATION_NAME"] })
-
- # show new display
- # if kargs['showMapDisplay'] is True:
- # self.mapdisplay.Show()
- # self.mapdisplay.Refresh()
- # self.mapdisplay.Update()
-
- #self.SetSize(300,300)
-
- self.root = self.AddRoot(_("Map Layers"))
- self.SetPyData(self.root, (None,None))
- self.items = []
-
- #create image list to use with layer tree
- il = wx.ImageList(16, 16, mask=False)
-
- trart = wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN, wx.ART_OTHER, (16, 16))
- self.folder_open = il.Add(trart)
- trart = wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16, 16))
- self.folder = il.Add(trart)
-
- bmpsize = (16, 16)
- trgif = Icons["addrast"].GetBitmap(bmpsize)
- self.rast_icon = il.Add(trgif)
-
- trgif = Icons["addrast3d"].GetBitmap(bmpsize)
- self.rast3d_icon = il.Add(trgif)
-
- trgif = Icons["addrgb"].GetBitmap(bmpsize)
- self.rgb_icon = il.Add(trgif)
-
- trgif = Icons["addhis"].GetBitmap(bmpsize)
- self.his_icon = il.Add(trgif)
-
- trgif = Icons["addshaded"].GetBitmap(bmpsize)
- self.shaded_icon = il.Add(trgif)
-
- trgif = Icons["addrarrow"].GetBitmap(bmpsize)
- self.rarrow_icon = il.Add(trgif)
-
- trgif = Icons["addrnum"].GetBitmap(bmpsize)
- self.rnum_icon = il.Add(trgif)
-
- trgif = Icons["addvect"].GetBitmap(bmpsize)
- self.vect_icon = il.Add(trgif)
-
- trgif = Icons["addthematic"].GetBitmap(bmpsize)
- self.theme_icon = il.Add(trgif)
-
- trgif = Icons["addchart"].GetBitmap(bmpsize)
- self.chart_icon = il.Add(trgif)
-
- trgif = Icons["addgrid"].GetBitmap(bmpsize)
- self.grid_icon = il.Add(trgif)
-
- trgif = Icons["addgeodesic"].GetBitmap(bmpsize)
- self.geodesic_icon = il.Add(trgif)
-
- trgif = Icons["addrhumb"].GetBitmap(bmpsize)
- self.rhumb_icon = il.Add(trgif)
-
- trgif = Icons["addlabels"].GetBitmap(bmpsize)
- self.labels_icon = il.Add(trgif)
-
- trgif = Icons["addcmd"].GetBitmap(bmpsize)
- self.cmd_icon = il.Add(trgif)
-
- self.AssignImageList(il)
-
- # use when groups implemented
- ## self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal)
- ## self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded)
-
- self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.OnExpandNode)
- self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnCollapseNode)
- self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivateLayer)
- self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnChangeSel)
- self.Bind(CT.EVT_TREE_ITEM_CHECKED, self.OnLayerChecked)
- #self.Bind(wx.EVT_TREE_DELETE_ITEM, self.OnDeleteLayer)
- self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.OnLayerContextMenu)
- #self.Bind(wx.EVT_TREE_BEGIN_DRAG, self.OnDrag)
- self.Bind(wx.EVT_TREE_END_DRAG, self.OnEndDrag)
- #self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnChangeLayerName)
- self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
- # self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
- self.Bind(wx.EVT_IDLE, self.OnIdle)
-
-
-
-
-
-
- def OnIdle(self, event):
- """
- Only re-order and re-render a composite map image from GRASS during
- idle time instead of multiple times during layer changing.
- """
- if self.rerender:
- if self.mapdisplay.toolbars['vdigit']:
- self.mapdisplay.toolbars['vdigit'].UpdateListOfLayers(updateTool=True)
- if self.mapdisplay.statusbarWin['render'].GetValue():
- self.mapdisplay.MapWindow2D.UpdateMap(render=True)
-
- event.Skip()
-
- def OnKeyUp(self, event):
- """!Key pressed"""
- key = event.GetKeyCode()
- if key == wx.WXK_DELETE and self.lmgr:
- self.frame.OnDeleteLayer(None)
-
- event.Skip()
-
- #def OnChangeLayerName (self, event):
- # """!Change layer name"""
- # Debug.msg (3, "LayerTree.OnChangeLayerName: name=%s" % event.GetLabel())
-
- def OnLayerContextMenu (self, event):
- """!Contextual menu for item/layer"""
- if not self.layer_selected:
- event.Skip()
- return
-
- #ltype = 'raster'
- #print self.ltype
-
- Debug.msg (4, "LayerTree.OnContextMenu: layertype=%s" % \
- self.ltype)
-
- if not hasattr (self, "popupID1"):
- self.popupID1 = wx.NewId()
- self.popupID2 = wx.NewId()
- self.popupID3 = wx.NewId()
- self.popupID4 = wx.NewId()
- self.popupID5 = wx.NewId()
- self.popupID6 = wx.NewId()
- self.popupID7 = wx.NewId()
- self.popupID8 = wx.NewId()
- self.popupID9 = wx.NewId()
- self.popupID10 = wx.NewId()
- self.popupID11 = wx.NewId() # nviz
- self.popupID12 = wx.NewId()
- self.popupID13 = wx.NewId()
- self.popupID14 = wx.NewId()
- self.popupID15 = wx.NewId()
-
- self.popupMenu = wx.Menu()
-
- numSelected = len(self.GetSelections())
-
- # general item
- self.popupMenu.Append(self.popupID1, text=_("Remove"))
-
- p = self.parent.GetParent()
- q= p.GetParent()
- r= q.GetParent()
- frame= r.GetParent()
- self.Bind(wx.EVT_MENU, frame.OnDeleteLayer, id=self.popupID1)
-
- if self.ltype != "command": # rename
- self.popupMenu.Append(self.popupID2, text=_("Rename"))
- self.Bind(wx.EVT_MENU, self.RenameLayer, id=self.popupID2)
- if numSelected > 1:
- self.popupMenu.Enable(self.popupID2, False)
-
- # map layer items
- if self.ltype != "group" and \
- self.ltype != "command":
- self.popupMenu.AppendSeparator()
- self.popupMenu.Append(self.popupID8, text=_("Change opacity level"))
- self.Bind(wx.EVT_MENU, self.OnPopupOpacityLevel, id=self.popupID8)
- self.popupMenu.Append(self.popupID3, text=_("Properties"))
- self.Bind(wx.EVT_MENU, self.OnPopupProperties, id=self.popupID3)
- if self.ltype in ('raster', 'vector', 'rgb'):
- self.popupMenu.Append(self.popupID9, text=_("Zoom to selected map(s)"))
- self.Bind(wx.EVT_MENU, self.mapdisplay.MapWindow2D.OnZoomToMap, id=self.popupID9)
- self.popupMenu.Append(self.popupID10, text=_("Set computational region from selected map(s)"))
- self.Bind(wx.EVT_MENU, self.OnSetCompRegFromMap, id=self.popupID10)
- if numSelected > 1:
- self.popupMenu.Enable(self.popupID8, False)
- self.popupMenu.Enable(self.popupID3, False)
-
- # specific items
- try:
- mltype = self.ltype
- except:
- mltype = None
- #
- # vector layers (specific items)
- #
- if mltype and mltype == "vector":
- self.popupMenu.AppendSeparator()
- self.popupMenu.Append(self.popupID4, text=_("Show attribute data"))
- self.Bind (wx.EVT_MENU, self.lmgr.OnShowAttributeTable, id=self.popupID4)
-
- self.popupMenu.Append(self.popupID5, text=_("Start editing"))
- self.popupMenu.Append(self.popupID6, text=_("Stop editing"))
- self.popupMenu.Enable(self.popupID6, False)
- self.Bind (wx.EVT_MENU, self.OnStartEditing, id=self.popupID5)
- self.Bind (wx.EVT_MENU, self.OnStopEditing, id=self.popupID6)
-
- layer = self.GetPyData(self.layer_selected)[0]['maplayer']
- # enable editing only for vector map layers available in the current mapset
- digitToolbar = self.mapdisplay.toolbars['vdigit']
- if digitToolbar:
- # background vector map
- self.popupMenu.Append(self.popupID14,
- text=_("Use as background vector map"),
- kind=wx.ITEM_CHECK)
- self.Bind(wx.EVT_MENU, self.OnSetBgMap, id=self.popupID14)
- if UserSettings.Get(group='vdigit', key='bgmap', subkey='value',
- internal=True) == layer.GetName():
- self.popupMenu.Check(self.popupID14, True)
-
- if layer.GetMapset() != grass.gisenv()['MAPSET']:
- # only vector map in current mapset can be edited
- self.popupMenu.Enable (self.popupID5, False)
- self.popupMenu.Enable (self.popupID6, False)
- elif digitToolbar and digitToolbar.GetLayer():
- # vector map already edited
- vdigitLayer = digitToolbar.GetLayer()
- if vdigitLayer is layer:
- # disable 'start editing'
- self.popupMenu.Enable (self.popupID5, False)
- # enable 'stop editing'
- self.popupMenu.Enable(self.popupID6, True)
- # disable 'remove'
- self.popupMenu.Enable(self.popupID1, False)
- # disable 'bgmap'
- self.popupMenu.Enable(self.popupID14, False)
- else:
- # disable 'start editing'
- self.popupMenu.Enable(self.popupID5, False)
- # disable 'stop editing'
- self.popupMenu.Enable(self.popupID6, False)
- # enable 'bgmap'
- self.popupMenu.Enable(self.popupID14, True)
-
- self.popupMenu.Append(self.popupID7, _("Metadata"))
- self.Bind (wx.EVT_MENU, self.OnMetadata, id=self.popupID7)
- if numSelected > 1:
- self.popupMenu.Enable(self.popupID4, False)
- self.popupMenu.Enable(self.popupID5, False)
- self.popupMenu.Enable(self.popupID6, False)
- self.popupMenu.Enable(self.popupID7, False)
- self.popupMenu.Enable(self.popupID14, False)
-
- #
- # raster layers (specific items)
- #
- elif mltype and mltype == "raster":
- self.popupMenu.Append(self.popupID12, text=_("Zoom to selected map(s) (ignore NULLs)"))
- self.Bind(wx.EVT_MENU, self.mapdisplay.MapWindow2D.OnZoomToRaster, id=self.popupID12)
- self.popupMenu.Append(self.popupID13, text=_("Set computational region from selected map(s) (ignore NULLs)"))
- self.Bind(wx.EVT_MENU, self.OnSetCompRegFromRaster, id=self.popupID13)
- self.popupMenu.AppendSeparator()
- self.popupMenu.Append(self.popupID15, _("Set color table"))
- self.Bind (wx.EVT_MENU, self.OnColorTable, id=self.popupID15)
- self.popupMenu.Append(self.popupID4, _("Histogram"))
- self.Bind (wx.EVT_MENU, self.OnHistogram, id=self.popupID4)
- self.popupMenu.Append(self.popupID5, _("Profile"))
- self.Bind (wx.EVT_MENU, self.OnProfile, id=self.popupID5)
- self.popupMenu.Append(self.popupID6, _("Metadata"))
- self.Bind (wx.EVT_MENU, self.OnMetadata, id=self.popupID6)
- if self.mapdisplay.toolbars['nviz']:
- self.popupMenu.Append(self.popupID11, _("Nviz properties"))
- self.Bind (wx.EVT_MENU, self.OnNvizProperties, id=self.popupID11)
-
- if numSelected > 1:
- self.popupMenu.Enable(self.popupID12, False)
- self.popupMenu.Enable(self.popupID13, False)
- self.popupMenu.Enable(self.popupID15, False)
- self.popupMenu.Enable(self.popupID4, False)
- self.popupMenu.Enable(self.popupID5, False)
- self.popupMenu.Enable(self.popupID6, False)
- self.popupMenu.Enable(self.popupID11, False)
-
- ## self.PopupMenu(self.popupMenu, pos)
- self.PopupMenu(self.popupMenu)
- self.popupMenu.Destroy()
-
- def OnMetadata(self, event):
- """!Print metadata of raster/vector map layer
- TODO: Dialog to modify metadata
- """
- mapLayer = self.GetPyData(self.layer_selected)[0]['maplayer']
- mltype = self.GetPyData(self.layer_selected)[0]['type']
-
- if mltype == 'raster':
- cmd = ['r.info']
- elif mltype == 'vector':
- cmd = ['v.info']
- cmd.append('map=%s' % mapLayer.name)
-
-
- # print output to command log area
- self.lmgr.goutput.RunCmd(cmd, switchPage=True)
-
- def OnSetCompRegFromRaster(self, event):
- """!Set computational region from selected raster map (ignore NULLs)"""
- mapLayer = self.GetPyData(self.layer_selected)[0]['maplayer']
-
- cmd = ['g.region',
- '-p',
- 'zoom=%s' % mapLayer.name]
-
- # print output to command log area
- self.lmgr.goutput.RunCmd(cmd)
-
- def OnSetCompRegFromMap(self, event):
- """!Set computational region from selected raster/vector map"""
- rast = []
- vect = []
- rast3d = []
- for layer in self.GetSelections():
- mapLayer = self.GetPyData(layer)[0]['maplayer']
- mltype = self.ltype
-
- if mltype == 'raster':
- rast.append(mapLayer.name)
- elif mltype == 'vector':
- vect.append(mapLayer.name)
- elif mltype == '3d-raster':
- rast3d.append(mapLayer.name)
-
- cmd = ['g.region']
- if rast:
- cmd.append('rast=%s' % ','.join(rast))
- if vect:
- cmd.append('vect=%s' % ','.join(vect))
- if rast3d:
- cmd.append('rast3d=%s' % ','.join(rast3d))
-
- # print output to command log area
- if len(cmd) > 1:
- cmd.append('-p')
- self.lmgr.goutput.RunCmd(cmd)
-
- def OnProfile(self, event):
- """!Plot profile of given raster map layer"""
- mapLayer = self.GetPyData(self.layer_selected)[0]['maplayer']
- if not mapLayer.name:
- wx.MessageBox(parent=self,
- message=_("Unable to create profile of "
- "raster map."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return False
-
- if not hasattr (self, "profileFrame"):
- self.profileFrame = None
-
- if hasattr (self.mapdisplay, "profile") and self.mapdisplay.profile:
- self.profileFrame = self.mapdisplay.profile
-
- if not self.profileFrame:
- self.profileFrame = profile.ProfileFrame(self.mapdisplay,
- id=wx.ID_ANY, pos=wx.DefaultPosition, size=(700,300),
- style=wx.DEFAULT_FRAME_STYLE, rasterList=[mapLayer.name])
- # show new display
- self.profileFrame.Show()
-
- def OnColorTable(self, event):
- """!Set color table for raster map"""
- name = self.GetPyData(self.layer_selected)[0]['maplayer'].name
- menuform.GUI().ParseCommand(['r.colors',
- 'map=%s' % name],
- parentframe=self)
-
- def OnHistogram(self, event):
- """
- Plot histogram for given raster map layer
- """
- mapLayer = self.GetPyData(self.layer_selected)[0]['maplayer']
- if not mapLayer.name:
- wx.MessageBox(parent=self,
- message=_("Unable to display histogram of "
- "raster map."),
- caption=_("Error"), style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return False
-
- if not hasattr (self, "histogramFrame"):
- self.histogramFrame = None
-
- if hasattr (self.mapdisplay, "histogram") and self.mapdisplay.histogram:
- self.histogramFrame = self.mapdisplay.histogram
-
- if not self.histogramFrame:
- self.histogramFrame = histogram.HistFrame(self,
- id=wx.ID_ANY,
- pos=wx.DefaultPosition, size=globalvar.HIST_WINDOW_SIZE,
- style=wx.DEFAULT_FRAME_STYLE)
- # show new display
- self.histogramFrame.Show()
-
- self.histogramFrame.SetHistLayer(mapLayer.name)
- self.histogramFrame.HistWindow.UpdateHist()
- self.histogramFrame.Refresh()
- self.histogramFrame.Update()
-
- return True
-
- def OnStartEditing(self, event):
- """
- Start editing vector map layer requested by the user
- """
- if not haveVDigit:
- from vdigit import errorMsg
- msg = _("Unable to start vector digitizer.\nThe VDigit python extension "
- "was not found or loaded properly.\n"
- "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg)
-
- self.mapdisplay.toolbars['map'].combo.SetValue (_("2D view"))
- wx.MessageBox(parent=self.mapdisplay,
- message=msg,
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
- return
-
- try:
- maplayer = self.GetPyData(self.layer_selected)[0]['maplayer']
- except:
- event.Skip()
- return
-
- if not self.mapdisplay.toolbars['vdigit']: # enable tool
- self.mapdisplay.AddToolbar('vdigit')
- else: # tool already enabled
- pass
-
- # mark layer as 'edited'
- self.mapdisplay.toolbars['vdigit'].StartEditing (maplayer)
-
- def OnStopEditing(self, event):
- """
- Stop editing the current vector map layer
- """
- maplayer = self.GetPyData(self.layer_selected)[0]['maplayer']
-
- self.mapdisplay.toolbars['vdigit'].OnExit()
- self.mapdisplay.imgVectorMap = None
-
- def OnSetBgMap(self, event):
- """!Set background vector map for editing sesstion"""
- if event.IsChecked():
- mapName = self.GetPyData(self.layer_selected)[0]['maplayer'].GetName()
- UserSettings.Set(group='vdigit', key='bgmap', subkey='value',
- value=str(mapName), internal=True)
- else:
- UserSettings.Set(group='vdigit', key='bgmap', subkey='value',
- value='', internal=True)
-
- def OnPopupProperties (self, event):
- """!Popup properties dialog"""
- self.PropertiesDialog(self.layer_selected)
-
- def OnPopupOpacityLevel(self, event):
- """!Popup opacity level indicator"""
- if not self.GetPyData(self.layer_selected)[0]['ctrl']:
- return
-
- #win = self.FindWindowById(self.GetPyData(self.layer_selected)[0]['ctrl'])
- #type = win.GetName()
- #
- #self.layer_selected.DeleteWindow()
-
- maplayer = self.GetPyData(self.layer_selected)[0]['maplayer']
- current_opacity = maplayer.GetOpacity()
-
- dlg = gdialogs.SetOpacityDialog(self, opacity=current_opacity,
- title=_("Set opacity <%s>") % maplayer.GetName())
- dlg.CentreOnParent()
-
- if dlg.ShowModal() == wx.ID_OK:
- new_opacity = dlg.GetOpacity() # string
- self.Map.ChangeOpacity(maplayer, new_opacity)
- maplayer.SetOpacity(new_opacity)
- opacity_pct = int(new_opacity * 100)
- layername = self.GetItemText(self.layer_selected)
- layerbase = layername.split('(')[0].strip()
- self.SetItemText(self.layer_selected,
- layerbase + ' (opacity: ' + str(opacity_pct) + '%)')
-
- # vector layer currently edited
- if self.mapdisplay.toolbars['vdigit'] and \
- self.mapdisplay.toolbars['vdigit'].GetLayer() == maplayer:
- alpha = int(new_opacity * 255)
- self.mapdisplay.digit.driver.UpdateSettings(alpha)
-
- # redraw map if auto-rendering is enabled
- self.rerender = True
- self.reorder = True
- #if self.mapdisplay.statusbarWin['render'].GetValue():
- # print "*** Opacity OnRender *****"
- # self.mapdisplay.OnRender(None)
-
- def OnNvizProperties(self, event):
- """!Nviz-related properties (raster/vector/volume)
-
- @todo vector/volume
- """
- if not self.mapdisplay.nvizToolWin.IsShown():
- self.mapdisplay.nvizToolWin.Show()
-
- self.mapdisplay.nvizToolWin.SetPage('surface')
-
- def RenameLayer (self, event):
- """!Rename layer"""
- self.EditLabel(self.layer_selected)
-
-
- def PlusLayer(self,maplayer):
- self.layer.append(maplayer)
-
-
- def AddLayer(self, ltype, lname=None, lchecked=None,
- lopacity=1.0, lcmd=None, lgroup=None, lvdigit=None, lnviz=None):
- """!Add new item to the layer tree, create corresponding MapLayer instance.
- Launch property dialog if needed (raster, vector, etc.)
-
- @param ltype layer type (raster, vector, 3d-raster, ...)
- @param lname layer name
- @param lchecked if True layer is checked
- @param lopacity layer opacity level
- @param lcmd command (given as a list)
- @param lgroup group name or None
- @param lvdigit vector digitizer settings (eg. geometry attributes)
- @param lnviz layer Nviz properties
- """
- self.first = True
- params = {} # no initial options parameters
-
- self.mapdict[str(lname)]=str(ltype)
-
-
- # deselect active item
- if self.layer_selected:
- self.SelectItem(self.layer_selected, select=False)
-
- Debug.msg (3, "LayerTree().AddLayer(): ltype=%s" % (ltype))
-
- if ltype == 'command':
- # generic command item
- ctrl = wx.TextCtrl(self, id=wx.ID_ANY, value='',
- pos=wx.DefaultPosition, size=(self.GetSize()[0]-100,25),
- # style=wx.TE_MULTILINE|wx.TE_WORDWRAP)
- style=wx.TE_PROCESS_ENTER | wx.TE_DONTWRAP)
- ctrl.Bind(wx.EVT_TEXT_ENTER, self.OnCmdChanged)
- # ctrl.Bind(wx.EVT_TEXT, self.OnCmdChanged)
- elif ltype == 'group':
- # group item
- ctrl = None
- grouptext = _('Layer group:') + str(self.groupnode)
- self.groupnode += 1
- else:
- btnbmp = Icons["layeropts"].GetBitmap((16,16))
- ctrl = buttons.GenBitmapButton(self, id=wx.ID_ANY, bitmap=btnbmp, size=(24,24))
- ctrl.SetToolTipString(_("Click to edit layer settings"))
- self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenu, ctrl)
- # add layer to the layer tree
- if self.layer_selected and self.layer_selected != self.GetRootItem():
- if self.GetPyData(self.layer_selected)[0]['type'] == 'group' \
- and self.IsExpanded(self.layer_selected):
- # add to group (first child of self.layer_selected) if group expanded
- layer = self.PrependItem(parent=self.layer_selected,
- text='', ct_type=1, wnd=ctrl)
- else:
- # prepend to individual layer or non-expanded group
- if lgroup is False:
- # -> last child of root (loading from workspace)
- layer = self.AppendItem(parentId=self.root,
- text='', ct_type=1, wnd=ctrl)
- elif lgroup is True:
- # -> last child of group (loading from workspace)
- parent = self.GetItemParent(self.layer_selected)
- if parent is self.root: # first item in group
- parent=self.layer_selected
- layer = self.AppendItem(parentId=parent,
- text='', ct_type=1, wnd=ctrl)
- elif lgroup is None:
- # -> previous sibling of selected layer
- parent = self.GetItemParent(self.layer_selected)
- layer = self.InsertItem(parentId=parent,
- input=self.GetPrevSibling(self.layer_selected),
- text='', ct_type=1, wnd=ctrl)
- else: # add first layer to the layer tree (first child of root)
- layer = self.PrependItem(parent=self.root, text='', ct_type=1, wnd=ctrl)
-
- # layer is initially unchecked as inactive (beside 'command')
- # use predefined value if given
- if lchecked is not None:
- checked = lchecked
- else:
- checked = True
-
- self.CheckItem(layer, checked=checked)
-
- # select new item
- self.SelectItem(layer, select=True)
- self.layer_selected = layer
-
- # add text and icons for each layer ltype
- if ltype == 'raster':
- self.SetItemImage(layer, self.rast_icon)
- self.SetItemText(layer, '%s %s' % (_('raster'), _('(double click to set properties)')))
- elif ltype == '3d-raster':
- self.SetItemImage(layer, self.rast3d_icon)
- self.SetItemText(layer, '%s %s' % (_('3d raster'), _('(double click to set properties)')))
- elif ltype == 'rgb':
- self.SetItemImage(layer, self.rgb_icon)
- self.SetItemText(layer, '%s %s' % (_('RGB'), _('(double click to set properties)')))
- elif ltype == 'his':
- self.SetItemImage(layer, self.his_icon)
- self.SetItemText(layer, '%s %s' % (_('HIS'), _('(double click to set properties)')))
- elif ltype == 'shaded':
- self.SetItemImage(layer, self.shaded_icon)
- self.SetItemText(layer, '%s %s' % (_('Shaded relief'), _('(double click to set properties)')))
- elif ltype == 'rastnum':
- self.SetItemImage(layer, self.rnum_icon)
- self.SetItemText(layer, '%s %s' % (_('raster cell numbers'), _('(double click to set properties)')))
- elif ltype == 'rastarrow':
- self.SetItemImage(layer, self.rarrow_icon)
- self.SetItemText(layer, '%s %s' % (_('raster flow arrows'), _('(double click to set properties)')))
- elif ltype == 'vector':
- self.SetItemImage(layer, self.vect_icon)
- self.SetItemText(layer, '%s %s' % (_('vector'), _('(double click to set properties)')))
- elif ltype == 'thememap':
- self.SetItemImage(layer, self.theme_icon)
- self.SetItemText(layer, '%s %s' % (_('thematic map'), _('(double click to set properties)')))
- elif ltype == 'themechart':
- self.SetItemImage(layer, self.chart_icon)
- self.SetItemText(layer, '%s %s' % (_('thematic charts'), _('(double click to set properties)')))
- elif ltype == 'grid':
- self.SetItemImage(layer, self.grid_icon)
- self.SetItemText(layer, '%s %s' % (_('grid'), _('(double click to set properties)')))
- elif ltype == 'geodesic':
- self.SetItemImage(layer, self.geodesic_icon)
- self.SetItemText(layer, '%s %s' % (_('geodesic line'), _('(double click to set properties)')))
- elif ltype == 'rhumb':
- self.SetItemImage(layer, self.rhumb_icon)
- self.SetItemText(layer, '%s %s' % (_('rhumbline'), _('(double click to set properties)')))
- elif ltype == 'labels':
- self.SetItemImage(layer, self.labels_icon)
- self.SetItemText(layer, '%s %s' % (_('vector labels'), _('(double click to set properties)')))
- elif ltype == 'command':
- self.SetItemImage(layer, self.cmd_icon)
- elif ltype == 'group':
- self.SetItemImage(layer, self.folder)
- self.SetItemText(layer, grouptext)
-
- self.first = False
-
- if ltype != 'group':
- if lcmd and len(lcmd) > 1:
- cmd = lcmd
- render = False
- name = utils.GetLayerNameFromCmd(lcmd)
- else:
- cmd = []
- if ltype == 'command' and lname:
- for c in lname.split(';'):
- cmd.append(c.split(' '))
-
- render = False
- name = None
-
- if ctrl:
- ctrlId = ctrl.GetId()
- else:
- ctrlId = None
-
- # add a data object to hold the layer's command (does not apply to generic command layers)
- self.SetPyData(layer, ({'cmd' : cmd,
- 'type' : ltype,
- 'ctrl' : ctrlId,
- 'maplayer' : None,
- 'vdigit' : lvdigit,
- 'nviz' : lnviz,
- 'propwin' : None},
- None))
-
- # find previous map layer instance
- prevItem = self.GetFirstChild(self.root)[0]
- prevMapLayer = None
- pos = -1
- while prevItem and prevItem.IsOk() and prevItem != layer:
- if self.GetPyData(prevItem)[0]['maplayer']:
- prevMapLayer = self.GetPyData(prevItem)[0]['maplayer']
-
- prevItem = self.GetNextSibling(prevItem)
-
- if prevMapLayer:
- pos = self.Map.GetLayerIndex(prevMapLayer)
- else:
- pos = -1
-
- maplayer = self.Map.AddLayer(pos=pos,
- type=ltype, command=self.GetPyData(layer)[0]['cmd'], name=name,
- l_active=checked, l_hidden=False,
- l_opacity=lopacity, l_render=render)
- self.GetPyData(layer)[0]['maplayer'] = maplayer
-
- self.layer.append(maplayer)
-
- # run properties dialog if no properties given
- if len(cmd) == 0:
- self.PropertiesDialog(layer, show=True)
-
- if ltype == '3d-raster' and \
- not self.mapdisplay.toolbars['nviz']:
- self.EnableItem(layer, False)
-
- else: # group
- self.SetPyData(layer, ({'cmd': None,
- 'type' : ltype,
- 'ctrl' : None,
- 'maplayer' : None,
- 'propwin' : None},
- None))
-
- # use predefined layer name if given
- if lname:
- if ltype == 'group':
- self.SetItemText(layer, lname)
- elif ltype == 'command':
- ctrl.SetValue(lname)
- else:
- name = lname + ' (opacity: ' + \
- str(self.GetPyData(layer)[0]['maplayer'].GetOpacity()) + '%)'
- self.SetItemText(layer, name)
-
- # updated progress bar range (mapwindow statusbar)
- if checked is True:
- self.mapdisplay.statusbarWin['progress'].SetRange(len(self.Map.GetListOfLayers(l_active=True)))
-
- # self.mapdisplay.statusbarWin['progress'].SetRange(len(self.Map.GetListOfLayers(l_active=True)))
-
- # layer.SetHeight(TREE_ITEM_HEIGHT)
-
- return layer
-
- def PropertiesDialog (self, layer, show=True):
- """!Launch the properties dialog"""
-
-
-
- if self.GetPyData(layer)[0].has_key('propwin') and self.GetPyData(layer)[0]['propwin']:
- win = self.GetPyData(layer)[0]['propwin']
- win.notebookpanel.OnUpdateSelection(None)
- if win.IsShown():
- win.SetFocus()
- else:
- win.Show()
- return
-
- completed = ''
- params = self.GetPyData(layer)[1]
- ltype = self.GetPyData(layer)[0]['type']
-
- Debug.msg (3, "LayerTree.PropertiesDialog(): ltype=%s" % \
- ltype)
-
- if self.GetPyData(layer)[0]['cmd']:
- cmdValidated = menuform.GUI().ParseCommand(self.GetPyData(layer)[0]['cmd'],
- completed=(self.GetOptData,layer,params),
- parentframe=self, show=show)
- self.GetPyData(layer)[0]['cmd'] = cmdValidated
- elif ltype == 'raster':
- cmd = ['d.rast']
-
- if UserSettings.Get(group='cmd', key='rasterOpaque', subkey='enabled'):
- cmd.append('-n')
- menuform.GUI().ParseCommand(cmd, completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == '3d-raster':
- cmd = ['d.rast3d']
- menuform.GUI().ParseCommand(cmd, completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'rgb':
- menuform.GUI().ParseCommand(['d.rgb'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'his':
- menuform.GUI().ParseCommand(['d.his'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'shaded':
- menuform.GUI().ParseCommand(['d.shadedmap'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'rastarrow':
- menuform.GUI().ParseCommand(['d.rast.arrow'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'rastnum':
- menuform.GUI().ParseCommand(['d.rast.num'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'vector':
- types = ''
- for type in UserSettings.Get(group='cmd', key='showType').keys():
- if UserSettings.Get(group='cmd', key='showType', subkey=[type, 'enabled']):
- types += type + ','
- types = types.rstrip(',')
-
- menuform.GUI().ParseCommand(['d.vect', 'type=%s' % types],
- completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'thememap':
- # -s flag requested, otherwise only first thematic category is displayed
- # should be fixed by C-based d.thematic.* modules
- menuform.GUI().ParseCommand(['d.vect.thematic', '-s'],
- completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'themechart':
- menuform.GUI().ParseCommand(['d.vect.chart'],
- completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'grid':
- menuform.GUI().ParseCommand(['d.grid'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'geodesic':
- menuform.GUI().ParseCommand(['d.geodesic'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'rhumb':
- menuform.GUI().ParseCommand(['d.rhumbline'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'labels':
- menuform.GUI().ParseCommand(['d.labels'], completed=(self.GetOptData,layer,params),
- parentframe=self)
- elif ltype == 'cmdlayer':
- pass
- elif ltype == 'group':
- pass
-
- def OnActivateLayer(self, event):
- """!Double click on the layer item.
- Launch property dialog, or expand/collapse group of items, etc."""
-
- layer = event.GetItem()
- self.layer_selected = layer
-
- self.PropertiesDialog (layer)
-
- if self.GetPyData(layer)[0]['type'] == 'group':
- if self.IsExpanded(layer):
- self.Collapse(layer)
- else:
- self.Expand(layer)
-
- def OnDeleteLayer(self, event):
- """!Remove selected layer item from the layer tree"""
-
- self.item = event.GetItem()
- item = self.item
- myString = self.GetItemText(item)
- substr = myString[0:myString.find(" ")]
- del self.mapdict[str(substr)]
- #print self.mapname_list
-
- try:
- item.properties.Close(True)
- except:
- pass
- if item != self.root:
- Debug.msg (3, "LayerTree.OnDeleteLayer(): name=%s" % \
- (self.GetItemText(item)))
- else:
- self.root = None
-
- # unselect item
- self.Unselect()
- self.layer_selected = None
-
- try:
- if self.GetPyData(item)[0]['type'] != 'group':
- self.Map.DeleteLayer( self.GetPyData(item)[0]['maplayer'])
- except:
- pass
-
- # redraw map if auto-rendering is enabled
- self.rerender = True
- self.reorder = True
- #if self.mapdisplay.statusbarWin['render'].GetValue():
- # print "*** Delete OnRender *****"
- # self.mapdisplay.OnRender(None)
-
-
- if self.mapdisplay.toolbars['vdigit']:
- self.mapdisplay.toolbars['vdigit'].UpdateListOfLayers (updateTool=True)
-
- # update progress bar range (mapwindow statusbar)
- self.mapdisplay.statusbarWin['progress'].SetRange(len(self.Map.GetListOfLayers(l_active=True)))
-
- event.Skip()
-
- def OnLayerChecked(self, event):
- """!Enable/disable data layer"""
- item = event.GetItem()
- checked = item.IsChecked()
-
- #import pdb
- #pdb.set_trace()
-
- digitToolbar = self.mapdisplay.toolbars['vdigit']
-
- if self.first == False:
- # change active parameter for item in layers list in render.Map
- if self.ltype == 'group':
- child, cookie = self.GetFirstChild(item)
- while child:
- self.CheckItem(child, checked)
- mapLayer = self.GetPyData(child)[0]['maplayer']
- if not digitToolbar or \
- (digitToolbar and digitToolbar.GetLayer() != mapLayer):
- # ignore when map layer is edited
- self.Map.ChangeLayerActive(mapLayer, checked)
- child = self.GetNextSibling(child)
- else:
- mapLayer = self.GetPyData(item)[0]['maplayer']
- if not digitToolbar or \
- (digitToolbar and digitToolbar.GetLayer() != mapLayer):
- # ignore when map layer is edited
- self.Map.ChangeLayerActive(mapLayer, checked)
-
- #
- # update progress bar range (mapwindow statusbar)
-
-
- self.mapdisplay.statusbarWin['progress'].SetRange(len(self.Map.GetListOfLayers(l_active=True)))
-
- #
- # nviz
- #
- if self.mapdisplay.toolbars['nviz'] and \
- self.GetPyData(item) is not None:
- # nviz - load/unload data layer
- mapLayer = self.GetPyData(item)[0]['maplayer']
-
- self.mapdisplay.SetStatusText(_("Please wait, updating data..."), 0)
-
- if checked: # enable
- if mapLayer.type == 'raster':
- self.mapdisplay.MapWindow.LoadRaster(item)
- elif mapLayer.type == '3d-raster':
- self.mapdisplay.MapWindow.LoadRaster3d(item)
- elif mapLayer.type == 'vector':
- self.mapdisplay.MapWindow.LoadVector(item)
-
- else: # disable
- data = self.GetPyData(item)[0]['nviz']
-
- if mapLayer.type == 'raster':
- self.mapdisplay.MapWindow.UnloadRaster(item)
- elif mapLayer.type == '3d-raster':
- self.mapdisplay.MapWindow.UnloadRaster3d(item)
- elif mapLayer.type == 'vector':
- self.mapdisplay.MapWindow.UnloadVector(item)
-
- if hasattr(self.mapdisplay, "nvizToolWin"):
- toolWin = self.mapdisplay.nvizToolWin
- # remove vector page
- if toolWin.notebook.GetSelection() == toolWin.page['vector']['id']:
- toolWin.notebook.RemovePage(toolWin.page['vector']['id'])
- toolWin.page['vector']['id'] = -1
- toolWin.page['settings']['id'] = 1
-
- self.mapdisplay.SetStatusText("", 0)
-
- # redraw map if auto-rendering is enabled
- self.rerender = True
- self.reorder = True
- #if self.mapdisplay.statusbarWin['render'].GetValue():
- # print "*** Checked OnRender *****"
- # self.mapdisplay.OnRender(None)
-
- def OnCmdChanged(self, event):
- """!Change command string"""
- ctrl = event.GetEventObject().GetId()
- cmd = event.GetString()
-
- layer = self.GetFirstVisibleItem()
-
- while layer and layer.IsOk():
- if self.GetPyData(layer)[0]['ctrl'] == ctrl:
- break
-
- layer = self.GetNextVisible(layer)
-
- # change parameters for item in layers list in render.Map
- self.ChangeLayer(layer)
-
- event.Skip()
-
- def OnChangeSel(self, event):
- """!Selection changed"""
- oldlayer = event.GetOldItem()
- layer = event.GetItem()
- if layer == oldlayer:
- event.Veto()
- return
-
- self.layer_selected = layer
-
- try:
- self.RefreshLine(oldlayer)
- self.RefreshLine(layer)
- except:
- pass
-
- #
- # update statusbar -> show command string
- #
- if self.GetPyData(layer) and self.GetPyData(layer)[0]['maplayer']:
- cmd = self.GetPyData(layer)[0]['maplayer'].GetCmd(string=True)
- if len(cmd) > 0:
- self.lmgr.SetStatusText(cmd)
-
- # set region if auto-zooming is enabled
- if self.GetPyData(layer) and self.GetPyData(layer)[0]['cmd'] and \
- UserSettings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'):
- mapLayer = self.GetPyData(layer)[0]['maplayer']
- if mapLayer.GetType() in ('raster', 'vector'):
- render = self.mapdisplay.statusbarWin['render'].IsChecked()
- self.mapdisplay.MapWindow.ZoomToMap(layers = [mapLayer,],
- render = render)
-
- #
- # update nviz tools
- #
-
-
- if self.mapdisplay.toolbars['nviz'] and \
- self.GetPyData(self.layer_selected) is not None:
-
- if self.layer_selected.IsChecked():
- # update Nviz tool window
- type = self.GetPyData(self.layer_selected)[0]['maplayer'].type
-
- if type == 'raster':
- self.mapdisplay.nvizToolWin.UpdatePage('surface')
- self.mapdisplay.nvizToolWin.SetPage('surface')
- elif type == 'vector':
- self.mapdisplay.nvizToolWin.UpdatePage('vector')
- self.mapdisplay.nvizToolWin.SetPage('vector')
- elif type == '3d-raster':
- self.mapdisplay.nvizToolWin.UpdatePage('volume')
- self.mapdisplay.nvizToolWin.SetPage('volume')
- else:
- for page in ('surface', 'vector', 'volume'):
- pageId = self.mapdisplay.nvizToolWin.page[page]['id']
- if pageId > -1:
- self.mapdisplay.nvizToolWin.notebook.RemovePage(pageId)
- self.mapdisplay.nvizToolWin.page[page]['id'] = -1
- self.mapdisplay.nvizToolWin.page['settings']['id'] = 1
-
- def OnCollapseNode(self, event):
- """
- Collapse node
- """
- if self.GetPyData(self.layer_selected)[0]['type'] == 'group':
- self.SetItemImage(self.layer_selected, self.folder)
-
- def OnExpandNode(self, event):
- """
- Expand node
- """
- self.layer_selected = event.GetItem()
- if self.GetPyData(self.layer_selected)[0]['type'] == 'group':
- self.SetItemImage(self.layer_selected, self.folder_open)
-
- def OnEndDrag(self, event):
- self.StopDragging()
- dropTarget = event.GetItem()
- self.flag = self.HitTest(event.GetPoint())[1]
- if self.IsValidDropTarget(dropTarget):
- self.UnselectAll()
- if dropTarget != None:
- self.SelectItem(dropTarget)
- self.OnDrop(dropTarget, self._dragItem)
- elif dropTarget == None:
- self.OnDrop(dropTarget, self._dragItem)
-
- def OnDrop(self, dropTarget, dragItem):
- # save everthing associated with item to drag
- try:
- old = dragItem # make sure this member exists
- except:
- return
-
- Debug.msg (4, "LayerTree.OnDrop(): layer=%s" % \
- (self.GetItemText(dragItem)))
-
- # recreate data layer, insert copy of layer in new position, and delete original at old position
- newItem = self.RecreateItem (dragItem, dropTarget)
-
- # if recreated layer is a group, also recreate its children
- if self.GetPyData(newItem)[0]['type'] == 'group':
- (child, cookie) = self.GetFirstChild(dragItem)
- if child:
- while child:
- self.RecreateItem(child, dropTarget, parent=newItem)
- self.Delete(child)
- child = self.GetNextChild(old, cookie)[0]
- #self.Expand(newItem)
-
- # delete layer at original position
- try:
- self.Delete(old) # entry in render.Map layers list automatically deleted by OnDeleteLayer handler
- except AttributeError:
- # FIXME being ugly (item.SetWindow(None))
- pass
-
- # reorder layers in render.Map to match new order after drag and drop
- #self.ReorderLayers()
-
- # redraw map if auto-rendering is enabled
- self.rerender = True
- self.reorder = True
- #if self.mapdisplay.statusbarWin['render'].GetValue():
- # print "*** Drop OnRender *****"
- # self.mapdisplay.OnRender(None)
-
- # select new item
- self.SelectItem(newItem)
-
- def RecreateItem (self, dragItem, dropTarget, parent=None):
- """
- Recreate item (needed for OnEndDrag())
- """
- Debug.msg (4, "LayerTree.RecreateItem(): layer=%s" % \
- self.GetItemText(dragItem))
-
- # fetch data (dragItem)
- checked = self.IsItemChecked(dragItem)
- image = self.GetItemImage(dragItem, 0)
- text = self.GetItemText(dragItem)
- if self.GetPyData(dragItem)[0]['ctrl']:
- # recreate data layer
- btnbmp = Icons["layeropts"].GetBitmap((16,16))
- newctrl = buttons.GenBitmapButton(self, id=wx.ID_ANY, bitmap=btnbmp, size=(24, 24))
- newctrl.SetToolTipString(_("Click to edit layer settings"))
- self.Bind(wx.EVT_BUTTON, self.OnLayerContextMenu, newctrl)
- data = self.GetPyData(dragItem)
-
- elif self.GetPyData(dragItem)[0]['type'] == 'command':
- # recreate command layer
- oldctrl = None
- newctrl = wx.TextCtrl(self, id=wx.ID_ANY, value='',
- pos=wx.DefaultPosition, size=(250,25),
- style=wx.TE_MULTILINE|wx.TE_WORDWRAP)
- try:
- newctrl.SetValue(self.GetPyData(dragItem)[0]['maplayer'].GetCmd(string=True))
- except:
- pass
- newctrl.Bind(wx.EVT_TEXT_ENTER, self.OnCmdChanged)
- newctrl.Bind(wx.EVT_TEXT, self.OnCmdChanged)
- data = self.GetPyData(dragItem)
-
- elif self.GetPyData(dragItem)[0]['type'] == 'group':
- # recreate group
- newctrl = None
- data = None
-
- # decide where to put recreated item
- if dropTarget != None and dropTarget != self.GetRootItem():
- if parent:
- # new item is a group
- afteritem = parent
- else:
- # new item is a single layer
- afteritem = dropTarget
-
- # dragItem dropped on group
- if self.GetPyData(afteritem)[0]['type'] == 'group':
- newItem = self.PrependItem(afteritem, text=text, \
- ct_type=1, wnd=newctrl, image=image, \
- data=data)
- self.Expand(afteritem)
- else:
- #dragItem dropped on single layer
- newparent = self.GetItemParent(afteritem)
- newItem = self.InsertItem(newparent, self.GetPrevSibling(afteritem), \
- text=text, ct_type=1, wnd=newctrl, \
- image=image, data=data)
- else:
- # if dragItem not dropped on a layer or group, append or prepend it to the layer tree
- if self.flag & wx.TREE_HITTEST_ABOVE:
- newItem = self.PrependItem(self.root, text=text, \
- ct_type=1, wnd=newctrl, image=image, \
- data=data)
- elif (self.flag & wx.TREE_HITTEST_BELOW) or (self.flag & wx.TREE_HITTEST_NOWHERE) \
- or (self.flag & wx.TREE_HITTEST_TOLEFT) or (self.flag & wx.TREE_HITTEST_TORIGHT):
- newItem = self.AppendItem(self.root, text=text, \
- ct_type=1, wnd=newctrl, image=image, \
- data=data)
-
- #update new layer
- self.SetPyData(newItem, self.GetPyData(dragItem))
- if newctrl:
- self.GetPyData(newItem)[0]['ctrl'] = newctrl.GetId()
- else:
- self.GetPyData(newItem)[0]['ctrl'] = None
-
- self.CheckItem(newItem, checked=checked) # causes a new render
-
- # newItem.SetHeight(TREE_ITEM_HEIGHT)
-
- return newItem
-
- def GetOptData(self, dcmd, layer, params, propwin):
- """!Process layer data"""
- # set layer text to map name
- if dcmd:
- mapLayer = self.GetPyData(layer)[0]['maplayer']
- opacity = int(mapLayer.GetOpacity(float=True) * 100)
- mapname = utils.GetLayerNameFromCmd(dcmd, layerType=mapLayer.type,
- fullyQualified=True)
- if not mapname:
- wx.MessageBox(parent=self,
- message=_("Map <%s> not found.") % utils.GetLayerNameFromCmd(dcmd),
- caption=_("Error"),
- style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-
- return
-
- self.SetItemText(layer, mapname + ' (opacity: ' + str(opacity) + '%)')
-
- # update layer data
- if params:
- self.SetPyData(layer, (self.GetPyData(layer)[0], params))
- if dcmd:
- self.GetPyData(layer)[0]['cmd'] = dcmd
- self.GetPyData(layer)[0]['propwin'] = propwin
-
- # change parameters for item in layers list in render.Map
- self.ChangeLayer(layer)
-
- # set region if auto-zooming is enabled
- if dcmd and UserSettings.Get(group = 'display', key = 'autoZooming', subkey = 'enabled'):
- mapLayer = self.GetPyData(layer)[0]['maplayer']
- if mapLayer.GetType() in ('raster', 'vector'):
- render = UserSettings.Get(group = 'display', key = 'autoRendering', subkey = 'enabled')
- self.mapdisplay.MapWindow.ZoomToMap(layers = [mapLayer,],
- render = render)
-
- if self.mapdisplay.toolbars['nviz'] and dcmd:
- # update nviz session
- mapLayer = self.GetPyData(layer)[0]['maplayer']
- mapWin = self.mapdisplay.MapWindow
- if len(mapLayer.GetCmd()) > 0:
- id = -1
- if mapLayer.type == 'raster':
- if mapWin.IsLoaded(layer):
- mapWin.UnloadRaster(layer)
-
- mapWin.LoadRaster(layer)
-
- elif mapLayer.type == '3d-raster':
- if mapWin.IsLoaded(layer):
- mapWin.UnloadRaster3d(layer)
-
- mapWin.LoadRaster3d(layer)
-
- elif mapLayer.type == 'vector':
- if mapWin.IsLoaded(layer):
- mapWin.UnloadVector(layer)
-
- mapWin.LoadVector(layer)
-
- # reset view when first layer loaded
- nlayers = len(mapWin.Map.GetListOfLayers(l_type=('raster', 'vector'),
- l_active=True))
- if nlayers < 2:
- mapWin.ResetView()
-
- def ReorderLayers(self):
- """!Add commands from data associated with
- any valid layers (checked or not) to layer list in order to
- match layers in layer tree."""
-
- # make a list of visible layers
- treelayers = []
-
- vislayer = self.GetFirstVisibleItem()
-
- if not vislayer or self.GetPyData(vislayer) is None:
- return
-
- itemList = ""
-
- for item in range(self.GetCount()):
- itemList += self.GetItemText(vislayer) + ','
- if self.GetPyData(vislayer)[0]['type'] != 'group':
- treelayers.append(self.GetPyData(vislayer)[0]['maplayer'])
-
- if not self.GetNextVisible(vislayer):
- break
- else:
- vislayer = self.GetNextVisible(vislayer)
-
- Debug.msg (4, "LayerTree.ReorderLayers(): items=%s" % \
- (itemList))
-
- # reorder map layers
- treelayers.reverse()
- self.Map.ReorderLayers(treelayers)
- self.reorder = False
-
- def ChangeLayer(self, item):
- """!Change layer"""
- type = self.GetPyData(item)[0]['type']
- layerName = None
-
- if type == 'command':
- win = self.FindWindowById(self.GetPyData(item)[0]['ctrl'])
- if win.GetValue() != None:
- cmd = win.GetValue().split(';')
- cmdlist = []
- for c in cmd:
- cmdlist.append(c.split(' '))
- opac = 1.0
- chk = self.IsItemChecked(item)
- hidden = not self.IsVisible(item)
- elif type != 'group':
- if self.GetPyData(item)[0] is not None:
- cmdlist = self.GetPyData(item)[0]['cmd']
- opac = self.GetPyData(item)[0]['maplayer'].GetOpacity(float=True)
- chk = self.IsItemChecked(item)
- hidden = not self.IsVisible(item)
- # determine layer name
- layerName = utils.GetLayerNameFromCmd(cmdlist, fullyQualified=True)
- if not layerName:
- layerName = self.GetItemText(item)
-
- maplayer = self.Map.ChangeLayer(layer=self.GetPyData(item)[0]['maplayer'], type=type,
- command=cmdlist, name=layerName,
- l_active=chk, l_hidden=hidden, l_opacity=opac, l_render=False)
-
- self.GetPyData(item)[0]['maplayer'] = maplayer
-
- # if digitization tool enabled -> update list of available vector map layers
- if self.mapdisplay.toolbars['vdigit']:
- self.mapdisplay.toolbars['vdigit'].UpdateListOfLayers(updateTool=True)
-
- # redraw map if auto-rendering is enabled
- self.rerender = True
- self.reorder = True
- #if self.mapdisplay.statusbarWin['render'].GetValue():
- # print "*** Change OnRender *****"
- # self.mapdisplay.OnRender(None)
-
- def OnCloseWindow(self, event):
- pass
- # self.Map.Clean()
-
- def FindItemByData(self, key, value):
- """!Find item based on key and value (see PyData[0])"""
- item = self.GetFirstChild(self.root)[0]
- return self.__FindSubItemByData(item, key, value)
-
- def EnableItemType(self, type, enable=True):
- """!Enable/disable items in layer tree"""
- item = self.GetFirstChild(self.root)[0]
- while item and item.IsOk():
- mapLayer = self.GetPyData(item)[0]['maplayer']
- if mapLayer and type == mapLayer.type:
- self.EnableItem(item, enable)
-
- item = self.GetNextSibling(item)
-
- def __FindSubItemByData(self, item, key, value):
- """!Support method for FindItemByValue"""
- while item and item.IsOk():
- itemValue = self.GetPyData(item)[0][key]
- if value == itemValue:
- return item
- if self.GetPyData(item)[0]['type'] == 'group':
- subItem = self.GetFirstChild(item)[0]
- found = self.__FindSubItemByData(subItem, key, value)
- if found:
- return found
- item = self.GetNextSibling(item)
-
- return None
-
More information about the grass-commit
mailing list