[GRASS-SVN] r47485 - grass/trunk/display/d.vect
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Aug 7 14:16:57 EDT 2011
Author: martinl
Date: 2011-08-07 11:16:56 -0700 (Sun, 07 Aug 2011)
New Revision: 47485
Added:
grass/trunk/display/d.vect/lines.c
grass/trunk/display/d.vect/opt.c
grass/trunk/display/d.vect/shape.c
Removed:
grass/trunk/display/d.vect/plot1.c
grass/trunk/display/d.vect/utils.c
Modified:
grass/trunk/display/d.vect/area.c
grass/trunk/display/d.vect/attr.c
grass/trunk/display/d.vect/dir.c
grass/trunk/display/d.vect/label.c
grass/trunk/display/d.vect/local_proto.h
grass/trunk/display/d.vect/main.c
grass/trunk/display/d.vect/plot.h
grass/trunk/display/d.vect/topo.c
grass/trunk/display/d.vect/zcoor.c
Log:
d.vect: major code reorganization
Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/area.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -8,39 +8,44 @@
#include <grass/vector.h>
#include <grass/display.h>
#include <grass/colors.h>
-#include <grass/dbmi.h>
+
#include <grass/glocale.h>
#include "plot.h"
#include "local_proto.h"
-int darea(struct Map_info *Map, struct cat_list *Clist,
- const struct color_rgb *bcolor, const struct color_rgb *fcolor,
- int chcat, int id_flag, int table_colors_flag, int cats_color_flag,
- struct Cell_head *window, char *rgb_column, int default_width,
- char *width_column, double width_scale, int z_color_flag,
- char *style)
+int display_area(struct Map_info *Map, struct cat_list *Clist, const struct Cell_head *window,
+ const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat, int id_flag,
+ int table_colors_flag, int cats_color_flag, const char *rgb_column,
+ int default_width, const char *width_column, double width_scale,
+ int z_color_flag, const char *z_column,
+ dbCatValArray *cvarr_rgb, dbCatValArray *cvarr_width, int nrec_width)
{
-
int num, area, isle, n_isles, n_points;
double xl, yl;
struct line_pnts *Points, * APoints, **IPoints;
struct line_cats *Cats;
int n_ipoints_alloc;
- int cat, centroid = 0;
+ int cat, centroid;
int red, grn, blu;
- struct field_info *fi = NULL;
- dbDriver *driver = NULL;
- dbCatValArray cvarr_rgb, cvarr_width;
- dbCatVal *cv_rgb = NULL, *cv_width = NULL;
- int nrec_rgb = 0, nrec_width = 0;
+ dbCatVal *cv_rgb, *cv_width;
- int open_db;
- int i, rgb = 0; /* 0|1 */
+ int i, rgb;
char colorstring[12]; /* RRR:GGG:BBB */
unsigned char which;
int width;
+ centroid = 0;
+ cv_rgb = cv_width = NULL;
+ rgb = 0;
+
+ if (Vect_level(Map) < 2) {
+ G_warning(_("Unable to display areas, topology not available. "
+ "Please try to rebuild topology using "
+ "v.build or v.build.all."));
+ return 1;
+ }
+
G_debug(1, "display areas:");
Points = Vect_new_line_struct();
APoints = Vect_new_line_struct();
@@ -50,89 +55,7 @@
IPoints[i] = Vect_new_line_struct();
}
Cats = Vect_new_cats_struct();
-
- open_db = table_colors_flag || width_column;
-
- if (open_db) {
-
- fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1));
- if (fi == NULL) {
- G_fatal_error(_("Database connection not defined for layer %d"),
- (Clist->field > 0 ? Clist->field : 1));
- }
-
- driver = db_start_driver_open_database(fi->driver, fi->database);
- if (driver == NULL)
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
- fi->database, fi->driver);
-
- }
-
- if (table_colors_flag) {
- /* for reading RRR:GGG:BBB color strings from table */
-
- if (rgb_column == NULL || *rgb_column == '\0')
- G_fatal_error(_("Color definition column not specified."));
-
- db_CatValArray_init(&cvarr_rgb);
-
- nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
- rgb_column, NULL, &cvarr_rgb);
-
- G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
-
- if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
- G_fatal_error(_("Color definition column (%s) not a string. "
- "Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
- rgb_column);
-
-
- if (nrec_rgb < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- rgb_column);
-
- G_debug(2, "\n%d records selected from table", nrec_rgb);
-
- for (i = 0; i < cvarr_rgb.n_values; i++) {
- G_debug(4, "cat = %d %s = %s", cvarr_rgb.value[i].cat,
- rgb_column, db_get_string(cvarr_rgb.value[i].val.s));
- }
- }
-
- if (width_column) {
- if (*width_column == '\0')
- G_fatal_error(_("Line width column not specified."));
-
- db_CatValArray_init(&cvarr_width);
-
- nrec_width = db_select_CatValArray(driver, fi->table, fi->key,
- width_column, NULL, &cvarr_width);
-
- G_debug(3, "nrec_width (%s) = %d", width_column, nrec_width);
-
- if (cvarr_width.ctype != DB_C_TYPE_INT &&
- cvarr_width.ctype != DB_C_TYPE_DOUBLE)
- G_fatal_error(_("Line width column (%s) not a number."),
- width_column);
-
- if (nrec_width < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- width_column);
-
- G_debug(2, "\n%d records selected from table", nrec_width);
-
- for (i = 0; i < cvarr_width.n_values; i++) {
- G_debug(4, "cat = %d %s = %d", cvarr_width.value[i].cat,
- width_column,
- (cvarr_width.ctype ==
- DB_C_TYPE_INT ? cvarr_width.value[i].val.
- i : (int)cvarr_width.value[i].val.d));
- }
- }
-
- if (open_db)
- db_close_database_shutdown_driver(driver);
-
+
num = Vect_get_num_areas(Map);
G_debug(2, "n_areas = %d", num);
@@ -152,7 +75,7 @@
if (window->proj != PROJECTION_LL)
continue;
- else { /* out of bounds for -180 to 180, try 0 to 360 as well */
+ else { /* out of bounds for -180 to 180, try 0 to 360 as well */
if (box.N < window->south || box.S > window->north)
continue;
if (box.E + 360 < window->west || box.W + 360 > window->east)
@@ -160,14 +83,16 @@
}
}
- if (chcat) { /* check category: where_opt or cat_opt used */
+ /* check category: where_opt or cat_opt used */
+ if (chcat) {
if (id_flag) {
if (!(Vect_cat_in_cat_list(area, Clist)))
continue;
}
else {
- int found = 0;
-
+ int found;
+
+ found = FALSE;
centroid = Vect_get_area_centroid(Map, area);
G_debug(3, "centroid = %d", centroid);
if (centroid < 1)
@@ -180,17 +105,19 @@
if (Cats->field[i] == Clist->field &&
Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
- found = 1;
+ found = TRUE;
break;
}
}
+
if (!found)
continue;
} /* end else */
} /* end if id_flag */
else if (Clist->field > 0) {
- int found = 0;
+ int found;
+ found = FALSE;
centroid = Vect_get_area_centroid(Map, area);
G_debug(3, "centroid = %d", centroid);
if (centroid < 1)
@@ -201,10 +128,11 @@
G_debug(3, " centroid = %d, field = %d, cat = %d", centroid,
Cats->field[i], Cats->cat[i]);
if (Cats->field[i] == Clist->field) {
- found = 1;
+ found = TRUE;
break;
}
}
+
/* lines with no category will be displayed */
if (Cats->n_cats > 0 && !found)
continue;
@@ -257,12 +185,11 @@
area, centroid, cat, Points->x[0], Points->y[0],
Points->z[0]);
rgb = 1;
- Rast_make_fp_colors(&colors, style, box.B, box.T);
+ Rast_make_fp_colors(&colors, z_column, box.B, box.T);
Rast_get_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
G_debug(3, "b %d, g: %d, r %d", blu, grn, red);
}
-
if (table_colors_flag) {
centroid = Vect_get_area_centroid(Map, area);
if (cat >= 0) {
@@ -270,7 +197,7 @@
centroid, cat);
/* Read RGB colors from db for current area # */
- if (db_CatValArray_get_value(&cvarr_rgb, cat, &cv_rgb) !=
+ if (db_CatValArray_get_value(cvarr_rgb, cat, &cv_rgb) !=
DB_OK) {
rgb = 0;
}
@@ -347,13 +274,13 @@
centroid, cat);
/* Read line width from db for current area # */
- if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) !=
+ if (db_CatValArray_get_value(cvarr_width, cat, &cv_width) !=
DB_OK) {
width = default_width;
}
else {
width =
- width_scale * (cvarr_width.ctype ==
+ width_scale * (cvarr_width->ctype ==
DB_C_TYPE_INT ? cv_width->val.
i : (int)cv_width->val.d);
if (width < 0) {
Modified: grass/trunk/display/d.vect/attr.c
===================================================================
--- grass/trunk/display/d.vect/attr.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/attr.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -7,8 +7,8 @@
#include "local_proto.h"
#include "plot.h"
-int attr(struct Map_info *Map, int type, char *attrcol,
- struct cat_list *Clist, LATTR *lattr, int chcat)
+int display_attr(struct Map_info *Map, int type, char *attrcol,
+ struct cat_list *Clist, LATTR *lattr, int chcat)
{
int i, ltype, more;
struct line_pnts *Points;
@@ -49,7 +49,7 @@
ltype = Vect_read_next_line(Map, Points, Cats);
switch (ltype) {
case -1:
- G_fatal_error(_("Can't read vector map"));
+ G_fatal_error(_("Unable to read vector map"));
case -2: /* EOF */
return 0;
}
Modified: grass/trunk/display/d.vect/dir.c
===================================================================
--- grass/trunk/display/d.vect/dir.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/dir.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -4,7 +4,7 @@
#include <grass/glocale.h>
#include "plot.h"
-int dir(struct Map_info *Map, int type, struct cat_list *Clist, int chcat)
+int display_dir(struct Map_info *Map, int type, struct cat_list *Clist, int chcat)
{
int ltype, dsize;
double len, x, y, angle, msize;
@@ -24,7 +24,7 @@
ltype = Vect_read_next_line(Map, Points, Cats);
switch (ltype) {
case -1:
- G_fatal_error(_("Can't read vector map"));
+ G_fatal_error(_("Unable to read vector map"));
case -2: /* EOF */
return 0;
}
Modified: grass/trunk/display/d.vect/label.c
===================================================================
--- grass/trunk/display/d.vect/label.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/label.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -5,8 +5,8 @@
#include "local_proto.h"
#include "plot.h"
-int label(struct Map_info *Map, int type, int do_area,
- struct cat_list *Clist, LATTR *lattr, int chcat)
+int display_label(struct Map_info *Map, int type, int do_area,
+ struct cat_list *Clist, LATTR *lattr, int chcat)
{
int i, ltype;
struct line_pnts *Points;
@@ -23,7 +23,7 @@
ltype = Vect_read_next_line(Map, Points, Cats);
switch (ltype) {
case -1:
- G_fatal_error(_("Can't read vector map"));
+ G_fatal_error(_("Unable to read vector map"));
case -2: /* EOF */
return 0;
}
@@ -86,3 +86,80 @@
return 0;
}
+
+void show_label(double *px, double *py, LATTR *lattr, const char *text)
+{
+ double X = *px, Y = *py;
+ int Xoffset, Yoffset;
+ double xarr[5], yarr[5];
+ double T, B, L, R;
+
+ X = X + D_get_d_to_u_xconv() * 0.5 * lattr->size;
+ Y = Y + D_get_d_to_u_yconv() * 1.5 * lattr->size;
+
+ D_pos_abs(X, Y);
+ D_get_text_box(text, &T, &B, &L, &R);
+
+ /* Expand border 1/2 of text size */
+ T = T - D_get_d_to_u_yconv() * lattr->size / 2;
+ B = B + D_get_d_to_u_yconv() * lattr->size / 2;
+ L = L - D_get_d_to_u_xconv() * lattr->size / 2;
+ R = R + D_get_d_to_u_xconv() * lattr->size / 2;
+
+ Xoffset = 0;
+ Yoffset = 0;
+ if (lattr->xref == LCENTER)
+ Xoffset = -(R - L) / 2;
+ if (lattr->xref == LRIGHT)
+ Xoffset = -(R - L);
+ if (lattr->yref == LCENTER)
+ Yoffset = -(B - T) / 2;
+ if (lattr->yref == LBOTTOM)
+ Yoffset = -(B - T);
+
+ if (lattr->has_bgcolor || lattr->has_bcolor) {
+ xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
+ xarr[2] = xarr[3] = R + Xoffset;
+ yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
+ yarr[1] = yarr[2] = T + Yoffset;
+
+ if (lattr->has_bgcolor) {
+ D_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
+ lattr->bgcolor.B);
+ D_polygon_abs(xarr, yarr, 5);
+ }
+
+ if (lattr->has_bcolor) {
+ D_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
+ lattr->bcolor.B);
+ D_polyline_abs(xarr, yarr, 5);
+ }
+ D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
+ }
+
+ D_pos_abs(X + Xoffset, Y + Yoffset);
+ D_text(text);
+}
+
+void show_label_line(const struct line_pnts *Points, int ltype, LATTR *lattr, const char *text)
+{
+ double X, Y;
+
+ if ((ltype & GV_POINTS) || Points->n_points == 1)
+ /* point/centroid or line/boundary with one coor */
+ {
+ X = Points->x[0];
+ Y = Points->y[0];
+ }
+ else if (Points->n_points == 2) { /* line with two coors */
+ X = (Points->x[0] + Points->x[1]) / 2;
+ Y = (Points->y[0] + Points->y[1]) / 2;
+ }
+ else {
+ int i = Points->n_points / 2;
+ X = Points->x[i];
+ Y = Points->y[i];
+ }
+
+ show_label(&X, &Y, lattr, text);
+}
Copied: grass/trunk/display/d.vect/lines.c (from rev 47480, grass/trunk/display/d.vect/plot1.c)
===================================================================
--- grass/trunk/display/d.vect/lines.c (rev 0)
+++ grass/trunk/display/d.vect/lines.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -0,0 +1,502 @@
+/* plot1() - Level One vector reading */
+
+#include <string.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/vector.h>
+#include <grass/display.h>
+#include "plot.h"
+#include "local_proto.h"
+#include <grass/symbol.h>
+#include <grass/glocale.h>
+#include <grass/dbmi.h>
+
+#define RENDER_POLYLINE 0
+#define RENDER_POLYGON 1
+
+int palette_ncolors = 16;
+
+struct rgb_color palette[16] = {
+ {198, 198, 198}, /* 1: light gray */
+ {127, 127, 127}, /* 2: medium/dark gray */
+ {255, 0, 0}, /* 3: bright red */
+ {139, 0, 0}, /* 4: dark red */
+ {0, 255, 0}, /* 5: bright green */
+ {0, 139, 0}, /* 6: dark green */
+ {0, 0, 255}, /* 7: bright blue */
+ {0, 0, 139}, /* 8: dark blue */
+ {255, 255, 0}, /* 9: yellow */
+ {139, 126, 10}, /* 10: olivey brown */
+ {255, 165, 0}, /* 11: orange */
+ {255, 192, 203}, /* 12: pink */
+ {255, 0, 255}, /* 13: magenta */
+ {139, 0, 139}, /* 14: dark magenta */
+ {0, 255, 255}, /* 15: cyan */
+ {0, 139, 139} /* 16: dark cyan */
+};
+
+int display_lines(struct Map_info *Map, int type, struct cat_list *Clist,
+ const struct color_rgb *color, const struct color_rgb *fcolor, int chcat,
+ const char *symbol_name, double size, const char *size_column, int sqrt_flag, const char *rot_column,
+ int id_flag, int table_colors_flag, int cats_color_flag, const char *rgb_column,
+ int default_width, const char *width_column, double width_scale,
+ int z_color_flag, const char *z_column,
+ dbCatValArray *cvarr_rgb, dbCatValArray *cvarr_width, int nrec_width,
+ dbCatValArray *cvarr_size, int nrec_size,
+ dbCatValArray *cvarr_rot, int nrec_rot)
+
+{
+ int i, ltype, nlines, line, cat;
+ double *x, *y;
+ struct line_pnts *Points;
+ struct line_cats *Cats;
+ double x0, y0;
+
+ dbCatVal *cv_rgb, *cv_width, *cv_size, *cv_rot;
+ int nerror_rgb;
+ int n_points, n_lines, n_centroids, n_boundaries, n_faces;
+
+ int custom_rgb;
+ char colorstring[12]; /* RRR:GGG:BBB */
+ int red, grn, blu;
+ RGBA_Color *line_color, *fill_color, *primary_color;
+ unsigned char which;
+ int width;
+ SYMBOL *Symb;
+ double var_size, rotation;
+
+ Symb = NULL;
+ custom_rgb = FALSE;
+ cv_rgb = cv_width = cv_size = cv_rot = NULL;
+ cat = -1;
+ nlines = 0;
+
+ if (id_flag && Vect_level(Map) < 2) {
+ G_warning(_("Unable to display lines by id, topology not available. "
+ "Please try to rebuild topology using "
+ "v.build or v.build.all."));
+ return 1;
+ }
+
+ var_size = size;
+ rotation = 0.0;
+ nerror_rgb = 0;
+
+ line_color = G_malloc(sizeof(RGBA_Color));
+ fill_color = G_malloc(sizeof(RGBA_Color));
+ primary_color = G_malloc(sizeof(RGBA_Color));
+ primary_color->a = RGBA_COLOR_OPAQUE;
+
+ /* change function prototype to pass RGBA_Color instead of color_rgb? */
+ if (color) {
+ line_color->r = color->r;
+ line_color->g = color->g;
+ line_color->b = color->b;
+ line_color->a = RGBA_COLOR_OPAQUE;
+ }
+ else
+ line_color->a = RGBA_COLOR_NONE;
+
+ if (fcolor) {
+ fill_color->r = fcolor->r;
+ fill_color->g = fcolor->g;
+ fill_color->b = fcolor->b;
+ fill_color->a = RGBA_COLOR_OPAQUE;
+ }
+ else
+ fill_color->a = RGBA_COLOR_NONE;
+
+ Points = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+
+ if (!(nrec_size || nrec_rot) ) {
+ Symb = S_read(symbol_name);
+ if (!Symb)
+ G_warning(_("Unable to read symbol, unable to display points"));
+ else
+ S_stroke(Symb, size, 0.0, 0);
+ }
+
+ Vect_rewind(Map);
+
+ /* Is it necessary to reset line/label color in each loop ? */
+
+ if (color && !table_colors_flag && !cats_color_flag)
+ D_RGB_color(color->r, color->g, color->b);
+
+ if (Vect_level(Map) >= 2)
+ nlines = Vect_get_num_lines(Map);
+
+ line = 0;
+ n_points = n_lines = 0;
+ n_centroids = n_boundaries = 0;
+ n_faces = 0;
+ while (1) {
+ line++;
+ if (Vect_level(Map) >= 2) {
+ if (line > nlines)
+ break;
+ if (!Vect_line_alive(Map, line))
+ continue;
+ ltype = Vect_read_line(Map, Points, Cats, line);
+ }
+ else {
+ ltype = Vect_read_next_line(Map, Points, Cats);
+ if (ltype == -1) {
+ G_fatal_error(_("Unable to read vector map"));
+ }
+ else if (ltype == -2) { /* EOF */
+ break;
+ }
+ }
+
+ if (!(type & ltype))
+ continue;
+
+ if (Points->n_points == 0)
+ continue;
+
+ if (chcat) {
+ int found = 0;
+
+ if (id_flag) { /* use line id */
+ if (!(Vect_cat_in_cat_list(line, Clist)))
+ continue;
+ }
+ else {
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field &&
+ Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
+ continue;
+ }
+ }
+ else if (Clist->field > 0) {
+ int found = 0;
+
+ for (i = 0; i < Cats->n_cats; i++) {
+ if (Cats->field[i] == Clist->field) {
+ found = 1;
+ break;
+ }
+ }
+ /* lines with no category will be displayed */
+ if (Cats->n_cats > 0 && !found)
+ continue;
+ }
+
+ /* z height colors */
+ if (z_color_flag && Vect_is_3d(Map)) {
+ struct bound_box box;
+ double zval;
+ struct Colors colors;
+
+ Vect_get_map_box(Map, &box);
+ zval = Points->z[0];
+ G_debug(3, "display line %d, cat %d, x: %f, y: %f, z: %f", line,
+ cat, Points->x[0], Points->y[0], Points->z[0]);
+ custom_rgb = TRUE;
+ Rast_make_fp_colors(&colors, z_column, box.B, box.T);
+ Rast_get_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
+ G_debug(3, "b %d, g: %d, r %d", blu, grn, red);
+ }
+
+ if (table_colors_flag) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats >
+ 0 ? Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read RGB colors from db for current area # */
+ if (db_CatValArray_get_value(cvarr_rgb, cat, &cv_rgb) !=
+ DB_OK) {
+ custom_rgb = FALSE;
+ }
+ else {
+ sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s));
+
+ if (*colorstring != '\0') {
+ G_debug(3, "element %d: colorstring: %s", line,
+ colorstring);
+
+ if (G_str_to_color(colorstring, &red, &grn, &blu) ==
+ 1) {
+ custom_rgb = TRUE;
+ G_debug(3, "element:%d cat %d r:%d g:%d b:%d",
+ line, cat, red, grn, blu);
+ }
+ else {
+ custom_rgb = FALSE;
+ G_important_message(_("Error in color definition column '%s', feature id %d "
+ "with cat %d: colorstring '%s'"),
+ rgb_column, line, cat, colorstring);
+ nerror_rgb++;
+ }
+ }
+ else {
+ custom_rgb = FALSE;
+ G_important_message(_("Error in color definition column '%s', feature id %d "
+ "with cat %d"),
+ rgb_column, line, cat);
+ nerror_rgb++;
+ }
+ }
+ } /* end if cat */
+ else {
+ custom_rgb = FALSE;
+ }
+ } /* end if table_colors_flag */
+
+
+ /* random colors */
+ if (cats_color_flag) {
+ custom_rgb = FALSE;
+ if (Clist->field > 0) {
+ Vect_cat_get(Cats, Clist->field, &cat);
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+ /* fetch color number from category */
+ which = (cat % palette_ncolors);
+ G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat,
+ which, palette[which].R, palette[which].G,
+ palette[which].B);
+
+ custom_rgb = TRUE;
+ red = palette[which].R;
+ grn = palette[which].G;
+ blu = palette[which].B;
+ }
+ }
+ else if (Cats->n_cats > 0) {
+ /* fetch color number from layer */
+ which = (Cats->field[0] % palette_ncolors);
+ G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d",
+ Cats->field[0], which, palette[which].R,
+ palette[which].G, palette[which].B);
+
+ custom_rgb = TRUE;
+ red = palette[which].R;
+ grn = palette[which].G;
+ blu = palette[which].B;
+ }
+ }
+
+
+ if (nrec_width) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats >
+ 0 ? Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read line width from db for current area # */
+ if (db_CatValArray_get_value(cvarr_width, cat, &cv_width) !=
+ DB_OK) {
+ width = default_width;
+ }
+ else {
+ width =
+ width_scale * (cvarr_width->ctype ==
+ DB_C_TYPE_INT ? cv_width->val.i
+ : (int)cv_width->val.d);
+ if (width < 0) {
+ G_warning(_("Error in line width column (%s), element %d "
+ "with cat %d: line width [%d]"),
+ width_column, line, cat, width);
+ width = default_width;
+ }
+ }
+ } /* end if cat */
+ else {
+ width = default_width;
+ }
+
+ D_line_width(width);
+ } /* end if nrec_width */
+
+
+ /* enough of the prep work, lets start plotting stuff */
+ x = Points->x;
+ y = Points->y;
+
+ if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
+ if (!(color || fcolor || custom_rgb))
+ continue;
+
+ x0 = x[0];
+ y0 = y[0];
+
+ /* skip if the point is outside of the display window */
+ /* xy<0 tests make it go ever-so-slightly faster */
+ if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
+ y0 < D_get_u_south() || y0 > D_get_u_north())
+ continue;
+
+ /* dynamic symbol size */
+ if (nrec_size) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats > 0 ?
+ Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read symbol size from db for current symbol # */
+ if (db_CatValArray_get_value(cvarr_size, cat, &cv_size) !=
+ DB_OK) {
+ var_size = size;
+ }
+ else {
+ var_size = size *
+ (cvarr_size->ctype == DB_C_TYPE_INT ?
+ (double)cv_size->val.i : cv_size->val.d);
+
+ if (var_size < 0.0) {
+ G_warning(_("Error in symbol size column (%s), element %d "
+ "with cat %d: symbol size [%f]"),
+ size_column, line, cat, var_size);
+ var_size = size;
+ }
+ }
+ } /* end if cat */
+ else {
+ var_size = size;
+ }
+ } /* end if nrec_size */
+
+ if (sqrt_flag)
+ var_size = sqrt(var_size);
+
+ /* dynamic symbol rotation */
+ if (nrec_rot) {
+ /* only first category */
+ Vect_cat_get(Cats,
+ (Clist->field > 0 ? Clist->field :
+ (Cats->n_cats > 0 ?
+ Cats->field[0] : 1)), &cat);
+
+ if (cat >= 0) {
+ G_debug(3, "display element %d, cat %d", line, cat);
+
+ /* Read symbol rotation from db for current symbol # */
+ if (db_CatValArray_get_value(cvarr_rot, cat, &cv_rot) !=
+ DB_OK) {
+ rotation = 0.0;
+ }
+ else {
+ rotation =
+ (cvarr_rot->ctype == DB_C_TYPE_INT ?
+ (double)cv_rot->val.i : cv_rot->val.d);
+ }
+ } /* end if cat */
+ else {
+ rotation = 0.0;
+ }
+ } /* end if nrec_rot */
+
+ if(nrec_size || nrec_rot) {
+ G_debug(3, ". dynamic symbol: cat=%d size=%.2f rotation=%.2f",
+ cat, var_size, rotation);
+
+ /* symbol stroking is cumulative, so we need to reread it each time */
+ if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
+ G_free(Symb);
+ Symb = S_read(symbol_name);
+ if (Symb == NULL)
+ G_warning(_("Unable to read symbol, unable to display points"));
+ else
+ S_stroke(Symb, var_size, rotation, 0);
+ }
+
+ /* use random or RGB column color if given, otherwise reset */
+ /* centroids always use default color to stand out from underlying area */
+ if (custom_rgb && (ltype != GV_CENTROID)) {
+ primary_color->r = (unsigned char)red;
+ primary_color->g = (unsigned char)grn;
+ primary_color->b = (unsigned char)blu;
+ D_symbol2(Symb, x0, y0, primary_color, line_color);
+ }
+ else
+ D_symbol(Symb, x0, y0, line_color, fill_color);
+
+ /* reset to defaults */
+ var_size = size;
+ rotation = 0.0;
+ }
+ else if (color || custom_rgb || (z_color_flag && Vect_is_3d(Map))) {
+ if (!table_colors_flag && !cats_color_flag && !z_color_flag)
+ D_RGB_color(color->r, color->g, color->b);
+ else {
+ if (custom_rgb)
+ D_RGB_color((unsigned char)red, (unsigned char)grn,
+ (unsigned char)blu);
+ else
+ D_RGB_color(color->r, color->g, color->b);
+ }
+
+ /* Plot the lines */
+ if (Points->n_points == 1) /* line with one coor */
+ D_polydots_abs(x, y, Points->n_points);
+ else /*use different user defined render methods */
+ D_polyline_abs(x, y, Points->n_points);
+ }
+
+ switch (ltype) {
+ case GV_POINT:
+ n_points++;
+ break;
+ case GV_LINE:
+ n_lines++;
+ break;
+ case GV_CENTROID:
+ n_centroids++;
+ break;
+ case GV_BOUNDARY:
+ n_boundaries++;
+ break;
+ case GV_FACE:
+ n_faces++;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (nerror_rgb > 0) {
+ G_warning(_("Error in color definition column '%s': %d features affected"),
+ rgb_column, nerror_rgb);
+ }
+
+ if (n_points > 0)
+ G_verbose_message(_("%d points plotted"), n_points);
+ if (n_lines > 0)
+ G_verbose_message(_("%d lines plotted"), n_lines);
+ if (n_centroids > 0)
+ G_verbose_message(_("%d centroids plotted"), n_centroids);
+ if (n_boundaries > 0)
+ G_verbose_message(_("%d boundaries plotted"), n_boundaries);
+ if (n_faces > 0)
+ G_verbose_message(_("%d faces plotted"), n_faces);
+
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_cats_struct(Cats);
+ G_free(line_color);
+ G_free(fill_color);
+ G_free(primary_color);
+
+ return 0; /* not reached */
+}
Modified: grass/trunk/display/d.vect/local_proto.h
===================================================================
--- grass/trunk/display/d.vect/local_proto.h 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/local_proto.h 2011-08-07 18:16:56 UTC (rev 47485)
@@ -1,20 +1,60 @@
+#include <grass/gis.h>
#include <grass/colors.h>
+#include <grass/vector.h>
+#include <grass/dbmi.h>
+
#include "plot.h"
-FILE *open_vect(char *, char *);
-int close_vect(FILE *);
-int plot1(struct Map_info *, int, int, struct cat_list *,
- const struct color_rgb *, const struct color_rgb *, int, char *,
- double, char *, int, char *, int, int, int, char *, int, char *, double,
- int, char *);
-int label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
-int topo(struct Map_info *, int, int, LATTR *);
-int dir(struct Map_info *, int, struct cat_list *, int);
-int darea(struct Map_info *, struct cat_list *, const struct color_rgb *,
- const struct color_rgb *, int, int, int, int, struct Cell_head *,
- char *, int, char *, double, int, char *);
-int attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
-int zcoor(struct Map_info *, int, LATTR *);
int test_bg_color(const char *);
+
+/* attr.c */
+int display_attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
+
+/* area.c */
+int display_area(struct Map_info *, struct cat_list *, const struct Cell_head *,
+ const struct color_rgb *, const struct color_rgb *, int, int,
+ int, int, const char *,
+ int, const char *, double,
+ int, const char *,
+ dbCatValArray *, dbCatValArray *, int);
+
+/* dir.c */
+int display_dir(struct Map_info *, int, struct cat_list *, int);
+
+/* labels.c */
+int display_label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
void show_label(double *, double *, LATTR *, const char *);
void show_label_line(const struct line_pnts *, int, LATTR *, const char *);
+
+/* lines.c */
+int display_lines(struct Map_info *, int, struct cat_list *,
+ const struct color_rgb *, const struct color_rgb *, int,
+ const char *, double, const char *, int, const char *,
+ int, int, int, const char *,
+ int, const char *, double,
+ int, const char *,
+ dbCatValArray *, dbCatValArray *, int,
+ dbCatValArray *, int, dbCatValArray *, int);
+
+/* shape.c */
+int display_shape(struct Map_info *, int, int, struct cat_list *, const struct Cell_head *,
+ const struct color_rgb *, const struct color_rgb *, int,
+ const char *, double, const char *, int, const char *, /* lines only */
+ int, int, int, char *,
+ int, char *, double,
+ int, char *);
+
+/* opt.c */
+int option_to_display(const struct Option *);
+void options_to_lattr(LATTR *, const char *,
+ const char *, const char *, const char *,
+ int, const char *, const char *,
+ const char *, const char *);
+int option_to_color(struct color_rgb *, const char *);
+void option_to_where(struct Map_info *, struct cat_list *, const char *);
+
+/* topo.c */
+int display_topo(struct Map_info *, int, int, LATTR *);
+
+/* zcoor.c */
+int display_zcoor(struct Map_info *, int, LATTR *);
Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/main.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -19,8 +19,6 @@
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/display.h>
-#include <grass/vector.h>
-#include <grass/colors.h>
#include <grass/dbmi.h>
#include <grass/glocale.h>
#include "plot.h"
@@ -76,16 +74,16 @@
int main(int argc, char **argv)
{
int ret, level;
- int i, stat = 0, type, area, display;
- int chcat = 0;
- int r, g, b;
+ int stat, type, area, display;
+ int chcat;
int has_color, has_fcolor;
struct color_rgb color, fcolor;
double size;
int default_width;
double width_scale;
double minreg, maxreg, reg;
- char map_name[128];
+ char map_name[GNAME_MAX];
+
struct GModule *module;
struct Option *map_opt;
struct Option *color_opt, *fcolor_opt, *rgbcol_opt, *zcol_opt;
@@ -99,17 +97,15 @@
struct Option *width_opt, *wcolumn_opt, *wscale_opt;
struct Flag *id_flag, *table_acolors_flag, *cats_acolors_flag,
*zcol_flag, *sqrt_flag;
+
struct cat_list *Clist;
- int *cats, ncat;
LATTR lattr;
struct Map_info Map;
- struct field_info *fi;
- dbDriver *driver;
- dbHandle handle;
struct Cell_head window;
struct bound_box box;
double overlap;
+ stat = 0;
/* Initialize the GIS calls */
G_gisinit(argv[0]);
@@ -380,15 +376,13 @@
G_get_set_window(&window);
- /* Read map options */
-
/* Check min/max region */
reg = ((window.east - window.west) + (window.north - window.south)) / 2;
if (minreg_opt->answer) {
minreg = atof(minreg_opt->answer);
if (reg < minreg) {
- G_message(_("Region size is lower than minreg, nothing displayed."));
+ G_important_message(_("Region size is lower than minreg, nothing displayed"));
exit(EXIT_SUCCESS);
}
}
@@ -396,7 +390,7 @@
maxreg = atof(maxreg_opt->answer);
if (reg > maxreg) {
- G_message(_("Region size is greater than maxreg, nothing displayed."));
+ G_important_message(_("Region size is greater than maxreg, nothing displayed"));
exit(EXIT_SUCCESS);
}
}
@@ -415,35 +409,10 @@
}
color = G_standard_color_rgb(WHITE);
- ret = G_str_to_color(color_opt->answer, &r, &g, &b);
- if (ret == 1) {
- has_color = 1;
- color.r = r;
- color.g = g;
- color.b = b;
- }
- else if (ret == 2) { /* none */
- has_color = 0;
- }
- else if (ret == 0) { /* error */
- G_fatal_error(_("Unknown color: [%s]"), color_opt->answer);
- }
-
+ has_color = option_to_color(&color, color_opt->answer);
fcolor = G_standard_color_rgb(WHITE);
- ret = G_str_to_color(fcolor_opt->answer, &r, &g, &b);
- if (ret == 1) {
- has_fcolor = 1;
- fcolor.r = r;
- fcolor.g = g;
- fcolor.b = b;
- }
- else if (ret == 2) { /* none */
- has_fcolor = 0;
- }
- else if (ret == 0) { /* error */
- G_fatal_error(_("Unknown color: '%s'"), fcolor_opt->answer);
- }
-
+ has_fcolor = option_to_color(&fcolor, fcolor_opt->answer);
+
size = atof(size_opt->answer);
/* if where_opt was specified select categories from db
@@ -454,148 +423,33 @@
/* open vector */
level = Vect_open_old2(&Map, map_name, "", field_opt->answer);
+ chcat = 0;
if (where_opt->answer) {
if (Clist->field < 1)
- G_fatal_error(_("'layer' must be > 0 for 'where'."));
+ G_fatal_error(_("Option <%s> must be > 0"), field_opt->key);
chcat = 1;
- if ((fi = Vect_get_field(&Map, Clist->field)) == NULL)
- G_fatal_error(_("Database connection not defined"));
- if (fi != NULL) {
- driver = db_start_driver(fi->driver);
- if (driver == NULL)
- G_fatal_error(_("Unable to start driver <%s>"), fi->driver);
-
- db_init_handle(&handle);
- db_set_handle(&handle, fi->database, NULL);
- if (db_open_database(driver, &handle) != DB_OK)
- G_fatal_error(_("Unable to open database <%s>"),
- fi->database);
-
- ncat =
- db_select_int(driver, fi->table, fi->key, where_opt->answer,
- &cats);
-
- db_close_database(driver);
- db_shutdown_driver(driver);
-
- Vect_array_to_cat_list(cats, ncat, Clist);
- }
+ option_to_where(&Map, Clist, where_opt->answer);
}
else if (cat_opt->answer) {
if (Clist->field < 1)
- G_fatal_error(_("'layer' must be > 0 for 'cats'."));
+ G_fatal_error(_("Option <%s> must be > 0"), field_opt->key);
chcat = 1;
ret = Vect_str_to_cat_list(cat_opt->answer, Clist);
if (ret > 0)
G_warning(_("%d errors in cat option"), ret);
}
+
+ type = Vect_option_to_types(type_opt);
+ area = type & GV_AREA;
+
+ display = option_to_display(display_opt);
- i = 0;
- type = 0;
- area = FALSE;
- while (type_opt->answers[i]) {
- switch (type_opt->answers[i][0]) {
- case 'p':
- type |= GV_POINT;
- break;
- case 'l':
- type |= GV_LINE;
- break;
- case 'b':
- type |= GV_BOUNDARY;
- break;
- case 'f':
- type |= GV_FACE;
- break;
- case 'c':
- type |= GV_CENTROID;
- break;
- case 'a':
- area = TRUE;
- break;
- }
- i++;
- }
+ /* labels */
+ options_to_lattr(&lattr, lfield_opt->answer,
+ lcolor_opt->answer, bgcolor_opt->answer, bcolor_opt->answer,
+ atoi(lsize_opt->answer), font_opt->answer, enc_opt->answer,
+ xref_opt->answer, yref_opt->answer);
- i = 0;
- display = 0;
- while (display_opt->answers[i]) {
- switch (display_opt->answers[i][0]) {
- case 's':
- display |= DISP_SHAPE;
- break;
- case 'c':
- display |= DISP_CAT;
- break;
- case 't':
- display |= DISP_TOPO;
- break;
- case 'd':
- display |= DISP_DIR;
- break;
- case 'a':
- display |= DISP_ATTR;
- break;
- case 'z':
- display |= DISP_ZCOOR;
- break;
- }
- i++;
- }
-
- /* Read label options */
- if (lfield_opt->answer != NULL)
- lattr.field = atoi(lfield_opt->answer);
- else
- lattr.field = Clist->field;
-
- lattr.color.R = lattr.color.G = lattr.color.B = 255;
- if (G_str_to_color(lcolor_opt->answer, &r, &g, &b)) {
- lattr.color.R = r;
- lattr.color.G = g;
- lattr.color.B = b;
- }
- lattr.has_bgcolor = 0;
- if (G_str_to_color(bgcolor_opt->answer, &r, &g, &b) == 1) {
- lattr.has_bgcolor = 1;
- lattr.bgcolor.R = r;
- lattr.bgcolor.G = g;
- lattr.bgcolor.B = b;
- }
- lattr.has_bcolor = 0;
- if (G_str_to_color(bcolor_opt->answer, &r, &g, &b) == 1) {
- lattr.has_bcolor = 1;
- lattr.bcolor.R = r;
- lattr.bcolor.G = g;
- lattr.bcolor.B = b;
- }
-
- lattr.size = atoi(lsize_opt->answer);
- lattr.font = font_opt->answer;
- lattr.enc = enc_opt->answer;
- switch (xref_opt->answer[0]) {
- case 'l':
- lattr.xref = LLEFT;
- break;
- case 'c':
- lattr.xref = LCENTER;
- break;
- case 'r':
- lattr.xref = LRIGHT;
- break;
- }
- switch (yref_opt->answer[0]) {
- case 't':
- lattr.yref = LTOP;
- break;
- case 'c':
- lattr.yref = LCENTER;
- break;
- case 'b':
- lattr.yref = LBOTTOM;
- break;
- }
-
D_setup(0);
D_set_reduction(1.0);
@@ -608,12 +462,12 @@
window.east < box.W ||
window.west > G_adjust_easting(box.E, &window))) {
G_message(_("The bounding box of the map is outside the current region, "
- "nothing drawn."));
- stat = 0;
+ "nothing drawn"));
+ exit(EXIT_SUCCESS);
}
else {
- overlap =
- G_window_percentage_overlap(&window, box.N, box.S, box.E, box.W);
+ overlap = G_window_percentage_overlap(&window, box.N, box.S,
+ box.E, box.W);
G_debug(1, "overlap = %f \n", overlap);
if (overlap < 1)
Vect_set_constraint_region(&Map, window.north, window.south,
@@ -624,52 +478,22 @@
if (!wcolumn_opt->answer)
D_line_width(default_width);
- if (area) {
- if (level >= 2) {
- if (display & DISP_SHAPE) {
- stat = darea(&Map, Clist,
- has_color ? &color : NULL,
- has_fcolor ? &fcolor : NULL, chcat,
- (int)id_flag->answer,
- table_acolors_flag->answer,
- cats_acolors_flag->answer, &window,
- rgbcol_opt->answer, default_width,
- wcolumn_opt->answer, width_scale,
- zcol_flag->answer, zcol_opt->answer);
- }
- if (wcolumn_opt->answer)
- D_line_width(default_width);
- }
- else
- G_warning(_("Unable to display areas, topology not available. "
- "Please try to rebuild topology using "
- "v.build or v.build.all."));
- }
-
if (display & DISP_SHAPE) {
- if (id_flag->answer && level < 2) {
- G_warning(_("Unable to display lines by id, topology not available. "
- "Please try to rebuild topology using "
- "v.build or v.build.all."));
- }
- else {
- stat = plot1(&Map, type, area, Clist,
- has_color ? &color : NULL,
- has_fcolor ? &fcolor : NULL, chcat, icon_opt->answer,
- size, sizecolumn_opt->answer, (int)sqrt_flag->answer, rotcolumn_opt->answer,
- (int)id_flag->answer, table_acolors_flag->answer,
- cats_acolors_flag->answer, rgbcol_opt->answer,
- default_width, wcolumn_opt->answer, width_scale,
- zcol_flag->answer, zcol_opt->answer);
- if (wcolumn_opt->answer)
- D_line_width(default_width);
- }
+ stat += display_shape(&Map, type, area, Clist, &window,
+ has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat,
+ icon_opt->answer, size, sizecolumn_opt->answer, sqrt_flag->answer ? 1 : 0, rotcolumn_opt->answer,
+ id_flag->answer ? 1 : 0, table_acolors_flag->answer ? 1 : 0, cats_acolors_flag->answer ? 1 : 0, rgbcol_opt->answer,
+ default_width, wcolumn_opt->answer, width_scale,
+ zcol_flag->answer ? 1 : 0, zcol_opt->answer);
+
+ if (wcolumn_opt->answer)
+ D_line_width(default_width);
}
if (has_color) {
D_RGB_color(color.r, color.g, color.b);
if (display & DISP_DIR)
- stat = dir(&Map, type, Clist, chcat);
+ stat += display_dir(&Map, type, Clist, chcat);
}
/* reset line width: Do we need to get line width from display
@@ -678,9 +502,9 @@
* d.linewidth). */
if (!wcolumn_opt->answer)
D_line_width(0);
-
+
if (display & DISP_CAT)
- stat = label(&Map, type, area, Clist, &lattr, chcat);
+ stat += display_label(&Map, type, area, Clist, &lattr, chcat);
if (display & DISP_ATTR) {
int attr_type = type;
@@ -688,21 +512,14 @@
if (area && !(attr_type & GV_CENTROID))
attr_type |= GV_CENTROID;
- stat =
- attr(&Map, attr_type, attrcol_opt->answer, Clist, &lattr, chcat);
+ stat += display_attr(&Map, attr_type, attrcol_opt->answer, Clist, &lattr, chcat);
}
if (display & DISP_ZCOOR)
- stat = zcoor(&Map, type, &lattr);
+ stat += display_zcoor(&Map, type, &lattr);
- if (display & DISP_TOPO) {
- if (level >= 2)
- stat = topo(&Map, type, area, &lattr);
- else
- G_warning(_("Unable to display topology, not available."
- "Please try to rebuild topology using "
- "v.build or v.build.all."));
- }
+ if (display & DISP_TOPO)
+ stat += display_topo(&Map, type, area, &lattr);
}
D_save_command(G_recreate_command());
@@ -713,5 +530,8 @@
Vect_close(&Map);
Vect_destroy_cat_list(Clist);
- exit(stat);
+ if (stat != 0)
+ exit(EXIT_FAILURE);
+
+ exit(EXIT_SUCCESS);
}
Added: grass/trunk/display/d.vect/opt.c
===================================================================
--- grass/trunk/display/d.vect/opt.c (rev 0)
+++ grass/trunk/display/d.vect/opt.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -0,0 +1,161 @@
+#include <grass/gis.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+int option_to_display(const struct Option *opt)
+{
+ int i, display;
+
+ i = display = 0;
+ while (opt->answers[i]) {
+ switch (opt->answers[i][0]) {
+ case 's':
+ display |= DISP_SHAPE;
+ break;
+ case 'c':
+ display |= DISP_CAT;
+ break;
+ case 't':
+ display |= DISP_TOPO;
+ break;
+ case 'd':
+ display |= DISP_DIR;
+ break;
+ case 'a':
+ display |= DISP_ATTR;
+ break;
+ case 'z':
+ display |= DISP_ZCOOR;
+ break;
+ }
+ i++;
+ }
+
+ return display;
+}
+
+void options_to_lattr(LATTR *lattr, const char *layer,
+ const char *color, const char *bgcolor, const char *bcolor,
+ int size, const char *font, const char *encoding,
+ const char *xref, const char *yref)
+{
+ int r, g, b;
+
+ if (layer)
+ lattr->field = atoi(layer);
+ else
+ lattr->field = 1;
+
+ lattr->color.R = lattr->color.G = lattr->color.B = 255;
+ if (G_str_to_color(color, &r, &g, &b)) {
+ lattr->color.R = r;
+ lattr->color.G = g;
+ lattr->color.B = b;
+ }
+ lattr->has_bgcolor = 0;
+ if (G_str_to_color(bgcolor, &r, &g, &b) == 1) {
+ lattr->has_bgcolor = 1;
+ lattr->bgcolor.R = r;
+ lattr->bgcolor.G = g;
+ lattr->bgcolor.B = b;
+ }
+ lattr->has_bcolor = 0;
+ if (G_str_to_color(bcolor, &r, &g, &b) == 1) {
+ lattr->has_bcolor = 1;
+ lattr->bcolor.R = r;
+ lattr->bcolor.G = g;
+ lattr->bcolor.B = b;
+ }
+
+ lattr->size = size;
+ lattr->font = font;
+ lattr->enc = encoding;
+ if (xref) {
+ switch (xref[0]) {
+ case 'l':
+ lattr->xref = LLEFT;
+ break;
+ case 'c':
+ lattr->xref = LCENTER;
+ break;
+ case 'r':
+ lattr->xref = LRIGHT;
+ break;
+ }
+ }
+ else
+ lattr->xref = LCENTER;
+
+ if (yref) {
+ switch (yref[0]) {
+ case 't':
+ lattr->yref = LTOP;
+ break;
+ case 'c':
+ lattr->yref = LCENTER;
+ break;
+ case 'b':
+ lattr->yref = LBOTTOM;
+ break;
+ }
+ }
+ else
+ lattr->yref = LCENTER;
+}
+
+int option_to_color(struct color_rgb *color, const char *color_val)
+{
+ int has_color, ret;
+ int r, g, b;
+
+ ret = G_str_to_color(color_val, &r, &g, &b);
+ if (ret == 1) {
+ has_color = 1;
+ color->r = r;
+ color->g = g;
+ color->b = b;
+ }
+ else if (ret == 2) { /* none */
+ has_color = 0;
+ }
+ else if (ret == 0) { /* error */
+ G_fatal_error(_("Unknown color: '%s'"), color_val);
+ }
+
+ return has_color;
+}
+
+void option_to_where(struct Map_info *Map, struct cat_list *Clist,
+ const char *where)
+{
+ int ncat;
+ int *cats;
+ struct field_info *fi;
+ dbDriver *driver;
+ dbHandle handle;
+
+ fi = Vect_get_field(Map, Clist->field);
+ if (!fi)
+ G_fatal_error(_("Database connection not defined"));
+
+ driver = db_start_driver(fi->driver);
+ if (!driver)
+ G_fatal_error(_("Unable to start driver <%s>"), fi->driver);
+
+ db_init_handle(&handle);
+ db_set_handle(&handle, fi->database, NULL);
+ if (db_open_database(driver, &handle) != DB_OK)
+ G_fatal_error(_("Unable to open database <%s>"),
+ fi->database);
+
+ ncat = db_select_int(driver, fi->table, fi->key, where,
+ &cats);
+
+ db_close_database(driver);
+ db_shutdown_driver(driver);
+
+ Vect_array_to_cat_list(cats, ncat, Clist);
+}
+
Property changes on: grass/trunk/display/d.vect/opt.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/display/d.vect/plot.h
===================================================================
--- grass/trunk/display/d.vect/plot.h 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/plot.h 2011-08-07 18:16:56 UTC (rev 47485)
@@ -19,8 +19,8 @@
int has_bcolor;
struct rgb_color color, bgcolor, bcolor;
int size;
- char *font;
- char *enc;
+ const char *font;
+ const char *enc;
int xref, yref;
} LATTR;
Deleted: grass/trunk/display/d.vect/plot1.c
===================================================================
--- grass/trunk/display/d.vect/plot1.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/plot1.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -1,635 +0,0 @@
-/* plot1() - Level One vector reading */
-
-#include <string.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/vector.h>
-#include <grass/display.h>
-#include "plot.h"
-#include "local_proto.h"
-#include <grass/symbol.h>
-#include <grass/glocale.h>
-#include <grass/dbmi.h>
-
-#define RENDER_POLYLINE 0
-#define RENDER_POLYGON 1
-
-int palette_ncolors = 16;
-
-struct rgb_color palette[16] = {
- {198, 198, 198}, /* 1: light gray */
- {127, 127, 127}, /* 2: medium/dark gray */
- {255, 0, 0}, /* 3: bright red */
- {139, 0, 0}, /* 4: dark red */
- {0, 255, 0}, /* 5: bright green */
- {0, 139, 0}, /* 6: dark green */
- {0, 0, 255}, /* 7: bright blue */
- {0, 0, 139}, /* 8: dark blue */
- {255, 255, 0}, /* 9: yellow */
- {139, 126, 10}, /* 10: olivey brown */
- {255, 165, 0}, /* 11: orange */
- {255, 192, 203}, /* 12: pink */
- {255, 0, 255}, /* 13: magenta */
- {139, 0, 139}, /* 14: dark magenta */
- {0, 255, 255}, /* 15: cyan */
- {0, 139, 139} /* 16: dark cyan */
-};
-
-/* *************************************************************** */
-/* *************************************************************** */
-/* *************************************************************** */
-int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
- const struct color_rgb *color, const struct color_rgb *fcolor,
- int chcat, char *symbol_name, double size, char *size_column,
- int sqrt_flag, char *rot_column, int id_flag, int table_colors_flag,
- int cats_color_flag, char *rgb_column, int default_width,
- char *width_column, double width_scale, int z_color_flag,
- char *style)
-{
- int i, ltype, nlines = 0, line, cat = -1;
- double *x, *y;
- struct line_pnts *Points, *PPoints;
- struct line_cats *Cats;
- double x0, y0;
-
- struct field_info *fi = NULL;
- dbDriver *driver = NULL;
- dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
- dbCatVal *cv_rgb = NULL, *cv_width = NULL, *cv_size = NULL, *cv_rot = NULL;
- int nrec_rgb = 0, nrec_width = 0, nrec_size = 0, nrec_rot = 0;
- int nerror_rgb;
- int n_points, n_lines, n_centroids, n_boundaries, n_faces;
-
- int open_db;
- int custom_rgb = FALSE;
- char colorstring[12]; /* RRR:GGG:BBB */
- int red, grn, blu;
- RGBA_Color *line_color, *fill_color, *primary_color;
- unsigned char which;
- int width;
- SYMBOL *Symb = NULL;
- double var_size, rotation;
-
- var_size = size;
- rotation = 0.0;
- nerror_rgb = 0;
-
- line_color = G_malloc(sizeof(RGBA_Color));
- fill_color = G_malloc(sizeof(RGBA_Color));
- primary_color = G_malloc(sizeof(RGBA_Color));
-
- primary_color->a = RGBA_COLOR_OPAQUE;
-
- /* change function prototype to pass RGBA_Color instead of color_rgb? */
- if (color) {
- line_color->r = color->r;
- line_color->g = color->g;
- line_color->b = color->b;
- line_color->a = RGBA_COLOR_OPAQUE;
- }
- else
- line_color->a = RGBA_COLOR_NONE;
-
- if (fcolor) {
- fill_color->r = fcolor->r;
- fill_color->g = fcolor->g;
- fill_color->b = fcolor->b;
- fill_color->a = RGBA_COLOR_OPAQUE;
- }
- else
- fill_color->a = RGBA_COLOR_NONE;
-
-
- Points = Vect_new_line_struct();
- PPoints = Vect_new_line_struct();
- Cats = Vect_new_cats_struct();
-
- open_db = table_colors_flag || width_column || size_column || rot_column;
-
- if (open_db) {
- fi = Vect_get_field(Map, (Clist->field > 0 ? Clist->field : 1));
- if (fi == NULL) {
- G_fatal_error(_("Database connection not defined for layer %d"),
- (Clist->field > 0 ? Clist->field : 1));
- }
-
- driver = db_start_driver_open_database(fi->driver, fi->database);
- if (driver == NULL)
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
- fi->database, fi->driver);
- }
-
- if (table_colors_flag) {
- /* for reading RRR:GGG:BBB color strings from table */
-
- if (rgb_column == NULL || *rgb_column == '\0')
- G_fatal_error(_("Color definition column not specified"));
-
- db_CatValArray_init(&cvarr_rgb);
-
- nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
- rgb_column, NULL, &cvarr_rgb);
-
- G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
-
- if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
- G_fatal_error(_("Color definition column (%s) not a string. "
- "Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
- rgb_column);
-
- if (nrec_rgb < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- rgb_column);
-
- G_debug(2, "\n%d records selected from table", nrec_rgb);
-
- for (i = 0; i < cvarr_rgb.n_values; i++) {
- G_debug(4, "cat = %d %s = %s", cvarr_rgb.value[i].cat,
- rgb_column, db_get_string(cvarr_rgb.value[i].val.s));
- }
- }
-
- if (width_column) {
- if (*width_column == '\0')
- G_fatal_error(_("Line width column not specified."));
-
- db_CatValArray_init(&cvarr_width);
-
- nrec_width = db_select_CatValArray(driver, fi->table, fi->key,
- width_column, NULL, &cvarr_width);
-
- G_debug(3, "nrec_width (%s) = %d", width_column, nrec_width);
-
- if (cvarr_width.ctype != DB_C_TYPE_INT &&
- cvarr_width.ctype != DB_C_TYPE_DOUBLE)
- G_fatal_error(_("Line width column (%s) is not numeric."),
- width_column);
-
- if (nrec_width < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- width_column);
-
- G_debug(2, " %d records selected from table", nrec_width);
-
- for (i = 0; i < cvarr_width.n_values; i++) {
- G_debug(4, "(width) cat = %d %s = %d", cvarr_width.value[i].cat,
- width_column,
- (cvarr_width.ctype ==
- DB_C_TYPE_INT ? cvarr_width.value[i].val.
- i : (int)cvarr_width.value[i].val.d));
- }
- }
-
- if (size_column) {
- if (*size_column == '\0')
- G_fatal_error(_("Symbol size column not specified."));
-
- db_CatValArray_init(&cvarr_size);
-
- nrec_size = db_select_CatValArray(driver, fi->table, fi->key,
- size_column, NULL, &cvarr_size);
-
- G_debug(3, "nrec_size (%s) = %d", size_column, nrec_size);
-
- if (cvarr_size.ctype != DB_C_TYPE_INT &&
- cvarr_size.ctype != DB_C_TYPE_DOUBLE)
- G_fatal_error(_("Symbol size column (%s) is not numeric."),
- size_column);
-
- if (nrec_size < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- size_column);
-
- G_debug(2, " %d records selected from table", nrec_size);
-
- for (i = 0; i < cvarr_size.n_values; i++) {
- G_debug(4, "(size) cat = %d %s = %.2f", cvarr_size.value[i].cat,
- size_column,
- (cvarr_size.ctype ==
- DB_C_TYPE_INT ? (double)cvarr_size.value[i].val.i
- : cvarr_size.value[i].val.d));
- }
- }
-
- if (rot_column) {
- if (*rot_column == '\0')
- G_fatal_error(_("Symbol rotation column not specified."));
-
- db_CatValArray_init(&cvarr_rot);
-
- nrec_rot = db_select_CatValArray(driver, fi->table, fi->key,
- rot_column, NULL, &cvarr_rot);
-
- G_debug(3, "nrec_rot (%s) = %d", rot_column, nrec_rot);
-
- if (cvarr_rot.ctype != DB_C_TYPE_INT &&
- cvarr_rot.ctype != DB_C_TYPE_DOUBLE)
- G_fatal_error(_("Symbol rotation column (%s) is not numeric."),
- rot_column);
-
- if (nrec_rot < 0)
- G_fatal_error(_("Cannot select data (%s) from table"),
- rot_column);
-
- G_debug(2, " %d records selected from table", nrec_rot);
-
- for (i = 0; i < cvarr_rot.n_values; i++) {
- G_debug(4, "(rot) cat = %d %s = %.2f", cvarr_rot.value[i].cat,
- rot_column,
- (cvarr_rot.ctype ==
- DB_C_TYPE_INT ? (double)cvarr_rot.value[i].val.i
- : cvarr_rot.value[i].val.d));
- }
- }
-
- if( !(nrec_size || nrec_rot) ) {
- Symb = S_read(symbol_name);
- if (Symb == NULL)
- G_warning(_("Unable to read symbol, unable to display points"));
- else
- S_stroke(Symb, size, 0.0, 0);
- }
-
- if (open_db)
- db_close_database_shutdown_driver(driver);
-
- Vect_rewind(Map);
-
- /* Is it necessary to reset line/label color in each loop ? */
-
- if (color && !table_colors_flag && !cats_color_flag)
- D_RGB_color(color->r, color->g, color->b);
-
- if (Vect_level(Map) >= 2)
- nlines = Vect_get_num_lines(Map);
-
- line = 0;
- n_points = n_lines = 0;
- n_centroids = n_boundaries = 0;
- n_faces = 0;
- while (1) {
- line++;
- if (Vect_level(Map) >= 2) {
- if (line > nlines)
- break;
- if (!Vect_line_alive(Map, line))
- continue;
- ltype = Vect_read_line(Map, Points, Cats, line);
- }
- else {
- ltype = Vect_read_next_line(Map, Points, Cats);
- if (ltype == -1) {
- G_fatal_error(_("Unable to read vector map"));
- }
- else if (ltype == -2) { /* EOF */
- break;
- }
- }
-
- if (!(type & ltype))
- continue;
-
- if (Points->n_points == 0)
- continue;
-
- if (chcat) {
- int found = 0;
-
- if (id_flag) { /* use line id */
- if (!(Vect_cat_in_cat_list(line, Clist)))
- continue;
- }
- else {
- for (i = 0; i < Cats->n_cats; i++) {
- if (Cats->field[i] == Clist->field &&
- Vect_cat_in_cat_list(Cats->cat[i], Clist)) {
- found = 1;
- break;
- }
- }
- if (!found)
- continue;
- }
- }
- else if (Clist->field > 0) {
- int found = 0;
-
- for (i = 0; i < Cats->n_cats; i++) {
- if (Cats->field[i] == Clist->field) {
- found = 1;
- break;
- }
- }
- /* lines with no category will be displayed */
- if (Cats->n_cats > 0 && !found)
- continue;
- }
-
- /* z height colors */
- if (z_color_flag && Vect_is_3d(Map)) {
- struct bound_box box;
- double zval;
- struct Colors colors;
-
- Vect_get_map_box(Map, &box);
- zval = Points->z[0];
- G_debug(3, "display line %d, cat %d, x: %f, y: %f, z: %f", line,
- cat, Points->x[0], Points->y[0], Points->z[0]);
- custom_rgb = TRUE;
- Rast_make_fp_colors(&colors, style, box.B, box.T);
- Rast_get_color(&zval, &red, &grn, &blu, &colors, DCELL_TYPE);
- G_debug(3, "b %d, g: %d, r %d", blu, grn, red);
- }
-
- if (table_colors_flag) {
- /* only first category */
- Vect_cat_get(Cats,
- (Clist->field > 0 ? Clist->field :
- (Cats->n_cats >
- 0 ? Cats->field[0] : 1)), &cat);
-
- if (cat >= 0) {
- G_debug(3, "display element %d, cat %d", line, cat);
-
- /* Read RGB colors from db for current area # */
- if (db_CatValArray_get_value(&cvarr_rgb, cat, &cv_rgb) !=
- DB_OK) {
- custom_rgb = FALSE;
- }
- else {
- sprintf(colorstring, "%s", db_get_string(cv_rgb->val.s));
-
- if (*colorstring != '\0') {
- G_debug(3, "element %d: colorstring: %s", line,
- colorstring);
-
- if (G_str_to_color(colorstring, &red, &grn, &blu) ==
- 1) {
- custom_rgb = TRUE;
- G_debug(3, "element:%d cat %d r:%d g:%d b:%d",
- line, cat, red, grn, blu);
- }
- else {
- custom_rgb = FALSE;
- G_important_message(_("Error in color definition column '%s', feature id %d "
- "with cat %d: colorstring '%s'"),
- rgb_column, line, cat, colorstring);
- nerror_rgb++;
- }
- }
- else {
- custom_rgb = FALSE;
- G_important_message(_("Error in color definition column '%s', feature id %d "
- "with cat %d"),
- rgb_column, line, cat);
- nerror_rgb++;
- }
- }
- } /* end if cat */
- else {
- custom_rgb = FALSE;
- }
- } /* end if table_colors_flag */
-
-
- /* random colors */
- if (cats_color_flag) {
- custom_rgb = FALSE;
- if (Clist->field > 0) {
- Vect_cat_get(Cats, Clist->field, &cat);
- if (cat >= 0) {
- G_debug(3, "display element %d, cat %d", line, cat);
- /* fetch color number from category */
- which = (cat % palette_ncolors);
- G_debug(3, "cat:%d which color:%d r:%d g:%d b:%d", cat,
- which, palette[which].R, palette[which].G,
- palette[which].B);
-
- custom_rgb = TRUE;
- red = palette[which].R;
- grn = palette[which].G;
- blu = palette[which].B;
- }
- }
- else if (Cats->n_cats > 0) {
- /* fetch color number from layer */
- which = (Cats->field[0] % palette_ncolors);
- G_debug(3, "layer:%d which color:%d r:%d g:%d b:%d",
- Cats->field[0], which, palette[which].R,
- palette[which].G, palette[which].B);
-
- custom_rgb = TRUE;
- red = palette[which].R;
- grn = palette[which].G;
- blu = palette[which].B;
- }
- }
-
-
- if (nrec_width) {
- /* only first category */
- Vect_cat_get(Cats,
- (Clist->field > 0 ? Clist->field :
- (Cats->n_cats >
- 0 ? Cats->field[0] : 1)), &cat);
-
- if (cat >= 0) {
- G_debug(3, "display element %d, cat %d", line, cat);
-
- /* Read line width from db for current area # */
- if (db_CatValArray_get_value(&cvarr_width, cat, &cv_width) !=
- DB_OK) {
- width = default_width;
- }
- else {
- width =
- width_scale * (cvarr_width.ctype ==
- DB_C_TYPE_INT ? cv_width->val.i
- : (int)cv_width->val.d);
- if (width < 0) {
- G_warning(_("Error in line width column (%s), element %d "
- "with cat %d: line width [%d]"),
- width_column, line, cat, width);
- width = default_width;
- }
- }
- } /* end if cat */
- else {
- width = default_width;
- }
-
- D_line_width(width);
- } /* end if nrec_width */
-
-
- /* enough of the prep work, lets start plotting stuff */
- x = Points->x;
- y = Points->y;
-
- if ((ltype & GV_POINTS) && (Symb != NULL || (nrec_size || nrec_rot)) ) {
- if (!(color || fcolor || custom_rgb))
- continue;
-
- x0 = x[0];
- y0 = y[0];
-
- /* skip if the point is outside of the display window */
- /* xy<0 tests make it go ever-so-slightly faster */
- if (x0 > D_get_u_east() || x0 < D_get_u_west() ||
- y0 < D_get_u_south() || y0 > D_get_u_north())
- continue;
-
- /* dynamic symbol size */
- if (nrec_size) {
- /* only first category */
- Vect_cat_get(Cats,
- (Clist->field > 0 ? Clist->field :
- (Cats->n_cats > 0 ?
- Cats->field[0] : 1)), &cat);
-
- if (cat >= 0) {
- G_debug(3, "display element %d, cat %d", line, cat);
-
- /* Read symbol size from db for current symbol # */
- if (db_CatValArray_get_value(&cvarr_size, cat, &cv_size) !=
- DB_OK) {
- var_size = size;
- }
- else {
- var_size = size *
- (cvarr_size.ctype == DB_C_TYPE_INT ?
- (double)cv_size->val.i : cv_size->val.d);
-
- if (var_size < 0.0) {
- G_warning(_("Error in symbol size column (%s), element %d "
- "with cat %d: symbol size [%f]"),
- size_column, line, cat, var_size);
- var_size = size;
- }
- }
- } /* end if cat */
- else {
- var_size = size;
- }
- } /* end if nrec_size */
-
- if (sqrt_flag)
- var_size = sqrt(var_size);
-
- /* dynamic symbol rotation */
- if (nrec_rot) {
- /* only first category */
- Vect_cat_get(Cats,
- (Clist->field > 0 ? Clist->field :
- (Cats->n_cats > 0 ?
- Cats->field[0] : 1)), &cat);
-
- if (cat >= 0) {
- G_debug(3, "display element %d, cat %d", line, cat);
-
- /* Read symbol rotation from db for current symbol # */
- if (db_CatValArray_get_value(&cvarr_rot, cat, &cv_rot) !=
- DB_OK) {
- rotation = 0.0;
- }
- else {
- rotation =
- (cvarr_rot.ctype == DB_C_TYPE_INT ?
- (double)cv_rot->val.i : cv_rot->val.d);
- }
- } /* end if cat */
- else {
- rotation = 0.0;
- }
- } /* end if nrec_rot */
-
- if(nrec_size || nrec_rot) {
- G_debug(3, ". dynamic symbol: cat=%d size=%.2f rotation=%.2f",
- cat, var_size, rotation);
-
- /* symbol stroking is cumulative, so we need to reread it each time */
- if(Symb) /* unclean free() on first iteration if variables are not init'd to NULL? */
- G_free(Symb);
- Symb = S_read(symbol_name);
- if (Symb == NULL)
- G_warning(_("Unable to read symbol, unable to display points"));
- else
- S_stroke(Symb, var_size, rotation, 0);
- }
-
- /* use random or RGB column color if given, otherwise reset */
- /* centroids always use default color to stand out from underlying area */
- if (custom_rgb && (ltype != GV_CENTROID)) {
- primary_color->r = (unsigned char)red;
- primary_color->g = (unsigned char)grn;
- primary_color->b = (unsigned char)blu;
- D_symbol2(Symb, x0, y0, primary_color, line_color);
- }
- else
- D_symbol(Symb, x0, y0, line_color, fill_color);
-
- /* reset to defaults */
- var_size = size;
- rotation = 0.0;
- }
- else if (color || custom_rgb || (z_color_flag && Vect_is_3d(Map))) {
- if (!table_colors_flag && !cats_color_flag && !z_color_flag)
- D_RGB_color(color->r, color->g, color->b);
- else {
- if (custom_rgb)
- D_RGB_color((unsigned char)red, (unsigned char)grn,
- (unsigned char)blu);
- else
- D_RGB_color(color->r, color->g, color->b);
- }
-
- /* Plot the lines */
- if (Points->n_points == 1) /* line with one coor */
- D_polydots_abs(x, y, Points->n_points);
- else /*use different user defined render methods */
- D_polyline_abs(x, y, Points->n_points);
- }
-
- switch (ltype) {
- case GV_POINT:
- n_points++;
- break;
- case GV_LINE:
- n_lines++;
- break;
- case GV_CENTROID:
- n_centroids++;
- break;
- case GV_BOUNDARY:
- n_boundaries++;
- break;
- case GV_FACE:
- n_faces++;
- break;
- default:
- break;
- }
- }
-
- if (nerror_rgb > 0) {
- G_warning(_("Error in color definition column '%s': %d features affected"),
- rgb_column, nerror_rgb);
- }
-
- if (n_points > 0)
- G_verbose_message(_("%d points plotted"), n_points);
- if (n_lines > 0)
- G_verbose_message(_("%d lines plotted"), n_lines);
- if (n_centroids > 0)
- G_verbose_message(_("%d centroids plotted"), n_centroids);
- if (n_boundaries > 0)
- G_verbose_message(_("%d boundaries plotted"), n_boundaries);
- if (n_faces > 0)
- G_verbose_message(_("%d faces plotted"), n_faces);
-
- Vect_destroy_line_struct(Points);
- Vect_destroy_cats_struct(Cats);
-
- return 0; /* not reached */
-}
Added: grass/trunk/display/d.vect/shape.c
===================================================================
--- grass/trunk/display/d.vect/shape.c (rev 0)
+++ grass/trunk/display/d.vect/shape.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -0,0 +1,184 @@
+#include <grass/vector.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+int display_shape(struct Map_info *Map, int type, int area, struct cat_list *Clist, const struct Cell_head *window,
+ const struct color_rgb *bcolor, const struct color_rgb *fcolor, int chcat,
+ const char *icon, double size, const char *size_column, int sqrt_flag, const char *rot_column, /* lines only */
+ int id_flag, int table_colors_flag, int cats_colors_flag, char *rgb_column,
+ int default_width, char *width_column, double width_scale,
+ int z_color_flag, char *z_column)
+{
+ int open_db, field, i, stat;
+ dbCatValArray cvarr_rgb, cvarr_width, cvarr_size, cvarr_rot;
+ struct field_info *fi;
+ dbDriver *driver;
+ int nrec_rgb, nrec_width, nrec_size, nrec_rot;
+
+ stat = 0;
+ nrec_rgb = nrec_width = nrec_size = nrec_rot = 0;
+
+ open_db = table_colors_flag || width_column || size_column || rot_column;
+ if (open_db) {
+ field = Clist->field > 0 ? Clist->field : 1;
+ fi = Vect_get_field(Map, field);
+ if (!fi) {
+ G_fatal_error(_("Database connection not defined for layer %d"),
+ field);
+ }
+
+ driver = db_start_driver_open_database(fi->driver, fi->database);
+ if (!driver)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ fi->database, fi->driver);
+ }
+
+ if (table_colors_flag) {
+ /* for reading RRR:GGG:BBB color strings from table */
+ if (!rgb_column || *rgb_column == '\0')
+ G_fatal_error(_("Color definition column not specified"));
+
+ db_CatValArray_init(&cvarr_rgb);
+
+ nrec_rgb = db_select_CatValArray(driver, fi->table, fi->key,
+ rgb_column, NULL, &cvarr_rgb);
+
+ G_debug(3, "nrec_rgb (%s) = %d", rgb_column, nrec_rgb);
+
+ if (cvarr_rgb.ctype != DB_C_TYPE_STRING)
+ G_fatal_error(_("Color definition column (%s) not a string. "
+ "Column must be of form RRR:GGG:BBB where RGB values range 0-255."),
+ rgb_column);
+
+
+ if (nrec_rgb < 0)
+ G_fatal_error(_("Unable to select data (%s) from table"),
+ rgb_column);
+
+ G_debug(2, "\n%d records selected from table", nrec_rgb);
+
+ for (i = 0; i < cvarr_rgb.n_values; i++) {
+ G_debug(4, "cat = %d %s = %s", cvarr_rgb.value[i].cat,
+ rgb_column, db_get_string(cvarr_rgb.value[i].val.s));
+ }
+ }
+
+ if (width_column) {
+ if (*width_column == '\0')
+ G_fatal_error(_("Line width column not specified"));
+
+ db_CatValArray_init(&cvarr_width);
+
+ nrec_width = db_select_CatValArray(driver, fi->table, fi->key,
+ width_column, NULL, &cvarr_width);
+
+ G_debug(3, "nrec_width (%s) = %d", width_column, nrec_width);
+
+ if (cvarr_width.ctype != DB_C_TYPE_INT &&
+ cvarr_width.ctype != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Line width column (%s) not a number"),
+ width_column);
+
+ if (nrec_width < 0)
+ G_fatal_error(_("Unable to select data (%s) from table"),
+ width_column);
+
+ G_debug(2, "\n%d records selected from table", nrec_width);
+
+ for (i = 0; i < cvarr_width.n_values; i++) {
+ G_debug(4, "cat = %d %s = %d", cvarr_width.value[i].cat,
+ width_column,
+ (cvarr_width.ctype ==
+ DB_C_TYPE_INT ? cvarr_width.value[i].val.
+ i : (int)cvarr_width.value[i].val.d));
+ }
+ }
+
+ if (size_column) {
+ if (*size_column == '\0')
+ G_fatal_error(_("Symbol size column not specified"));
+
+ db_CatValArray_init(&cvarr_size);
+
+ nrec_size = db_select_CatValArray(driver, fi->table, fi->key,
+ size_column, NULL, &cvarr_size);
+
+ G_debug(3, "nrec_size (%s) = %d", size_column, nrec_size);
+
+ if (cvarr_size.ctype != DB_C_TYPE_INT &&
+ cvarr_size.ctype != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Symbol size column (%s) is not numeric"),
+ size_column);
+
+ if (nrec_size < 0)
+ G_fatal_error(_("Unable to select data (%s) from table"),
+ size_column);
+
+ G_debug(2, " %d records selected from table", nrec_size);
+
+ for (i = 0; i < cvarr_size.n_values; i++) {
+ G_debug(4, "(size) cat = %d %s = %.2f", cvarr_size.value[i].cat,
+ size_column,
+ (cvarr_size.ctype ==
+ DB_C_TYPE_INT ? (double)cvarr_size.value[i].val.i
+ : cvarr_size.value[i].val.d));
+ }
+ }
+
+ if (rot_column) {
+ if (*rot_column == '\0')
+ G_fatal_error(_("Symbol rotation column not specified"));
+
+ db_CatValArray_init(&cvarr_rot);
+
+ nrec_rot = db_select_CatValArray(driver, fi->table, fi->key,
+ rot_column, NULL, &cvarr_rot);
+
+ G_debug(3, "nrec_rot (%s) = %d", rot_column, nrec_rot);
+
+ if (cvarr_rot.ctype != DB_C_TYPE_INT &&
+ cvarr_rot.ctype != DB_C_TYPE_DOUBLE)
+ G_fatal_error(_("Symbol rotation column (%s) is not numeric"),
+ rot_column);
+
+ if (nrec_rot < 0)
+ G_fatal_error(_("Unable to select data (%s) from table"),
+ rot_column);
+
+ G_debug(2, " %d records selected from table", nrec_rot);
+
+ for (i = 0; i < cvarr_rot.n_values; i++) {
+ G_debug(4, "(rot) cat = %d %s = %.2f", cvarr_rot.value[i].cat,
+ rot_column,
+ (cvarr_rot.ctype ==
+ DB_C_TYPE_INT ? (double)cvarr_rot.value[i].val.i
+ : cvarr_rot.value[i].val.d));
+ }
+ }
+
+ if (open_db)
+ db_close_database_shutdown_driver(driver);
+
+ stat = 0;
+ if (area)
+ stat += display_area(Map, Clist, window,
+ bcolor, fcolor, chcat,
+ id_flag, table_colors_flag, cats_colors_flag,
+ rgb_column, default_width, width_column, width_scale,
+ z_color_flag, z_column,
+ &cvarr_rgb, &cvarr_width, nrec_width);
+
+
+ stat += display_lines(Map, type, Clist,
+ bcolor, fcolor, chcat,
+ icon, size, size_column, sqrt_flag, rot_column,
+ id_flag, table_colors_flag, cats_colors_flag,
+ rgb_column, default_width, width_column, width_scale,
+ z_color_flag, z_column,
+ &cvarr_rgb, &cvarr_width, nrec_width,
+ &cvarr_size, nrec_size, &cvarr_rot, nrec_rot);
+
+ return stat;
+}
Property changes on: grass/trunk/display/d.vect/shape.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/display/d.vect/topo.c
===================================================================
--- grass/trunk/display/d.vect/topo.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/topo.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -5,7 +5,7 @@
#include "local_proto.h"
#include "plot.h"
-int topo(struct Map_info *Map, int type, int do_area, LATTR *lattr)
+int display_topo(struct Map_info *Map, int type, int do_area, LATTR *lattr)
{
int ltype, num, el;
struct line_pnts *Points;
@@ -13,6 +13,13 @@
char text[50];
LATTR lattr2 = *lattr;
+ if (Vect_level(Map) < 2) {
+ G_warning(_("Unable to display topology, not available."
+ "Please try to rebuild topology using "
+ "v.build or v.build.all."));
+ return 1;
+ }
+
lattr2.xref = lattr->xref == LRIGHT ? LLEFT : LRIGHT;
G_debug(1, "display topo:");
@@ -39,8 +46,7 @@
G_debug(3, "ltype = %d", ltype);
switch (ltype) {
case -1:
- fprintf(stderr, _("\nERROR: vector map - can't read\n"));
- return -1;
+ G_fatal_error(_("Unable to read vector map"));
case -2: /* EOF */
return 0;
}
Deleted: grass/trunk/display/d.vect/utils.c
===================================================================
--- grass/trunk/display/d.vect/utils.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/utils.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -1,84 +0,0 @@
-#include <grass/gis.h>
-#include <grass/vector.h>
-#include <grass/display.h>
-#include <grass/glocale.h>
-#include "local_proto.h"
-#include "plot.h"
-
-void show_label(double *px, double *py, LATTR *lattr, const char *text)
-{
- double X = *px, Y = *py;
- int Xoffset, Yoffset;
- double xarr[5], yarr[5];
- double T, B, L, R;
-
- X = X + D_get_d_to_u_xconv() * 0.5 * lattr->size;
- Y = Y + D_get_d_to_u_yconv() * 1.5 * lattr->size;
-
- D_pos_abs(X, Y);
- D_get_text_box(text, &T, &B, &L, &R);
-
- /* Expand border 1/2 of text size */
- T = T - D_get_d_to_u_yconv() * lattr->size / 2;
- B = B + D_get_d_to_u_yconv() * lattr->size / 2;
- L = L - D_get_d_to_u_xconv() * lattr->size / 2;
- R = R + D_get_d_to_u_xconv() * lattr->size / 2;
-
- Xoffset = 0;
- Yoffset = 0;
- if (lattr->xref == LCENTER)
- Xoffset = -(R - L) / 2;
- if (lattr->xref == LRIGHT)
- Xoffset = -(R - L);
- if (lattr->yref == LCENTER)
- Yoffset = -(B - T) / 2;
- if (lattr->yref == LBOTTOM)
- Yoffset = -(B - T);
-
- if (lattr->has_bgcolor || lattr->has_bcolor) {
- xarr[0] = xarr[1] = xarr[4] = L + Xoffset;
- xarr[2] = xarr[3] = R + Xoffset;
- yarr[0] = yarr[3] = yarr[4] = B + Yoffset;
- yarr[1] = yarr[2] = T + Yoffset;
-
- if (lattr->has_bgcolor) {
- D_RGB_color(lattr->bgcolor.R, lattr->bgcolor.G,
- lattr->bgcolor.B);
- D_polygon_abs(xarr, yarr, 5);
- }
-
- if (lattr->has_bcolor) {
- D_RGB_color(lattr->bcolor.R, lattr->bcolor.G,
- lattr->bcolor.B);
- D_polyline_abs(xarr, yarr, 5);
- }
- D_RGB_color(lattr->color.R, lattr->color.G, lattr->color.B);
- }
-
- D_pos_abs(X + Xoffset, Y + Yoffset);
- D_text(text);
-}
-
-void show_label_line(const struct line_pnts *Points, int ltype, LATTR *lattr, const char *text)
-{
- double X, Y;
-
- if ((ltype & GV_POINTS) || Points->n_points == 1)
- /* point/centroid or line/boundary with one coor */
- {
- X = Points->x[0];
- Y = Points->y[0];
- }
- else if (Points->n_points == 2) { /* line with two coors */
- X = (Points->x[0] + Points->x[1]) / 2;
- Y = (Points->y[0] + Points->y[1]) / 2;
- }
- else {
- int i = Points->n_points / 2;
- X = Points->x[i];
- Y = Points->y[i];
- }
-
- show_label(&X, &Y, lattr, text);
-}
-
Modified: grass/trunk/display/d.vect/zcoor.c
===================================================================
--- grass/trunk/display/d.vect/zcoor.c 2011-08-07 16:48:34 UTC (rev 47484)
+++ grass/trunk/display/d.vect/zcoor.c 2011-08-07 18:16:56 UTC (rev 47485)
@@ -3,10 +3,12 @@
#include <grass/gis.h>
#include <grass/vector.h>
#include <grass/display.h>
+#include <grass/glocale.h>
+
#include "local_proto.h"
#include "plot.h"
-int zcoor(struct Map_info *Map, int type, LATTR *lattr)
+int display_zcoor(struct Map_info *Map, int type, LATTR *lattr)
{
int num, el;
double xl, yl, zl;
@@ -14,6 +16,11 @@
struct line_cats *Cats;
char text[50];
+ if (!Vect_is_3d(Map)) {
+ G_warning(_("Vector map is not 3D. Unable to display z-coordinates."));
+ return 1;
+ }
+
G_debug(1, "display zcoor:");
Points = Vect_new_line_struct();
Cats = Vect_new_cats_struct();
@@ -27,7 +34,6 @@
Vect_rewind(Map);
-
num = Vect_get_num_nodes(Map);
G_debug(1, "n_nodes = %d", num);
More information about the grass-commit
mailing list