Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Common/vtkPythonUtil.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkPythonUtil.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00040 #include "vtkObject.h"
00041 #include "vtkTimeStamp.h"
00042 #include "Python.h"
00043 #include "vtkCommand.h"
00044 
00045 #if defined(WIN32)
00046 #if defined(vtkCommonPython_EXPORTS)
00047   #define VTK_PYTHON_EXPORT __declspec( dllexport )
00048 #else
00049     #define VTK_PYTHON_EXPORT __declspec( dllimport )
00050 #endif
00051 #else
00052   #define VTK_PYTHON_EXPORT
00053 #endif
00054 
00055 // This is the VTK/Python 'class,' it contains the method list and a pointer
00056 // to the superclass
00057 typedef vtkObject *(*vtknewfunc)();
00058 
00059 typedef struct {
00060   PyObject_HEAD
00061   PyMethodDef *vtk_methods;
00062   vtknewfunc vtk_new;
00063   char *vtk_name;
00064   char *vtk_module;
00065   char *vtk_doc;
00066   PyObject *vtk_bases;
00067 } PyVTKClass;
00068 
00069 // This is the VTK/Python 'object,' it contains the python object header
00070 // plus a pointer to the associated vtkObject and PyVTKClass.
00071 typedef struct {
00072   PyObject_HEAD
00073   vtkObject *vtk_ptr;
00074   PyVTKClass *vtk_class;
00075 } PyVTKObject;
00076 
00077 // This for objects not derived from vtkObject
00078 typedef struct {
00079   PyObject_HEAD
00080   void *vtk_ptr;
00081   PyMethodDef *vtk_methods;
00082   char *vtk_name;
00083   char *vtk_doc;
00084 } PyVTKSpecialObject;
00085 
00086 // Standard methods for all vtk/python objects
00087 extern "C" 
00088 {
00089 VTK_PYTHON_EXPORT int PyVTKObject_Check(PyObject *obj);
00090 VTK_PYTHON_EXPORT int PyVTKClass_Check(PyObject *obj);
00091 VTK_PYTHON_EXPORT int PyVTKSpecialObjectCheck(PyObject *obj);
00092 VTK_PYTHON_EXPORT PyObject *PyVTKObject_New(PyObject *vtkclass, vtkObject *ptr);
00093 VTK_PYTHON_EXPORT PyObject *PyVTKClass_New(vtknewfunc constructor, PyMethodDef *methods,
00094                          char *classname, char *modulename, char *docstring[],
00095                          PyObject *base);
00096 VTK_PYTHON_EXPORT PyObject *PyVTKSpecialObject_New(void *ptr, PyMethodDef *methods,
00097                                  char *classname, char *docstring[]);
00098 
00099 // this is a special version of ParseTuple that handles both bound
00100 // and unbound method calls for VTK objects
00101 VTK_PYTHON_EXPORT vtkObject *PyArg_VTKParseTuple(PyObject *self, PyObject *args, 
00102                                char *format, ...);
00103 }
00104 
00105 // Add a PyVTKClass to the type lookup table, this allows us to later
00106 // create object given only the class name.
00107 extern VTK_PYTHON_EXPORT void vtkPythonAddClassToHash(PyObject *obj, char *type); 
00108 
00109 // Extract the vtkObject from a PyVTKObject.  If the PyObject is not a 
00110 // PyVTKObject, or is not a PyVTKObject of the specified type, the python
00111 // error indicator will be set.
00112 // Special behaviour: Py_None is converted to NULL without no error.
00113 extern VTK_PYTHON_EXPORT vtkObject *vtkPythonGetPointerFromObject(PyObject *obj, char *type);
00114 
00115 // Convert a vtkObject to a PyVTKObject.  This will first check to see if
00116 // the PyVTKObject already exists, and create a new PyVTKObject if necessary.
00117 // This function also passes ownership of the reference to the PyObject.
00118 // Special behaviour: NULL is converted to Py_None.
00119 extern VTK_PYTHON_EXPORT PyObject *vtkPythonGetObjectFromPointer(vtkObject *ptr);
00120 
00121 // Try to convert some PyObject into a PyVTKObject, currently conversion
00122 // is supported for SWIG-style mangled pointer strings.
00123 extern VTK_PYTHON_EXPORT PyObject *vtkPythonGetObjectFromObject(PyObject *arg, const char *type);
00124 
00125 // Add and delete PyVTKObject/vtkObject pairs from the wrapper hash table,
00126 // these methods do not change the reference counts of either the vtkObject
00127 // or the PyVTKObject.
00128 extern VTK_PYTHON_EXPORT void vtkPythonAddObjectToHash(PyObject *obj, vtkObject *anInstance);
00129 extern VTK_PYTHON_EXPORT void vtkPythonDeleteObjectFromHash(PyObject *obj);
00130 
00131 // Utility functions for creating/usinge SWIG-style mangled pointer strings.
00132 extern VTK_PYTHON_EXPORT char *vtkPythonManglePointer(void *ptr, const char *type);
00133 extern VTK_PYTHON_EXPORT void *vtkPythonUnmanglePointer(char *ptrText, int *len,
00134                                       const char *type);
00135 
00136 // check array arguments sent through the wrappers to see if the underlying
00137 // C++ method changed the values, and attempt to modify the original python
00138 // sequence (list or tuple) if so.
00139 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, char *a, int n);
00140 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, unsigned char *a, int n);
00141 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, short *a, int n);
00142 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, unsigned short *a, int n);
00143 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, int *a, int n);
00144 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, unsigned int *a, int n);
00145 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, long *a, int n);
00146 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, unsigned long *a, int n);
00147 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, float *a, int n);
00148 extern VTK_PYTHON_EXPORT int vtkPythonCheckArray(PyObject *args, int i, double *a, int n);
00149 
00150 // For use by SetXXMethod() , SetXXMethodArgDelete()
00151 extern VTK_PYTHON_EXPORT void vtkPythonVoidFunc(void *);
00152 extern VTK_PYTHON_EXPORT void vtkPythonVoidFuncArgDelete(void *);
00153 
00154 // To allow Python to use the vtkCommand features
00155 class vtkPythonCommand : public vtkCommand
00156 {
00157 public:
00158   static vtkPythonCommand *New() { return new vtkPythonCommand; };
00159 
00160   void SetObject(PyObject *o);
00161   void Execute(vtkObject *ptr, unsigned long eventtype, void *);
00162  
00163   PyObject *obj;
00164 protected:
00165   vtkPythonCommand();
00166   ~vtkPythonCommand(); 
00167 };
00168 
00169 

Generated on Thu Mar 28 14:19:17 2002 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001