Merge remote-tracking branch 'origin/master' into windows
[scilab.git] / scilab / modules / graphics / sci_gateway / cpp / sci_xget.cpp
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2006 - INRIA - Fabrice Leray
4  * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
5  * Copyright (C) 2011 - Scilab Enterprises - Bruno JOFRET
6  * Copyright (C) 2013 - Scilab Enterprises - Cedric Delamarre
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: sci_xget.cpp                                                       */
21 /* desc : interface for xget routine                                      */
22 /*------------------------------------------------------------------------*/
23
24 #include "graphics_gw.hxx"
25 #include "function.hxx"
26 #include "double.hxx"
27 #include "configgraphicvariable.hxx"
28 #include "overload.hxx"
29 #include "string.hxx"
30
31 extern "C"
32 {
33 #include <string.h>
34 #include "GetProperty.h"
35 #include "Scierror.h"
36 #include "localization.h"
37 #include "returnProperty.h"
38 #include "HandleManagement.h"
39 #include "CurrentSubwin.h"
40 #include "getGraphicObjectProperty.h"
41 #include "graphicObjectProperties.h"
42 #include "BuildObjects.h"
43 #include "sci_malloc.h"
44 #include "getHandleProperty.h"
45 #include "CurrentFigure.h"
46 }
47 /*--------------------------------------------------------------------------*/
48 types::Function::ReturnValue sci_xget(types::typed_list &in, int _iRetCount, types::typed_list &out)
49 {
50     double dValue = 0;
51     char* pcsWhat = NULL;
52     void* pvApiCtx = NULL;
53
54     if (in.size() == 0)
55     {
56         return Overload::call("%_xget", in, _iRetCount, out);
57     }
58
59     if (in.size() > 2)
60     {
61         Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "xget", 1, 2);
62         return types::Function::Error;
63     }
64
65     if (_iRetCount > 1)
66     {
67         Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "xget", 1);
68         return types::Function::Error;
69     }
70
71     if (in[0]->isString() == false)
72     {
73         Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xget", 1);
74         return types::Function::Error;
75     }
76
77     types::String* pStr = in[0]->getAs<types::String>();
78
79     if (pStr->isScalar() == false)
80     {
81         Scierror(999, _("%s: Wrong type for input argument #%d: A single string expected.\n"), "xget", 1);
82         return types::Function::Error;
83     }
84
85     pcsWhat = pStr->get(0);
86
87     if (ConfigGraphicVariable::bPropertyFound(pcsWhat) == false)
88     {
89         Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xget", pcsWhat);
90         return types::Function::Error;
91     }
92
93     if (in.size() == 2)
94     {
95         if (in[1]->isDouble() == false)
96         {
97             Scierror(202, _("%s: Wrong type for argument #%d: A real expected.\n"), "xget", 2);
98             return types::Function::Error;
99         }
100
101         types::Double* pDbl = in[1]->getAs<types::Double>();
102
103         //CheckScalar
104         if (pDbl->isScalar())
105         {
106             Scierror(999, _("%s: Wrong size for input argument #%d: A real scalar expected.\n"), "xget", 2);
107             return types::Function::Error;
108         }
109
110         dValue = pDbl->get(0);
111     }
112
113     switch (ConfigGraphicVariable::getPropertyValue(pcsWhat))
114     {
115         case 15 : // fpf
116         {
117             out.push_back(new types::String(ConfigGraphicVariable::getFPF().c_str()));
118         }
119         break;
120         case 2 : // auto clear
121         {
122             int iAutoClear = 0;
123             int* piAutoClear = &iAutoClear;
124             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_AUTO_CLEAR__, jni_bool, (void **)&piAutoClear);
125             if (iAutoClear == 1)
126             {
127                 out.push_back(new types::String("on"));
128             }
129             else
130             {
131                 out.push_back(new types::String("off"));
132             }
133         }
134         break;
135         case 8 : // colormap
136         {
137             int iObjUID = 0;
138             // Force figure creation if none exists.
139             getOrCreateDefaultSubwin();
140             iObjUID = getCurrentFigure();
141
142             out.push_back((types::InternalType*)get_color_map_property(pvApiCtx, iObjUID));
143         }
144         break;
145         case 20 : // mark
146         {
147             int iObjUID = getOrCreateDefaultSubwin();
148             int iMarkStyle = 0;
149             int* piMarkStyle = &iMarkStyle;
150             int iMarkSize = 0;
151             int* piMarkSize = &iMarkSize;
152             types::Double* pDbl = new types::Double(1, 2);
153
154             getGraphicObjectProperty(iObjUID, __GO_MARK_STYLE__, jni_int, (void**)&piMarkStyle);
155             getGraphicObjectProperty(iObjUID, __GO_MARK_SIZE__, jni_int, (void**)&piMarkSize);
156
157             pDbl->set(0, (double)iMarkStyle);
158             pDbl->set(1, (double)iMarkSize);
159             out.push_back(pDbl);
160         }
161         break;
162         case 21 : // mark size
163         {
164             int iObjUID = getOrCreateDefaultSubwin();
165             out.push_back((types::InternalType*)get_mark_size_property(pvApiCtx, iObjUID));
166         }
167         break;
168         case 19 : // line style
169         {
170             out.push_back((types::InternalType*)get_line_style_property(pvApiCtx, getOrCreateDefaultSubwin()));
171         }
172         break;
173         case 5 : // clipping
174         {
175             types::Double* pDblClipBox = new types::Double(1, 4);
176             double *clipBox = NULL;
177             int iObjUID = getOrCreateDefaultSubwin();
178             getGraphicObjectProperty(iObjUID, __GO_CLIP_BOX__, jni_double_vector, (void **)&clipBox);
179             memcpy(pDblClipBox->get(), clipBox, 4 * sizeof(double));
180             out.push_back(pDblClipBox);
181         }
182         break;
183         case 12 : // font
184         {
185             int iObjUID = getOrCreateDefaultSubwin();
186             double dblFontSize = 0;
187             double* pdblFontSize = &dblFontSize;
188             int iFontStyle = 0;
189             int* piFontStyle = &iFontStyle;
190             types::Double* pDbl = new types::Double(1, 2);
191
192             getGraphicObjectProperty(iObjUID, __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);
193             getGraphicObjectProperty(iObjUID, __GO_FONT_STYLE__, jni_int, (void**)&piFontStyle);
194
195             pDbl->set(0, (double)iFontStyle);
196             pDbl->set(1, dblFontSize);
197             out.push_back(pDbl);
198         }
199         break;
200         case 13 : // font size
201         {
202             double dblFontSize = 0;
203             double* pdblFontSize = &dblFontSize;
204             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_FONT_SIZE__, jni_double, (void **)&pdblFontSize);
205
206             out.push_back(new types::Double(dblFontSize));
207         }
208         break;
209         case 9 : // dashes
210         {
211             int iLineStyle = 0;
212             int* piLineStyle = &iLineStyle;
213
214             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_STYLE__, jni_int, (void**)&piLineStyle);
215
216             out.push_back(new types::Double((double)iLineStyle));
217         }
218         break;
219         case 16 : // hidden3d
220         {
221             out.push_back((types::InternalType*)get_hidden_color_property(pvApiCtx, getOrCreateDefaultSubwin()));
222         }
223         break;
224         case 30 : // window
225         case 11 : // figure
226         {
227             int iFigureId = 0;
228             int* piFigureId = &iFigureId;
229
230             getOrCreateDefaultSubwin();
231             getGraphicObjectProperty(getCurrentFigure(), __GO_ID__, jni_int, (void**)&piFigureId);
232
233             out.push_back(new types::Double((double)iFigureId));
234         }
235         break;
236         case 25 : // thickness
237         {
238             out.push_back((types::InternalType*)get_thickness_property(pvApiCtx, getOrCreateDefaultSubwin()));
239         }
240         break;
241         case 28 : // wdim
242         case 31 : // wpdim
243         {
244             int *piFigureSize = NULL;
245             types::Double* pDblFigureSize = new types::Double(1, 2);
246
247             getOrCreateDefaultSubwin();
248             getGraphicObjectProperty(getCurrentFigure(), __GO_SIZE__, jni_int_vector, (void **) &piFigureSize);
249
250             pDblFigureSize->set(0, (double) piFigureSize[0]);
251             pDblFigureSize->set(1, (double) piFigureSize[1]);
252             out.push_back(pDblFigureSize);
253         }
254         break;
255         case 32 : // wpos
256         {
257             int *piFigurePosition = NULL;
258             types::Double* pDblFigurePos = new types::Double(1, 2);
259
260             getOrCreateDefaultSubwin();
261             getGraphicObjectProperty(getCurrentFigure(), __GO_POSITION__, jni_int_vector, (void **) &piFigurePosition);
262
263             pDblFigurePos->set(0, (double) piFigurePosition[0]);
264             pDblFigurePos->set(1, (double) piFigurePosition[1]);
265             out.push_back(pDblFigurePos);
266         }
267         break;
268         case 27 : // viewport
269         {
270             int *piViewport = NULL;
271             types::Double* pDblViewport = new types::Double(1, 2);
272
273             getOrCreateDefaultSubwin();
274             getGraphicObjectProperty(getCurrentFigure(), __GO_VIEWPORT__, jni_int_vector, (void **)&piViewport);
275
276             pDblViewport->set(0, (double) piViewport[0]);
277             pDblViewport->set(1, (double) piViewport[1]);
278             out.push_back(pDblViewport);
279         }
280         break;
281         case 3 : // background
282         {
283             out.push_back((types::InternalType*)get_background_property(pvApiCtx, getOrCreateDefaultSubwin()));
284         }
285         break;
286         case 7 : // color
287         case 14 : // foreground
288         case 23 : // pattern
289         {
290             out.push_back((types::InternalType*)get_foreground_property(pvApiCtx, getOrCreateDefaultSubwin()));
291         }
292         break;
293         case 17 : // lastpattern
294         {
295             int iNumColors = 0;
296             int* piNumColors = &iNumColors;
297
298             getOrCreateDefaultSubwin();
299             getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);
300
301             out.push_back(new types::Double((double)iNumColors));
302         }
303         break;
304         case 18 : // line mode
305         {
306             int iLineMode = 0;
307             int* lineMode = &iLineMode;
308
309             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_LINE_MODE__, jni_bool, (void **)&lineMode);
310
311             out.push_back(new types::Double((double)iLineMode));
312         }
313         break;
314         case 29 : // white
315         {
316             int iNumColors = 0;
317             int* piNumColors = &iNumColors;
318
319             getOrCreateDefaultSubwin();
320             getGraphicObjectProperty(getCurrentFigure(), __GO_COLORMAP_SIZE__, jni_int, (void**)&piNumColors);
321
322             /* White is lqst colormap index + 2 */
323             out.push_back(new types::Double((double)(iNumColors + 2)));
324         }
325         break;
326         case 33 : // wresize
327         {
328             // autoresize property
329             int iAutoResize = 0;
330             int* piAutoResize =  &iAutoResize;
331
332             getOrCreateDefaultSubwin();
333             getGraphicObjectProperty(getCurrentFigure(), __GO_AUTORESIZE__, jni_bool, (void **)&piAutoResize);
334
335             out.push_back(new types::Double((double)iAutoResize));
336         }
337         break;
338         case 6 : // clipgrf
339         {
340             /* clip_state : 0 = off, 1 = on */
341             int iClipState = 0;
342             int* piClipState = &iClipState;
343
344             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);
345
346             out.push_back(new types::Double((double)iClipState));
347         }
348         break;
349         case 4 : // clipoff
350         {
351             int iClipState = 0;
352             int* piClipState = &iClipState;
353
354             getGraphicObjectProperty(getOrCreateDefaultSubwin(), __GO_CLIP_STATE__, jni_int, (void**)&piClipState);
355
356             /* clip_state : 0 = off, 1 = on */
357             if (iClipState == 0)
358             {
359                 out.push_back(new types::Double(1));
360             }
361             else
362             {
363                 out.push_back(new types::Double(0));
364             }
365         }
366         break;
367         default :
368         {
369             Scierror(999, _("%s: Unrecognized input argument: '%s'.\n"), "xget", pcsWhat);
370             return types::Function::Error;
371         }
372     }
373
374     return types::Function::OK;
375 }
376 /*--------------------------------------------------------------------------*/