do_plt.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Function: do_plt
  2. **
  3. ** Author: Paul W. Carlson March 1992
  4. */
  5. #include <string.h>
  6. #include <grass/gis.h>
  7. #include <grass/glocale.h>
  8. #include <grass/symbol.h>
  9. #include "clr.h"
  10. #include "local_proto.h"
  11. int do_plt(int after_masking)
  12. {
  13. FILE *fp;
  14. char buf[1024], symb[1024], sname[100];
  15. char name[1024] /*, prev_name[50] */;
  16. double e1, n1, e2, n2, llx, lly, urx, ury;
  17. int color_R, color_G, color_B;
  18. int fcolor_R, fcolor_G, fcolor_B;
  19. int masked;
  20. double size, scale, rotate;
  21. int i;
  22. int x_int, y_int;
  23. double width, x, y, x_off, y_off;
  24. PSCOLOR pcolor, pfcolor;
  25. SYMBOL *Symb;
  26. static int snum = 0;
  27. if (PS.plfile == NULL)
  28. return 1;
  29. fp = fopen(PS.plfile, "r");
  30. if (fp == NULL) {
  31. error("point/line file", "", "can't open");
  32. return 1;
  33. }
  34. G_message(_("Reading point/line file ..."));
  35. while (fgets(buf, sizeof buf, fp))
  36. switch (*buf) {
  37. case 'L':
  38. if (sscanf(buf, "L %d %lf %lf %lf %lf %d %d %d %lf", &masked, &e1,
  39. &n1, &e2, &n2, &color_R, &color_G, &color_B,
  40. &width) == 9) {
  41. if (masked && after_masking)
  42. continue;
  43. if (!masked && !after_masking)
  44. continue;
  45. if (color_R == -1)
  46. continue; /* ie color was set to "none" */
  47. set_color(&pcolor, color_R, color_G, color_B);
  48. set_ps_color(&pcolor);
  49. set_line_width(width);
  50. if (G_projection() == PROJECTION_LL) {
  51. /* use the same method as the vlines instruction,
  52. for completely out of region lines just move, don't put
  53. the pen down. but the thing this method has going for it
  54. is that for lat/lon (AFAIU) it draws the line twice,
  55. so that at least one of them will go the desired way
  56. around the sphere, and the other will be discarded.
  57. (I think). But it means your self-defined lines need to
  58. keep at least one little toe in the map box. --HB Feb2012 */
  59. start_line(e1, n1);
  60. sec_draw = 0;
  61. G_plot_line(e1, n1, e2, n2);
  62. }
  63. else {
  64. G_plot_where_xy(e1, n1, &x_int, &y_int);
  65. llx = (double)x_int / 10.;
  66. lly = (double)y_int / 10.;
  67. G_plot_where_xy(e2, n2, &x_int, &y_int);
  68. urx = (double)x_int / 10.;
  69. ury = (double)y_int / 10.;
  70. fprintf(PS.fp, " %.1f %.1f NM %.1f %.1f LN",
  71. llx, lly, urx, ury);
  72. }
  73. fprintf(PS.fp, " stroke\n");
  74. }
  75. break;
  76. case 'R':
  77. if (sscanf(buf, "R %d %lf %lf %lf %lf %d %d %d %d %d %d %lf",
  78. &masked, &e1, &n1, &e2, &n2, &color_R, &color_G,
  79. &color_B, &fcolor_R, &fcolor_G, &fcolor_B,
  80. &width) == 12) {
  81. if (masked && after_masking)
  82. continue;
  83. if (!masked && !after_masking)
  84. continue;
  85. fprintf(PS.fp, " NP\n");
  86. G_plot_where_xy(e1, n1, &x_int, &y_int);
  87. llx = (double)x_int / 10.;
  88. lly = (double)y_int / 10.;
  89. G_plot_where_xy(e2, n2, &x_int, &y_int);
  90. urx = (double)x_int / 10.;
  91. ury = (double)y_int / 10.;
  92. fprintf(PS.fp, " %.1f %.1f M %.1f %.1f LN\n", llx, lly, urx,
  93. lly);
  94. fprintf(PS.fp, " %.1f %.1f LN %.1f %.1f LN\n", urx, ury, llx,
  95. ury);
  96. fprintf(PS.fp, " CP\n");
  97. if (fcolor_R != -1) { /* ie color is not set to "none" */
  98. set_color(&pfcolor, fcolor_R, fcolor_G, fcolor_B);
  99. set_ps_color(&pfcolor);
  100. fprintf(PS.fp, " F\n");
  101. }
  102. if (color_R != -1) { /* ie color is not set to "none" */
  103. set_color(&pcolor, color_R, color_G, color_B);
  104. set_ps_color(&pcolor);
  105. set_line_width(width);
  106. fprintf(PS.fp, " D\n");
  107. }
  108. }
  109. break;
  110. case 'P':
  111. i = sscanf(buf, "P %d %lf %lf %d %d %d %d %d %d %lf %lf %s %lf",
  112. &masked, &e1, &n1, &color_R, &color_G, &color_B,
  113. &fcolor_R, &fcolor_G, &fcolor_B, &size, &rotate, symb,
  114. &width);
  115. if (i == 13) {
  116. if (masked && after_masking)
  117. continue;
  118. if (!masked && !after_masking)
  119. continue;
  120. if (size <= 0.0)
  121. size = 10;
  122. /* HB 7/2005: allow all points through as only way to generate
  123. one is explicitly with the ps.map "point" instruction. */
  124. /*
  125. if (n1 > PS.w.north || n1 < PS.w.south) continue;
  126. if (e1 > PS.w.east || e1 < PS.w.west ) continue;
  127. */
  128. G_plot_where_xy(e1, n1, &x_int, &y_int);
  129. x = (double)x_int / 10.;
  130. y = (double)y_int / 10.;
  131. if (color_R == -1)
  132. unset_color(&pcolor);
  133. else
  134. set_color(&pcolor, color_R, color_G, color_B);
  135. if (fcolor_R == -1)
  136. unset_color(&pfcolor);
  137. else
  138. set_color(&pfcolor, fcolor_R, fcolor_G, fcolor_B);
  139. if (width < 0) /* default: autoscale relative to size */
  140. width = 0.05 * size;
  141. /* Read symbol */
  142. sprintf(sname, "POINTSYMBOL%d", snum);
  143. Symb = S_read(symb);
  144. if (Symb == NULL)
  145. G_warning(_("Cannot read symbol, using default icon"));
  146. symbol_save(Symb, &pcolor, &pfcolor, sname);
  147. symbol_draw(sname, x, y, size, rotate, width);
  148. snum++;
  149. }
  150. break;
  151. case 'E': /* EPS file */
  152. if (sscanf(buf, "E %d %lf %lf %lf %lf %[^\n]s",
  153. &masked, &e1, &n1, &scale, &rotate, name) == 6) {
  154. if (masked && after_masking)
  155. continue;
  156. if (!masked && !after_masking)
  157. continue;
  158. /* find eps bbox */
  159. if (!eps_bbox(name, &llx, &lly, &urx, &ury))
  160. continue;
  161. G_plot_where_xy(e1, n1, &x_int, &y_int);
  162. x = (double)x_int / 10.;
  163. y = (double)y_int / 10.;
  164. /* calculate translation */
  165. eps_trans(llx, lly, urx, ury, x, y, scale, rotate, &x_off,
  166. &y_off);
  167. /* write eps to PS */
  168. eps_draw(PS.fp, name, x_off, y_off, scale, rotate);
  169. }
  170. break;
  171. }
  172. fclose(fp);
  173. return 0;
  174. }