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

« back to all changes in this revision

Viewing changes to display/d.graph/do_graph.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:
1
1
#include <stdio.h>
2
2
#include <string.h>
3
3
#include <grass/gis.h>
 
4
#include <grass/colors.h>
 
5
#include <grass/raster.h>
4
6
#include <grass/display.h>
5
 
#include <grass/raster.h>
6
7
#include <grass/symbol.h>
7
8
#include <grass/glocale.h>
8
9
 
12
13
#define CHUNK   128
13
14
 
14
15
static int coors_allocated = 0;
15
 
static int *xarray;
16
 
static int *yarray;
 
16
static double *xarray;
 
17
static double *yarray;
17
18
 
18
19
static float xincr;
19
20
static float yincr;
22
23
 
23
24
static RGBA_Color last_color;
24
25
 
 
26
static double t, b, l, r;
 
27
 
 
28
static double cur_x, cur_y;
 
29
 
25
30
int set_graph_stuff(void)
26
31
{
27
 
    xincr = (float)(r - l) / 100.;
28
 
    if (xincr < 0.0)
29
 
        xincr = -xincr;         /* mod: shapiro 13 jun 1991 */
30
 
    yincr = (float)(b - t) / 100.;
31
 
    if (yincr < 0.0)
32
 
        yincr = -yincr;         /* mod: shapiro 13 jun 1991 */
 
32
    D_get_dst(&t, &b, &l, &r);
 
33
 
 
34
    if (mapunits) {
 
35
        xincr = (r - l) / 100.;
 
36
        if (xincr < 0.0)
 
37
            xincr = -xincr;             /* mod: shapiro 13 jun 1991 */
 
38
        yincr = (b - t) / 100.;
 
39
        if (yincr < 0.0)
 
40
            yincr = -yincr;             /* mod: shapiro 13 jun 1991 */
 
41
    }
 
42
    else
 
43
        xincr = yincr = 1;
33
44
 
34
45
    rotation = 0.0;             /* init */
35
46
 
39
50
int set_text_size(void)
40
51
{
41
52
    if (hsize >= 0. && vsize >= 0. && hsize <= 100. && vsize <= 100.) {
42
 
        R_text_size((int)(hsize * xincr), (int)(vsize * yincr));
43
 
        G_debug(3, "text size initialized to [%d,%d] pixels",
44
 
                (int)(hsize * xincr), (int)(vsize * yincr));
45
 
    }
46
 
    return (0);
47
 
}
48
 
 
49
 
int do_draw(char *buff)
50
 
{
51
 
    float xper, yper;
52
 
 
53
 
    if (2 != sscanf(buff, "%*s %f %f", &xper, &yper)) {
54
 
        G_warning(_("Problem parsing coordinates [%s]"), buff);
55
 
        return (-1);
56
 
    }
57
 
 
58
 
    if (mapunits) {
59
 
        /* skip check: clips segments if map coordinate is out of region.
60
 
           if( xper < D_get_u_west() ||
61
 
           yper < D_get_u_south() ||
62
 
           xper > D_get_u_east() ||
63
 
           yper > D_get_u_north() )
64
 
           return(-1);
65
 
         */
66
 
        R_cont_abs((int)(D_u_to_d_col(xper) + 0.5),
67
 
                   (int)(D_u_to_d_row(yper) + 0.5));
68
 
    }
69
 
    else {
70
 
        if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
71
 
            return (-1);
72
 
        R_cont_abs(l + (int)(xper * xincr), b - (int)(yper * yincr));
73
 
    }
74
 
 
75
 
    return (0);
76
 
}
77
 
 
78
 
int do_move(char *buff)
79
 
{
80
 
    float xper, yper;
81
 
 
82
 
    if (2 != sscanf(buff, "%*s %f %f", &xper, &yper)) {
83
 
        G_warning(_("Problem parsing coordinates [%s]"), buff);
84
 
        return (-1);
85
 
    }
86
 
 
87
 
    if (mapunits)
88
 
        R_move_abs((int)(D_u_to_d_col(xper) + 0.5),
89
 
                   (int)(D_u_to_d_row(yper) + 0.5));
90
 
    else {
91
 
        if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
92
 
            return (-1);
93
 
        R_move_abs(l + (int)(xper * xincr), b - (int)(yper * yincr));
94
 
    }
95
 
 
96
 
    return (0);
97
 
}
98
 
 
99
 
int do_color(char *buff)
 
53
        D_text_size(hsize * xincr, vsize * yincr);
 
54
        G_debug(3, "text size initialized to [%.1f,%.1f]",
 
55
                hsize * xincr, vsize * yincr);
 
56
    }
 
57
    return (0);
 
58
}
 
59
 
 
60
int do_draw(const char *str)
 
61
{
 
62
    float xper, yper;
 
63
 
 
64
    if (2 != sscanf(str, "%*s %f %f", &xper, &yper)) {
 
65
        G_warning(_("Problem parsing coordinates [%s]"), str);
 
66
        return (-1);
 
67
    }
 
68
 
 
69
    D_line_abs(cur_x, cur_y, xper, yper);
 
70
    cur_x = xper;
 
71
    cur_y = yper;
 
72
 
 
73
    return (0);
 
74
}
 
75
 
 
76
int do_move(const char *str)
 
77
{
 
78
    float xper, yper;
 
79
 
 
80
    if (2 != sscanf(str, "%*s %f %f", &xper, &yper)) {
 
81
        G_warning(_("Problem parsing coordinates [%s]"), str);
 
82
        return (-1);
 
83
    }
 
84
 
 
85
    D_pos_abs(xper, yper);
 
86
    cur_x = xper;
 
87
    cur_y = yper;
 
88
 
 
89
    return (0);
 
90
}
 
91
 
 
92
int do_color(const char *str)
100
93
{
101
94
    char in_color[64];
102
95
    int R, G, B, color = 0;
103
96
 
104
 
    if (1 != sscanf(buff, "%*s %s", in_color)) {
 
97
    if (1 != sscanf(str, "%*s %s", in_color)) {
105
98
        G_warning(_("Unable to read color"));
106
99
        return (-1);
107
100
    }
115
108
        return (-1);
116
109
    }
117
110
    if (color == 1) {
118
 
        R_RGB_color(R, G, B);
 
111
        D_RGB_color(R, G, B);
119
112
        /* store for backup */
120
113
        set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
121
114
    }
122
115
    if (color == 2) {           /* color == 'none' */
123
116
        R = D_translate_color(DEFAULT_BG_COLOR);
124
 
        R_standard_color(R);
 
117
        D_use_color(R);
125
118
        /* store for backup */
126
119
        set_last_color(0, 0, 0, RGBA_COLOR_NONE);
127
120
    }
128
121
    return (0);
129
122
}
130
123
 
131
 
int do_linewidth(char *buff)
 
124
int do_linewidth(const char *str)
132
125
{
133
 
    int width;                  /* in pixels */
 
126
    double width;
134
127
 
135
 
    if (1 != sscanf(buff, "%*s %d", &width)) {
136
 
        G_warning(_("Problem parsing command [%s]"), buff);
 
128
    if (1 != sscanf(str, "%*s %lf", &width)) {
 
129
        G_warning(_("Problem parsing command [%s]"), str);
137
130
        return (-1);
138
131
    }
139
132
 
140
133
    D_line_width(width);
141
 
    G_debug(3, "line width set to %d pixels", width);
 
134
    G_debug(3, "line width set to %.1f", width);
142
135
 
143
136
    return (0);
144
137
}
149
142
    int num;
150
143
    char origcmd[64];
151
144
    float xper, yper;
152
 
    char *fgets();
153
145
    int to_return;
154
146
 
155
147
    sscanf(buff, "%s", origcmd);
172
164
            break;
173
165
        }
174
166
 
175
 
        if (!mapunits) {
176
 
            if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
177
 
                break;
178
 
        }
179
167
        check_alloc(num + 1);
180
168
 
181
 
        if (mapunits) {
182
 
            xarray[num] = (int)(D_u_to_d_col(xper) + 0.5);
183
 
            yarray[num] = (int)(D_u_to_d_row(yper) + 0.5);
184
 
        }
185
 
        else {
186
 
            xarray[num] = l + (int)(xper * xincr);
187
 
            yarray[num] = b - (int)(yper * yincr);
188
 
        }
 
169
        xarray[num] = xper;
 
170
        yarray[num] = yper;
189
171
 
190
172
        num++;
191
173
    }
194
176
        /* this check is here so you can use the "polyline" command 
195
177
           to make an unfilled polygon */
196
178
        if (!strcmp(origcmd, "polygon"))
197
 
            R_polygon_abs(xarray, yarray, num);
 
179
            D_polygon_abs(xarray, yarray, num);
198
180
        else
199
 
            R_polyline_abs(xarray, yarray, num);
 
181
            D_polyline_abs(xarray, yarray, num);
200
182
    }
201
183
 
202
184
    return (to_return);
203
185
}
204
186
 
205
 
int do_size(char *buff)
 
187
int do_size(const char *str)
206
188
{
207
189
    float xper, yper;
208
190
    int ret;
209
191
 
210
 
    ret = sscanf(buff, "%*s %f %f", &xper, &yper);
 
192
    ret = sscanf(str, "%*s %f %f", &xper, &yper);
211
193
 
212
194
    if (ret != 2 && ret != 1) {
213
 
        G_warning(_("Problem parsing command [%s]"), buff);
 
195
        G_warning(_("Problem parsing command [%s]"), str);
214
196
        return (-1);
215
197
    }
216
198
 
221
203
    if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
222
204
        return (-1);
223
205
 
224
 
    R_text_size((int)(xper * xincr), (int)(yper * yincr));
225
 
    G_debug(3, "text size set to [%d,%d] pixels",
226
 
            (int)(xper * xincr), (int)(yper * yincr));
 
206
    D_text_size(xper * xincr, yper * yincr);
 
207
    G_debug(3, "text size set to [%.1f,%.1f]",
 
208
            xper * xincr, yper * yincr);
227
209
 
228
210
    return (0);
229
211
}
230
212
 
231
 
int do_rotate(char *buff)
 
213
int do_rotate(const char *str)
232
214
{
233
 
    if (1 != sscanf(buff, "%*s %lf", &rotation)) {
234
 
        G_warning(_("Problem parsing command [%s]"), buff);
 
215
    if (1 != sscanf(str, "%*s %lf", &rotation)) {
 
216
        G_warning(_("Problem parsing command [%s]"), str);
235
217
        return (-1);
236
218
    }
237
219
 
238
 
    R_text_rotation((float)rotation);
 
220
    D_text_rotation(rotation);
239
221
    G_debug(3, "rotation set to %.1f degrees", rotation);
240
222
 
241
223
    return (0);
242
224
}
243
225
 
244
 
int do_text(char *buff)
 
226
int do_text(const char *str)
245
227
{
246
 
    char *ptr;
 
228
    const char *ptr = str;
247
229
 
248
 
    ptr = buff;
249
230
    /* skip to beginning of actual text */
250
 
    for (; *ptr != ' '; ptr++) ;
251
 
    for (; *ptr == ' '; ptr++) ;
252
 
    R_text(ptr);
 
231
    for (; *ptr != ' '; ptr++)
 
232
        ;
 
233
    for (; *ptr == ' '; ptr++)
 
234
        ;
 
235
    D_text(ptr);
253
236
 
254
237
    return 0;
255
238
}
262
245
        return 0;
263
246
 
264
247
    to_alloc = coors_allocated;
265
 
    while (num >= to_alloc)
266
 
        to_alloc += CHUNK;
 
248
    if (num >= to_alloc)
 
249
        to_alloc = num + CHUNK;
267
250
 
268
 
    if (coors_allocated == 0) {
269
 
        xarray = (int *)falloc(to_alloc, sizeof(int));
270
 
        yarray = (int *)falloc(to_alloc, sizeof(int));
271
 
    }
272
 
    else {
273
 
        xarray = (int *)frealloc((char *)xarray,
274
 
                                 to_alloc, sizeof(int), coors_allocated);
275
 
        yarray = (int *)frealloc((char *)yarray,
276
 
                                 to_alloc, sizeof(int), coors_allocated);
277
 
    }
 
251
    xarray = G_realloc(xarray, to_alloc * sizeof(double));
 
252
    yarray = G_realloc(yarray, to_alloc * sizeof(double));
278
253
 
279
254
    coors_allocated = to_alloc;
280
255
 
281
256
    return 0;
282
257
}
283
258
 
284
 
int do_icon(char *buff)
 
259
int do_icon(const char *str)
285
260
{
286
261
    double xper, yper;
287
262
    char type;
288
 
    int size;
289
 
    int ix, iy;
 
263
    double size;
 
264
    double ix, iy;
290
265
 
291
 
    if (4 != sscanf(buff, "%*s %c %d %lf %lf", &type, &size, &xper, &yper)) {
292
 
        G_warning(_("Problem parsing command [%s]"), buff);
 
266
    if (4 != sscanf(str, "%*s %c %lf %lf %lf", &type, &size, &xper, &yper)) {
 
267
        G_warning(_("Problem parsing command [%s]"), str);
293
268
        return (-1);
294
269
    }
295
270
 
296
 
    if (mapunits) {
297
 
        ix = (int)(D_u_to_d_col(xper) + 0.5);
298
 
        iy = (int)(D_u_to_d_row(yper) + 0.5);
299
 
        /* size in map units too? currently in percentage.
300
 
           use "size * D_get_u_to_d_yconv()" to convert? */
301
 
    }
302
 
    else {
303
 
        if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
304
 
            return (-1);
305
 
 
306
 
        ix = l + (int)(xper * xincr);
307
 
        iy = b - (int)(yper * yincr);
308
 
    }
309
 
 
310
 
    switch (type & 0177) {
 
271
    ix = xper;
 
272
    iy = yper;
 
273
    size *= yincr;
 
274
 
 
275
    D_begin();
 
276
 
 
277
    switch (type & 0x7F) {
311
278
    case 'o':
312
 
        R_move_abs(ix - size, iy - size);
313
 
        R_cont_abs(ix - size, iy + size);
314
 
        R_cont_abs(ix + size, iy + size);
315
 
        R_cont_abs(ix + size, iy - size);
316
 
        R_cont_abs(ix - size, iy - size);
 
279
        D_move_abs(ix - size, iy - size);
 
280
        D_cont_abs(ix - size, iy + size);
 
281
        D_cont_abs(ix + size, iy + size);
 
282
        D_cont_abs(ix + size, iy - size);
 
283
        D_cont_abs(ix - size, iy - size);
317
284
        break;
318
285
    case 'x':
319
 
        R_move_abs(ix - size, iy - size);
320
 
        R_cont_abs(ix + size, iy + size);
321
 
        R_move_abs(ix - size, iy + size);
322
 
        R_cont_abs(ix + size, iy - size);
 
286
        D_move_abs(ix - size, iy - size);
 
287
        D_cont_abs(ix + size, iy + size);
 
288
        D_move_abs(ix - size, iy + size);
 
289
        D_cont_abs(ix + size, iy - size);
323
290
        break;
324
291
    case '+':
325
292
    default:
326
 
        R_move_abs(ix, iy - size);
327
 
        R_cont_abs(ix, iy + size);
328
 
        R_move_abs(ix - size, iy);
329
 
        R_cont_abs(ix + size, iy);
 
293
        D_move_abs(ix, iy - size);
 
294
        D_cont_abs(ix, iy + size);
 
295
        D_move_abs(ix - size, iy);
 
296
        D_cont_abs(ix + size, iy);
330
297
        break;
331
298
    }
 
299
 
 
300
    D_end();
 
301
    D_stroke();
 
302
 
332
303
    return (0);
333
304
}
334
305
 
335
 
int do_symbol(char *buff)
 
306
int do_symbol(const char *str)
336
307
{
337
308
    double xper, yper;
338
 
    int size;
339
 
    int ix, iy;
 
309
    double size;
 
310
    double ix, iy;
340
311
    char *symb_name;
341
312
    SYMBOL *Symb;
342
313
    char *line_color_str, *fill_color_str;
347
318
    line_color = G_malloc(sizeof(RGBA_Color));
348
319
    fill_color = G_malloc(sizeof(RGBA_Color));
349
320
 
350
 
    symb_name = G_malloc(sizeof(char) * strlen(buff) + 1);      /* well, it won't be any bigger than this */
351
 
    line_color_str = G_malloc(sizeof(char) * strlen(buff) + 1);
352
 
    fill_color_str = G_malloc(sizeof(char) * strlen(buff) + 1);
 
321
    symb_name = G_malloc(strlen(str) + 1);      /* well, it won't be any bigger than this */
 
322
    line_color_str = G_malloc(strlen(str) + 1);
 
323
    fill_color_str = G_malloc(strlen(str) + 1);
353
324
 
354
 
    G_debug(3, "do_symbol() [%s]", buff);
 
325
    G_debug(3, "do_symbol() [%s]", str);
355
326
 
356
327
    /* set default colors so colors are optional */
357
328
    strcpy(line_color_str, DEFAULT_FG_COLOR);
358
329
    strcpy(fill_color_str, "grey");
359
330
 
360
331
    if (sscanf
361
 
        (buff, "%*s %s %d %lf %lf %s %s", symb_name, &size, &xper, &yper,
 
332
        (str, "%*s %s %lf %lf %lf %s %s", symb_name, &size, &xper, &yper,
362
333
         line_color_str, fill_color_str) < 4) {
363
 
        G_warning(_("Problem parsing command [%s]"), buff);
 
334
        G_warning(_("Problem parsing command [%s]"), str);
364
335
        return (-1);
365
336
    }
366
337
 
367
 
    if (mapunits) {
368
 
        ix = (int)(D_u_to_d_col(xper) + 0.5);
369
 
        iy = (int)(D_u_to_d_row(yper) + 0.5);
370
 
        /* consider size in map units too? maybe as percentage of display?
371
 
           perhaps use "size * D_get_u_to_d_yconv()" to convert */
372
 
    }
373
 
    else {
374
 
        if (xper < 0. || yper < 0. || xper > 100. || yper > 100.)
375
 
            return (-1);
376
 
        ix = l + (int)(xper * xincr);
377
 
        iy = b - (int)(yper * yincr);
378
 
    }
 
338
    ix = xper;
 
339
    iy = yper;
 
340
    size *= yincr;
379
341
 
380
342
    /* parse line color */
381
343
    ret = G_str_to_color(line_color_str, &R, &G, &B);
422
384
 
423
385
    /* restore previous d.graph draw color */
424
386
    if (last_color.a == RGBA_COLOR_OPAQUE)
425
 
        R_RGB_color(last_color.r, last_color.g, last_color.b);
 
387
        D_RGB_color(last_color.r, last_color.g, last_color.b);
426
388
    else if (last_color.a == RGBA_COLOR_NONE)
427
 
        D_raster_use_color(D_parse_color(DEFAULT_BG_COLOR, 0));
 
389
        D_use_color(D_parse_color(DEFAULT_BG_COLOR, 0));
428
390
    else                        /* unset or bad */
429
 
        R_RGB_color(line_color->r, line_color->g, line_color->b);
 
391
        D_RGB_color(line_color->r, line_color->g, line_color->b);
430
392
 
431
393
    G_free(symb_name);
432
394
    G_free(line_color_str);