10 #include "lab-bitmaps.h"
11 #include "lab-utils.h"
12 #include "lab-evolution.h"
13 #include "lab-lines.h"
15 struct request_point *requests_point = NULL;
16 struct request_line *requests_line = NULL;
17 struct request_area *requests_area = NULL;
19 struct longline *longlines = NULL;
20 struct buffer_line *buffer_line = NULL;
21 struct buffer_linelabel *buffer_linelabel = NULL;
23 int dbg_segments = VERBOSITY_NONE;
24 int dbg_plan = VERBOSITY_NONE;
25 int dbg_requests = VERBOSITY_NONE;
26 int dbg_graph = VERBOSITY_NONE;
27 int dbg_bfs = VERBOSITY_NONE;
28 int dbg_map_parts = VERBOSITY_NONE;
29 int dbg_movement = VERBOSITY_NONE;
30 int dbg_init = VERBOSITY_NONE;
31 int dbg_overlaps = VERBOSITY_GENERAL;
32 int dbg_rank = VERBOSITY_NONE;
33 int dbg_evolution = VERBOSITY_POPULATION;
34 int dbg_mutation = VERBOSITY_NONE;
35 int dbg_breeding = VERBOSITY_NONE;
37 int page_width_int = 0;
38 int page_height_int = 0;
41 int num_placements = 0;
44 int conf_map_part_width = 5;
45 int conf_map_part_height = 5;
47 uns num_map_parts_row = 0;
48 uns num_map_parts_col = 0;
49 uns num_map_parts = 0;
51 static struct cf_section labelling_cf = {
53 CF_DOUBLE("MaxSectionLenght", &conf_max_section_length),
54 CF_DOUBLE("MaxSectionOverlay", &conf_max_section_overlay),
55 CF_DOUBLE("BitmapGranularity", &bitmap_granularity),
60 static void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t zindex);
61 static void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t zindex);
63 static void compute_sizes(void);
65 static void compute_sizes(void)
67 page_width_int = floor(page_width);
68 page_height_int = floor(page_height);
70 page_width_gran = page_width * bitmap_granularity;
71 page_height_gran = page_height * bitmap_granularity;
73 num_map_parts_row = (page_width_int + conf_map_part_width) / conf_map_part_width;
74 num_map_parts_col = (page_height_int + conf_map_part_height) / conf_map_part_height;
75 num_map_parts = num_map_parts_row * num_map_parts_col;
79 void labeller_conf(void)
81 cf_declare_section("Labelling", &labelling_cf, 0);
85 void labeller_init(void)
89 GARY_INIT(requests_point, 0);
90 GARY_INIT(requests_line, 0);
91 GARY_INIT(requests_area, 0);
92 GARY_INIT(buffer_line, 0);
93 GARY_INIT(buffer_linelabel, 0);
97 void labeller_add_point(struct symbol *sym, struct osm_object *object, z_index_t zindex)
99 DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding point\n");
100 if (object->type != OSM_TYPE_NODE)
102 printf("Warning: Point label requested on non-point object\n");
106 struct request_point *r = GARY_PUSH(requests_point);
108 r->request.type = REQUEST_POINT;
109 r->request.ind = num_requests++;
114 GARY_INIT(r->request.variants, 0);
116 struct variant *v = GARY_PUSH(r->request.variants);
118 struct osm_node *n = (struct osm_node *) object; // FIXME: Compiler warning
124 case SYMBOLIZER_ICON:
126 r->x = ((struct sym_icon *)sym)->sir.x;
127 r->y = ((struct sym_icon *)sym)->sir.y;
134 DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Inited point to [%.2f; %.2f] on %u\n", r->x, r->y, r->zindex);
137 void labeller_notify_line(struct symbol *sym, z_index_t zindex)
139 DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding line on %u\n", zindex);
140 struct buffer_line *b = GARY_PUSH(buffer_line);
141 b->line = (struct sym_line *) sym;
144 void labeller_add_label(struct symbol *sym, struct osm_object *o, z_index_t zindex)
149 if (osm_way_cyclic_p((struct osm_way *) o))
150 labeller_add_arealabel(sym, o, zindex);
152 labeller_add_linelabel(sym, o, zindex);
159 static void labeller_add_linelabel(struct symbol *sym, struct osm_object *o, z_index_t zindex)
161 if (o->type != OSM_TYPE_WAY)
163 printf("Linelabel request on object which is not way\n");
167 DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Labelling way %ju on %u\n", o->id, zindex);
168 struct buffer_linelabel *ll = GARY_PUSH(buffer_linelabel);
169 ll->way = (struct osm_way *) o;
174 static void labeller_add_arealabel(struct symbol *sym, struct osm_object *o, z_index_t zindex)
176 DEBUG(dbg_requests, VERBOSITY_PLACEMENT, "Adding area on %u\n", zindex);
177 struct request_area *r = GARY_PUSH(requests_area);
179 r->request.type = REQUEST_AREA;
180 r->request.ind = num_requests++;
182 r->o = (struct osm_multipolygon *) o;
186 osm_obj_center(o, &(r->cx), &(r->cy));
188 GARY_INIT(r->request.variants, 0);
189 struct variant *v = GARY_PUSH(r->request.variants);
193 void labeller_label(void)
201 void labeller_cleanup(void)
204 GARY_FREE(longlines);
206 GARY_FREE(requests_point);
207 GARY_FREE(requests_area);
209 for (uns i=0; i<GARY_SIZE(requests_line); i++)
211 for (uns j=0; j<GARY_SIZE(requests_line[i].sections); j++)
213 GARY_FREE(requests_line[i].sections[j].segments);
215 GARY_FREE(requests_line[i].sections);
217 GARY_FREE(requests_line);