00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include <stdio.h>
00044 #include <string.h>
00045 #include "vtkParse.h"
00046
00047 int numberOfWrappedFunctions = 0;
00048 FunctionInfo *wrappedFunctions[1000];
00049 extern FunctionInfo *currentFunction;
00050
00051
00052 void output_temp(FILE *fp, int i, int aType, char *Id, int count)
00053 {
00054
00055 if (aType == 5000)
00056 {
00057 fprintf(fp," vtkTclVoidFuncArg *temp%i = new vtkTclVoidFuncArg;\n",i);
00058 return;
00059 }
00060
00061
00062 if (((aType % 10) == 2)&&(!((aType%1000)/100)))
00063 {
00064 return;
00065 }
00066
00067
00068 if ((i == MAX_ARGS) && (aType%2000 >= 1000))
00069 {
00070 fprintf(fp," const ");
00071 }
00072 else
00073 {
00074 fprintf(fp," ");
00075 }
00076
00077 if ((aType%100)/10 == 1)
00078 {
00079 fprintf(fp,"unsigned ");
00080 }
00081
00082 switch (aType%10)
00083 {
00084 case 1: fprintf(fp,"float "); break;
00085 case 7: fprintf(fp,"double "); break;
00086 case 4: fprintf(fp,"int "); break;
00087 case 5: fprintf(fp,"short "); break;
00088 case 6: fprintf(fp,"long "); break;
00089 case 2: fprintf(fp,"void "); break;
00090 case 3: fprintf(fp,"char "); break;
00091 case 9: fprintf(fp,"%s ",Id); break;
00092 case 8: return;
00093 }
00094
00095
00096 if (count > 1)
00097 {
00098 fprintf(fp,"temp%i[%i];\n",i,count);
00099 return;
00100 }
00101
00102 switch ((aType%1000)/100)
00103 {
00104 case 1: fprintf(fp, " *"); break;
00105 case 2: fprintf(fp, "&&"); break;
00106 case 3: fprintf(fp, " *"); break;
00107 case 4: fprintf(fp, "&*"); break;
00108 case 5: fprintf(fp, "*&"); break;
00109 case 7: fprintf(fp, "**"); break;
00110 default: fprintf(fp," "); break;
00111 }
00112
00113 fprintf(fp,"temp%i",i);
00114 fprintf(fp,";\n");
00115 }
00116
00117
00118 void use_hints(FILE *fp)
00119 {
00120 int i;
00121
00122
00123 switch (currentFunction->ReturnType%1000)
00124 {
00125 case 301: case 307:
00126 fprintf(fp," char tempResult[1024];\n");
00127 fprintf(fp," sprintf(tempResult,\"");
00128 for (i = 0; i < currentFunction->HintSize; i++)
00129 {
00130 fprintf(fp,"%%g ");
00131 }
00132 fprintf(fp,"\"");
00133 for (i = 0; i < currentFunction->HintSize; i++)
00134 {
00135 fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
00136 }
00137 fprintf(fp,");\n");
00138 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00139 break;
00140 case 304: case 305: case 306:
00141 fprintf(fp," char tempResult[1024];\n");
00142 fprintf(fp," sprintf(tempResult,\"");
00143 for (i = 0; i < currentFunction->HintSize; i++)
00144 {
00145 fprintf(fp,"%%i ");
00146 }
00147 fprintf(fp,"\"");
00148 for (i = 0; i < currentFunction->HintSize; i++)
00149 {
00150 fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
00151 }
00152 fprintf(fp,");\n");
00153 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00154 break;
00155 case 313: case 314: case 315: case 316:
00156 fprintf(fp," char tempResult[1024];\n");
00157 fprintf(fp," sprintf(tempResult,\"");
00158 for (i = 0; i < currentFunction->HintSize; i++)
00159 {
00160 fprintf(fp,"%%u ");
00161 }
00162 fprintf(fp,"\"");
00163 for (i = 0; i < currentFunction->HintSize; i++)
00164 {
00165 fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
00166 }
00167 fprintf(fp,");\n");
00168 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00169 break;
00170 }
00171 }
00172
00173 void return_result(FILE *fp)
00174 {
00175 switch (currentFunction->ReturnType%1000)
00176 {
00177 case 2:
00178 fprintf(fp," Tcl_ResetResult(interp);\n");
00179 break;
00180 case 1: case 7:
00181 fprintf(fp," char tempResult[1024];\n");
00182 fprintf(fp," sprintf(tempResult,\"%%g\",temp%i);\n",
00183 MAX_ARGS);
00184 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00185 break;
00186 case 4:
00187 fprintf(fp," char tempResult[1024];\n");
00188 fprintf(fp," sprintf(tempResult,\"%%i\",temp%i);\n",
00189 MAX_ARGS);
00190 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00191 break;
00192 case 5:
00193 fprintf(fp," char tempResult[1024];\n");
00194 fprintf(fp," sprintf(tempResult,\"%%hi\",temp%i);\n",
00195 MAX_ARGS);
00196 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00197 break;
00198 case 6:
00199 fprintf(fp," char tempResult[1024];\n");
00200 fprintf(fp," sprintf(tempResult,\"%%li\",temp%i);\n",
00201 MAX_ARGS);
00202 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00203 break;
00204 case 14:
00205 fprintf(fp," char tempResult[1024];\n");
00206 fprintf(fp," sprintf(tempResult,\"%%u\",temp%i);\n",
00207 MAX_ARGS);
00208 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00209 break;
00210 case 15:
00211 fprintf(fp," char tempResult[1024];\n");
00212 fprintf(fp," sprintf(tempResult,\"%%hu\",temp%i);\n",
00213 MAX_ARGS);
00214 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00215 break;
00216 case 16:
00217 fprintf(fp," char tempResult[1024];\n");
00218 fprintf(fp," sprintf(tempResult,\"%%lu\",temp%i);\n",
00219 MAX_ARGS);
00220 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00221 break;
00222 case 13:
00223 fprintf(fp," char tempResult[1024];\n");
00224 fprintf(fp," sprintf(tempResult,\"%%hu\",temp%i);\n",
00225 MAX_ARGS);
00226 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00227 break;
00228 case 303:
00229 fprintf(fp," if (temp%i)\n {\n Tcl_SetResult(interp, (char*)temp%i, TCL_VOLATILE);\n",MAX_ARGS,MAX_ARGS);
00230 fprintf(fp," }\n else\n {\n");
00231 fprintf(fp," Tcl_ResetResult(interp);\n }\n");
00232 break;
00233 case 3:
00234 fprintf(fp," char tempResult[1024];\n");
00235 fprintf(fp," sprintf(tempResult,\"%%c\",temp%i);\n",
00236 MAX_ARGS);
00237 fprintf(fp," Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
00238 break;
00239 case 109:
00240 case 309:
00241 fprintf(fp," vtkTclGetObjectFromPointer(interp,(void *)temp%i,%sCommand);\n",MAX_ARGS,currentFunction->ReturnClass);
00242 break;
00243
00244
00245
00246 case 301: case 307:
00247 case 304: case 305: case 306:
00248 case 313: case 314: case 315: case 316:
00249 use_hints(fp);
00250 break;
00251 default:
00252 fprintf(fp," Tcl_SetResult(interp, (char *) \"unable to return result.\", TCL_VOLATILE);\n");
00253 break;
00254 }
00255 }
00256
00257 void handle_return_prototype(FILE *fp)
00258 {
00259 switch (currentFunction->ReturnType%1000)
00260 {
00261 case 109:
00262 case 309:
00263 fprintf(fp," int %sCommand(ClientData, Tcl_Interp *, int, char *[]);\n",currentFunction->ReturnClass);
00264 break;
00265 }
00266 }
00267
00268 void get_args(FILE *fp, int i)
00269 {
00270 int j;
00271 int start_arg = 2;
00272
00273
00274 for (j = 0; j < i; j++)
00275 {
00276 start_arg = start_arg +
00277 (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
00278 }
00279
00280
00281 if (currentFunction->ArgTypes[i] == 5000)
00282 {
00283 fprintf(fp," temp%i->interp = interp;\n",i);
00284 fprintf(fp," temp%i->command = strcpy(new char [strlen(argv[2])+1],argv[2]);\n",i);
00285 return;
00286 }
00287
00288
00289 if (((currentFunction->ArgTypes[i] % 10) == 2)&&
00290 (!((currentFunction->ArgTypes[i]%1000)/100)))
00291 {
00292 return;
00293 }
00294
00295 switch (currentFunction->ArgTypes[i]%1000)
00296 {
00297 case 1: case 7:
00298 fprintf(fp,
00299 " if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
00300 start_arg);
00301 fprintf(fp," temp%i = tempd;\n",i);
00302 break;
00303 case 4: case 5: case 6:
00304 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00305 start_arg);
00306 fprintf(fp," temp%i = tempi;\n",i);
00307 break;
00308 case 3:
00309 fprintf(fp," temp%i = *(argv[%i]);\n",i,start_arg);
00310 break;
00311 case 13:
00312 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00313 start_arg);
00314 fprintf(fp," temp%i = (unsigned char)tempi;\n",i);
00315 break;
00316 case 14:
00317 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00318 start_arg);
00319 fprintf(fp," temp%i = (unsigned int)tempi;\n",i);
00320 break;
00321 case 15:
00322 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00323 start_arg);
00324 fprintf(fp," temp%i = (unsigned short)tempi;\n",i);
00325 break;
00326 case 16:
00327 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00328 start_arg);
00329 fprintf(fp," temp%i = (unsigned long)tempi;\n",i);
00330 break;
00331 case 303:
00332 fprintf(fp," temp%i = argv[%i];\n",i,start_arg);
00333 break;
00334 case 109:
00335 case 309:
00336 fprintf(fp," temp%i = (%s *)(vtkTclGetPointerFromObject(argv[%i],(char *) \"%s\",interp,error));\n",i,currentFunction->ArgClasses[i],start_arg,
00337 currentFunction->ArgClasses[i]);
00338 break;
00339 case 2:
00340 case 9:
00341 break;
00342 default:
00343 if (currentFunction->ArgCounts[i] > 1)
00344 {
00345 for (j = 0; j < currentFunction->ArgCounts[i]; j++)
00346 {
00347 switch (currentFunction->ArgTypes[i]%100)
00348 {
00349 case 1: case 7:
00350 fprintf(fp,
00351 " if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
00352 start_arg);
00353 fprintf(fp," temp%i[%i] = tempd;\n",i,j);
00354 break;
00355 case 4: case 5: case 6:
00356 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00357 start_arg);
00358 fprintf(fp," temp%i[%i] = tempi;\n",i,j);
00359 break;
00360 case 3:
00361 fprintf(fp," temp%i[%i] = *(argv[%i]);\n",i,j,start_arg);
00362 break;
00363 case 13:
00364 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00365 start_arg);
00366 fprintf(fp," temp%i[%i] = (unsigned char)tempi;\n",i,j);
00367 break;
00368 case 14:
00369 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00370 start_arg);
00371 fprintf(fp," temp%i[%i] = (unsigned int)tempi;\n",i,j);
00372 break;
00373 case 15:
00374 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00375 start_arg);
00376 fprintf(fp," temp%i[%i] = (unsigned short)tempi;\n",i,j);
00377 break;
00378 case 16:
00379 fprintf(fp," if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
00380 start_arg);
00381 fprintf(fp," temp%i[%i] = (unsigned long)tempi;\n",i,j);
00382 break;
00383 }
00384 start_arg++;
00385 }
00386 }
00387
00388 }
00389 }
00390
00391 void outputFunction(FILE *fp, FileInfo *data)
00392 {
00393 int i;
00394 int args_ok = 1;
00395
00396
00397 if (currentFunction->IsOperator ||
00398 currentFunction->ArrayFailure ||
00399 !currentFunction->IsPublic ||
00400 !currentFunction->Name)
00401 {
00402 return;
00403 }
00404
00405
00406 for (i = 0; i < currentFunction->NumberOfArguments; i++)
00407 {
00408 if ((currentFunction->ArgTypes[i]%10) == 8) args_ok = 0;
00409
00410 if ((currentFunction->ArgTypes[i]%1000 >= 100) &&
00411 (currentFunction->ArgTypes[i]%1000 != 303)&&
00412 (currentFunction->ArgTypes[i]%1000 != 309)&&
00413 (currentFunction->ArgTypes[i]%1000 != 109))
00414 {
00415 if (currentFunction->NumberOfArguments > 1 ||
00416 !currentFunction->ArgCounts[i])
00417 {
00418 args_ok = 0;
00419 }
00420 }
00421 if ((currentFunction->ArgTypes[i]%100 >= 10)&&
00422 (currentFunction->ArgTypes[i] != 13)&&
00423 (currentFunction->ArgTypes[i] != 14)&&
00424 (currentFunction->ArgTypes[i] != 15)&&
00425 (currentFunction->ArgTypes[i] != 16)) args_ok = 0;
00426 }
00427 if ((currentFunction->ReturnType%10) == 8) args_ok = 0;
00428 if (((currentFunction->ReturnType%1000)/100 != 3)&&
00429 ((currentFunction->ReturnType%1000)/100 != 1)&&
00430 ((currentFunction->ReturnType%1000)/100)) args_ok = 0;
00431 if (currentFunction->NumberOfArguments &&
00432 (currentFunction->ArgTypes[0] == 5000)
00433 &&(currentFunction->NumberOfArguments != 1)) args_ok = 0;
00434
00435
00436 if ((currentFunction->ReturnType%1000) == 302)
00437 {
00438 args_ok = 0;
00439 }
00440
00441
00442 switch (currentFunction->ReturnType%1000)
00443 {
00444 case 301: case 307:
00445 case 304: case 305: case 306:
00446 case 313: case 314: case 315: case 316:
00447 args_ok = currentFunction->HaveHint;
00448 break;
00449 }
00450
00451
00452 if (args_ok &&
00453 strcmp(data->ClassName,currentFunction->Name) &&
00454 strcmp(data->ClassName,currentFunction->Name + 1))
00455 {
00456 int required_args = 0;
00457
00458
00459 for (i = 0; i < currentFunction->NumberOfArguments; i++)
00460 {
00461 required_args = required_args +
00462 (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
00463 }
00464
00465 fprintf(fp," if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n {\n",
00466 currentFunction->Name, required_args + 2);
00467
00468
00469 for (i = 0; i < currentFunction->NumberOfArguments; i++)
00470 {
00471 output_temp(fp, i, currentFunction->ArgTypes[i],
00472 currentFunction->ArgClasses[i],
00473 currentFunction->ArgCounts[i]);
00474 }
00475 output_temp(fp, MAX_ARGS,currentFunction->ReturnType,
00476 currentFunction->ReturnClass, 0);
00477 handle_return_prototype(fp);
00478 fprintf(fp," error = 0;\n\n");
00479
00480
00481 for (i = 0; i < currentFunction->NumberOfArguments; i++)
00482 {
00483 get_args(fp,i);
00484 }
00485
00486 fprintf(fp," if (!error)\n {\n");
00487 switch (currentFunction->ReturnType%1000)
00488 {
00489 case 2:
00490 fprintf(fp," op->%s(",currentFunction->Name);
00491 break;
00492 case 109:
00493 fprintf(fp," temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name);
00494 break;
00495 default:
00496 fprintf(fp," temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name);
00497 }
00498 for (i = 0; i < currentFunction->NumberOfArguments; i++)
00499 {
00500 if (i)
00501 {
00502 fprintf(fp,",");
00503 }
00504 if (currentFunction->ArgTypes[i] == 109)
00505 {
00506 fprintf(fp,"*(temp%i)",i);
00507 }
00508 else if (currentFunction->ArgTypes[i] == 5000)
00509 {
00510 fprintf(fp,"vtkTclVoidFunc,(void *)temp%i",i);
00511 }
00512 else
00513 {
00514 fprintf(fp,"temp%i",i);
00515 }
00516 }
00517 fprintf(fp,");\n");
00518 if (currentFunction->NumberOfArguments &&
00519 (currentFunction->ArgTypes[0] == 5000))
00520 {
00521 fprintf(fp," op->%sArgDelete(vtkTclVoidFuncArgDelete);\n",
00522 currentFunction->Name);
00523 }
00524 return_result(fp);
00525 fprintf(fp," return TCL_OK;\n }\n");
00526 fprintf(fp," }\n");
00527
00528 wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
00529 numberOfWrappedFunctions++;
00530 }
00531 }
00532
00533
00534 void vtkParseOutput(FILE *fp, FileInfo *data)
00535 {
00536 int i,j;
00537
00538 fprintf(fp,"// tcl wrapper for %s object\n//\n",data->ClassName);
00539 fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
00540 fprintf(fp,"#include \"%s.h\"\n\n",data->ClassName);
00541 fprintf(fp,"#include \"vtkTclUtil.h\"\n");
00542 if (data->IsConcrete)
00543 {
00544 if (strcmp(data->ClassName, "vtkRenderWindowInteractor") == 0)
00545 {
00546 fprintf(fp,"#ifndef _WIN32\n");
00547 fprintf(fp,"#include \"vtkXRenderWindowTclInteractor.h\"\n");
00548 fprintf(fp,"#endif\n");
00549
00550 fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
00551
00552 fprintf(fp,"#ifndef _WIN32\n");
00553 fprintf(fp," %s *temp = vtkXRenderWindowTclInteractor::New();\n",
00554 data->ClassName);
00555 fprintf(fp,"#else\n");
00556 fprintf(fp," %s *temp = %s::New();\n",data->ClassName,data->ClassName);
00557 fprintf(fp,"#endif\n");
00558 fprintf(fp," return ((ClientData)temp);\n}\n\n");
00559 }
00560 else
00561 {
00562 fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
00563 fprintf(fp," %s *temp = %s::New();\n",data->ClassName,data->ClassName);
00564 fprintf(fp," return ((ClientData)temp);\n}\n\n");
00565 }
00566 }
00567
00568 for (i = 0; i < data->NumberOfSuperClasses; i++)
00569 {
00570 fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->SuperClasses[i],data->SuperClasses[i]);
00571 }
00572 fprintf(fp,"int VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[]);\n",data->ClassName,data->ClassName);
00573 fprintf(fp,"\nint VTKTCL_EXPORT %sCommand(ClientData cd, Tcl_Interp *interp,\n int argc, char *argv[])\n{\n",data->ClassName);
00574 fprintf(fp," if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n {\n");
00575 fprintf(fp," Tcl_DeleteCommand(interp,argv[0]);\n");
00576 fprintf(fp," return TCL_OK;\n }\n");
00577 fprintf(fp," return %sCppCommand((%s *)(((vtkTclCommandArgStruct *)cd)->Pointer),interp, argc, argv);\n}\n",data->ClassName,data->ClassName);
00578
00579 fprintf(fp,"\nint VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n int argc, char *argv[])\n{\n",data->ClassName,data->ClassName);
00580 fprintf(fp," int tempi;\n");
00581 fprintf(fp," double tempd;\n");
00582 fprintf(fp," static char temps[80];\n");
00583 fprintf(fp," int error;\n\n");
00584 fprintf(fp," error = 0; error = error;\n");
00585 fprintf(fp," tempi = 0; tempi = tempi;\n");
00586 fprintf(fp," tempd = 0; tempd = tempd;\n");
00587 fprintf(fp," temps[0] = 0; temps[0] = temps[0];\n\n");
00588
00589 fprintf(fp," if (argc < 2)\n {\n Tcl_SetResult(interp, (char *) \"Could not find requested method.\", TCL_VOLATILE);\n return TCL_ERROR;\n }\n");
00590
00591
00592 fprintf(fp," if (!interp)\n {\n");
00593 fprintf(fp," if (!strcmp(\"DoTypecasting\",argv[0]))\n {\n");
00594 fprintf(fp," if (!strcmp(\"%s\",argv[1]))\n {\n",
00595 data->ClassName);
00596 fprintf(fp," argv[2] = (char *)((void *)op);\n");
00597 fprintf(fp," return TCL_OK;\n }\n");
00598
00599
00600 for (i = 0; i < data->NumberOfSuperClasses; i++)
00601 {
00602 fprintf(fp," if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n {\n",
00603 data->SuperClasses[i],data->SuperClasses[i]);
00604 fprintf(fp," return TCL_OK;\n }\n");
00605 }
00606 fprintf(fp," }\n return TCL_ERROR;\n }\n\n");
00607
00608
00609 if (data->NumberOfSuperClasses)
00610 {
00611 fprintf(fp," if (!strcmp(\"GetSuperClassName\",argv[1]))\n");
00612 fprintf(fp," {\n");
00613 fprintf(fp," Tcl_SetResult(interp,(char *) \"%s\", TCL_VOLATILE);\n",data->SuperClasses[0]);
00614 fprintf(fp," return TCL_OK;\n");
00615 fprintf(fp," }\n\n");
00616 }
00617
00618
00619 for (i = 0; i < data->NumberOfFunctions; i++)
00620 {
00621 currentFunction = data->Functions + i;
00622 outputFunction(fp, data);
00623 }
00624
00625
00626 fprintf(fp,"\n if (!strcmp(\"ListInstances\",argv[1]))\n {\n");
00627 fprintf(fp," vtkTclListInstances(interp,(ClientData)%sCommand);\n",data->ClassName);
00628 fprintf(fp," return TCL_OK;\n }\n");
00629
00630
00631 fprintf(fp,"\n if (!strcmp(\"ListMethods\",argv[1]))\n {\n");
00632
00633 for (i = 0; i < data->NumberOfSuperClasses; i++)
00634 {
00635 fprintf(fp," %sCppCommand(op,interp,argc,argv);\n",
00636 data->SuperClasses[i]);
00637 }
00638
00639 fprintf(fp," Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->ClassName);
00640 fprintf(fp," Tcl_AppendResult(interp,\" GetSuperClassName\\n\",NULL);\n");
00641 for (i = 0; i < numberOfWrappedFunctions; i++)
00642 {
00643 int numArgs = 0;
00644
00645 currentFunction = wrappedFunctions[i];
00646
00647
00648 for (j = 0; j < currentFunction->NumberOfArguments; j++)
00649 {
00650 numArgs = numArgs +
00651 (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
00652 }
00653
00654 if (numArgs > 1)
00655 {
00656 fprintf(fp," Tcl_AppendResult(interp,\" %s\\t with %i args\\n\",NULL);\n",
00657 currentFunction->Name, numArgs);
00658 }
00659 if (numArgs == 1)
00660 {
00661 fprintf(fp," Tcl_AppendResult(interp,\" %s\\t with 1 arg\\n\",NULL);\n",
00662 currentFunction->Name);
00663 }
00664 if (numArgs == 0)
00665 {
00666 fprintf(fp," Tcl_AppendResult(interp,\" %s\\n\",NULL);\n",
00667 currentFunction->Name);
00668 }
00669 }
00670 fprintf(fp," return TCL_OK;\n }\n");
00671
00672
00673 for (i = 0; i < data->NumberOfSuperClasses; i++)
00674 {
00675 fprintf(fp,"\n if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n",
00676 data->SuperClasses[i], data->SuperClasses[i]);
00677 fprintf(fp," {\n return TCL_OK;\n }\n");
00678 }
00679
00680
00681 if (!strcmp("vtkObject",data->ClassName))
00682 {
00683 fprintf(fp," if ((!strcmp(\"Print\",argv[1]))&&(argc == 2))\n {\n");
00684 fprintf(fp," ostrstream buf;\n");
00685 fprintf(fp," op->Print(buf);\n");
00686 fprintf(fp," buf.put('\\0');\n");
00687 fprintf(fp," Tcl_SetResult(interp,buf.str(),TCL_VOLATILE);\n");
00688 fprintf(fp," delete buf.str();\n");
00689 fprintf(fp," return TCL_OK;\n }\n");
00690
00691 fprintf(fp," if ((!strcmp(\"AddObserver\",argv[1]))&&(argc == 4))\n {\n");
00692 fprintf(fp," vtkTclCommand *cbc = vtkTclCommand::New();\n");
00693 fprintf(fp," cbc->SetInterp(interp);\n");
00694 fprintf(fp," cbc->SetStringCommand(argv[3]);\n");
00695
00696 fprintf(fp," unsigned long temp20;\n");
00697 fprintf(fp," temp20 = op->AddObserver(argv[2],cbc);\n");
00698 fprintf(fp," cbc->Delete();\n");
00699 fprintf(fp," char tempResult[1024];\n");
00700 fprintf(fp," sprintf(tempResult,\"%%li\",temp20);\n");
00701 fprintf(fp," Tcl_SetResult(interp,tempResult,TCL_VOLATILE);\n");
00702 fprintf(fp," return TCL_OK;\n }\n");
00703 }
00704 fprintf(fp,"\n if ((argc >= 2)&&(!strstr(interp->result,\"Object named:\")))\n {\n");
00705 fprintf(fp," char temps2[256];\n sprintf(temps2,\"Object named: %%s, could not find requested method: %%s\\nor the method was called with incorrect arguments.\\n\",argv[0],argv[1]);\n Tcl_AppendResult(interp,temps2,NULL);\n }\n");
00706 fprintf(fp," return TCL_ERROR;\n}\n");
00707
00708 }