digit.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 GetCurrentCategory(self):
  48. """!Returns current category (class).
  49. Category should be assigned to new features (areas).
  50. It is taken from parent's toolbar.
  51. """
  52. return self.parent.GetToolbar("iClass").GetSelectedCategoryIdx()
  53. class IClassIVDigit(IVDigit):
  54. """! Class similar to IVDigit but specialized for wxIClass."""
  55. def __init__(self, mapwindow):
  56. IVDigit.__init__(self, mapwindow)
  57. def _getNewFeaturesLayer(self):
  58. return 1
  59. def _getNewFeaturesCat(self):
  60. cat = self.mapWindow.GetCurrentCategory()
  61. return cat