1 /*
2     This file is part of darktable,
3     Copyright (C) 2010-2021 darktable developers.
4 
5     darktable is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     darktable is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with darktable.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 
21 #include "common/geo.h"
22 #include <glib.h>
23 #include <sqlite3.h>
24 #include <stdint.h>
25 
26 typedef enum dt_map_locations_type_t
27 {
28   MAP_LOCATION_SHAPE_ELLIPSE,
29   MAP_LOCATION_SHAPE_RECTANGLE,
30   MAP_LOCATION_SHAPE_POLYGONS,
31   MAP_LOCATION_SHAPE_MAX
32 } dt_map_locations_type_t;
33 
34 typedef enum dt_map_locations_action_t
35 {
36   MAP_LOCATION_ACTION_REMOVE,
37   MAP_LOCATION_ACTION_UPDATE_OTHERS,
38   MAP_LOCATION_ACTION_MAX
39 } dt_map_locations_action_t;
40 
41 typedef struct dt_map_location_data_t
42 {
43   double lon, lat, delta1, delta2, ratio;
44   int shape;
45   GList *polygons;
46   int plg_pts;
47 } dt_map_location_data_t;
48 
49 typedef struct dt_location_draw_t
50 {
51   guint id;
52   dt_map_location_data_t data;
53   void *location;
54 } dt_location_draw_t;
55 
56 typedef struct dt_map_location_t
57 {
58   guint id;
59   gchar *tag;
60   guint count;
61 } dt_map_location_t;
62 
63 // create a new location
64 guint dt_map_location_new(const char *const name);
65 
66 // remove a location
67 void dt_map_location_delete(const guint locid);
68 
69 // rename a location
70 void dt_map_location_rename(const guint locid, const char *const name);
71 
72 // does the location name already exist
73 gboolean dt_map_location_name_exists(const char *const name);
74 
75 // gets location's images number
76 int dt_map_location_get_images_count(const guint locid);
77 
78 // retrieve list of tags which are on that path
79 // to be freed with dt_map_location_free_result()
80 GList *dt_map_location_get_locations_by_path(const gchar *path,
81                                              const gboolean remove_root);
82 
83 // retrieve list of locations which are on the map
84 // to be freed with g_list_free_full(list, g_free)
85 GList *dt_map_location_get_locations_on_map(const dt_map_box_t *const bbox);
86 
87 // free map location list
88 void dt_map_location_free_result(GList **result);
89 
90 // sort the tag list considering the '|' character
91 GList *dt_map_location_sort(GList *tags);
92 
93 // get location's data
94 dt_map_location_data_t *dt_map_location_get_data(const guint locid);
95 
96 // set locations's data
97 void dt_map_location_set_data(const guint locid, const dt_map_location_data_t *g);
98 
99 // find locations which match with that image
100 GList *dt_map_location_find_locations(const guint imgid);
101 
102 // update image's locations - remove old ones and add new ones
103 void dt_map_location_update_locations(const guint imgid, const GList *tags);
104 
105 // update location's images - remove old ones and add new ones
106 gboolean dt_map_location_update_images(dt_location_draw_t *ld);
107 
108 // return root tag for location geotagging
109 const char *dt_map_location_data_tag_root();
110 
111 // tell if the point (lon, lat) belongs to location
112 gboolean dt_map_location_included(const float lon, const float lat,
113                                   dt_map_location_data_t *g);
114 
115 // get the map box containing the polygon + flat polygons
116 GList *dt_map_location_convert_polygons(void *polygons, dt_map_box_t *bbox, int *nb_pts);
117 
118 // get the polygons for the given location
119 void dt_map_location_get_polygons(dt_location_draw_t *ld);
120 
121 // free flat polygons
122 void dt_map_location_free_polygons(dt_location_draw_t *ld);
123 
124 
125 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
126 // vim: shiftwidth=2 expandtab tabstop=2 cindent
127 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
128