]> saetta.ns0.it Git - libgtkgis/commitdiff
Added initial support for layer's style.
authorAndrea Zagli <azagli@libero.it>
Wed, 5 Aug 2009 15:55:32 +0000 (17:55 +0200)
committerAndrea Zagli <azagli@libero.it>
Wed, 5 Aug 2009 15:55:32 +0000 (17:55 +0200)
17 files changed:
data/gtkgis.dtd
docs/reference/libgtkgis-decl-list.txt
docs/reference/libgtkgis-decl.txt
docs/reference/libgtkgis-undocumented.txt
docs/reference/libgtkgis-unused.txt
docs/reference/tmpl/geometry.sgml
src/commons.h
src/geometry.c
src/geometry.h
src/geometryline.c
src/geometrypoint.c
src/geometrypolygon.c
src/geometryraster.c
src/gtkgis.c
src/layer.c
src/layer.h
tests/test1.gtkgis

index 7150f4cb129a46a4ed9933a4141bb56874e2e103..b7d8922a7c5e769a8af11011c48b120584ceec5d 100644 (file)
@@ -2,7 +2,7 @@
 
 <!ELEMENT group (layer*)>
 
-<!ELEMENT layer (source)>
+<!ELEMENT layer (source, style?)>
 <!ATTLIST layer
        name CDATA #REQUIRED
        visible (y | n) "y"
@@ -27,3 +27,9 @@
 <!ATTLIST
        filename CDATA #REQUIRED
 >
+
+<!ELEMENT style (width?, stroke-color?, fill-color?)>
+
+<!ELEMENT width (#PCDATA)>
+<!ELEMENT stroke-color (#PCDATA)>
+<!ELEMENT fill-color (#PCDATA)>
index 35fd1d98db29ef54995bff98ff32133277368a0c..d13f871e741dd8c65b11e9bf2343a4ab7991cdf4 100644 (file)
@@ -120,6 +120,8 @@ gtk_gis_layer_remove_geometry
 gtk_gis_layer_get_extent
 gtk_gis_layer_get_editable
 gtk_gis_layer_set_editable
+gtk_gis_layer_get_style
+gtk_gis_layer_set_style
 gtk_gis_layer_draw
 </SECTION>
 
index d6e6f66bf704230e49a1698478f70bd259a7a2fa..bf232564e2eb1a8f0d7f65270f08b2951acdfe13 100644 (file)
@@ -523,6 +523,16 @@ GtkGisLayer *layer
 GtkGisLayer *layer,gboolean editable
 </FUNCTION>
 <FUNCTION>
+<NAME>gtk_gis_layer_get_style</NAME>
+<RETURNS>GtkGisLayerStyle *</RETURNS>
+GtkGisLayer *layer
+</FUNCTION>
+<FUNCTION>
+<NAME>gtk_gis_layer_set_style</NAME>
+<RETURNS>void </RETURNS>
+GtkGisLayer *layer, GtkGisLayerStyle style
+</FUNCTION>
+<FUNCTION>
 <NAME>gtk_gis_layer_draw</NAME>
 <RETURNS>void </RETURNS>
 GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale
@@ -639,7 +649,9 @@ struct _GtkGisGeometryClass
        {
                GObjectClass parent_class;
 
-               GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale);
+               GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
+                                       GtkGisScale *scale,
+                                       GtkGisLayerStyle style);
        };
 </STRUCT>
 <FUNCTION>
@@ -660,7 +672,7 @@ GtkGisGeometry *geometry, gboolean editable
 <FUNCTION>
 <NAME>gtk_gis_geometry_draw</NAME>
 <RETURNS>GooCanvasItem *</RETURNS>
-GtkGisGeometry *geometry, GtkGisScale *scale
+GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle style
 </FUNCTION>
 <MACRO>
 <NAME>TYPE_GTK_GIS_LAYER_SOURCE_POSTGIS</NAME>
index cdf5a9303865478f72a089f014467a380b33c298..0221b22980079a62b1289108f2f6ce7c2b77372b 100644 (file)
@@ -1,7 +1,7 @@
 11% symbol docs coverage.
-21 symbols documented.
+22 symbols documented.
 7 symbols incomplete.
-169 not documented.
+170 not documented.
 
 
 GTK_GIS
@@ -120,6 +120,7 @@ gtk_gis_layer_get_editable
 gtk_gis_layer_get_extent
 gtk_gis_layer_get_name
 gtk_gis_layer_get_source
+gtk_gis_layer_get_style
 gtk_gis_layer_get_type
 gtk_gis_layer_get_xml
 gtk_gis_layer_new (geometrytype, geometry_type)
index 84968bca0ff0ab16c407c22c66f4ec225414950b..4144b618118aca4c85a47c684fb7d741eca21dfa 100644 (file)
@@ -10,3 +10,5 @@ GtkGisLayerSourcePostgisClass
 GtkGisLayerSourceRasterClass
 GtkGisLayerSourceShpClass
 GtkGisLayersGroupClass
+gtk_gis_layer_get_style
+gtk_gis_layer_set_style
index e85927146f6c80fed11be5062c002d6178f93815..073d518cd9442b20e095209a9278debe941632a8 100644 (file)
@@ -103,6 +103,7 @@ GtkGisGeometry
 
 @geometry: 
 @scale: 
+@style: 
 @Returns: 
 
 
index 21e15c731cbec98e2010513dbb15fd2c39f7a500..5dcd2eed9ca5b8a244123d65b28057bd03159d2a 100644 (file)
@@ -39,14 +39,6 @@ typedef struct
                gdouble xy;
        } GtkGisScale;
 
-typedef enum
-       {
-               LAYER_GEOMETRY_TYPE_POINT,
-               LAYER_GEOMETRY_TYPE_LINE,
-               LAYER_GEOMETRY_TYPE_POLYGON,
-               LAYER_GEOMETRY_TYPE_RASTER
-       } GtkGisLayerGeometryType;
-
 typedef struct
        {
                gdouble min_x;
@@ -55,6 +47,21 @@ typedef struct
                gdouble max_y;
        } GtkGisLayerExtent;
 
+typedef struct
+       {
+               gdouble width;
+               gchar *stroke_color;
+               gchar *fill_color;
+       } GtkGisLayerStyle;
+
+typedef enum
+       {
+               LAYER_GEOMETRY_TYPE_POINT,
+               LAYER_GEOMETRY_TYPE_LINE,
+               LAYER_GEOMETRY_TYPE_POLYGON,
+               LAYER_GEOMETRY_TYPE_RASTER
+       } GtkGisLayerGeometryType;
+
 
 G_END_DECLS
 
index b4780244bd9ffce6d9fc6ddaa1883311ead4e295..ec07da48e3d31a2d56bf1a195b5cf0fd7cc0ec6c 100644 (file)
@@ -103,13 +103,15 @@ gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable)
  *
  */
 GooCanvasItem
-*gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale)
+*gtk_gis_geometry_draw (GtkGisGeometry *geometry,
+                        GtkGisScale *scale,
+                        GtkGisLayerStyle style)
 {
        GooCanvasItem *item = NULL;
 
        if (IS_GTK_GIS_GEOMETRY (geometry) && GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw != NULL)
                {
-                       item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry, scale);
+                       item = GTK_GIS_GEOMETRY_GET_CLASS (geometry)->draw (geometry, scale, style);
                }
 
        return item;
index 30d31a065782d3cd1b498377bb1656dc27cd008f..8fbf675e0b2ae74767ddc1aa7432783cf292254a 100644 (file)
@@ -50,7 +50,9 @@ struct _GtkGisGeometryClass
        {
                GObjectClass parent_class;
 
-               GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale);
+               GooCanvasItem *(*draw) (GtkGisGeometry *geometry,
+                                       GtkGisScale *scale,
+                                       GtkGisLayerStyle style);
        };
 
 GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
@@ -59,7 +61,9 @@ GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
 gboolean gtk_gis_geometry_get_editable (GtkGisGeometry *geometry);
 void gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable);
 
-GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale);
+GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry,
+                                      GtkGisScale *scale,
+                                      GtkGisLayerStyle style);
 
 
 G_END_DECLS
index 4341a58daab5a545a3699e1a9594bf821fd9a2be..15d10516e52e5d88dfdf5b5e834442cab7c9bd2f 100644 (file)
@@ -32,7 +32,9 @@ static void gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_lin
 
 static gchar *convert_comma_to_dot (gchar *str);
 
-static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line,
+                                                  GtkGisScale *scale,
+                                                  GtkGisLayerStyle style);
 
 static void gtk_gis_geometry_line_set_property (GObject *object,
                                      guint property_id,
@@ -183,7 +185,9 @@ static gchar
 }
 
 static GooCanvasItem
-*gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale)
+*gtk_gis_geometry_line_draw (GtkGisGeometry *line,
+                             GtkGisScale *scale,
+                             GtkGisLayerStyle style)
 {
        GtkGisGeometryLinePrivate *priv;
        GooCanvasItem *item = NULL;
@@ -216,7 +220,8 @@ static GooCanvasItem
                        path = convert_comma_to_dot (path);
                        item = goo_canvas_path_new (NULL,
                                                    path,
-                                                   "line-width", 0.5 / scale->xy,
+                                                   "line-width", style.width / scale->xy,
+                                                   "stroke-color", style.stroke_color,
                                                    NULL);
                }
 
index a0c05726c7b51af396ede3f91723232ffa258849..c970abfab1213298cbe12e4a4cb83bd1e6b26789 100644 (file)
@@ -30,7 +30,9 @@
 static void gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass);
 static void gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point);
 
-static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point,
+                                                   GtkGisScale *scale,
+                                                   GtkGisLayerStyle style);
 
 static void gtk_gis_geometry_point_set_property (GObject *object,
                                      guint property_id,
@@ -148,7 +150,9 @@ gtk_gis_geometry_point_get_y (GtkGisGeometryPoint *point)
 }
 
 static
-GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale)
+GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point,
+                                            GtkGisScale *scale,
+                                            GtkGisLayerStyle style)
 {
        GooCanvasItem *item = NULL;
 
@@ -159,8 +163,9 @@ GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *
                        item = goo_canvas_ellipse_new (NULL,
                                                       priv->point->x, priv->point->y,
                                                       0.5 / scale->x, 0.5 / scale->y,
-                                                      "line-width", 0.5 / scale->xy,
-                                                      "fill-color", "black",
+                                                      "line-width", style.width / scale->xy,
+                                                      "stroke-color", style.stroke_color,
+                                                      "fill-color", style.fill_color,
                                                       NULL);
                }
 
index 96e52cf774ef7287e976bbcb01f1a6137842ecaf..90aaa5075ffd7f0aa056cde9f1b0a15dc9dc8440 100644 (file)
@@ -30,7 +30,9 @@
 static void gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass);
 static void gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geometry_polygon);
 
-static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale);
+static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon,
+                                                     GtkGisScale *scale,
+                                                    GtkGisLayerStyle style);
 
 static void gtk_gis_geometry_polygon_set_property (GObject *object,
                                      guint property_id,
@@ -185,7 +187,9 @@ gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon,
 }
 
 static GooCanvasItem
-*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale)
+*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon,
+                                GtkGisScale *scale,
+                                GtkGisLayerStyle style)
 {
        GtkGisGeometryPolygonPrivate *priv;
        GooCanvasItem *polygon_item = NULL;
@@ -207,7 +211,7 @@ static GooCanvasItem
                        while (cur != NULL)
                                {
                                        line = (GtkGisGeometry *)cur->data;
-                                       item = gtk_gis_geometry_draw (line, scale);
+                                       item = gtk_gis_geometry_draw (line, scale, style);
 
                                        if (item != NULL)
                                                {
index 630c5242f50b6ed1b32acfab7a89b96c4c299358..dc9704409836d48c9ee9f493dc5472356dc1475a 100644 (file)
@@ -31,7 +31,9 @@ static void gtk_gis_geometry_raster_class_init (GtkGisGeometryRasterClass *klass
 static void gtk_gis_geometry_raster_init (GtkGisGeometryRaster *gtk_gis_geometry_raster);
 
 static
-GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale);
+GooCanvasItem *gtk_gis_geometry_raster_draw (GtkGisGeometry *raster,
+                                             GtkGisScale *scale,
+                                             GtkGisLayerStyle style);
 
 static void gtk_gis_geometry_raster_set_property (GObject *object,
                                      guint property_id,
@@ -114,7 +116,9 @@ GtkGisGeometry
 }
 
 static GooCanvasItem
-*gtk_gis_geometry_raster_draw (GtkGisGeometry *raster, GtkGisScale *scale)
+*gtk_gis_geometry_raster_draw (GtkGisGeometry *raster,
+                               GtkGisScale *scale,
+                               GtkGisLayerStyle style)
 {
        GooCanvasItem *item = NULL;
 
index 1708a127a793c4da12abf9f5f4200e475a405e07..d176a07f6794a72bab87d62abf38852f6b3ab239 100644 (file)
@@ -208,6 +208,7 @@ GtkWidget
                                                                {
                                                                        xmlNode *xml_layer;
                                                                        gchar *layer_name;
+                                                                       GtkGisLayer *layer;
 
                                                                        xml_layer = cur;
 
@@ -219,6 +220,9 @@ GtkWidget
                                                                                        layer_name = g_strdup_printf ("layer");
                                                                                }
 
+                                                                       /* TO DO
+                                                                        * don't use a cycle: first find source and then style
+                                                                        */
                                                                        cur = cur->children;
                                                                        while (cur != NULL)
                                                                                {
@@ -238,7 +242,6 @@ GtkWidget
                                                                                                                                || xmlStrcmp (cur->name, "raster") == 0))
                                                                                                                                {
                                                                                                                                        xmlNode *xml_source_spec;
-                                                                                                                                       GtkGisLayer *layer = NULL;
                                                                                                                                        GtkGisLayerSource *layer_source = NULL;
 
                                                                                                                                        xml_source_spec = cur;
@@ -253,7 +256,7 @@ GtkWidget
                                                                                                                                                }
                                                                                                                                        else if (xmlStrcmp (cur->name, "raster") == 0)
                                                                                                                                                {
-                                                                                                                                                                       layer_source = gtk_gis_layer_source_raster_new_from_xml (cur);
+                                                                                                                                                       layer_source = gtk_gis_layer_source_raster_new_from_xml (cur);
                                                                                                                                                }
 
                                                                                                                                        if (layer_source != NULL)
@@ -268,6 +271,40 @@ GtkWidget
                                                                                                                }
                                                                                                        cur = xml_source;
                                                                                                }
+                                                                                       else if (cur->type == XML_ELEMENT_NODE
+                                                                                               && xmlStrcmp (cur->name, "style") == 0)
+                                                                                               {
+                                                                                                       xmlNode *xml_style;
+                                                                                                       GtkGisLayerStyle style;
+
+                                                                                                       xml_style = cur;
+
+                                                                                                       cur = cur->children;
+                                                                                                       while (cur != NULL)
+                                                                                                               {
+                                                                                                                       if (cur->type == XML_ELEMENT_NODE
+                                                                                                                               && (xmlStrcmp (cur->name, "width") == 0))
+                                                                                                                               {
+                                                                                                                                       style.width = g_strtod ((gchar *)xmlNodeGetContent (cur), NULL);
+                                                                                                                               }
+                                                                                                                       else if (cur->type == XML_ELEMENT_NODE
+                                                                                                                               && (xmlStrcmp (cur->name, "stroke-color") == 0))
+                                                                                                                               {
+                                                                                                                                       style.stroke_color = g_strdup ((gchar *)xmlNodeGetContent (cur));
+                                                                                                                               }
+                                                                                                                       else if (cur->type == XML_ELEMENT_NODE
+                                                                                                                               && (xmlStrcmp (cur->name, "fill-color") == 0))
+                                                                                                                               {
+                                                                                                                                       style.fill_color = g_strdup ((gchar *)xmlNodeGetContent (cur));
+                                                                                                                               }
+                                                                                                                       cur = cur->next;
+                                                                                                               }
+
+                                                                                                       gtk_gis_layer_set_style (layer, style);
+
+                                                                                                       cur = xml_style;
+                                                                                               }
+
                                                                                        cur = cur->next;
                                                                                }
                                                                        cur = xml_layer;
index c967f281884cca428fcf4b5dfe2a22f0e3b4ecfe..a7c86c748adb78a8cebf6e668b2540dfb0e4ab67 100644 (file)
@@ -55,6 +55,8 @@ struct _GtkGisLayerPrivate
                GList *geometries;
 
                gboolean editable;
+
+               GtkGisLayerStyle *style;
        };
 
 G_DEFINE_TYPE (GtkGisLayer, gtk_gis_layer, G_TYPE_OBJECT)
@@ -74,6 +76,11 @@ static void
 gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer)
 {
        GtkGisLayerPrivate *priv = GTK_GIS_LAYER_GET_PRIVATE (gtk_gis_layer);
+
+       priv->style = g_malloc (sizeof (GtkGisLayerStyle));
+       priv->style->width = 0.5;
+       priv->style->stroke_color = g_strdup ("black");
+       priv->style->fill_color =  g_strdup ("white");
 }
 
 /**
@@ -294,6 +301,75 @@ gtk_gis_layer_set_editable (GtkGisLayer *layer,
        priv->editable = editable;
 }
 
+/**
+ * gtk_gis_layer_get_style:
+ * @layer: a #GtkGisLayer object.
+ *
+ * Returns: a pointer to a #GtkGisLayerStyle struct. This is a copy of the struct
+ * inside the object, so it must be free after use.
+ */
+GtkGisLayerStyle
+*gtk_gis_layer_get_style (GtkGisLayer *layer)
+{
+       GtkGisLayerPrivate *priv;
+       GtkGisLayerStyle *style;
+
+       g_return_val_if_fail (IS_GTK_GIS_LAYER (layer), NULL);
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       style = g_malloc (sizeof (GtkGisLayerStyle));
+       style = g_memdup (priv->style, sizeof (GtkGisLayerStyle));
+
+       return style;
+}
+
+/**
+ * gtk_gis_layer_set_stroke_color:
+ * @layer: a #GtkGisLayer object.
+ * @style: a #GtkGisLayerStyle struct.
+ *
+ * Valid only for layers that aren't rasters.
+ */
+void
+gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style)
+{
+       GtkGisLayerPrivate *priv;
+       GtkGisLayerStyle new_style;
+
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       if (style.width != 0)
+               {
+                       new_style.width = style.width;
+               }
+       else
+               {
+                       new_style.width = priv->style->width;
+               }
+       if (style.stroke_color != NULL)
+               {
+                       new_style.stroke_color = g_strdup (style.stroke_color);
+               }
+       else
+               {
+                       new_style.stroke_color = g_strdup (priv->style->stroke_color);
+               }
+       if (style.fill_color != NULL)
+               {
+                       new_style.fill_color = g_strdup (style.fill_color);
+               }
+       else
+               {
+                       new_style.fill_color = g_strdup (priv->style->fill_color);
+               }
+
+       g_free (priv->style);
+       priv->style = g_memdup (&new_style, sizeof (GtkGisLayerStyle));
+}
+
 /**
  * gtk_gis_layer_draw:
  * @layer: a #GtkGisLayer object.
@@ -305,11 +381,12 @@ void
 gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
 {
        GtkGisLayerPrivate *priv;
-
        GList *cur;
-
        GooCanvasItem *item;
 
+       g_return_if_fail (IS_GTK_GIS_LAYER (layer));
+       g_return_if_fail (GOO_IS_CANVAS_ITEM (root));
+
        priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
 
        gtk_gis_layer_fill_from_source (layer);
@@ -319,7 +396,7 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale)
        cur = g_list_first (priv->geometries);
        while (cur != NULL)
                {
-                       item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale);
+                       item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, *priv->style);
 
                        if (item != NULL)
                                {
index 31daa88bbdd9e9ad6e9737d729f6e2775f68c342..13d42f3ff8c1a534093c93828e072863c0524e43 100644 (file)
@@ -87,6 +87,9 @@ gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer);
 void gtk_gis_layer_set_editable (GtkGisLayer *layer,
                                  gboolean editable);
 
+GtkGisLayerStyle *gtk_gis_layer_get_style (GtkGisLayer *layer);
+void gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style);
+
 void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale);
 
 
index 090eb87d9692a9a56b7d64ec2546afc7dbcdb4e3..28baeca005f57a5e8a14a072884531bc086b0a78 100644 (file)
                <source>
                        <shape filename="tests/samples/railroads.shp" />
                </source>
+               <style>
+                       <stroke-color>red</stroke-color>
+               </style>
        </layer>
 
        <layer name="rivers">
                <source>
                        <shape filename="tests/samples/rivers.shp" />
                </source>
+               <style>
+                       <stroke-color>blue</stroke-color>
+               </style>
        </layer>
 
 </gtkgis>