1 /* UI generator main module */
2 /* Bertrand Guiheneuf, INRIA 1997 */
4 #include "C-LAB_Interf.h"
5 #include "TK_uicontrol.h"
6 #include "TK_ScilabCallback.h"
8 /*#include "x_data.h" /* To get screen properties */
12 /* forward declarations */
21 char *UiStyleName[] = {"button", "checkbutton", "checkbutton", "entry", "label",
22 "scale", "frame", "scrolllistbox", "popupmenu"};
30 int GetStyle(StyleStr)
34 if (! strcmp(StyleStr,"pushbutton" )) return 0;
35 else if (! strcmp(StyleStr,"radiobutton" )) return 1;
36 else if (! strcmp(StyleStr,"checkbox" )) return 2;
37 else if (! strcmp(StyleStr,"edit" )) return 3;
38 else if (! strcmp(StyleStr,"text" )) return 4;
39 else if (! strcmp(StyleStr,"slider" )) return 5;
40 else if (! strcmp(StyleStr,"frame" )) return 6;
41 else if (! strcmp(StyleStr,"listbox" )) return 7;
42 else if (! strcmp(StyleStr,"popupmenu" )) return 8;
50 int TK_UiSet( int Handle,Matrix * Mfield,Matrix * Mvalue)
52 char *StrField, *StrValue;
56 StrField = MatrixReadString(Mfield);
58 if (MatrixIsString(Mvalue))
60 StrValue = MatrixReadString(Mvalue);
61 /* nocase(StrValue); (modif Bruno 14/1/2001) */
63 else if (MatrixIsReal(Mvalue))
64 StrValue = Mat2Str(Mvalue);
65 else if (MatrixIsList(Mvalue))
66 StrValue = ListStr2Str(Mvalue);
72 if (!strcmp(StrField,"userdata"))
74 mem_siz = MatrixMemSize(Mvalue);
75 UserData[Handle]=(Matrix *)malloc(mem_siz);
76 MatrixCopy(Mvalue,UserData[Handle]);
80 sprintf(MyCommand,"SetField %d \"%s\" \"%s\"",Handle,StrField,StrValue);
81 Tcl_Eval(TKinterp,MyCommand);
93 int TK_UiGet(int Handle,Matrix * Mfield,Matrix ** Mvalue)
102 StrField = MatrixReadString(Mfield);
105 sprintf(MyCommand,"set MyTmpBertrand [GetField %d \"%s\"]", Handle, StrField);
107 if(Handle==0) /* Screen properties */
109 if(!GetScreenProperty(StrField,&MyAnswer))
111 Str2MatReal(MyAnswer, Mvalue);
116 *Mvalue = MatrixCreate(0,0,"real");
122 Tcl_Eval(TKinterp,MyCommand);
123 MyAnswer = (char*)Tcl_GetVar(TKinterp, "MyTmpBertrand", 0);
125 if ( MyAnswer == NULL)
127 *Mvalue = MatrixCreate(0,0,"real");
132 if (!strcmp(StrField,"position")) {Str2MatReal(MyAnswer, Mvalue); goto fin; }
133 if (!strcmp(StrField,"value")) {Str2MatReal(MyAnswer, Mvalue); goto fin; }
134 if (!strcmp(StrField,"min")) {Str2MatReal(MyAnswer, Mvalue); goto fin; }
135 if (!strcmp(StrField,"max")) {Str2MatReal(MyAnswer, Mvalue); goto fin; }
136 if (!strcmp(StrField,"userdata"))
138 if (UserData[Handle]!=NULL)
140 mem_siz = MatrixMemSize(UserData[Handle]);
141 TmpMat=(Matrix *)malloc(mem_siz);
142 MatrixCopy(UserData[Handle],TmpMat);
146 *Mvalue = MatrixCreate(0,0,"real");
150 Str2ListStr(MyAnswer, Mvalue);
177 in = MatrixGetPr(Min);
178 m=MatrixGetHeight(Min);
179 n=MatrixGetWidth(Min);
184 strl = sz * (ENT * MANT + 2);
185 /* the before the dot, after the dot, the dot and a space */
187 retstr = malloc( (1+strl) * sizeof(char));
188 tmpstr = malloc( (ENT * MANT + 2) * sizeof(char));
192 for (i=0; i<(sz-1); i++)
194 sprintf(tmpstr,"%.10lf|", in[i]);
195 strcat( retstr,tmpstr );
198 sprintf(tmpstr,"%.10lf", in[i]);
199 strcat( retstr,tmpstr );
205 retstr = malloc( sizeof(char) );
218 int Str2MatReal(str, Mat)
221 /* Split a string (str) which contains float numbers separated by '|' */
222 /* and return a vector formed with those numbers. */
241 tmpstr = (char *)malloc((lgth+1) * sizeof(char));
243 /* How many elements in the string ? */
244 for (i=0; i<(lgth-1); i++)
245 if (str[i]=='|') nbelem++;
247 /* Let's ask for some mem. */
248 *Mat=(Matrix *)MatrixCreate(1, nbelem, "real");
249 MatPr=MatrixGetPr(*Mat);
255 for (elem=0; elem<nbelem; elem++)
258 while ( (end_elem<lgth) && (str[end_elem] != '|') )
264 strncpy(tmpstr, str+begin_elem, end_elem-begin_elem);
265 *(MatPr++)=atof(tmpstr);
266 begin_elem = end_elem+1;
267 end_elem = begin_elem;
272 /* string was empty */
273 else *Mat = MatrixCreate(0,0,"real");
284 int Str2ListStr(str, Mat)
287 /* Split a string (str) which contains substrings separated by '|' */
288 /* and return a scilab list formed with those substrings */
308 tmpstr = (char *)malloc((lgth+1) * sizeof(char));
310 /* How many elements in the string ? */
311 for (i=0; i<(lgth-1); i++)
312 if (str[i]=='|') nbelem++;
314 /* Let's ask for some mem. */
315 *Mat=(Matrix *)ListCreate();
322 /* there is more than one substring in the string */
323 /* so we create a scilab list of strings */
325 for (elem=0; elem<nbelem; elem++)
328 while ( (end_elem<lgth) && (str[end_elem] != '|') )
334 strncpy(tmpstr, str+begin_elem, end_elem-begin_elem);
335 tmpstr[end_elem-begin_elem]='\0';
336 MTmpStr = MatrixCreateString(tmpstr);
337 *Mat=AppendList(*Mat, MTmpStr);
339 begin_elem = end_elem+1;
340 end_elem = begin_elem;
344 /* the string contains no separator, so we return a scilab string */
346 *Mat = MatrixCreateString(str);
349 /* string was empty */
350 else *Mat = MatrixCreateString("");
362 /* concat. a list of strings into a single string */
363 /* the substrings are saprated by a '|' */
373 if (!MatrixIsList(l)) { InterfError("Input parameter must be a list"); return(NULL);}
374 nbelem = ListGetSize(l);
376 for (i=0; i<nbelem; i++)
378 Mtmp = ListGetCell(i, l);
379 if (!MatrixIsString(Mtmp) )
381 InterfError("One element of the list is not a string");
385 tmpstr = MatrixReadString(Mtmp);
386 bigsize += strlen(tmpstr);
390 bigstr = (char *)malloc( (bigsize + nbelem) *sizeof(char));
392 /* set the first string into the result */
395 Mtmp = ListGetCell(0, l);
396 tmpstr = MatrixReadString(Mtmp);
398 strncpy(begin, tmpstr, sz);
402 for (i=1; i<nbelem; i++)
404 /* now set all the other */
406 Mtmp = ListGetCell(i , l);
407 tmpstr = MatrixReadString(Mtmp);
409 strncpy(begin, tmpstr, sz);