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
|
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2007 - INRIA - Vincent COUVERT
* Copyright (C) 2011-2012 - DIGITEO - Vincent COUVERT
* Sets the value property of an uicontrol object
*
* This file must be used under the terms of the CeCILL.
* This source file is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at
* http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
*
*/
extern "C"
{
#include <stdio.h>
#include "GetUicontrol.h"
}
int SetUicontrolValue(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
double *value = NULL;
double* truncatedValue = NULL;
int valueSize = 0;
int nbValues = 0;
int kValue = 0;
BOOL status = FALSE;
BOOL truncated = FALSE;
double maxValue = 0;
double* pdblMaxValue = &maxValue;
double minValue = 0;
double* pdblMinValue = &minValue;
int objectStyle = -1;
int *piObjectStyle = &objectStyle;
int type = -1;
int *piType = &type;
// Check type
getGraphicObjectProperty(iObjUID, __GO_TYPE__, jni_int, (void**) &piType);
if (type != __GO_UICONTROL__)
{
Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "Value");
return SET_PROPERTY_ERROR;
}
if (valueType == sci_matrix)
{
if (nbRow > 1)
{
/* Wrong value size */
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A real row vector expected.\n")), "Value");
return SET_PROPERTY_ERROR;
}
value = (double*)_pvData;
valueSize = nbCol * nbRow;
}
else if (valueType == sci_strings) // Ascendant compatibility
{
if (nbCol > 1)
{
/* Wrong value size */
Scierror(999, const_cast<char*>(_("Wrong size for '%s' property: A string expected.\n")), "Value");
return SET_PROPERTY_ERROR;
}
value = new double[1];
valueSize = 1;
nbValues = sscanf((char*)_pvData, "%lf", &value[0]);
if (nbValues != 1)
{
/* Wrong value size */
Scierror(999, const_cast<char*>(_("Wrong value for '%s' property: A String containing a numeric value expected.\n")), "Value");
return SET_PROPERTY_ERROR;
}
}
else
{
/* Wrong datatype */
Scierror(999, const_cast<char*>(_("Wrong type for '%s' property: A real row vector or a string expected.\n")), "Value");
return SET_PROPERTY_ERROR;
}
truncatedValue = new double[valueSize];
for (kValue = 0; kValue < valueSize; kValue++)
{
truncatedValue[kValue] = floor(value[kValue]);
if (truncatedValue[kValue] != value[kValue])
{
truncated = TRUE;
}
}
getGraphicObjectProperty(iObjUID, __GO_STYLE__, jni_int, (void**) &piObjectStyle);
/*
* For popumenus/listboxes: display a warning if the value is not an integer
*/
if ((objectStyle == __GO_UI_POPUPMENU__ || objectStyle == __GO_UI_LISTBOX__) && truncated)
{
sciprint(const_cast<char*>(_("Warning: '%s' 'Value' property should be an integer, the value will be truncated.\n")), IntToStyle(objectStyle));
}
/*
* For Checkboxes and Radiobuttons: display a warning if the value is neither equal to Min nor Max
*/
if (objectStyle == __GO_UI_CHECKBOX__ || objectStyle == __GO_UI_RADIOBUTTON__)
{
getGraphicObjectProperty(iObjUID, __GO_UI_MIN__, jni_double, (void**) &pdblMinValue);
getGraphicObjectProperty(iObjUID, __GO_UI_MAX__, jni_double, (void**) &pdblMaxValue);
if ((value[0] != minValue) && (value[0] != maxValue))
{
sciprint(const_cast<char*>(_("Warning: '%s' 'Value' property should be equal to either '%s' or '%s' property value.\n")), IntToStyle(objectStyle), "Min", "Max");
}
}
if (objectStyle == __GO_UI_POPUPMENU__ || objectStyle == __GO_UI_LISTBOX__)
{
int iDataSize = 0;
int* piDataSize = & iDataSize;
getGraphicObjectProperty(iObjUID, __GO_UI_STRING_SIZE__, jni_int, (void**)&piDataSize);
if (piDataSize == NULL)
{
Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "Value");
return SET_PROPERTY_ERROR;
}
for (int i = 0 ; i < valueSize ; i++)
{
if (truncatedValue[i] < 0 || truncatedValue[i] > iDataSize)
{
Scierror(999, _("'%s' value must be between 0 and %d.\n"), "Value", iDataSize);
return SET_PROPERTY_ERROR;
}
}
status = setGraphicObjectProperty(iObjUID, __GO_UI_VALUE__, truncatedValue, jni_double_vector, valueSize);
}
else
{
status = setGraphicObjectProperty(iObjUID, __GO_UI_VALUE__, value, jni_double_vector, valueSize);
}
delete[] truncatedValue;
if (valueType == sci_strings)
{
delete[] value;
}
if (status == TRUE)
{
return SET_PROPERTY_SUCCEED;
}
else
{
Scierror(999, const_cast<char*>(_("'%s' property does not exist for this handle.\n")), "Value");
return SET_PROPERTY_ERROR;
}
}
|