forked from sduclos/S52
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgvS57layer.c
136 lines (98 loc) · 3.71 KB
/
gvS57layer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// gvS57layer.c: S57 layer classe for OpenEV
//
// Project: OpENCview/OpenEV
/*
This file is part of the OpENCview project, a viewer of ENC.
Copyright (C) 2000-2016 Sylvain Duclos [email protected]
OpENCview is free software: you can redistribute it and/or modify
it under the terms of the Lesser GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpENCview is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Lesser GNU General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with OpENCview. If not, see <http://www.gnu.org/licenses/>.
*/
// Note: openev-2 only because openev-1 depend on GLib-1
// and libS52 use GLib-2 only now (2016)
#include "gvS57layer.h"
int S52_init();
int S52_drawLayer();
int S52_loadLayer(const char *layername, void *layer);
int S52_pickAt(double x, double y);
int S52_done();
#include "S52utils.h" // PRINTF()
#include <glib.h> // g_signal_connect()
#include <glib-object.h> // G_TYPE_CHECK_INSTANCE()
#include <gmodule.h> // g_module_init(), g_module_check_init(), g_module_unload()
static GModule *self = NULL; // handel to libS52.so (this)
static void _motion_handle_hint(GtkWidget *view, GdkEventMotion *event)
{
if (event->type==GDK_BUTTON_RELEASE && event->state & GDK_SHIFT_MASK) {
S52_pickAt(event->x, event->y);
}
}
static void gv_S57_draw_layer(GvLayer *layer, GvViewArea *view)
{
//GObject *layer = view->layers;
//char *name = (char *)gv_data_get_name(GV_DATA(layer));
char *name = (char *)gv_data_get_name(GV_DATA(layer));
S52_drawLayer(name);
//S52_drawLayer("DEPARE");
}
static void gv_S57_layer_setup(GvShapesLayer *layer, GvViewArea *view)
// load S57 --its in "wkt" OGC layer format
{
//printf("start S52 gv_S57_layer_setup\n");
if (NULL==layer || NULL==view) {
PRINTF("ERROR: no GvShapesLayer or GvViewArea\n");
return;
}
g_signal_connect(layer, "draw", gv_S57_draw_layer, view);
g_signal_connect(view, "button-release-event", _motion_handle_hint, view);
//printf("S52 name gv_S57_layer_setup\n");
//char *name = (char *)gv_data_get_name(GV_DATA(layer));
char *name = (char *)gv_data_get_name(layer);
S52_loadLayer(name, (void *)layer);
//printf("S52 fini gv_S57_layer_setup\n");
return;
}
void _layer_init(GvShapesLayer *layer)
{
// debug
//printf("from S52 _layer_init\n", sizeof(GvShapesLayer));
//printf("from S52 _layer_init\n");
//printf("from S52 sizeof(GvShapesLayer)%i\n", sizeof(GvShapesLayer));
//printf("from S52 sizeof(GArray) %i\n", sizeof(GArray));
g_signal_connect((gpointer)layer, "setup", gv_S57_layer_setup, (gpointer)layer);
//printf("fini _layer_init\n");
return;
}
const gchar * _ogr_driver_name()
{
// FIXME: get this programaticaly
//OGRSFDriverH hDriver = ... load_S57_driver_ ...
//return OGR_Dr_GetName(hDriver);
// pulled from: gdal/ogr/ogrsf_frmts/s57/ogrs57driver.cpp:69
// in 'const char *OGRS57Driver::GetName()'
return "S57";
}
const gchar *g_module_check_init(GModule *module)
{
PRINTF("loading libS52.so ...\n");
if (NULL == self) {
self = module;
//PRINTF("self name = %s\n", g_basename(g_module_name(self)));
// will print "self name = libS52.so"
}
S52_init();
return NULL;
}
void g_module_unload()
{
PRINTF("unloading libS52.so ...\n");
S52_done();
return;
}