ii2t_statusbar.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 core.utils import _
  16. from mapdisp.statusbar import SbItem, SbTextItem
  17. from gui_core.wrap import SpinCtrl
  18. class SbGoToGCP(SbItem):
  19. """SpinCtrl to select GCP to focus on
  20. Requires MapFrame.GetSrcWindow, MapFrame.GetTgtWindow,
  21. MapFrame.GetListCtrl, MapFrame.GetMapCoordList.
  22. """
  23. def __init__(self, mapframe, statusbar, position=0):
  24. SbItem.__init__(self, mapframe, statusbar, position)
  25. self.name = 'gotoGCP'
  26. self.label = _("Go to GCP No.")
  27. self.widget = SpinCtrl(parent=self.statusbar, id=wx.ID_ANY,
  28. value="", min=0)
  29. self.widget.Hide()
  30. self.widget.Bind(wx.EVT_TEXT_ENTER, self.OnGoToGCP)
  31. self.widget.Bind(wx.EVT_SPINCTRL, self.OnGoToGCP)
  32. def OnGoToGCP(self, event):
  33. """Zooms to given GCP."""
  34. gcpNumber = self.GetValue()
  35. mapCoords = self.mapFrame.GetMapCoordList()
  36. # always false, spin checks it
  37. if gcpNumber < 0 or gcpNumber > len(mapCoords):
  38. GMessage(parent=self,
  39. message="%s 1 - %s." % (_("Valid Range:"),
  40. len(mapCoords)))
  41. return
  42. if gcpNumber == 0:
  43. return
  44. listCtrl = self.mapFrame.GetListCtrl()
  45. listCtrl.selectedkey = gcpNumber
  46. listCtrl.selected = listCtrl.FindItemData(-1, gcpNumber)
  47. listCtrl.render = False
  48. listCtrl.SetItemState(listCtrl.selected,
  49. wx.LIST_STATE_SELECTED,
  50. wx.LIST_STATE_SELECTED)
  51. listCtrl.render = True
  52. listCtrl.EnsureVisible(listCtrl.selected)
  53. srcWin = self.mapFrame.GetSrcWindow()
  54. tgtWin = self.mapFrame.GetTgtWindow()
  55. # Source MapWindow:
  56. begin = (mapCoords[gcpNumber][1], mapCoords[gcpNumber][2])
  57. begin = srcWin.Cell2Pixel(begin)
  58. end = begin
  59. srcWin.Zoom(begin, end, 0)
  60. # redraw map
  61. srcWin.UpdateMap()
  62. if self.mapFrame.GetShowTarget():
  63. # Target MapWindow:
  64. begin = (mapCoords[gcpNumber][3], mapCoords[gcpNumber][4])
  65. begin = tgtWin.Cell2Pixel(begin)
  66. end = begin
  67. tgtWin.Zoom(begin, end, 0)
  68. # redraw map
  69. tgtWin.UpdateMap()
  70. self.GetWidget().SetFocus()
  71. def Update(self):
  72. """Checks the number of items in the gcp list
  73. and sets the spin limits accordingly."""
  74. self.statusbar.SetStatusText("")
  75. maximum = self.mapFrame.GetListCtrl().GetItemCount()
  76. if maximum < 1:
  77. maximum = 1
  78. self.widget.SetRange(0, maximum)
  79. self.Show()
  80. # disable long help
  81. self.mapFrame.StatusbarEnableLongHelp(False)
  82. class SbRMSError(SbTextItem):
  83. """Shows RMS error.
  84. Requires MapFrame.GetFwdError, MapFrame.GetBkwError.
  85. """
  86. def __init__(self, mapframe, statusbar, position=0):
  87. SbTextItem.__init__(self, mapframe, statusbar, position)
  88. self.name = 'RMSError'
  89. self.label = _("RMS error")
  90. def Show(self):
  91. """Shows the RMS errors."""
  92. self.SetValue(_("Forward: %(forw)s, Backward: %(back)s") %
  93. {'forw': self.mapFrame.GetFwdError(),
  94. 'back': self.mapFrame.GetBkwError()})
  95. SbTextItem.Show(self)