TclUiSet.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* INRIA 2005 */
00003 /* Allan CORNET */
00004 /*-----------------------------------------------------------------------------------*/
00005 #include "TclUiSet.h"
00006 /*-----------------------------------------------------------------------------------*/
00007 #define NBRSTYLE 9
00008 char *UiStyleInternalName[NBRSTYLE] = {"button",
00009                                                    "checkbutton",
00010                                                    "checkbutton",
00011                                                    "entry",
00012                                                    "label",
00013                                        "scale",
00014                                                    "frame",
00015                                                    "scrolllistbox",
00016                                                    "popupmenu"};
00017 char *UiStyleExternalName[NBRSTYLE] = {"pushbutton",
00018                                "radiobutton",
00019                                "checkbox",
00020                                "edit",
00021                                "text",
00022                                "slider",
00023                                "frame",
00024                                "listbox",
00025                                                "popupmenu"};
00026 /*-----------------------------------------------------------------------------------*/
00027 int GetStyleInternalName(char *StyleStr);
00028 int SetVarStrings(Tcl_Interp *TCLinterpreter,char *VarName,char **Str,int m,int n);
00029 int SetVarAString(Tcl_Interp *TCLinterpreter,char *VarName,char **Str);
00030 int SetVarMatrix(Tcl_Interp *TCLinterpreter,char *VarName,int ptrValues,int m,int n);
00031 int SetVarScalar(Tcl_Interp *TCLinterpreter,char *VarName,double VarValue);
00032 /*-----------------------------------------------------------------------------------*/
00033 int InterfaceScilabToUiSet(int Handle,int RhsPropertieField,int RhsPropertieValue)
00034 {
00035         int bOK=0;
00036 
00037         if (Handle>0)
00038         {
00039                 if (GetType(RhsPropertieField)==sci_strings)
00040                 {
00041                         static int l1,n1,m1;
00042                         char *StrField=NULL;
00043 
00044                         GetRhsVar(RhsPropertieField,"c",&m1,&n1,&l1);
00045                         StrField=cstk(l1);
00046                         nocase(StrField);
00047 
00048                         if (strcmp(StrField,"userdata")==0)
00049                         {
00050                                 if (GetType(RhsPropertieValue)==sci_strings)
00051                                 {
00052                                         char **Str=NULL;
00053                                         char VarName[64];
00054                                         int i=0;
00055 
00056                                         GetRhsVar(RhsPropertieValue,"S",&m1,&n1,&Str);
00057                                         sprintf(VarName,"USERDATA_%d",Handle);
00058 
00059                                         /* Efface valeur precedente */
00060                                         Tcl_UnsetVar(TCLinterp, VarName, TCL_GLOBAL_ONLY);
00061 
00062                                         if ( (m1==1) && (n1==1) )
00063                                         {
00064                                                 SetVarAString(TCLinterp,VarName,Str);
00065                                         }
00066                                         else
00067                                         {
00068                                                 SetVarStrings(TCLinterp,VarName,Str,m1,n1);
00069                                         }
00070                                         if (Str) for (i = 0; i<m1*n1 ;i++)
00071                                         {
00072                                                 if (Str[i]) 
00073                                                 {
00074                                                         FREE(Str[i]);
00075                                                         Str[i]=NULL;
00076                                                 }
00077                                         }
00078                                         if (Str) {FREE(Str); Str=NULL;}
00079                                 }
00080                                 else if (GetType(RhsPropertieValue)==sci_matrix)
00081                                 {
00082                                         char VarName[64];
00083 
00084                                         sprintf(VarName,"USERDATA_%d",Handle);
00085 
00086                                         GetRhsVar(RhsPropertieValue,"d",&m1,&n1,&l1);
00087 
00088                                         if ( (m1==0) && (n1==0) )
00089                                         {
00090                                                 Scierror(999,"[] doesn''t work with TCL");
00091                                                 return 0;
00092                                         }
00093 
00094                                         if ( (m1==1) && (n1==1) )
00095                                         {
00096                                                 SetVarScalar(TCLinterp,VarName,(double)*stk(l1));
00097                                         }
00098                                 else 
00099                                         {
00100                                                 SetVarMatrix(TCLinterp,VarName,l1,m1,n1);
00101                                         }
00102                                 }
00103                                 else
00104                                 {
00105                                         Scierror(999,TCL_ERROR8);
00106                                         return 0;
00107                                 }
00108                         }
00109                         else
00110                         {
00111                                 if(strcmp(StrField,"string")==0)
00112                                 {
00113                                         if (GetType(RhsPropertieValue)==sci_strings)
00114                                         {
00115                                                 char **Str=NULL;
00116                                                 char VarName[64];
00117                                                 int i=0;
00118 
00119                                                 GetRhsVar(RhsPropertieValue,"S",&m1,&n1,&Str);
00120                                                 sprintf(VarName,"STRING_%d",Handle);
00121 
00122                                                 /* Efface valeur precedente */
00123                                                 Tcl_UnsetVar(TCLinterp, VarName, TCL_GLOBAL_ONLY);
00124 
00125                                                 if ( (m1==1) && (n1==1) )
00126                                                 {
00127                                                         /* Les donnees sont dans STRING_%d */
00128                                                         SetVarAString(TCLinterp,VarName,Str);
00129 
00130                                                         /* Block inutile apres modifications dans set.tcl */
00131                                                         {
00132                                                                 #define CommandLenMax 2048      
00133                                                         
00134 
00135                                                                 char MyTclCommand[CommandLenMax];
00136                                                                 sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,StrField,Str[0]);
00137 
00138                                                                 if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
00139                                                                 {
00140                                                                         Scierror(999,TCL_ERROR4,TCLinterp->result);
00141                                                                         return 0;
00142                                                                 }
00143                                                         }
00144                                                 }
00145                                                 else
00146                                                 {
00147                                                         SetVarStrings(TCLinterp,VarName,Str,m1,n1);
00148 
00149                                                         /* Block inutil apres modifications dans set.tcl */
00150                                                         {
00151                                                                 #define CommandLenMax 2048      
00152 
00153                                                                 char MyTclCommand[CommandLenMax];
00154                                                                 sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,StrField,Str[0]);
00155 
00156                                                                 if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
00157                                                                 {
00158                                                                         Scierror(999,TCL_ERROR4,TCLinterp->result);
00159                                                                         return 0;
00160                                                                 }
00161                                                         }
00162                                                 }
00163                                                 if (Str) for (i = 0; i<m1*n1 ;i++)
00164                                                 {
00165                                                         if (Str[i]) 
00166                                                         {
00167                                                                 FREE(Str[i]);
00168                                                                 Str[i]=NULL;
00169                                                         }
00170                                                 }
00171                                                 if (Str) {FREE(Str); Str=NULL;}
00172                                                 bOK=1;
00173                                         }
00174                                         else
00175                                         {
00176                                                 /* doit une chaine ou matrice de chaine */
00177                                                 Scierror(999,TCL_ERROR9);
00178                                                 return 0;
00179                                         }
00180 
00181                                 }
00182                                 else
00183                                 {
00184                                         /* Cas general */
00185                                         char *PropertieField=NULL;
00186                                         char *PropertieValue=NULL;
00187 
00188                                         PropertieField=(char*)MALLOC((strlen(StrField)+1)*sizeof(char));
00189                                         sprintf(PropertieField,"%s",StrField);
00190 
00191                                         if (GetType(RhsPropertieValue) == sci_strings)
00192                                         {
00193                                                 char *TmpCharValue=NULL;
00194 
00195                                                 GetRhsVar(RhsPropertieValue,"c",&m1,&n1,&l1);
00196                                                 TmpCharValue=cstk(l1);
00197 
00198                                                 PropertieValue=(char*)MALLOC((strlen(TmpCharValue)+1)*sizeof(char));
00199                                                 sprintf(PropertieValue,"%s",TmpCharValue);
00200                                         }
00201                                         else if (GetType(RhsPropertieValue) == sci_matrix)
00202                                         {
00203                                                 if (PropertieValue){FREE(PropertieValue);PropertieValue=NULL;}
00204                                                 PropertieValue=Matrix2String(RhsPropertieValue);
00205                                         }
00206                                         else
00207                                         {
00208                                                 Scierror(999,TCL_ERROR8);
00209                                                 return 0;
00210                                         }
00211                                         bOK=TCL_UiSet(Handle,PropertieField,PropertieValue);
00212 
00213                                         if (PropertieField){FREE(PropertieField);PropertieField=NULL;}
00214                                         if (PropertieValue){FREE(PropertieValue);PropertieValue=NULL;}
00215                                 }
00216                         }
00217                 }
00218                 else
00219                 {
00220                         /* champ propertie doit etre une chaine */
00221                         Scierror(999,TCL_ERROR22);
00222                         return 0;
00223                 }
00224         }
00225         else
00226         {
00227                 /* Handle numero incorrect */
00228                 Scierror(999,TCL_ERROR34);
00229                 return 0;
00230         }
00231         return bOK;
00232 }
00233 /*-----------------------------------------------------------------------------------*/
00234 int TCL_UiSet(int Handle,char *PropertieField,char *PropertieValue)
00235 {
00236         #define CommandLenMax 2048      
00237         int bOK=0;
00238         int LenStr=0;
00239         
00240         char MyTclCommand[CommandLenMax];
00241 
00242         LenStr=(int)(strlen(PropertieField)+strlen(PropertieValue)+strlen("SetField              ")+1);
00243 
00244         if (LenStr >= CommandLenMax)
00245         {
00246                 Scierror(999,TCL_ERROR32,CommandLenMax);
00247                 return 0;
00248         }
00249         nocase(PropertieField);
00250 
00251         if ( CheckPropertyField(PropertieField) )
00252         {
00253                 if (strcmp(PropertieField,"style")==0)
00254                 {
00255                         int StyleValue=-1;
00256 
00257                         StyleValue=GetStyleInternalName(PropertieValue);
00258                         if (StyleValue!=-1)
00259                         {
00260                                 sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,PropertieField,UiStyleExternalName[StyleValue]);
00261                         }
00262                         else
00263                         {
00264                                 Scierror(999,TCL_ERROR33);
00265                                 return 0;
00266                         }
00267                 }
00268                 else
00269                 {
00270                         sprintf(MyTclCommand,"SetField %d \"%s\" \"%s\"",Handle,PropertieField,PropertieValue);
00271                 }
00272 
00273                 if ( Tcl_Eval(TCLinterp,MyTclCommand) == TCL_ERROR  )
00274                 {
00275                         Scierror(999,TCL_ERROR4,TCLinterp->result);
00276                         return 0;
00277                 }
00278                 bOK=1;
00279         }
00280         else
00281         {
00282                 Scierror(999,TCL_ERROR30,PropertieField);
00283                 return 0;
00284         }
00285         
00286         return bOK;
00287 }
00288 /*-----------------------------------------------------------------------------------*/
00289 int GetStyleInternalName(char *StyleStr)
00290 {
00291         int IndexInternalName=-1;
00292         int i=0;
00293         for(i=0;i<NBRSTYLE;i++)
00294         {
00295                 if ( strcmp(StyleStr,UiStyleExternalName[i])==0 )
00296                 {
00297                         IndexInternalName=i;
00298                         return IndexInternalName;
00299                 }
00300         }
00301         return IndexInternalName;
00302 }
00303 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:04:01 2007 for Scilab [trunk] by  doxygen 1.5.1