Salome HOME
Fix remarks related to the "0021709: [CEA 583] Toolbar preferences" issue.
[modules/paravis.git] / idl / vtkWrapIDL.c
index 11e33cd8722b0405b4d9c38dfa9e43c9388290ed..60385a428c11e5f6dfe518ac80b8bcb0e9d7dbab 100644 (file)
@@ -1,6 +1,6 @@
 // PARAVIS : ParaView wrapper SALOME module
 //
-// Copyright (C) 2010-2012  CEA/DEN, EDF R&D
+// Copyright (C) 2010-2013  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include "vtkConfigure.h"
 #include "vtkParse.h"
 #include "vtkParseType.h"
+#include "vtkParseMain.h"
 #include "vtkWrapIDL.h"
 #include "vtkWrap.h"
 
@@ -54,9 +56,11 @@ char* Copyright[] = {
 
 #define bs 12288
 
+HierarchyInfo *hierarchyInfo = NULL;
 int numberOfWrappedFunctions = 0;
 FunctionInfo *wrappedFunctions[1000];
 extern FunctionInfo *currentFunction;
+char *EmptyString = "";
 
 
 static void add_to_sig(char *sig, const char *add, int *i)
@@ -188,6 +192,10 @@ void AddCharAtomArg(int I, ValueInfo* Type, char *Result, int *CurrPos) {
   AddAtomArg(I,Type,"char","Char",Result,CurrPos);
 }
 
+void AddCharArrayArg(int I, ValueInfo* Type, char *Result, int *CurrPos) {
+  AddArrayArg(I,Type,"char",Result,CurrPos);
+}
+
 void AddStringArg(int I, char *Result, int *CurrPos) {
 #if defined(IDL_I_HH) || defined(IDL_I_CC)
   add_to_sig(Result,"char ",CurrPos);
@@ -238,11 +246,22 @@ int IsvtkIdType(ValueInfo* theType) {
 int IsShort(ValueInfo* theType) {
   //return ((Type % 0x10) == 0x4 || (Type % 0x10) == 0x5 || (Type % 0x10) == 0xA);
   int aVal = theType->Type & VTK_PARSE_BASE_TYPE;
-  return (aVal == VTK_PARSE_SHORT) || (aVal == VTK_PARSE_INT) || 
-    (aVal == VTK_PARSE_ID_TYPE) || (aVal == VTK_PARSE_UNSIGNED_INT) || (aVal == VTK_PARSE_UNSIGNED_SHORT) ||
+  return (aVal == VTK_PARSE_SHORT) || (aVal == VTK_PARSE_UNSIGNED_SHORT);
+}
+
+int IsInt(ValueInfo* theType) {
+  //return ((Type % 0x10) == 0x4 || (Type % 0x10) == 0x5 || (Type % 0x10) == 0xA);
+  int aVal = theType->Type & VTK_PARSE_BASE_TYPE;
+  return (aVal == VTK_PARSE_INT) || 
+    (aVal == VTK_PARSE_ID_TYPE) || (aVal == VTK_PARSE_UNSIGNED_INT) ||
     (aVal == VTK_PARSE_SSIZE_T) || (aVal == VTK_PARSE_SIZE_T);
 }
 
+int IsShortInt(ValueInfo* theType) {
+  //return ((Type % 0x10) == 0x4 || (Type % 0x10) == 0x5 || (Type % 0x10) == 0xA);
+  return (IsShort(theType) || IsInt(theType));
+}
+
 void AddShortAtomArg(int I, ValueInfo* Type, char *Result, int *CurrPos) {
   AddAtomArg(I,Type,"short","Short",Result,CurrPos);
 }
@@ -251,6 +270,10 @@ int IsShortArray(ValueInfo* Type) {
   return (IsShort(Type) && IsArray(Type));
 }
 
+int IsIntArray(ValueInfo* Type) {
+  return (IsInt(Type) && IsArray(Type));
+}
+
 void AddShortArrayArg(int I, ValueInfo* Type, char *Result, int *CurrPos) {
   AddArrayArg(I,Type,"short",Result,CurrPos);
 }
@@ -343,7 +366,7 @@ void AddVoidArg(int I, char *Result, int *CurrPos, ValueInfo* Type) {
 }
 
 void AddTypeArray(ValueInfo* Type, char *Result, int *CurrPos) {
-  if(IsShort(Type))
+  if(IsShortInt(Type))
     add_to_sig(Result,"short",CurrPos);
   if(IsLong(Type))
     add_to_sig(Result,"long",CurrPos);
@@ -390,7 +413,7 @@ void output_type(char* result, int *currPos, int i, ValueInfo* aType, const char
     }
   }
   
-  if(IsShort(aType)) {
+  if(IsShortInt(aType)) {
     if(IsArray(aType)) {
       if (IsUnsigned(aType))
         add_to_sig(result,"unsigned ",currPos);
@@ -414,10 +437,18 @@ void output_type(char* result, int *currPos, int i, ValueInfo* aType, const char
     }
   }
   
-  if(IsChar(aType)) {
-    if(IsString(aType)) {
-      if(IsReturnArg(i))
-        add_to_sig(result,"const ",currPos);
+  if(IsString(aType)) {
+    if(IsReturnArg(i))
+      add_to_sig(result,"const ",currPos);
+    if(strcmp(aType->Class, "vtkStdString") == 0) {
+      add_to_sig(result,"vtkStdString",currPos);
+    } else {
+      add_to_sig(result,"char",currPos);
+    }
+  } else if(IsChar(aType)) {
+    if(IsArray(aType)) {
+      if (IsUnsigned(aType))
+        add_to_sig(result,"unsigned ",currPos);
       add_to_sig(result,"char",currPos);
     } else {
       add_to_sig(result,"CORBA::Char",currPos);            
@@ -438,7 +469,9 @@ void output_type(char* result, int *currPos, int i, ValueInfo* aType, const char
   }
   
   if(IsArray(aType) || IsPtr(aType) || IsClass(aType) || IsString(aType)) {
-    add_to_sig(result,"*",currPos);
+    if(strcmp(aType->Class, "vtkStdString") != 0) {
+      add_to_sig(result,"*",currPos);
+    }
   }
 }
 
@@ -495,8 +528,8 @@ void output_temp(char* result, int *currPos, int i, ValueInfo* aType, const char
     }
   }
 
-  if(IsShort(aType)) {
-    if(IsShortArray(aType)) {
+  if(IsShortInt(aType)) {
+    if(IsArray(aType)) {
       AddShortArrayArg(i,aType,result,currPos);
     } else {
       AddShortAtomArg(i,aType,result,currPos);
@@ -515,7 +548,11 @@ void output_temp(char* result, int *currPos, int i, ValueInfo* aType, const char
     if(IsString(aType)) {
       AddStringArg(i,result,currPos);
     } else {
-      AddCharAtomArg(i,aType,result,currPos);
+      if(IsCharArray(aType)) {
+       AddCharArrayArg(i,aType,result,currPos);
+      } else {
+       AddCharAtomArg(i,aType,result,currPos);
+      }
     }
   } else if (IsString(aType)) //!!! VSV
     AddStringArg(i,result,currPos);
@@ -743,8 +780,8 @@ void get_signature(const char* num, ClassInfo *data)
       ret = 1;
   }
   
-  for (j = 0; j < currentFunction->NumberOfArguments; j++) {
-    aArgVal = currentFunction->Arguments[j];
+  for (j = 0; j < vtkWrap_CountWrappedParameters(currentFunction); j++) {
+    aArgVal = currentFunction->Parameters[j];
     if(IsFunction(aArgVal))
       ret == 1;
     if(IsClass(aArgVal) && ret == 0) {
@@ -762,6 +799,7 @@ void get_signature(const char* num, ClassInfo *data)
     ret = 1;
   }
   
+
   if(ret) {
     add_to_sig(result,"//\n",&currPos);
     /*currentFunction->Signature = (const char*)realloc((void*)currentFunction->Signature,
@@ -802,8 +840,8 @@ void get_signature(const char* num, ClassInfo *data)
   add_to_sig(result,"* TObj;\n",&currPos);
   add_to_sig(result,"  TObj myObj;\n",&currPos);
   
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     //output_typedef(result, &currPos, i, currentFunction->ArgTypes[i],
     //               currentFunction->ArgClasses[i]);
     output_typedef(result, &currPos, i, aArgVal, currentFunction->ArgClasses[i]);
@@ -821,13 +859,13 @@ void get_signature(const char* num, ClassInfo *data)
   }
   add_to_sig(result,")",&currPos);
   add_to_sig(result,"(TObj theObj",&currPos);  
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
     sprintf(buf,", TParam%d theParam%d",i,i);
     add_to_sig(result,buf,&currPos);
   }
   add_to_sig(result,"):\n",&currPos);  
   add_to_sig(result,"  myObj(theObj)",&currPos);  
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
     sprintf(buf,", myParam%d(theParam%d)",i,i);
     add_to_sig(result,buf,&currPos);
   }
@@ -846,14 +884,14 @@ void get_signature(const char* num, ClassInfo *data)
   add_to_sig(result,"myObj->",&currPos);  
   add_to_sig(result,currentFunction->Name,&currPos);  
   add_to_sig(result,"(",&currPos);  
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     if(i!=0)
       add_to_sig(result,", ",&currPos);  
     if(IsClass(aArgVal) && IsPtr(aArgVal)) {
       add_to_sig(result,"*",&currPos);  
     }
-    if (IsString(aArgVal) && IsConst(aArgVal))
+    if (IsString(aArgVal) && IsConst(aArgVal) && strcmp(aArgVal->Class, "vtkStdString") != 0)
       sprintf(buf,"checkNullStr(myParam%d)",i);
     else
       sprintf(buf,"myParam%d",i);
@@ -895,23 +933,23 @@ void get_signature(const char* num, ClassInfo *data)
   /* print the arg list */
   add_to_sig(result,"(",&currPos);
 
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     if( i != 0 ) {
       add_to_sig(result,", ",&currPos);          
     }
     /*    output_temp(result, &currPos, i, currentFunction->ArgTypes[i],
                 (char*)currentFunction->ArgClasses[i],
                 currentFunction->ArgCounts[i]);*/
-    output_temp(result, &currPos, i, aArgVal,  aArgVal->Class, currentFunction->NumberOfArguments);
+    output_temp(result, &currPos, i, aArgVal,  aArgVal->Class, vtkWrap_CountWrappedParameters(currentFunction));
   }
 
   add_to_sig(result,")",&currPos);
 #if defined(IDL_I_CC)
   add_to_sig(result," {\n",&currPos);
   add_to_sig(result,"  try {\n",&currPos);
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     if(IsClass(aArgVal)) {
       sprintf(buf,"    PARAVIS_Base_i* i_temp%d = GET_SERVANT(temp%d);\n",i,i);
       add_to_sig(result,buf,&currPos);
@@ -930,12 +968,18 @@ void get_signature(const char* num, ClassInfo *data)
       if(IsDouble(aArgVal))
         add_to_sig(result,"double",&currPos);
       
+      if(IsChar(aArgVal)) {
+       if (IsUnsigned(aArgVal))
+         add_to_sig(result,"unsigned ",&currPos);
+        add_to_sig(result,"char",&currPos);
+      }
+
       if(IsvtkIdType(aArgVal)) {
         if (IsUnsigned(aArgVal))
           add_to_sig(result,"unsigned ",&currPos);
         add_to_sig(result,"vtkIdType",&currPos);
       } else {
-        if(IsShort(aArgVal)) {
+        if(IsShortInt(aArgVal)) {
           if (IsUnsigned(aArgVal))
             add_to_sig(result,"unsigned ",&currPos);
           add_to_sig(result,"int",&currPos);
@@ -956,12 +1000,18 @@ void get_signature(const char* num, ClassInfo *data)
       if(IsDouble(aArgVal))
         add_to_sig(result,"double",&currPos);
       
+      if(IsChar(aArgVal)) {
+       if (IsUnsigned(aArgVal))
+         add_to_sig(result,"unsigned ",&currPos);
+        add_to_sig(result,"char",&currPos);
+      }
+
       if(IsvtkIdType(aArgVal)) {
         if (IsUnsigned(aArgVal))
           add_to_sig(result,"unsigned ",&currPos);
         add_to_sig(result,"vtkIdType",&currPos);
       } else {
-        if(IsShort(aArgVal)) {
+        if(IsShortInt(aArgVal)) {
           if (IsUnsigned(aArgVal))
             add_to_sig(result,"unsigned ",&currPos);
           add_to_sig(result,"int",&currPos);
@@ -1012,6 +1062,10 @@ void get_signature(const char* num, ClassInfo *data)
     add_to_sig(result,buf,&currPos);
     add_to_sig(result,"    ",&currPos); 
   }
+
+  if(IsArray(aRetVal) && IsUnsigned(aRetVal)) {
+    add_to_sig(result,"unsigned ",&currPos);
+  }
   
   if(IsFloat(aRetVal)) {
     if(IsArray(aRetVal)) {
@@ -1029,12 +1083,16 @@ void get_signature(const char* num, ClassInfo *data)
     }
   }
   
-  if(IsShort(aRetVal)) {
+  if(IsShortInt(aRetVal)) {
     if(IsArray(aRetVal)) {
       if(IsvtkIdType(aRetVal)) {
         add_to_sig(result,"vtkIdType",&currPos);
       } else {
-        add_to_sig(result,"int",&currPos);
+       if(IsShort(aRetVal)) {
+         add_to_sig(result,"short",&currPos);
+       } else {
+         add_to_sig(result,"int",&currPos);
+       }
       }
       add_to_sig(result,"* a_ret = ",&currPos);
     } else {
@@ -1092,8 +1150,8 @@ void get_signature(const char* num, ClassInfo *data)
   add_to_sig(result,"*)",&currPos);
   add_to_sig(result,"getVTKObject()\n",&currPos);
   
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     add_to_sig(result,"      , ",&currPos);
     
     //if(IsClass(currentFunction->ArgTypes[i]) && IsPtr(currentFunction->ArgTypes[i])) {
@@ -1159,8 +1217,8 @@ void get_signature(const char* num, ClassInfo *data)
     add_to_sig(result,");\n",&currPos);              
   }
     
-  for (i = 0; i < currentFunction->NumberOfArguments; i++) {
-    aArgVal = currentFunction->Arguments[i];
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++) {
+    aArgVal = currentFunction->Parameters[i];
     if(IsArray(aArgVal) && !IsVoid(aArgVal) && !IsString(aArgVal) && !IsClass(aArgVal)) {
       if (!IsIn(aArgVal)) {
         sprintf(buf,"    for(j_temp%d=0;j_temp%d<l_temp%d;j_temp%d++) {\n",i,i,i,i);
@@ -1266,7 +1324,8 @@ void get_signature(const char* num, ClassInfo *data)
       buf[j]=0;
       buf1[j]=0;
       if(strcmp(buf,buf1) == 0) {
-        ((char*)currentFunction->Signature)[0]='\0';
+        //((char*)currentFunction->Signature)[0]='\0';
+       currentFunction->Signature = EmptyString;
         return;
       }
     }
@@ -1311,6 +1370,16 @@ void outputFunction2(FILE *fp, ClassInfo *data)
     fprintf(fp,"#include \"PARAVIS_Gen_%s_i.hh\"\n",data->SuperClasses[i]);
   }
 
+  //RNV: to avoid link error on windows via Visual Studio
+  //undef GetObject macro.
+  if( strcmp(data->Name, "vtkWebGLExporter") == 0 ) {
+    fprintf(fp,"#ifdef WIN32\n");
+    fprintf(fp,"  #ifdef GetObject\n");
+    fprintf(fp,"    #undef GetObject\n");
+    fprintf(fp,"  #endif\n");
+    fprintf(fp,"#endif\n");
+  }
+
   fprintf(fp,"\nclass %s;\n",data->Name);
   fprintf(fp,"\nnamespace PARAVIS\n{\n\n");
 #elif defined(IDL_I_CC)
@@ -1373,7 +1442,6 @@ void outputFunction2(FILE *fp, ClassInfo *data)
         {
           sprintf(num,"_%d",j);
         }
-      
       get_signature(num,data);
     }
   /* create external type declarations for all object
@@ -1385,7 +1453,7 @@ void outputFunction2(FILE *fp, ClassInfo *data)
       theName = NULL;
       theType = 0;
       
-      for (i = theFunc->NumberOfArguments; i >= 0; i--)
+      for (i = vtkWrap_CountWrappedParameters(theFunc); i >= 0; i--)
         {
           if (i==0)/* return type */
             {
@@ -1395,7 +1463,7 @@ void outputFunction2(FILE *fp, ClassInfo *data)
             }
           else /* arg type */
             {
-              aArgVal = theFunc->Arguments[i-1];
+              aArgVal = theFunc->Parameters[i-1];
               //theType = theFunc->ArgTypes[i-1];
               //theName = (char*)theFunc->ArgClasses[i-1];
             }
@@ -1416,7 +1484,7 @@ void outputFunction2(FILE *fp, ClassInfo *data)
                     k = i+1;
                   else
                     k = 0;
-                  for (j = backFunc->NumberOfArguments; j >= k; j--)
+                  for (j = vtkWrap_CountWrappedParameters(backFunc); j >= k; j--)
                     {
                       if (j==0) /* return type */
                         {
@@ -1426,7 +1494,7 @@ void outputFunction2(FILE *fp, ClassInfo *data)
                         }
                       else /* arg type */
                         {
-                          aBackArgVal = backFunc->Arguments[j-1];
+                          aBackArgVal = backFunc->Parameters[j-1];
                           //backType = backFunc->ArgTypes[j-1];
                           //backName = (char*)backFunc->ArgClasses[j-1];
                         }
@@ -1553,9 +1621,9 @@ void outputFunction(FILE *fp, ClassInfo *data)
   //printf("#### Check %s\n", currentFunction->Name);
  
   /* check to see if we can handle the args */
-  for (i = 0; i < currentFunction->NumberOfArguments; i++)
+  for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++)
     {
-      aArgVal = currentFunction->Arguments[i];
+      aArgVal = currentFunction->Parameters[i];
       /*printf("  Argument: %s ", vtkWrap_GetTypeName(aArgVal));
       if (vtkWrap_IsArray(aArgVal)) {
         printf("!!!! Argument %i is array\n", i);
@@ -1652,12 +1720,12 @@ void outputFunction(FILE *fp, ClassInfo *data)
   if (aRetVal % VTK_PARSE_BASE_TYPE == 0x316) args_ok = 0;
   
 
-  if (currentFunction->NumberOfArguments && 
+  if (vtkWrap_CountWrappedParameters(currentFunction) && 
       (currentFunction->ArgTypes[0] == 0x5000)
-      &&(currentFunction->NumberOfArguments != 0x1)) args_ok = 0;*/
+      &&(vtkWrap_CountWrappedParameters(currentFunction) != 0x1)) args_ok = 0;*/
 
   /* make sure we have all the info we need for array arguments in */
-  /*for (i = 0; i < currentFunction->NumberOfArguments; i++)
+  /*for (i = 0; i < vtkWrap_CountWrappedParameters(currentFunction); i++)
     {
     if (((currentFunction->ArgTypes[i] % VTK_PARSE_BASE_TYPE)/0x100 == 0x3)&&
         (currentFunction->ArgCounts[i] <= 0)&&
@@ -1689,7 +1757,7 @@ void outputFunction(FILE *fp, ClassInfo *data)
   }
   
   /* check for New() function */
-  if (!strcmp("New",currentFunction->Name) && currentFunction->NumberOfArguments == 0)
+  if (!strcmp("New",currentFunction->Name) && vtkWrap_CountWrappedParameters(currentFunction) == 0)
     {
       class_has_new = 1;
     }
@@ -1707,17 +1775,41 @@ void outputFunction(FILE *fp, ClassInfo *data)
 }
 
 /* print the parsed structures */
-void vtkParseOutput(FILE *fp, FileInfo *file_info)
+int main(int argc, char *argv[])
 {
-  int i;
+  OptionInfo *options;
+  FileInfo *file_info;
   ClassInfo *data;
+  FILE *fp;
+  int i;
+
+  /* get command-line args and parse the header file */
+  file_info = vtkParse_Main(argc, argv);
+
+  /* get the command-line options */
+  options = vtkParse_GetCommandLineOptions();
+
+  /* get the output file */
+  fp = fopen(options->OutputFileName, "w");
+
+  if (!fp)
+    {
+    fprintf(stderr, "Error opening output file %s\n", options->OutputFileName);
+    exit(1);
+    }
 
   /* get the main class */
-  data = file_info->MainClass;
+  if ((data = file_info->MainClass) == NULL)
+    {
+    fclose(fp);
+    exit(0);
+    }
 
-  // Do not wrap this class
-  //  if (strcmp(data->Name, "vtkVariant") == 0)
-  //  return;
+  /* get the hierarchy info for accurate typing */
+  if (options->HierarchyFileName)
+    {
+    hierarchyInfo = vtkParseHierarchy_ReadFile(options->HierarchyFileName);
+    }
 
 #if defined(IDL_I_HH)
   fprintf(fp, "// idl wrapper interface for %s object implementation\n//\n", data->Name);
@@ -1753,6 +1845,10 @@ void vtkParseOutput(FILE *fp, FileInfo *file_info)
   for (i = 0; i < data->NumberOfFunctions; i++)
     {
       currentFunction = data->Functions[i];
+#ifdef VTK_LEGACY_REMOVE
+      if(currentFunction->IsLegacy)
+       continue;
+#endif
       outputFunction(fp, data);
     }
   //printf("#### NbFunctions %i\n", numberOfWrappedFunctions);
@@ -1768,5 +1864,8 @@ void vtkParseOutput(FILE *fp, FileInfo *file_info)
 #else
   fprintf(fp,"\n#endif\n");
 #endif
-  return;
+
+  vtkParse_Free(file_info);
+
+  return 0;
 }