1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 /*------------------------------------------------------------------------*/
17 /* file: set_colors_property.c                                            */
18 /* desc : function to modify in Scilab he polylines colors                */
19 /*------------------------------------------------------------------------*/
20 
21 #include "sci_malloc.h"
22 #include "setHandleProperty.h"
23 #include "SetProperty.h"
24 #include "getPropertyAssignedValue.h"
25 #include "Scierror.h"
26 #include "localization.h"
27 #include "GetProperty.h"
28 #include "SetPropertyStatus.h"
29 
30 #include "getGraphicObjectProperty.h"
31 #include "setGraphicObjectProperty.h"
32 #include "graphicObjectProperties.h"
33 
34 /*------------------------------------------------------------------------*/
set_colors_property(void * _pvCtx,int iObjUID,void * _pvData,int valueType,int nbRow,int nbCol)35 int set_colors_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol )
36 {
37     BOOL status = FALSE;
38     int iNumElements = 0;
39     int* piNumElements = &iNumElements;
40 
41     if (valueType != sci_matrix)
42     {
43         Scierror(999, _("Wrong type for '%s' property: Real matrix expected.\n"), "colors");
44         return SET_PROPERTY_ERROR;
45     }
46 
47     getGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_NUM_ELEMENTS__, jni_int, (void **) &piNumElements);
48 
49     /*
50      * A way to display a more explicit message would be to first get the
51      * interpolation vector set flag and test it for NULL.
52      */
53     if (piNumElements == NULL)
54     {
55         Scierror(999, _("'%s' property does not exist for this handle.\n"), "data");
56         return SET_PROPERTY_ERROR;
57     }
58 
59     if (nbCol == 0)
60     {
61         int colorSet = 0;
62         status = setGraphicObjectProperty(iObjUID, __GO_COLOR_SET__, &colorSet, jni_bool, 1);
63         if (status == FALSE)
64         {
65             Scierror(999, _("'%s' property does not exist for this handle.\n"), "colors");
66             return SET_PROPERTY_ERROR;
67         }
68         setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_COLORS__, NULL, jni_int_vector, 0);
69 
70         return SET_PROPERTY_SUCCEED;
71     }
72 
73     if (nbCol == iNumElements)
74     {
75         int * tmp = MALLOC(nbCol * sizeof(int));
76         copyDoubleVectorToIntFromStack(_pvData, tmp, nbCol);
77 
78         status = setGraphicObjectProperty(iObjUID, __GO_DATA_MODEL_COLORS__, tmp, jni_int_vector, nbCol);
79         if (status == TRUE)
80         {
81             int colorSet = 1;
82             setGraphicObjectProperty(iObjUID, __GO_COLOR_SET__, &colorSet, jni_bool, 1);
83             FREE(tmp);
84             return SET_PROPERTY_SUCCEED;
85         }
86         else
87         {
88             FREE(tmp);
89             Scierror(999, _("'%s' property does not exist for this handle.\n"), "colors");
90             return SET_PROPERTY_ERROR;
91         }
92     }
93     else
94     {
95         Scierror(999, _("The number of column of the color vector must match the number of points defining the line.\n"));
96         return SET_PROPERTY_ERROR;
97     }
98 }
99 /*------------------------------------------------------------------------*/
100