]> mj.ucw.cz Git - leo.git/commitdiff
Support for fixed objects
authorMartin Mares <mj@ucw.cz>
Mon, 16 Jun 2014 09:40:35 +0000 (11:40 +0200)
committerMartin Mares <mj@ucw.cz>
Mon, 16 Jun 2014 09:40:35 +0000 (11:40 +0200)
Makefile
TODO
fixed.c [new file with mode: 0644]
fixed.h [new file with mode: 0644]
map.c
map.cf
map.h

index f2a7361ea73f1349aa371e7adb4026535675b06e..447963c78ef6fc15b7f18250d6fa1fe90ce784ff 100644 (file)
--- 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 925cf329d37f17e2b71945188882ea6b5e130353..2977c8326286cc47bf302a580f8c76ff0b21140e 100644 (file)
--- 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 (file)
index 0000000..53acdf2
--- /dev/null
+++ b/fixed.c
@@ -0,0 +1,75 @@
+/*
+ *     Hic Est Leo -- Fixed Objects
+ *
+ *     (c) 2014 Martin Mares <mj@ucw.cz>
+ */
+
+#include <ucw/lib.h>
+#include <ucw/conf.h>
+
+#include <stdio.h>
+
+#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 (file)
index 0000000..47345b7
--- /dev/null
+++ b/fixed.h
@@ -0,0 +1,12 @@
+/*
+ *     Hic Est Leo -- Fixed Objects
+ *
+ *     (c) 2014 Martin Mares <mj@ucw.cz>
+ */
+
+#ifndef _LEO_FIXED_H
+#define _LEO_FIXED_H
+
+void fixed_add(void);
+
+#endif
diff --git a/map.c b/map.c
index 2aab9e2c66cdbe2687187277e37bc99ccea5de97..8f318e23e9427bafa5a65a7baf5417a2d1ed68ad 100644 (file)
--- 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 c55a3e745f8f9df443d751584163314eee821034..92a2435409b2412594140eb2a2845ac1f7599ccf 100644 (file)
--- 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 f031f7b65fdfd5d74c932bbb0f888fedbc3aa8c3..2fa4f89bbbc6d1b2c94c309eae09d716f556d328 100644 (file)
--- 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 {