digit.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """!
  2. @package iclass::digit
  3. @brief wxIClass digitizer classes
  4. Classes:
  5. - digit::IClassVDigit
  6. - digit::IClassVDigitWindow
  7. (C) 2006-2011 by the GRASS Development Team
  8. This program is free software under the GNU General Public
  9. License (>=v2). Read the file COPYING that comes with GRASS
  10. for details.
  11. @author Vaclav Petras <wenzeslaus gmail.com>
  12. @author Anna Kratochvilova <kratochanna gmail.com>
  13. """
  14. import wx
  15. from vdigit.mapwindow import VDigitWindow
  16. from vdigit.wxdigit import IVDigit
  17. class IClassVDigitWindow(VDigitWindow):
  18. """! Class similar to VDigitWindow but specialized for wxIClass."""
  19. def __init__(self, parent, map):
  20. """!
  21. @a parent should has toolbar providing current class (category).
  22. @param parent gui parent
  23. @param map map renderer instance
  24. """
  25. VDigitWindow.__init__(self, parent = parent, Map = map)
  26. def _onLeftDown(self, event):
  27. action = self.toolbar.GetAction()
  28. if not action:
  29. return
  30. cat = self.GetCurrentCategory()
  31. if cat is None and action == "addLine":
  32. dlg = wx.MessageDialog(parent = self.parent,
  33. message = _("In order to create a training area, "
  34. "you have to select class first.\n\n"
  35. "There is no class yet, "
  36. "do you want to create one?"),
  37. caption = _("No class selected"),
  38. style = wx.YES_NO)
  39. if dlg.ShowModal() == wx.ID_YES:
  40. self.parent.OnCategoryManager(None)
  41. dlg.Destroy()
  42. event.Skip()
  43. return
  44. super(IClassVDigitWindow, self)._onLeftDown(event)
  45. def _addRecord(self):
  46. return False
  47. def _updateATM(self):
  48. pass
  49. def _onRightUp(self, event):
  50. super(IClassVDigitWindow, self)._onRightUp(event)
  51. self.parent.UpdateChangeState(changes = True)
  52. def GetCurrentCategory(self):
  53. """!Returns current category (class).
  54. Category should be assigned to new features (areas).
  55. It is taken from parent's toolbar.
  56. """
  57. return self.parent.GetToolbar("iClass").GetSelectedCategoryIdx()
  58. class IClassVDigit(IVDigit):
  59. """! Class similar to IVDigit but specialized for wxIClass."""
  60. def __init__(self, mapwindow):
  61. IVDigit.__init__(self, mapwindow)
  62. def _getNewFeaturesLayer(self):
  63. return 1
  64. def _getNewFeaturesCat(self):
  65. cat = self.mapWindow.GetCurrentCategory()
  66. return cat