From af80b4c6ce10632dfda42b6f93634c4ad5f5e3f5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 16 Jun 2014 11:40:35 +0200 Subject: [PATCH] Support for fixed objects --- Makefile | 2 +- TODO | 2 +- fixed.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fixed.h | 12 +++++++++ map.c | 38 ++++++++++++++++++++-------- map.cf | 16 ++++++++++++ map.h | 1 + 7 files changed, 134 insertions(+), 12 deletions(-) create mode 100644 fixed.c create mode 100644 fixed.h diff --git a/Makefile b/Makefile index f2a7361..447963c 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ include $(BUILDSYS)/Maketop PROGS+=$(o)/leo CFLAGS+=$(LIBUCW_CFLAGS) -LEO_MODULES=leo xml osm svg svg-icon css-parse css-lex style css dict sym sym-point sym-line sym-text map shp +LEO_MODULES=leo xml osm svg svg-icon css-parse css-lex style css dict sym sym-point sym-line sym-text map shp fixed LEO_OBJECTS=$(addprefix $(o)/, $(addsuffix .o, $(LEO_MODULES))) $(o)/leo: $(LEO_OBJECTS) diff --git a/TODO b/TODO index 925cf32..2977c83 100644 --- a/TODO +++ b/TODO @@ -3,4 +3,4 @@ should override each other, but currently they are mixed upon rendering. Does it matter? - Fixing of label positions should include some margin -- Clean up Makefile +- Clean up shp.c diff --git a/fixed.c b/fixed.c new file mode 100644 index 0000000..53acdf2 --- /dev/null +++ b/fixed.c @@ -0,0 +1,75 @@ +/* + * Hic Est Leo -- Fixed Objects + * + * (c) 2014 Martin Mares + */ + +#include +#include + +#include + +#include "leo.h" +#include "osm.h" +#include "fixed.h" + +struct fixed_tag { + cnode n; + char *key, *val; +}; + +struct fixed_object { + cnode n; + double x, y; + clist tags; +}; + +static clist fixed_objects; + +static struct cf_section fixed_tag_cf = { +#define P(_x) PTR_TO(struct fixed_tag, _x) + CF_TYPE(struct fixed_object), + CF_ITEMS { + CF_STRING("Key", P(key)), + CF_STRING("Value", P(val)), + CF_END + } +#undef P +}; + +static struct cf_section fixed_object_cf = { +#define P(_x) PTR_TO(struct fixed_object, _x) + CF_TYPE(struct fixed_object), + CF_ITEMS { + CF_DOUBLE("X", P(x)), + CF_DOUBLE("Y", P(y)), + CF_LIST("Tag", P(tags), &fixed_tag_cf), + CF_END + } +#undef P +}; + +static struct cf_section fixed_cf = { + CF_ITEMS { + CF_LIST("Object", &fixed_objects, &fixed_object_cf), + CF_END + } +}; + +static void CONSTRUCTOR fixed_preinit(void) +{ + cf_declare_section("FixedObjects", &fixed_cf, 0); +} + +void fixed_add(void) +{ + u64 id = 1; + CLIST_FOR_EACH(struct fixed_object *, fo, fixed_objects) + { + struct osm_node *n = osm_node_new(id++); + n->x = fo->x; + n->y = fo->y; + CLIST_FOR_EACH(struct fixed_tag *, ft, fo->tags) + osm_obj_add_tag(&n->o, ft->key, ft->val); + } +} diff --git a/fixed.h b/fixed.h new file mode 100644 index 0000000..47345b7 --- /dev/null +++ b/fixed.h @@ -0,0 +1,12 @@ +/* + * Hic Est Leo -- Fixed Objects + * + * (c) 2014 Martin Mares + */ + +#ifndef _LEO_FIXED_H +#define _LEO_FIXED_H + +void fixed_add(void); + +#endif diff --git a/map.c b/map.c index 2aab9e2..8f318e2 100644 --- a/map.c +++ b/map.c @@ -18,6 +18,7 @@ #include "map.h" #include "css.h" #include "sym.h" +#include "fixed.h" double map_min_x, map_min_y; double map_max_x, map_max_y; @@ -42,6 +43,7 @@ static struct cf_section map_style_cf = { static const char * const map_formats[] = { "invalid", "osmxml", + "fixed", }; static struct cf_section map_source_cf = { @@ -217,29 +219,45 @@ static void map_load_source(struct data_source *ds) { ds->osm = osm_init(); + bool need_mp = 0; + bool need_proj = 0; + switch (ds->format) { case DATA_SOURCE_OSMXML: msg(L_INFO, "Parsing %s as OSM XML", ds->file); + if (!ds->file) + die("OSM XML data sources must have a file name"); osm_xml_parse(ds->file); - if (debug_dump_source) - { - puts("=== Source data ==="); - osm_dump(); - } - osm_make_multipolygons(); + need_mp = 1; + need_proj = 1; + break; + case DATA_SOURCE_FIXED: + msg(L_INFO, "Adding fixed objects"); + fixed_add(); break; default: die("Invalid data source format"); } - msg(L_INFO, "Projecting"); - osm_project(map_projection); - if (debug_dump_after_proj) + if (debug_dump_source) { - puts("=== Map after projection ==="); + puts("=== Source data ==="); osm_dump(); } + if (need_mp) + osm_make_multipolygons(); + + if (need_proj) + { + msg(L_INFO, "Projecting"); + osm_project(map_projection); + if (debug_dump_after_proj) + { + puts("=== Map after projection ==="); + osm_dump(); + } + } } void map_load_sources(void) diff --git a/map.cf b/map.cf index c55a3e7..92a2435 100644 --- a/map.cf +++ b/map.cf @@ -6,12 +6,18 @@ Map { # File format: # osmxml OpenStreetMap XML + # fixed Fixed objects (no File used, see FixedObjects section below) Format osmxml # MapCSS stylesheet to apply (multiple style-sheets are allowed) StyleSheet poskole.css } + Source { + Format fixed + StyleSheet poskole.css + } + # Projection of our map Projection "+proj=utm +zone=33 +ellps=WGS84" @@ -42,6 +48,16 @@ Map { SVGOutput output.svg } +FixedObjects { + # Fixed objects may be placed at specific positions on the paper + # with specific tags. Remember to enable the "fixed" data source. + Object { + X 100 + Y 100 + Tag legend logo + } +} + Debug { # Dump map data exactly as parsed DumpSource 0 diff --git a/map.h b/map.h index f031f7b..2fa4f89 100644 --- a/map.h +++ b/map.h @@ -22,6 +22,7 @@ extern char *map_svg_output; enum data_source_type { DATA_SOURCE_INVALID, DATA_SOURCE_OSMXML, + DATA_SOURCE_FIXED, }; struct data_source { -- 2.39.2