Initial step :
[scilab.git] / scilab / modules / graphics / sci_gateway / c / sci_get.c
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2004 - INRIA - Djalel Abdemouche
4 * Copyright (C) 2006 - INRIA - Fabrice Leray
5 * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
6 * Copyright (C) 2006 - INRIA - Vincent Couvert
7 *
8 * This file must be used under the terms of the CeCILL.
9 * This source file is licensed as described in the file COPYING, which
10 * you should have received as part of this distribution.  The terms
11 * are also available at
12 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 *
14 */
15
16 /*------------------------------------------------------------------------*/
17 /* file: sci_get.c                                                        */
18 /* desc : interface for sci_get routine                                   */
19 /*------------------------------------------------------------------------*/
20 #include "gw_graphics.h"
21 /*--------------------------------------------------------------------------*/
22
23 #include "stack-c.h"
24 #include "HandleManagement.h"
25
26 #include "GetHashTable.h"
27 #include "BuildObjects.h"
28 #include "localization.h"
29 #include "Scierror.h"
30
31 #include "HandleManagement.h"
32 #include "CurrentObject.h"
33 #include "CurrentSubwin.h"
34
35
36 #include "SetPropertyStatus.h"
37 #include "GetScreenProperty.h"
38 #include "freeArrayOfString.h"
39 /*--------------------------------------------------------------------------*/
40 int sciGet(sciPointObj *pobj,char *marker);
41 /*--------------------------------------------------------------------------*/
42 int sciGet(sciPointObj *pobj,char *marker)
43 {
44         /* find the function in the hashtable relative to the property name */
45         /* and call it */
46         return callGetProperty( pobj, marker ) ;
47 }
48 /*--------------------------------------------------------------------------*/
49 int sci_get(char *fname,unsigned long fname_len)
50 {
51         int m1,n1,numrow2,numcol2,l2 ;
52         int l1;
53         long hdl;
54
55         int lw;
56         sciPointObj *pobj;
57
58         /* Root properties */
59         char **stkAdr = NULL;
60         int status = SET_PROPERTY_ERROR;
61
62         if ((VarType(1) == sci_mlist) || (VarType(1) == sci_tlist))
63           {
64             lw = 1 + Top - Rhs;
65             C2F(overload)(&lw,"get",3);
66             return 0;
67           }
68
69         CheckRhs(1,2);
70         CheckLhs(0,1);
71
72         /*  set or create a graphic window */
73
74         /*
75         The first input argument can be an ID or a marker (in this case, get returns the value of the current object */
76         switch(VarType(1))
77         {
78         case 1: /* tclsci handle */
79                 GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE , &m1, &n1, &l1);
80                 if ((int) *stk(l1) == 0) /* Root property */
81                 {
82                         CheckRhs(2,2);
83                         if (VarType(2) == sci_strings)
84                         {
85                                 GetRhsVar(2,  MATRIX_OF_STRING_DATATYPE, &m1, &n1, &stkAdr);
86
87                                 if (m1*n1 != 1)
88                                 {
89                                         freeArrayOfString(stkAdr, m1 * n1);
90                                         Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), "get",2);
91                                         return SET_PROPERTY_ERROR;
92                                 }
93
94                                 status = GetScreenProperty(stkAdr[0]);
95
96                                 if(status != SET_PROPERTY_SUCCEED) /* Return property */
97                                 {
98                                         Scierror(999, _("%s: Could not read property '%s' for root object.\n"), "get", stkAdr[0]);
99                                         freeArrayOfString(stkAdr, m1 * n1);
100                                         return FALSE;
101                                 }
102                                 freeArrayOfString(stkAdr, m1 * n1);
103                         }
104                         else
105                         {
106                                 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), "get",2);
107                                 return FALSE;
108                         }
109                         LhsVar(1) = Rhs+1;
110                         C2F(putlhsvar)();
111                 }
112                 else /* tclsci handle: should no more happen */
113                 {
114                         lw = 1 + Top - Rhs;
115                         C2F(overload)(&lw,"get",3);
116                 }
117                 return 0;
118                 break;
119         case sci_handles: /* scalar argument (hdl + string) */
120                 CheckRhs(2,2);
121                 GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&m1,&n1,&l1);
122                 if (m1!=1||n1!=1)
123                 {
124                         lw = 1 + Top - Rhs;
125                         C2F(overload)(&lw,"get",3);
126                         return 0;
127                 }
128                 GetRhsVar(2,STRING_DATATYPE,&numrow2,&numcol2,&l2);
129                 hdl = (long)*hstk(l1); /* on recupere le pointeur d'objet par le handle */
130                 break;
131         case sci_strings:/* string argument (string) */
132                 CheckRhs(1,1);
133                 GetRhsVar(1,STRING_DATATYPE,&numrow2,&numcol2,&l2);
134                 if (strcmp(cstk(l2),"default_figure") != 0 && strcmp(cstk(l2),"default_axes") != 0)
135                 {
136                         if ( strcmp(cstk(l2),"current_figure") == 0 ||  strcmp(cstk(l2),"current_axes") == 0 ||  strcmp(cstk(l2),"current_entity") == 0 ||  strcmp(cstk(l2),"hdl") == 0)
137                         {
138                                 hdl = 0;
139                         }
140                         else
141                         {
142                                 /* Test debug F.Leray 13.04.04 */
143                                 if ((strcmp(cstk(l2),"children") != 0) && (strcmp(cstk(l2),"zoom_") !=0) && (strcmp(cstk(l2),"clip_box") !=0) && (strcmp(cstk(l2),"auto_") !=0))
144                                 {
145                                         SciWin();
146                                         hdl = getHandle(getCurrentObject());
147                                 }
148                                 else
149                                 {
150                                         hdl = getHandle(getCurrentSubWin());/* on recupere le pointeur d'objet par le handle */
151                                 }
152                         }/* DJ.A 08/01/04 */
153                 }
154                 else
155                 {
156                         hdl = 0;
157                 }
158                 break;
159         default:
160                 lw = 1 + Top - Rhs;
161                 C2F(overload)(&lw,"get",3);
162                 return 0;
163                 break;
164         }
165         /* cstk(l2) est la commande, l3 l'indice sur les parametres de la commande */
166         CheckLhs(0,1);
167
168         if (hdl == 0)
169         {
170                 /* No handle specified */
171                 if (sciGet(NULL, cstk(l2)) != 0)
172                 {
173                         /* An error has occured */
174                         C2F(putlhsvar)();
175                         return 0;
176                 }
177         }
178         else
179         {
180                 pobj = sciGetPointerFromHandle(hdl);
181                 if (pobj != NULL)
182                 {
183
184                         if (sciGet(pobj, cstk(l2)) != 0)
185                         {
186                                 /* An error has occured */
187                                 C2F(putlhsvar)();
188                                 return 0;
189                         }
190                 }
191                 else
192                 {
193                         Scierror(999,_("%s: The handle is not or no more valid.\n"),fname);
194                         return 0;
195                 }
196         }
197
198         LhsVar(1) = Rhs + 1;
199         C2F(putlhsvar)();
200
201         return 0;
202 }
203 /*--------------------------------------------------------------------------*/