Salome HOME
Merge from BR_PARAVIS_DEV 29Dec09
[modules/paravis.git] / idl / vtkWrapIDL.c
1 // PARAVIS : ParaView wrapper SALOME module
2 //
3 // Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : vtkWrapIDL.c
23 // Author : Vladimir TURIN
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <ctype.h>
29 #include "vtkParse.h"
30 #include "vtkWrapIDL.h"
31
32 char* Copyright[] = {
33   "// Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,",
34   "// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS",
35   "//",
36   "// This library is free software; you can redistribute it and/or",
37   "// modify it under the terms of the GNU Lesser General Public",
38   "// License as published by the Free Software Foundation; either",
39   "// version 2.1 of the License.",
40   "//",
41   "// This library is distributed in the hope that it will be useful,",
42   "// but WITHOUT ANY WARRANTY; without even the implied warranty of",
43   "// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU",
44   "// Lesser General Public License for more details.",
45   "//",
46   "// You should have received a copy of the GNU Lesser General Public",
47   "// License along with this library; if not, write to the Free Software",
48   "// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA",
49   "//",
50   "// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com",
51   ""
52 };
53
54 #define bs 8192
55
56 int numberOfWrappedFunctions = 0;
57 FunctionInfo *wrappedFunctions[1000];
58 extern FunctionInfo *currentFunction;
59
60 static void add_to_sig(char *sig, const char *add, int *i)
61 {
62   strcpy(&sig[*i],add);
63   *i += (int)strlen(add);
64 }
65
66 int IsReturnArg(int I) {
67   return (I == MAX_ARGS);
68 }
69
70 void AddReturnArg(char *Result, int *CurrPos) {
71   add_to_sig(Result,"virtual ",CurrPos);
72 }
73
74 void AddNotReturnArg(int Type, char *Result, int *CurrPos) {
75 #if defined(IDL_I_HH) || defined(IDL_I_CC)
76   ;
77 #else
78   if(IsIn(Type))
79     add_to_sig(Result,"in ",CurrPos);
80   else
81     add_to_sig(Result,"inout ",CurrPos);
82 #endif
83 }
84
85 int IsFunction(int Type) {
86   return (Type == 0x5000);
87 }
88
89 int IsConst(int Type) {
90   return ((Type % 0x2000) >= 0x1000);
91 }
92
93 void AddConst(char *Result, int *CurrPos) {
94 #if defined(IDL_I_HH) || defined(IDL_I_CC)
95   add_to_sig(Result,"const ",CurrPos);
96 #else
97   add_to_sig(Result,"in ",CurrPos);
98 #endif
99 }
100
101 int IsPtr(int Type) {
102   return ((Type % 0x1000)/0x100 == 0x1);
103 }
104
105 int IsIn(int Type) {
106   return 1;
107   //return ((Type % 0x1000)/0x100 < 1 || (Type % 0x1000)/0x100 > 7);
108 }
109
110 int IsUnknown(int Type) {
111   return ((Type % 0x1000)/0x100 == 0x8);
112 }
113
114 void AddAtomArg(int I, int Type, char *TypeIDL, char *TypeCorba, char *Result, int *CurrPos) {
115 #if defined(IDL_I_HH) || defined(IDL_I_CC)
116   add_to_sig(Result,"CORBA::",CurrPos);
117   add_to_sig(Result,TypeCorba,CurrPos);
118
119   if (!IsReturnArg(I) && !IsConst(Type) && !IsIn(Type))
120     add_to_sig(Result,"&",CurrPos);
121 #else
122   add_to_sig(Result,TypeIDL,CurrPos);
123 #endif
124   add_to_sig(Result," ",CurrPos);
125 }
126
127 int IsArray(int Type) {
128   return ((Type % 0x1000)/0x100 == 0x3);
129 }
130
131 void AddArrayArg(int I, int Type, char *TypeIDL, char *Result, int *CurrPos) {
132 #if defined(IDL_I_HH) || defined(IDL_I_CC)
133   if(!IsReturnArg(I) && !IsConst(Type))
134     add_to_sig(Result, "const ",CurrPos);
135 #endif
136   add_to_sig(Result, TypeIDL,CurrPos);
137   add_to_sig(Result, "_array",CurrPos);
138 #if defined(IDL_I_HH) || defined(IDL_I_CC)
139   if(IsReturnArg(I)) {
140     add_to_sig(Result, "*",CurrPos);
141   } else {
142     add_to_sig(Result, "&",CurrPos);
143   }
144 #else
145 #endif
146   add_to_sig(Result, " ",CurrPos);
147 }
148
149 int IsBoolean(int Type) {
150   return ((Type % 0x10) == 0xE);
151 }
152
153 void AddBooleanAtomArg(int I, int Type, char *Result, int *CurrPos) {
154   AddAtomArg(I,Type,"boolean","Boolean",Result,CurrPos);
155 }
156
157 int IsChar(int Type) {
158   return ((Type % 0x10) == 0x3 || (Type % 0x10) == 0xD);
159 }
160
161 void AddCharAtomArg(int I, int Type, char *Result, int *CurrPos) {
162   AddAtomArg(I,Type,"char","Char",Result,CurrPos);
163 }
164
165 int IsString(Type) {
166   return (IsChar(Type) && IsArray(Type));
167 }
168
169 void AddStringArg(int I, char *Result, int *CurrPos) {
170 #if defined(IDL_I_HH) || defined(IDL_I_CC)
171   add_to_sig(Result,"char ",CurrPos);
172 #else
173   add_to_sig(Result,"string ",CurrPos);
174 #endif
175 }
176
177 int IsFloat(int Type) {
178   return ((Type % 0x10) == 0x1);
179 }
180
181 void AddFloatAtomArg(int I, int Type, char *Result, int *CurrPos) {
182   AddAtomArg(I,Type,"float","Float",Result,CurrPos);
183 }
184
185 int IsFloatArray(int Type) {
186   return (IsFloat(Type) && IsArray(Type));
187 }
188
189 void AddFloatArrayArg(int I, int Type, char *Result, int *CurrPos) {
190   AddArrayArg(I,Type,"float",Result,CurrPos);
191 }
192
193 int IsDouble(int Type) {
194   return ((Type % 0x10) == 0x7);
195 }
196
197 void AddDoubleAtomArg(int I, int Type, char *Result, int *CurrPos) {
198   AddAtomArg(I,Type,"double","Double",Result,CurrPos);
199 }
200
201 int IsDoubleArray(int Type) {
202   return (IsDouble(Type) && IsArray(Type));
203 }
204
205 void AddDoubleArrayArg(int I, int Type, char *Result, int *CurrPos) {
206   AddArrayArg(I,Type,"double",Result,CurrPos);
207 }
208
209 int IsvtkIdType(int Type) {
210   return((Type % 0x10) == 0xA);
211 }
212
213 int IsShort(int Type) {
214   return ((Type % 0x10) == 0x4 || (Type % 0x10) == 0x5 || (Type % 0x10) == 0xA);
215 }
216
217 void AddShortAtomArg(int I, int Type, char *Result, int *CurrPos) {
218   AddAtomArg(I,Type,"short","Short",Result,CurrPos);
219 }
220
221 int IsShortArray(int Type) {
222   return (IsShort(Type) && IsArray(Type));
223 }
224
225 void AddShortArrayArg(int I, int Type, char *Result, int *CurrPos) {
226   AddArrayArg(I,Type,"short",Result,CurrPos);
227 }
228
229 int IsLong(int Type) {
230   return ((Type % 0x10) == 0x6 || (Type % 0x10) == 0xB || (Type % 0x10) == 0xC);
231 }
232
233 void AddLongAtomArg(int I, int Type, char *Result, int *CurrPos) {
234   AddAtomArg(I,Type,"long","Long",Result,CurrPos);
235 }
236
237 int IsLongArray(int Type) {
238   return (IsLong(Type) && IsArray(Type));
239 }
240
241 void AddLongArrayArg(int I, int Type, char *Result, int *CurrPos) {
242   AddArrayArg(I,Type,"long",Result,CurrPos);
243 }
244
245 int IsClass(int Type) {
246   return ((Type % 0x10) == 0x9);
247 }
248
249 void AddClassArg(int I, int Type, char *Class, char *Result, int *CurrPos) {
250 #if defined(IDL_I_HH) || defined(IDL_I_CC)
251   add_to_sig(Result,"PARAVIS_Base",CurrPos);
252   if(IsReturnArg(I) || IsConst(Type) || IsIn(Type)) {
253     add_to_sig(Result,"_ptr",CurrPos);
254   } else {
255     add_to_sig(Result,"_ptr&",CurrPos);
256   }
257   add_to_sig(Result," ",CurrPos);
258 #else
259   add_to_sig(Result,"PARAVIS_Base ",CurrPos);
260 #endif
261 }
262
263 int _IsVoid(int Type) {
264   return ((Type % 0x10) == 0x2);
265 }
266
267 int IsVoid(int Type) {
268   return (_IsVoid(Type) && (!IsPtr(Type)));
269 }
270
271 void AddVoid(char *Result, int *CurrPos) {
272   add_to_sig(Result,"void ",CurrPos);
273 }
274
275 int IsVoidPtr(int Type) {
276   return (_IsVoid(Type) && (IsPtr(Type) || IsArray(Type)));
277 }
278
279 void AddVoidArg(int I, char *Result, int *CurrPos, int Type) {
280 #if defined(IDL_I_HH) || defined(IDL_I_CC)
281   if(!IsReturnArg(I)) {
282     if(!IsConst(Type))
283       add_to_sig(Result,"const ",CurrPos);
284     add_to_sig(Result,"CORBA::Any& ",CurrPos);
285   } else {
286     add_to_sig(Result,"CORBA::Any ",CurrPos);
287   }
288 #else
289   add_to_sig(Result,"any ",CurrPos);
290 #endif
291 }
292
293 void AddTypeArray(int Type, char *Result, int *CurrPos) {
294   if(IsShort(Type))
295     add_to_sig(Result,"short",CurrPos);
296   if(IsLong(Type))
297     add_to_sig(Result,"long",CurrPos);
298   if(IsFloat(Type))
299     add_to_sig(Result,"float",CurrPos);
300   if(IsDouble(Type))
301     add_to_sig(Result,"double",CurrPos);
302   add_to_sig(Result,"_array",CurrPos);
303 }
304
305 typedef struct _ReadFuncs
306 {
307   char* Name;
308   char* Signature;
309   int   EndPos;
310   int   NumPos;
311 } ReadFuncs;
312
313 ReadFuncs readFunctions[1000];
314 int numberOfReadFunctions = 0;
315
316 static int class_has_new = 0;
317
318 void output_type(char* result, int *currPos, int i, int aType, char *Id)
319 {
320   if(IsFloat(aType)) {
321     if(IsArray(aType)) {
322       add_to_sig(result,"float",currPos);
323     } else {
324       add_to_sig(result,"CORBA::Float",currPos);
325     }
326   }
327   
328   if(IsDouble(aType)) {
329     if(IsArray(aType)) {
330       add_to_sig(result,"double",currPos);
331     } else {
332       add_to_sig(result,"CORBA::Double",currPos);
333     }
334   }
335   
336   if(IsShort(aType)) {
337     if(IsArray(aType)) {
338       if(IsvtkIdType(aType)) {
339         add_to_sig(result,"vtkIdType",currPos);
340       } else {
341         add_to_sig(result,"int",currPos);
342       }
343     } else {
344       add_to_sig(result,"CORBA::Short",currPos);
345     }
346   }
347   
348   if(IsLong(aType)) {
349     if(IsArray(aType)) {
350       add_to_sig(result,"long",currPos);
351     } else {
352       add_to_sig(result,"CORBA::Long",currPos);
353     }
354   }
355   
356   if(IsChar(aType)) {
357     if(IsString(aType)) {
358       if(IsReturnArg(i))
359         add_to_sig(result,"const ",currPos);
360       add_to_sig(result,"char",currPos);
361     } else {
362       add_to_sig(result,"CORBA::Char",currPos);     
363     }
364   }
365
366   if(IsBoolean(aType)) {
367     add_to_sig(result,"CORBA::Boolean",currPos);
368   }
369   
370   if(IsVoidPtr(aType)) {
371     add_to_sig(result,"void",currPos);
372   }
373   
374   if(IsClass(aType)) {
375     add_to_sig(result,"::",currPos);
376     add_to_sig(result,Id,currPos);
377   }
378   
379   if(IsArray(aType) || IsPtr(aType) || IsClass(aType) || IsString(aType)) {
380     add_to_sig(result,"*",currPos);
381   }
382 }
383
384 void output_typedef(char* result, int *currPos, int i, int aType, char *Id)
385 {
386   add_to_sig(result,"  typedef ",currPos);
387   output_type(result,currPos,i,aType,Id);
388 }
389
390 void output_temp(char* result, int *currPos, int i, int aType, char *Id, int aCount)
391 {
392   static char buf[bs];
393
394   /* handle VAR FUNCTIONS */
395   if (IsFunction(aType)) {
396     return;
397   }
398
399 #if defined(IDL_I_HH)
400   if(IsReturnArg(i)) {
401     AddReturnArg(result,currPos);
402   }
403 #endif
404
405   if (IsReturnArg(i) && IsVoid(aType) && !IsVoidPtr(aType)) {
406     AddVoid(result,currPos);
407     return;
408   }
409
410   /* for const * return types prototype with const */
411   if ( IsConst(aType) || IsString(aType)) {
412     if(!IsReturnArg(i)) {
413       AddConst(result,currPos);
414     }
415   } else {
416     if(!IsReturnArg(i)) {
417       AddNotReturnArg(aType,result,currPos);
418     }
419   }
420
421   if(IsFloat(aType)) {
422     if(IsFloatArray(aType)) {
423       AddFloatArrayArg(i,aType,result,currPos);
424     } else {
425       AddFloatAtomArg(i,aType,result,currPos);
426     }
427   }
428   
429   if(IsDouble(aType)) {
430     if(IsDoubleArray(aType)) {
431       AddDoubleArrayArg(i,aType,result,currPos);
432     } else {
433       AddDoubleAtomArg(i,aType,result,currPos);
434     }
435   }
436
437   if(IsShort(aType)) {
438     if(IsShortArray(aType)) {
439       AddShortArrayArg(i,aType,result,currPos);
440     } else {
441       AddShortAtomArg(i,aType,result,currPos);
442     }
443   }
444
445   if(IsLong(aType)) {
446     if(IsLongArray(aType)) {
447       AddLongArrayArg(i,aType,result,currPos);
448     } else {
449       AddLongAtomArg(i,aType,result,currPos);
450     }
451   }
452
453   if(IsChar(aType)) {
454     if(IsString(aType)) {
455       AddStringArg(i,result,currPos);
456     } else {
457       AddCharAtomArg(i,aType,result,currPos);
458     }
459   }
460
461   if(IsBoolean(aType)) {
462     AddBooleanAtomArg(i,aType,result,currPos);
463   }
464
465   if(IsVoid(aType)) {
466     AddVoidArg(i,result,currPos,aType);
467   }
468
469   if(IsClass(aType)) {
470     AddClassArg(i,aType,Id,result,currPos);
471   }
472
473   if(IsUnknown(aType)) {
474     return;
475   }
476
477   if(!IsClass(aType)) {
478     if(IsPtr(aType)) {
479       add_to_sig(result," *",currPos);
480     }
481 #if defined(IDL_I_HH) || defined(IDL_I_CC)
482     if(IsString(aType) && !IsIn(aType) && !IsConst(aType) && !IsReturnArg(i)) {
483         add_to_sig(result,"*&",currPos);
484     } else {
485       if(IsString(aType) || (IsReturnArg(i) && IsVoidPtr(aType))) {
486         add_to_sig(result," *",currPos);
487       }
488     }
489 #endif
490   }
491
492   if(!IsReturnArg(i)) {
493     sprintf(buf,"temp%i",i);
494     add_to_sig(result,buf,currPos);
495   }
496   
497   return;
498 }
499
500 void read_class_functions(const char* name, const char* classname, FILE* fp)
501 {
502   int len=0;
503   int curlen=0;
504   int i;
505   int j;
506   int flen=0;
507   int num=0;
508   int ret_str=0;
509   FILE *fin;
510   char buf[bs];
511   char buf1[bs];
512   char fname[bs];
513   static char sig[bs];
514   static int slen=8;
515 #if ! defined(IDL_I_CC)
516   static int clen=15;
517 #else
518   static int clen=7;
519 #endif
520
521 #if defined(IDL_I_HH)
522   sprintf(buf,"PARAVIS_Gen_%s_i.hh",name);
523 #elif defined(IDL_I_CC)
524   sprintf(buf,"PARAVIS_Gen_%s_i.cc",name);
525 #else
526   sprintf(buf,"PARAVIS_Gen_%s.idl",name);
527 #endif
528   if (!(fin = fopen(buf,"r"))) {
529     fprintf(stderr,"Error opening input file %s\n",buf);
530     exit(1);
531   }
532   while (fgets(sig,bs-1,fin) != 0) {
533 #if defined(IDL_I_CC)
534     if(strncmp("#include \"PARAVIS_Gen_vtk",sig,25)==0) {
535       fprintf(fp,sig);
536     }
537     if(strncmp("#include <vtk",sig,13)==0) {
538       fprintf(fp,sig);
539     }
540 #endif
541
542 #if ! defined(IDL_I_CC)
543     if(strncmp("        //C++: ",sig,clen)==0) {
544 #else
545     if(strncmp("//C++: ",sig,clen)==0) {
546 #endif
547 #if defined(IDL_I_CC)
548       while(fgets(buf,bs-1,fin) != 0) {
549         len=strlen(sig);
550         strcpy(sig+len,buf);
551         if(strlen(buf) == 3 && buf[0]=='/' && buf[1]=='/')
552           break;
553       }
554 #endif
555       len=strlen(sig);
556       fgets(buf,bs-1,fin);
557       if(strlen(buf) > 1) {
558         ret_str=0;
559 #if defined(IDL_I_HH)
560         strcpy(sig+len,buf);
561         readFunctions[numberOfReadFunctions].EndPos=strlen(sig);  
562         sscanf(sig+len,"%s %s %s",buf,buf1,fname);
563         if(fname[0] == '*') {
564           ret_str=1;
565         }
566 #elif defined(IDL_I_CC)
567         strcpy(buf1,buf);
568         sscanf(buf1,"%s %s",buf,fname);
569
570         curlen=strlen(sig);
571         sprintf(sig+curlen,"%s ",buf);
572         j=strlen(buf)+1;
573
574         if(fname[0] == '*') {
575           curlen=strlen(sig);
576           sprintf(sig+curlen," *");
577           j+=1;
578         }
579         curlen=strlen(sig);
580         sprintf(sig+curlen,"%s_i::",classname);
581
582         for(i = 0; i < strlen(fname)-1; i++) {
583           ret_str+=1;
584           j+=1;
585           if(fname[i] == ':' && fname[i] == ':') {
586             ret_str+=1;
587             j+=1;
588             break;
589           }
590         }
591         curlen=strlen(sig);
592         sprintf(sig+curlen,"%s", buf1+j);
593
594         curlen=strlen(sig);
595         readFunctions[numberOfReadFunctions].EndPos=curlen;  
596         while (fgets(sig+curlen,bs-1-curlen,fin) != 0) {
597           if(sig[curlen] == '}')
598             break;
599           curlen=strlen(sig);
600         }
601 #else
602         strcpy(sig+len,buf);
603         readFunctions[numberOfReadFunctions].EndPos=strlen(sig);  
604         sscanf(sig+len,"%s _%s",buf,fname);
605 #endif
606         flen=strlen(fname);
607         if(flen>0) {
608           if(flen>2 && fname[flen-2]=='_') {
609             flen-=2;
610           }
611           readFunctions[numberOfReadFunctions].Name = malloc((flen+1-ret_str)*sizeof(char));
612           strncpy(readFunctions[numberOfReadFunctions].Name,fname+ret_str,flen-ret_str);
613           readFunctions[numberOfReadFunctions].Name[flen-ret_str]='\0';
614           
615 #if defined(IDL_I_HH)
616           len+=slen+strlen(buf)+1+strlen(buf1)+2+flen+ret_str-1; //spaces+virtual+space+return+space+space+*+name
617 #elif defined(IDL_I_CC)
618           len+=2+strlen(buf)+2+strlen(classname)+2+strlen(readFunctions[numberOfReadFunctions].Name)-1; //return+space+space+name
619           if(fname[0] == '*') {
620             len+=2;
621           }
622           if(fname[flen-2]=='_') {
623             len+=2;
624           }
625 #else
626           len+=slen+strlen(buf)+2+flen; //spaces+return+space+_+name
627 #endif
628           readFunctions[numberOfReadFunctions].NumPos=len;
629           if(fname[flen]=='_') {
630             readFunctions[numberOfReadFunctions].NumPos=len+2; //+_+num
631           }
632           
633           len=strlen(sig);
634           readFunctions[numberOfReadFunctions].Signature = malloc((len+1)*sizeof(char));
635           strncpy(readFunctions[numberOfReadFunctions].Signature,sig,len);
636           readFunctions[numberOfReadFunctions].Signature[len]='\0';
637
638           numberOfReadFunctions++;
639         }
640       }
641     }
642   }
643   fclose (fin);
644   return;
645 }
646
647 void get_signature(const char* num, FileInfo *data)
648 {
649   static char result[bs];
650   int currPos = 0;
651   int currPos_sig = 0;
652   int argtype;
653   int i, j;
654   static char buf[bs];
655   static char buf1[bs];
656   int ret = 0;
657   int found = 0;
658   int currPos_num = 0;
659
660   add_to_sig(result,"\n",&currPos);
661   if (currentFunction->Signature) {
662 #if ! defined(IDL_I_CC)
663     add_to_sig(result,"        ",&currPos);
664 #endif
665     add_to_sig(result,"//C++: ",&currPos);
666     add_to_sig(result,currentFunction->Signature,&currPos);
667     add_to_sig(result,"\n",&currPos);
668   }
669
670   if(IsClass(currentFunction->ReturnType) && ret == 0) {
671     found = 0;
672     for(i = 0; strcmp(wrapped_classes[i],"") != 0 && found == 0; i++) {
673       if(strcmp(wrapped_classes[i],currentFunction->ReturnClass) == 0)
674         found = 1;
675     }
676     if(!found)
677       ret = 1;
678   }
679
680   for (j = 0; j < currentFunction->NumberOfArguments; j++) {
681     if(IsFunction(currentFunction->ArgTypes[j]))
682       ret == 1;
683     if(IsClass(currentFunction->ArgTypes[j]) && ret == 0) {
684       found = 0;
685       for(i = 0; strcmp(wrapped_classes[i],"") != 0 && found == 0; i++) {
686         if(strcmp(wrapped_classes[i],currentFunction->ArgClasses[j]) == 0)
687           found = 1;
688       }
689       if(!found)
690         ret = 1;
691     }
692   }
693
694   if (IsArray(currentFunction->ReturnType) && !IsClass(currentFunction->ReturnType) && !IsString(currentFunction->ReturnType) && currentFunction->HintSize == 0) {
695     ret = 1;
696   }
697
698   if(ret) {
699     add_to_sig(result,"//\n",&currPos);
700     currentFunction->Signature = realloc(currentFunction->Signature,
701                                          (size_t)(currPos+1));
702     strcpy(currentFunction->Signature,result);
703     
704     return;
705   }
706
707 #if defined(IDL_I_CC)
708     add_to_sig(result,"struct CreateEventName(",&currPos);
709     add_to_sig(result,currentFunction->Name,&currPos);
710     if( strlen(num)!=0 ) {
711       add_to_sig(result,num,&currPos);
712     }
713     add_to_sig(result,")",&currPos);
714     add_to_sig(result,": public SALOME_Event\n",&currPos);
715     add_to_sig(result,"{\n",&currPos);
716     if(!IsVoid(currentFunction->ReturnType)) {
717       output_typedef(result,&currPos,MAX_ARGS,currentFunction->ReturnType,
718                      currentFunction->ReturnClass);
719       add_to_sig(result," TResult;\n",&currPos);
720       add_to_sig(result,"  TResult myResult;\n",&currPos);
721     }
722     
723     output_typedef(result, &currPos, 0, 0x309,
724                    data->ClassName);
725     add_to_sig(result," TObj;\n",&currPos);
726     add_to_sig(result,"  TObj myObj;\n",&currPos);
727     
728     for (i = 0; i < currentFunction->NumberOfArguments; i++) {
729       output_typedef(result, &currPos, i, currentFunction->ArgTypes[i],
730                      currentFunction->ArgClasses[i]);
731       sprintf(buf," TParam%d;\n",i);
732       add_to_sig(result,buf,&currPos);
733       sprintf(buf,"  TParam%d myParam%d;\n",i,i);
734       add_to_sig(result,buf,&currPos);
735     }
736     
737     add_to_sig(result,"\n",&currPos);  
738     add_to_sig(result,"  CreateEventName(",&currPos);  
739     add_to_sig(result,currentFunction->Name,&currPos);
740     if( strlen(num)!=0 ) {
741       add_to_sig(result,num,&currPos);
742     }
743     add_to_sig(result,")",&currPos);
744     add_to_sig(result,"(TObj theObj",&currPos);  
745     for (i = 0; i < currentFunction->NumberOfArguments; i++) {
746       sprintf(buf,", TParam%d theParam%d",i,i);
747       add_to_sig(result,buf,&currPos);
748     }
749     add_to_sig(result,"):\n",&currPos);  
750     add_to_sig(result,"  myObj(theObj)",&currPos);  
751     for (i = 0; i < currentFunction->NumberOfArguments; i++) {
752       sprintf(buf,", myParam%d(theParam%d)",i,i);
753       add_to_sig(result,buf,&currPos);
754     }
755     add_to_sig(result,"\n",&currPos);  
756     add_to_sig(result,"  { }\n",&currPos);  
757     add_to_sig(result,"\n",&currPos);  
758     add_to_sig(result,"  virtual void Execute()\n",&currPos);  
759     add_to_sig(result,"  {\n",&currPos);  
760     add_to_sig(result,"    ",&currPos);  
761     if(!IsVoid(currentFunction->ReturnType)/* && !IsString(currentFunction->ReturnType)*/) {
762       add_to_sig(result,"myResult = ",&currPos);  
763     }
764     //if(IsString(currentFunction->ReturnType)) {
765     //add_to_sig(result,"const char* ret = ",&currPos);  
766     //}
767     add_to_sig(result,"myObj->",&currPos);  
768     add_to_sig(result,currentFunction->Name,&currPos);  
769     add_to_sig(result,"(",&currPos);  
770     for (i = 0; i < currentFunction->NumberOfArguments; i++) {
771       if(i!=0)
772         add_to_sig(result,", ",&currPos);  
773       if(IsClass(currentFunction->ArgTypes[i]) && IsPtr(currentFunction->ArgTypes[i])) {
774         add_to_sig(result,"*",&currPos);  
775       }
776       sprintf(buf,"myParam%d",i);
777       add_to_sig(result,buf,&currPos);
778     }
779     add_to_sig(result,");\n",&currPos);  
780     //if(IsString(currentFunction->ReturnType)) {
781     //add_to_sig(result,"    myResult = (ret==NULL)?NULL:CORBA::string_dup(\"\");\n",&currPos);  
782     //}
783     add_to_sig(result,"  }\n",&currPos);  
784     
785     add_to_sig(result,"};\n",&currPos);  
786     add_to_sig(result,"//\n",&currPos);  
787 #endif
788   currPos_sig=currPos;
789
790 #if ! defined(IDL_I_CC)
791   add_to_sig(result,"        ",&currPos);
792 #endif
793
794   output_temp(result,&currPos,MAX_ARGS,currentFunction->ReturnType,
795               currentFunction->ReturnClass,0);
796
797 #if defined(IDL_I_CC)
798   add_to_sig(result,data->ClassName,&currPos);
799   add_to_sig(result,"_i::",&currPos);
800 #endif
801 #if ! defined(IDL_I_HH) && ! defined(IDL_I_CC)
802   add_to_sig(result,"_",&currPos);
803 #endif
804   add_to_sig(result,currentFunction->Name,&currPos);
805
806   if( strlen(num)!=0 ) {
807     add_to_sig(result,num,&currPos);
808   }
809   currPos_num=currPos;
810   add_to_sig(result," ",&currPos);
811
812   /* print the arg list */
813   add_to_sig(result,"(",&currPos);
814
815   for (i = 0; i < currentFunction->NumberOfArguments; i++) {
816     if( i != 0 ) {
817       add_to_sig(result,", ",&currPos);   
818     }
819     output_temp(result, &currPos, i, currentFunction->ArgTypes[i],
820                 currentFunction->ArgClasses[i],
821                 currentFunction->ArgCounts[i]);
822   }
823
824   add_to_sig(result,")",&currPos);
825 #if defined(IDL_I_CC)
826   add_to_sig(result," {\n",&currPos);
827   add_to_sig(result,"  try {\n",&currPos);
828   for (i = 0; i < currentFunction->NumberOfArguments; i++) {
829     if(IsClass(currentFunction->ArgTypes[i])) {
830       sprintf(buf,"    PARAVIS_Base_i* i_temp%d = GET_SERVANT(temp%d);\n",i,i);
831       add_to_sig(result,buf,&currPos);
832     }
833       
834     if(
835        IsArray(currentFunction->ArgTypes[i])
836        && !IsString(currentFunction->ArgTypes[i])
837        && !IsClass(currentFunction->ArgTypes[i])
838        && !IsVoid(currentFunction->ArgTypes[i])
839        ) {
840       sprintf(buf,"    CORBA::ULong j_temp%d;\n",i);
841       add_to_sig(result,buf,&currPos);
842       sprintf(buf,"    CORBA::ULong l_temp%d = temp%d.length();\n",i,i);
843       add_to_sig(result,buf,&currPos);
844       add_to_sig(result,"    ",&currPos);             
845       
846       if(IsFloat(currentFunction->ArgTypes[i]))
847         add_to_sig(result,"float",&currPos);
848       
849       if(IsDouble(currentFunction->ArgTypes[i]))
850         add_to_sig(result,"double",&currPos);
851       
852       if(IsvtkIdType(currentFunction->ArgTypes[i])) {
853         add_to_sig(result,"vtkIdType",&currPos);
854       } else {
855           if(IsShort(currentFunction->ArgTypes[i])) {
856             add_to_sig(result,"int",&currPos);
857           }
858       }
859       
860       if(IsLong(currentFunction->ArgTypes[i]))
861         add_to_sig(result,"long",&currPos);
862       
863       sprintf(buf,"* a_temp%d = new ",i);
864       add_to_sig(result,buf,&currPos);
865
866       if(IsFloat(currentFunction->ArgTypes[i]))
867         add_to_sig(result,"float",&currPos);
868       
869       if(IsDouble(currentFunction->ArgTypes[i]))
870         add_to_sig(result,"double",&currPos);
871       
872       if(IsvtkIdType(currentFunction->ArgTypes[i])) {
873         add_to_sig(result,"vtkIdType",&currPos);
874       } else {
875         if(IsShort(currentFunction->ArgTypes[i])) {
876           add_to_sig(result,"int",&currPos);
877         }
878       }
879
880       if(IsLong(currentFunction->ArgTypes[i]))
881         add_to_sig(result,"long",&currPos);
882       
883       sprintf(buf,"[l_temp%d];\n",i);
884       add_to_sig(result,buf,&currPos);
885       
886       sprintf(buf,"    for(j_temp%d=0;j_temp%d<l_temp%d;j_temp%d++) {\n",i,i,i,i);
887       add_to_sig(result,buf,&currPos);
888       
889       sprintf(buf,"      a_temp%d[j_temp%d]=temp%d[j_temp%d];\n",i,i,i,i);
890       add_to_sig(result,buf,&currPos);
891       
892       add_to_sig(result,"    }\n",&currPos);
893     }
894
895     if(IsString(currentFunction->ArgTypes[i])) {
896       sprintf(buf,"    char *c_temp%d = CORBA::string_dup(temp%d);\n",i,i);
897       add_to_sig(result,buf,&currPos);
898     }
899
900     if(IsVoid(currentFunction->ArgTypes[i])) {
901       sprintf(buf,"    long v_temp%d;\n",i);
902       add_to_sig(result,buf,&currPos);
903       
904       sprintf(buf,"    temp%d.operator>>=(v_temp%d);\n",i,i);
905       add_to_sig(result,buf,&currPos);
906     }
907   }  
908   add_to_sig(result,"    ",&currPos);
909
910   if(IsArray(currentFunction->ReturnType) && !IsClass(currentFunction->ReturnType) && !IsString(currentFunction->ReturnType)) {
911     add_to_sig(result,"CORBA::ULong i_ret;\n",&currPos); 
912     add_to_sig(result,"    PARAVIS::",&currPos); 
913     AddTypeArray(currentFunction->ReturnType,result,&currPos);
914     add_to_sig(result,"_var s_ret = new ",&currPos);
915     AddTypeArray(currentFunction->ReturnType,result,&currPos);
916     add_to_sig(result,"();\n",&currPos);
917     sprintf(buf,"    s_ret->length(%d);\n",currentFunction->HintSize);
918     add_to_sig(result,buf,&currPos);
919     add_to_sig(result,"    ",&currPos); 
920   }
921   
922   if(IsFloat(currentFunction->ReturnType)) {
923     if(IsArray(currentFunction->ReturnType)) {
924       add_to_sig(result,"float* a_ret = ",&currPos);
925     } else {
926       add_to_sig(result,"CORBA::Float ret = ",&currPos);
927     }
928   }
929   
930   if(IsDouble(currentFunction->ReturnType)) {
931     if(IsArray(currentFunction->ReturnType)) {
932       add_to_sig(result,"double* a_ret = ",&currPos);
933     } else {
934       add_to_sig(result,"CORBA::Double ret = ",&currPos);
935     }
936   }
937   
938   if(IsShort(currentFunction->ReturnType)) {
939     if(IsArray(currentFunction->ReturnType)) {
940       if(IsvtkIdType(currentFunction->ReturnType)) {
941         add_to_sig(result,"vtkIdType",&currPos);
942       } else {
943         add_to_sig(result,"int",&currPos);
944       }
945       add_to_sig(result,"* a_ret = ",&currPos);
946     } else {
947       add_to_sig(result,"CORBA::Short ret = ",&currPos);
948     }
949   }
950   
951   if(IsLong(currentFunction->ReturnType)) {
952     if(IsArray(currentFunction->ReturnType)) {
953       add_to_sig(result,"long* a_ret = ",&currPos);
954     } else {
955       add_to_sig(result,"CORBA::Long ret = ",&currPos);
956     }
957   }
958   
959   if(IsChar(currentFunction->ReturnType)) {
960     if(IsString(currentFunction->ReturnType)) {
961       add_to_sig(result,"char * ret = CORBA::string_dup(\"\");\n",&currPos);
962       add_to_sig(result,"    const char * cret = ",&currPos);
963     } else {
964       add_to_sig(result,"CORBA::Char ret = ",&currPos);     
965     }
966   }
967
968   if(IsBoolean(currentFunction->ReturnType)) {
969     add_to_sig(result,"CORBA::Boolean ret = ",&currPos);
970   }
971   
972   if(IsVoidPtr(currentFunction->ReturnType)) {
973     add_to_sig(result,"void * v_ret = ",&currPos);
974   }
975   
976   if(IsClass(currentFunction->ReturnType)) {
977     add_to_sig(result,"::",&currPos);
978     add_to_sig(result,currentFunction->ReturnClass,&currPos);
979     add_to_sig(result,"* a",&currPos);
980     add_to_sig(result,currentFunction->ReturnClass,&currPos);
981     add_to_sig(result," = ",&currPos);
982   }
983   if(IsVoid(currentFunction->ReturnType)) {
984     add_to_sig(result,"if(getVTKObject() != NULL) ProcessVoidEvent",&currPos);
985   } else {
986     add_to_sig(result,"(getVTKObject() != NULL) ? ProcessEvent",&currPos);
987   }
988   add_to_sig(result,"(\n",&currPos);
989   add_to_sig(result,"      new CreateEventName(",&currPos);
990   add_to_sig(result,currentFunction->Name,&currPos);
991   if( strlen(num)!=0 ) {
992     add_to_sig(result,num,&currPos);
993   }
994   add_to_sig(result,")",&currPos);
995   
996   add_to_sig(result,"((::",&currPos);
997   add_to_sig(result,data->ClassName,&currPos);        
998   add_to_sig(result,"*)",&currPos);
999   add_to_sig(result,"getVTKObject()\n",&currPos);
1000   
1001   for (i = 0; i < currentFunction->NumberOfArguments; i++) {
1002     add_to_sig(result,"      , ",&currPos);
1003     
1004     //if(IsClass(currentFunction->ArgTypes[i]) && IsPtr(currentFunction->ArgTypes[i])) {
1005     //add_to_sig(result,"*(",&currPos);
1006     //}
1007     
1008     if(IsClass(currentFunction->ArgTypes[i])) {
1009       sprintf(buf,"(i_temp%d != NULL)?dynamic_cast< ::%s*>(i_temp%d->getVTKObject()):NULL",i,currentFunction->ArgClasses[i],i);
1010     } else {
1011       if(
1012          IsArray(currentFunction->ArgTypes[i])
1013          && !IsString(currentFunction->ArgTypes[i])
1014          && !IsVoid(currentFunction->ArgTypes[i])
1015          ) {
1016         sprintf(buf,"a_temp%d",i);
1017       } else {
1018         if(IsVoidPtr(currentFunction->ArgTypes[i])) {
1019           sprintf(buf,"(void*)v_temp%d",i);
1020         } else {
1021           if(IsString(currentFunction->ArgTypes[i])) {
1022             sprintf(buf,"c_temp%d",i);
1023           } else {
1024             sprintf(buf,"temp%d",i);
1025           }
1026         }
1027       }
1028     }
1029       
1030     add_to_sig(result,buf,&currPos);
1031     //if(IsClass(currentFunction->ArgTypes[i]) && IsPtr(currentFunction->ArgTypes[i])) {
1032     //add_to_sig(result,")",&currPos);
1033     //}
1034     add_to_sig(result,"\n",&currPos);
1035   }
1036
1037   add_to_sig(result,"      )\n",&currPos);            
1038   add_to_sig(result,"    )",&currPos);
1039   if(!IsVoid(currentFunction->ReturnType)) {
1040     add_to_sig(result,":",&currPos);
1041     if(IsClass(currentFunction->ReturnType) || IsString(currentFunction->ReturnType) || IsPtr(currentFunction->ReturnType) || IsArray(currentFunction->ReturnType))
1042       add_to_sig(result,"NULL",&currPos);
1043     else
1044       add_to_sig(result,"0",&currPos);
1045   }
1046   add_to_sig(result,";\n",&currPos);
1047   if(IsString(currentFunction->ReturnType)) {
1048     add_to_sig(result,"    if(cret!=NULL) ret=CORBA::string_dup(cret);\n",&currPos);
1049   }
1050   
1051   if(IsClass(currentFunction->ReturnType)) {
1052     add_to_sig(result,"    if(a",&currPos);
1053     add_to_sig(result,currentFunction->ReturnClass,&currPos);         
1054     add_to_sig(result," == NULL) {\n",&currPos);
1055     add_to_sig(result,"      return PARAVIS::",&currPos);             
1056     add_to_sig(result,currentFunction->ReturnClass,&currPos);         
1057     add_to_sig(result,"::_nil();\n",&currPos);        
1058     add_to_sig(result,"    }\n",&currPos);            
1059     add_to_sig(result,"    ",&currPos);       
1060     add_to_sig(result,"PARAVIS_Base_i* aPtr = ::CreateInstance(a",&currPos);          
1061     add_to_sig(result,currentFunction->ReturnClass,&currPos);         
1062     add_to_sig(result,", a",&currPos);        
1063     add_to_sig(result,currentFunction->ReturnClass,&currPos);         
1064     add_to_sig(result,"->GetClassName());\n",&currPos);
1065     add_to_sig(result,"    aPtr->Init(a",&currPos);           
1066     add_to_sig(result,currentFunction->ReturnClass,&currPos);         
1067     add_to_sig(result,");\n",&currPos);       
1068   }
1069     
1070   for (i = 0; i < currentFunction->NumberOfArguments; i++) {
1071     if(
1072        IsArray(currentFunction->ArgTypes[i])
1073        && !IsVoid(currentFunction->ArgTypes[i])
1074        && !IsString(currentFunction->ArgTypes[i])
1075        && !IsClass(currentFunction->ArgTypes[i])
1076        ) {
1077       if (!IsIn(currentFunction->ArgTypes[i])) {
1078         sprintf(buf,"    for(j_temp%d=0;j_temp%d<l_temp%d;j_temp%d++) {\n",i,i,i,i);
1079         add_to_sig(result,buf,&currPos);
1080         
1081         sprintf(buf,"      temp%d[j_temp%d]=a_temp%d[j_temp%d];\n",i,i,i,i);
1082         add_to_sig(result,buf,&currPos);
1083         
1084         add_to_sig(result,"    }\n",&currPos);
1085       }
1086       sprintf(buf,"    delete [] a_temp%d;\n",i);
1087       add_to_sig(result,buf,&currPos);
1088     }
1089   }
1090
1091   if (IsVoid(currentFunction->ReturnType) && !IsVoidPtr(currentFunction->ReturnType)) {
1092     add_to_sig(result,"    return;\n",&currPos); 
1093   } else {
1094     if(IsClass(currentFunction->ReturnType)) {
1095       add_to_sig(result,"    return aPtr->_this();\n",&currPos);
1096     } else {
1097       if(IsVoid(currentFunction->ReturnType)) {
1098         add_to_sig(result,"    CORBA::Any* ret = new CORBA::Any;\n",&currPos);
1099         add_to_sig(result,"    (*ret) <<= v_ret;\n",&currPos);
1100         add_to_sig(result,"    return ret;\n",&currPos); 
1101       } else {
1102         if(IsArray(currentFunction->ReturnType) && !IsString(currentFunction->ReturnType)) {
1103           sprintf(buf,"    for(i_ret=0; i_ret<%d; i_ret++) {\n",currentFunction->HintSize);
1104           add_to_sig(result,buf,&currPos); 
1105           add_to_sig(result,"      s_ret[i_ret]=a_ret[i_ret];\n",&currPos); 
1106           add_to_sig(result,"    }\n",&currPos); 
1107           add_to_sig(result,"    return s_ret._retn();\n",&currPos); 
1108         } else {
1109           add_to_sig(result,"    return ret;\n",&currPos); 
1110         }
1111       }
1112     }
1113   }
1114
1115   add_to_sig(result,"  } catch(...) {\n",&currPos);
1116   add_to_sig(result,"    MESSAGE(\"",&currPos);
1117   //add_to_sig(result,data->ClassName,&currPos);              
1118   //add_to_sig(result,"::",&currPos);
1119   add_to_sig(result,currentFunction->Name,&currPos);          
1120   add_to_sig(result," - Unknown exception was occured!!!\");\n",&currPos);
1121
1122   if (IsVoid(currentFunction->ReturnType)&& !IsVoidPtr(currentFunction->ReturnType)) {
1123     add_to_sig(result,"    return;\n",&currPos);
1124   } else{
1125     if(IsString(currentFunction->ReturnType)) {
1126       add_to_sig(result,"    return CORBA::string_dup(\"\");\n",&currPos);
1127     } else {
1128       if(IsClass(currentFunction->ReturnType)) {
1129         add_to_sig(result,"    return PARAVIS::",&currPos);
1130         add_to_sig(result,currentFunction->ReturnClass,&currPos);
1131         add_to_sig(result,"::_nil();\n",&currPos);
1132       } else {
1133         if(IsArray(currentFunction->ReturnType) && !IsVoid(currentFunction->ReturnType)) {
1134           add_to_sig(result,"    PARAVIS::",&currPos);
1135           AddTypeArray(currentFunction->ReturnType,result,&currPos);
1136           add_to_sig(result,"_var s_ret = new ",&currPos);
1137           AddTypeArray(currentFunction->ReturnType,result,&currPos);
1138           add_to_sig(result,"();\n",&currPos);
1139           sprintf(buf,"    s_ret->length(%d);\n",currentFunction->HintSize);
1140           add_to_sig(result,buf,&currPos);
1141           add_to_sig(result,"    return s_ret._retn();\n",&currPos);
1142         } else {
1143           add_to_sig(result,"    return 0;\n",&currPos);
1144         }
1145       }
1146     }
1147   }
1148
1149   add_to_sig(result,"  }\n",&currPos);
1150   add_to_sig(result,"}\n",&currPos);
1151 #else
1152   add_to_sig(result,";\n",&currPos);
1153 #endif
1154
1155   if(ret)
1156     {
1157       result[currPos_sig]='\0';
1158       currentFunction->Signature = realloc(currentFunction->Signature,
1159                                            (size_t)(currPos_sig+1));
1160       strcpy(currentFunction->Signature,result);
1161
1162       return;
1163     }
1164
1165   //if(strcmp(currentFunction->Name,"NewInstance") == 0) {
1166   //currentFunction->Signature[0]='\0';
1167   //return;
1168   //}
1169
1170   for(i = 0; i < numberOfReadFunctions; i++) {
1171     if(strcmp(readFunctions[i].Name,currentFunction->Name) == 0) {
1172       j=readFunctions[i].EndPos-readFunctions[i].NumPos;
1173       strncpy(buf,result+currPos_num,j);
1174       strncpy(buf1,readFunctions[i].Signature+readFunctions[i].NumPos,j);
1175       buf[j]=0;
1176       buf1[j]=0;
1177       if(strcmp(buf,buf1) == 0) {
1178         currentFunction->Signature[0]='\0';
1179         return;
1180       }
1181     }
1182   }
1183
1184   currentFunction->Signature = realloc(currentFunction->Signature,
1185                                        (size_t)(currPos+1));
1186   strcpy(currentFunction->Signature,result);
1187 }
1188
1189 void outputFunction2(FILE *fp, FileInfo *data)
1190 {
1191   int i, j, k, is_static, is_vtkobject, fnum, occ, backnum, goto_used;
1192   int all_legacy;
1193   FunctionInfo *theFunc;
1194   FunctionInfo *backFunc;
1195   char *theName;
1196   int theType;
1197   char *backName;
1198   int backType;
1199   char static num[8];
1200   //int isSMObject = 0;
1201   int found = 0;
1202
1203 #if defined(IDL_I_HH)
1204   fprintf(fp,"#include \"SALOMEconfig.h\"\n");
1205   fprintf(fp,"#include CORBA_SERVER_HEADER(PARAVIS_Gen_%s)\n",data->ClassName);
1206   fprintf(fp,"\n");
1207   fprintf(fp,"#include \"SALOME_GenericObj_i.hh\"\n");
1208   fprintf(fp,"#include \"PARAVIS_Gen_i.hh\"\n");
1209   fprintf(fp,"#include \"PARAVIS_Gen_Types.hh\"\n");
1210   fprintf(fp,"#include \"vtkSmartPointer.h\"\n");
1211   fprintf(fp,"#include \"SALOME_Event.h\"\n");
1212
1213   for(i=0;i<data->NumberOfSuperClasses;i++)
1214   {
1215     fprintf(fp,"#include \"PARAVIS_Gen_%s_i.hh\"\n",data->SuperClasses[i]);
1216   }
1217
1218   fprintf(fp,"\nclass %s;\n",data->ClassName);
1219   fprintf(fp,"\nnamespace PARAVIS\n{\n\n");
1220 #elif defined(IDL_I_CC)
1221   fprintf(fp,"#include \"SALOME_GenericObj_i.hh\"\n");
1222   fprintf(fp,"#include \"PARAVIS_Gen_%s_i.hh\"\n",data->ClassName);
1223   fprintf(fp,"#include \"PV_Tools.h\"\n");
1224   fprintf(fp,"#include \"SALOME_Event.h\"\n");
1225   fprintf(fp,"#include <%s.h>\n",data->ClassName);
1226 #else
1227   fprintf(fp,"#include \"PARAVIS_Gen.idl\"\n");
1228   fprintf(fp,"#include \"PARAVIS_Gen_Types.idl\"\n");
1229
1230   for(i=0;i<data->NumberOfSuperClasses;i++)
1231   {
1232     fprintf(fp,"#include \"PARAVIS_Gen_%s.idl\"\n",data->SuperClasses[i]);
1233   }
1234
1235   fprintf(fp,"\nmodule PARAVIS\n{\n\n");
1236 #endif
1237
1238   is_vtkobject = ((strcmp(data->ClassName,"vtkObjectBase") == 0) || 
1239                   (data->NumberOfSuperClasses != 0));
1240
1241   for(i = 0; i < data->NumberOfSuperClasses; i++) {
1242     read_class_functions(data->SuperClasses[i],data->ClassName,fp);
1243   }
1244
1245   /* create a idl signature for each method */
1246   for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++)
1247     {
1248
1249     theFunc = wrappedFunctions[fnum];
1250     currentFunction = theFunc;
1251
1252     /* names of idl methods should be unique */
1253     num[0]='\0';
1254     j=-1;
1255     for (i = 0; i < numberOfReadFunctions; i++) {
1256       if(strcmp(currentFunction->Name,readFunctions[i].Name) == 0)
1257         j++;
1258     }
1259
1260     for (i = 0; i < fnum; i++)
1261       {
1262         if( strcmp(currentFunction->Name,wrappedFunctions[i]->Name) ==  0 )
1263           j++;
1264       }
1265
1266     if(j<0) {
1267       for (i = fnum+1; i < numberOfWrappedFunctions; i++) {
1268         if( strcmp(currentFunction->Name,wrappedFunctions[i]->Name) ==  0 ) {
1269           j=0;
1270           break;
1271         }
1272       }
1273     } else {
1274       j++;
1275     }
1276
1277     if(j>=0)
1278       {
1279         sprintf(num,"_%d",j);
1280       }
1281
1282     get_signature(num,data);
1283     }
1284
1285   /* create external type declarations for all object
1286      return types */
1287   for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++)
1288     {
1289     theFunc = wrappedFunctions[fnum];
1290     currentFunction = theFunc;
1291     theName = NULL;
1292     theType = 0;
1293
1294     for (i = theFunc->NumberOfArguments; i >= 0; i--)
1295       {
1296         if (i==0)/* return type */
1297           {
1298             theType = theFunc->ReturnType;
1299             theName = theFunc->ReturnClass;
1300           }
1301         else /* arg type */
1302           {
1303             theType = theFunc->ArgTypes[i-1];
1304             theName = theFunc->ArgClasses[i-1];
1305           }
1306         /* check for object types */
1307         if ((theType % 0x1000 == 0x309)||
1308             (theType % 0x1000 == 0x109))
1309           {
1310             /* check that we haven't done this type (no duplicate declarations) */
1311             for (backnum = fnum; backnum >= 0; backnum--) 
1312               {
1313                 backFunc = wrappedFunctions[backnum];
1314                 backName = NULL;
1315                 backType = 0;
1316                 if (backnum == fnum)
1317                   k = i+1;
1318                 else
1319                   k = 0;
1320                 for (j = backFunc->NumberOfArguments; j >= k; j--)
1321                   {
1322                     if (j==0) /* return type */
1323                       {
1324                         backType = backFunc->ReturnType;
1325                         backName = backFunc->ReturnClass;
1326                       }
1327                     else /* arg type */
1328                       {
1329                         backType = backFunc->ArgTypes[j-1];
1330                         backName = backFunc->ArgClasses[j-1];
1331                       }
1332                     if (((backType % 0x1000 == 0x309)||
1333                          (backType % 0x1000 == 0x109)))
1334                       {
1335                         if(strcmp(theName,backName) == 0)
1336                           {
1337                             break;
1338                           }
1339                       }
1340                   }
1341                 if (j >= k)
1342                   {
1343                     break;
1344                   }
1345               }
1346             if (backnum < 0 && strcmp(data->ClassName,theName) != 0)
1347               {
1348                 found = 0;
1349                 for(j = 0; strcmp(wrapped_classes[j],"") != 0 && found == 0; j++)
1350                   {
1351                     if(strcmp(wrapped_classes[j],theName) == 0)
1352                       found = 1;
1353                   }
1354                 if(found)
1355                   {
1356 #if defined(IDL_I_HH)
1357                     fprintf(fp,"    class %s_i;\n",theName);
1358 #elif defined(IDL_I_CC)
1359                     fprintf(fp,"#include \"PARAVIS_Gen_%s_i.hh\"\n",theName);
1360                     fprintf(fp,"#include <%s.h>\n",theName);
1361 #else
1362                     //fprintf(fp,"#include \"PARAVIS_Gen_%s.idl\"\n",theName);
1363                     fprintf(fp,"    interface %s;\n",theName);
1364 #endif
1365                   }
1366               }
1367           }
1368       }
1369     }
1370
1371   //fprintf(fp,"\nmodule PARAVIS\n{\n");
1372 #if defined(IDL_I_HH)
1373   fprintf(fp,"\n    class %s_i : public virtual POA_PARAVIS::%s, public virtual PARAVIS::PARAVIS_Base_i",data->ClassName,data->ClassName);
1374   //for(i = 0; i < data->NumberOfSuperClasses; i++) {
1375   //  fprintf(fp,", public virtual %s_i",data->SuperClasses[i]);
1376   //}
1377   //fprintf(fp,", public virtual SALOME::GenericObj_i");
1378   fprintf(fp," {");
1379   fprintf(fp,"\n    public:\n");
1380   fprintf(fp,"\n        %s_i();\n",data->ClassName);
1381 #elif defined(IDL_I_CC)
1382   fprintf(fp,"extern PARAVIS::PARAVIS_Base_i* CreateInstance(::vtkObjectBase* Inst, const QString&);\n");
1383   fprintf(fp,"\nnamespace PARAVIS\n{\n");
1384   fprintf(fp,"typedef %s_i current_inderface;\n",data->ClassName);
1385   fprintf(fp,"#define CreateEventName(Function) Event%s ##Function\n",data->ClassName);
1386   fprintf(fp,"%s_i::%s_i() {\n",data->ClassName,data->ClassName);
1387   fprintf(fp,"    Init(::%s::New());\n",data->ClassName);
1388   fprintf(fp,"}\n");
1389   fprintf(fp,"\n");
1390 #else
1391   fprintf(fp,"\n    interface %s : PARAVIS_Base",data->ClassName);
1392   fprintf(fp,"\n    {\n");
1393 #endif
1394
1395   for(i = 0; i < numberOfReadFunctions; i++) {
1396     fprintf(fp, "%s\n", readFunctions[i].Signature);
1397   }
1398
1399   for (fnum = 0; fnum < numberOfWrappedFunctions; fnum++) {
1400     fprintf(fp,"%s\n",wrappedFunctions[fnum]->Signature);
1401   }
1402
1403 #if defined(IDL_I_HH)
1404   fprintf(fp,"    };\n");
1405   fprintf(fp,"}\n");
1406 #elif defined(IDL_I_CC)
1407   fprintf(fp,"};\n");
1408 #else
1409   fprintf(fp,"    };\n");
1410   fprintf(fp,"};\n");
1411 #endif
1412
1413   return;
1414 }
1415
1416 void outputFunction(FILE *fp, FileInfo *data)
1417 {
1418   int i;
1419   int args_ok = 1;
1420  
1421   fp = fp;
1422   /* some functions will not get wrapped no matter what else,
1423      and some really common functions will appear only in vtkObjectPython */
1424   if (currentFunction->IsOperator || 
1425       currentFunction->ArrayFailure ||
1426       !currentFunction->IsPublic ||
1427       !currentFunction->Name)
1428     {
1429       return;
1430     }
1431   
1432   /* check to see if we can handle the args */
1433   for (i = 0; i < currentFunction->NumberOfArguments; i++)
1434     {
1435     if (currentFunction->ArgTypes[i] % 0x1000 == 9) args_ok = 0;
1436     if ((currentFunction->ArgTypes[i] % 0x10) == 8) args_ok = 0;
1437     if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 != 0x3)&&
1438         (currentFunction->ArgTypes[i] % 0x1000 != 0x109)&&
1439         ((currentFunction->ArgTypes[i] % 0x1000)/0x100)) args_ok = 0;
1440     if (currentFunction->ArgTypes[i] % 0x1000 == 0x313) args_ok = 0;
1441     if (currentFunction->ArgTypes[i] % 0x1000 == 0x314) args_ok = 0;
1442     if (currentFunction->ArgTypes[i] % 0x1000 == 0x31A) args_ok = 0;
1443     if (currentFunction->ArgTypes[i] % 0x1000 == 0x31B) args_ok = 0;
1444     if (currentFunction->ArgTypes[i] % 0x1000 == 0x31C) args_ok = 0;
1445     if (currentFunction->ArgTypes[i] % 0x1000 == 0x315) args_ok = 0;
1446     if (currentFunction->ArgTypes[i] % 0x1000 == 0x316) args_ok = 0;
1447     }
1448   if ((currentFunction->ReturnType % 0x10) == 0x8) args_ok = 0;
1449   if (currentFunction->ReturnType % 0x1000 == 0x9) args_ok = 0;
1450   if (((currentFunction->ReturnType % 0x1000)/0x100 != 0x3)&&
1451       (currentFunction->ReturnType % 0x1000 != 0x109)&&
1452       ((currentFunction->ReturnType % 0x1000)/0x100)) args_ok = 0;
1453
1454
1455   /* eliminate unsigned char * and unsigned short * */
1456   if (currentFunction->ReturnType % 0x1000 == 0x313) args_ok = 0;
1457   if (currentFunction->ReturnType % 0x1000 == 0x314) args_ok = 0;
1458   if (currentFunction->ReturnType % 0x1000 == 0x31A) args_ok = 0;
1459   if (currentFunction->ReturnType % 0x1000 == 0x31B) args_ok = 0;
1460   if (currentFunction->ReturnType % 0x1000 == 0x31C) args_ok = 0;
1461   if (currentFunction->ReturnType % 0x1000 == 0x315) args_ok = 0;
1462   if (currentFunction->ReturnType % 0x1000 == 0x316) args_ok = 0;
1463
1464   if (currentFunction->NumberOfArguments && 
1465       (currentFunction->ArgTypes[0] == 0x5000)
1466       &&(currentFunction->NumberOfArguments != 0x1)) args_ok = 0;
1467
1468   /* make sure we have all the info we need for array arguments in */
1469   for (i = 0; i < currentFunction->NumberOfArguments; i++)
1470     {
1471     if (((currentFunction->ArgTypes[i] % 0x1000)/0x100 == 0x3)&&
1472         (currentFunction->ArgCounts[i] <= 0)&&
1473         (currentFunction->ArgTypes[i] % 0x1000 != 0x309)&&
1474         (currentFunction->ArgTypes[i] % 0x1000 != 0x303)&&
1475         (currentFunction->ArgTypes[i] % 0x1000 != 0x302)) args_ok = 0;
1476     }
1477
1478   /* if we need a return type hint make sure we have one */
1479   switch (currentFunction->ReturnType % 0x1000)
1480     {
1481     case 0x301: case 0x307: case 0x30A: case 0x30B: case 0x30C: case 0x30D: case 0x30E:
1482     case 0x304: case 0x305: case 0x306:
1483       args_ok = currentFunction->HaveHint;
1484       break;
1485     }
1486   
1487   /* make sure it isn't a Delete or New function */
1488   if (!strcmp("Delete",currentFunction->Name) ||
1489       !strcmp("New",currentFunction->Name))
1490     {
1491     args_ok = 0;
1492     }
1493   
1494   /* check for New() function */
1495   if (!strcmp("New",currentFunction->Name) &&
1496       currentFunction->NumberOfArguments == 0)
1497     {
1498     class_has_new = 1;
1499     }
1500
1501   if (currentFunction->IsPublic && args_ok && 
1502       strcmp(data->ClassName,currentFunction->Name) &&
1503       strcmp(data->ClassName, currentFunction->Name + 1))
1504     {
1505     wrappedFunctions[numberOfWrappedFunctions] = currentFunction;
1506     numberOfWrappedFunctions++;
1507     }
1508
1509   return;
1510 }
1511
1512 /* print the parsed structures */
1513 void vtkParseOutput(FILE *fp, FileInfo *data)
1514 {
1515   int i;
1516
1517 #if defined(IDL_I_HH)
1518   fprintf(fp, "// idl wrapper interface for %s object implementation\n//\n", data->ClassName);
1519 #elif defined(IDL_I_CC)
1520   fprintf(fp, "// idl wrapper implementation for %s object\n//\n", data->ClassName);
1521 #else
1522   fprintf(fp, "// idl wrapper for %s object\n//\n", data->ClassName);
1523 #endif
1524   for (i = 0;1;i++)
1525     {
1526       if(strlen(Copyright[i]) != 0)
1527         {
1528           fprintf(fp,"%s\n",Copyright[i]);
1529         }
1530       else
1531         {
1532           break;
1533         }
1534     }
1535   fprintf(fp,"\n");
1536 #if defined(IDL_I_HH)
1537   fprintf(fp,"#ifndef PARAVIS_Gen_%s_i_HeaderFile\n",data->ClassName);
1538   fprintf(fp,"#define PARAVIS_Gen_%s_i_HeaderFile\n",data->ClassName);
1539   fprintf(fp,"\n");
1540 #elif defined(IDL_I_CC)
1541 #else
1542   fprintf(fp,"#ifndef __PARAVIS_Gen_%s__\n",data->ClassName);
1543   fprintf(fp,"#define __PARAVIS_Gen_%s__\n",data->ClassName);
1544   fprintf(fp,"\n");
1545 #endif
1546
1547   /* insert function handling code here */
1548   for (i = 0; i < data->NumberOfFunctions; i++)
1549     {
1550       currentFunction = data->Functions + i;
1551       outputFunction(fp, data);
1552     }
1553
1554   if (data->NumberOfSuperClasses || !data->IsAbstract)
1555     {
1556     outputFunction2(fp, data);
1557     }
1558
1559 #if defined(IDL_I_HH)
1560   fprintf(fp,"\n#endif\n");
1561 #elif defined(IDL_I_CC)
1562 #else
1563   fprintf(fp,"\n#endif\n");
1564 #endif
1565   return;
1566 }