* Bug #11550 fixed - Closing the scope graph while running simulation led to a
[scilab.git] / scilab / modules / graphic_objects / src / cpp / getGraphicObjectProperty.cpp
1 /*
2  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  *  Copyright (C) 2010-2010 - DIGITEO - Bruno JOFRET
4  *
5  *  This file must be used under the terms of the CeCILL.
6  *  This source file is licensed as described in the file COPYING, which
7  *  you should have received as part of this distribution.  The terms
8  *  are also available at
9  *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12
13 extern "C"
14 {
15 #include <stdlib.h>
16 #include <string.h>
17 #include "getGraphicObjectProperty.h"
18 #include "graphicObjectProperties.h"
19 #include "getScilabJavaVM.h"
20 }
21
22 #include "CallGraphicController.hxx"
23 #include "DataController.hxx"
24
25 using namespace org_scilab_modules_graphic_objects;
26
27 void getGraphicObjectProperty(char const* _pstID, char const* _pstName, _ReturnType_ _returnType, void **_pvData)
28 {
29     // do not perform anything if the id is undefined
30     if (_pstID == NULL)
31     {
32         return;
33     }
34
35     /* All the Data model properties have the DATA_MODEL prefix */
36     if (strncmp(_pstName, __GO_DATA_MODEL__, strlen(__GO_DATA_MODEL__)) == 0)
37     {
38         DataController::getGraphicObjectProperty(_pstID, _pstName, _pvData);
39         return;
40     }
41
42     try
43     {
44         switch (_returnType)
45         {
46             case jni_string:
47             {
48                 *(_pvData) = CallGraphicController::getGraphicObjectPropertyAsString(getScilabJavaVM(), _pstID, _pstName);
49                 return;
50             }
51             case jni_string_vector:
52             {
53                 *_pvData = CallGraphicController::getGraphicObjectPropertyAsStringVector(getScilabJavaVM(), _pstID, _pstName);
54                 return;
55             }
56             case jni_double:
57             {
58                 ((double *)*_pvData)[0] = (double)CallGraphicController::getGraphicObjectPropertyAsDouble(getScilabJavaVM(), _pstID, _pstName);
59                 return;
60             }
61             case jni_double_vector:
62             {
63                 *_pvData = CallGraphicController::getGraphicObjectPropertyAsDoubleVector(getScilabJavaVM(), _pstID, _pstName);
64                 return;
65             }
66             case jni_bool:
67             {
68                 ((int *)*_pvData)[0] = (int)CallGraphicController::getGraphicObjectPropertyAsBoolean(getScilabJavaVM(), _pstID, _pstName);
69                 return;
70             }
71             case jni_bool_vector:
72             {
73                 *_pvData = CallGraphicController::getGraphicObjectPropertyAsBooleanVector(getScilabJavaVM(), _pstID, _pstName);
74                 return;
75             }
76             case jni_int:
77             {
78                 ((int *)*_pvData)[0] = CallGraphicController::getGraphicObjectPropertyAsInteger(getScilabJavaVM(), _pstID, _pstName);
79                 return;
80             }
81             case jni_int_vector:
82             {
83                 *_pvData = CallGraphicController::getGraphicObjectPropertyAsIntegerVector(getScilabJavaVM(), _pstID, _pstName);
84                 return;
85             }
86             default:
87                 *_pvData = NULL;
88                 return;
89         }
90     }
91     catch (std::exception &e)
92     {
93         e.what();
94         // If we have an exception, return null to scilab to manage error.
95         *_pvData = NULL;
96         return;
97     }
98
99 }
100
101
102 void releaseGraphicObjectProperty(char const* _pstName, void * _pvData, enum _ReturnType_ _returnType, int numElements)
103 {
104
105     /* All the Data model properties have the DATA_MODEL prefix */
106     if (strncmp(_pstName, __GO_DATA_MODEL__, strlen(__GO_DATA_MODEL__)) == 0)
107     {
108         // passed by reference, do not free them
109         return;
110     }
111
112     switch (_returnType)
113     {
114         case jni_string:
115         {
116             delete[] (char*) _pvData;
117             return;
118         }
119         case jni_string_vector:
120         {
121             char** data = (char**) _pvData;
122             for (int i = 0; i < numElements; ++i)
123             {
124                 delete[] data[i];
125             }
126             delete[] data;
127             return;
128         }
129         case jni_double:
130         {
131             // passed by value
132             return;
133         }
134         case jni_double_vector:
135         {
136             delete[] (double*) _pvData;
137             return;
138         }
139         case jni_bool:
140         {
141             // passed by value
142             return;
143         }
144         case jni_bool_vector:
145         {
146             delete[] (int*) _pvData;
147             return;
148         }
149         case jni_int:
150         {
151             // passed by value
152             return;
153         }
154         case jni_int_vector:
155         {
156             delete[] (int*) _pvData;
157             return;
158         }
159         default:
160             return;
161     }
162
163 }
164