digit.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. extern "C" {
  11. #include <grass/glocale.h>
  12. }
  13. #include "driver.h"
  14. #include "digit.h"
  15. #if defined _WIN32 && defined MSVC_VER
  16. #ifndef _CPPRTTI
  17. #error "compile with /GR!"
  18. #endif
  19. #endif
  20. /**
  21. \brief Initialize digit interface
  22. \param driver display driver instance
  23. \param window parent window for message dialog
  24. */
  25. Digit::Digit(DisplayDriver *ddriver, wxWindow *window)
  26. {
  27. display = ddriver;
  28. if (!display)
  29. return;
  30. if (display->mapInfo) {
  31. InitCats();
  32. }
  33. changesetEnd = changesetCurrent = -1; // initial value for undo/redo
  34. display->msgCaption = _("Digitization error");
  35. // avoid GUI crash
  36. // Vect_set_fatal_error(GV_FATAL_PRINT);
  37. }
  38. /**
  39. \brief Digit class destructor
  40. Frees changeset structure
  41. */
  42. Digit::~Digit()
  43. {
  44. for(int changeset = 0; changeset < (int) changesets.size(); changeset++) {
  45. FreeChangeset(changeset);
  46. }
  47. }
  48. /**
  49. \brief Update digit settings
  50. \param breakLines break lines on intersection
  51. \param addCentroid add centroid to left/right area
  52. \param catBoundary attach category to boundary
  53. */
  54. void Digit::UpdateSettings(bool breakLines,
  55. bool addCentroid, bool catBoundary)
  56. {
  57. settings.breakLines = breakLines;
  58. settings.addCentroid = addCentroid;
  59. settings.catBoundary = !catBoundary; /* do not attach */
  60. return;
  61. }
  62. /*!
  63. \brief Register action before operation
  64. \return changeset id
  65. */
  66. int Digit::AddActionsBefore(void)
  67. {
  68. int changeset;
  69. /* register changeset */
  70. changeset = changesets.size();
  71. for (int i = 0; i < display->selected.ids->n_values; i++) {
  72. int line = display->selected.ids->value[i];
  73. if (Vect_line_alive(display->mapInfo, line))
  74. AddActionToChangeset(changeset, DEL, line);
  75. }
  76. return changeset;
  77. }
  78. /*!
  79. \brief Register action after operation
  80. */
  81. void Digit::AddActionsAfter(int changeset, int nlines)
  82. {
  83. for (int i = 0; i < display->selected.ids->n_values; i++) {
  84. int line = display->selected.ids->value[i];
  85. if (Vect_line_alive(display->mapInfo, line)) {
  86. RemoveActionFromChangeset(changeset, DEL, line);
  87. }
  88. }
  89. for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
  90. if (Vect_line_alive(display->mapInfo, line)) {
  91. AddActionToChangeset(changeset, ADD, line);
  92. }
  93. }
  94. return;
  95. }