digit.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. \file vdigit/digit.cpp
  3. \brief wxvdigit - C++ interace for wxGUI vector digitizer.
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. (C) 2008-2009 by Martin Landa, and the GRASS development team
  8. \author Martin Landa <landa.martin gmail.com>
  9. */
  10. #include "driver.h"
  11. #include "digit.h"
  12. #ifdef _WIN32
  13. #ifndef _CPPRTTI
  14. #error "compile with /GR!"
  15. #endif
  16. #endif
  17. /**
  18. \brief Initialize digit interface used by SWIG
  19. \param driver display driver instance
  20. \param window parent window for message dialog
  21. */
  22. Digit::Digit(DisplayDriver *ddriver, wxWindow *window)
  23. {
  24. display = ddriver;
  25. display->parentWin = window;
  26. if (display->mapInfo) {
  27. InitCats();
  28. }
  29. changesetEnd = changesetCurrent = -1; // initial value for undo/redo
  30. display->msgCaption = _("Digitization error");
  31. // avoid GUI crash
  32. // Vect_set_fatal_error(GV_FATAL_PRINT);
  33. }
  34. /**
  35. \brief Digit class destructor
  36. Frees changeset structure
  37. */
  38. Digit::~Digit()
  39. {
  40. for(int changeset = 0; changeset < (int) changesets.size(); changeset++) {
  41. FreeChangeset(changeset);
  42. }
  43. }
  44. /**
  45. \brief Update digit settings
  46. \param breakLines break lines on intersection
  47. \param addCentroid add centroid to left/right area
  48. \param catBoundary attach category to boundary
  49. */
  50. void Digit::UpdateSettings(bool breakLines,
  51. bool addCentroid, bool catBoundary)
  52. {
  53. settings.breakLines = breakLines;
  54. settings.addCentroid = addCentroid;
  55. settings.catBoundary = !catBoundary; /* do not attach */
  56. return;
  57. }
  58. /*!
  59. \brief Register action before operation
  60. \return changeset id
  61. */
  62. int Digit::AddActionsBefore(void)
  63. {
  64. int changeset;
  65. /* register changeset */
  66. changeset = changesets.size();
  67. for (int i = 0; i < display->selected.ids->n_values; i++) {
  68. int line = display->selected.ids->value[i];
  69. if (Vect_line_alive(display->mapInfo, line))
  70. AddActionToChangeset(changeset, DEL, line);
  71. }
  72. return changeset;
  73. }
  74. /*!
  75. \brief Register action after operation
  76. */
  77. void Digit::AddActionsAfter(int changeset, int nlines)
  78. {
  79. for (int i = 0; i < display->selected.ids->n_values; i++) {
  80. int line = display->selected.ids->value[i];
  81. if (Vect_line_alive(display->mapInfo, line)) {
  82. RemoveActionFromChangeset(changeset, DEL, line);
  83. }
  84. }
  85. for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
  86. if (Vect_line_alive(display->mapInfo, line)) {
  87. AddActionToChangeset(changeset, ADD, line);
  88. }
  89. }
  90. return;
  91. }