digit.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. try:
  18. from grass.lib.vedit import *
  19. except ImportError:
  20. pass
  21. class IClassVDigitWindow(VDigitWindow):
  22. """! Class similar to VDigitWindow but specialized for wxIClass."""
  23. def __init__(self, parent, map, frame):
  24. """!
  25. @a parent should has toolbar providing current class (category).
  26. @param parent gui parent
  27. @param map map renderer instance
  28. """
  29. VDigitWindow.__init__(self, parent = parent, Map = map, frame = frame)
  30. def _onLeftDown(self, event):
  31. action = self.toolbar.GetAction()
  32. if not action:
  33. return
  34. cat = self.GetCurrentCategory()
  35. if cat is None and action == "addLine":
  36. dlg = wx.MessageDialog(parent = self.parent,
  37. message = _("In order to create a training area, "
  38. "you have to select class first.\n\n"
  39. "There is no class yet, "
  40. "do you want to create one?"),
  41. caption = _("No class selected"),
  42. style = wx.YES_NO)
  43. if dlg.ShowModal() == wx.ID_YES:
  44. self.parent.OnCategoryManager(None)
  45. dlg.Destroy()
  46. event.Skip()
  47. return
  48. super(IClassVDigitWindow, self)._onLeftDown(event)
  49. def _addRecord(self):
  50. return False
  51. def _updateATM(self):
  52. pass
  53. def _onRightUp(self, event):
  54. super(IClassVDigitWindow, self)._onRightUp(event)
  55. self.parent.UpdateChangeState(changes = True)
  56. def GetCurrentCategory(self):
  57. """!Returns current category (class).
  58. Category should be assigned to new features (areas).
  59. It is taken from parent's toolbar.
  60. """
  61. return self.parent.GetToolbar("iClass").GetSelectedCategoryIdx()
  62. class IClassVDigit(IVDigit):
  63. """! Class similar to IVDigit but specialized for wxIClass."""
  64. def __init__(self, mapwindow):
  65. IVDigit.__init__(self, mapwindow)
  66. def _getNewFeaturesLayer(self):
  67. return 1
  68. def _getNewFeaturesCat(self):
  69. cat = self.mapWindow.GetCurrentCategory()
  70. return cat
  71. def DeleteAreasByCat(self, cats):
  72. """!Delete areas (centroid+boundaries) by categories
  73. @param cats list of categories
  74. """
  75. for cat in cats:
  76. Vedit_delete_areas_cat(self.poMapInfo, 1, cat)