Implemented GtkGis::save_to_xml.
Added GtkGisLayer::get_xml.
Added GtkGisLayerSource::get_xml.
Added GtkGisLayerSourceShp::get_xml.
Added GtkGisLayerSourcePostgis::get_xml.
Added GtkGisLayerSourceRaster::get_xml.
tests/.deps
tests/.libs
tests/from_xml
+tests/test_comune.gtkgis
tests/samples
# temporarily
static void gtk_gis_add (GtkContainer *container,
GtkWidget *widget);
+
+static gboolean gtk_gis_focus (GtkWidget*widget,
+ GtkDirectionType direction);
+
static void gtk_gis_forall (GtkContainer *container,
gboolean include_internals,
GtkCallback callback,
GValue *value,
GParamSpec *pspec);
+static gboolean gtk_gis_scroll_event (GtkWidget *widget,
+ GdkEventScroll *event);
+
static void gtk_gis_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_gis_size_allocate (GtkWidget *widget,
object_class->destroy = gtk_gis_destroy;
+ widget_class->scroll_event = gtk_gis_scroll_event;
widget_class->size_request = gtk_gis_size_request;
widget_class->size_allocate = gtk_gis_size_allocate;
+ widget_class->focus = gtk_gis_focus;
container_class->add = gtk_gis_add;
container_class->forall = gtk_gis_forall;
{
GtkGisPrivate *priv = GTK_GIS_GET_PRIVATE (gtk_gis);
+ GTK_WIDGET_SET_FLAGS (gtk_gis, GTK_NO_WINDOW | GTK_CAN_FOCUS);
+
+ gtk_widget_set_events (GTK_WIDGET (gtk_gis),
+ GDK_BUTTON_PRESS_MASK
+ | gtk_widget_get_events (GTK_WIDGET (gtk_gis)));
+
+ //g_signal_connect (G_OBJECT (gtk_gis), "scroll-event", G_CALLBACK (gtk_gis_scroll_event), (gpointer)NULL);
+
priv->scroll_win = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (gtk_gis), priv->scroll_win);
priv->extent = NULL;
- priv->scale = g_malloc0 (sizeof (GtkGisScale));
+ priv->scale = g_malloc (sizeof (GtkGisScale));
priv->scale->x = 1.0;
priv->scale->y = 1.0;
priv->scale->xy = 1.0;
return gtkgis;
}
+/**
+ * gtk_gis_get_xml:
+ * @gtkgis:
+ *
+ */
+xmlDoc
+*gtk_gis_get_xml (GtkGis *gtkgis)
+{
+ xmlDoc *xdoc = NULL;
+ xmlNode *xroot;
+ xmlNode *xreport;
+ xmlNode *xnode;
+
+ GSList *cur_layer;
+
+ GtkGisPrivate *priv;
+
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+ xdoc = xmlNewDoc ("1.0");
+
+ xroot = xmlNewNode (NULL, "gtkgis");
+ xmlDocSetRootElement (xdoc, xroot);
+
+ cur_layer = priv->layers;
+ while (cur_layer != NULL)
+ {
+ xnode = gtk_gis_layer_get_xml ((GtkGisLayer *)cur_layer->data);
+
+ if (xnode != NULL)
+ {
+ xmlAddChild (xroot, xnode);
+ }
+
+ cur_layer = g_slist_next (cur_layer);
+ }
+
+ return xdoc;
+}
+
/**
* gtk_gis_save_to_xml:
* @gtkgis:
void
*gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *filename)
{
+ xmlDoc *xdoc;
+
+ g_return_if_fail (filename != NULL);
+
+ xdoc = gtk_gis_get_xml (gtkgis);
+
+ if (xdoc != NULL)
+ {
+ xmlSaveFormatFile (filename, xdoc, 2);
+ }
}
/**
gtk_widget_set_parent (child, GTK_WIDGET (bin));
}
+static gboolean
+gtk_gis_focus (GtkWidget*widget,
+ GtkDirectionType direction)
+{
+ if (GTK_WIDGET_CAN_FOCUS (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ return TRUE;
+ }
+ else
+ return FALSE;
+}
+
static void
gtk_gis_forall (GtkContainer *container,
gboolean include_internals,
}
}
+static gboolean
+gtk_gis_scroll_event (GtkWidget *widget,
+ GdkEventScroll *event)
+{
+ GtkGisPrivate *priv;
+
+ GtkGis *gtkgis;
+ GtkGisScale *scale;
+g_fprintf(stderr,"dentro scroll event");
+ g_return_val_if_fail (IS_GTK_GIS (widget), FALSE);
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ gtkgis = GTK_GIS (widget);
+ priv = GTK_GIS_GET_PRIVATE (gtkgis);
+
+ scale = gtk_gis_get_scale (gtkgis);
+
+ if (event->direction == GDK_SCROLL_UP)
+ {g_fprintf(stderr,"dentro scroll up");
+ scale->x = (scale->x * 120) / 100;
+ scale->y = (scale->y * 120) / 100;
+ scale->xy = (scale->xy * 120) / 100;
+ }
+ else if (event->direction == GDK_SCROLL_DOWN)
+ {g_fprintf(stderr,"dentro scroll down");
+ scale->x = (scale->x * 80) / 100;
+ scale->y = (scale->y * 80) / 100;
+ scale->xy = (scale->xy * 80) / 100;
+ }
+
+ gtk_gis_set_scale (gtkgis, scale);
+
+ return TRUE;
+}
+
static void
gtk_gis_size_request (GtkWidget *widget,
GtkRequisition *requisition)
GtkWidget *gtk_gis_new_from_xml (xmlDoc *xdoc);
GtkWidget *gtk_gis_new_from_file (const gchar *filename);
+xmlDoc *gtk_gis_get_xml (GtkGis *gtkgis);
void *gtk_gis_save_to_xml (GtkGis *gtkgis, const gchar *filename);
void gtk_gis_add_group (GtkGis *gtkgis, GtkGisLayersGroup *group);
return layer;
}
+/**
+ * gtk_gis_layer_get_xml:
+ * @layer:
+ *
+ */
+xmlNode
+*gtk_gis_layer_get_xml (GtkGisLayer *layer)
+{
+ xmlNode *xnode;
+
+ GtkGisLayerPrivate *priv;
+
+ priv = GTK_GIS_LAYER_GET_PRIVATE (layer);
+
+ xnode = xmlNewNode (NULL, "layer");
+
+ if (priv->name != NULL)
+ {
+ xmlSetProp (xnode, "name", priv->name);
+ }
+
+ if (priv->source != NULL)
+ {
+ xmlNode *xnode_source;
+
+ xnode_source = gtk_gis_layer_source_get_xml (priv->source);
+ xmlAddChild (xnode, xnode_source);
+ }
+
+ return xnode;
+}
+
/**
* gtk_gis_layer_get_name:
* @layer:
#include <goocanvas.h>
+#include <libxml/tree.h>
+
#include "commons.h"
#include "geometry.h"
#include "layersource.h"
GtkGisLayer *gtk_gis_layer_new_from_source (GtkGisLayerSource *source,
const gchar *name);
+xmlNode *gtk_gis_layer_get_xml (GtkGisLayer *layer);
+
gchar *gtk_gis_layer_get_name (GtkGisLayer *layer);
GtkGisLayerSource *gtk_gis_layer_get_source (GtkGisLayer *layer);
GtkGisLayerSourcePrivate *priv = GTK_GIS_LAYER_SOURCE_GET_PRIVATE (gtk_gis_layer_source);
}
+/**
+ * gtk_gis_layer_source_get_xml:
+ * @source:
+ *
+ */
+xmlNode
+*gtk_gis_layer_source_get_xml (GtkGisLayerSource *source)
+{
+ xmlNode *xnode = NULL;
+ xmlNode *xnode_source = NULL;
+
+ if (IS_GTK_GIS_LAYER_SOURCE (source) && GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_xml != NULL)
+ {
+ xnode_source = GTK_GIS_LAYER_SOURCE_GET_CLASS (source)->get_xml (source);
+ }
+
+ if (xnode_source != NULL)
+ {
+ xnode = xmlNewNode (NULL, "source");
+ xmlAddChild (xnode, xnode_source);
+ }
+
+ return xnode;
+}
+
/**
* gtk_gis_layer_source_get_geometries:
* @source:
#include <ogr_api.h>
#include <ogr_core.h>
+#include <libxml/tree.h>
+
#include "commons.h"
#include "geometry.h"
{
GObjectClass parent_class;
+ xmlNode *(*get_xml) (GtkGisLayerSource *source);
+
void (*set_ogr_datasource) (GtkGisLayerSource *source,
OGRDataSourceH datasource);
void (*set_gdal_dataset) (GtkGisLayerSource *source,
GType gtk_gis_layer_source_get_type (void) G_GNUC_CONST;
+xmlNode *gtk_gis_layer_source_get_xml (GtkGisLayerSource *source);
+
GList *gtk_gis_layer_source_get_geometries (GtkGisLayerSource *source,
const gchar *name);
#include <config.h>
#endif
+#include <libxml/tree.h>
+
#include "layersourcepostgis.h"
static void gtk_gis_layer_source_postgis_class_init (GtkGisLayerSourcePostgisClass *klass);
static void gtk_gis_layer_source_postgis_init (GtkGisLayerSourcePostgis *gtk_gis_layer_source_postgis);
+static xmlNode *gtk_gis_layer_source_postgis_get_xml (GtkGisLayerSource *source);
+
static void gtk_gis_layer_source_postgis_set_property (GObject *object,
guint property_id,
const GValue *value,
gtk_gis_layer_source_postgis_class_init (GtkGisLayerSourcePostgisClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkGisLayerSourceClass *gtkgislayersource_class = GTK_GIS_LAYER_SOURCE_CLASS (klass);
g_type_class_add_private (object_class, sizeof (GtkGisLayerSourcePostgisPrivate));
object_class->set_property = gtk_gis_layer_source_postgis_set_property;
object_class->get_property = gtk_gis_layer_source_postgis_get_property;
+
+ gtkgislayersource_class->get_xml = gtk_gis_layer_source_postgis_get_xml;
}
static void
return source;
}
+static xmlNode
+*gtk_gis_layer_source_postgis_get_xml (GtkGisLayerSource *source)
+{
+ xmlNode *xnode = NULL;
+
+ GtkGisLayerSourcePostgisPrivate *priv;
+
+ priv = GTK_GIS_LAYER_SOURCE_POSTGIS_GET_PRIVATE (source);
+
+ xnode = xmlNewNode (NULL, "postgis");
+
+ if (priv->host != NULL)
+ {
+ xmlSetProp (xnode, "host", priv->host);
+ }
+ if (priv->port != 0)
+ {
+ xmlSetProp (xnode, "port", g_strdup_printf ("%d", priv->port));
+ }
+ if (priv->username != NULL)
+ {
+ xmlSetProp (xnode, "username", priv->username);
+ }
+ if (priv->password != NULL)
+ {
+ xmlSetProp (xnode, "password", priv->password);
+ }
+
+ return xnode;
+}
+
static void
gtk_gis_layer_source_postgis_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
#include <config.h>
#endif
+#include <libxml/tree.h>
+
#include <gdal.h>
#include "layersourceraster.h"
static void gtk_gis_layer_source_raster_class_init (GtkGisLayerSourceRasterClass *klass);
static void gtk_gis_layer_source_raster_init (GtkGisLayerSourceRaster *gtk_gis_layer_source_raster);
+static xmlNode *gtk_gis_layer_source_raster_get_xml (GtkGisLayerSource *source);
+
static void
gtk_gis_layer_source_raster_set_gdal_dataset (GtkGisLayerSource *source,
GDALDatasetH hDataset);
object_class->set_property = gtk_gis_layer_source_raster_set_property;
object_class->get_property = gtk_gis_layer_source_raster_get_property;
+
+ gtkgislayersource_class->get_xml = gtk_gis_layer_source_raster_get_xml;
}
static void
return g_strdup (priv->filename);
}
+static xmlNode
+*gtk_gis_layer_source_raster_get_xml (GtkGisLayerSource *source)
+{
+ xmlNode *xnode = NULL;
+
+ GtkGisLayerSourceRasterPrivate *priv;
+
+ priv = GTK_GIS_LAYER_SOURCE_RASTER_GET_PRIVATE (source);
+
+ xnode = xmlNewNode (NULL, "raster");
+
+ if (priv->filename != NULL)
+ {
+ xmlSetProp (xnode, "filename", priv->filename);
+ }
+
+ return xnode;
+}
+
static void
gtk_gis_layer_source_raster_set_gdal_dataset (GtkGisLayerSource *source,
GDALDatasetH hDataset)
#include <ogr_api.h>
#include <ogr_core.h>
+#include <libxml/tree.h>
+
#include "layersourceshp.h"
static void gtk_gis_layer_source_shp_class_init (GtkGisLayerSourceShpClass *klass);
static void gtk_gis_layer_source_shp_init (GtkGisLayerSourceShp *gtk_gis_layer_source_shp);
+static xmlNode *gtk_gis_layer_source_shp_get_xml (GtkGisLayerSource *source);
+
static void
gtk_gis_layer_source_shp_set_ogr_datasource (GtkGisLayerSource *source,
OGRDataSourceH datasource);
object_class->set_property = gtk_gis_layer_source_shp_set_property;
object_class->get_property = gtk_gis_layer_source_shp_get_property;
+
+ gtkgislayersource_class->get_xml = gtk_gis_layer_source_shp_get_xml;
}
static void
return g_strdup (priv->filename);
}
+static xmlNode
+*gtk_gis_layer_source_shp_get_xml (GtkGisLayerSource *source)
+{
+ xmlNode *xnode = NULL;
+
+ GtkGisLayerSourceShpPrivate *priv;
+
+ priv = GTK_GIS_LAYER_SOURCE_SHP_GET_PRIVATE (source);
+
+ xnode = xmlNewNode (NULL, "shape");
+
+ if (priv->filename != NULL)
+ {
+ xmlSetProp (xnode, "filename", priv->filename);
+ }
+
+ return xnode;
+}
+
static void
gtk_gis_layer_source_shp_set_ogr_datasource (GtkGisLayerSource *source,
OGRDataSourceH datasource)
gtk_gis_zoom_to_max (GTK_GIS (gtkgis));
gtk_gis_draw (GTK_GIS (gtkgis));
+ gtk_gis_save_to_xml (GTK_GIS (gtkgis), "test_saved.gtkgis");
+
gtk_main ();
return 0;
<layer name="alaska">
<source>
- <shape filename="samples/alaska.shp" />
+ <shape filename="tests/samples/alaska.shp" />
</source>
</layer>
<layer name="airports">
<source>
- <shape filename="samples/airports.shp" />
+ <shape filename="tests/samples/airports.shp" />
</source>
</layer>
<layer name="railroads">
<source>
- <shape filename="samples/railroads.shp" />
+ <shape filename="tests/samples/railroads.shp" />
</source>
</layer>
<layer name="rivers">
<source>
- <shape filename="samples/rivers.shp" />
+ <shape filename="tests/samples/rivers.shp" />
</source>
</layer>