1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2013 - Pedro SOUZA
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 #include "gw_graphics.h"
17 #include "api_scilab.h"
18 #include "Scierror.h"
19 #include "localization.h"
20 #include "HandleManagement.h"
21 #include "BuildObjects.h"
22 #include "os_string.h"
23
24 static const char fname[] = "light";
25
sci_light(scilabEnv env,int nin,scilabVar * in,int nopt,scilabOpt opt,int nout,scilabVar * out)26 int sci_light(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
27 {
28 int light = 0;
29 if (nin > 1)
30 {
31 Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), fname, 0, 1);
32 return 1;
33 }
34
35 if (nin + nopt == 0)
36 {
37 light = ConstructLight(fname, 0, -1, TRUE, NULL, NULL, NULL, NULL, NULL);
38 }
39 else
40 {
41 int type = -1;
42 BOOL visible = 1;
43 double* position = NULL;
44 double* direction = NULL;
45 double* ambient_color = NULL;
46 double* diffuse_color = NULL;
47 double* specular_color = NULL;
48 int axes = 0;
49 scilabVar var = NULL;
50
51 if (nin > 0 && scilab_isHandle(env, in[0]))
52 {
53 long long axesHandle = 0;
54 if (scilab_isScalar(env, in[0]))
55 {
56 if (scilab_getHandle(env, in[0], &axesHandle))
57 {
58 Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1);
59 return 1;
60 }
61 }
62 else
63 {
64 Scierror(999, _("%s: Wrong type for input argument #%d: A graphic handle expected.\n"), fname, 1);
65 return 1;
66 }
67
68 axes = getObjectFromHandle((long)axesHandle);
69 }
70
71 //optionals
72 var = scilab_getOptional(env, opt, L"visible");
73 if (var && scilab_isString(env, var) && scilab_isScalar(env, var))
74 {
75 wchar_t* wstr = NULL;
76 if (scilab_getString(env, var, &wstr))
77 {
78 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 7);
79 return 0;
80 }
81
82 if (wcsicmp(wstr, L"on") == 0)
83 {
84 visible = 1;
85 }
86 else if (wcsicmp(wstr, L"off") == 0)
87 {
88 visible = 0;
89 }
90 }
91
92 var = scilab_getOptional(env, opt, L"type");
93 if (var && scilab_isString(env, var) && scilab_isScalar(env, var))
94 {
95 wchar_t* wstr = NULL;
96 if (scilab_getString(env, var, &wstr))
97 {
98 Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), fname, 7);
99 return 0;
100 }
101
102 if (wcsicmp(wstr, L"directional") == 0)
103 {
104 type = 0;
105 }
106 else if (wcsicmp(wstr, L"point") == 0)
107 {
108 type = 1;
109 }
110 }
111
112 var = scilab_getOptional(env, opt, L"position");
113 if (var && scilab_isDouble(env, var) && scilab_getSize(env, var) == 3)
114 {
115 scilab_getDoubleArray(env, var, &position);
116 }
117
118 var = scilab_getOptional(env, opt, L"direction");
119 if (var && scilab_isDouble(env, var) && scilab_getSize(env, var) == 3)
120 {
121 scilab_getDoubleArray(env, var, &direction);
122 }
123
124 var = scilab_getOptional(env, opt, L"ambient_color");
125 if (var && scilab_isDouble(env, var) && scilab_getSize(env, var) == 3)
126 {
127 scilab_getDoubleArray(env, var, &ambient_color);
128 }
129
130 var = scilab_getOptional(env, opt, L"diffuse_color");
131 if (var && scilab_isDouble(env, var) && scilab_getSize(env, var) == 3)
132 {
133 scilab_getDoubleArray(env, var, &diffuse_color);
134 }
135
136 var = scilab_getOptional(env, opt, L"specular_color");
137 if (var && scilab_isDouble(env, var) && scilab_getSize(env, var) == 3)
138 {
139 scilab_getDoubleArray(env, var, &specular_color);
140 }
141
142 light = ConstructLight(fname, axes, type, visible, position, direction, ambient_color, diffuse_color, specular_color);
143 }
144
145 //error occurs in ConstructLight
146 if (light == 0)
147 {
148 //error is manage in ConstructLight
149 return 1;
150 }
151
152 out[0] = scilab_createHandle(env);
153 if (out[0] == NULL)
154 {
155 Scierror(999, _("%s: Memory allocation error.\n"), fname);
156 return 0;
157 }
158
159 scilab_setHandle(env, out[0], getHandle(light));
160 return 0;
161 }
162