topo.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <grass/gis.h>
  2. #include <grass/vector.h>
  3. #include <grass/display.h>
  4. #include <grass/glocale.h>
  5. #include "local_proto.h"
  6. #include "plot.h"
  7. int display_topo(struct Map_info *Map, int type, LATTR *lattr)
  8. {
  9. int ltype, num, el;
  10. struct line_pnts *Points;
  11. struct line_cats *Cats;
  12. char text[50];
  13. LATTR lattr2 = *lattr;
  14. if (Vect_level(Map) < 2) {
  15. G_warning(_("Unable to display topology, not available."
  16. "Please try to rebuild topology using "
  17. "v.build or v.build.all."));
  18. return 1;
  19. }
  20. lattr2.xref = lattr->xref == LRIGHT ? LLEFT : LRIGHT;
  21. G_debug(1, "display topo:");
  22. Points = Vect_new_line_struct();
  23. Cats = Vect_new_cats_struct();
  24. D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
  25. D_text_size(lattr->size, lattr->size);
  26. if (lattr->font)
  27. D_font(lattr->font);
  28. if (lattr->enc)
  29. D_encoding(lattr->enc);
  30. Vect_rewind(Map);
  31. num = Vect_get_num_lines(Map);
  32. G_debug(1, "n_lines = %d", num);
  33. /* Lines */
  34. for (el = 1; el <= num; el++) {
  35. if (!Vect_line_alive(Map, el))
  36. continue;
  37. ltype = Vect_read_line(Map, Points, Cats, el);
  38. G_debug(3, "ltype = %d", ltype);
  39. switch (ltype) {
  40. case -1:
  41. G_fatal_error(_("Unable to read vector map"));
  42. case -2: /* EOF */
  43. return 0;
  44. }
  45. if (!(type & ltype))
  46. continue; /* used for both lines and labels */
  47. sprintf(text, "%d", el);
  48. show_label_line(Points, ltype, lattr, text);
  49. }
  50. num = Vect_get_num_nodes(Map);
  51. G_debug(1, "n_nodes = %d", num);
  52. /* Nodes */
  53. for (el = 1; el <= num; el++) {
  54. double X, Y;
  55. if (!Vect_node_alive(Map, el))
  56. continue;
  57. Vect_get_node_coor(Map, el, &X, &Y, NULL);
  58. G_debug(3, "node = %d", el);
  59. sprintf(text, "n%d", el);
  60. show_label(&X, &Y, &lattr2, text);
  61. D_plot_icon(X, Y, G_ICON_BOX, 0, 10);
  62. }
  63. Vect_destroy_line_struct(Points);
  64. Vect_destroy_cats_struct(Cats);
  65. return 0;
  66. }