do_vectors.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* Function: do_vectors
  2. **
  3. ** Author: Paul W. Carlson March 1992
  4. ** Modified by: Janne Soimasuo August 1994 line_cat added
  5. ** Modified by: Radim Blazek Jan 2000 areas added
  6. ** Modified by: Hamish Bowman Jun 2005 points moved to do_vpoints()
  7. */
  8. #include <string.h>
  9. #include <grass/gis.h>
  10. #include <grass/glocale.h>
  11. #include <grass/vector.h>
  12. #include <grass/symbol.h>
  13. #include "clr.h"
  14. #include "vector.h"
  15. #include "local_proto.h"
  16. int do_vectors(int after_masking)
  17. {
  18. int n, z, lz, dig;
  19. struct Map_info Map;
  20. char dashes[100], buf[20], *ptr;
  21. n = vector.count;
  22. while (n-- > 0) {
  23. if (vector.layer[n].type == VPOINTS)
  24. continue;
  25. if (after_masking && vector.layer[n].masked)
  26. continue;
  27. if (!after_masking && !vector.layer[n].masked)
  28. continue;
  29. G_message(_("Reading vector map <%s in %s> ..."),
  30. vector.layer[n].name, vector.layer[n].mapset);
  31. Vect_set_open_level(2);
  32. if (2 > Vect_open_old(&Map, vector.layer[n].name,
  33. vector.layer[n].mapset)) {
  34. char name[100];
  35. sprintf(name, "%s in %s", vector.layer[n].name,
  36. vector.layer[n].mapset);
  37. error("vector map", name, "can't open");
  38. continue;
  39. }
  40. if (vector.layer[n].type == VAREAS) {
  41. PS_vareas_plot(&Map, n);
  42. }
  43. else if (vector.layer[n].type == VLINES) {
  44. fprintf(PS.fp, "[] 0 setdash\n");
  45. if (vector.layer[n].hwidth &&
  46. vector.layer[n].ref == LINE_REF_CENTER) {
  47. set_ps_color(&(vector.layer[n].hcolor));
  48. fprintf(PS.fp, "%.8f W\n",
  49. vector.layer[n].width + 2. * vector.layer[n].hwidth);
  50. PS_vlines_plot(&Map, n, LINE_DRAW_HIGHLITE);
  51. Vect_rewind(&Map);
  52. }
  53. fprintf(PS.fp, "%.8f W\n", vector.layer[n].width);
  54. set_ps_color(&(vector.layer[n].color));
  55. if (vector.layer[n].linecap >= 0) {
  56. G_debug(1, "Line cap: '%d'", vector.layer[n].linecap);
  57. fprintf(PS.fp, "%d setlinecap\n",vector.layer[n].linecap);
  58. }
  59. dashes[0] = '[';
  60. dashes[1] = 0;
  61. lz = 0;
  62. if (vector.layer[n].linestyle != NULL) {
  63. G_debug(1, "Line style: '%s'", vector.layer[n].linestyle);
  64. G_strip(vector.layer[n].linestyle);
  65. ptr = vector.layer[n].linestyle;
  66. while (*ptr && (*ptr < '1' || *ptr > '9')) {
  67. lz++;
  68. ptr++;
  69. }
  70. if (lz) {
  71. sprintf(buf, "%d ", lz);
  72. strcat(dashes, buf);
  73. }
  74. while (*ptr) {
  75. dig = 0;
  76. while (*ptr >= '1' && *ptr <= '9') {
  77. dig++;
  78. ptr++;
  79. }
  80. if (dig) {
  81. sprintf(buf, "%d ", dig);
  82. strcat(dashes, buf);
  83. }
  84. z = 0;
  85. while (*ptr && (*ptr < '1' || *ptr > '9')) {
  86. z++;
  87. ptr++;
  88. }
  89. if (z) {
  90. sprintf(buf, "%d ", z);
  91. strcat(dashes, buf);
  92. }
  93. }
  94. }
  95. sprintf(buf, "] %d", lz);
  96. strcat(dashes, buf);
  97. fprintf(PS.fp, "%s setdash\n", dashes);
  98. vector.layer[n].setdash = G_store(dashes);
  99. if (vector.layer[n].linestyle != NULL)
  100. G_debug(1, "Dash style: '%s setdash'", dashes);
  101. PS_vlines_plot(&Map, n, LINE_DRAW_LINE);
  102. }
  103. Vect_close(&Map);
  104. fprintf(PS.fp, "[] 0 setdash\n");
  105. }
  106. return 0;
  107. }
  108. int do_vpoints(int after_masking)
  109. {
  110. int n;
  111. struct Map_info Map;
  112. n = vector.count;
  113. while (n-- > 0) {
  114. if (vector.layer[n].type != VPOINTS)
  115. continue;
  116. if (after_masking && vector.layer[n].masked)
  117. continue;
  118. if (!after_masking && !vector.layer[n].masked)
  119. continue;
  120. G_message(_("Reading vector points file <%s in %s> ..."),
  121. vector.layer[n].name, vector.layer[n].mapset);
  122. Vect_set_open_level(2);
  123. if (2 > Vect_open_old(&Map, vector.layer[n].name,
  124. vector.layer[n].mapset)) {
  125. char name[100];
  126. sprintf(name, "%s in %s", vector.layer[n].name,
  127. vector.layer[n].mapset);
  128. error("vector map", name, "can't open");
  129. continue;
  130. }
  131. PS_vpoints_plot(&Map, n);
  132. Vect_close(&Map);
  133. fprintf(PS.fp, "[] 0 setdash\n");
  134. }
  135. return 0;
  136. }