digit.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. display->parentWin = window;
  29. if (display->mapInfo) {
  30. InitCats();
  31. }
  32. changesetEnd = changesetCurrent = -1; // initial value for undo/redo
  33. display->msgCaption = _("Digitization error");
  34. // avoid GUI crash
  35. // Vect_set_fatal_error(GV_FATAL_PRINT);
  36. }
  37. /**
  38. \brief Digit class destructor
  39. Frees changeset structure
  40. */
  41. Digit::~Digit()
  42. {
  43. for(int changeset = 0; changeset < (int) changesets.size(); changeset++) {
  44. FreeChangeset(changeset);
  45. }
  46. }
  47. /**
  48. \brief Update digit settings
  49. \param breakLines break lines on intersection
  50. \param addCentroid add centroid to left/right area
  51. \param catBoundary attach category to boundary
  52. */
  53. void Digit::UpdateSettings(bool breakLines,
  54. bool addCentroid, bool catBoundary)
  55. {
  56. settings.breakLines = breakLines;
  57. settings.addCentroid = addCentroid;
  58. settings.catBoundary = !catBoundary; /* do not attach */
  59. return;
  60. }
  61. /*!
  62. \brief Register action before operation
  63. \return changeset id
  64. */
  65. int Digit::AddActionsBefore(void)
  66. {
  67. int changeset;
  68. /* register changeset */
  69. changeset = changesets.size();
  70. for (int i = 0; i < display->selected.ids->n_values; i++) {
  71. int line = display->selected.ids->value[i];
  72. if (Vect_line_alive(display->mapInfo, line))
  73. AddActionToChangeset(changeset, DEL, line);
  74. }
  75. return changeset;
  76. }
  77. /*!
  78. \brief Register action after operation
  79. */
  80. void Digit::AddActionsAfter(int changeset, int nlines)
  81. {
  82. for (int i = 0; i < display->selected.ids->n_values; i++) {
  83. int line = display->selected.ids->value[i];
  84. if (Vect_line_alive(display->mapInfo, line)) {
  85. RemoveActionFromChangeset(changeset, DEL, line);
  86. }
  87. }
  88. for (int line = nlines + 1; line <= Vect_get_num_lines(display->mapInfo); line++) {
  89. if (Vect_line_alive(display->mapInfo, line)) {
  90. AddActionToChangeset(changeset, ADD, line);
  91. }
  92. }
  93. return;
  94. }