load: avoid creation of double axes in figure
[scilab.git] / scilab / modules / gui / sci_gateway / cpp / sci_datatip_set_style.cpp
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2013 - Gustavo Barbosa Libotte <gustavolibotte@gmail.com>
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 "DatatipSetStyle.hxx"
17
18 extern "C"
19 {
20 #include "api_scilab.h"
21 #include "getScilabJavaVM.h"
22 #include "localization.h"
23 #include "Scierror.h"
24 #include "gw_gui.h"
25 #include "HandleManagement.h"
26 #include "CurrentFigure.h"
27 #include "getGraphicObjectProperty.h"
28 #include "setGraphicObjectProperty.h"
29 #include "graphicObjectProperties.h"
30 }
31
32 using namespace org_scilab_modules_gui_datatip;
33
34 int sci_datatip_set_style(char *fname, void* pvApiCtx)
35 {
36     int* piAddr                 = NULL;
37     int iPolylineUID            = 0;
38     double* markStyle           = NULL;
39     int* pbBoxed                = NULL;
40     int* pbLabeled              = NULL;
41     int datatipSetStyleOption   = 0;
42     long long llHandle          = 0;
43     int nbRow                   = 0;
44     int nbCol                   = 0;
45     int iErr                    = 0;
46
47     int iType = 0;
48     int *piType = &iType;
49
50     SciErr sciErr;
51     CheckInputArgument(pvApiCtx, 1, 4);
52     CheckOutputArgument(pvApiCtx, 0, 1);
53
54     sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
55     if (sciErr.iErr)
56     {
57         printError(&sciErr, 0);
58         return 0;
59     }
60
61     iErr = getScalarHandle(pvApiCtx, piAddr, &llHandle);
62     if (iErr)
63     {
64         Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
65         return 0;
66     }
67
68     iPolylineUID = getObjectFromHandle((unsigned long) llHandle);
69
70     if (checkInputArgumentType(pvApiCtx, 1, sci_handles))
71     {
72         getGraphicObjectProperty(iPolylineUID, __GO_TYPE__, jni_int, (void**) &piType);
73         if (iType == __GO_POLYLINE__)
74         {
75             if (nbInputArgument(pvApiCtx) == 1)
76             {
77                 datatipSetStyleOption = DatatipSetStyle::datatipSetStyleWindow(getScilabJavaVM());
78                 switch (datatipSetStyleOption)
79                 {
80                     case 0:
81                         //Do nothing.
82                         AssignOutputVariable(pvApiCtx, 1) = 0;
83                         ReturnArguments(pvApiCtx);
84                         return 0;
85                     case 1:
86                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 1, true, true);
87                         AssignOutputVariable(pvApiCtx, 1) = 0;
88                         ReturnArguments(pvApiCtx);
89                         return 0;
90                     case 2:
91                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 1, false, true);
92                         AssignOutputVariable(pvApiCtx, 1) = 0;
93                         ReturnArguments(pvApiCtx);
94                         return 0;
95                     case 3:
96                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 1, false, false);
97                         AssignOutputVariable(pvApiCtx, 1) = 0;
98                         ReturnArguments(pvApiCtx);
99                         return 0;
100                     case 4:
101                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 2, true, true);
102                         AssignOutputVariable(pvApiCtx, 1) = 0;
103                         ReturnArguments(pvApiCtx);
104                         return 0;
105                     case 5:
106                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 2, false, true);
107                         AssignOutputVariable(pvApiCtx, 1) = 0;
108                         ReturnArguments(pvApiCtx);
109                         return 0;
110                     case 6:
111                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, 2, false, false);
112                         AssignOutputVariable(pvApiCtx, 1) = 0;
113                         ReturnArguments(pvApiCtx);
114                         return 0;
115                 }
116             }
117             else if (nbInputArgument(pvApiCtx) == 2)
118             {
119                 if (checkInputArgumentType(pvApiCtx, 2, sci_matrix))
120                 {
121                     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
122                     if (sciErr.iErr)
123                     {
124                         printError(&sciErr, 0);
125                         return 1;
126                     }
127                     sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &markStyle);
128                     if (sciErr.iErr)
129                     {
130                         printError(&sciErr, 0);
131                         return 1;
132                     }
133
134                     if ((int)markStyle[0] == 1 || (int)markStyle[0] == 2)
135                     {
136                         DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, (int)markStyle[0], true, true);
137                         AssignOutputVariable(pvApiCtx, 1) = 0;
138                         ReturnArguments(pvApiCtx);
139                         return 0;
140                     }
141                     else
142                     {
143                         Scierror(999, _("%s: Wrong value for input argument #%d: %d or %d expected.\n"), fname, 2, 1, 2);
144                         return 1;
145                     }
146                 }
147                 else
148                 {
149                     Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2);
150                     return 1;
151                 }
152             }
153             else if (nbInputArgument(pvApiCtx) == 3)
154             {
155                 if (checkInputArgumentType(pvApiCtx, 2, sci_matrix))
156                 {
157                     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
158                     if (sciErr.iErr)
159                     {
160                         printError(&sciErr, 0);
161                         return 1;
162                     }
163                     sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &markStyle);
164                     if (sciErr.iErr)
165                     {
166                         printError(&sciErr, 0);
167                         return 1;
168                     }
169
170                     if ((int)markStyle[0] == 1 || (int)markStyle[0] == 2)
171                     {
172
173                         if (checkInputArgumentType(pvApiCtx, 3, sci_boolean))
174                         {
175
176                             sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
177                             if (sciErr.iErr)
178                             {
179                                 printError(&sciErr, 0);
180                                 return 1;
181                             }
182                             sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &nbRow, &nbCol, &pbBoxed);
183                             if (sciErr.iErr)
184                             {
185                                 printError(&sciErr, 0);
186                                 return 1;
187                             }
188
189                             DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, (int)markStyle[0], pbBoxed[0] != 0, true);
190                             AssignOutputVariable(pvApiCtx, 1) = 0;
191                             ReturnArguments(pvApiCtx);
192                             return 0;
193                         }
194                         else
195                         {
196                             Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
197                             return 1;
198                         }
199                     }
200                     else
201                     {
202                         Scierror(999, _("%s: Wrong value for input argument #%d: %d or %d expected.\n"), fname, 2, 1, 2);
203                         return 1;
204                     }
205                 }
206                 else
207                 {
208                     Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2);
209                     return 1;
210                 }
211             }
212             else if (nbInputArgument(pvApiCtx) == 4)
213             {
214                 if (checkInputArgumentType(pvApiCtx, 2, sci_matrix))
215                 {
216                     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
217                     if (sciErr.iErr)
218                     {
219                         printError(&sciErr, 0);
220                         return 1;
221                     }
222                     sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &nbRow, &nbCol, &markStyle);
223                     if (sciErr.iErr)
224                     {
225                         printError(&sciErr, 0);
226                         return 1;
227                     }
228
229                     if ((int)markStyle[0] == 1 || (int)markStyle[0] == 2)
230                     {
231                         if (checkInputArgumentType(pvApiCtx, 3, sci_boolean))
232                         {
233                             sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
234                             if (sciErr.iErr)
235                             {
236                                 printError(&sciErr, 0);
237                                 return 1;
238                             }
239                             sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &nbRow, &nbCol, &pbBoxed);
240                             if (sciErr.iErr)
241                             {
242                                 printError(&sciErr, 0);
243                                 return 1;
244                             }
245
246                             if (checkInputArgumentType(pvApiCtx, 4, sci_boolean))
247                             {
248                                 sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
249                                 if (sciErr.iErr)
250                                 {
251                                     printError(&sciErr, 0);
252                                     return 1;
253                                 }
254                                 sciErr = getMatrixOfBoolean(pvApiCtx, piAddr, &nbRow, &nbCol, &pbLabeled);
255                                 if (sciErr.iErr)
256                                 {
257                                     printError(&sciErr, 0);
258                                     return 1;
259                                 }
260
261                                 DatatipSetStyle::datatipSetStyle(getScilabJavaVM(), iPolylineUID, (int)markStyle[0], pbBoxed[0] != 0, pbLabeled[0] != 0);
262                                 AssignOutputVariable(pvApiCtx, 1) = 0;
263                                 ReturnArguments(pvApiCtx);
264                                 return 0;
265                             }
266                             else
267                             {
268                                 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 4);
269                                 return 1;
270                             }
271                         }
272                         else
273                         {
274                             Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
275                             return 1;
276                         }
277                     }
278                     else
279                     {
280                         Scierror(999, _("%s: Wrong value for input argument #%d: %d or %d expected.\n"), fname, 2, 1, 2);
281                         return 1;
282                     }
283                 }
284                 else
285                 {
286                     Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), fname, 2);
287                     return 1;
288                 }
289             }
290             else
291             {
292                 Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), fname, 1, 4);
293                 return 1;
294             }
295         }
296         else
297         {
298             Scierror(999, _("%s: Wrong type for input argument #%d: A '%s' handle expected.\n"), fname, 1, "Polyline");
299             return 1;
300         }
301     }
302
303     AssignOutputVariable(pvApiCtx, 1) = 0;
304     ReturnArguments(pvApiCtx);
305     return 0;
306 }