1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkParseJavaBeans.c
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 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 #include "vtkParse.h"
19 #include "vtkParseMain.h"
20 #include "vtkParseHierarchy.h"
21
22 HierarchyInfo *hierarchyInfo = NULL;
23 int numberOfWrappedFunctions = 0;
24 FunctionInfo *wrappedFunctions[1000];
25 extern FunctionInfo *currentFunction;
26
output_temp(FILE * fp,int i)27 void output_temp(FILE *fp,int i)
28 {
29 unsigned int aType =
30 (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE);
31
32 /* ignore void */
33 if (aType == VTK_PARSE_VOID)
34 {
35 return;
36 }
37
38 if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION)
39 {
40 fprintf(fp,"Object id0, String id1");
41 return;
42 }
43
44 if ((aType == VTK_PARSE_CHAR_PTR) ||
45 (aType == VTK_PARSE_STRING) ||
46 (aType == VTK_PARSE_STRING_REF))
47 {
48 fprintf(fp,"String ");
49 }
50 else
51 {
52 switch ((aType & VTK_PARSE_BASE_TYPE) & ~VTK_PARSE_UNSIGNED)
53 {
54 case VTK_PARSE_FLOAT: fprintf(fp,"double "); break;
55 case VTK_PARSE_DOUBLE: fprintf(fp,"double "); break;
56 case VTK_PARSE_INT: fprintf(fp,"int "); break;
57 case VTK_PARSE_SHORT: fprintf(fp,"int "); break;
58 case VTK_PARSE_LONG: fprintf(fp,"int "); break;
59 case VTK_PARSE_ID_TYPE: fprintf(fp,"int "); break;
60 case VTK_PARSE_LONG_LONG: fprintf(fp,"int "); break;
61 case VTK_PARSE___INT64: fprintf(fp,"int "); break;
62 case VTK_PARSE_VOID: fprintf(fp,"void "); break;
63 case VTK_PARSE_SIGNED_CHAR: fprintf(fp,"char "); break;
64 case VTK_PARSE_CHAR: fprintf(fp,"char "); break;
65 case VTK_PARSE_OBJECT: fprintf(fp,"%s ",currentFunction->ArgClasses[i]); break;
66 case VTK_PARSE_UNKNOWN: return;
67 }
68 }
69
70 fprintf(fp,"id%i",i);
71 if (((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER) &&
72 (aType != VTK_PARSE_CHAR_PTR) &&
73 (aType != VTK_PARSE_OBJECT_PTR))
74 {
75 fprintf(fp,"[]");
76 }
77 }
78
return_result(FILE * fp)79 void return_result(FILE *fp)
80 {
81 switch (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE)
82 {
83 case VTK_PARSE_FLOAT:
84 fprintf(fp,"double ");
85 break;
86 case VTK_PARSE_VOID:
87 fprintf(fp,"void ");
88 break;
89 case VTK_PARSE_CHAR:
90 fprintf(fp,"char ");
91 break;
92 case VTK_PARSE_DOUBLE:
93 fprintf(fp,"double ");
94 break;
95 case VTK_PARSE_INT:
96 case VTK_PARSE_SHORT:
97 case VTK_PARSE_LONG:
98 case VTK_PARSE_ID_TYPE:
99 case VTK_PARSE_LONG_LONG:
100 case VTK_PARSE___INT64:
101 case VTK_PARSE_UNSIGNED_CHAR:
102 case VTK_PARSE_UNSIGNED_INT:
103 case VTK_PARSE_UNSIGNED_SHORT:
104 case VTK_PARSE_UNSIGNED_LONG:
105 case VTK_PARSE_UNSIGNED_ID_TYPE:
106 case VTK_PARSE_UNSIGNED_LONG_LONG:
107 case VTK_PARSE_UNSIGNED___INT64:
108 fprintf(fp,"int ");
109 break;
110 case VTK_PARSE_CHAR_PTR:
111 case VTK_PARSE_STRING:
112 case VTK_PARSE_STRING_REF:
113 fprintf(fp,"String ");
114 break;
115 case VTK_PARSE_OBJECT_PTR:
116 fprintf(fp,"%s ",currentFunction->ReturnClass);
117 break;
118
119 /* handle functions returning vectors */
120 /* this is done by looking them up in a hint file */
121 case VTK_PARSE_FLOAT_PTR:
122 case VTK_PARSE_DOUBLE_PTR:
123 fprintf(fp,"double[] ");
124 break;
125 case VTK_PARSE_INT_PTR:
126 case VTK_PARSE_SHORT_PTR:
127 case VTK_PARSE_LONG_PTR:
128 case VTK_PARSE_ID_TYPE_PTR:
129 case VTK_PARSE_LONG_LONG_PTR:
130 case VTK_PARSE___INT64_PTR:
131 case VTK_PARSE_SIGNED_CHAR_PTR:
132 case VTK_PARSE_UNSIGNED_CHAR_PTR:
133 case VTK_PARSE_UNSIGNED_INT_PTR:
134 case VTK_PARSE_UNSIGNED_SHORT_PTR:
135 case VTK_PARSE_UNSIGNED_LONG_PTR:
136 case VTK_PARSE_UNSIGNED_ID_TYPE_PTR:
137 case VTK_PARSE_UNSIGNED_LONG_LONG_PTR:
138 case VTK_PARSE_UNSIGNED___INT64_PTR:
139 fprintf(fp,"int[] "); break;
140 }
141 }
142
143 /* Check to see if two types will map to the same Java type,
144 * return 1 if type1 should take precedence,
145 * return 2 if type2 should take precedence,
146 * return 0 if the types do not map to the same type */
CheckMatch(unsigned int type1,unsigned int type2,const char * c1,const char * c2)147 static int CheckMatch(
148 unsigned int type1, unsigned int type2, const char *c1, const char *c2)
149 {
150 static unsigned int floatTypes[] = {
151 VTK_PARSE_DOUBLE, VTK_PARSE_FLOAT, 0 };
152
153 static unsigned int intTypes[] = {
154 VTK_PARSE_UNSIGNED_LONG_LONG, VTK_PARSE_UNSIGNED___INT64,
155 VTK_PARSE_LONG_LONG, VTK_PARSE___INT64, VTK_PARSE_ID_TYPE,
156 VTK_PARSE_UNSIGNED_LONG, VTK_PARSE_LONG,
157 VTK_PARSE_UNSIGNED_INT, VTK_PARSE_INT,
158 VTK_PARSE_UNSIGNED_SHORT, VTK_PARSE_SHORT,
159 VTK_PARSE_UNSIGNED_CHAR, VTK_PARSE_SIGNED_CHAR, 0 };
160
161 static unsigned int stringTypes[] = {
162 VTK_PARSE_CHAR_PTR, VTK_PARSE_STRING_REF, VTK_PARSE_STRING, 0 };
163
164 static unsigned int *numericTypes[] = { floatTypes, intTypes, 0 };
165
166 int i, j;
167 int hit1, hit2;
168
169 if ((type1 & VTK_PARSE_UNQUALIFIED_TYPE) ==
170 (type2 & VTK_PARSE_UNQUALIFIED_TYPE))
171 {
172 if ((type1 & VTK_PARSE_BASE_TYPE) == VTK_PARSE_OBJECT)
173 {
174 if (strcmp(c1, c2) == 0)
175 {
176 return 1;
177 }
178 return 0;
179 }
180 else
181 {
182 return 1;
183 }
184 }
185
186 for (i = 0; numericTypes[i]; i++)
187 {
188 hit1 = 0;
189 hit2 = 0;
190 for (j = 0; numericTypes[i][j]; j++)
191 {
192 if ((type1 & VTK_PARSE_BASE_TYPE) == numericTypes[i][j])
193 {
194 hit1 = j+1;
195 }
196 if ((type2 & VTK_PARSE_BASE_TYPE) == numericTypes[i][j])
197 {
198 hit2 = j+1;
199 }
200 }
201 if (hit1 && hit2 &&
202 (type1 & VTK_PARSE_INDIRECT) == (type2 & VTK_PARSE_INDIRECT))
203 {
204 if (hit1 < hit2)
205 {
206 return 1;
207 }
208 else
209 {
210 return 2;
211 }
212 }
213 }
214
215 hit1 = 0;
216 hit2 = 0;
217 for (j = 0; stringTypes[j]; j++)
218 {
219 if ((type1 & VTK_PARSE_UNQUALIFIED_TYPE) == stringTypes[j])
220 {
221 hit1 = j+1;
222 }
223 if ((type2 & VTK_PARSE_UNQUALIFIED_TYPE) == stringTypes[j])
224 {
225 hit2 = j+1;
226 }
227 }
228 if (hit1 && hit2)
229 {
230 if (hit1 < hit2)
231 {
232 return 1;
233 }
234 else
235 {
236 return 2;
237 }
238 }
239
240 return 0;
241 }
242
243 /* have we done one of these yet */
DoneOne()244 int DoneOne()
245 {
246 int i,j;
247 int match;
248 FunctionInfo *fi;
249
250 for (i = 0; i < numberOfWrappedFunctions; i++)
251 {
252 fi = wrappedFunctions[i];
253
254 if ((!strcmp(fi->Name,currentFunction->Name))
255 &&(fi->NumberOfArguments == currentFunction->NumberOfArguments))
256 {
257 match = 1;
258 for (j = 0; j < fi->NumberOfArguments; j++)
259 {
260 if (!CheckMatch(currentFunction->ArgTypes[j], fi->ArgTypes[j],
261 currentFunction->ArgClasses[j],fi->ArgClasses[j]))
262 {
263 match = 0;
264 }
265 }
266 if (!CheckMatch(currentFunction->ReturnType, fi->ReturnType,
267 currentFunction->ReturnClass, fi->ReturnClass))
268 {
269 match = 0;
270 }
271 if (match) return 1;
272 }
273 }
274 return 0;
275 }
276
isClassWrapped(const char * classname)277 static int isClassWrapped(const char *classname)
278 {
279 HierarchyEntry *entry;
280
281 if (hierarchyInfo)
282 {
283 entry = vtkParseHierarchy_FindEntry(hierarchyInfo, classname);
284
285 if (entry == 0 ||
286 vtkParseHierarchy_GetProperty(entry, "WRAP_EXCLUDE_PYTHON") ||
287 !vtkParseHierarchy_IsTypeOf(hierarchyInfo, entry, "vtkObjectBase"))
288 {
289 return 0;
290 }
291 }
292
293 return 1;
294 }
295
checkFunctionSignature(ClassInfo * data)296 int checkFunctionSignature(ClassInfo *data)
297 {
298 static unsigned int supported_types[] = {
299 VTK_PARSE_VOID, VTK_PARSE_BOOL, VTK_PARSE_FLOAT, VTK_PARSE_DOUBLE,
300 VTK_PARSE_CHAR, VTK_PARSE_UNSIGNED_CHAR, VTK_PARSE_SIGNED_CHAR,
301 VTK_PARSE_INT, VTK_PARSE_UNSIGNED_INT,
302 VTK_PARSE_SHORT, VTK_PARSE_UNSIGNED_SHORT,
303 VTK_PARSE_LONG, VTK_PARSE_UNSIGNED_LONG,
304 VTK_PARSE_ID_TYPE, VTK_PARSE_UNSIGNED_ID_TYPE,
305 VTK_PARSE_LONG_LONG, VTK_PARSE_UNSIGNED_LONG_LONG,
306 VTK_PARSE___INT64, VTK_PARSE_UNSIGNED___INT64,
307 VTK_PARSE_OBJECT, VTK_PARSE_STRING,
308 0
309 };
310
311 int i, j;
312 int args_ok = 1;
313 unsigned int rType =
314 (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE);
315 unsigned int aType = 0;
316 unsigned int baseType = 0;
317
318 /* some functions will not get wrapped no matter what else */
319 if (currentFunction->IsOperator ||
320 currentFunction->ArrayFailure ||
321 !currentFunction->IsPublic ||
322 !currentFunction->Name)
323 {
324 return 0;
325 }
326
327 /* NewInstance and SafeDownCast can not be wrapped because it is a
328 (non-virtual) method which returns a pointer of the same type as
329 the current pointer. Since all methods are virtual in Java, this
330 looks like polymorphic return type. */
331 if (!strcmp("NewInstance",currentFunction->Name))
332 {
333 return 0;
334 }
335
336 if (!strcmp("SafeDownCast",currentFunction->Name))
337 {
338 return 0;
339 }
340
341 /* The GetInput() in vtkMapper cannot be overridden with a
342 * different return type, Java doesn't allow this */
343 if (strcmp(data->Name, "vtkMapper") == 0 &&
344 strcmp(currentFunction->Name, "GetInput") == 0)
345 {
346 return 0;
347 }
348
349 /* function pointer arguments for callbacks */
350 if (currentFunction->NumberOfArguments == 2 &&
351 currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION &&
352 currentFunction->ArgTypes[1] == VTK_PARSE_VOID_PTR &&
353 rType == VTK_PARSE_VOID)
354 {
355 return 1;
356 }
357
358 /* check to see if we can handle the args */
359 for (i = 0; i < currentFunction->NumberOfArguments; i++)
360 {
361 aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE);
362 baseType = (aType & VTK_PARSE_BASE_TYPE);
363
364 for (j = 0; supported_types[j] != 0; j++)
365 {
366 if (baseType == supported_types[j]) { break; }
367 }
368 if (supported_types[j] == 0)
369 {
370 args_ok = 0;
371 }
372
373 if (baseType == VTK_PARSE_OBJECT)
374 {
375 if ((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
376 {
377 args_ok = 0;
378 }
379 else if (!isClassWrapped(currentFunction->ArgClasses[i]))
380 {
381 args_ok = 0;
382 }
383 }
384
385 if (aType == VTK_PARSE_OBJECT) args_ok = 0;
386 if (((aType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) &&
387 ((aType & VTK_PARSE_INDIRECT) != 0) &&
388 (aType != VTK_PARSE_STRING_REF)) args_ok = 0;
389 if (aType == VTK_PARSE_STRING_PTR) args_ok = 0;
390 if (aType == VTK_PARSE_UNSIGNED_CHAR_PTR) args_ok = 0;
391 if (aType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0;
392 if (aType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0;
393 if (aType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0;
394 if (aType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
395 if (aType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
396 if (aType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
397 }
398
399 baseType = (rType & VTK_PARSE_BASE_TYPE);
400
401 for (j = 0; supported_types[j] != 0; j++)
402 {
403 if (baseType == supported_types[j]) { break; }
404 }
405 if (supported_types[j] == 0)
406 {
407 args_ok = 0;
408 }
409
410 if (baseType == VTK_PARSE_OBJECT)
411 {
412 if ((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER)
413 {
414 args_ok = 0;
415 }
416 else if (!isClassWrapped(currentFunction->ReturnClass))
417 {
418 args_ok = 0;
419 }
420 }
421
422 if (((rType & VTK_PARSE_INDIRECT) != VTK_PARSE_POINTER) &&
423 ((rType & VTK_PARSE_INDIRECT) != 0) &&
424 (rType != VTK_PARSE_STRING_REF)) args_ok = 0;
425 if (rType == VTK_PARSE_STRING_PTR) args_ok = 0;
426
427 /* eliminate unsigned char * and unsigned short * */
428 if (rType == VTK_PARSE_UNSIGNED_INT_PTR) args_ok = 0;
429 if (rType == VTK_PARSE_UNSIGNED_SHORT_PTR) args_ok = 0;
430 if (rType == VTK_PARSE_UNSIGNED_LONG_PTR) args_ok = 0;
431 if (rType == VTK_PARSE_UNSIGNED_ID_TYPE_PTR) args_ok = 0;
432 if (rType == VTK_PARSE_UNSIGNED_LONG_LONG_PTR) args_ok = 0;
433 if (rType == VTK_PARSE_UNSIGNED___INT64_PTR) args_ok = 0;
434
435 /* make sure we have all the info we need for array arguments in */
436 for (i = 0; i < currentFunction->NumberOfArguments; i++)
437 {
438 aType = (currentFunction->ArgTypes[i] & VTK_PARSE_UNQUALIFIED_TYPE);
439
440 if (((aType & VTK_PARSE_INDIRECT) == VTK_PARSE_POINTER)&&
441 (currentFunction->ArgCounts[i] <= 0)&&
442 (aType != VTK_PARSE_OBJECT_PTR)&&
443 (aType != VTK_PARSE_CHAR_PTR)) args_ok = 0;
444 }
445
446 /* if we need a return type hint make sure we have one */
447 switch (rType)
448 {
449 case VTK_PARSE_FLOAT_PTR:
450 case VTK_PARSE_VOID_PTR:
451 case VTK_PARSE_DOUBLE_PTR:
452 case VTK_PARSE_INT_PTR:
453 case VTK_PARSE_SHORT_PTR:
454 case VTK_PARSE_LONG_PTR:
455 case VTK_PARSE_ID_TYPE_PTR:
456 case VTK_PARSE_LONG_LONG_PTR:
457 case VTK_PARSE___INT64_PTR:
458 case VTK_PARSE_SIGNED_CHAR_PTR:
459 case VTK_PARSE_BOOL_PTR:
460 case VTK_PARSE_UNSIGNED_CHAR_PTR:
461 args_ok = currentFunction->HaveHint;
462 break;
463 }
464
465 /* make sure there isn't a Java-specific override */
466 if (!strcmp("vtkObject",data->Name))
467 {
468 /* remove the original vtkCommand observer methods */
469 if (!strcmp(currentFunction->Name,"AddObserver") ||
470 !strcmp(currentFunction->Name,"GetCommand") ||
471 (!strcmp(currentFunction->Name,"RemoveObserver") &&
472 (currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG)) ||
473 ((!strcmp(currentFunction->Name,"RemoveObservers") ||
474 !strcmp(currentFunction->Name,"HasObserver")) &&
475 (((currentFunction->ArgTypes[0] != VTK_PARSE_UNSIGNED_LONG) &&
476 (currentFunction->ArgTypes[0] !=
477 (VTK_PARSE_CHAR_PTR|VTK_PARSE_CONST))) ||
478 (currentFunction->NumberOfArguments > 1))) ||
479 (!strcmp(currentFunction->Name,"RemoveAllObservers") &&
480 (currentFunction->NumberOfArguments > 0)))
481 {
482 args_ok = 0;
483 }
484 }
485 else if (!strcmp("vtkObjectBase",data->Name))
486 {
487 /* remove the special vtkObjectBase methods */
488 if (!strcmp(currentFunction->Name,"Print"))
489 {
490 args_ok = 0;
491 }
492 }
493
494 /* make sure it isn't a Delete or New function */
495 if (!strcmp("Delete",currentFunction->Name) ||
496 !strcmp("New",currentFunction->Name))
497 {
498 args_ok = 0;
499 }
500
501 return args_ok;
502 }
503
outputFunction(FILE * fp,ClassInfo * data)504 void outputFunction(FILE *fp, ClassInfo *data)
505 {
506 unsigned int rType =
507 (currentFunction->ReturnType & VTK_PARSE_UNQUALIFIED_TYPE);
508 unsigned int aType = 0;
509 int i;
510 /* beans */
511 char *beanfunc;
512
513 /* make the first letter lowercase for set get methods */
514 beanfunc = strdup(currentFunction->Name);
515 if (isupper(beanfunc[0])) beanfunc[0] = beanfunc[0] + 32;
516
517 args_ok = checkFunctionSignature(data);
518
519 if (currentFunction->IsPublic && args_ok &&
520 strcmp(data->Name,currentFunction->Name) &&
521 strcmp(data->Name, currentFunction->Name + 1))
522 {
523 /* make sure we haven't already done one of these */
524 if (!DoneOne())
525 {
526 fprintf(fp,"\n private native ");
527 return_result(fp);
528 fprintf(fp,"%s_%i(",currentFunction->Name,numberOfWrappedFunctions);
529
530 for (i = 0; i < currentFunction->NumberOfArguments; i++)
531 {
532 if (i)
533 {
534 fprintf(fp,",");
535 }
536 output_temp(fp,i);
537
538 /* ignore args after function pointer */
539 if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION)
540 {
541 break;
542 }
543 }
544 fprintf(fp,");\n");
545 fprintf(fp," public ");
546 return_result(fp);
547 fprintf(fp,"%s(",beanfunc);
548
549 for (i = 0; i < currentFunction->NumberOfArguments; i++)
550 {
551 if (i)
552 {
553 fprintf(fp,",");
554 }
555 output_temp(fp,i);
556
557 /* ignore args after function pointer */
558 if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION)
559 {
560 break;
561 }
562 }
563 /* if not void then need return otherwise none */
564 if (rType == VTK_PARSE_VOID)
565 {
566 fprintf(fp,")\n { %s_%i(",currentFunction->Name,
567 numberOfWrappedFunctions);
568 }
569 else
570 {
571 fprintf(fp,")\n { return %s_%i(",currentFunction->Name,
572 numberOfWrappedFunctions);
573 }
574 for (i = 0; i < currentFunction->NumberOfArguments; i++)
575 {
576 if (i)
577 {
578 fprintf(fp,",");
579 }
580 fprintf(fp,"id%i",i);
581
582 /* ignore args after function pointer */
583 if (currentFunction->ArgTypes[i] == VTK_PARSE_FUNCTION)
584 {
585 break;
586 }
587 }
588 if ((currentFunction->NumberOfArguments == 1) &&
589 (currentFunction->ArgTypes[0] == VTK_PARSE_FUNCTION)) fprintf(fp,",id1");
590
591 /* stick in secret beanie code for set methods */
592 if (rType == VTK_PARSE_VOID)
593 {
594 aType = (currentFunction->ArgTypes[0] & VTK_PARSE_UNQUALIFIED_TYPE);
595
596 /* only care about set methods and On/Off methods */
597 if (!strncmp(beanfunc,"set",3) &&
598 currentFunction->NumberOfArguments == 1 &&
599 (((aType & VTK_PARSE_INDIRECT) == 0 &&
600 (aType & VTK_PARSE_UNSIGNED) == 0)||
601 aType == VTK_PARSE_CHAR_PTR ||
602 (aType & VTK_PARSE_BASE_TYPE) == VTK_PARSE_OBJECT))
603 {
604 char prop[256];
605
606 strncpy(prop,beanfunc+3,strlen(beanfunc)-3);
607 prop[strlen(beanfunc)-3] = '\0';
608 if (isupper(prop[0])) prop[0] = prop[0] + 32;
609 fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,",prop);
610
611 /* handle basic types */
612 if ((aType == VTK_PARSE_CHAR_PTR) ||
613 (aType == VTK_PARSE_STRING) ||
614 (aType == VTK_PARSE_STRING_REF))
615 {
616 fprintf(fp," id0");
617 }
618 else
619 {
620 switch ((aType & VTK_PARSE_BASE_TYPE) & ~VTK_PARSE_UNSIGNED)
621 {
622 case VTK_PARSE_FLOAT:
623 case VTK_PARSE_DOUBLE: fprintf(fp," new Double(id0)"); break;
624 case VTK_PARSE_INT:
625 case VTK_PARSE_SHORT:
626 case VTK_PARSE_LONG: fprintf(fp," new Integer(id0)"); break;
627 case VTK_PARSE_OBJECT: fprintf(fp," id0"); break;
628 case VTK_PARSE_CHAR: /* not implemented yet */
629 default: fprintf(fp," null");
630 }
631 }
632 }
633 /* not a set method is it an On/Off method ? */
634 else
635 {
636 if (!strncmp(beanfunc + strlen(beanfunc) - 2, "On",2))
637 {
638 /* OK we think this is a Boolean method so need to fire a change */
639 char prop[256];
640 strncpy(prop,beanfunc,strlen(beanfunc)-2);
641 prop[strlen(beanfunc)-2] = '\0';
642 fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(1)",
643 prop);
644 }
645 if (!strncmp(beanfunc + strlen(beanfunc) - 3, "Off",3))
646 {
647 /* OK we think this is a Boolean method so need to fire a change */
648 char prop[256];
649 strncpy(prop,beanfunc,strlen(beanfunc)-3);
650 prop[strlen(beanfunc)-3] = '\0';
651 fprintf(fp,");\n changes.firePropertyChange(\"%s\",null,new Integer(0)",
652 prop);
653 }
654 }
655 }
656 fprintf(fp,"); }\n");
657
658 wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
659 numberOfWrappedFunctions++;
660 }
661 }
662 free(beanfunc);
663 }
664
665 /* print the parsed structures */
vtkParseOutput(FILE * fp,FileInfo * file_info)666 void vtkParseOutput(FILE *fp, FileInfo *file_info)
667 {
668 OptionInfo *options;
669 ClassInfo *data;
670 int i;
671
672 if ((data = file_info->MainClass) == NULL)
673 {
674 return;
675 }
676
677 /* get the command-line options */
678 options = vtkParse_GetCommandLineOptions();
679
680 /* get the hierarchy info for accurate typing */
681 if (options->HierarchyFileNames)
682 {
683 hierarchyInfo = vtkParseHierarchy_ReadFiles(
684 options->NumberOfHierarchyFileNames, options->HierarchyFileNames);
685 }
686
687 fprintf(fp,"// java wrapper for %s object\n//\n",data->Name);
688 fprintf(fp,"\npackage vtk;\n");
689
690 /* beans */
691 if (!data->NumberOfSuperClasses)
692 {
693 fprintf(fp,"import java.beans.*;\n");
694 }
695
696 if (strcmp("vtkObject",data->Name))
697 {
698 fprintf(fp,"import vtk.*;\n");
699 }
700 fprintf(fp,"\npublic class %s",data->Name);
701 if (strcmp("vtkObject",data->Name))
702 {
703 if (data->NumberOfSuperClasses)
704 fprintf(fp," extends %s",data->SuperClasses[0]);
705 }
706 fprintf(fp,"\n{\n");
707
708 fprintf(fp," public %s getThis%s() { return this;}\n\n",
709 data->Name, data->Name+3);
710
711 /* insert function handling code here */
712 for (i = 0; i < data->NumberOfFunctions; i++)
713 {
714 currentFunction = data->Functions[i];
715 outputFunction(fp, data);
716 }
717
718 if (!data->NumberOfSuperClasses)
719 {
720 fprintf(fp,"\n public %s() { this.VTKInit();};\n",data->Name);
721 fprintf(fp," protected int vtkId = 0;\n");
722
723 /* beans */
724 fprintf(fp," public void addPropertyChangeListener(PropertyChangeListener l)\n {\n");
725 fprintf(fp," changes.addPropertyChangeListener(l);\n }\n");
726 fprintf(fp," public void removePropertyChangeListener(PropertyChangeListener l)\n {\n");
727 fprintf(fp," changes.removePropertyChangeListener(l);\n }\n");
728 fprintf(fp," protected PropertyChangeSupport changes = new PropertyChangeSupport(this);\n\n");
729
730 /* if we are a base class and have a delete method */
731 if (data->HasDelete)
732 {
733 fprintf(fp,"\n public native void VTKDelete();\n");
734 fprintf(fp," protected void finalize() { this.VTKDelete();};\n");
735 }
736 }
737 if ((!data->IsAbstract)&&
738 strcmp(data->Name,"vtkDataWriter") &&
739 strcmp(data->Name,"vtkPointSet") &&
740 strcmp(data->Name,"vtkDataSetSource")
741 )
742 {
743 fprintf(fp," public native void VTKInit();\n");
744 }
745 if (!strcmp("vtkObject",data->Name))
746 {
747 fprintf(fp," public native String Print();\n");
748 }
749 fprintf(fp,"}\n");
750 }
751