1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2004-2006 - INRIA - Fabrice Leray
4 * Copyright (C) 2006 - INRIA - Allan Cornet
5 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
6 * Copyright (C) 2010 - DIGITEO - Manuel Juliachs
7 *
8 * Copyright (C) 2012 - 2016 - Scilab Enterprises
9 *
10 * This file is hereby licensed under the terms of the GNU GPL v2.0,
11 * pursuant to article 5.3.4 of the CeCILL v.2.1.
12 * This file was originally licensed under the terms of the CeCILL v2.1,
13 * and continues to be available under such terms.
14 * For more information, see the COPYING file which you should have received
15 * along with this program.
16 *
17 */
18
19 /*------------------------------------------------------------------------*/
20 /* file: set_grid_property.c */
21 /* desc : function to modify in Scilab the grid field of */
22 /* a handle */
23 /*------------------------------------------------------------------------*/
24
25 #include "setHandleProperty.h"
26 #include "SetProperty.h"
27 #include "getPropertyAssignedValue.h"
28 #include "SetPropertyStatus.h"
29 #include "GetProperty.h"
30 #include "Scierror.h"
31 #include "localization.h"
32
33 #include "getGraphicObjectProperty.h"
34 #include "setGraphicObjectProperty.h"
35 #include "graphicObjectProperties.h"
36
37 /*------------------------------------------------------------------------*/
set_grid_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)38 int set_grid_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
39 {
40 BOOL status[3];
41 int i = 0;
42 int iGridColor = 0;
43 int* piGridColor = &iGridColor;
44 int gridStyles[3];
45 int const gridColorPropertiesNames[3] = {__GO_X_AXIS_GRID_COLOR__, __GO_Y_AXIS_GRID_COLOR__, __GO_Z_AXIS_GRID_COLOR__};
46
47 double* values = (double*)_pvData;
48
49 if (valueType != sci_matrix)
50 {
51 Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "grid");
52 return SET_PROPERTY_ERROR;
53 }
54
55 if (nbRow != 1 || nbCol > 3)
56 {
57 Scierror(999, _("Wrong size for '%s' property: Must be in the set {%s}.\n"), "grid", "1x2, 1x3");
58 return SET_PROPERTY_ERROR;
59 }
60
61 getGraphicObjectProperty(iObjUID, gridColorPropertiesNames[0], jni_int, (void**)&piGridColor);
62
63 if (piGridColor == NULL)
64 {
65 Scierror(999, _("'%s' property does not exist for this handle.\n"), "grid");
66 return SET_PROPERTY_ERROR;
67 }
68
69 gridStyles[0] = iGridColor;
70
71 getGraphicObjectProperty(iObjUID, gridColorPropertiesNames[1], jni_int, (void**)&piGridColor);
72 gridStyles[1] = iGridColor;
73
74 getGraphicObjectProperty(iObjUID, gridColorPropertiesNames[2], jni_int, (void**)&piGridColor);
75 gridStyles[2] = iGridColor;
76
77 for ( i = 0 ; i < nbCol ; i++)
78 {
79 int curValue = (int) values[i];
80 if (values[i] < -1 || !sciCheckColorIndex(iObjUID, curValue))
81 {
82 Scierror(999, _("Wrong value for '%s' property: Must be -1 or a valid color index.\n"), "grid");
83 return SET_PROPERTY_ERROR;
84 }
85 gridStyles[i] = curValue;
86 }
87
88 status[0] = setGraphicObjectProperty(iObjUID, gridColorPropertiesNames[0], &gridStyles[0], jni_int, 1);
89 status[1] = setGraphicObjectProperty(iObjUID, gridColorPropertiesNames[1], &gridStyles[1], jni_int, 1);
90 status[2] = setGraphicObjectProperty(iObjUID, gridColorPropertiesNames[2], &gridStyles[2], jni_int, 1);
91
92 if (status[0] == TRUE && status[1] == TRUE && status[2] == TRUE)
93 {
94 return SET_PROPERTY_SUCCEED;
95 }
96 else
97 {
98 Scierror(999, _("'%s' property does not exist for this handle.\n"), "grid");
99 return SET_PROPERTY_ERROR;
100 }
101
102 }
103 /*------------------------------------------------------------------------*/
104