topo.c 2.0 KB

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