vtkWrapTcl.c 24.6 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkWrapTcl.c

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
13
14
15
16

=========================================================================*/

#include <stdio.h>
17
#include <string.h>
18
19
20
21
#include "vtkParse.h"

int numberOfWrappedFunctions = 0;
FunctionInfo *wrappedFunctions[1000];
22
extern FunctionInfo *currentFunction;
23
24


Ken Martin's avatar
Ken Martin committed
25
void output_temp(FILE *fp, int i, int aType, char *Id, int count)
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{
  /* handle VAR FUNCTIONS */
  if (aType == 5000)
    {
    fprintf(fp,"    vtkTclVoidFuncArg *temp%i = new vtkTclVoidFuncArg;\n",i);
    return;
    }
  
  /* ignore void */
  if (((aType % 10) == 2)&&(!((aType%1000)/100)))
    {
    return;
    }

  /* for const * return types prototype with const */
  if ((i == MAX_ARGS) && (aType%2000 >= 1000))
    {
    fprintf(fp,"    const ");
    }
  else
    {
    fprintf(fp,"    ");
    }

  if ((aType%100)/10 == 1)
    {
    fprintf(fp,"unsigned ");
    }

  switch (aType%10)
    {
    case 1:   fprintf(fp,"float  "); break;
    case 7:   fprintf(fp,"double "); break;
    case 4:   fprintf(fp,"int    "); break;
    case 5:   fprintf(fp,"short  "); break;
    case 6:   fprintf(fp,"long   "); break;
    case 2:     fprintf(fp,"void   "); break;
    case 3:     fprintf(fp,"char   "); break;
    case 9:     fprintf(fp,"%s ",Id); break;
    case 8: return;
    }

Ken Martin's avatar
Ken Martin committed
68
69
70
71
72
73
74
  /* handle array arguements */
  if (count > 1)
    {
    fprintf(fp,"temp%i[%i];\n",i,count);
    return;
    }
  
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  switch ((aType%1000)/100)
    {
    case 1: fprintf(fp, " *"); break; /* act " &" */
    case 2: fprintf(fp, "&&"); break;
    case 3: fprintf(fp, " *"); break;
    case 4: fprintf(fp, "&*"); break;
    case 5: fprintf(fp, "*&"); break;
    case 7: fprintf(fp, "**"); break;
    default: fprintf(fp,"  "); break;
    }
  
  fprintf(fp,"temp%i",i);
  fprintf(fp,";\n");
}

/* when the cpp file doesn't have enough info use the hint file */
void use_hints(FILE *fp)
{
  int  i;

  /* use the hint */
  switch (currentFunction->ReturnType%1000)
    {
    case 301: case 307:  
99
100
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
101
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
102
103
104
        {
        fprintf(fp,"%%g ");
        }
105
106
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
107
108
109
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
110
      fprintf(fp,");\n");
111
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
112
      break;
Ken Martin's avatar
Ken Martin committed
113
    case 304: case 305: case 306: 
114
115
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
116
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
117
118
119
        {
        fprintf(fp,"%%i ");
        }
120
121
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
122
123
124
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
125
      fprintf(fp,");\n");
126
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
127
      break;
Ken Martin's avatar
Ken Martin committed
128
    case 313: case 314: case 315: case 316:
129
130
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"");
Ken Martin's avatar
Ken Martin committed
131
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
132
133
134
        {
        fprintf(fp,"%%u ");
        }
Ken Martin's avatar
Ken Martin committed
135
136
      fprintf(fp,"\"");
      for (i = 0; i < currentFunction->HintSize; i++)
Ken Martin's avatar
Ken Martin committed
137
138
139
        {
        fprintf(fp,",temp%i[%i]",MAX_ARGS,i);
        }
Ken Martin's avatar
Ken Martin committed
140
      fprintf(fp,");\n");
141
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
Ken Martin's avatar
Ken Martin committed
142
      break;
143
144
145
146
147
148
149
150
    }
}

void return_result(FILE *fp)
{
  switch (currentFunction->ReturnType%1000)
    {
    case 2:
151
      fprintf(fp,"    Tcl_ResetResult(interp);\n"); 
152
      break;
153
    case 1: case 7: 
154
155
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%g\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
156
              MAX_ARGS); 
157
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
158
      break;
159
    case 4:  
160
161
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%i\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
162
              MAX_ARGS); 
163
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
164
165
      break;
    case 5:
166
167
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hi\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
168
              MAX_ARGS); 
169
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
170
171
      break;
    case 6:
172
173
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%li\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
174
              MAX_ARGS);
175
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
176
      break;
177
    case 14:
178
179
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%u\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
180
              MAX_ARGS); 
181
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
182
      break;
183
    case 15: 
184
185
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
186
              MAX_ARGS);  
187
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
188
      break;
189
    case 16:  
190
191
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%lu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
192
              MAX_ARGS);
193
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
194
195
      break;
    case 13:
196
197
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%hu\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
198
              MAX_ARGS); 
199
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
200
201
      break;
    case 303:
202
203
204
      fprintf(fp,"    if (temp%i)\n      {\n      Tcl_SetResult(interp, (char*)temp%i, TCL_VOLATILE);\n",MAX_ARGS,MAX_ARGS); 
      fprintf(fp,"      }\n    else\n      {\n");
      fprintf(fp,"      Tcl_ResetResult(interp);\n      }\n"); 
205
206
      break;
    case 3:
207
208
      fprintf(fp,"    char tempResult[1024];\n");
      fprintf(fp,"    sprintf(tempResult,\"%%c\",temp%i);\n",
Ken Martin's avatar
Ken Martin committed
209
              MAX_ARGS); 
210
      fprintf(fp,"    Tcl_SetResult(interp, tempResult, TCL_VOLATILE);\n");
211
212
213
      break;
    case 109:
    case 309:  
214
      fprintf(fp,"      vtkTclGetObjectFromPointer(interp,(void *)temp%i,\"%s\");\n",MAX_ARGS,currentFunction->ReturnClass);
215
216
217
218
219
220
      break;

    /* handle functions returning vectors */
    /* this is done by looking them up in a hint file */
    case 301: case 307:
    case 304: case 305: case 306:
221
    case 313: case 314: case 315: case 316:      
222
223
224
      use_hints(fp);
      break;
    default:
Bill Lorensen's avatar
Bill Lorensen committed
225
      fprintf(fp,"    Tcl_SetResult(interp, (char *) \"unable to return result.\", TCL_VOLATILE);\n");
226
227
228
229
230
231
      break;
    }
}

void get_args(FILE *fp, int i)
{
Ken Martin's avatar
Ken Martin committed
232
233
234
235
236
237
238
239
240
241
  int j;
  int start_arg = 2;
  
  /* what arg do we start with */
  for (j = 0; j < i; j++)
    {
    start_arg = start_arg + 
      (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
    }
  
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
  /* handle VAR FUNCTIONS */
  if (currentFunction->ArgTypes[i] == 5000)
    {
    fprintf(fp,"    temp%i->interp = interp;\n",i);
    fprintf(fp,"    temp%i->command = strcpy(new char [strlen(argv[2])+1],argv[2]);\n",i);
    return;
    }

  /* ignore void */
  if (((currentFunction->ArgTypes[i] % 10) == 2)&&
      (!((currentFunction->ArgTypes[i]%1000)/100)))
    {
    return;
    }
  
  switch (currentFunction->ArgTypes[i]%1000)
    {
    case 1: case 7:  
      fprintf(fp,
Ken Martin's avatar
Ken Martin committed
261
262
              "    if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
              start_arg); 
263
264
265
266
      fprintf(fp,"    temp%i = tempd;\n",i);
      break;
    case 4: case 5: case 6: 
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
267
              start_arg); 
268
269
270
      fprintf(fp,"    temp%i = tempi;\n",i);
      break;
    case 3:
Ken Martin's avatar
Ken Martin committed
271
      fprintf(fp,"    temp%i = *(argv[%i]);\n",i,start_arg);
272
273
274
      break;
    case 13:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
275
              start_arg); 
276
277
278
279
      fprintf(fp,"    temp%i = (unsigned char)tempi;\n",i);
      break;
    case 14:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
280
              start_arg); 
281
282
283
284
      fprintf(fp,"    temp%i = (unsigned int)tempi;\n",i);
      break;
    case 15:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
285
              start_arg); 
286
287
      fprintf(fp,"    temp%i = (unsigned short)tempi;\n",i);
      break;
Ken Martin's avatar
Ken Martin committed
288
289
    case 16:
      fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
Ken Martin's avatar
Ken Martin committed
290
              start_arg); 
Ken Martin's avatar
Ken Martin committed
291
292
      fprintf(fp,"    temp%i = (unsigned long)tempi;\n",i);
      break;
293
    case 303:
Ken Martin's avatar
Ken Martin committed
294
      fprintf(fp,"    temp%i = argv[%i];\n",i,start_arg);
295
296
297
      break;
    case 109:
    case 309:
298
      fprintf(fp,"    temp%i = (%s *)(vtkTclGetPointerFromObject(argv[%i],(char *) \"%s\",interp,error));\n",i,currentFunction->ArgClasses[i],start_arg,
Ken Martin's avatar
Ken Martin committed
299
              currentFunction->ArgClasses[i]);
300
301
302
303
      break;
    case 2:    
    case 9:
      break;
Ken Martin's avatar
Ken Martin committed
304
305
    default:
      if (currentFunction->ArgCounts[i] > 1)
Ken Martin's avatar
Ken Martin committed
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
        {
        for (j = 0; j < currentFunction->ArgCounts[i]; j++)
          {
          switch (currentFunction->ArgTypes[i]%100)
            {
            case 1: case 7:  
              fprintf(fp,
                      "    if (Tcl_GetDouble(interp,argv[%i],&tempd) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = tempd;\n",i,j);
              break;
            case 4: case 5: case 6: 
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = tempi;\n",i,j);
              break;
            case 3:
              fprintf(fp,"    temp%i[%i] = *(argv[%i]);\n",i,j,start_arg);
              break;
            case 13:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned char)tempi;\n",i,j);
              break;
            case 14:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned int)tempi;\n",i,j);
              break;
            case 15:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned short)tempi;\n",i,j);
              break;
            case 16:
              fprintf(fp,"    if (Tcl_GetInt(interp,argv[%i],&tempi) != TCL_OK) error = 1;\n",
                      start_arg); 
              fprintf(fp,"    temp%i[%i] = (unsigned long)tempi;\n",i,j);
              break;
            }
          start_arg++;
          }
        }
Ken Martin's avatar
Ken Martin committed
349
      
350
351
352
353
354
355
356
357
358
    }
}

void outputFunction(FILE *fp, FileInfo *data)
{
  int i;
  int args_ok = 1;
 
  /* some functions will not get wrapped no matter what else */
359
  if (currentFunction->IsOperator || 
360
      currentFunction->ArrayFailure ||
Ken Martin's avatar
Ken Martin committed
361
362
      !currentFunction->IsPublic ||
      !currentFunction->Name) 
363
364
365
366
367
368
369
370
    {
    return;
    }
  
  /* check to see if we can handle the args */
  for (i = 0; i < currentFunction->NumberOfArguments; i++)
    {
    if ((currentFunction->ArgTypes[i]%10) == 8) args_ok = 0;
Ken Martin's avatar
Ken Martin committed
371
    /* if its a pointer arg make sure we have the ArgCount */
372
    if ((currentFunction->ArgTypes[i]%1000 >= 100) &&
Ken Martin's avatar
Ken Martin committed
373
374
375
        (currentFunction->ArgTypes[i]%1000 != 303)&&
        (currentFunction->ArgTypes[i]%1000 != 309)&&
        (currentFunction->ArgTypes[i]%1000 != 109)) 
Ken Martin's avatar
Ken Martin committed
376
377
      {
      if (currentFunction->NumberOfArguments > 1 ||
Ken Martin's avatar
Ken Martin committed
378
379
380
381
          !currentFunction->ArgCounts[i])
        {
        args_ok = 0;
        }
Ken Martin's avatar
Ken Martin committed
382
      }
383
    if ((currentFunction->ArgTypes[i]%100 >= 10)&&
Ken Martin's avatar
Ken Martin committed
384
385
386
387
        (currentFunction->ArgTypes[i] != 13)&&
        (currentFunction->ArgTypes[i] != 14)&&
        (currentFunction->ArgTypes[i] != 15)&&
        (currentFunction->ArgTypes[i] != 16)) args_ok = 0;
388
389
390
391
392
393
394
395
396
    }
  if ((currentFunction->ReturnType%10) == 8) args_ok = 0;
  if (((currentFunction->ReturnType%1000)/100 != 3)&&
      ((currentFunction->ReturnType%1000)/100 != 1)&&
      ((currentFunction->ReturnType%1000)/100)) args_ok = 0;
  if (currentFunction->NumberOfArguments && 
      (currentFunction->ArgTypes[0] == 5000)
      &&(currentFunction->NumberOfArguments != 1)) args_ok = 0;

Ken Martin's avatar
Ken Martin committed
397
398
399
400
401
402
  /* we can't handle void * return types */
  if ((currentFunction->ReturnType%1000) == 302) 
    {
    args_ok = 0;
    }
  
403
404
405
406
407
  /* watch out for functions that dont have enough info */
  switch (currentFunction->ReturnType%1000)
    {
    case 301: case 307:
    case 304: case 305: case 306:
408
    case 313: case 314: case 315: case 316:
409
410
411
412
413
414
415
416
417
      args_ok = currentFunction->HaveHint;
      break;
    }
  
  /* if the args are OK and it is not a constructor or destructor */
  if (args_ok && 
      strcmp(data->ClassName,currentFunction->Name) &&
      strcmp(data->ClassName,currentFunction->Name + 1))
    {
Ken Martin's avatar
Ken Martin committed
418
419
420
421
422
423
    int required_args = 0;
    
    /* calc the total required args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      required_args = required_args + 
Ken Martin's avatar
Ken Martin committed
424
        (currentFunction->ArgCounts[i] ? currentFunction->ArgCounts[i] : 1);
Ken Martin's avatar
Ken Martin committed
425
426
      }
    
427
428
429
430
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
431
    fprintf(fp,"  if ((!strcmp(\"%s\",argv[1]))&&(argc == %i))\n    {\n",
Ken Martin's avatar
Ken Martin committed
432
            currentFunction->Name, required_args + 2);
433
434
435
436
437
    
    /* process the args */
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      output_temp(fp, i, currentFunction->ArgTypes[i],
Ken Martin's avatar
Ken Martin committed
438
439
                  currentFunction->ArgClasses[i], 
                  currentFunction->ArgCounts[i]);
440
441
      }
    output_temp(fp, MAX_ARGS,currentFunction->ReturnType,
Ken Martin's avatar
Ken Martin committed
442
                currentFunction->ReturnClass, 0);
443

444
    /* only use the error variable if we have arguments to parse */
445
    if (currentFunction->NumberOfArguments)
446
      {
447
448
449
450
451
452
453
      fprintf(fp,"    error = 0;\n\n");
      /* now get the required args from the stack */
      for (i = 0; i < currentFunction->NumberOfArguments; i++)
        {
        get_args(fp,i);
        }
      fprintf(fp,"    if (!error)\n    {\n");
454
455
456
457
458
      }
    
    switch (currentFunction->ReturnType%1000)
      {
      case 2:
459
        fprintf(fp,"    op->%s(",currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
460
        break;
461
      case 109:
462
        fprintf(fp,"    temp%i = &(op)->%s(",MAX_ARGS,currentFunction->Name);
Ken Martin's avatar
Ken Martin committed
463
        break;
464
      default:
465
        fprintf(fp,"    temp%i = (op)->%s(",MAX_ARGS,currentFunction->Name);
466
467
468
469
      }
    for (i = 0; i < currentFunction->NumberOfArguments; i++)
      {
      if (i)
Ken Martin's avatar
Ken Martin committed
470
471
472
        {
        fprintf(fp,",");
        }
473
      if (currentFunction->ArgTypes[i] == 109)
Ken Martin's avatar
Ken Martin committed
474
475
476
        {
        fprintf(fp,"*(temp%i)",i);
        }
477
      else if (currentFunction->ArgTypes[i] == 5000)
Ken Martin's avatar
Ken Martin committed
478
479
480
        {
        fprintf(fp,"vtkTclVoidFunc,(void *)temp%i",i);
        }
481
      else
Ken Martin's avatar
Ken Martin committed
482
483
484
        {
        fprintf(fp,"temp%i",i);
        }
485
486
487
      }
    fprintf(fp,");\n");
    if (currentFunction->NumberOfArguments && 
Ken Martin's avatar
Ken Martin committed
488
        (currentFunction->ArgTypes[0] == 5000))
489
      {
490
      fprintf(fp,"    op->%sArgDelete(vtkTclVoidFuncArgDelete);\n",
Ken Martin's avatar
Ken Martin committed
491
              currentFunction->Name);
492
493
      }
    return_result(fp);
494
495
    fprintf(fp,"    return TCL_OK;\n");
    
496
    /* close the if error */
497
498
499
500
501
    if (currentFunction->NumberOfArguments)
      {
      fprintf(fp,"    }\n");
      }
    
502
    fprintf(fp,"    }\n");
503
504
505
506
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
Ken Martin's avatar
Ken Martin committed
507
    
508
509
510
511
512
513
514
515
    wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
    numberOfWrappedFunctions++;
    }
}

/* print the parsed structures */
void vtkParseOutput(FILE *fp, FileInfo *data)
{
516
  int i,j;
517
518
  
  fprintf(fp,"// tcl wrapper for %s object\n//\n",data->ClassName);
519
  fprintf(fp,"#define VTK_WRAPPING_CXX\n");
520
521
  if (strcmp("vtkObjectBase",data->ClassName) != 0)
    {
522
      /* Block inclusion of full streams. */
523
524
    fprintf(fp,"#define VTK_STREAMS_FWD_ONLY\n");
    }
Will Schroeder's avatar
Will Schroeder committed
525
  fprintf(fp,"#include \"vtkSystemIncludes.h\"\n");
526
527
528
529
  fprintf(fp,"#include \"%s.h\"\n\n",data->ClassName);
  fprintf(fp,"#include \"vtkTclUtil.h\"\n");
  if (data->IsConcrete)
    {
530
531
    if (strcmp(data->ClassName, "vtkRenderWindowInteractor") == 0)
      {
532
533
534
      fprintf(fp,"#include \"vtkToolkits.h\"\n");
      fprintf(fp,"#ifdef VTK_USE_X\n");
      fprintf(fp,"# include \"vtkXRenderWindowTclInteractor.h\"\n");
Yves Starreveld's avatar
   
Yves Starreveld committed
535
      fprintf(fp,"#endif\n");
536
537
538

      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);

539
      fprintf(fp,"#ifdef VTK_USE_X\n");
540
      fprintf(fp,"  %s *temp = vtkXRenderWindowTclInteractor::New();\n",
Ken Martin's avatar
Ken Martin committed
541
              data->ClassName);
542
543
544
545
546
547
548
549
550
551
552
      fprintf(fp,"#else\n");
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"#endif\n");
      fprintf(fp,"  return ((ClientData)temp);\n}\n\n");
      }
    else
      {
      fprintf(fp,"\nClientData %sNewCommand()\n{\n",data->ClassName);
      fprintf(fp,"  %s *temp = %s::New();\n",data->ClassName,data->ClassName);
      fprintf(fp,"  return ((ClientData)temp);\n}\n\n");
      }
553
554
555
556
557
558
559
560
    }
  
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"int %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[]);\n",data->SuperClasses[i],data->SuperClasses[i]);
    }
  fprintf(fp,"int VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[]);\n",data->ClassName,data->ClassName);
  fprintf(fp,"\nint VTKTCL_EXPORT %sCommand(ClientData cd, Tcl_Interp *interp,\n             int argc, char *argv[])\n{\n",data->ClassName);
561
  fprintf(fp,"  if ((argc == 2)&&(!strcmp(\"Delete\",argv[1]))&& !vtkTclInDelete(interp))\n    {\n");
562
563
  fprintf(fp,"    Tcl_DeleteCommand(interp,argv[0]);\n");
  fprintf(fp,"    return TCL_OK;\n    }\n");
564
  fprintf(fp,"   return %sCppCommand((%s *)(((vtkTclCommandArgStruct *)cd)->Pointer),interp, argc, argv);\n}\n",data->ClassName,data->ClassName);
565
566
567
568
569
570
  
  fprintf(fp,"\nint VTKTCL_EXPORT %sCppCommand(%s *op, Tcl_Interp *interp,\n             int argc, char *argv[])\n{\n",data->ClassName,data->ClassName);
  fprintf(fp,"  int    tempi;\n");
  fprintf(fp,"  double tempd;\n");
  fprintf(fp,"  static char temps[80];\n");
  fprintf(fp,"  int    error;\n\n");
571
572
573
574
  fprintf(fp,"  error = 0; error = error;\n");
  fprintf(fp,"  tempi = 0; tempi = tempi;\n");
  fprintf(fp,"  tempd = 0; tempd = tempd;\n");
  fprintf(fp,"  temps[0] = 0; temps[0] = temps[0];\n\n");
575

576
  fprintf(fp,"  if (argc < 2)\n    {\n    Tcl_SetResult(interp, (char *) \"Could not find requested method.\", TCL_VOLATILE);\n    return TCL_ERROR;\n    }\n");
577
578
579
580
581

  /* stick in the typecasting and delete functionality here */
  fprintf(fp,"  if (!interp)\n    {\n");
  fprintf(fp,"    if (!strcmp(\"DoTypecasting\",argv[0]))\n      {\n");
  fprintf(fp,"      if (!strcmp(\"%s\",argv[1]))\n        {\n",
Ken Martin's avatar
Ken Martin committed
582
          data->ClassName);
583
584
585
586
587
588
589
  fprintf(fp,"        argv[2] = (char *)((void *)op);\n");
  fprintf(fp,"        return TCL_OK;\n        }\n");

  /* check our superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"      if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n        {\n",
Ken Martin's avatar
Ken Martin committed
590
            data->SuperClasses[i],data->SuperClasses[i]);
591
592
593
594
    fprintf(fp,"        return TCL_OK;\n        }\n");      
    }
  fprintf(fp,"      }\n    return TCL_ERROR;\n    }\n\n");
  
Ken Martin's avatar
Ken Martin committed
595
596
597
598
599
  /* add the GetSuperClassName */
  if (data->NumberOfSuperClasses)
    {
    fprintf(fp,"  if (!strcmp(\"GetSuperClassName\",argv[1]))\n");
    fprintf(fp,"    {\n");
600
    fprintf(fp,"    Tcl_SetResult(interp,(char *) \"%s\", TCL_VOLATILE);\n",data->SuperClasses[0]);
Ken Martin's avatar
Ken Martin committed
601
602
603
    fprintf(fp,"    return TCL_OK;\n");
    fprintf(fp,"    }\n\n");      
    }
604
605
606
607
608
609
610
611
612
613
  
  /* insert function handling code here */
  for (i = 0; i < data->NumberOfFunctions; i++)
    {
    currentFunction = data->Functions + i;
    outputFunction(fp, data);
    }
  
  /* add the ListInstances method */
  fprintf(fp,"\n  if (!strcmp(\"ListInstances\",argv[1]))\n    {\n");
Jim Miller's avatar
Jim Miller committed
614
  fprintf(fp,"    vtkTclListInstances(interp,(ClientData)%sCommand);\n",data->ClassName);
615
616
617
618
619
620
621
622
  fprintf(fp,"    return TCL_OK;\n    }\n");
  
  /* add the ListMethods method */
  fprintf(fp,"\n  if (!strcmp(\"ListMethods\",argv[1]))\n    {\n");
  /* recurse up the tree */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"    %sCppCommand(op,interp,argc,argv);\n",
Ken Martin's avatar
Ken Martin committed
623
            data->SuperClasses[i]);
624
625
626
    }
  /* now list our methods */
  fprintf(fp,"    Tcl_AppendResult(interp,\"Methods from %s:\\n\",NULL);\n",data->ClassName);
Ken Martin's avatar
Ken Martin committed
627
  fprintf(fp,"    Tcl_AppendResult(interp,\"  GetSuperClassName\\n\",NULL);\n");
628
629
  for (i = 0; i < numberOfWrappedFunctions; i++)
    {
630
631
    int numArgs = 0;

632
    currentFunction = wrappedFunctions[i];
633
634
635
636
    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#if !defined(VTK_LEGACY_REMOVE)\n");
      }
Ken Martin's avatar
Ken Martin committed
637
            
638
639
640
641
    /* calc the total required args */
    for (j = 0; j < currentFunction->NumberOfArguments; j++)
      {
      numArgs = numArgs + 
Ken Martin's avatar
Ken Martin committed
642
        (currentFunction->ArgCounts[j] ? currentFunction->ArgCounts[j] : 1);
643
644
645
      }

    if (numArgs > 1)
646
647
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with %i args\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
648
              currentFunction->Name, numArgs);
649
      }
650
    if (numArgs == 1)
651
      {
Ken Martin's avatar
Ken Martin committed
652
653
          fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\t with 1 arg\\n\",NULL);\n",
                  currentFunction->Name);
654
      }
655
    if (numArgs == 0)
656
657
      {
      fprintf(fp,"    Tcl_AppendResult(interp,\"  %s\\n\",NULL);\n",
Ken Martin's avatar
Ken Martin committed
658
              currentFunction->Name);
659
      }
660
661
662
663
664

    if(currentFunction->IsLegacy)
      {
      fprintf(fp,"#endif\n");
      }
665
666
667
668
669
670
671
    }
  fprintf(fp,"    return TCL_OK;\n    }\n");
  
  /* try superclasses */
  for (i = 0; i < data->NumberOfSuperClasses; i++)
    {
    fprintf(fp,"\n  if (%sCppCommand((%s *)op,interp,argc,argv) == TCL_OK)\n",
Ken Martin's avatar
Ken Martin committed
672
            data->SuperClasses[i], data->SuperClasses[i]);
673
674
675
    fprintf(fp,"    {\n    return TCL_OK;\n    }\n");
    }
  
676
  /* Add the Print method to vtkObjectBase. */
677
  if (!strcmp("vtkObjectBase",data->ClassName))
678
679
    {
    fprintf(fp,"  if ((!strcmp(\"Print\",argv[1]))&&(argc == 2))\n    {\n");
680
681
682
683
684
685
    fprintf(fp,"    ostrstream buf_with_warning_C4701;\n");
    fprintf(fp,"    op->Print(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
    fprintf(fp,"    Tcl_SetResult(interp,buf_with_warning_C4701.str(),\n");
    fprintf(fp,"      TCL_VOLATILE);\n");
    fprintf(fp,"    buf_with_warning_C4701.rdbuf()->freeze(0);\n");
686
    fprintf(fp,"    return TCL_OK;\n    }\n");
687
688
    /* Add the PrintRevisions method to vtkObjectBase. */
    fprintf(fp,"  if ((!strcmp(\"PrintRevisions\",argv[1]))&&(argc == 2))\n    {\n");
689
690
691
692
693
694
    fprintf(fp,"    ostrstream buf_with_warning_C4701;\n");
    fprintf(fp,"    op->PrintRevisions(buf_with_warning_C4701);\n");
    fprintf(fp,"    buf_with_warning_C4701.put('\\0');\n");
    fprintf(fp,"    Tcl_SetResult(interp,buf_with_warning_C4701.str(),\n");
    fprintf(fp,"      TCL_VOLATILE);\n");
    fprintf(fp,"    delete [] buf_with_warning_C4701.str();\n");
695
    fprintf(fp,"    return TCL_OK;\n    }\n");    
696
    }
697
  /* Add the AddObserver method to vtkObject. */
698
699
  if (!strcmp("vtkObject",data->ClassName))
    {
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
    fprintf(fp,"  if ((!strcmp(\"AddObserver\",argv[1]))&&(argc >= 4))\n    {\n");
    fprintf(fp,"    error = 0;\n");
    fprintf(fp,"    if (argc > 4 && Tcl_GetDouble(interp,argv[4],&tempd) != TCL_OK) error = 1;\n");
    fprintf(fp,"    if (!error)\n      {\n");
    fprintf(fp,"      vtkTclCommand *cbc = vtkTclCommand::New();\n");
    fprintf(fp,"      cbc->SetInterp(interp);\n");
    fprintf(fp,"      cbc->SetStringCommand(argv[3]);\n");
    fprintf(fp,"      unsigned long      temp20;\n");
    fprintf(fp,"      if (argc > 4)\n        {\n");
    fprintf(fp,"        temp20 = op->AddObserver(argv[2],cbc,tempd);\n");
    fprintf(fp,"        }\n      else\n        {\n");
    fprintf(fp,"        temp20 = op->AddObserver(argv[2],cbc);\n");
    fprintf(fp,"        }\n");
    fprintf(fp,"      cbc->Delete();\n");
    fprintf(fp,"      char tempResult[1024];\n");
    fprintf(fp,"      sprintf(tempResult,\"%%li\",temp20);\n");
    fprintf(fp,"      Tcl_SetResult(interp,tempResult,TCL_VOLATILE);\n");
    fprintf(fp,"      return TCL_OK;\n      }\n");
    fprintf(fp,"    }\n");
719
720
721
722
723
724
    }
  fprintf(fp,"\n  if ((argc >= 2)&&(!strstr(interp->result,\"Object named:\")))\n    {\n");
  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");
  fprintf(fp,"  return TCL_ERROR;\n}\n");

}