1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
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 #include "gw_graphics.h"
16 #include "api_scilab.h"
17 #include "localization.h"
18 #include "Scierror.h"
19 #include "addColor.h"
20 #include "CurrentFigure.h"
21 #include "createGraphicObject.h"
22 #include "sciprint.h"
23
checkValue(double dblValue)24 int checkValue(double dblValue)
25 {
26 return (dblValue >= 0.0 && dblValue <= 1.0);
27 }
28
checkValues(double * pdblValues,int iRows)29 int checkValues(double* pdblValues, int iRows)
30 {
31 int i = 0;
32 for (i = 0 ; i < iRows ; i++)
33 {
34 if ((checkValue(pdblValues[i]) && checkValue(pdblValues[i + iRows]) && checkValue(pdblValues[i + iRows * 2])) == 0)
35 {
36 sciprint("%d %f %f %f\n", i, pdblValues[i], pdblValues[i + iRows], pdblValues[i + iRows * 2]);
37 return 0;
38 }
39 }
40
41 return 1;
42 }
43 /*--------------------------------------------------------------------------*/
sci_addcolor(char * fname,void * pvApiCtx)44 int sci_addcolor(char *fname, void* pvApiCtx)
45 {
46 SciErr sciErr;
47 int i = 0;
48 int* piAddr = NULL;
49 int iRows = 0;
50 int iCols = 0;
51 double* pdblColor = NULL;
52 double color[3];
53
54 int iCurrentFigure = 0;
55 double* pdblReturnColor = NULL;
56
57 CheckInputArgument(pvApiCtx, 1, 1);
58
59 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
60 if (sciErr.iErr)
61 {
62 printError(&sciErr, 0);
63 return 1;
64 }
65
66 if (isDoubleType(pvApiCtx, piAddr) == FALSE)
67 {
68 Scierror(999, _("%s: Wrong type for input argument #%d: Real vector 1x3 expected.\n"), fname, 1);
69 return 1;
70 }
71
72 sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblColor);
73 if (sciErr.iErr)
74 {
75 printError(&sciErr, 0);
76 return 1;
77 }
78
79 if (iCols != 3)
80 {
81 Scierror(999, _("%s: Wrong type for input argument #%d: Real vector nx3 expected.\n"), fname, 1);
82 return 1;
83 }
84
85 //check values
86 if (checkValues(pdblColor, iRows) == 0)
87 {
88 Scierror(999, _("%s: Wrong value for input argument #%d: Must be between 0.0 and 1.0.\n"), fname, 1);
89 return 1;
90 }
91
92 iCurrentFigure = getCurrentFigure();
93 if (iCurrentFigure == 0)
94 {
95 iCurrentFigure = createNewFigureWithAxes();
96 }
97
98 allocMatrixOfDouble(pvApiCtx, 2, 1, iRows, &pdblReturnColor);
99 for (i = 0 ; i < iRows ; i++)
100 {
101 color[0] = pdblColor[i];
102 color[1] = pdblColor[i + iRows];
103 color[2] = pdblColor[i + iRows * 2];
104
105 pdblReturnColor[i] = addColor(iCurrentFigure, color);
106 }
107
108 AssignOutputVariable(pvApiCtx, 1) = 2;
109 ReturnArguments(pvApiCtx);
110 return 0;
111 }
112