20 #include <grass/gis.h>
21 #include <grass/symbol.h>
22 #include <grass/glocale.h>
24 static char key[100],
data[500];
37 G_debug(3,
" get_key_data(): %s", buf);
62 p = (SYMBOL *) G_malloc(
sizeof(SYMBOL));
73 if (s->count == s->alloc) {
76 (SYMBPART **) G_realloc(s->part, s->alloc *
sizeof(SYMBPART *));
78 s->part[s->count] = p;
88 p = (SYMBPART *) G_malloc(
sizeof(SYMBPART));
93 p->color.color = S_COL_DEFAULT;
94 p->fcolor.color = S_COL_DEFAULT;
101 if (p->count == p->alloc) {
104 (SYMBCHAIN **) G_realloc(p->chain,
105 p->alloc *
sizeof(SYMBCHAIN *));
107 p->chain[p->count] =
s;
118 p = (SYMBCHAIN *) G_malloc(
sizeof(SYMBCHAIN));
132 if (s->count == s->alloc) {
134 s->elem = (SYMBEL **) G_realloc(s->elem, s->alloc *
sizeof(SYMBEL *));
136 s->elem[s->count] = e;
146 p = (SYMBEL *) G_malloc(
sizeof(SYMBEL));
148 p->coor.line.count = 0;
149 p->coor.line.alloc = 0;
150 p->coor.line.x =
NULL;
151 p->coor.line.y =
NULL;
158 if (el->coor.line.count == el->coor.line.alloc) {
159 el->coor.line.alloc += 10;
161 (
double *)G_realloc(el->coor.line.x,
162 el->coor.line.alloc *
sizeof(
double));
164 (
double *)G_realloc(el->coor.line.y,
165 el->coor.line.alloc *
sizeof(
double));
167 el->coor.line.x[el->coor.line.count] = x;
168 el->coor.line.y[el->coor.line.count] =
y;
169 el->coor.line.count++;
173 SYMBEL *
new_arc(
double x,
double y,
double r,
double a1,
double a2,
int c)
177 p = (SYMBEL *) G_malloc(
sizeof(SYMBEL));
179 p->coor.arc.clock = c;
196 while (
G_getl2(buf, 500, fp) != 0) {
200 if ((buf[0] ==
'#') || (buf[0] ==
'\0'))
205 if (strcmp(key,
"END") == 0) {
210 if (sscanf(buf,
"%lf %lf", &x, &y) != 2) {
211 G_warning(_(
"Cannot read symbol line coordinates: %s"), buf);
214 G_debug(5,
" x = %f y = %f", x, y);
239 char group[500],
name[500],
buf[2001];
241 double x,
y, x2, y2, rad, ang1, ang2;
252 G_debug(3,
"S_read(): sname = %s", sname);
256 strcpy(group, sname);
257 c = strchr(group,
'/');
259 G_warning(_(
"Incorrect symbol name: '%s' (should be: group/name or group/name@mapset)"),
268 G_debug(3,
" group: '%s' name: '%s'", group, name);
271 sprintf(buf,
"symbol/%s", group);
279 fp = fopen(buf,
"r");
283 G_warning(_(
"Cannot find/open symbol: '%s'"), sname);
293 while (
G_getl2(buf, 2000, fp) != 0) {
298 if ((buf[0] ==
'#') || (buf[0] ==
'\0'))
303 if (strcmp(key,
"VERSION") == 0) {
304 if (strcmp(
data,
"1.0") != 0) {
306 return (
err(fp, symb, buf));
309 else if (strcmp(key,
"BOX") == 0) {
310 if (sscanf(
data,
"%lf %lf %lf %lf", &x, &y, &x2, &y2) != 4) {
311 sprintf(buf,
"Incorrect box definition: '%s'",
data);
312 return (
err(fp, symb, buf));
315 symb->scale = 1 / (x2 - x);
317 symb->scale = 1 / (y2 -
y);
319 else if (strcmp(key,
"STRING") == 0) {
328 else if (strcmp(key,
"POLYGON") == 0) {
335 else if (strcmp(key,
"RING") == 0) {
342 else if (strcmp(key,
"LINE") == 0) {
349 else if (strcmp(key,
"ARC") == 0) {
352 sscanf(
data,
"%lf %lf %lf %lf %lf %c", &x, &y, &rad, &ang1,
355 sprintf(buf,
"Incorrect arc definition: '%s'", buf);
356 return (
err(fp, symb, buf));
358 if (ret == 6 && (clock ==
'c' || clock ==
'C'))
362 elem =
new_arc(x, y, rad, ang1, ang2, i);
366 else if (strcmp(key,
"END") == 0) {
382 else if (strcmp(key,
"COLOR") == 0) {
384 part->color.color = S_COL_NONE;
386 else if (sscanf(
data,
"%d %d %d", &r, &g, &b) == 3) {
387 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
388 G_warning(_(
"Incorrect symbol color: '%s', using default."),
394 part->color.color = S_COL_DEFINED;
401 G_debug(4,
" color [%d %d %d] = [%.3f %.3f %.3f]", r, g,
406 G_warning(_(
"Incorrect symbol color: '%s', using default."),
410 else if (strcmp(key,
"FCOLOR") == 0) {
412 part->fcolor.color = S_COL_NONE;
414 else if (sscanf(
data,
"%d %d %d", &r, &g, &b) == 3) {
415 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
416 G_warning(_(
"Incorrect symbol color: '%s', using default."),
422 part->fcolor.color = S_COL_DEFINED;
426 part->fcolor.fr = fr;
427 part->fcolor.fg = fg;
428 part->fcolor.fb = fb;
429 G_debug(4,
" color [%d %d %d] = [%.3f %.3f %.3f]", r, g,
434 G_warning(_(
"Incorrect symbol color: '%s', using default."),
439 sprintf(buf,
"Unknown keyword in symbol: '%s'", buf);
440 return (
err(fp, symb, buf));
447 G_debug(3,
"Number of parts: %d", symb->count);
448 for (i = 0; i < symb->count; i++) {
449 part = symb->part[i];
450 G_debug(4,
" Part %d: type: %d number of chains: %d", i, part->type,
452 G_debug(4,
" color: %d: fcolor: %d", part->color.color,
454 for (j = 0; j < part->count; j++) {
455 chain = part->chain[j];
456 G_debug(4,
" Chain %d: number of elements: %d", j,
458 for (k = 0; k < chain->count; k++) {
459 elem = chain->elem[k];
460 G_debug(4,
" Element %d: type: %d", k, elem->type);
461 if (elem->type == S_LINE) {
462 G_debug(4,
" Number of points %d",
463 elem->coor.line.count);
464 for (l = 0; l < elem->coor.line.count; l++) {
466 elem->coor.line.x[l], elem->coor.line.y[l]);
470 G_debug(4,
" arc r = %f", elem->coor.arc.r);
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
void read_coor(FILE *fp, SYMBEL *e)
SYMBCHAIN * new_chain(void)
void get_key_data(char *buf)
SYMBOL * new_symbol(void)
SYMBEL * new_arc(double x, double y, double r, double a1, double a2, int c)
char * G_chop(char *line)
Chop leading and trailing white spaces:
void add_element(SYMBCHAIN *s, SYMBEL *e)
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
void add_chain(SYMBPART *p, SYMBCHAIN *s)
SYMBOL * S_read(char *sname)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
SYMBPART * new_part(int type)
char * G_gisbase(void)
top level module directory
char * G_find_file(const char *element, char *name, const char *mapset)
searches for a file from the mapset search list or in a specified mapset. returns the mapset name whe...
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
void add_part(SYMBOL *s, SYMBPART *p)
void add_point(SYMBEL *el, double x, double y)