~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to display/d.path/select.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
#include <unistd.h>
4
4
#include <math.h>
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>
11
10
#include "proto.h"
12
11
 
13
12
#define WDTH 5
14
13
 
15
 
int display(struct Map_info *Map, struct line_pnts *,
16
 
            const struct color_rgb *, int, int, int);
17
 
 
18
 
int path(struct Map_info *Map, const struct color_rgb *color,
19
 
         const struct color_rgb *hcolor, const struct color_rgb *bgcolor,
20
 
         int be_bold)
21
 
{
22
 
    int button, ret;
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;
27
 
    int node;
28
 
    int from_disp = 0, to_disp = 0, sp_disp = 0, from_node = 0, to_node = 0;
29
 
 
30
 
    Points = Vect_new_line_struct();
31
 
 
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);
34
 
 
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"));
39
 
 
40
 
    while (1) {
41
 
        R_get_location_with_pointer(&screen_x, &screen_y, &button);
42
 
 
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); */
46
 
 
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));
51
 
 
52
 
        x1 = fabs(x2 - x1);
53
 
        y1 = fabs(y2 - y1);
54
 
 
55
 
        if (x1 > y1)
56
 
            maxdist = x1;
57
 
        else
58
 
            maxdist = y1;
59
 
        G_debug(1, "Maximum distance in map units = %f\n", maxdist);
60
 
 
61
 
        node = Vect_find_node(Map, x, y, 0.0, maxdist, 0);
62
 
 
63
 
        if (node > 0) {
64
 
            Vect_get_node_coor(Map, node, &nx, &ny, NULL);
65
 
            fprintf(stderr, _("Node %d: %f %f\n"), node, nx, ny);
66
 
        }
67
 
 
68
 
        if (sp_disp) {          /* erase old */
69
 
            /* delete old highlight */
70
 
 
71
 
            display(Map, Points, color, from_node, to_node, be_bold);
72
 
 
73
 
            R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
74
 
            if (!from_node)
75
 
                G_plot_line(Points->x[0], Points->y[0], Points->x[1],
76
 
                            Points->y[1]);
77
 
 
78
 
            if (!to_node)
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]);
83
 
        }
84
 
 
85
 
        switch (button) {
86
 
        case 1:
87
 
            if (from_disp) {
88
 
                R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
89
 
                G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
90
 
            }
91
 
            if (node > 0) {
92
 
                fx = nx;
93
 
                fy = ny;
94
 
                from_node = 1;
95
 
            }
96
 
            else {
97
 
                fx = x;
98
 
                fy = y;
99
 
                from_node = 0;
100
 
            }
101
 
            R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
102
 
            G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
103
 
            R_flush();
104
 
            from_disp = 1;
105
 
            break;
106
 
        case 2:
107
 
            if (to_disp) {
108
 
                R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
109
 
                G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
110
 
            }
111
 
            if (node > 0) {
112
 
                tx = nx;
113
 
                ty = ny;
114
 
                to_node = 1;
115
 
            }
116
 
            else {
117
 
                tx = x;
118
 
                ty = y;
119
 
                to_node = 0;
120
 
            }
121
 
            R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
122
 
            G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
123
 
            R_flush();
124
 
            to_disp = 1;
125
 
            break;
126
 
        case 3:
127
 
            if (from_disp) {
128
 
                R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
129
 
                G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
130
 
            }
131
 
            if (to_disp) {
132
 
                R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
133
 
                G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
134
 
            }
135
 
            return 1;
136
 
            break;
137
 
        }
138
 
        if (from_disp && to_disp) {
139
 
            double fdist, tdist, cost;
140
 
 
141
 
            G_debug(2, "find path %f %f -> %f %f", fx, fy, tx, ty);
142
 
 
143
 
            ret =
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,
147
 
                                            &tdist);
148
 
            if (ret == 0) {
149
 
                fprintf(stdout, _("Destination unreachable\n"));
150
 
                sp_disp = 0;
151
 
            }
152
 
            else {
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"),
156
 
                        fdist, tdist);
157
 
 
158
 
                display(Map, Points, hcolor, 1, 1, be_bold);
159
 
                sp_disp = 1;
160
 
            }
161
 
 
162
 
        }
163
 
        R_flush();
164
 
    };
165
 
 
166
 
    return 0;
167
 
}
168
 
 
169
 
 
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)
172
16
{
173
 
    int i, from, to;
 
17
    int from, to;
174
18
 
175
 
    R_RGB_color(color->r, color->g, color->b);
 
19
    D_RGB_color(color->r, color->g, color->b);
176
20
 
177
21
    if (first)
178
22
        from = 0;
186
30
    if (be_bold)
187
31
        D_line_width(2);
188
32
 
189
 
    for (i = from; i < to - 1; i++)
190
 
        G_plot_line(Points->x[i], Points->y[i], Points->x[i + 1],
191
 
                    Points->y[i + 1]);
 
33
    D_polyline_abs(&Points->x[from], &Points->y[from], to - from);
192
34
 
193
35
    if (be_bold)
194
 
        R_line_width(0);
 
36
        D_line_width(0);
195
37
 
196
38
    return 0;
197
39
}
249
91
        fx = start_x;
250
92
        fy = start_y;
251
93
    }
252
 
    R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
253
 
    G_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
 
94
    D_RGB_color(hcolor->r, hcolor->g, hcolor->b);
 
95
    D_plot_icon(fx, fy, G_ICON_BOX, 0.0, msize);
254
96
 
255
97
 
256
98
    end_node = Vect_find_node(Map, end_x, end_y, 0.0, maxdist, 0);
266
108
        tx = end_x;
267
109
        ty = end_y;
268
110
    }
269
 
    R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
270
 
    G_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
 
111
    D_RGB_color(hcolor->r, hcolor->g, hcolor->b);
 
112
    D_plot_icon(tx, ty, G_ICON_CROSS, 0.0, msize);
271
113
 
272
114
 
273
115
    G_debug(2, "find path %f %f -> %f %f", fx, fy, tx, ty);