/* Declare the exports and imports for a VTK/Python class */ static void vtkWrapPython_ExportVTKClass( FILE *fp, ClassInfo *data, HierarchyInfo *hinfo) { char classname[1024]; const char *supername; /* mangle the classname if necessary */ vtkWrapText_PythonName(data->Name, classname); /* for vtkObjectBase objects: export New method for use by subclasses */ fprintf(fp, "extern \"C\" { %s PyObject *Py%s_ClassNew(); }\n" "\n", "VTK_ABI_EXPORT", classname); /* declare the New methods for all the superclasses */ supername = vtkWrapPython_GetSuperClass(data, hinfo); if (supername) { vtkWrapText_PythonName(supername, classname); fprintf(fp, "#ifndef DECLARED_Py%s_ClassNew\n" "extern \"C\" { PyObject *Py%s_ClassNew(); }\n" "#define DECLARED_Py%s_ClassNew\n" "#endif\n", classname, classname, classname); } }
/* generate the New method for a vtkObjectBase object */ static void vtkWrapPython_GenerateObjectNew( FILE *fp, const char *classname, ClassInfo *data, HierarchyInfo *hinfo, int class_has_new) { char superclassname[1024]; const char *name; int has_constants = 0; int i; if (class_has_new) { fprintf(fp, "static vtkObjectBase *Py%s_StaticNew()\n" "{\n" " return %s::New();\n" "}\n" "\n", classname, data->Name); } fprintf(fp, "PyObject *Py%s_ClassNew()\n" "{\n" " PyVTKClass_Add(\n" " &Py%s_Type, Py%s_Methods,\n", classname, classname, classname); if (strcmp(data->Name, classname) == 0) { fprintf(fp, " \"%s\",\n" " Py%s_Doc(),", classname, classname); } else { /* use of typeid() matches vtkTypeTemplate */ fprintf(fp, " typeid(%s).name(),\n" " Py%s_Doc(),", data->Name, classname); } if (class_has_new) { fprintf(fp, " &Py%s_StaticNew);\n\n", classname); } else { fprintf(fp, " NULL);\n\n"); } fprintf(fp, " PyTypeObject *pytype = &Py%s_Type;\n\n", classname); /* if type is already ready, then return */ fprintf(fp, " if ((pytype->tp_flags & Py_TPFLAGS_READY) != 0)\n" " {\n" " return (PyObject *)pytype;\n" " }\n\n"); /* add any flags specific to this type */ fprintf(fp, "#if !defined(VTK_PY3K) && PY_VERSION_HEX >= 0x02060000\n" " pytype->tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;\n" "#endif\n\n"); /* find the first superclass that is a VTK class, create it first */ name = vtkWrapPython_GetSuperClass(data, hinfo); if (name) { vtkWrapText_PythonName(name, superclassname); fprintf(fp, " pytype->tp_base = (PyTypeObject *)Py%s_ClassNew();\n\n", superclassname); } /* check if any constants need to be added to the class dict */ for (i = 0; i < data->NumberOfConstants; i++) { if (data->Constants[i]->Access == VTK_ACCESS_PUBLIC) { has_constants = 1; break; } } if (has_constants) { fprintf(fp, " PyObject *d = pytype->tp_dict;\n" " PyObject *o;\n" "\n"); /* add any enum types defined in the class to its dict */ vtkWrapPython_AddPublicEnumTypes(fp, " ", "d", "o", data); /* add any constants defined in the class to its dict */ vtkWrapPython_AddPublicConstants(fp, " ", "d", "o", data); } fprintf(fp, " PyType_Ready(pytype);\n" " return (PyObject *)pytype;\n" "}\n\n"); }
/* Create the docstring for a class, and print it to fp */ void vtkWrapPython_ClassDoc( FILE *fp, FileInfo *file_info, ClassInfo *data, HierarchyInfo *hinfo, int is_vtkobject) { char pythonname[1024]; const char *supername; char *cp; const char *ccp = NULL; size_t i, n; size_t briefmax = 255; int j; char temp[500]; char *comment; if (data == file_info->MainClass && file_info->NameComment) { /* use the old VTK-style class description */ fprintf(fp, " \"%s\\n\",\n", vtkWrapText_QuoteString( vtkWrapText_FormatComment(file_info->NameComment, 70), 500)); } else if (data->Comment) { strncpy(temp, data->Name, briefmax); temp[briefmax] = '\0'; i = strlen(temp); temp[i++] = ' '; temp[i++] = '-'; if (data->Comment[0] != ' ') { temp[i++] = ' '; } /* extract the brief comment, if present */ ccp = data->Comment; while (i < briefmax && *ccp != '\0') { /* a blank line ends the brief comment */ if (ccp[0] == '\n' && ccp[1] == '\n') { break; } /* fuzzy: capital letter or a new command on next line ends brief */ if (ccp[0] == '\n' && ccp[1] == ' ' && ((ccp[2] >= 'A' && ccp[2] <= 'Z') || ccp[2] == '@' || ccp[2] == '\\')) { break; } temp[i] = *ccp; /* a sentence-ending period ends the brief comment */ if (ccp[0] == '.' && (ccp[1] == ' ' || ccp[1] == '\n')) { i++; ccp++; while (*ccp == ' ') { ccp++; } break; } ccp++; i++; } /* skip all blank lines */ while (*ccp == '\n') { ccp++; } if (*ccp == '\0') { ccp = NULL; } temp[i] = '\0'; fprintf(fp, " \"%s\\n\",\n", vtkWrapText_QuoteString( vtkWrapText_FormatComment(temp, 70), 500)); } else { fprintf(fp, " \"%s - no description provided.\\n\\n\",\n", vtkWrapText_QuoteString(data->Name, 500)); } /* only consider superclasses that are wrapped */ supername = vtkWrapPython_GetSuperClass(data, hinfo); if (supername) { vtkWrapPython_PyTemplateName(supername, pythonname); fprintf(fp, " \"Superclass: %s\\n\\n\",\n", vtkWrapText_QuoteString(pythonname, 500)); } if (data == file_info->MainClass && (file_info->Description || file_info->Caveats || file_info->SeeAlso)) { n = 100; if (file_info->Description) { n += strlen(file_info->Description); } if (file_info->Caveats) { n += strlen(file_info->Caveats); } if (file_info->SeeAlso) { n += strlen(file_info->SeeAlso); } comment = (char *)malloc(n); cp = comment; *cp = '\0'; if (file_info->Description) { strcpy(cp, file_info->Description); cp += strlen(cp); *cp++ = '\n'; *cp++ = '\n'; *cp = '\0'; } if (file_info->Caveats) { sprintf(cp, ".SECTION Caveats\n\n"); cp += strlen(cp); strcpy(cp, file_info->Caveats); cp += strlen(cp); *cp++ = '\n'; *cp++ = '\n'; *cp = '\0'; } if (file_info->SeeAlso) { sprintf(cp, ".SECTION See Also\n\n"); cp += strlen(cp); strcpy(cp, file_info->SeeAlso); cp += strlen(cp); *cp = '\0'; } ccp = vtkWrapText_FormatComment(comment, 70); free(comment); } else if (ccp) { ccp = vtkWrapText_FormatComment(ccp, 70); } if (ccp) { n = (strlen(ccp) + 400-1)/400; for (i = 0; i < n; i++) { strncpy(temp, &ccp[400*i], 400); temp[400] = '\0'; if (i < n-1) { fprintf(fp, " \"%s\",\n", vtkWrapText_QuoteString(temp, 500)); } else { /* just for the last time */ fprintf(fp, " \"%s\\n\",\n", vtkWrapText_QuoteString(temp, 500)); } } } /* for special objects, add constructor signatures to the doc */ if (!is_vtkobject && !data->Template && !data->IsAbstract) { for (j = 0; j < data->NumberOfFunctions; j++) { if (vtkWrapPython_MethodCheck(data, data->Functions[j], hinfo) && vtkWrap_IsConstructor(data, data->Functions[j])) { fprintf(fp," \"%s\\n\",\n", vtkWrapText_FormatSignature( data->Functions[j]->Signature, 70, 2000)); } } } }
/* Create the docstring for a class, and print it to fp */ void vtkWrapPython_ClassDoc( FILE *fp, FileInfo *file_info, ClassInfo *data, HierarchyInfo *hinfo, int is_vtkobject) { char pythonname[1024]; const char *supername; char *cp; const char *ccp; size_t i, n; int j; char temp[500]; char *comment; if (file_info->NameComment) { fprintf(fp, " \"%s\\n\",\n", vtkWrapText_QuoteString( vtkWrapText_FormatComment(file_info->NameComment, 70), 500)); } else { fprintf(fp, " \"%s - no description provided.\\n\\n\",\n", vtkWrapText_QuoteString(data->Name, 500)); } /* only consider superclasses that are wrapped */ supername = vtkWrapPython_GetSuperClass(data, hinfo); if (supername) { vtkWrapPython_PyTemplateName(supername, pythonname); fprintf(fp, " \"Superclass: %s\\n\\n\",\n", vtkWrapText_QuoteString(pythonname, 500)); } n = 100; if (file_info->Description) { n += strlen(file_info->Description); } if (file_info->Caveats) { n += strlen(file_info->Caveats); } if (file_info->SeeAlso) { n += strlen(file_info->SeeAlso); } comment = (char *)malloc(n); cp = comment; *cp = '\0'; if (file_info->Description) { strcpy(cp, file_info->Description); cp += strlen(cp); *cp++ = '\n'; *cp++ = '\n'; *cp = '\0'; } if (file_info->Caveats) { sprintf(cp, ".SECTION Caveats\n\n"); cp += strlen(cp); strcpy(cp, file_info->Caveats); cp += strlen(cp); *cp++ = '\n'; *cp++ = '\n'; *cp = '\0'; } if (file_info->SeeAlso) { sprintf(cp, ".SECTION See Also\n\n"); cp += strlen(cp); strcpy(cp, file_info->SeeAlso); cp += strlen(cp); *cp = '\0'; } ccp = vtkWrapText_FormatComment(comment, 70); free(comment); n = (strlen(ccp) + 400-1)/400; for (i = 0; i < n; i++) { strncpy(temp, &ccp[400*i], 400); temp[400] = '\0'; if (i < n-1) { fprintf(fp, " \"%s\",\n", vtkWrapText_QuoteString(temp, 500)); } else { /* just for the last time */ fprintf(fp, " \"%s\\n\",\n", vtkWrapText_QuoteString(temp, 500)); } } /* for special objects, add constructor signatures to the doc */ if (!is_vtkobject && !data->Template && !data->IsAbstract) { for (j = 0; j < data->NumberOfFunctions; j++) { if (vtkWrapPython_MethodCheck(data, data->Functions[j], hinfo) && vtkWrap_IsConstructor(data, data->Functions[j])) { fprintf(fp," \"%s\\n\",\n", vtkWrapText_FormatSignature( data->Functions[j]->Signature, 70, 2000)); } } } }