GRASS Programmer's Manual  6.4.2(2012)
toolbars.py
Go to the documentation of this file.
00001 """!
00002 @package toolbar
00003 
00004 @brief wxGUI toolbar widgets
00005 
00006 Classes:
00007  - AbstractToolbar
00008  - MapToolbar
00009  - GCPMapToolbar
00010  - GCPDisplayToolbar
00011  - VDigitToolbar
00012  - ProfileToolbar
00013  - NvizToolbar
00014  - ModelToolbar
00015  - HistogramToolbar
00016  - LMWorkspaceToolbar
00017  - LMDataToolbar
00018  - LMToolsToolbar
00019  - LMMiscToolbar
00020  - LMVectorToolbar
00021  - PsMapToolbar
00022 
00023 (C) 2007-2011 by the GRASS Development Team
00024 This program is free software under the GNU General Public License
00025 (>=v2). Read the file COPYING that comes with GRASS for details.
00026 
00027 @author Michael Barton
00028 @author Jachym Cepicky
00029 @author Martin Landa <landa.martin gmail.com>
00030 @author Anna Kratochvilova <anna.kratochvilova fsv.cvut.cz>
00031 """
00032 
00033 import os
00034 import sys
00035 import platform
00036 
00037 from grass.script import core as grass
00038 
00039 import wx
00040 
00041 import globalvar
00042 import gcmd
00043 import gdialogs
00044 from vdigit import VDigitSettingsDialog, haveVDigit, VDigit
00045 from debug import Debug
00046 from preferences import globalSettings as UserSettings
00047 from nviz import haveNviz
00048 from nviz_preferences import NvizPreferencesDialog
00049 
00050 sys.path.append(os.path.join(globalvar.ETCWXDIR, "icons"))
00051 from icon import Icons
00052 
00053 class AbstractToolbar(wx.ToolBar):
00054     """!Abstract toolbar class"""
00055     def __init__(self, parent):
00056         self.parent = parent
00057         wx.ToolBar.__init__(self, parent = self.parent, id = wx.ID_ANY)
00058         
00059         self.action = dict()
00060         
00061         self.Bind(wx.EVT_TOOL, self.OnTool)
00062         
00063         self.SetToolBitmapSize(globalvar.toolbarSize)
00064         
00065     def InitToolbar(self, toolData):
00066         """!Initialize toolbar, add tools to the toolbar
00067         """
00068         for tool in toolData:
00069             self.CreateTool(*tool)
00070         
00071         self._data = toolData
00072         
00073     def _toolbarData(self):
00074         """!Toolbar data (virtual)"""
00075         return None
00076     
00077     def CreateTool(self, label, bitmap, kind,
00078                    shortHelp, longHelp, handler):
00079         """!Add tool to the toolbar
00080         
00081         @return id of tool
00082         """
00083         bmpDisabled = wx.NullBitmap
00084         tool = -1
00085         if label: 
00086             tool = vars(self)[label] = wx.NewId()
00087             Debug.msg(3, "CreateTool(): tool=%d, label=%s bitmap=%s" % \
00088                           (tool, label, bitmap))
00089             
00090             toolWin = self.AddLabelTool(tool, label, bitmap,
00091                                         bmpDisabled, kind,
00092                                         shortHelp, longHelp)
00093             self.Bind(wx.EVT_TOOL, handler, toolWin)
00094         else: # separator
00095             self.AddSeparator()
00096         
00097         return tool
00098     
00099     def EnableLongHelp(self, enable = True):
00100         """!Enable/disable long help
00101         
00102         @param enable True for enable otherwise disable
00103         """
00104         for tool in self._data:
00105             if tool[0] == '': # separator
00106                 continue
00107             
00108             if enable:
00109                 self.SetToolLongHelp(vars(self)[tool[0]], tool[4])
00110             else:
00111                 self.SetToolLongHelp(vars(self)[tool[0]], "")
00112         
00113     def OnTool(self, event):
00114         """!Tool selected
00115         """
00116         if self.parent.GetName() == "GCPFrame":
00117             return
00118         
00119         if hasattr(self.parent, 'toolbars'):
00120             if self.parent.toolbars['vdigit']:
00121                 # update vdigit toolbar (unselect currently selected tool)
00122                 id = self.parent.toolbars['vdigit'].GetAction(type = 'id')
00123                 self.parent.toolbars['vdigit'].ToggleTool(id, False)
00124         
00125         if event:
00126             # deselect previously selected tool
00127             id = self.action.get('id', -1)
00128             if id != event.GetId():
00129                 self.ToggleTool(self.action['id'], False)
00130             else:
00131                 self.ToggleTool(self.action['id'], True)
00132             
00133             self.action['id'] = event.GetId()
00134             
00135             event.Skip()
00136         else:
00137             # initialize toolbar
00138             self.ToggleTool(self.action['id'], True)
00139         
00140     def GetAction(self, type = 'desc'):
00141         """!Get current action info"""
00142         return self.action.get(type, '')
00143     
00144     def SelectDefault(self, event):
00145         """!Select default tool"""
00146         self.ToggleTool(self.defaultAction['id'], True)
00147         self.defaultAction['bind'](event)
00148         self.action = { 'id' : self.defaultAction['id'],
00149                         'desc' : self.defaultAction.get('desc', '') }
00150         
00151     def FixSize(self, width):
00152         """!Fix toolbar width on Windows
00153         
00154         @todo Determine why combobox causes problems here
00155         """
00156         if platform.system() == 'Windows':
00157             size = self.GetBestSize()
00158             self.SetSize((size[0] + width, size[1]))
00159 
00160     def Enable(self, tool, enable = True):
00161         """!Enable defined tool
00162         
00163         @param tool name
00164         @param enable True to enable otherwise disable tool
00165         """
00166         try:
00167             id = getattr(self, tool)
00168         except AttributeError:
00169             return
00170         
00171         self.EnableTool(id, enable)
00172         
00173     def _getToolbarData(self, data):
00174         """!Define tool
00175         """
00176         retData = list()
00177         for args in data:
00178             retData.append(self._defineTool(*args))
00179         
00180         return retData
00181 
00182     def _defineTool(self, name = None, icon = None, handler = None, item = wx.ITEM_NORMAL):
00183         """!Define tool
00184         """
00185         if name:
00186             return (name, icon.GetBitmap(),
00187                     item, icon.GetLabel(), icon.GetDesc(),
00188                     handler)
00189         return ("", "", "", "", "", "") # separator
00190     
00191 class MapToolbar(AbstractToolbar):
00192     """!Map Display toolbar
00193     """
00194     def __init__(self, parent, mapcontent):
00195         """!Map Display constructor
00196 
00197         @param parent reference to MapFrame
00198         @param mapcontent reference to render.Map (registred by MapFrame)
00199         """
00200         self.mapcontent = mapcontent # render.Map
00201         AbstractToolbar.__init__(self, parent = parent) # MapFrame
00202         
00203         self.InitToolbar(self._toolbarData())
00204         
00205         # optional tools
00206         choices = [ _('2D view'), ]
00207         self.toolId = { '2d' : 0 }
00208         if self.parent.GetLayerManager():
00209             log = self.parent.GetLayerManager().GetLogWindow()
00210         
00211         if haveNviz:
00212             choices.append(_('3D view'))
00213             self.toolId['3d'] = 1
00214         else:
00215             from nviz import errorMsg
00216             ### log.WriteCmdLog(_('3D view mode not available'))
00217             ### log.WriteWarning(_('Reason: %s') % str(errorMsg))
00218             ### log.WriteLog(_('Note that the wxGUI\'s 3D view mode is currently disabled '
00219             ### 'on MS Windows (hopefully this will be fixed soon). '
00220             ### 'Please keep an eye out for updated versions of GRASS. '
00221             ### 'In the meantime you can use "NVIZ" from the File menu.'), wrap = 60)
00222             
00223             self.toolId['3d'] = -1
00224 
00225         if haveVDigit:
00226             choices.append(_('Digitize'))
00227             if self.toolId['3d'] > -1:
00228                 self.toolId['vdigit'] = 2
00229             else:
00230                 self.toolId['vdigit'] = 1
00231         else:
00232             from vdigit import errorMsg
00233             log.WriteCmdLog(_('Vector digitizer not available'))
00234             log.WriteWarning(_('Reason: %s') % errorMsg)
00235             log.WriteLog(_('Note that the wxGUI\'s vector digitizer is currently disabled '
00236                            '(hopefully this will be fixed soon). '
00237                            'Please keep an eye out for updated versions of GRASS. '
00238                            'In the meantime you can use "v.digit" from the Develop Vector menu.'), wrap = 60)
00239             
00240             self.toolId['vdigit'] = -1
00241         
00242         self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
00243                                  choices = choices,
00244                                  style = wx.CB_READONLY, size = (110, -1))
00245         self.combo.SetSelection(0)
00246         
00247         self.comboid = self.AddControl(self.combo)
00248         self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectTool, self.comboid)
00249         
00250         # realize the toolbar
00251         self.Realize()
00252         
00253         # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
00254         self.combo.Hide()
00255         self.combo.Show()
00256         
00257         self.action = { 'id' : self.pointer }
00258         self.defaultAction = { 'id' : self.pointer,
00259                                'bind' : self.parent.OnPointer }
00260         
00261         self.OnTool(None)
00262         
00263         self.EnableTool(self.zoomback, False)
00264         
00265         self.FixSize(width = 90)
00266         
00267     def _toolbarData(self):
00268         """!Toolbar data"""
00269         icons = Icons['displayWindow']
00270         return self._getToolbarData((('displaymap', icons['display'],
00271                                       self.parent.OnDraw),
00272                                      ('rendermap', icons['render'],
00273                                       self.parent.OnRender),
00274                                      ('erase', icons['erase'],
00275                                       self.parent.OnErase),
00276                                      (None, ),
00277                                      ('pointer', icons['pointer'],
00278                                       self.parent.OnPointer,
00279                                       wx.ITEM_CHECK),
00280                                      ('query', icons['query'],
00281                                       self.parent.OnQuery,
00282                                       wx.ITEM_CHECK),
00283                                      ('pan', icons['pan'],
00284                                       self.parent.OnPan,
00285                                       wx.ITEM_CHECK),
00286                                      ('zoomin', icons['zoomIn'],
00287                                       self.parent.OnZoomIn,
00288                                       wx.ITEM_CHECK),
00289                                      ('zoomout', icons['zoomOut'],
00290                                       self.parent.OnZoomOut,
00291                                       wx.ITEM_CHECK),
00292                                      ('zoomextent', icons['zoomExtent'],
00293                                       self.parent.OnZoomToMap),
00294                                      ('zoomback', icons['zoomBack'],
00295                                       self.parent.OnZoomBack),
00296                                      ('zoommenu', icons['zoomMenu'],
00297                                       self.parent.OnZoomMenu),
00298                                      (None, ),
00299                                      ('analyze', icons['analyze'],
00300                                       self.parent.OnAnalyze),
00301                                      (None, ),
00302                                      ('dec', icons['overlay'],
00303                                       self.parent.OnDecoration),
00304                                      (None, ),
00305                                      ('savefile', icons['saveFile'],
00306                                       self.parent.SaveToFile),
00307                                      ('printmap', icons['print'],
00308                                       self.parent.PrintMenu),
00309                                      (None, ))
00310                                     )
00311     
00312     def OnSelectTool(self, event):
00313         """!Select / enable tool available in tools list
00314         """
00315         tool =  event.GetSelection()
00316         
00317         if tool == self.toolId['2d']:
00318             self.ExitToolbars()
00319             self.Enable2D(True)
00320         
00321         elif tool == self.toolId['3d'] and \
00322                 not self.parent.toolbars['nviz']:
00323             self.ExitToolbars()
00324             self.parent.AddToolbar("nviz")
00325             
00326         elif tool == self.toolId['vdigit'] and \
00327                 not self.parent.toolbars['vdigit']:
00328             self.ExitToolbars()
00329             self.parent.AddToolbar("vdigit")
00330             self.parent.MapWindow.SetFocus()
00331         
00332     def ExitToolbars(self):
00333         if self.parent.toolbars['vdigit']:
00334             self.parent.toolbars['vdigit'].OnExit()
00335         if self.parent.toolbars['nviz']:       
00336             self.parent.toolbars['nviz'].OnExit()
00337         
00338     def Enable2D(self, enabled):
00339         """!Enable/Disable 2D display mode specific tools"""
00340         for tool in (self.pointer,
00341                      self.pan,
00342                      self.zoomin,
00343                      self.zoomout,
00344                      self.zoomback,
00345                      self.zoommenu,
00346                      self.analyze,
00347                      self.dec,
00348                      self.printmap):
00349             self.EnableTool(tool, enabled)
00350         
00351 class GCPManToolbar(AbstractToolbar):
00352     """!Toolbar for managing ground control points
00353 
00354     @param parent reference to GCP widget
00355     """
00356     def __init__(self, parent):
00357         AbstractToolbar.__init__(self, parent)
00358         
00359         self.InitToolbar(self._toolbarData())
00360         
00361         # realize the toolbar
00362         self.Realize()
00363 
00364     def _toolbarData(self):
00365         icons = Icons['georectify']
00366         return self._getToolbarData((('gcpSave', icons["gcpSave"],
00367                                       self.parent.SaveGCPs),
00368                                      ('gcpReload', icons["gcpReload"],
00369                                       self.parent.ReloadGCPs),
00370                                      (None, ),
00371                                      ('gcpAdd', icons["gcpAdd"],
00372                                       self.parent.AddGCP),
00373                                      ('gcpDelete', icons["gcpDelete"],
00374                                       self.parent.DeleteGCP),
00375                                      ('gcpClear', icons["gcpClear"],
00376                                       self.parent.ClearGCP),
00377                                      (None, ),
00378                                      ('rms', icons["gcpRms"],
00379                                       self.parent.OnRMS),
00380                                      ('georect', icons["georectify"],
00381                                       self.parent.OnGeorect))
00382                                     )
00383     
00384 class GCPDisplayToolbar(AbstractToolbar):
00385     """
00386     GCP Display toolbar
00387     """
00388     def __init__(self, parent):
00389         """!
00390         GCP Display toolbar constructor
00391         """
00392         AbstractToolbar.__init__(self, parent)
00393         
00394         self.InitToolbar(self._toolbarData())
00395         
00396         # add tool to toggle active map window
00397         self.togglemapid = wx.NewId()
00398         self.togglemap = wx.Choice(parent = self, id = self.togglemapid,
00399                                                     choices = [_('source'), _('target')],
00400                                                     style = wx.CB_READONLY)
00401 
00402         self.InsertControl(10, self.togglemap)
00403 
00404         self.SetToolShortHelp(self.togglemapid, '%s %s %s' % (_('Set map canvas for '),
00405                                                               Icons['displayWindow']["zoomBack"].GetLabel(),
00406                                                               _(' / Zoom to map')))
00407 
00408         # realize the toolbar
00409         self.Realize()
00410         
00411         self.action = { 'id' : self.gcpset }
00412         self.defaultAction = { 'id' : self.gcpset,
00413                                'bind' : self.parent.OnPointer }
00414         
00415         self.OnTool(None)
00416         
00417         self.EnableTool(self.zoomback, False)
00418         
00419     def _toolbarData(self):
00420         """!Toolbar data"""
00421         icons = Icons['displayWindow']
00422         return self._getToolbarData((("displaymap", icons["display"],
00423                                       self.parent.OnDraw),
00424                                      ("rendermap", icons["render"],
00425                                       self.parent.OnRender),
00426                                      ("erase", icons["erase"],
00427                                       self.parent.OnErase),
00428                                      (None, ),
00429                                      ("gcpset", Icons["georectify"]["gcpSet"],
00430                                       self.parent.OnPointer),
00431                                      ("pan", icons["pan"],
00432                                       self.parent.OnPan),
00433                                      ("zoomin", icons["zoomIn"],
00434                                       self.parent.OnZoomIn),
00435                                      ("zoomout", icons["zoomOut"],
00436                                       self.parent.OnZoomOut),
00437                                      ("zoommenu", icons["zoomMenu"],
00438                                       self.parent.OnZoomMenuGCP),
00439                                      (None, ),
00440                                      ("zoomback", icons["zoomBack"],
00441                                       self.parent.OnZoomBack),
00442                                      ("zoomtomap", icons["zoomExtent"],
00443                                       self.parent.OnZoomToMap),
00444                                      (None, ),
00445                                      ('settings', Icons["georectify"]["settings"],
00446                                       self.parent.OnSettings),
00447                                      ('help', Icons["misc"]["help"],
00448                                       self.parent.OnHelp),
00449                                      (None, ),
00450                                      ('quit', Icons["georectify"]["quit"],
00451                                       self.parent.OnQuit))
00452                                     )
00453     
00454     def OnZoomMap(self, event):
00455         """!Zoom to selected map"""
00456         self.parent.MapWindow.ZoomToMap(layers = self.mapcontent.GetListOfLayers())
00457         if event:
00458             event.Skip()
00459         
00460 class VDigitToolbar(AbstractToolbar):
00461     """!Toolbar for digitization
00462     """
00463     def __init__(self, parent, mapcontent, layerTree = None, log = None):
00464         self.mapcontent    = mapcontent # Map class instance
00465         self.layerTree     = layerTree  # reference to layer tree associated to map display
00466         self.log           = log        # log area
00467         AbstractToolbar.__init__(self, parent)
00468         self.digit         = None
00469         
00470         # currently selected map layer for editing (reference to MapLayer instance)
00471         self.mapLayer = None
00472         # list of vector layers from Layer Manager (only in the current mapset)
00473         self.layers   = [] 
00474         
00475         self.comboid    = None
00476         
00477         # only one dialog can be open
00478         self.settingsDialog   = None
00479         
00480         # create toolbars (two rows optionally)
00481         self.InitToolbar(self._toolbarData())
00482         self.Bind(wx.EVT_TOOL, self.OnTool)
00483         
00484         # default action (digitize new point, line, etc.)
00485         self.action = { 'desc' : '',
00486                         'type' : '',
00487                         'id'   : -1 }
00488         
00489         # list of available vector maps
00490         self.UpdateListOfLayers(updateTool = True)
00491         
00492         # realize toolbar
00493         self.Realize()
00494         # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
00495         self.combo.Hide()
00496         self.combo.Show()
00497         
00498         # disable undo/redo
00499         self.EnableTool(self.undo, False)
00500         
00501         ### hide undo before releasing 6.4.2 - this tool is quite buggy in GRASS 6
00502         self.RemoveTool(self.undo)
00503         
00504         # toogle to pointer by default
00505         self.OnTool(None)
00506         
00507         self.FixSize(width = 105)
00508         
00509     def _toolbarData(self):
00510         """!Toolbar data
00511         """
00512         data = []
00513         icons = Icons['vdigit']
00514         return self._getToolbarData(((None, ),
00515                                      ("addPoint", icons["addPoint"],
00516                                       self.OnAddPoint,
00517                                       wx.ITEM_CHECK),
00518                                      ("addLine", icons["addLine"],
00519                                       self.OnAddLine,
00520                                       wx.ITEM_CHECK),
00521                                      ("addBoundary", icons["addBoundary"],
00522                                       self.OnAddBoundary,
00523                                       wx.ITEM_CHECK),
00524                                      ("addCentroid", icons["addCentroid"],
00525                                       self.OnAddCentroid,
00526                                       wx.ITEM_CHECK),
00527                                      ("addArea", icons["addArea"],
00528                                       self.OnAddArea,
00529                                       wx.ITEM_CHECK),
00530                                      ("moveVertex", icons["moveVertex"],
00531                                       self.OnMoveVertex,
00532                                       wx.ITEM_CHECK),
00533                                      ("addVertex", icons["addVertex"],
00534                                       self.OnAddVertex,
00535                                       wx.ITEM_CHECK),
00536                                      ("removeVertex", icons["removeVertex"],
00537                                       self.OnRemoveVertex,
00538                                       wx.ITEM_CHECK),
00539                                      ("editLine", icons["editLine"],
00540                                       self.OnEditLine,
00541                                       wx.ITEM_CHECK),
00542                                      ("moveLine", icons["moveLine"],
00543                                       self.OnMoveLine,
00544                                       wx.ITEM_CHECK),
00545                                      ("deleteLine", icons["deleteLine"],
00546                                       self.OnDeleteLine,
00547                                       wx.ITEM_CHECK),
00548                                      ("displayCats", icons["displayCats"],
00549                                       self.OnDisplayCats,
00550                                       wx.ITEM_CHECK),
00551                                      ("displayAttr", icons["displayAttr"],
00552                                       self.OnDisplayAttr,
00553                                       wx.ITEM_CHECK),
00554                                      ("additionalTools", icons["additionalTools"],
00555                                       self.OnAdditionalToolMenu,
00556                                       wx.ITEM_CHECK),                                      
00557                                      (None, ),
00558                                      ("undo", icons["undo"],
00559                                       self.OnUndo),
00560                                      ("settings", icons["settings"],
00561                                       self.OnSettings),
00562                                      ("quit", icons["quit"],
00563                                       self.OnExit))
00564                                     )
00565     
00566     def OnTool(self, event):
00567         """!Tool selected -> disable selected tool in map toolbar"""
00568         aId = self.parent.toolbars['map'].GetAction(type = 'id')
00569         self.parent.toolbars['map'].ToggleTool(aId, False)
00570         
00571         # set cursor
00572         cursor = self.parent.cursors["cross"]
00573         self.parent.MapWindow.SetCursor(cursor)
00574         
00575         # pointer
00576         self.parent.OnPointer(None)
00577         
00578         if event:
00579             # deselect previously selected tool
00580             aId = self.action.get('id', -1)
00581             if aId != event.GetId() and \
00582                     self.action['id'] != -1:
00583                 self.ToggleTool(self.action['id'], False)
00584             else:
00585                 self.ToggleTool(self.action['id'], True)
00586             
00587             self.action['id'] = event.GetId()
00588             
00589             event.Skip()
00590         
00591         if self.action['id'] != -1:
00592             self.ToggleTool(self.action['id'], True)
00593         
00594         # clear tmp canvas
00595         if self.action['id'] != aId:
00596             self.parent.MapWindow.ClearLines(pdc = self.parent.MapWindow.pdcTmp)
00597             if self.digit and \
00598                     len(self.parent.MapWindow.digit.GetDisplay().GetSelected()) > 0:
00599                 # cancel action
00600                 self.parent.MapWindow.OnMiddleDown(None)
00601         
00602         # set focus
00603         self.parent.MapWindow.SetFocus()
00604         
00605     def OnAddPoint(self, event):
00606         """!Add point to the vector map Laier"""
00607         Debug.msg (2, "VDigitToolbar.OnAddPoint()")
00608         self.action = { 'desc' : "addLine",
00609                         'type' : "point",
00610                         'id'   : self.addPoint }
00611         self.parent.MapWindow.mouse['box'] = 'point'
00612         
00613     def OnAddLine(self, event):
00614         """!Add line to the vector map layer"""
00615         Debug.msg (2, "VDigitToolbar.OnAddLine()")
00616         self.action = { 'desc' : "addLine",
00617                         'type' : "line",
00618                         'id'   : self.addLine }
00619         self.parent.MapWindow.mouse['box'] = 'line'
00620         ### self.parent.MapWindow.polycoords = [] # reset temp line
00621                 
00622     def OnAddBoundary(self, event):
00623         """!Add boundary to the vector map layer"""
00624         Debug.msg (2, "VDigitToolbar.OnAddBoundary()")
00625         if self.action['desc'] != 'addLine' or \
00626                 self.action['type'] != 'boundary':
00627             self.parent.MapWindow.polycoords = [] # reset temp line
00628         self.action = { 'desc' : "addLine",
00629                         'type' : "boundary",
00630                         'id'   : self.addBoundary }
00631         self.parent.MapWindow.mouse['box'] = 'line'
00632         
00633     def OnAddCentroid(self, event):
00634         """!Add centroid to the vector map layer"""
00635         Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
00636         self.action = { 'desc' : "addLine",
00637                         'type' : "centroid",
00638                         'id'   : self.addCentroid }
00639         self.parent.MapWindow.mouse['box'] = 'point'
00640 
00641     def OnAddArea(self, event):
00642         """!Add area to the vector map layer"""
00643         Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
00644         self.action = { 'desc' : "addLine",
00645                         'type' : "area",
00646                         'id'   : self.addArea }
00647         self.parent.MapWindow.mouse['box'] = 'line'
00648 
00649     def OnExit (self, event=None):
00650         """!Quit digitization tool"""
00651         # stop editing of the currently selected map layer
00652         if self.mapLayer:
00653             self.StopEditing()
00654         
00655         # close dialogs if still open
00656         if self.settingsDialog:
00657             self.settingsDialog.OnCancel(None)
00658             
00659         # set default mouse settings
00660         self.parent.MapWindow.mouse['use'] = "pointer"
00661         self.parent.MapWindow.mouse['box'] = "point"
00662         self.parent.MapWindow.polycoords = []
00663         
00664         # disable the toolbar
00665         self.parent.RemoveToolbar("vdigit")
00666         
00667     def OnMoveVertex(self, event):
00668         """!Move line vertex"""
00669         Debug.msg(2, "Digittoolbar.OnMoveVertex():")
00670         self.action = { 'desc' : "moveVertex",
00671                         'id'   : self.moveVertex }
00672         self.parent.MapWindow.mouse['box'] = 'point'
00673 
00674     def OnAddVertex(self, event):
00675         """!Add line vertex"""
00676         Debug.msg(2, "Digittoolbar.OnAddVertex():")
00677         self.action = { 'desc' : "addVertex",
00678                         'id'   : self.addVertex }
00679         self.parent.MapWindow.mouse['box'] = 'point'
00680         
00681     def OnRemoveVertex(self, event):
00682         """!Remove line vertex"""
00683         Debug.msg(2, "Digittoolbar.OnRemoveVertex():")
00684         self.action = { 'desc' : "removeVertex",
00685                         'id'   : self.removeVertex }
00686         self.parent.MapWindow.mouse['box'] = 'point'
00687 
00688     def OnEditLine(self, event):
00689         """!Edit line"""
00690         Debug.msg(2, "Digittoolbar.OnEditLine():")
00691         self.action = { 'desc' : "editLine",
00692                         'id'   : self.editLine }
00693         self.parent.MapWindow.mouse['box'] = 'line'
00694 
00695     def OnMoveLine(self, event):
00696         """!Move line"""
00697         Debug.msg(2, "Digittoolbar.OnMoveLine():")
00698         self.action = { 'desc' : "moveLine",
00699                         'id'   : self.moveLine }
00700         self.parent.MapWindow.mouse['box'] = 'box'
00701 
00702     def OnDeleteLine(self, event):
00703         """!Delete line"""
00704         Debug.msg(2, "Digittoolbar.OnDeleteLine():")
00705         self.action = { 'desc' : "deleteLine",
00706                         'id'   : self.deleteLine }
00707         self.parent.MapWindow.mouse['box'] = 'box'
00708 
00709     def OnDisplayCats(self, event):
00710         """!Display/update categories"""
00711         Debug.msg(2, "Digittoolbar.OnDisplayCats():")
00712         self.action = { 'desc' : "displayCats",
00713                         'id'   : self.displayCats }
00714         self.parent.MapWindow.mouse['box'] = 'point'
00715 
00716     def OnDisplayAttr(self, event):
00717         """!Display/update attributes"""
00718         Debug.msg(2, "Digittoolbar.OnDisplayAttr():")
00719         self.action = { 'desc' : "displayAttrs",
00720                         'id'   : self.displayAttr }
00721         self.parent.MapWindow.mouse['box'] = 'point'
00722         
00723     def OnUndo(self, event):
00724         """!Undo previous changes"""
00725         self.digit.Undo()
00726         
00727         event.Skip()
00728 
00729     def EnableUndo(self, enable=True):
00730         """!Enable 'Undo' in toolbar
00731         
00732         @param enable False for disable
00733         """
00734         if enable:
00735             if self.GetToolEnabled(self.undo) is False:
00736                 self.EnableTool(self.undo, True)
00737         else:
00738             if self.GetToolEnabled(self.undo) is True:
00739                 self.EnableTool(self.undo, False)
00740         
00741     def OnSettings(self, event):
00742         """!Show settings dialog"""
00743         if self.digit is None:
00744             try:
00745                 self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
00746             except SystemExit:
00747                 self.digit = self.parent.MapWindow.digit = None
00748         
00749         if not self.settingsDialog:
00750             self.settingsDialog = VDigitSettingsDialog(parent = self.parent, title = _("Digitization settings"),
00751                                                        style = wx.DEFAULT_DIALOG_STYLE)
00752             self.settingsDialog.Show()
00753 
00754     def OnAdditionalToolMenu(self, event):
00755         """!Menu for additional tools"""
00756         point = wx.GetMousePosition()
00757         toolMenu = wx.Menu()
00758         
00759         for label, itype, handler, desc in (
00760             (_('Break selected lines/boundaries at intersection'),
00761              wx.ITEM_CHECK, self.OnBreak, "breakLine"),
00762             (_('Connect selected lines/boundaries'),
00763              wx.ITEM_CHECK, self.OnConnect, "connectLine"),
00764             (_('Copy categories'),
00765              wx.ITEM_CHECK, self.OnCopyCats, "copyCats"),
00766             (_('Copy features from (background) vector map'),
00767              wx.ITEM_CHECK, self.OnCopy, "copyLine"),
00768             (_('Copy attributes'),
00769              wx.ITEM_CHECK, self.OnCopyAttrb, "copyAttrs"),
00770             (_('Feature type conversion'),
00771              wx.ITEM_CHECK, self.OnTypeConversion, "typeConv"),
00772             (_('Flip selected lines/boundaries'),
00773              wx.ITEM_CHECK, self.OnFlip, "flipLine"),
00774             (_('Merge selected lines/boundaries'),
00775              wx.ITEM_CHECK, self.OnMerge, "mergeLine"),
00776             (_('Snap selected lines/boundaries (only to nodes)'),
00777              wx.ITEM_CHECK, self.OnSnap, "snapLine"),
00778             (_('Split line/boundary'),
00779              wx.ITEM_CHECK, self.OnSplitLine, "splitLine"),
00780             (_('Query features'),
00781              wx.ITEM_CHECK, self.OnQuery, "queryLine"),
00782             (_('Z bulk-labeling of 3D lines'),
00783              wx.ITEM_CHECK, self.OnZBulk, "zbulkLine")):
00784             # Add items to the menu
00785             item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
00786                                text = label,
00787                                kind = itype)
00788             toolMenu.AppendItem(item)
00789             self.parent.MapWindow.Bind(wx.EVT_MENU, handler, item)
00790             if self.action['desc'] == desc:
00791                 item.Check(True)
00792         
00793         # Popup the menu.  If an item is selected then its handler
00794         # will be called before PopupMenu returns.
00795         self.parent.MapWindow.PopupMenu(toolMenu)
00796         toolMenu.Destroy()
00797         
00798         if self.action['desc'] == 'addPoint':
00799             self.ToggleTool(self.additionalTools, False)
00800         
00801     def OnCopy(self, event):
00802         """!Copy selected features from (background) vector map"""
00803         if self.action['desc'] == 'copyLine': # select previous action
00804             self.ToggleTool(self.addPoint, True)
00805             self.ToggleTool(self.additionalTools, False)
00806             self.OnAddPoint(event)
00807             return
00808         
00809         Debug.msg(2, "Digittoolbar.OnCopy():")
00810         self.action = { 'desc' : "copyLine",
00811                         'id'   : self.additionalTools }
00812         self.parent.MapWindow.mouse['box'] = 'box'
00813 
00814     def OnSplitLine(self, event):
00815         """!Split line"""
00816         if self.action['desc'] == 'splitLine': # select previous action
00817             self.ToggleTool(self.addPoint, True)
00818             self.ToggleTool(self.additionalTools, False)
00819             self.OnAddPoint(event)
00820             return
00821         
00822         Debug.msg(2, "Digittoolbar.OnSplitLine():")
00823         self.action = { 'desc' : "splitLine",
00824                         'id'   : self.additionalTools }
00825         self.parent.MapWindow.mouse['box'] = 'point'
00826 
00827 
00828     def OnCopyCats(self, event):
00829         """!Copy categories"""
00830         if self.action['desc'] == 'copyCats': # select previous action
00831             self.ToggleTool(self.addPoint, True)
00832             self.ToggleTool(self.copyCats, False)
00833             self.OnAddPoint(event)
00834             return
00835         
00836         Debug.msg(2, "Digittoolbar.OnCopyCats():")
00837         self.action = { 'desc' : "copyCats",
00838                         'id'   : self.additionalTools }
00839         self.parent.MapWindow.mouse['box'] = 'point'
00840 
00841     def OnCopyAttrb(self, event):
00842         """!Copy attributes"""
00843         if self.action['desc'] == 'copyAttrs': # select previous action
00844             self.ToggleTool(self.addPoint, True)
00845             self.ToggleTool(self.copyCats, False)
00846             self.OnAddPoint(event)
00847             return
00848         
00849         Debug.msg(2, "Digittoolbar.OnCopyAttrb():")
00850         self.action = { 'desc' : "copyAttrs",
00851                         'id'   : self.additionalTools }
00852         self.parent.MapWindow.mouse['box'] = 'point'
00853         
00854 
00855     def OnFlip(self, event):
00856         """!Flip selected lines/boundaries"""
00857         if self.action['desc'] == 'flipLine': # select previous action
00858             self.ToggleTool(self.addPoint, True)
00859             self.ToggleTool(self.additionalTools, False)
00860             self.OnAddPoint(event)
00861             return
00862         
00863         Debug.msg(2, "Digittoolbar.OnFlip():")
00864         self.action = { 'desc' : "flipLine",
00865                         'id'   : self.additionalTools }
00866         self.parent.MapWindow.mouse['box'] = 'box'
00867 
00868     def OnMerge(self, event):
00869         """!Merge selected lines/boundaries"""
00870         if self.action['desc'] == 'mergeLine': # select previous action
00871             self.ToggleTool(self.addPoint, True)
00872             self.ToggleTool(self.additionalTools, False)
00873             self.OnAddPoint(event)
00874             return
00875         
00876         Debug.msg(2, "Digittoolbar.OnMerge():")
00877         self.action = { 'desc' : "mergeLine",
00878                         'id'   : self.additionalTools }
00879         self.parent.MapWindow.mouse['box'] = 'box'
00880 
00881     def OnBreak(self, event):
00882         """!Break selected lines/boundaries"""
00883         if self.action['desc'] == 'breakLine': # select previous action
00884             self.ToggleTool(self.addPoint, True)
00885             self.ToggleTool(self.additionalTools, False)
00886             self.OnAddPoint(event)
00887             return
00888         
00889         Debug.msg(2, "Digittoolbar.OnBreak():")
00890         self.action = { 'desc' : "breakLine",
00891                         'id'   : self.additionalTools }
00892         self.parent.MapWindow.mouse['box'] = 'box'
00893 
00894     def OnSnap(self, event):
00895         """!Snap selected features"""
00896         if self.action['desc'] == 'snapLine': # select previous action
00897             self.ToggleTool(self.addPoint, True)
00898             self.ToggleTool(self.additionalTools, False)
00899             self.OnAddPoint(event)
00900             return
00901         
00902         Debug.msg(2, "Digittoolbar.OnSnap():")
00903         self.action = { 'desc' : "snapLine",
00904                         'id'   : self.additionalTools }
00905         self.parent.MapWindow.mouse['box'] = 'box'
00906 
00907     def OnConnect(self, event):
00908         """!Connect selected lines/boundaries"""
00909         if self.action['desc'] == 'connectLine': # select previous action
00910             self.ToggleTool(self.addPoint, True)
00911             self.ToggleTool(self.additionalTools, False)
00912             self.OnAddPoint(event)
00913             return
00914         
00915         Debug.msg(2, "Digittoolbar.OnConnect():")
00916         self.action = { 'desc' : "connectLine",
00917                         'id'   : self.additionalTools }
00918         self.parent.MapWindow.mouse['box'] = 'box'
00919 
00920     def OnQuery(self, event):
00921         """!Query selected lines/boundaries"""
00922         if self.action['desc'] == 'queryLine': # select previous action
00923             self.ToggleTool(self.addPoint, True)
00924             self.ToggleTool(self.additionalTools, False)
00925             self.OnAddPoint(event)
00926             return
00927         
00928         Debug.msg(2, "Digittoolbar.OnQuery(): %s" % \
00929                       UserSettings.Get(group = 'vdigit', key = 'query', subkey = 'selection'))
00930         self.action = { 'desc' : "queryLine",
00931                         'id'   : self.additionalTools }
00932         self.parent.MapWindow.mouse['box'] = 'box'
00933 
00934     def OnZBulk(self, event):
00935         """!Z bulk-labeling selected lines/boundaries"""
00936         if not self.digit.IsVector3D():
00937             gcmd.GError(parent = self.parent,
00938                         message = _("Vector map is not 3D. Operation canceled."))
00939             return
00940         
00941         if self.action['desc'] == 'zbulkLine': # select previous action
00942             self.ToggleTool(self.addPoint, True)
00943             self.ToggleTool(self.additionalTools, False)
00944             self.OnAddPoint(event)
00945             return
00946         
00947         Debug.msg(2, "Digittoolbar.OnZBulk():")
00948         self.action = { 'desc' : "zbulkLine",
00949                         'id'   : self.additionalTools }
00950         self.parent.MapWindow.mouse['box'] = 'line'
00951 
00952     def OnTypeConversion(self, event):
00953         """!Feature type conversion
00954 
00955         Supported conversions:
00956          - point <-> centroid
00957          - line <-> boundary
00958         """
00959         if self.action['desc'] == 'typeConv': # select previous action
00960             self.ToggleTool(self.addPoint, True)
00961             self.ToggleTool(self.additionalTools, False)
00962             self.OnAddPoint(event)
00963             return
00964         
00965         Debug.msg(2, "Digittoolbar.OnTypeConversion():")
00966         self.action = { 'desc' : "typeConv",
00967                         'id'   : self.additionalTools }
00968         self.parent.MapWindow.mouse['box'] = 'box'
00969 
00970     def OnSelectMap (self, event):
00971         """!Select vector map layer for editing
00972 
00973         If there is a vector map layer already edited, this action is
00974         firstly terminated. The map layer is closed. After this the
00975         selected map layer activated for editing.
00976         """
00977         if event.GetSelection() == 0: # create new vector map layer
00978             if self.mapLayer:
00979                 openVectorMap = self.mapLayer.GetName(fullyQualified = False)['name']
00980             else:
00981                 openVectorMap = None
00982             dlg = gdialogs.CreateNewVector(self.parent,
00983                                            exceptMap = openVectorMap, log = self.log,
00984                                            cmd = (('v.edit',
00985                                                    { 'tool' : 'create' },
00986                                                    'map')),
00987                                            disableAdd = True)
00988             
00989             if dlg and dlg.GetName():
00990                 # add layer to map layer tree
00991                 if self.layerTree:
00992                     mapName = dlg.GetName() + '@' + grass.gisenv()['MAPSET']
00993                     self.layerTree.AddLayer(ltype = 'vector',
00994                                             lname = mapName,
00995                                             lcmd = ['d.vect', 'map=%s' % mapName])
00996                     
00997                     vectLayers = self.UpdateListOfLayers(updateTool = True)
00998                     selection = vectLayers.index(mapName)
00999                 
01000                 # create table ?
01001                 if dlg.IsChecked('table'):
01002                     lmgr = self.parent.GetLayerManager()
01003                     if lmgr:
01004                         lmgr.OnShowAttributeTable(None, selection = 1)
01005                 dlg.Destroy()
01006             else:
01007                 self.combo.SetValue(_('Select vector map'))
01008                 if dlg:
01009                     dlg.Destroy()
01010                 return
01011         else:
01012             selection = event.GetSelection() - 1 # first option is 'New vector map'
01013         
01014         # skip currently selected map
01015         if self.layers[selection] == self.mapLayer:
01016             return
01017         
01018         if self.mapLayer:
01019             # deactive map layer for editing
01020             self.StopEditing()
01021         
01022         # select the given map layer for editing
01023         self.StartEditing(self.layers[selection])
01024         
01025         event.Skip()
01026     
01027     def StartEditing (self, mapLayer):
01028         """!Start editing selected vector map layer.
01029         
01030         @param mapLayer MapLayer to be edited
01031         """
01032         # deactive layer
01033         self.mapcontent.ChangeLayerActive(mapLayer, False)
01034         
01035         # clean map canvas
01036         self.parent.MapWindow.EraseMap()
01037         
01038         # unset background map if needed
01039         if mapLayer:
01040             if UserSettings.Get(group = 'vdigit', key = 'bgmap',
01041                                 subkey = 'value', internal = True) == mapLayer.GetName():
01042                 UserSettings.Set(group = 'vdigit', key = 'bgmap',
01043                                  subkey = 'value', value = '', internal = True)
01044             
01045             self.parent.statusbar.SetStatusText(_("Please wait, "
01046                                                   "opening vector map <%s> for editing...") % mapLayer.GetName(),
01047                                                 0)
01048         
01049         self.parent.MapWindow.pdcVector = wx.PseudoDC()
01050         self.digit = self.parent.MapWindow.digit = VDigit(mapwindow = self.parent.MapWindow)
01051         
01052         self.mapLayer = mapLayer
01053         
01054         # open vector map
01055         if self.digit.OpenMap(mapLayer.GetName()) is None:
01056             self.mapLayer = None
01057             self.StopEditing()
01058             return False
01059         
01060         # update toolbar
01061         self.combo.SetValue(mapLayer.GetName())
01062         self.parent.toolbars['map'].combo.SetValue (_('Digitize'))
01063         lmgr = self.parent.GetLayerManager()
01064         if lmgr:
01065             lmgr.toolbars['tools'].Enable('vdigit', enable = False)
01066         
01067         Debug.msg (4, "VDigitToolbar.StartEditing(): layer=%s" % mapLayer.GetName())
01068         
01069         # change cursor
01070         if self.parent.MapWindow.mouse['use'] == 'pointer':
01071             self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
01072         
01073         if not self.parent.MapWindow.resize:
01074             self.parent.MapWindow.UpdateMap(render = True)
01075         
01076         # respect opacity
01077         opacity = mapLayer.GetOpacity(float = True)
01078         if opacity < 1.0:
01079             alpha = int(opacity * 255)
01080             self.digit.GetDisplay().UpdateSettings(alpha = alpha)
01081         
01082         return True
01083 
01084     def StopEditing(self):
01085         """!Stop editing of selected vector map layer.
01086 
01087         @return True on success
01088         @return False on failure
01089         """
01090         self.combo.SetValue (_('Select vector map'))
01091         
01092         # save changes
01093         if self.mapLayer:
01094             Debug.msg (4, "VDigitToolbar.StopEditing(): layer=%s" % self.mapLayer.GetName())
01095             if UserSettings.Get(group = 'vdigit', key = 'saveOnExit', subkey = 'enabled') is False:
01096                 if self.digit.GetUndoLevel() > -1:
01097                     dlg = wx.MessageDialog(parent = self.parent,
01098                                            message = _("Do you want to save changes "
01099                                                      "in vector map <%s>?") % self.mapLayer.GetName(),
01100                                            caption = _("Save changes?"),
01101                                            style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
01102                     if dlg.ShowModal() == wx.ID_NO:
01103                         # revert changes
01104                         self.digit.Undo(0)
01105                     dlg.Destroy()
01106             
01107             self.parent.statusbar.SetStatusText(_("Please wait, "
01108                                                   "closing and rebuilding topology of "
01109                                                   "vector map <%s>...") % self.mapLayer.GetName(),
01110                                                 0)
01111             lmgr = self.parent.GetLayerManager()
01112             if lmgr:
01113                 lmgr.toolbars['tools'].Enable('vdigit', enable = True)
01114                 lmgr.notebook.SetSelectionByName('output')
01115             self.digit.CloseMap()
01116             if lmgr:
01117                 lmgr.GetLogWindow().GetProgressBar().SetValue(0)
01118                 lmgr.GetLogWindow().WriteCmdLog(_("Editing of vector map <%s> successfully finished") % \
01119                                                     self.mapLayer.GetName())
01120             # re-active layer 
01121             item = self.parent.tree.FindItemByData('maplayer', self.mapLayer)
01122             if item and self.parent.tree.IsItemChecked(item):
01123                 self.mapcontent.ChangeLayerActive(self.mapLayer, True)
01124         
01125         # change cursor
01126         self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
01127         self.parent.MapWindow.pdcVector = None
01128         
01129         # close dialogs
01130         for dialog in ('attributes', 'category'):
01131             if self.parent.dialogs[dialog]:
01132                 self.parent.dialogs[dialog].Close()
01133                 self.parent.dialogs[dialog] = None
01134         
01135         del self.digit
01136         del self.parent.MapWindow.digit
01137         
01138         self.mapLayer = None
01139         
01140         self.parent.MapWindow.redrawAll = True
01141         
01142         return True
01143     
01144     def UpdateListOfLayers (self, updateTool = False):
01145         """!
01146         Update list of available vector map layers.
01147         This list consists only editable layers (in the current mapset)
01148 
01149         Optionally also update toolbar
01150         """
01151         Debug.msg (4, "VDigitToolbar.UpdateListOfLayers(): updateTool=%d" % \
01152                    updateTool)
01153         
01154         layerNameSelected = None
01155          # name of currently selected layer
01156         if self.mapLayer:
01157             layerNameSelected = self.mapLayer.GetName()
01158         
01159         # select vector map layer in the current mapset
01160         layerNameList = []
01161         self.layers = self.mapcontent.GetListOfLayers(l_type = "vector",
01162                                                       l_mapset = grass.gisenv()['MAPSET'])
01163         for layer in self.layers:
01164             if not layer.name in layerNameList: # do not duplicate layer
01165                 layerNameList.append (layer.GetName())
01166         
01167         if updateTool: # update toolbar
01168             if not self.mapLayer:
01169                 value = _('Select vector map')
01170             else:
01171                 value = layerNameSelected
01172 
01173             if not self.comboid:
01174                 self.combo = wx.ComboBox(self, id = wx.ID_ANY, value = value,
01175                                          choices = [_('New vector map'), ] + layerNameList, size = (80, -1),
01176                                          style = wx.CB_READONLY)
01177                 self.comboid = self.InsertControl(0, self.combo)
01178                 self.parent.Bind(wx.EVT_COMBOBOX, self.OnSelectMap, self.comboid)
01179             else:
01180                 self.combo.SetItems([_('New vector map'), ] + layerNameList)
01181             
01182             self.Realize()
01183         
01184         return layerNameList
01185 
01186     def GetLayer(self):
01187         """!Get selected layer for editing -- MapLayer instance"""
01188         return self.mapLayer
01189     
01190 class ProfileToolbar(AbstractToolbar):
01191     """!Toolbar for profiling raster map
01192     """ 
01193     def __init__(self, parent):
01194         AbstractToolbar.__init__(self, parent)
01195         
01196         self.InitToolbar(self._toolbarData())
01197         
01198         # realize the toolbar
01199         self.Realize()
01200         
01201     def _toolbarData(self):
01202         """!Toolbar data"""
01203         icons = Icons['profile']
01204         return self._getToolbarData((('addraster', Icons['layerManager']["addRast"],
01205                                       self.parent.OnSelectRaster),
01206                                      ('transect', icons["transect"],
01207                                       self.parent.OnDrawTransect),
01208                                      (None, ),
01209                                      ('draw', icons["draw"],
01210                                       self.parent.OnCreateProfile),
01211                                      ('erase', Icons['displayWindow']["erase"],
01212                                       self.parent.OnErase),
01213                                      ('drag', Icons['displayWindow']['pan'],
01214                                       self.parent.OnDrag),
01215                                      ('zoom', Icons['displayWindow']['zoomIn'],
01216                                       self.parent.OnZoom),
01217                                      ('unzoom', Icons['displayWindow']['zoomBack'],
01218                                       self.parent.OnRedraw),
01219                                      (None, ),
01220                                      ('datasave', icons["save"],
01221                                       self.parent.SaveProfileToFile),
01222                                      ('image', Icons['displayWindow']["saveFile"],
01223                                       self.parent.SaveToFile),
01224                                      ('print', Icons['displayWindow']["print"],
01225                                       self.parent.PrintMenu),
01226                                      (None, ),
01227                                      ('settings', icons["options"],
01228                                       self.parent.ProfileOptionsMenu),
01229                                      ('quit', icons["quit"],
01230                                       self.parent.OnQuit),
01231                                      ))
01232     
01233 class NvizToolbar(AbstractToolbar):
01234     """!Nviz toolbar
01235     """
01236     def __init__(self, parent, mapcontent):
01237         self.mapcontent = mapcontent
01238         self.lmgr = parent.GetLayerManager()
01239         
01240         AbstractToolbar.__init__(self, parent)
01241         
01242         # only one dialog can be open
01243         self.settingsDialog   = None
01244         
01245         self.InitToolbar(self._toolbarData())
01246         
01247         # realize the toolbar
01248         self.Realize()
01249         
01250     def _toolbarData(self):
01251         """!Toolbar data"""
01252         icons = Icons['nviz']
01253         return self._getToolbarData((("view", icons["view"],
01254                                       self.OnShowPage),
01255                                      (None, ),
01256                                      ("surface", icons["surface"],
01257                                       self.OnShowPage),
01258                                      ("vector", icons["vector"],
01259                                       self.OnShowPage),
01260                                      ("volume", icons["volume"],
01261                                       self.OnShowPage),
01262                                      (None, ),
01263                                      ("light", icons["light"],
01264                                       self.OnShowPage),
01265                                      ("fringe", icons["fringe"],
01266                                       self.OnShowPage),
01267                                      (None, ),
01268                                      ("settings", icons["settings"],
01269                                       self.OnSettings),
01270                                      ("help", Icons['misc']["help"],
01271                                       self.OnHelp),
01272                                      (None, ),
01273                                      ('quit', icons["quit"],
01274                                       self.OnExit))
01275                                     )
01276     
01277     def OnShowPage(self, event):
01278         """!Go to the selected page"""
01279         if not self.lmgr or not hasattr(self.lmgr, "nviz"):
01280             event.Skip()
01281             return
01282         
01283         self.lmgr.notebook.SetSelectionByName('nviz')
01284         eId = event.GetId()
01285         if eId == self.view:
01286             self.lmgr.nviz.SetPage('view')
01287         elif eId == self.surface:
01288             self.lmgr.nviz.SetPage('surface')
01289         elif eId == self.surface:
01290             self.lmgr.nviz.SetPage('surface')
01291         elif eId == self.vector:
01292             self.lmgr.nviz.SetPage('vector')
01293         elif eId == self.volume:
01294             self.lmgr.nviz.SetPage('volume')
01295         elif eId == self.light:
01296             self.lmgr.nviz.SetPage('light')
01297         elif eId == self.fringe:
01298             self.lmgr.nviz.SetPage('fringe')
01299         
01300         self.lmgr.Raise()
01301 
01302     def OnHelp(self, event):
01303         """!Show 3D view mode help"""
01304         if not self.lmgr:
01305             gcmd.RunCommand('g.manual',
01306                             entry = 'wxGUI.Nviz')
01307         else:
01308             log = self.lmgr.GetLogWindow()
01309             log.RunCmd(['g.manual',
01310                         'entry=wxGUI.Nviz'])
01311         
01312     def OnSettings(self, event):
01313         """!Show nviz notebook page"""
01314         if not self.settingsDialog:
01315             self.settingsDialog = NvizPreferencesDialog(parent = self.parent)
01316         self.settingsDialog.Show()
01317             
01318     def OnExit (self, event = None):
01319         """!Quit nviz tool (swith to 2D mode)"""
01320         # set default mouse settings
01321         self.parent.MapWindow.mouse['use'] = "pointer"
01322         self.parent.MapWindow.mouse['box'] = "point"
01323         self.parent.MapWindow.polycoords = []
01324         
01325         # return to map layer page (gets rid of ugly exit bug)
01326         self.lmgr.notebook.SetSelectionByName('layers')
01327 
01328         # disable the toolbar
01329         self.parent.RemoveToolbar("nviz")
01330         
01331 class ModelToolbar(AbstractToolbar):
01332     """!Graphical modeler toolbar (see gmodeler.py)
01333     """
01334     def __init__(self, parent):
01335         AbstractToolbar.__init__(self, parent)
01336         
01337         self.InitToolbar(self._toolbarData())
01338         
01339         # realize the toolbar
01340         self.Realize()
01341         
01342     def _toolbarData(self):
01343         """!Toolbar data"""
01344         icons = Icons['modeler']
01345         return self._getToolbarData((('new', icons['new'],
01346                                       self.parent.OnModelNew),
01347                                      ('open', icons['open'],
01348                                       self.parent.OnModelOpen),
01349                                      ('save', icons['save'],
01350                                       self.parent.OnModelSave),
01351                                      ('image', icons['toImage'],
01352                                       self.parent.OnExportImage),
01353                                      ('python', icons['toPython'],
01354                                       self.parent.OnExportPython),
01355                                      (None, ),
01356                                      ('action', icons['actionAdd'],
01357                                       self.parent.OnAddAction),
01358                                      ('data', icons['dataAdd'],
01359                                       self.parent.OnAddData),
01360                                      ('relation', icons['relation'],
01361                                       self.parent.OnDefineRelation),
01362                                      (None, ),
01363                                      ('redraw', icons['redraw'],
01364                                       self.parent.OnCanvasRefresh),
01365                                      ('validate', icons['validate'],
01366                                       self.parent.OnValidateModel),
01367                                      ('run', icons['run'],
01368                                       self.parent.OnRunModel),
01369                                      (None, ),
01370                                      ("variables", icons['variables'],
01371                                       self.parent.OnVariables),
01372                                      ("settings", icons['settings'],
01373                                       self.parent.OnPreferences),
01374                                      ("help", Icons['misc']['help'],
01375                                       self.parent.OnHelp),
01376                                      (None, ),
01377                                      ('quit', icons['quit'],
01378                                       self.parent.OnCloseWindow))
01379                                     )
01380     
01381 class HistogramToolbar(AbstractToolbar):
01382     """!Histogram toolbar (see histogram.py)
01383     """
01384     def __init__(self, parent):
01385         AbstractToolbar.__init__(self, parent)
01386         
01387         self.InitToolbar(self._toolbarData())
01388         
01389         # realize the toolbar
01390         self.Realize()
01391         
01392     def _toolbarData(self):
01393         """!Toolbar data"""
01394         icons = Icons['displayWindow']
01395         return self._getToolbarData((('histogram', icons["histogram"],
01396                                       self.parent.OnOptions),
01397                                      ('rendermao', icons["display"],
01398                                       self.parent.OnRender),
01399                                      ('erase', icons["erase"],
01400                                       self.parent.OnErase),
01401                                      ('font', Icons['misc']["font"],
01402                                       self.parent.SetHistFont),
01403                                      (None, ),
01404                                      ('save', icons["saveFile"],
01405                                       self.parent.SaveToFile),
01406                                      ('hprint', icons["print"],
01407                                       self.parent.PrintMenu),
01408                                      (None, ),
01409                                      ('quit', Icons['misc']["quit"],
01410                                       self.parent.OnQuit))
01411                                     )
01412 
01413 class LMWorkspaceToolbar(AbstractToolbar):
01414     """!Layer Manager `workspace` toolbar
01415     """
01416     def __init__(self, parent):
01417         AbstractToolbar.__init__(self, parent)
01418         
01419         self.InitToolbar(self._toolbarData())
01420         
01421         # realize the toolbar
01422         self.Realize()
01423 
01424     def _toolbarData(self):
01425         """!Toolbar data
01426         """
01427         icons = Icons['layerManager']
01428         return self._getToolbarData((('newdisplay', icons["newdisplay"],
01429                                       self.parent.OnNewDisplay),
01430                                      (None, ),
01431                                      ('workspaceNew', icons["workspaceNew"],
01432                                       self.parent.OnWorkspaceNew),
01433                                      ('workspaceOpen', icons["workspaceOpen"],
01434                                       self.parent.OnWorkspaceOpen),
01435                                      ('workspaceSave', icons["workspaceSave"],
01436                                       self.parent.OnWorkspaceSave),
01437                                      ))
01438 
01439 class LMDataToolbar(AbstractToolbar):
01440     """!Layer Manager `data` toolbar
01441     """
01442     def __init__(self, parent):
01443         AbstractToolbar.__init__(self, parent)
01444         
01445         self.InitToolbar(self._toolbarData())
01446         
01447         # realize the toolbar
01448         self.Realize()
01449 
01450     def _toolbarData(self):
01451         """!Toolbar data
01452         """
01453         icons = Icons['layerManager']
01454         return self._getToolbarData((('addMulti', icons["addMulti"],
01455                                       self.parent.OnAddMaps),
01456                                      ('addrast', icons["addRast"],
01457                                       self.parent.OnAddRaster),
01458                                      ('rastmisc', icons["rastMisc"],
01459                                       self.parent.OnAddRasterMisc),
01460                                      ('addvect', icons["addVect"],
01461                                       self.parent.OnAddVector),
01462                                      ('vectmisc', icons["vectMisc"],
01463                                       self.parent.OnAddVectorMisc),
01464                                      ('addgrp',  icons["addGroup"],
01465                                       self.parent.OnAddGroup),
01466                                      ('addovl',  icons["addOverlay"],
01467                                       self.parent.OnAddOverlay),
01468                                      ('delcmd',  icons["delCmd"],
01469                                       self.parent.OnDeleteLayer),
01470                                      ))
01471 
01472 class LMToolsToolbar(AbstractToolbar):
01473     """!Layer Manager `tools` toolbar
01474     """
01475     def __init__(self, parent):
01476         AbstractToolbar.__init__(self, parent)
01477         
01478         self.InitToolbar(self._toolbarData())
01479         
01480         # realize the toolbar
01481         self.Realize()
01482 
01483     def _toolbarData(self):
01484         """!Toolbar data
01485         """
01486         icons = Icons['layerManager']
01487         return self._getToolbarData((('importMap', icons["import"],
01488                                       self.parent.OnImportMenu),
01489                                      (None, ),
01490                                      ('mapCalc', icons["mapcalc"],
01491                                       self.parent.OnMapCalculator),
01492                                      ('georect', Icons["georectify"]["georectify"],
01493                                       self.parent.OnGCPManager),
01494                                      ('modeler', icons["modeler"],
01495                                       self.parent.OnGModeler),
01496                                      ('mapOutput', icons['mapOutput'],
01497                                       self.parent.OnPsMap)
01498                                      ))
01499 
01500 class LMMiscToolbar(AbstractToolbar):
01501     """!Layer Manager `misc` toolbar
01502     """
01503     def __init__(self, parent):
01504         AbstractToolbar.__init__(self, parent)
01505         
01506         self.InitToolbar(self._toolbarData())
01507         
01508         # realize the toolbar
01509         self.Realize()
01510 
01511     def _toolbarData(self):
01512         """!Toolbar data
01513         """
01514         icons = Icons['layerManager']
01515         return self._getToolbarData((('settings', icons["settings"],
01516                                       self.parent.OnPreferences),
01517                                      ('help', Icons["misc"]["help"],
01518                                       self.parent.OnHelp),
01519                                      ))
01520 
01521 class LMVectorToolbar(AbstractToolbar):
01522     """!Layer Manager `vector` toolbar
01523     """
01524     def __init__(self, parent):
01525         AbstractToolbar.__init__(self, parent)
01526         
01527         self.InitToolbar(self._toolbarData())
01528         
01529         # realize the toolbar
01530         self.Realize()
01531 
01532     def _toolbarData(self):
01533         """!Toolbar data
01534         """
01535         icons = Icons['layerManager']
01536         return self._getToolbarData((('vdigit', icons["vdigit"],
01537                                       self.parent.OnVDigit),
01538                                      ('attribute', icons["attrTable"],
01539                                       self.parent.OnShowAttributeTable),
01540                                      ))
01541     
01542 class PsMapToolbar(AbstractToolbar):
01543     def __init__(self, parent):
01544         """!Toolbar Cartographic Composer (psmap.py)
01545         
01546         @param parent parent window
01547         """
01548         AbstractToolbar.__init__(self, parent)
01549         
01550         self.InitToolbar(self._toolbarData())
01551         
01552         self.Realize()
01553         
01554         self.action = { 'id' : self.pointer }
01555         self.defaultAction = { 'id' : self.pointer,
01556                                'bind' : self.parent.OnPointer }
01557         self.OnTool(None)
01558         
01559         from psmap import haveImage
01560         if not haveImage:
01561             self.EnableTool(self.preview, False)
01562         
01563     def _toolbarData(self):
01564         """!Toolbar data
01565         """
01566         icons = Icons['psMap']
01567         return self._getToolbarData((('loadFile', icons['scriptLoad'],
01568                                       self.parent.OnLoadFile),                                    
01569                                      ('instructionFile', icons['scriptSave'],
01570                                       self.parent.OnInstructionFile),
01571                                      (None, ),
01572                                      ('pagesetup', icons['pageSetup'],
01573                                       self.parent.OnPageSetup),
01574                                      (None, ),
01575                                      ("pointer", Icons["displayWindow"]["pointer"],
01576                                       self.parent.OnPointer, wx.ITEM_CHECK),
01577                                      ('pan', Icons["displayWindow"]['pan'],
01578                                       self.parent.OnPan, wx.ITEM_CHECK),
01579                                      ("zoomin", Icons["displayWindow"]["zoomIn"],
01580                                       self.parent.OnZoomIn, wx.ITEM_CHECK),
01581                                      ("zoomout", Icons["displayWindow"]["zoomOut"],
01582                                       self.parent.OnZoomOut, wx.ITEM_CHECK),
01583                                      ('zoomAll', icons['fullExtent'],
01584                                       self.parent.OnZoomAll),
01585                                      (None, ),
01586                                      ('addMap', icons['addMap'],
01587                                       self.parent.OnAddMap, wx.ITEM_CHECK),
01588                                      ('addRaster', icons['addRast'],
01589                                       self.parent.OnAddRaster),
01590                                      ('addVector', icons['addVect'],
01591                                       self.parent.OnAddVect),
01592                                      ("dec", Icons["displayWindow"]["overlay"],
01593                                       self.parent.OnDecoration),
01594                                      ("delete", icons["deleteObj"],
01595                                       self.parent.OnDelete),
01596                                      (None, ),
01597                                      ("preview", icons["preview"],
01598                                       self.parent.OnPreview),
01599                                      ('generatePS', icons['psExport'],
01600                                       self.parent.OnPSFile),
01601                                      ('generatePDF', icons['pdfExport'],
01602                                       self.parent.OnPDFFile),
01603                                      (None, ),
01604                                      ("help", Icons['misc']['help'],
01605                                       self.parent.OnHelp),
01606                                      ('quit', icons['quit'],
01607                                       self.parent.OnCloseWindow))
01608                                     )
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines