From d13225041ce6788a0d9af85e5b13a960b070208b Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 16 Aug 2009 15:55:37 +0200 Subject: [PATCH] Ended initial layer's label support. Many bug fixes. --- .gitignore | 1 + INSTALL | 1 - docs/reference/libgtkgis-decl-list.txt | 2 +- docs/reference/libgtkgis-decl.txt | 14 +-- docs/reference/libgtkgis-undeclared.txt | 1 + docs/reference/libgtkgis-undocumented.txt | 5 +- docs/reference/libgtkgis-unused.txt | 1 + docs/reference/tmpl/geometryline.sgml | 9 -- docs/reference/tmpl/layer.sgml | 2 +- docs/reference/tmpl/libgtkgis-unused.sgml | 8 ++ src/geometry.c | 36 +++++-- src/geometry.h | 4 +- src/geometryline.c | 72 ++++++++++--- src/geometryline.h | 4 +- src/geometrypoint.c | 34 ++++-- src/geometrypolygon.c | 38 ++++--- src/gtkgis.c | 79 ++++++++++++-- src/layer.c | 126 +++++++++++++++++----- src/layer.h | 4 +- src/layersource.c | 2 +- tests/from_xml.c | 6 +- tests/test1.gtkgis | 15 ++- 22 files changed, 355 insertions(+), 109 deletions(-) delete mode 120000 INSTALL diff --git a/.gitignore b/.gitignore index 197a3e0..3cb57fa 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ configure depcomp gtk-doc.make install-sh +INSTALL libgtkgis.pc libtool ltmain.sh diff --git a/INSTALL b/INSTALL deleted file mode 120000 index 5bb6e7b..0000000 --- a/INSTALL +++ /dev/null @@ -1 +0,0 @@ -/usr/share/automake-1.10/INSTALL \ No newline at end of file diff --git a/docs/reference/libgtkgis-decl-list.txt b/docs/reference/libgtkgis-decl-list.txt index 93bc5b8..37d6dc3 100644 --- a/docs/reference/libgtkgis-decl-list.txt +++ b/docs/reference/libgtkgis-decl-list.txt @@ -147,7 +147,7 @@ GTK_GIS_GEOMETRY_LINE_GET_CLASS GtkGisGeometryLine gtk_gis_geometry_line_get_type gtk_gis_geometry_line_new -gtk_gis_geometry_line_new_from_list +gtk_gis_geometry_line_new_from_points gtk_gis_geometry_line_add_point gtk_gis_geometry_line_add_point_from_coordinates gtk_gis_geometry_line_get_svg_path diff --git a/docs/reference/libgtkgis-decl.txt b/docs/reference/libgtkgis-decl.txt index 2806a37..7600ce7 100644 --- a/docs/reference/libgtkgis-decl.txt +++ b/docs/reference/libgtkgis-decl.txt @@ -550,7 +550,7 @@ GtkGisLayer *layer gtk_gis_layer_set_style void -GtkGisLayer *layer, GtkGisLayerStyle style +GtkGisLayer *layer, GtkGisLayerStyle *style gtk_gis_layer_get_label @@ -564,8 +564,8 @@ GtkGisLayer *layer, GtkGisLayerLabel *label gtk_gis_layer_draw -void -GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale +GooCanvasItem * +GtkGisLayer *layer, GtkGisScale *scale TYPE_GTK_GIS_GEOMETRY_LINE @@ -622,14 +622,14 @@ void void -gtk_gis_geometry_line_new_from_list +gtk_gis_geometry_line_new_from_points GtkGisGeometry * GSList *points gtk_gis_geometry_line_add_point void -GtkGisGeometryLine *line, GtkGisPoint point +GtkGisGeometryLine *line, GtkGisPoint *point gtk_gis_geometry_line_add_point_from_coordinates @@ -688,7 +688,7 @@ struct _GtkGisGeometryClass GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); }; @@ -724,7 +724,7 @@ GtkGisGeometry *geometry gtk_gis_geometry_draw GooCanvasItem * -GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle style +GtkGisGeometry *geometry,GtkGisScale *scale,GtkGisLayerStyle *style TYPE_GTK_GIS_LAYER_SOURCE_POSTGIS diff --git a/docs/reference/libgtkgis-undeclared.txt b/docs/reference/libgtkgis-undeclared.txt index 994f2fb..e80e9c7 100644 --- a/docs/reference/libgtkgis-undeclared.txt +++ b/docs/reference/libgtkgis-undeclared.txt @@ -1,2 +1,3 @@ +gtk_gis_geometry_line_new_from_list gtk_gis_geometry_polygon_add_line_from_list gtk_gis_geometry_polygon_new_from_list diff --git a/docs/reference/libgtkgis-undocumented.txt b/docs/reference/libgtkgis-undocumented.txt index 1aad4e2..7dfb79f 100644 --- a/docs/reference/libgtkgis-undocumented.txt +++ b/docs/reference/libgtkgis-undocumented.txt @@ -1,7 +1,7 @@ 11% symbol docs coverage. -22 symbols documented. +23 symbols documented. 7 symbols incomplete. -180 not documented. +179 not documented. GTK_GIS @@ -163,7 +163,6 @@ gtk_gis_save_to_xml gtk_gis_set_scale gtk_gis_zoom_to_extent gtk_gis_zoom_to_layer -gtk_gis_zoom_to_max commons:Long_Description diff --git a/docs/reference/libgtkgis-unused.txt b/docs/reference/libgtkgis-unused.txt index b02fb86..1569339 100644 --- a/docs/reference/libgtkgis-unused.txt +++ b/docs/reference/libgtkgis-unused.txt @@ -13,6 +13,7 @@ GtkGisLayersGroupClass gtk_gis_geometry_get_extent gtk_gis_geometry_get_label gtk_gis_geometry_line_get_svg_path +gtk_gis_geometry_line_new_from_points gtk_gis_geometry_polygon_add_line_from_points gtk_gis_geometry_polygon_new_from_points gtk_gis_geometry_set_label diff --git a/docs/reference/tmpl/geometryline.sgml b/docs/reference/tmpl/geometryline.sgml index 4d0e081..88afbd6 100644 --- a/docs/reference/tmpl/geometryline.sgml +++ b/docs/reference/tmpl/geometryline.sgml @@ -86,15 +86,6 @@ GtkGisGeometryLine @Returns: - - - - - -@points: -@Returns: - - diff --git a/docs/reference/tmpl/layer.sgml b/docs/reference/tmpl/layer.sgml index 95f4c19..eaf9acb 100644 --- a/docs/reference/tmpl/layer.sgml +++ b/docs/reference/tmpl/layer.sgml @@ -195,7 +195,7 @@ GtkGisLayer @layer: -@root: @scale: +@Returns: diff --git a/docs/reference/tmpl/libgtkgis-unused.sgml b/docs/reference/tmpl/libgtkgis-unused.sgml index 75e4975..17ef532 100644 --- a/docs/reference/tmpl/libgtkgis-unused.sgml +++ b/docs/reference/tmpl/libgtkgis-unused.sgml @@ -1,3 +1,11 @@ + + + + + +@points: +@Returns: + diff --git a/src/geometry.c b/src/geometry.c index 49a007e..be1058f 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -70,6 +70,7 @@ gtk_gis_geometry_init (GtkGisGeometry *gtk_gis_geometry) GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry); priv->editable = FALSE; + priv->label = NULL; } /** @@ -109,23 +110,33 @@ gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable) /** * gtk_gis_geometry_get_label: - * @geometry: + * @geometry: a #GtkGisGeometry object. * + * Returns: the field's name used as label. */ const gchar *gtk_gis_geometry_get_label (GtkGisGeometry *geometry) { GtkGisGeometryPrivate *priv; + gchar *label; g_return_val_if_fail (IS_GTK_GIS_GEOMETRY (geometry), NULL); - return g_strdup (priv->label); + priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry); + + label = NULL; + if (priv->label != NULL) + { + label = g_strdup (priv->label); + } + + return label; } /** * gtk_gis_geometry_set_label: - * @geometry: - * @label: + * @geometry: a #GtkGisGeometry object. + * @label: the field's name to use as label. * */ void @@ -135,12 +146,21 @@ gtk_gis_geometry_set_label (GtkGisGeometry *geometry, const gchar *label) g_return_if_fail (IS_GTK_GIS_GEOMETRY (geometry)); - priv->label = g_strdup (label); + priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry); + + if (label == NULL) + { + priv->label = NULL; + } + else + { + priv->label = g_strdup (label); + } } /** * gtk_gis_geometry_get_extent: - * @line: a #GtkGisGeometry object. + * @geometry: a #GtkGisGeometry object. * */ GtkGisExtent @@ -159,12 +179,14 @@ GtkGisExtent /** * gtk_gis_geometry_draw: * @geometry: a #GtkGisGeometry object. + * @scale: + * @style: * */ GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle style) + GtkGisLayerStyle *style) { GooCanvasItem *item = NULL; diff --git a/src/geometry.h b/src/geometry.h index 95e53c6..50a7ad5 100644 --- a/src/geometry.h +++ b/src/geometry.h @@ -54,7 +54,7 @@ struct _GtkGisGeometryClass GooCanvasItem *(*draw) (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); }; GType gtk_gis_geometry_get_type (void) G_GNUC_CONST; @@ -70,7 +70,7 @@ GtkGisExtent *gtk_gis_geometry_get_extent (GtkGisGeometry *geometry); GooCanvasItem *gtk_gis_geometry_draw (GtkGisGeometry *geometry, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); G_END_DECLS diff --git a/src/geometryline.c b/src/geometryline.c index a11398f..c76c7c9 100644 --- a/src/geometryline.c +++ b/src/geometryline.c @@ -35,7 +35,7 @@ static gchar *convert_comma_to_dot (gchar *str); static GtkGisExtent *gtk_gis_geometry_line_get_extent (GtkGisGeometry *line); static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); static void gtk_gis_geometry_line_set_property (GObject *object, guint property_id, @@ -101,7 +101,7 @@ GtkGisGeometry } /** - * gtk_gis_geometry_line_new_from_list: + * gtk_gis_geometry_line_new_from_points: * @points: a #GSList of #GtkGisPoint to add to the line. * * Creates a new #GtkGisGeometryLine object. @@ -109,16 +109,25 @@ GtkGisGeometry * Returns: the newly created #GtkGisGeometryLine object. */ GtkGisGeometry -*gtk_gis_geometry_line_new_from_list (GSList *points) +*gtk_gis_geometry_line_new_from_points (GSList *points) { GtkGisGeometry *line = NULL; GtkGisGeometryLinePrivate *priv; + GSList *cur; + + g_return_val_if_fail (points != NULL, NULL); line = gtk_gis_geometry_line_new (); priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line)); - priv->points = g_slist_copy (points); + cur = points; + while (cur != NULL) + { + gtk_gis_geometry_line_add_point (GTK_GIS_GEOMETRY_LINE (line), (GtkGisPoint *)cur->data); + + cur = g_slist_next (cur); + } return line; } @@ -129,7 +138,7 @@ GtkGisGeometry * @point: a #GtkGisPoint to add to the line. */ void -gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point) +gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint *point) { GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (line); @@ -139,11 +148,11 @@ gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point) gpoint = g_malloc0 (sizeof (GtkGisPoint)); - gpoint->x = point.x; - gpoint->y = point.y; + gpoint->x = point->x; + gpoint->y = point->y; /* recalculate the new extent */ - if (priv->extent = NULL) + if (priv->extent == NULL) { priv->extent = g_malloc (sizeof (GtkGisExtent)); priv->extent->min_x = gpoint->x; @@ -185,12 +194,14 @@ void gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line, gdouble x, gdouble y) { - GtkGisPoint gpoint; + GtkGisPoint *gpoint; g_return_if_fail (IS_GTK_GIS_GEOMETRY_LINE (line)); - gpoint.x = x; - gpoint.y = y; + gpoint = g_malloc0 (sizeof (GtkGisPoint)); + + gpoint->x = x; + gpoint->y = y; gtk_gis_geometry_line_add_point (line, gpoint); } @@ -276,7 +287,7 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line, GtkGisScale *scale, - GtkGisLayerStyle style) + GtkGisLayerStyle *style) { GtkGisGeometryLinePrivate *priv; GooCanvasItem *item = NULL; @@ -290,11 +301,44 @@ static GooCanvasItem path = (gchar *)gtk_gis_geometry_line_get_svg_path (GTK_GIS_GEOMETRY_LINE (line)); if (path != NULL) { + const gchar *str_label; + item = goo_canvas_path_new (NULL, path, - "line-width", style.width / scale->xy, - "stroke-color", style.stroke_color, + "line-width", style->width / scale->xy, + "stroke-color", style->stroke_color, NULL); + + str_label = gtk_gis_geometry_get_label (line); + if (str_label != NULL + && g_strcmp0 (str_label, "") != 0) + { + GooCanvasItem *group; + gdouble x; + gdouble y; + + group = goo_canvas_group_new (NULL, NULL); + + goo_canvas_item_add_child (group, item, -1); + + /* center the label inside the polygon */ + + /* TO DO + * the label must be visible every time that the polygon is visible + */ + + x = priv->extent->min_x + (priv->extent->max_x - priv->extent->min_x) / 2; + y = priv->extent->min_y + (priv->extent->max_y - priv->extent->min_y) / 2; + + goo_canvas_text_new (group, + str_label, + x, y, -1, + GTK_ANCHOR_CENTER, + "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + NULL); + + item = group; + } } } diff --git a/src/geometryline.h b/src/geometryline.h index 96a73ca..80d5c46 100644 --- a/src/geometryline.h +++ b/src/geometryline.h @@ -52,9 +52,9 @@ GType gtk_gis_geometry_line_get_type (void) G_GNUC_CONST; GtkGisGeometry *gtk_gis_geometry_line_new (void); -GtkGisGeometry *gtk_gis_geometry_line_new_from_list (GSList *points); +GtkGisGeometry *gtk_gis_geometry_line_new_from_points (GSList *points); -void gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point); +void gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint *point); void gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line, gdouble x, gdouble y); diff --git a/src/geometrypoint.c b/src/geometrypoint.c index 90b01ae..7979884 100644 --- a/src/geometrypoint.c +++ b/src/geometrypoint.c @@ -33,7 +33,7 @@ static void gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_p static GtkGisExtent *gtk_gis_geometry_point_get_extent (GtkGisGeometry *point); static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); static void gtk_gis_geometry_point_set_property (GObject *object, guint property_id, @@ -173,7 +173,7 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, GtkGisScale *scale, - GtkGisLayerStyle style) + GtkGisLayerStyle *style) { GooCanvasItem *item = NULL; @@ -181,13 +181,35 @@ GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point, if (priv->point != NULL) { + const gchar *str_label; + item = goo_canvas_ellipse_new (NULL, priv->point->x, priv->point->y, - 0.5 / scale->x, 0.5 / scale->y, - "line-width", style.width / scale->xy, - "stroke-color", style.stroke_color, - "fill-color", style.fill_color, + (style->width / 2) / scale->x, (style->width / 2) / scale->y, + "line-width", style->width / scale->xy, + "stroke-color", style->stroke_color, + "fill-color", style->fill_color, NULL); + + str_label = gtk_gis_geometry_get_label (point); + if (str_label != NULL + && g_strcmp0 (str_label, "") != 0) + { + GooCanvasItem *group; + + group = goo_canvas_group_new (NULL, NULL); + + goo_canvas_item_add_child (group, item, -1); + + goo_canvas_text_new (group, + str_label, + priv->point->x, priv->point->y, -1, + GTK_ANCHOR_CENTER, + "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + NULL); + + item = group; + } } return item; diff --git a/src/geometrypolygon.c b/src/geometrypolygon.c index 38f5029..ca15d63 100644 --- a/src/geometrypolygon.c +++ b/src/geometrypolygon.c @@ -33,7 +33,7 @@ static void gtk_gis_geometry_polygon_init (GtkGisGeometryPolygon *gtk_gis_geomet static GtkGisExtent *gtk_gis_geometry_polygon_get_extent (GtkGisGeometry *polygon); static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale, - GtkGisLayerStyle style); + GtkGisLayerStyle *style); static void gtk_gis_geometry_polygon_set_property (GObject *object, guint property_id, @@ -131,7 +131,7 @@ GtkGisGeometry GtkGisGeometry *polygon = NULL; GtkGisGeometry *line = NULL; - line = gtk_gis_geometry_line_new_from_list (points); + line = gtk_gis_geometry_line_new_from_points (points); if (line != NULL) { @@ -163,7 +163,7 @@ gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, /* recalculate the new extent */ line_extent = gtk_gis_geometry_get_extent (GTK_GIS_GEOMETRY (line)); - if (priv->extent = NULL) + if (priv->extent == NULL) { priv->extent = g_malloc (sizeof (GtkGisExtent)); priv->extent->min_x = line_extent->min_x; @@ -208,7 +208,7 @@ gtk_gis_geometry_polygon_add_line_from_points (GtkGisGeometryPolygon *polygon, g_return_if_fail (IS_GTK_GIS_GEOMETRY_POLYGON (polygon)); - line = gtk_gis_geometry_line_new_from_list (points); + line = gtk_gis_geometry_line_new_from_points (points); if (line != NULL) { @@ -255,7 +255,7 @@ static GtkGisExtent static GooCanvasItem *gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon, GtkGisScale *scale, - GtkGisLayerStyle style) + GtkGisLayerStyle *style) { GtkGisGeometryPolygonPrivate *priv; GooCanvasItem *item = NULL; @@ -272,7 +272,6 @@ static GooCanvasItem GtkGisGeometry *line; const gchar *str_label; - GooCanvasItem *item_label; cur = priv->lines; while (cur != NULL) @@ -287,10 +286,10 @@ static GooCanvasItem } item = goo_canvas_path_new (NULL, - path, - "line-width", style.width / scale->xy, - "stroke-color", style.stroke_color, - "fill-color", style.fill_color, + path + 1, + "line-width", style->width / scale->xy, + "stroke-color", style->stroke_color, + "fill-color", style->fill_color, "fill-rule", CAIRO_FILL_RULE_EVEN_ODD, NULL); @@ -298,9 +297,14 @@ static GooCanvasItem if (str_label != NULL && g_strcmp0 (str_label, "") != 0) { + GooCanvasItem *group; gdouble x; gdouble y; + group = goo_canvas_group_new (NULL, NULL); + + goo_canvas_item_add_child (group, item, -1); + /* center the label inside the polygon */ /* TO DO @@ -310,12 +314,14 @@ static GooCanvasItem x = priv->extent->min_x + (priv->extent->max_x - priv->extent->min_x) / 2; y = priv->extent->min_y + (priv->extent->max_y - priv->extent->min_y) / 2; - item_label = goo_canvas_text_new (item, - str_label, - x, y, -1, - GTK_ANCHOR_CENTER, - "font", "Sans 12", - NULL); + goo_canvas_text_new (group, + str_label, + x, y, -1, + GTK_ANCHOR_CENTER, + "font", g_strdup_printf ("Sans %fpx", 12 / scale->xy), + NULL); + + item = group; } } diff --git a/src/gtkgis.c b/src/gtkgis.c index 45d1ef2..694d07f 100644 --- a/src/gtkgis.c +++ b/src/gtkgis.c @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include #include @@ -289,27 +291,31 @@ GtkWidget && xmlStrcmp (cur->name, "style") == 0) { xmlNode *xml_style; - GtkGisLayerStyle style; + GtkGisLayerStyle *style; xml_style = cur; + style = g_malloc0 (sizeof (GtkGisLayerStyle)); + style->stroke_color = NULL; + style->fill_color = NULL; + 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); + 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)); + 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)); + style->fill_color = g_strdup ((gchar *)xmlNodeGetContent (cur)); } cur = cur->next; } @@ -318,6 +324,50 @@ GtkWidget cur = xml_style; } + else if (cur->type == XML_ELEMENT_NODE + && xmlStrcmp (cur->name, "label") == 0) + { + xmlNode *xml_label; + GtkGisLayerLabel *label; + + xml_label = cur; + + label = g_malloc0 (sizeof (GtkGisLayerLabel)); + label->field = NULL; + label->color = NULL; + label->background_color = NULL; + label->font = NULL; + + cur = cur->children; + while (cur != NULL) + { + if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "field") == 0)) + { + label->field = g_strdup ((gchar *)xmlNodeGetContent (cur)); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "color") == 0)) + { + label->color = g_strdup ((gchar *)xmlNodeGetContent (cur)); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "background-color") == 0)) + { + label->background_color = g_strdup ((gchar *)xmlNodeGetContent (cur)); + } + else if (cur->type == XML_ELEMENT_NODE + && (xmlStrcmp (cur->name, "font") == 0)) + { + label->font = g_strdup ((gchar *)xmlNodeGetContent (cur)); + } + cur = cur->next; + } + + gtk_gis_layer_set_label (layer, label); + + cur = xml_label; + } cur = cur->next; } @@ -381,6 +431,9 @@ GtkWidget xmlDoc *gtk_gis_get_xml (GtkGis *gtkgis) { + gchar *locale_old; + gchar *locale_num; + xmlDoc *xdoc = NULL; xmlNode *xroot; xmlNode *xreport; @@ -394,6 +447,9 @@ xmlDoc priv = GTK_GIS_GET_PRIVATE (gtkgis); + locale_old = setlocale (LC_ALL, NULL); + locale_num = setlocale (LC_NUMERIC, "C"); + xdoc = xmlNewDoc ("1.0"); xroot = xmlNewNode (NULL, "gtkgis"); @@ -412,6 +468,9 @@ xmlDoc cur_layer = g_slist_next (cur_layer); } + setlocale (LC_NUMERIC, locale_num); + setlocale (LC_ALL, locale_old); + return xdoc; } @@ -559,6 +618,7 @@ gtk_gis_draw (GtkGis *gtkgis) GdkCursor *cursor; GSList *cur; GtkGisLayerSource *layer_source; + GooCanvasItem *item_layer; g_return_if_fail (IS_GTK_GIS (gtkgis)); @@ -576,7 +636,11 @@ gtk_gis_draw (GtkGis *gtkgis) layer_source = gtk_gis_layer_get_source ((GtkGisLayer *)cur->data); gtk_gis_layer_source_set_max_extent (layer_source, priv->extent); - gtk_gis_layer_draw ((GtkGisLayer *)cur->data, priv->canvas_root, priv->scale); + item_layer = gtk_gis_layer_draw ((GtkGisLayer *)cur->data, priv->scale); + if (item_layer != NULL) + { + goo_canvas_item_add_child (priv->canvas_root, item_layer, -1); + } cur = g_slist_next (cur); } @@ -613,7 +677,7 @@ GtkGisScale /** * gtk_gis_set_scale: * @gtkgis: a #GtkGis object. - * @scale: + * @scale: a #GtkGisScale struct. * */ void @@ -682,7 +746,7 @@ gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisExtent extent) scale = g_malloc0 (sizeof (GtkGisScale)); - /* must add width or height to make the max extent + /* must add width or height to make the extent * the same proportion of the canvas */ extent_width = extent.max_x - extent.min_x; extent_height = extent.max_y - extent.min_y; @@ -719,6 +783,7 @@ gtk_gis_zoom_to_extent (GtkGis *gtkgis, GtkGisExtent extent) * gtk_gis_zoom_to_max: * @gtkgis: a #GtkGis object. * + * Zoom to the possible max extent. */ void gtk_gis_zoom_to_max (GtkGis *gtkgis) diff --git a/src/layer.c b/src/layer.c index 6f3b12a..2deef9a 100644 --- a/src/layer.c +++ b/src/layer.c @@ -88,7 +88,11 @@ gtk_gis_layer_init (GtkGisLayer *gtk_gis_layer) priv->style->stroke_color = g_strdup ("black"); priv->style->fill_color = g_strdup ("white"); - priv->label = NULL; + priv->label = g_malloc (sizeof (GtkGisLayerLabel)); + priv->label->field = NULL; + priv->label->color = g_strdup ("black"); + priv->label->background_color = g_strdup ("white"); + priv->label->font = g_strdup ("Sans 12"); } /** @@ -170,7 +174,11 @@ xmlNode xmlSetProp (xnode, "name", priv->name); } - if (!priv->visible) + if (priv->visible) + { + xmlSetProp (xnode, "visible", "y"); + } + else { xmlSetProp (xnode, "visible", "n"); } @@ -215,6 +223,18 @@ xmlNode xnode_label_prop = xmlNewNode (NULL, "field"); xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->field)); xmlAddChild (xnode_label, xnode_label_prop); + + xnode_label_prop = xmlNewNode (NULL, "color"); + xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->color)); + xmlAddChild (xnode_label, xnode_label_prop); + + xnode_label_prop = xmlNewNode (NULL, "background-color"); + xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->background_color)); + xmlAddChild (xnode_label, xnode_label_prop); + + xnode_label_prop = xmlNewNode (NULL, "font"); + xmlNodeSetContent (xnode_label_prop, g_strdup (priv->label->font)); + xmlAddChild (xnode_label, xnode_label_prop); } return xnode; @@ -271,7 +291,7 @@ gtk_gis_layer_fill_from_source (GtkGisLayer *layer, GtkGisLayerLabel *label) priv = GTK_GIS_LAYER_GET_PRIVATE (layer); field = NULL; - if (label->field != NULL && g_strcmp0 (label->field, "") != 0) + if (label != NULL && label->field != NULL && g_strcmp0 (label->field, "") != 0) { field = g_strdup (label->field); } @@ -452,49 +472,53 @@ GtkGisLayerStyle * Valid only for layers that aren't rasters. */ void -gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle style) +gtk_gis_layer_set_style (GtkGisLayer *layer, GtkGisLayerStyle *style) { GtkGisLayerPrivate *priv; - GtkGisLayerStyle new_style; + GtkGisLayerStyle *new_style; gchar *prop; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); + if (style == NULL) return; + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); - if (style.width != 0) + new_style = g_malloc0 (sizeof (GtkGisLayerStyle)); + + if (style->width != 0) { - new_style.width = style.width; + new_style->width = style->width; } else { - new_style.width = priv->style->width; + new_style->width = priv->style->width; } - prop = g_strdup (style.stroke_color); - if (style.stroke_color != NULL && + prop = g_strdup (style->stroke_color); + if (style->stroke_color != NULL && g_strcmp0 (g_strstrip (prop), "") != 0) { - new_style.stroke_color = g_strdup (style.stroke_color); + new_style->stroke_color = g_strdup (prop); } else { - new_style.stroke_color = g_strdup (priv->style->stroke_color); + new_style->stroke_color = g_strdup (priv->style->stroke_color); } - prop = g_strdup (style.fill_color); - if (style.fill_color != NULL && + prop = g_strdup (style->fill_color); + if (style->fill_color != NULL && g_strcmp0 (g_strstrip (prop), "") != 0) { - new_style.fill_color = g_strdup (style.fill_color); + new_style->fill_color = g_strdup (prop); } else { - new_style.fill_color = g_strdup (priv->style->fill_color); + new_style->fill_color = g_strdup (priv->style->fill_color); } g_free (priv->style); - priv->style = g_memdup (&new_style, sizeof (GtkGisLayerStyle)); + priv->style = new_style; } /** @@ -523,28 +547,80 @@ void gtk_gis_layer_set_label (GtkGisLayer *layer, GtkGisLayerLabel *label) { GtkGisLayerPrivate *priv; + GtkGisLayerLabel *new_label; + gchar *prop; g_return_if_fail (IS_GTK_GIS_LAYER (layer)); - priv->label = g_memdup (label, sizeof (GtkGisLayerLabel)); + if (label == NULL) return; + + priv = GTK_GIS_LAYER_GET_PRIVATE (layer); + + new_label = g_malloc0 (sizeof (GtkGisLayerLabel)); + + prop = g_strdup (label->field); + if (label->field != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) + { + new_label->field = g_strdup (prop); + } + else + { + new_label->field = g_strdup (priv->label->field); + } + + prop = g_strdup (label->color); + if (label->color != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) + { + new_label->color = g_strdup (prop); + } + else + { + new_label->color = g_strdup (priv->label->color); + } + + prop = g_strdup (label->background_color); + if (label->background_color != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) + { + new_label->background_color = g_strdup (prop); + } + else + { + new_label->background_color = g_strdup (priv->label->background_color); + } + + prop = g_strdup (label->font); + if (label->font != NULL && + g_strcmp0 (g_strstrip (prop), "") != 0) + { + new_label->font = g_strdup (prop); + } + else + { + new_label->font = g_strdup (priv->label->font); + } + + g_free (priv->label); + priv->label = new_label; } /** * gtk_gis_layer_draw: * @layer: a #GtkGisLayer object. - * @root: * @scale: * + * Returns: the #GooCanvasItem object with the layer's content draw. */ -void -gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) +GooCanvasItem +*gtk_gis_layer_draw (GtkGisLayer *layer, GtkGisScale *scale) { GtkGisLayerPrivate *priv; GSList *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); @@ -560,12 +636,12 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) gtk_gis_layer_fill_from_source (layer, priv->label); - priv->layer_item = goo_canvas_group_new (root, NULL); + priv->layer_item = goo_canvas_group_new (NULL, NULL); cur = priv->geometries; while (cur != NULL) { - item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, *priv->style); + item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data, scale, priv->style); if (item != NULL) { goo_canvas_item_add_child (priv->layer_item, item, -1); @@ -573,6 +649,8 @@ gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale) cur = g_slist_next (cur); } + + return priv->layer_item; } static void diff --git a/src/layer.h b/src/layer.h index 08ee2a3..1ff0dca 100644 --- a/src/layer.h +++ b/src/layer.h @@ -92,12 +92,12 @@ 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_set_style (GtkGisLayer *layer, GtkGisLayerStyle *style); GtkGisLayerLabel *gtk_gis_layer_get_label (GtkGisLayer *layer); void gtk_gis_layer_set_label (GtkGisLayer *layer, GtkGisLayerLabel *label); -void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root, GtkGisScale *scale); +GooCanvasItem *gtk_gis_layer_draw (GtkGisLayer *layer, GtkGisScale *scale); G_END_DECLS diff --git a/src/layersource.c b/src/layersource.c index 6eff09e..1fa8a58 100644 --- a/src/layersource.c +++ b/src/layersource.c @@ -384,7 +384,7 @@ static GSList gpoints = g_slist_append (gpoints, gpoint); } - geometry = gtk_gis_geometry_line_new_from_list (gpoints); + geometry = gtk_gis_geometry_line_new_from_points (gpoints); } else if (poGeometry != NULL && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbPolygon) diff --git a/tests/from_xml.c b/tests/from_xml.c index fb7d49a..5bec20d 100644 --- a/tests/from_xml.c +++ b/tests/from_xml.c @@ -26,9 +26,9 @@ main (int argc, char *argv[]) gtk_widget_show_all (window); - /*gtk_gis_zoom_to_max (GTK_GIS (gtkgis));*/ - gtk_gis_zoom_to_layer (GTK_GIS (gtkgis), - gtk_gis_get_layer_by_name (GTK_GIS (gtkgis), "railroads")); + gtk_gis_zoom_to_max (GTK_GIS (gtkgis)); + /*gtk_gis_zoom_to_layer (GTK_GIS (gtkgis), + gtk_gis_get_layer_by_name (GTK_GIS (gtkgis), "railroads"));*/ gtk_gis_draw (GTK_GIS (gtkgis)); /*scale = gtk_gis_get_scale (GTK_GIS (gtkgis)); diff --git a/tests/test1.gtkgis b/tests/test1.gtkgis index 33d044e..e717e18 100644 --- a/tests/test1.gtkgis +++ b/tests/test1.gtkgis @@ -13,24 +13,33 @@ + + - + - + + -- 2.49.0