Commit 9e0906e5 authored by David Gobbi's avatar David Gobbi Committed by Marcus D. Hanwell
Browse files

ENH: some much-needed code reorganization in vtkWraPython.c

parent 84beb47c
......@@ -2579,99 +2579,11 @@ static void vtkWrapPython_GenerateSpecialHeaders(
}
/* -------------------------------------------------------------------- */
/* This is the main entry point for the python wrappers. When called,
* it will print the vtkXXPython.c file contents to "fp". */
void vtkParseOutput(FILE *fp, FileInfo *data)
/* generate code for custom methods for some classes */
static void vtkWrapPython_CustomMethods(FILE *fp, FileInfo *data)
{
static const char *compare_consts[6] = {
"Py_LT", "Py_LE", "Py_EQ", "Py_NE", "Py_GT", "Py_GE" };
static const char *compare_tokens[6] = {
"<", "<=", "==", "!=", ">", ">=" };
int compare_ops = 0;
int has_hash = 0;
int class_has_new = 0;
int i;
/* the VTK_WRAPPING_CXX tells header files where they're included from */
fprintf(fp,
"// python wrapper for %s object\n//\n"
"#define VTK_WRAPPING_CXX\n",
data->ClassName);
/* unless this is vtkObjectBase, define VTK_STREAMS_FWD_ONLY */
if (strcmp("vtkObjectBase",data->ClassName) != 0)
{
/* Block inclusion of full streams. */
fprintf(fp,
"#define VTK_STREAMS_FWD_ONLY\n");
}
/* include vtkPython.h on all platforms but apple */
fprintf(fp,
"#if !defined(__APPLE__)\n"
"#include \"vtkPython.h\"\n"
"#undef _XOPEN_SOURCE /* Conflicts with standards.h. */\n"
"#undef _THREAD_SAFE /* Conflicts with pthread.h. */\n"
"#endif\n");
/* lots of important utility functions are defined in vtkPythonUtil.h */
fprintf(fp,
"#include \"vtkPythonUtil.h\"\n");
/* vtkPythonCommand is needed to wrap vtkObject.h */
if (strcmp("vtkObject", data->ClassName) == 0)
{
fprintf(fp,
"#include \"vtkPythonCommand.h\"\n");
}
/* generate includes for any special types that are used */
vtkWrapPython_GenerateSpecialHeaders(fp, data);
/* the header file for the wrapped class */
fprintf(fp,
"#include \"%s.h\"\n",
data->ClassName);
if ((data->NumberOfSuperClasses == 0) && !(data->IsAbstract))
{
fprintf(fp,
"\n"
"#include <vtksys/ios/sstream>\n");
}
/* do the export of the main entry point */
fprintf(fp,
"\n"
"#if defined(WIN32)\n"
"extern \"C\" { __declspec( dllexport ) PyObject *PyVTKClass_%sNew(const char *); }\n"
"#else\n"
"extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n"
"#endif\n"
"\n",
data->ClassName, data->ClassName);
/* bring in all the superclasses */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
fprintf(fp,
"extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n",
data->SuperClasses[i]);
}
/* prototype for the docstring function */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"\n"
"static const char **%sDoc();\n"
"\n",
data->ClassName);
}
/* the python vtkObject needs special hooks for observers */
if (!strcmp("vtkObject",data->ClassName))
if (strcmp("vtkObject",data->ClassName) == 0)
{
/* Add the AddObserver method to vtkObject. */
fprintf(fp,
......@@ -2766,29 +2678,13 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
"\n",
data->ClassName, data->ClassName);
}
}
/* check for New() function */
for (i = 0; i < data->NumberOfFunctions; i++)
{
if (data->Functions[i].Name &&
strcmp("New",data->Functions[i].Name) == 0 &&
data->Functions[i].NumberOfArguments == 0)
{
class_has_new = 1;
}
}
/* now output all the methods are wrappable */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
vtkWrapPython_GenerateMethods(fp, data, class_has_new, 0);
}
/* output the class initilization function */
/* the New method for vtkObjectBase */
if (strcmp(data->ClassName,"vtkObjectBase") == 0)
{
/* -------------------------------------------------------------------- */
/* generate the New method for a vtkObjectBase object */
static void vtkWrapPython_GenerateObjectNew(
FILE *fp, FileInfo *data, int class_has_new)
{
if (class_has_new)
{
fprintf(fp,
......@@ -2820,57 +2716,38 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
fprintf(fp,
" Py%sMethods,\n"
" \"%s\",modulename,\n"
" %sDoc(),0);\n"
"}\n"
"\n",
" %sDoc(),",
data->ClassName, data->ClassName, data->ClassName);
}
/* the New method for descendants of vtkObjectBase */
else if (data->NumberOfSuperClasses)
{
if (class_has_new)
{
fprintf(fp,
"static vtkObjectBase *%sStaticNew()\n"
"{\n"
" return %s::New();\n"
"}\n"
"\n",
data->ClassName, data->ClassName);
}
fprintf(fp,
"PyObject *PyVTKClass_%sNew(const char *modulename)\n"
"{\n",
data->ClassName);
if (class_has_new)
if (strcmp(data->ClassName,"vtkObjectBase") == 0)
{
fprintf(fp,
" return PyVTKClass_New(&%sStaticNew,\n",
data->ClassName);
fprintf(fp, "0);\n");
}
else
{
fprintf(fp,
" return PyVTKClass_New(NULL,\n");
fprintf(fp, "\n"
" PyVTKClass_%sNew(modulename));\n",
data->SuperClasses[0]);
}
fprintf(fp,
" Py%sMethods,\n"
" \"%s\",modulename,\n"
" %sDoc(),\n"
" PyVTKClass_%sNew(modulename));\n"
"}\n"
"\n",
data->ClassName, data->ClassName, data->ClassName,
data->SuperClasses[0]);
}
"\n");
}
/* -------------------------------------------------------------------- */
/* generate extra functions for a special object */
static void vtkWrapPython_GenerateSpecialObjectNew(
FILE *fp, FileInfo *data, int class_has_new)
{
static const char *compare_consts[6] = {
"Py_LT", "Py_LE", "Py_EQ", "Py_NE", "Py_GT", "Py_GE" };
static const char *compare_tokens[6] = {
"<", "<=", "==", "!=", ">", ">=" };
int compare_ops = 0;
int has_hash = 0;
int i;
/* the New method of 'special' non-vtkObject classes */
else if (!data->IsAbstract)
{
/* handle all constructors */
vtkWrapPython_GenerateMethods(fp, data, class_has_new, 1);
......@@ -2930,8 +2807,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
}
else if (strcmp(data->ClassName, "vtkTimeStamp") == 0)
{
compare_ops =
( (1 << Py_LT) | (1 << Py_GT) );
compare_ops = ( (1 << Py_LT) | (1 << Py_GT) );
}
/* the compare function */
......@@ -3050,6 +2926,134 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
data->ClassName, data->ClassName, data->ClassName,
data->ClassName, data->ClassName, data->ClassName,
data->ClassName, data->ClassName);
}
/* -------------------------------------------------------------------- */
/* This is the main entry point for the python wrappers. When called,
* it will print the vtkXXPython.c file contents to "fp". */
void vtkParseOutput(FILE *fp, FileInfo *data)
{
int class_has_new = 0;
int is_vtk_object = 1;
int i;
/* the VTK_WRAPPING_CXX tells header files where they're included from */
fprintf(fp,
"// python wrapper for %s object\n//\n"
"#define VTK_WRAPPING_CXX\n",
data->ClassName);
/* unless this is vtkObjectBase, define VTK_STREAMS_FWD_ONLY */
if (strcmp("vtkObjectBase",data->ClassName) != 0)
{
/* Block inclusion of full streams. */
fprintf(fp,
"#define VTK_STREAMS_FWD_ONLY\n");
}
/* include vtkPython.h on all platforms but apple */
fprintf(fp,
"#if !defined(__APPLE__)\n"
"#include \"vtkPython.h\"\n"
"#undef _XOPEN_SOURCE /* Conflicts with standards.h. */\n"
"#undef _THREAD_SAFE /* Conflicts with pthread.h. */\n"
"#endif\n");
/* lots of important utility functions are defined in vtkPythonUtil.h */
fprintf(fp,
"#include \"vtkPythonUtil.h\"\n");
/* vtkPythonCommand is needed to wrap vtkObject.h */
if (strcmp("vtkObject", data->ClassName) == 0)
{
fprintf(fp,
"#include \"vtkPythonCommand.h\"\n");
}
/* generate includes for any special types that are used */
vtkWrapPython_GenerateSpecialHeaders(fp, data);
/* the header file for the wrapped class */
fprintf(fp,
"#include \"%s.h\"\n",
data->ClassName);
/* is this isn't a vtkObjectBase-derived object, then it is special */
if (strcmp(data->ClassName,"vtkObjectBase") != 0 &&
data->NumberOfSuperClasses == 0)
{
is_vtk_object = 0;
}
/* add sstream header for special objects and vtkObjectBase*/
if (strcmp(data->ClassName, "vtkObjectBase") == 0 ||
(!is_vtk_object && !data->IsAbstract))
{
fprintf(fp,
"\n"
"#include <vtksys/ios/sstream>\n");
}
/* do the export of the main entry point */
fprintf(fp,
"\n"
"#if defined(WIN32)\n"
"extern \"C\" { __declspec( dllexport ) PyObject *PyVTKClass_%sNew(const char *); }\n"
"#else\n"
"extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n"
"#endif\n"
"\n",
data->ClassName, data->ClassName);
/* bring in all the superclasses */
for (i = 0; i < data->NumberOfSuperClasses; i++)
{
fprintf(fp,
"extern \"C\" { PyObject *PyVTKClass_%sNew(const char *); }\n",
data->SuperClasses[i]);
}
/* prototype for the docstring function */
if (data->NumberOfSuperClasses || !data->IsAbstract)
{
fprintf(fp,
"\n"
"static const char **%sDoc();\n"
"\n",
data->ClassName);
}
/* check for New() function */
for (i = 0; i < data->NumberOfFunctions; i++)
{
if (data->Functions[i].Name &&
strcmp("New",data->Functions[i].Name) == 0 &&
data->Functions[i].NumberOfArguments == 0)
{
class_has_new = 1;
}
}
/* output any custom methods */
vtkWrapPython_CustomMethods(fp, data);
/* now output all the methods are wrappable */
if (is_vtk_object || !data->IsAbstract)
{
vtkWrapPython_GenerateMethods(fp, data, class_has_new, 0);
}
/* output the class initilization function for VTK objects */
if (is_vtk_object)
{
vtkWrapPython_GenerateObjectNew(fp, data, class_has_new);
}
/* output the class initilization function for special objects */
else if (!data->IsAbstract)
{
vtkWrapPython_GenerateSpecialObjectNew(fp, data, class_has_new);
}
/* the New method for un-wrappable classes returns "NULL" */
......@@ -3065,7 +3069,7 @@ void vtkParseOutput(FILE *fp, FileInfo *data)
}
/* the docstring for the class, as a static var ending in "Doc" */
if (data->NumberOfSuperClasses || !data->IsAbstract)
if (is_vtk_object || !data->IsAbstract)
{
fprintf(fp,
"const char **%sDoc()\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment