statusbar.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. """
  2. @package gcp.statusbar
  3. @brief Classes for statusbar management in GCP Manager
  4. Classes:
  5. - statusbar::SbRMSError
  6. - statusbar::SbGoToGCP
  7. (C) 2012-2013 by the GRASS Development Team
  8. This program is free software under the GNU General Public License
  9. (>=v2). Read the file COPYING that comes with GRASS for details.
  10. @author Vaclav Petras <wenzeslaus gmail.com> (statusbar refactoring)
  11. @author Anna Kratochvilova <kratochanna gmail.com> (statusbar refactoring)
  12. """
  13. import wx
  14. from core.gcmd import GMessage
  15. from mapdisp.statusbar import SbItem, SbTextItem
  16. from gui_core.wrap import SpinCtrl
  17. class SbGoToGCP(SbItem):
  18. """SpinCtrl to select GCP to focus on
  19. Requires MapFrame.GetSrcWindow, MapFrame.GetTgtWindow,
  20. MapFrame.GetListCtrl, MapFrame.GetMapCoordList.
  21. """
  22. def __init__(self, mapframe, statusbar, position=0):
  23. SbItem.__init__(self, mapframe, statusbar, position)
  24. self.name = "gotoGCP"
  25. self.label = _("Pan to GCP by number")
  26. self.widget = SpinCtrl(parent=self.statusbar, id=wx.ID_ANY, value="", min=0)
  27. self.widget.Hide()
  28. self.widget.Bind(wx.EVT_TEXT_ENTER, self.OnGoToGCP)
  29. self.widget.Bind(wx.EVT_SPINCTRL, self.OnGoToGCP)
  30. def OnGoToGCP(self, event):
  31. """Zooms to given GCP."""
  32. gcpNumber = self.GetValue()
  33. mapCoords = self.mapFrame.GetMapCoordList()
  34. # always false, spin checks it
  35. if gcpNumber < 0 or gcpNumber > len(mapCoords):
  36. GMessage(
  37. parent=self, message="%s 1 - %s." % (_("Valid Range:"), len(mapCoords))
  38. )
  39. return
  40. if gcpNumber == 0:
  41. return
  42. listCtrl = self.mapFrame.GetListCtrl()
  43. listCtrl.selectedkey = gcpNumber
  44. listCtrl.selected = listCtrl.FindItem(-1, gcpNumber)
  45. listCtrl.render = False
  46. listCtrl.SetItemState(
  47. listCtrl.selected, wx.LIST_STATE_SELECTED, wx.LIST_STATE_SELECTED
  48. )
  49. listCtrl.render = True
  50. listCtrl.EnsureVisible(listCtrl.selected)
  51. srcWin = self.mapFrame.GetSrcWindow()
  52. tgtWin = self.mapFrame.GetTgtWindow()
  53. # Source MapWindow:
  54. begin = (mapCoords[gcpNumber][1], mapCoords[gcpNumber][2])
  55. begin = srcWin.Cell2Pixel(begin)
  56. end = begin
  57. srcWin.Zoom(begin, end, 0)
  58. # redraw map
  59. srcWin.UpdateMap()
  60. if self.mapFrame.GetShowTarget():
  61. # Target MapWindow:
  62. begin = (mapCoords[gcpNumber][3], mapCoords[gcpNumber][4])
  63. begin = tgtWin.Cell2Pixel(begin)
  64. end = begin
  65. tgtWin.Zoom(begin, end, 0)
  66. # redraw map
  67. tgtWin.UpdateMap()
  68. self.GetWidget().SetFocus()
  69. def Update(self):
  70. """Checks the number of items in the gcp list
  71. and sets the spin limits accordingly."""
  72. self.statusbar.SetStatusText("")
  73. maximum = self.mapFrame.GetListCtrl().GetItemCount()
  74. if maximum < 1:
  75. maximum = 1
  76. self.widget.SetRange(0, maximum)
  77. self.Show()
  78. # disable long help
  79. self.mapFrame.StatusbarEnableLongHelp(False)
  80. class SbRMSError(SbTextItem):
  81. """Shows RMS error.
  82. Requires MapFrame.GetFwdError, MapFrame.GetBkwError.
  83. """
  84. def __init__(self, mapframe, statusbar, position=0):
  85. SbTextItem.__init__(self, mapframe, statusbar, position)
  86. self.name = "RMSError"
  87. self.label = _("RMS error")
  88. def Show(self):
  89. """Shows the RMS errors."""
  90. self.SetValue(
  91. _("Forward: %(forw)s, Backward: %(back)s")
  92. % {"forw": self.mapFrame.GetFwdError(), "back": self.mapFrame.GetBkwError()}
  93. )
  94. SbTextItem.Show(self)