5
5
#include <grass/gis.h>
6
#include <grass/raster.h>
7
6
#include <grass/display.h>
8
#include <grass/Vect.h>
7
#include <grass/vector.h>
9
8
#include <grass/colors.h>
10
9
#include <grass/glocale.h>
15
int display(struct Map_info *Map, struct line_pnts *,
16
const struct color_rgb *, int, int, int);
18
int path(struct Map_info *Map, const struct color_rgb *color,
19
const struct color_rgb *hcolor, const struct color_rgb *bgcolor,
23
int screen_x, screen_y;
24
double x, y, nx, ny, fx, fy, tx, ty, msize;
25
double x1, y1, x2, y2, maxdist;
26
struct line_pnts *Points;
28
int from_disp = 0, to_disp = 0, sp_disp = 0, from_node = 0, to_node = 0;
30
Points = Vect_new_line_struct();
32
msize = 10 * (D_d_to_u_col(2.0) - D_d_to_u_col(1.0)); /* do it better */
33
G_debug(1, "msize = %f\n", msize);
35
G_message(_("\nMouse Buttons:"));
36
fprintf(stderr, _("Left: Select From\n"));
37
fprintf(stderr, _("Middle: Select To\n"));
38
fprintf(stderr, _("Right: Quit\n\n"));
41
R_get_location_with_pointer(&screen_x, &screen_y, &button);
43
x = D_d_to_u_col((double)(screen_x));
44
y = D_d_to_u_row((double)(screen_y));
45
/* fprintf (stderr, "%f %f\n", x, y); */
47
x1 = D_d_to_u_col((double)(screen_x - WDTH));
48
y1 = D_d_to_u_row((double)(screen_y - WDTH));
49
x2 = D_d_to_u_col((double)(screen_x + WDTH));
50
y2 = D_d_to_u_row((double)(screen_y + WDTH));
59
G_debug(1, "Maximum distance in map units = %f\n", maxdist);
61
node = Vect_find_node(Map, x, y, 0.0, maxdist, 0);
64
Vect_get_node_coor(Map, node, &nx, &ny, NULL);
65
fprintf(stderr, _("Node %d: %f %f\n"), node, nx, ny);
68
if (sp_disp) { /* erase old */
69
/* delete old highlight */
71
display(Map, Points, color, from_node, to_node, be_bold);
73
R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
75
G_plot_line(Points->x[0], Points->y[0], Points->x[1],
79
G_plot_line(Points->x[Points->n_points - 2],
80
Points->y[Points->n_points - 2],
81
Points->x[Points->n_points - 1],
82
Points->y[Points->n_points - 1]);
88
R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
89
G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
101
R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
102
G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
108
R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
109
G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
121
R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
122
G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
128
R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
129
G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
132
R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
133
G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
138
if (from_disp && to_disp) {
139
double fdist, tdist, cost;
141
G_debug(2, "find path %f %f -> %f %f", fx, fy, tx, ty);
144
Vect_net_shortest_path_coor(Map, fx, fy, 0.0, tx, ty, 0.0,
145
5 * maxdist, 5 * maxdist, &cost,
146
Points, NULL, NULL, NULL, &fdist,
149
fprintf(stdout, _("Destination unreachable\n"));
153
fprintf(stdout, _("Costs on the network = %f\n"), cost);
154
fprintf(stdout, _(" Distance to the network = %f, "
155
"distance from the network = %f\n\n"),
158
display(Map, Points, hcolor, 1, 1, be_bold);
170
14
int display(struct Map_info *Map, struct line_pnts *Points,
171
15
const struct color_rgb *color, int first, int last, int be_bold)
175
R_RGB_color(color->r, color->g, color->b);
19
D_RGB_color(color->r, color->g, color->b);