-
-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy patharvgcfloat.c
313 lines (242 loc) · 8.92 KB
/
arvgcfloat.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* Aravis - Digital camera library
*
* Copyright © 2009-2025 Emmanuel Pacaud <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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 GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Emmanuel Pacaud <[email protected]>
*/
/**
* SECTION: arvgcfloat
* @short_description: Float interface
*/
#include <arvgcfloat.h>
#include <arvgcfeaturenodeprivate.h>
#include <arvgcdefaultsprivate.h>
#include <arvgc.h>
#include <arvmisc.h>
#include <stdio.h>
#include <arvdebugprivate.h>
static void
arv_gc_float_default_init (ArvGcFloatInterface *gc_float_iface)
{
}
G_DEFINE_INTERFACE (ArvGcFloat, arv_gc_float, G_TYPE_OBJECT)
double
arv_gc_float_get_value (ArvGcFloat *gc_float, GError **error)
{
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
if (!arv_gc_feature_node_check_read_access (ARV_GC_FEATURE_NODE (gc_float), error))
return 0.0;
return ARV_GC_FLOAT_GET_IFACE (gc_float)->get_value (gc_float, error);
}
void
arv_gc_float_set_value (ArvGcFloat *gc_float, double value, GError **error)
{
ArvGc *genicam;
ArvRangeCheckPolicy policy;
GError *local_error = NULL;
g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
g_return_if_fail (error == NULL || *error == NULL);
if (!arv_gc_feature_node_check_write_access (ARV_GC_FEATURE_NODE (gc_float), error))
return;
genicam = arv_gc_node_get_genicam (ARV_GC_NODE (gc_float));
g_return_if_fail (ARV_IS_GC (genicam));
policy = arv_gc_get_range_check_policy (genicam);
if (policy != ARV_RANGE_CHECK_POLICY_DISABLE) {
ArvGcFloatInterface *iface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (iface->get_min != NULL) {
double min = iface->get_min (gc_float, &local_error);
if (local_error == NULL && value < min) {
g_set_error (&local_error, ARV_GC_ERROR, ARV_GC_ERROR_OUT_OF_RANGE,
"[%s] Value '%g' lower than allowed minimum '%g'",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)), value, min);
}
}
if (local_error == NULL && iface->get_max != NULL) {
double max = iface->get_max (gc_float, &local_error);
if (local_error == NULL && value > max) {
g_set_error (&local_error, ARV_GC_ERROR, ARV_GC_ERROR_OUT_OF_RANGE,
"[%s] Value '%g' greater than allowed maximum '%g'",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)), value, max);
}
}
if (local_error != NULL) {
if (policy == ARV_RANGE_CHECK_POLICY_DEBUG) {
arv_warning_policies ("Range check (%s) ignored", local_error->message);
} else if (policy == ARV_RANGE_CHECK_POLICY_ENABLE) {
g_propagate_error (error, local_error);
return;
}
g_clear_error (&local_error);
}
}
ARV_GC_FLOAT_GET_IFACE (gc_float)->set_value (gc_float, value, error);
}
/**
* arv_gc_float_get_min:
* @gc_float: a #ArvGcFloat
* @error: a #GError placeholder, NULL to ignore
*
* Returns: The feature Min property, -#G_MAXDOUBLE if not defined or on error
*/
double
arv_gc_float_get_min (ArvGcFloat *gc_float, GError **error)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_min != NULL)
return float_interface->get_min (gc_float, error);
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "[%s] <Min> node not found",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
return -G_MAXDOUBLE;
}
/**
* arv_gc_float_get_max:
* @gc_float: a #ArvGcFloat
* @error: a #GError placeholder, NULL to ignore
*
* Returns: The feature Max property, #G_MAXDOUBLE if not defined or on error
*/
double
arv_gc_float_get_max (ArvGcFloat *gc_float, GError **error)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), 0.0);
g_return_val_if_fail (error == NULL || *error == NULL, 0.0);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_max != NULL)
return float_interface->get_max (gc_float, error);
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "[%s] <Max> node not found",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
return G_MAXDOUBLE;
}
/**
* arv_gc_float_get_inc:
* @gc_float: a #ArvGcFloat
* @error: a #GError placeholder, NULL to ignore
*
* Returns: The feature Inc property, #G_MINDOUBLE if not defined or on error
*/
double
arv_gc_float_get_inc (ArvGcFloat *gc_float, GError **error)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), G_MINDOUBLE);
g_return_val_if_fail (error == NULL || *error == NULL, G_MINDOUBLE);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_inc != NULL)
return float_interface->get_inc (gc_float, error);
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "[%s] <Inc> node not found",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
return G_MINDOUBLE;
}
/**
* arv_gc_float_get_representation:
* @gc_float: a #ArvGcFloat
*
* Get number representation format.
*
* Returns: Number representation format as #ArvGcRepresentation.
*/
ArvGcRepresentation
arv_gc_float_get_representation (ArvGcFloat *gc_float)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), ARV_GC_REPRESENTATION_UNDEFINED);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_representation != NULL)
return float_interface->get_representation (gc_float);
return ARV_GC_REPRESENTATION_UNDEFINED;
}
const char *
arv_gc_float_get_unit (ArvGcFloat *gc_float)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), NULL);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_unit != NULL)
return float_interface->get_unit (gc_float);
return NULL;
}
/**
* arv_gc_float_get_display_notation:
* @gc_float: a #ArvGcFloat
*
* Get number display notation.
*
* Returns: Number display notation as #ArvGcDisplayNotation.
*
* Since: 0.8.0
*/
ArvGcDisplayNotation
arv_gc_float_get_display_notation (ArvGcFloat *gc_float)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), ARV_GC_DISPLAY_NOTATION_DEFAULT);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_display_notation != NULL)
return float_interface->get_display_notation (gc_float);
return ARV_GC_DISPLAY_NOTATION_DEFAULT;
}
/**
* arv_gc_float_get_display_precision:
* @gc_float: a #ArvGcFloat
*
* Gets number of digits to show in user interface. This number should always be positive and represent
* total number of digits on left and right side of decimal.
*
* Returns: Number of digits to show.
*
* Since: 0.8.0
*/
gint64
arv_gc_float_get_display_precision (ArvGcFloat *gc_float)
{
ArvGcFloatInterface *float_interface;
g_return_val_if_fail (ARV_IS_GC_FLOAT (gc_float), ARV_GC_DISPLAY_PRECISION_DEFAULT);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->get_display_precision != NULL)
return float_interface->get_display_precision (gc_float);
return ARV_GC_DISPLAY_PRECISION_DEFAULT;
}
void arv_gc_float_impose_min (ArvGcFloat *gc_float, double minimum, GError **error)
{
ArvGcFloatInterface *float_interface;
g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
g_return_if_fail (error == NULL || *error == NULL);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->impose_min != NULL)
float_interface->impose_min (gc_float, minimum, error);
else
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "[%s] <Min> node not found",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
}
void arv_gc_float_impose_max (ArvGcFloat *gc_float, double maximum, GError **error)
{
ArvGcFloatInterface *float_interface;
g_return_if_fail (ARV_IS_GC_FLOAT (gc_float));
g_return_if_fail (error == NULL || *error == NULL);
float_interface = ARV_GC_FLOAT_GET_IFACE (gc_float);
if (float_interface->impose_max != NULL)
float_interface->impose_max (gc_float, maximum, error);
else
g_set_error (error, ARV_GC_ERROR, ARV_GC_ERROR_PROPERTY_NOT_DEFINED, "[%s] <Max> node not found",
arv_gc_feature_node_get_name (ARV_GC_FEATURE_NODE (gc_float)));
}