fc6377f6502a80de32a53202b7dcf94e2b95ac5d
[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 #include "CurrentObjectsManagement.h"
26
27 #include "GetHashTable.h"
28 #include "BuildObjects.h"
29 #include "localization.h"
30 #include "Scierror.h"
31
32 #include "SetPropertyStatus.h"
33 #include "GetScreenProperty.h"
34 #include "freeArrayOfString.h"
35 /*--------------------------------------------------------------------------*/
36 int sciGet(sciPointObj *pobj,char *marker);
37 /*--------------------------------------------------------------------------*/
38 int sciGet(sciPointObj *pobj,char *marker)
39 {
40         /* find the function in the hashtable relative to the property name */
41         /* and call it */
42         return callGetProperty( pobj, marker ) ;
43 }
44 /*--------------------------------------------------------------------------*/
45 int sci_get(char *fname,unsigned long fname_len)
46 {
47         int m1,n1,numrow2,numcol2,l2 ;
48         int l1;
49         long hdl;
50
51         int lw;
52         sciPointObj *pobj;
53
54         /* Root properties */
55         char **stkAdr = NULL;
56         int status = SET_PROPERTY_ERROR;
57
58         if ((VarType(1) == sci_mlist) || (VarType(1) == sci_tlist))
59           {
60             lw = 1 + Top - Rhs;
61             C2F(overload)(&lw,"get",3);
62             return 0;
63           }
64         
65         CheckRhs(1,2);
66         CheckLhs(0,1);
67
68         /*  set or create a graphic window */
69
70         /* 
71         The first input argument can be an ID or a marker (in this case, get returns the value of the current object */
72         switch(VarType(1))
73         {
74         case 1: /* tclsci handle */
75                 GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE , &m1, &n1, &l1);
76                 if ((int) *stk(l1) == 0) /* Root property */
77                 {
78                         CheckRhs(2,2);
79                         if (VarType(2) == sci_strings)
80                         {
81                                 GetRhsVar(2,  MATRIX_OF_STRING_DATATYPE, &m1, &n1, &stkAdr);
82
83                                 if (m1*n1 != 1)
84                                 {
85                                         freeArrayOfString(stkAdr, m1 * n1);
86                                         Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), "get",2);
87                                         return SET_PROPERTY_ERROR;
88                                 }
89
90                                 status = GetScreenProperty(stkAdr[0]);
91
92                                 if(status != SET_PROPERTY_SUCCEED) /* Return property */
93                                 {
94                                         Scierror(999, _("%s: Could not read property '%s' for root object.\n"), "get", stkAdr[0]);
95                                         freeArrayOfString(stkAdr, m1 * n1);
96                                         return FALSE;
97                                 }
98                                 freeArrayOfString(stkAdr, m1 * n1);
99                         }
100                         else
101                         {
102                                 Scierror(999, _("%s: Wrong type for input argument #%d: Single string expected.\n"), "get",2);
103                                 return FALSE;
104                         }
105                         LhsVar(1) = Rhs+1;
106                         C2F(putlhsvar)();
107                 }
108                 else /* tclsci handle: should no more happen */
109                 {
110                         lw = 1 + Top - Rhs;
111                         C2F(overload)(&lw,"get",3);
112                 }
113                 return 0;
114                 break;
115         case sci_handles: /* scalar argument (hdl + string) */
116                 CheckRhs(2,2);
117                 GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&m1,&n1,&l1);
118                 if (m1!=1||n1!=1) 
119                 { 
120                         lw = 1 + Top - Rhs;
121                         C2F(overload)(&lw,"get",3);
122                         return 0;
123                 }
124                 GetRhsVar(2,STRING_DATATYPE,&numrow2,&numcol2,&l2);
125                 hdl = (long)*hstk(l1); /* on recupere le pointeur d'objet par le handle */
126                 break;
127         case sci_strings:/* string argument (string) */
128                 CheckRhs(1,1);
129                 GetRhsVar(1,STRING_DATATYPE,&numrow2,&numcol2,&l2);
130                 if (strcmp(cstk(l2),"default_figure") != 0 && strcmp(cstk(l2),"default_axes") != 0)
131                 {
132                         if ( strcmp(cstk(l2),"current_figure") == 0 ||  strcmp(cstk(l2),"current_axes") == 0 ||  strcmp(cstk(l2),"current_entity") == 0 ||  strcmp(cstk(l2),"hdl") == 0)
133                         {
134                                 hdl = 0;
135                         }
136                         else
137                         {
138                                 /* Test debug F.Leray 13.04.04 */
139                                 if ((strcmp(cstk(l2),"children") != 0) && (strcmp(cstk(l2),"zoom_") !=0) && (strcmp(cstk(l2),"clip_box") !=0) && (strcmp(cstk(l2),"auto_") !=0)) 
140                                 {
141                                         SciWin();
142                                         hdl = sciGetHandle(sciGetCurrentObj());
143                                 }
144                                 else
145                                 {
146                                         hdl = sciGetHandle(sciGetCurrentSubWin());/* on recupere le pointeur d'objet par le handle */
147                                 }
148                         }/* DJ.A 08/01/04 */
149                 }
150                 else
151                 {
152                         hdl = 0;
153                 }
154                 break;
155         default:
156                 lw = 1 + Top - Rhs;
157                 C2F(overload)(&lw,"get",3);
158                 return 0;
159                 break;
160         }
161         /* cstk(l2) est la commande, l3 l'indice sur les parametres de la commande */
162         CheckLhs(0,1);
163
164         if (hdl == 0) 
165         {
166                 /* No handle specified */
167                 if (sciGet(NULL, cstk(l2)) != 0) 
168                 {
169                         /* An error has occured */
170                         C2F(putlhsvar)();
171                         return 0;
172                 }
173         }
174         else
175         {
176                 pobj = sciGetPointerFromHandle(hdl);
177                 if (pobj != NULL)
178                 {
179
180                         if (sciGet(pobj, cstk(l2)) != 0)
181                         {
182                                 /* An error has occured */
183                                 C2F(putlhsvar)();
184                                 return 0;
185                         }
186                 }
187                 else
188                 {
189                         Scierror(999,_("%s: The handle is not or no more valid.\n"),fname);
190                         return 0;
191                 }
192         }
193
194         LhsVar(1) = Rhs + 1;
195         C2F(putlhsvar)();
196
197         return 0;
198 }
199 /*--------------------------------------------------------------------------*/