~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to display/d.vect/plot1.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
128
128
/* *************************************************************** */
129
129
int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
130
130
          const struct color_rgb *color, const struct color_rgb *fcolor,
131
 
          int chcat, SYMBOL * Symb, int size, int id_flag,
132
 
          int table_colors_flag, int cats_color_flag, char *rgb_column,
133
 
          int default_width, char *width_column, double width_scale,
134
 
          int z_color_flag, char *style)
 
131
          int chcat, char *symbol_name, double size, char *size_column,
 
132
          char *rot_column, int id_flag, int table_colors_flag,
 
133
          int cats_color_flag, char *rgb_column, int default_width,
 
134
          char *width_column, double width_scale, int z_color_flag,
 
135
          char *style)
135
136
{
136
137
    int i, ltype, nlines = 0, line, cat = -1;
137
138
    double *x, *y;
142
143
 
143
144
    struct field_info *fi = NULL;
144
145
    dbDriver *driver = NULL;
145
 
    dbCatValArray cvarr_rgb, cvarr_width;
146
 
    dbCatVal *cv_rgb = NULL, *cv_width = NULL;
147
 
    int nrec_rgb = 0, nrec_width = 0;
 
146
    dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
 
147
    dbCatVal *cv_rgb = NULL, *cv_width = NULL, *cv_size = NULL, *cv_rot = NULL;
 
148
    int nrec_rgb = 0, nrec_width = 0, nrec_size = 0, nrec_rot = 0;
148
149
    int nerror_rgb;
149
150
    
150
151
    int open_db;
154
155
    RGBA_Color *line_color, *fill_color, *primary_color;
155
156
    unsigned char which;
156
157
    int width;
 
158
    SYMBOL *Symb = NULL;
 
159
    double var_size, rotation;
157
160
 
 
161
    var_size = size;
 
162
    rotation = 0.0;
158
163
    nerror_rgb = 0;
159
 
    
 
164
 
160
165
    line_color = G_malloc(sizeof(RGBA_Color));
161
166
    fill_color = G_malloc(sizeof(RGBA_Color));
162
167
    primary_color = G_malloc(sizeof(RGBA_Color));
189
194
    PPoints = Vect_new_line_struct();
190
195
    Cats = Vect_new_cats_struct();
191
196
 
192
 
    open_db = table_colors_flag || width_column;
 
197
    open_db = table_colors_flag || width_column || size_column || rot_column;
193
198
 
194
199
    if (open_db) {
195
200
        fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1));
247
252
 
248
253
        if (cvarr_width.ctype != DB_C_TYPE_INT &&
249
254
            cvarr_width.ctype != DB_C_TYPE_DOUBLE)
250
 
            G_fatal_error(_("Line width column (%s) not a number."),
 
255
            G_fatal_error(_("Line width column (%s) is not numeric."),
251
256
                          width_column);
252
257
 
253
258
        if (nrec_width < 0)
254
259
            G_fatal_error(_("Cannot select data (%s) from table"),
255
260
                          width_column);
256
261
 
257
 
        G_debug(2, "\n%d records selected from table", nrec_width);
 
262
        G_debug(2, " %d records selected from table", nrec_width);
258
263
 
259
264
        for (i = 0; i < cvarr_width.n_values; i++) {
260
 
            G_debug(4, "cat = %d  %s = %d", cvarr_width.value[i].cat,
 
265
            G_debug(4, "(width) cat = %d  %s = %d", cvarr_width.value[i].cat,
261
266
                    width_column,
262
267
                    (cvarr_width.ctype ==
263
268
                     DB_C_TYPE_INT ? cvarr_width.value[i].val.
265
270
        }
266
271
    }
267
272
 
 
273
    if (size_column) {
 
274
        if (*size_column == '\0')
 
275
            G_fatal_error(_("Symbol size column not specified."));
 
276
 
 
277
        db_CatValArray_init(&cvarr_size);
 
278
 
 
279
        nrec_size = db_select_CatValArray(driver, fi->table, fi->key,
 
280
                                           size_column, NULL, &cvarr_size);
 
281
 
 
282
        G_debug(3, "nrec_size (%s) = %d", size_column, nrec_size);
 
283
 
 
284
        if (cvarr_size.ctype != DB_C_TYPE_INT &&
 
285
            cvarr_size.ctype != DB_C_TYPE_DOUBLE)
 
286
            G_fatal_error(_("Symbol size column (%s) is not numeric."),
 
287
                          size_column);
 
288
 
 
289
        if (nrec_size < 0)
 
290
            G_fatal_error(_("Cannot select data (%s) from table"),
 
291
                          size_column);
 
292
 
 
293
        G_debug(2, " %d records selected from table", nrec_size);
 
294
 
 
295
        for (i = 0; i < cvarr_size.n_values; i++) {
 
296
            G_debug(4, "(size) cat = %d  %s = %d", cvarr_size.value[i].cat,
 
297
                    size_column,
 
298
                    (cvarr_size.ctype ==
 
299
                     DB_C_TYPE_INT ? cvarr_size.value[i].val.
 
300
                     i : (int)cvarr_size.value[i].val.d));
 
301
        }
 
302
    }
 
303
 
 
304
    if (rot_column) {
 
305
        if (*rot_column == '\0')
 
306
            G_fatal_error(_("Symbol rotation column not specified."));
 
307
 
 
308
        db_CatValArray_init(&cvarr_rot);
 
309
 
 
310
        nrec_rot = db_select_CatValArray(driver, fi->table, fi->key,
 
311
                                           rot_column, NULL, &cvarr_rot);
 
312
 
 
313
        G_debug(3, "nrec_rot (%s) = %d", rot_column, nrec_rot);
 
314
 
 
315
        if (cvarr_rot.ctype != DB_C_TYPE_INT &&
 
316
            cvarr_rot.ctype != DB_C_TYPE_DOUBLE)
 
317
            G_fatal_error(_("Symbol rotation column (%s) is not numeric."),
 
318
                          rot_column);
 
319
 
 
320
        if (nrec_rot < 0)
 
321
            G_fatal_error(_("Cannot select data (%s) from table"),
 
322
                          rot_column);
 
323
 
 
324
        G_debug(2, " %d records selected from table", nrec_rot);
 
325
 
 
326
        for (i = 0; i < cvarr_rot.n_values; i++) {
 
327
            G_debug(4, "(rot) cat = %d  %s = %d", cvarr_rot.value[i].cat,
 
328
                    rot_column,
 
329
                    (cvarr_rot.ctype ==
 
330
                     DB_C_TYPE_INT ? cvarr_rot.value[i].val.
 
331
                     i : (int)cvarr_rot.value[i].val.d));
 
332
        }
 
333
    }
 
334
 
 
335
    if( !(nrec_size || nrec_rot) ) {
 
336
        Symb = S_read(symbol_name);
 
337
        if (Symb == NULL)
 
338
            G_warning(_("Unable to read symbol, unable to display points"));
 
339
        else
 
340
            S_stroke(Symb, (int)(size + 0.5), 0.0, 0);
 
341
    }
 
342
 
268
343
    if (open_db)
269
344
        db_close_database_shutdown_driver(driver);
270
345
 
444
519
                         (Clist->field > 0 ? Clist->field :
445
520
                          (Cats->n_cats >
446
521
                           0 ? Cats->field[0] : 1)), &cat);
447
 
            
 
522
 
448
523
            if (cat >= 0) {
449
524
                G_debug(3, "display element %d, cat %d", line, cat);
450
525
 
451
526
                /* Read line width from db for current area # */
452
 
 
453
527
                if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) !=
454
528
                    DB_OK) {
455
529
                    width = default_width;
466
540
                        width = default_width;
467
541
                    }
468
542
                }
469
 
            }                   /* end if cat */
 
543
            }           /* end if cat */
470
544
            else {
471
545
                width = default_width;
472
546
            }
473
547
 
474
548
            D_line_width(width);
475
 
        }                       /* end if nrec_width */
 
549
        }               /* end if nrec_width */
476
550
 
477
551
 
478
552
        /* enough of the prep work, lets start plotting stuff */
479
553
        x = Points->x;
480
554
        y = Points->y;
481
555
 
482
 
        if ((ltype & GV_POINTS) && Symb != NULL) {
 
556
        if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
483
557
            if (!(color || fcolor || custom_rgb))
484
558
                continue;
485
559
 
492
566
                y0 > D_get_d_south() || y0 < D_get_d_north())
493
567
                continue;
494
568
 
 
569
            /* dynamic symbol size */
 
570
            if (nrec_size) {
 
571
                /* only first category */
 
572
                Vect_cat_get(Cats,
 
573
                             (Clist->field > 0 ? Clist->field :
 
574
                              (Cats->n_cats > 0 ?
 
575
                               Cats->field[0] : 1)), &cat);
 
576
 
 
577
                if (cat >= 0) {
 
578
                    G_debug(3, "display element %d, cat %d", line, cat);
 
579
 
 
580
                    /* Read symbol size from db for current symbol # */
 
581
                    if (db_CatValArray_get_value(&cvarr_size, cat, &cv_size) !=
 
582
                        DB_OK) {
 
583
                        var_size = size;
 
584
                    }
 
585
                    else {
 
586
                        var_size = size *
 
587
                            (cvarr_size.ctype == DB_C_TYPE_INT ?
 
588
                             (double)cv_size->val.i : cv_size->val.d);
 
589
 
 
590
                        if (var_size < 0.0) {
 
591
                            G_warning(_("Error in symbol size column (%s), element %d "
 
592
                                        "with cat %d: symbol size [%f]"),
 
593
                                      size_column, line, cat, var_size);
 
594
                            var_size = size;
 
595
                        }
 
596
                    }
 
597
                }               /* end if cat */
 
598
                else {
 
599
                    var_size = size;
 
600
                }
 
601
            }           /* end if nrec_size */
 
602
 
 
603
            /* dynamic symbol rotation */
 
604
            if (nrec_rot) {
 
605
                /* only first category */
 
606
                Vect_cat_get(Cats,
 
607
                             (Clist->field > 0 ? Clist->field :
 
608
                              (Cats->n_cats > 0 ?
 
609
                               Cats->field[0] : 1)), &cat);
 
610
 
 
611
                if (cat >= 0) {
 
612
                    G_debug(3, "display element %d, cat %d", line, cat);
 
613
 
 
614
                    /* Read symbol rotation from db for current symbol # */
 
615
                    if (db_CatValArray_get_value(&cvarr_rot, cat, &cv_rot) !=
 
616
                        DB_OK) {
 
617
                        rotation = 0.0;
 
618
                    }
 
619
                    else {
 
620
                        rotation =
 
621
                            (cvarr_rot.ctype == DB_C_TYPE_INT ?
 
622
                             (double)cv_rot->val.i : cv_rot->val.d);
 
623
                    }
 
624
                }               /* end if cat */
 
625
                else {
 
626
                    rotation = 0.0;
 
627
                }
 
628
            }           /* end if nrec_rot */
 
629
 
 
630
            if(nrec_size || nrec_rot) {
 
631
                G_debug(3, ". dynamic symbol: cat=%d  size=%d  rotation=%.2f",
 
632
                        cat, (int)(var_size + 0.5), rotation);
 
633
 
 
634
                /* symbol stroking is cumulative, so we need to reread it each time */
 
635
                if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
 
636
                    G_free(Symb);
 
637
                Symb = S_read(symbol_name);
 
638
                if (Symb == NULL)
 
639
                    G_warning(_("Unable to read symbol, unable to display points"));
 
640
                else
 
641
                    S_stroke(Symb, (int)(var_size + 0.5), rotation, 0);
 
642
            }
 
643
 
495
644
            /* use random or RGB column color if given, otherwise reset */
496
645
            /* centroids always use default color to stand out from underlying area */
497
646
            if (custom_rgb && (ltype != GV_CENTROID)) {
503
652
            else
504
653
                D_symbol(Symb, x0, y0, line_color, fill_color);
505
654
 
506
 
 
 
655
            /* reset to defaults */
 
656
            var_size = size;
 
657
            rotation = 0.0;
507
658
        }
508
659
        else if (color || custom_rgb || (z_color_flag && Vect_is_3d(Map))) {
509
660
            if (!table_colors_flag && !cats_color_flag && !z_color_flag)