Add LCOV remarkers to increase line coverage rate
[platform/core/api/maps-service.git] / src / view / runtime_data.cpp
1 /* Copyright (c) 2010-2014 Samsung Electronics Co., Ltd. All rights reserved.
2  *
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include "runtime_data.h"
19 #include "maps_util.h"
20 #include "maps_view_plugin.h"
21 #include <glib.h>
22
23 //LCOV_EXCL_START
24 view::touch_point::touch_point()
25         : _x(0)
26         , _y(0)
27         , _timestamp(0)
28 {
29         reset();
30 }
31
32 view::touch_point::~touch_point()
33 {
34 }
35
36 view::touch_point::touch_point(const int x,
37                                const int y,
38                                const unsigned int ts)
39         : _x(x)
40         , _y(y)
41         , _timestamp(ts)
42 {
43 }
44
45 view::touch_point::touch_point(const touch_point &src)
46         : _x(0)
47         , _y(0)
48         , _timestamp(0)
49 {
50         *this = src;
51 }
52
53 view::touch_point &view::touch_point::operator=(const touch_point &src)
54 {
55         if(this != &src) {
56                 _x = src._x;
57                 _y = src._y;
58                 _timestamp = src._timestamp;
59         }
60         return *this;
61 }
62
63 void view::touch_point::reset()
64 {
65         _x = 0;
66         _y = 0;
67         _timestamp = 0;
68 }
69
70 bool view::touch_point::empty() const
71 {
72         if(_x != 0)
73                 return false;
74         if(_y != 0)
75                 return false;
76         if(_timestamp != 0)
77                 return false;
78         return true;
79 }
80 /* ---------------------------------------------------------------------------*/
81
82
83 view::map_state::map_state()
84         : _center(NULL)
85         , _zoom_factor(.1)
86         , _rotation_angle(.0)
87         , _prev_zoom_factor(.1)
88         , _prev_rotation_angle(.0)
89 {
90         reset();
91 }
92
93 view::map_state::~map_state()
94 {
95         if(_center)
96                 maps_coordinates_destroy(_center);
97         _center = NULL;
98 }
99
100 view::map_state::map_state(const map_state &src)
101         : _center(NULL)
102         , _zoom_factor(.1)
103         , _rotation_angle(.0)
104         , _prev_zoom_factor(.1)
105         , _prev_rotation_angle(.0)
106 {
107         *this = src;
108 }
109
110 view::map_state &view::map_state::operator=(const map_state &src)
111 {
112         if(this != &src) {
113                 reset();
114                 maps_coordinates_clone(src._center, &_center);
115                 _zoom_factor = src._zoom_factor;
116                 _rotation_angle = src._rotation_angle;
117                 _prev_zoom_factor = src._prev_zoom_factor;
118                 _prev_rotation_angle = src._prev_rotation_angle;
119         }
120         return *this;
121 }
122
123 void view::map_state::reset()
124 {
125         if(_center)
126                 maps_coordinates_destroy(_center);
127         _center = NULL;
128
129         _zoom_factor = .1;
130         _rotation_angle = .0;
131         _prev_zoom_factor = .1;
132         _prev_rotation_angle = .0;
133
134 /*
135         MAPS_LOGI("%c[%d;%d;%dm"
136                   "central coordinates: RESET"
137                   "%c[%d;%d;%dm",
138                   0x1B, 1, 0, 31,
139                   0x1B, 0, 0, 0);
140 */
141 }
142
143 void view::map_state::capture(maps_view_h view)
144 {
145         if(!view)
146                 return;
147
148         reset();
149
150         maps_view_get_center(view, &_center);
151         maps_view_get_zoom_factor(view, &_zoom_factor);
152         maps_view_get_orientation(view, &_rotation_angle);
153         _prev_zoom_factor = _zoom_factor;
154         _prev_rotation_angle = _rotation_angle;
155
156         /* DEBUG */
157         maps_coordinates_h central_coords = NULL;
158         maps_view_get_center(view, &central_coords);
159         double lat = .0, lon = .0;
160         maps_coordinates_get_latitude_longitude(central_coords, &lat, &lon);
161         maps_coordinates_destroy(central_coords);
162         MAPS_LOGI("%c[%d;%d;%dm"
163                   "central coordinates: (%f, %f)"
164                   "%c[%d;%d;%dm",
165                   0x1B, 1, 0, 31,
166                   lat, lon,
167                   0x1B, 0, 0, 0);
168 }
169
170 void view::map_state::trace()
171 {
172         double latitude = .0;
173         double longitude = .0;
174         maps_coordinates_get_latitude_longitude(_center, &latitude, &longitude);
175
176         MAPS_LOGI("%c[%d;%d;%dm"
177                   "Map State: center(%f,%f), zoom(%f), angle(%f)"
178                   "%c[%d;%d;%dm",
179                   0x1B, 1, 0, 93,
180                   latitude, longitude, _zoom_factor, _rotation_angle,
181                   0x1B, 0, 0, 0);
182 }
183 /* ---------------------------------------------------------------------------*/
184
185 view::runtime_touch_info::runtime_touch_info()
186         : _fingers_pressed(0)
187           , _cur_gesture(MAPS_VIEW_GESTURE_NONE)
188           /*, _going(false)*/
189 {
190         reset();
191 }
192
193 view::runtime_touch_info::~runtime_touch_info()
194 {
195 }
196
197 view::runtime_touch_info::runtime_touch_info(const runtime_touch_info &src)
198 {
199         *this = src;
200 }
201
202 view::runtime_touch_info &view::runtime_touch_info::operator=(const
203                                                               runtime_touch_info
204                                                               &src)
205 {
206         if(this != &src) {
207                 _fingers_pressed = src._fingers_pressed;
208                 _cur_gesture = src._cur_gesture;
209                 /*_going = src._going;*/
210                 _start_view_state = src._start_view_state;
211
212                 for(unsigned int i = 0; i < MAX_FINGERS; i ++) {
213                         _finger_down[i] = src._finger_down[i];
214                         _finger_move[i] = src._finger_move[i];
215                         _prev_finger_down[i] = src._prev_finger_down[i];
216                         _finger_up[i] = src._finger_up[i];
217                         _is_finger_pressed[i] = src._is_finger_pressed[i];
218                 }
219         }
220         return *this;
221 }
222
223 void view::runtime_touch_info::reset()
224 {
225         /*_going = false;*/
226
227         _fingers_pressed = 0;
228
229         for(unsigned int i = 0; i < MAX_FINGERS; i ++) {
230                 _finger_down[i].reset();
231                 _finger_move[i].reset();
232                 _prev_finger_down[i].reset();
233                 _finger_up[i].reset();
234                 _is_finger_pressed[i] = false;
235         }
236
237         _cur_gesture = MAPS_VIEW_GESTURE_NONE;
238
239         _start_view_state.reset();
240 }
241
242 int view::runtime_touch_info::calc_finger_pressed()
243 {
244         int cnt = 0;
245         for(unsigned int i = 0; i < MAX_FINGERS; i ++)
246                 if(_is_finger_pressed[i])
247                         cnt++;
248         return cnt;
249 }
250 //LCOV_EXCL_STOP