]> saetta.ns0.it Git - libgtkgis/commitdiff
Added GtkGisGeometry::draw.
authorAndrea Zagli <azagli@libero.it>
Sat, 4 Jul 2009 11:00:48 +0000 (13:00 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 4 Jul 2009 11:00:48 +0000 (13:00 +0200)
Added GtkGis::zoom_to_max.
Fixed some bugs.
Now the widget draws points, lines and poligons.

14 files changed:
src/geometry.c
src/geometry.h
src/geometryline.c
src/geometryline.h
src/geometrypoint.c
src/geometrypolygon.c
src/geometrypolygon.h
src/gtkgis.c
src/gtkgis.h
src/layer.c
src/layer.h
src/layersource.c
tests/from_xml.c
tests/test1.gtkgis

index 78a3f0eec5860c4d83428be8ea28784e388cefad..31f8aef24bb46eca13098805fb1670b21f59b077 100644 (file)
@@ -40,12 +40,13 @@ static void gtk_gis_geometry_get_property (GObject *object,
                                      GParamSpec *pspec);
 
 
-/*#define GTK_GIS_GEOMETRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY, GtkGisGeometryPrivate))
+#define GTK_GIS_GEOMETRY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_GTK_GIS_GEOMETRY, GtkGisGeometryPrivate))
 
 typedef struct _GtkGisGeometryPrivate GtkGisGeometryPrivate;
 struct _GtkGisGeometryPrivate
        {
-       };*/
+               gboolean editable;
+       };
 
 G_DEFINE_TYPE (GtkGisGeometry, gtk_gis_geometry, G_TYPE_OBJECT)
 
@@ -54,7 +55,7 @@ gtk_gis_geometry_class_init (GtkGisGeometryClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-       /*g_type_class_add_private (object_class, sizeof (GtkGisGeometryPrivate));*/
+       g_type_class_add_private (object_class, sizeof (GtkGisGeometryPrivate));
 
        object_class->set_property = gtk_gis_geometry_set_property;
        object_class->get_property = gtk_gis_geometry_get_property;
@@ -63,7 +64,54 @@ gtk_gis_geometry_class_init (GtkGisGeometryClass *klass)
 static void
 gtk_gis_geometry_init (GtkGisGeometry *gtk_gis_geometry)
 {
-       /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+       GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
+
+       priv->editable = FALSE;
+}
+
+/**
+ * gtk_gis_geometry_get_editable:
+ * @geometry:
+ *
+ */
+gboolean
+gtk_gis_geometry_get_editable (GtkGisGeometry *geometry)
+{
+       GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry);
+
+       return priv->editable;
+}
+
+/**
+ * gtk_gis_geometry_set_editable:
+ * @geometry:
+ * @editable:
+ *
+ */
+void
+gtk_gis_geometry_set_editable (GtkGisGeometry *geometry, gboolean editable)
+{
+       GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (geometry);
+
+       priv->editable = editable;
+}
+
+/**
+ * gtk_gis_geometry_draw:
+ * @geometry:
+ *
+ */
+GooCanvasItem
+*gtk_gis_geometry_draw (GtkGisGeometry *geometry)
+{
+       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);
+               }
+
+       return item;
 }
 
 static void
@@ -71,7 +119,7 @@ gtk_gis_geometry_set_property (GObject *object, guint property_id, const GValue
 {
        GtkGisGeometry *gtk_gis_geometry = GTK_GIS_GEOMETRY (object);
 
-       /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+       GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
 
        switch (property_id)
                {
@@ -86,7 +134,7 @@ gtk_gis_geometry_get_property (GObject *object, guint property_id, GValue *value
 {
        GtkGisGeometry *gtk_gis_geometry = GTK_GIS_GEOMETRY (object);
 
-       /*GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);*/
+       GtkGisGeometryPrivate *priv = GTK_GIS_GEOMETRY_GET_PRIVATE (gtk_gis_geometry);
 
        switch (property_id)
                {
index ec5994703aaaaf03c3e8e0c0c9e18276b43f8595..07606a5fa08f51ff61746a5e33eaaaf6a4f08ee4 100644 (file)
@@ -23,6 +23,8 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <goocanvas.h>
+
 G_BEGIN_DECLS
 
 
@@ -45,6 +47,8 @@ struct _GtkGisGeometry
 struct _GtkGisGeometryClass
        {
                GObjectClass parent_class;
+
+               GooCanvasItem *(*draw) (GtkGisGeometry *geometry);
        };
 
 GType gtk_gis_geometry_get_type (void) G_GNUC_CONST;
@@ -60,6 +64,8 @@ typedef struct
 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);
+
 
 G_END_DECLS
 
index c2cd977702bc69556a69af5f6bf0a2dfdeceef8b..0c399649d822937d65fa7756fe0b56f99bb2ce2e 100644 (file)
 static void gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass);
 static void gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_line);
 
+static gchar *convert_comma_to_dot (gchar *str);
+
+static GooCanvasItem *gtk_gis_geometry_line_draw (GtkGisGeometry *line);
+
 static void gtk_gis_geometry_line_set_property (GObject *object,
                                      guint property_id,
                                      const GValue *value,
@@ -45,7 +49,7 @@ static void gtk_gis_geometry_line_get_property (GObject *object,
 typedef struct _GtkGisGeometryLinePrivate GtkGisGeometryLinePrivate;
 struct _GtkGisGeometryLinePrivate
        {
-               GPtrArray *points;
+               GSList *points;
        };
 
 G_DEFINE_TYPE (GtkGisGeometryLine, gtk_gis_geometry_line, TYPE_GTK_GIS_GEOMETRY)
@@ -54,11 +58,14 @@ static void
 gtk_gis_geometry_line_class_init (GtkGisGeometryLineClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
 
        g_type_class_add_private (object_class, sizeof (GtkGisGeometryLinePrivate));
 
        object_class->set_property = gtk_gis_geometry_line_set_property;
        object_class->get_property = gtk_gis_geometry_line_get_property;
+
+       geometry_class->draw = gtk_gis_geometry_line_draw;
 }
 
 static void
@@ -66,7 +73,7 @@ gtk_gis_geometry_line_init (GtkGisGeometryLine *gtk_gis_geometry_line)
 {
        GtkGisGeometryLinePrivate *priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (gtk_gis_geometry_line);
 
-       priv->points = g_ptr_array_new ();
+       priv->points = NULL;
 }
 
 /**
@@ -87,7 +94,7 @@ GtkGisGeometry
 }
 
 /**
- * gtk_gis_geometry_line_new_from_array:
+ * gtk_gis_geometry_line_new_from_list:
  * @points:
  *
  * Creates a new #GtkGisGeometryLine object.
@@ -95,7 +102,7 @@ GtkGisGeometry
  * Returns: the newly created #GtkGisGeometryLine object.
  */
 GtkGisGeometry
-*gtk_gis_geometry_line_new_from_array (GPtrArray *points)
+*gtk_gis_geometry_line_new_from_list (GSList *points)
 {
        GtkGisGeometry *line = NULL;
        GtkGisGeometryLinePrivate *priv;
@@ -104,7 +111,7 @@ GtkGisGeometry
 
        priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line));
 
-       priv->points = points;
+       priv->points = g_slist_copy (points);
 
        return line;
 }
@@ -126,7 +133,7 @@ gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point)
        gpoint->x = point.x;
        gpoint->y = point.y;
 
-       g_ptr_array_add (priv->points, gpoint);
+       priv->points = g_slist_append (priv->points, gpoint);
 }
 
 /**
@@ -148,6 +155,74 @@ gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
        gtk_gis_geometry_line_add_point (line, gpoint);
 }
 
+static gchar
+*convert_comma_to_dot (gchar *str)
+{
+       /* convert , in . */
+       gint len;
+       gint i;
+       gchar *ret = NULL;
+
+       len = strlen (str);
+
+       if (len > 0)
+               {
+                       ret = g_malloc (len + 1);
+                       strcpy (ret, str);
+               }
+
+       for (i = 0; i < len; i++)
+               {
+                       if (ret[i] == ',')
+                               {
+                                       ret[i] = '.';
+                               }
+               }
+
+       return ret;
+}
+
+static GooCanvasItem
+*gtk_gis_geometry_line_draw (GtkGisGeometry *line)
+{
+       GtkGisGeometryLinePrivate *priv;
+       GooCanvasItem *item = NULL;
+       GtkGisPoint *point;
+
+       gchar *path;
+
+       priv = GTK_GIS_GEOMETRY_LINE_GET_PRIVATE (GTK_GIS_GEOMETRY_LINE (line));
+
+       if (priv->points != NULL)
+               {
+                       GSList *cur;
+
+                       cur = priv->points;
+
+                       point = (GtkGisPoint *)cur->data;
+                       path = g_strdup_printf ("M %f %f", point->x, point->y);
+
+                       cur = g_slist_next (cur);
+                       while (cur != NULL)
+                               {
+                                       point = (GtkGisPoint *)cur->data;
+                                       path = g_strconcat (path,
+                                              g_strdup_printf (" L %f %f", point->x, point->y),
+                                              NULL);
+
+                                       cur = g_slist_next (cur);
+                               }
+
+                       path = convert_comma_to_dot (path);
+                       item = goo_canvas_path_new (NULL,
+                                                   path,
+                                                   "line-width", 1.0,
+                                                   NULL);
+               }
+
+       return item;
+}
+
 static void
 gtk_gis_geometry_line_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
index 97d3d52e872060f6f7b3932e59dba3c6496a25ff..e967a9b5e45bad985ffc233c83ebe5c3fce5d8ba 100644 (file)
@@ -52,7 +52,7 @@ 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_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_line_new_from_list (GSList *points);
 
 void gtk_gis_geometry_line_add_point (GtkGisGeometryLine *line, GtkGisPoint point);
 void gtk_gis_geometry_line_add_point_from_coordinates (GtkGisGeometryLine *line,
index 8647b296ddb20fcfcca1d7d85d12d4e73dfd1e15..1a16c871467978897bf0463dd492571cca2bc765 100644 (file)
@@ -30,6 +30,8 @@
 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);
+
 static void gtk_gis_geometry_point_set_property (GObject *object,
                                      guint property_id,
                                      const GValue *value,
@@ -45,7 +47,7 @@ static void gtk_gis_geometry_point_get_property (GObject *object,
 typedef struct _GtkGisGeometryPointPrivate GtkGisGeometryPointPrivate;
 struct _GtkGisGeometryPointPrivate
        {
-               GtkGisPoint point;
+               GtkGisPoint *point;
        };
 
 G_DEFINE_TYPE (GtkGisGeometryPoint, gtk_gis_geometry_point, TYPE_GTK_GIS_GEOMETRY)
@@ -54,17 +56,22 @@ static void
 gtk_gis_geometry_point_class_init (GtkGisGeometryPointClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
 
        g_type_class_add_private (object_class, sizeof (GtkGisGeometryPointPrivate));
 
        object_class->set_property = gtk_gis_geometry_point_set_property;
        object_class->get_property = gtk_gis_geometry_point_get_property;
+
+       geometry_class->draw = gtk_gis_geometry_point_draw;
 }
 
 static void
 gtk_gis_geometry_point_init (GtkGisGeometryPoint *gtk_gis_geometry_point)
 {
        GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (gtk_gis_geometry_point);
+
+       priv->point = NULL;
 }
 
 /**
@@ -85,8 +92,10 @@ GtkGisGeometry
 
        priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (GTK_GIS_GEOMETRY_POINT (gpoint));
 
-       priv->point.x = point.x;
-       priv->point.y = point.y;
+       priv->point = g_malloc0 (sizeof (GtkGisPoint));
+
+       priv->point->x = point.x;
+       priv->point->y = point.y;
 
        return gpoint;
 }
@@ -106,8 +115,8 @@ GtkGisPoint
 
        gpoint = g_malloc0 (sizeof (GtkGisPoint));
 
-       gpoint->x = priv->point.x;
-       gpoint->y = priv->point.y;
+       gpoint->x = priv->point->x;
+       gpoint->y = priv->point->y;
 
        return gpoint;
 }
@@ -122,7 +131,7 @@ gtk_gis_geometry_point_get_x (GtkGisGeometryPoint *point)
 {
        GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
 
-       return priv->point.x;
+       return priv->point->x;
 }
 
 /**
@@ -135,7 +144,26 @@ gtk_gis_geometry_point_get_y (GtkGisGeometryPoint *point)
 {
        GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (point);
 
-       return priv->point.y;
+       return priv->point->y;
+}
+
+static
+GooCanvasItem *gtk_gis_geometry_point_draw (GtkGisGeometry *point)
+{
+       GooCanvasItem *item = NULL;
+
+       GtkGisGeometryPointPrivate *priv = GTK_GIS_GEOMETRY_POINT_GET_PRIVATE (GTK_GIS_GEOMETRY_POINT (point));
+
+       if (priv->point != NULL)
+               {
+                       item = goo_canvas_rect_new (NULL,
+                                                   priv->point->x, priv->point->y,
+                                                   1, 1,
+                                                   "line-width", 1.0,
+                                                   NULL);
+               }
+
+       return item;
 }
 
 static void
index 01bc588cb878c1e6a928a01607d69a548f720d0f..27af4ab9af4f554329596f6fff6f0641a8a1c492 100644 (file)
@@ -30,6 +30,8 @@
 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);
+
 static void gtk_gis_geometry_polygon_set_property (GObject *object,
                                      guint property_id,
                                      const GValue *value,
@@ -45,7 +47,7 @@ static void gtk_gis_geometry_polygon_get_property (GObject *object,
 typedef struct _GtkGisGeometryPolygonPrivate GtkGisGeometryPolygonPrivate;
 struct _GtkGisGeometryPolygonPrivate
        {
-               GList *lines;
+               GSList *lines;
        };
 
 G_DEFINE_TYPE (GtkGisGeometryPolygon, gtk_gis_geometry_polygon, TYPE_GTK_GIS_GEOMETRY)
@@ -54,11 +56,14 @@ static void
 gtk_gis_geometry_polygon_class_init (GtkGisGeometryPolygonClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkGisGeometryClass *geometry_class = GTK_GIS_GEOMETRY_CLASS (klass);
 
        g_type_class_add_private (object_class, sizeof (GtkGisGeometryPolygonPrivate));
 
        object_class->set_property = gtk_gis_geometry_polygon_set_property;
        object_class->get_property = gtk_gis_geometry_polygon_get_property;
+
+       geometry_class->draw = gtk_gis_geometry_polygon_draw;
 }
 
 static void
@@ -105,7 +110,7 @@ GtkGisGeometry
 }
 
 /**
- * gtk_gis_geometry_polygon_new_from_array:
+ * gtk_gis_geometry_polygon_new_from_list:
  * @points:
  *
  * Creates a new #GtkGisGeometryPolygon object.
@@ -113,12 +118,12 @@ GtkGisGeometry
  * Returns: the newly created #GtkGisGeometryPolygon object.
  */
 GtkGisGeometry
-*gtk_gis_geometry_polygon_new_from_array (GPtrArray *points)
+*gtk_gis_geometry_polygon_new_from_list (GSList *points)
 {
        GtkGisGeometry *polygon = NULL;
        GtkGisGeometry *line = NULL;
 
-       line = gtk_gis_geometry_line_new_from_array (points);
+       line = gtk_gis_geometry_line_new_from_list (points);
 
        if (line != NULL)
                {
@@ -141,7 +146,7 @@ gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon,
 {
        GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
 
-       priv->lines = g_list_append (priv->lines, line);
+       priv->lines = g_slist_append (priv->lines, line);
 }
 
 /**
@@ -156,7 +161,45 @@ gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon,
 {
        GtkGisGeometryPolygonPrivate *priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (polygon);
 
-       priv->lines = g_list_remove (priv->lines, line);
+       priv->lines = g_slist_remove (priv->lines, line);
+}
+
+static GooCanvasItem
+*gtk_gis_geometry_polygon_draw (GtkGisGeometry *polygon)
+{
+       GtkGisGeometryPolygonPrivate *priv;
+       GooCanvasItem *polygon_item = NULL;
+
+       gchar *path;
+
+       priv = GTK_GIS_GEOMETRY_POLYGON_GET_PRIVATE (GTK_GIS_GEOMETRY_POLYGON (polygon));
+
+       if (priv->lines != NULL)
+               {
+                       GSList *cur;
+                       GtkGisGeometryLine *line;
+                       GooCanvasItem *item = NULL;
+
+                       polygon_item = goo_canvas_group_new (NULL, NULL);
+
+                       cur = priv->lines;
+
+                       line = (GtkGisGeometryLine *)cur->data;
+
+                       while (cur != NULL)
+                               {
+                                       item = gtk_gis_geometry_draw (GTK_GIS_GEOMETRY (line));
+
+                                       if (item != NULL)
+                                               {
+                                                       goo_canvas_item_add_child (polygon_item, item, -1);
+                                               }
+                                       
+                                       cur = g_slist_next (cur);
+                               }
+               }
+
+       return polygon_item;
 }
 
 static void
index 0b6e008c94fc0e7ae4b295170c212b683be3b393..641ac47107e3fe4877b91ab1d6cc98b065ebfbbf 100644 (file)
@@ -52,7 +52,7 @@ GType gtk_gis_geometry_polygon_get_type (void) G_GNUC_CONST;
 GtkGisGeometry *gtk_gis_geometry_polygon_new (void);
 
 GtkGisGeometry *gtk_gis_geometry_polygon_new_from_line (GtkGisGeometryLine *line);
-GtkGisGeometry *gtk_gis_geometry_polygon_new_from_array (GPtrArray *points);
+GtkGisGeometry *gtk_gis_geometry_polygon_new_from_list (GSList *points);
 
 void gtk_gis_geometry_polygon_add_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
 void gtk_gis_geometry_polygon_remove_line (GtkGisGeometryPolygon *polygon, GtkGisGeometryLine *line);
index 526cde861f627020ab107762780a8c778c67eabc..81434779f57132218ddca15c5dc711a969853c4d 100644 (file)
@@ -38,6 +38,10 @@ static void gtk_gis_destroy (GtkObject *object);
 
 static void gtk_gis_add (GtkContainer *container,
                          GtkWidget *widget);
+static void gtk_gis_forall (GtkContainer *container,
+                            gboolean include_internals,
+                            GtkCallback callback,
+                            gpointer callback_data);
 
 static void gtk_gis_set_property (GObject *object,
                                      guint property_id,
@@ -64,10 +68,13 @@ struct _GtkGisPrivate
                GtkWidget *canvas;
                GooCanvasItem *canvas_root;
 
-               GList *layers_groups;
-               GList *layers;
+               GSList *layers_groups;
+               GSList *layers;
 
-               GtkGisLayerExtent extent;
+               GtkGisLayerExtent *extent;
+
+               gdouble scale_x;
+               gdouble scale_y;
        };
 
 G_DEFINE_TYPE (GtkGis, gtk_gis, GTK_TYPE_BIN)
@@ -91,6 +98,7 @@ gtk_gis_class_init (GtkGisClass *klass)
        widget_class->size_allocate = gtk_gis_size_allocate;
 
        container_class->add = gtk_gis_add;
+       container_class->forall = gtk_gis_forall;
 }
 
 static void
@@ -105,6 +113,14 @@ gtk_gis_init (GtkGis *gtk_gis)
     gtk_container_add (GTK_CONTAINER (priv->scroll_win), priv->canvas);
   
     priv->canvas_root = goo_canvas_get_root_item (GOO_CANVAS (priv->canvas));
+
+       priv->layers_groups = NULL;
+       priv->layers = NULL;
+
+       priv->extent = NULL;
+
+       priv->scale_x = 0.0;
+       priv->scale_y = 0.0;
 }
 
 /**
@@ -241,6 +257,8 @@ GtkWidget
                        g_warning ("The file is not a valid gtkgis file.");
                }
 
+       gtk_gis_draw (GTK_GIS (gtkgis));
+
        return gtkgis;
 }
 
@@ -287,32 +305,43 @@ gtk_gis_add_layer (GtkGis *gtkgis, GtkGisLayer *layer)
 
        priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
-       priv->layers = g_list_append (priv->layers, layer);
+       priv->layers = g_slist_append (priv->layers, layer);
 
        extent = gtk_gis_layer_get_extent (layer);
 
-       if (extent.min_x < priv->extent.min_x)
-               {
-                       priv->extent.min_x = extent.min_x;
-               }
-       if (extent.min_y < priv->extent.min_y)
-               {
-                       priv->extent.min_y = extent.min_y;
-               }
-       if (extent.max_x > priv->extent.max_x)
+       if (priv->extent == NULL)
                {
-                       priv->extent.max_x = extent.max_x;
+                       priv->extent = g_malloc (sizeof (GtkGisLayerExtent));
+                       priv->extent->min_x = extent.min_x;
+                       priv->extent->max_x = extent.max_x;
+                       priv->extent->min_y = extent.min_y;
+                       priv->extent->max_y = extent.max_y;
                }
-       if (extent.max_y > priv->extent.max_y)
+       else
                {
-                       priv->extent.max_y = extent.max_y;
+                       if (extent.min_x < priv->extent->min_x)
+                               {
+                                       priv->extent->min_x = extent.min_x;
+                               }
+                       if (extent.min_y < priv->extent->min_y)
+                               {
+                                       priv->extent->min_y = extent.min_y;
+                               }
+                       if (extent.max_x > priv->extent->max_x)
+                               {
+                                       priv->extent->max_x = extent.max_x;
+                               }
+                       if (extent.max_y > priv->extent->max_y)
+                               {
+                                       priv->extent->max_y = extent.max_y;
+                               }
                }
 
        goo_canvas_set_bounds (GOO_CANVAS (priv->canvas),
-                              priv->extent.min_x,
-                              priv->extent.min_y,
-                              priv->extent.max_x,
-                              priv->extent.max_y);
+                              priv->extent->min_x,
+                              priv->extent->min_y,
+                              priv->extent->max_x,
+                              priv->extent->max_y);
 }
 
 /**
@@ -325,7 +354,73 @@ gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer)
 {
        GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtkgis);
 
-       priv->layers = g_list_remove (priv->layers, layer);
+       priv->layers = g_slist_remove (priv->layers, layer);
+}
+
+/**
+ * gtk_gis_draw:
+ * @gtkgis:
+ *
+ */
+void
+gtk_gis_draw (GtkGis *gtkgis)
+{
+       GtkGisPrivate *priv;
+       GSList *cur;
+
+       priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+       cur = priv->layers;
+       while (cur != NULL)
+               {
+                       gtk_gis_layer_draw ((GtkGisLayer *)cur->data, priv->canvas_root);
+
+                       cur = g_slist_next (cur);
+               }
+}
+
+/**
+ * gtk_gis_zoom_to_max:
+ * @gtkgis:
+ *
+ */
+void
+gtk_gis_zoom_to_max (GtkGis *gtkgis)
+{
+       GtkGisPrivate *priv;
+       GtkRequisition requisition;
+
+       priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+g_fprintf(stderr,"%f %f %f %f\n", priv->extent->min_x, priv->extent->max_x,
+priv->extent->min_y, priv->extent->max_y);
+
+       gtk_gis_size_request (GTK_WIDGET (gtkgis), &requisition);
+g_fprintf(stderr,"%d %d\n", requisition.width, requisition.height);
+       /*priv->scale_x = requisition.width / (priv->extent->max_x - priv->extent->min_x);
+       priv->scale_y = requisition.height / (priv->extent->max_y - priv->extent->min_y);*/
+       priv->scale_x = 640 / (priv->extent->max_x - priv->extent->min_x);
+       priv->scale_y = 600 / (priv->extent->max_y - priv->extent->min_y);
+g_fprintf(stderr,"%f %f\n", priv->scale_x, priv->scale_y);
+       g_object_set (priv->canvas,
+                     "scale-x", priv->scale_x,
+                     "scale-y", priv->scale_y,
+                     NULL);
+}
+
+/**
+ * gtk_gis_zoom_to_layer:
+ * @gtkgis:
+ * @layer:
+ *
+ */
+void
+gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer)
+{
+       GtkGisPrivate *priv;
+
+       priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
 }
 
 static void
@@ -336,11 +431,11 @@ gtk_gis_destroy (GtkObject *object)
 
        /* TO DO */
        /* free each layers_groups before */
-       g_list_free (priv->layers_groups);
+       g_slist_free (priv->layers_groups);
 
        /* TO DO */
        /* free each layers before */
-       g_list_free (priv->layers);
+       g_slist_free (priv->layers);
 
        GTK_OBJECT_CLASS (gtk_gis_parent_class)->destroy (object);
 }
@@ -361,6 +456,21 @@ gtk_gis_add (GtkContainer *container,
        gtk_widget_set_parent (child, GTK_WIDGET (bin));
 }
 
+static void
+gtk_gis_forall (GtkContainer *container,
+                gboolean include_internals,
+                GtkCallback callback,
+                gpointer callback_data)
+{
+       g_return_if_fail (IS_GTK_GIS (container));
+       g_return_if_fail (callback != NULL);
+
+       GTK_CONTAINER_CLASS (gtk_gis_parent_class)->forall (container,
+                            include_internals,
+                            callback,
+                            callback_data);
+}
+
 static void
 gtk_gis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
 {
@@ -450,7 +560,6 @@ gtk_gis_size_allocate (GtkWidget *widget,
                        child_allocation.y = relative_allocation.y + allocation->y;
                        child_allocation.width = relative_allocation.width;
                        child_allocation.height = relative_allocation.height;
-
                        gtk_widget_size_allocate (bin->child, &child_allocation);
                }
 }
index 9bb0e7bf9bb4212f1eb82d88360b51be727dc9bd..3e19dc1a61ab0ba5bbb41ed8ef6b28718f7fbe21 100644 (file)
@@ -66,8 +66,12 @@ void gtk_gis_remove_group (GtkGis *gtkgis, GtkGisLayersGroup *group);
 void gtk_gis_add_layer (GtkGis *gtkgis, GtkGisLayer *layer);
 void gtk_gis_remove_layer (GtkGis *gtkgis, GtkGisLayer *layer);
 
-void gtk_gis_set_legend_visible (GtkGis *gtkgis, gboolean visible);
+void gtk_gis_draw (GtkGis *gtkgis);
+
+void gtk_gis_zoom_to_max (GtkGis *gtkgis);
+void gtk_gis_zoom_to_layer (GtkGis *gtkgis, GtkGisLayer *layer);
 
+void gtk_gis_set_legend_visible (GtkGis *gtkgis, gboolean visible);
 GtkWidget *gtk_gis_get_legend (GtkGis *gtkgis);
 
 
index 66c88f8f532a6bccefa1ac17980b366b6d7771bf..53fbc4ba74ff85b0070e9039a697e68e86014b17 100644 (file)
@@ -51,6 +51,7 @@ struct _GtkGisLayerPrivate
 
                GtkGisLayerSource *source;
 
+               GooCanvasItem *layer_item;
                GList *geometries;
 
                gboolean editable;
@@ -266,17 +267,36 @@ gtk_gis_layer_set_editable (GtkGisLayer *layer,
 /**
  * gtk_gis_layer_draw:
  * @layer:
- * @canvas_root:
+ * @root:
  *
  */
 void
-gtk_gis_layer_draw (GtkGisLayer *layer,
-                    GooCanvasItem *canvas_root)
+gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root)
 {
-       /*if (IS_GTK_GIS_LAYER_OBJECT (layer) && GTK_GIS_LAYER_GET_CLASS (layer)->draw != NULL)
+       GtkGisLayerPrivate *priv;
+
+       GList *cur;
+
+       GooCanvasItem *item;
+
+       priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+       g_return_if_fail (priv->geometries != NULL);
+
+       priv->layer_item = goo_canvas_group_new (root, NULL);
+
+       cur = g_list_first (priv->geometries);
+       while (cur != NULL)
                {
-                       GTK_GIS_LAYER_GET_CLASS (layer)->draw (layer, canvas_root);
-               }*/
+                       item = gtk_gis_geometry_draw ((GtkGisGeometry *)cur->data);
+
+                       if (item != NULL)
+                               {
+                                       goo_canvas_item_add_child (priv->layer_item, item, -1);
+                               }
+
+                       cur = g_list_next (cur);
+               }
 }
 
 static void
index a89b7c4fcb908c8268f24626d713b9f66dde2220..4adfb8aff8a082b3e81fad497ec7802abff75cea 100644 (file)
@@ -82,8 +82,7 @@ gboolean gtk_gis_layer_get_editable (GtkGisLayer *layer);
 void gtk_gis_layer_set_editable (GtkGisLayer *layer,
                                  gboolean editable);
 
-void gtk_gis_layer_draw (GtkGisLayer *layer,
-                         GooCanvasItem *canvas_root);
+void gtk_gis_layer_draw (GtkGisLayer *layer, GooCanvasItem *root);
 
 
 G_END_DECLS
index b40d53cefcf011193c8432442f66c59b98715c41..7ffdfc0be6ac135005d93d2fd6f0bd9ff90885de 100644 (file)
@@ -101,103 +101,96 @@ GList
 {
        GList *geometries = NULL;
 
+       OGRLayerH layer;
+
+       OGRFeatureH feature;
+       OGRGeometryH poGeometry;
+       GtkGisGeometry *geometry;
+
        GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (source);
 
-    if (priv->datasource == NULL)
-           {
-                       /* TO DO */
-               }
-       else
+    g_return_if_fail (priv->datasource != NULL);
+
+       layer = OGR_DS_GetLayerByName (priv->datasource, name);
+
+       g_return_if_fail (layer != NULL);
+
+       OGR_L_ResetReading (layer);
+
+       while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
                {
-                       OGRLayerH layer;
-                       OGRFeatureDefnH layerDefn;
-                       OGRFeatureH feature;
-                       OGRGeometryH poGeometry;
-                       GtkGisGeometry *geometry;
+                       poGeometry = OGR_F_GetGeometryRef (feature);
 
-                       layer = OGR_DS_GetLayerByName (priv->datasource, name);
+                       if (poGeometry != NULL
+                               && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
+                               {
+                                       GtkGisPoint gpoint;
 
-                       layerDefn = OGR_L_GetLayerDefn (layer);
+                                       gpoint.x = OGR_G_GetX (poGeometry, 0);
+                                       gpoint.y = OGR_G_GetY (poGeometry, 0);
 
-                       while ((feature = OGR_L_GetNextFeature (layer)) != NULL)
+                                       geometry = gtk_gis_geometry_point_new (gpoint);
+                               }
+                       else if (poGeometry != NULL
+                               && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
                                {
-                                       poGeometry = OGR_F_GetGeometryRef (feature);
+                                       gint points;
+                                       gint point;
+                                       GSList *gpoints = NULL;
 
-                                       if (poGeometry != NULL
-                                               && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPoint)
+                                       GtkGisPoint *gpoint;
+
+                                       points = OGR_G_GetPointCount (poGeometry);
+
+                                       for (point = 0; point < points; point++)
                                                {
-                                                       GtkGisPoint gpoint;
+                                                       gpoint = g_malloc0 (sizeof (GtkGisPoint));
 
-                                                       gpoint.x = OGR_G_GetX (poGeometry, 0);
-                                                       gpoint.y = OGR_G_GetY (poGeometry, 0);
+                                                       gpoint->x = OGR_G_GetX (poGeometry, point);
+                                                       gpoint->y = OGR_G_GetY (poGeometry, point);
 
-                                                       geometry = gtk_gis_geometry_point_new (gpoint);
+                                                       gpoints = g_slist_append (gpoints, gpoint);
                                                }
-                                       else if (poGeometry != NULL
-                                               && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbLineString)
+
+                                       geometry = gtk_gis_geometry_line_new_from_list (gpoints);
+                               }
+                       else if (poGeometry != NULL
+                               && wkbFlatten (OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
+                               {
+                                       gint num_geometries;
+                                       gint i_geometry;
+
+                                       OGRGeometryH poGeometryIns;
+
+                                       num_geometries = OGR_G_GetGeometryCount (poGeometry);
+
+                                       for (i_geometry = 0; i_geometry < num_geometries; i_geometry++)
                                                {
                                                        gint points;
                                                        gint point;
-                                                       GPtrArray *gar_points;
+                                                       GSList *gpoints = NULL;
 
                                                        GtkGisPoint *gpoint;
 
-                                                       gar_points = g_ptr_array_new ();
+                                                       poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry);
 
-                                                       points = OGR_G_GetPointCount (poGeometry);
+                                                       points = OGR_G_GetPointCount (poGeometryIns);
 
                                                        for (point = 0; point < points; point++)
                                                                {
                                                                        gpoint = g_malloc0 (sizeof (GtkGisPoint));
 
-                                                                       gpoint->x = OGR_G_GetX (poGeometry, point);
-                                                                       gpoint->y = OGR_G_GetY (poGeometry, point);
+                                                                       gpoint->x = OGR_G_GetX (poGeometryIns, point);
+                                                                       gpoint->y = OGR_G_GetY (poGeometryIns, point);
 
-                                                                       g_ptr_array_add (gar_points, gpoint);
+                                                                       gpoints = g_slist_append (gpoints, gpoint);
                                                                }
 
-                                                       geometry = gtk_gis_geometry_line_new_from_array (gar_points);
+                                                       geometry = gtk_gis_geometry_polygon_new_from_list (gpoints);
                                                }
-                                       else if (poGeometry != NULL
-                                               && wkbFlatten(OGR_G_GetGeometryType (poGeometry)) == wkbPolygon)
-                                               {
-                                                       gint num_geometries;
-                                                       gint i_geometry;
-
-                                                       OGRGeometryH poGeometryIns;
-
-                                                       num_geometries = OGR_G_GetGeometryCount (poGeometry);
-
-                                                       for (i_geometry = 0; i_geometry < num_geometries; i_geometry++)
-                                                               {
-                                                                       gint points;
-                                                                       gint point;
-                                                                       GPtrArray *gar_points;
-
-                                                                       GtkGisPoint *gpoint;
-
-                                                                       poGeometryIns = OGR_G_GetGeometryRef (poGeometry, i_geometry);
-
-                                                                       gar_points = g_ptr_array_new ();
-
-                                                                       points = OGR_G_GetPointCount (poGeometry);
-
-                                                                       for (point = 0; point < points; point++)
-                                                                               {
-                                                                                       gpoint = g_malloc0 (sizeof (GtkGisPoint));
-
-                                                                                       gpoint->x = OGR_G_GetX (poGeometry, point);
-                                                                                       gpoint->y = OGR_G_GetY (poGeometry, point);
-
-                                                                                       g_ptr_array_add (gar_points, gpoint);
-                                                                               }
-
-                                                                       geometry = gtk_gis_geometry_polygon_new_from_array (gar_points);
-                                                               }
-                                               }
-
-                                       geometries = g_list_append (geometries, geometry);
                                }
+
+                       geometries = g_list_append (geometries, geometry);
                }
 
        return geometries;
@@ -231,17 +224,17 @@ gtk_gis_layer_source_get_layer_geometry_type (GtkGisLayerSource *source,
 
                        poGeometry = OGR_F_GetGeometryRef (feature);
                        if (poGeometry != NULL
-                           && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
+                           && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPoint)
                                {
                                        type = LAYER_GEOMETRY_TYPE_POINT;
                                }
                        else if (poGeometry != NULL
-                                && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
+                                && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbLineString)
                                {
                                        type = LAYER_GEOMETRY_TYPE_LINE;
                                }
                        else if (poGeometry != NULL
-                                && wkbFlatten(OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
+                                && wkbFlatten (OGR_G_GetGeometryType(poGeometry)) == wkbPolygon)
                                {
                                        type = LAYER_GEOMETRY_TYPE_POLYGON;
                                }
index afa64c73ea10237e346b322eefb5196645191dac..76e5091cbd39401a3b34650eaaf9b72183863e5f 100644 (file)
@@ -20,6 +20,8 @@ main (int argc, char *argv[])
 
        gtk_widget_show_all (window);
 
+       gtk_gis_zoom_to_max (GTK_GIS (gtkgis));
+
        gtk_main ();
 
        return 0;
index eb25c76cefa417502ed458f35418863d94cf45c2..f1bd6d99928671fc42d12bd6e5a2127abf68186b 100644 (file)
@@ -1,16 +1,16 @@
 <gtkgis>
 
-       <layer name="alaska">
+       <!--<layer name="alaska">
                <source>
                        <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/alaska.shp" />
                </source>
-       </layer>
+       </layer>-->
 
        <!--<layer name="airports">
                <source>
                        <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/airports.shp" />
                </source>
-       </layer>
+       </layer>-->
 
        <layer name="railroads">
                <source>
@@ -18,7 +18,7 @@
                </source>
        </layer>
 
-       <layer name="rivers">
+       <!--<layer name="rivers">
                <source>
                        <shape filename="/home/andreaz/files/c/libgtkgis/tests/samples/rivers.shp" />
                </source>