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