VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPythonUtil.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 00019 #ifndef __vtkPythonUtil_h 00020 #define __vtkPythonUtil_h 00021 00022 #include "vtkPython.h" 00023 #include "PyVTKClass.h" 00024 #include "PyVTKMutableObject.h" 00025 #include "PyVTKObject.h" 00026 #include "PyVTKSpecialObject.h" 00027 00028 class vtkPythonClassMap; 00029 class vtkPythonCommand; 00030 class vtkPythonCommandList; 00031 class vtkPythonGhostMap; 00032 class vtkPythonObjectMap; 00033 class vtkPythonSpecialTypeMap; 00034 class vtkStdString; 00035 class vtkUnicodeString; 00036 class vtkVariant; 00037 00038 extern "C" void vtkPythonUtilDelete(); 00039 00040 class VTKWRAPPINGPYTHONCORE_EXPORT vtkPythonUtil 00041 { 00042 public: 00043 00046 static const char *PythonicClassName(const char *classname); 00047 00050 static void AddClassToMap(PyObject *obj, const char *classname); 00051 00053 static PyObject *FindClass(const char *classname); 00054 00058 static PyObject *FindNearestBaseClass(vtkObjectBase *ptr); 00059 00061 00065 static vtkObjectBase *GetPointerFromObject(PyObject *obj, 00066 const char *classname); 00068 00073 static PyObject *GetObjectFromPointer(vtkObjectBase *ptr); 00074 00078 static void *SIPGetPointerFromObject(PyObject *obj, const char *classname); 00079 00081 00083 static PyObject *SIPGetObjectFromPointer( 00084 const void *ptr, const char* classname, bool is_new); 00086 00089 static PyObject *GetObjectFromObject(PyObject *arg, const char *type); 00090 00094 static void AddObjectToMap(PyObject *obj, vtkObjectBase *anInstance); 00095 00098 static void RemoveObjectFromMap(PyObject *obj); 00099 00101 00103 static PyVTKSpecialType *AddSpecialTypeToMap( 00104 PyTypeObject *pytype, PyMethodDef *methods, PyMethodDef *constructors, 00105 const char *docstring[], PyVTKSpecialCopyFunc copyfunc); 00107 00109 static PyVTKSpecialType *FindSpecialType(const char *classname); 00110 00112 00119 static void *GetPointerFromSpecialObject( 00120 PyObject *obj, const char *result_type, PyObject **newobj); 00122 00125 static PyObject *BuildDocString(const char *docstring[]); 00126 00128 static char *ManglePointer(const void *ptr, const char *type); 00129 00131 static void *UnmanglePointer(char *ptrText, int *len, const char *type); 00132 00134 static long VariantHash(const vtkVariant *variant); 00135 00137 00142 static void RegisterPythonCommand(vtkPythonCommand*); 00143 static void UnRegisterPythonCommand(vtkPythonCommand*); 00145 00146 private: 00147 vtkPythonUtil(); 00148 ~vtkPythonUtil(); 00149 vtkPythonUtil(const vtkPythonUtil&); // Not implemented. 00150 void operator=(const vtkPythonUtil&); // Not implemented. 00151 00152 vtkPythonObjectMap *ObjectMap; 00153 vtkPythonGhostMap *GhostMap; 00154 vtkPythonClassMap *ClassMap; 00155 vtkPythonSpecialTypeMap *SpecialTypeMap; 00156 vtkPythonCommandList *PythonCommandList; 00157 00158 friend void vtkPythonUtilDelete(); 00159 friend void vtkPythonUtilCreateIfNeeded(); 00160 }; 00161 00162 // For use by SetXXMethod() , SetXXMethodArgDelete() 00163 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFunc(void *); 00164 extern VTKWRAPPINGPYTHONCORE_EXPORT void vtkPythonVoidFuncArgDelete(void *); 00165 00166 // The following macro is used to suppress missing initializer 00167 // warnings. Python documentation says these should not be necessary. 00168 // We define it as a macro in case the length needs to change across 00169 // python versions. 00170 #if PY_VERSION_HEX >= 0x02060000 // for tp_version_tag 00171 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00172 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 0, 00173 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ 00174 0, 0, 00175 #elif PY_VERSION_HEX >= 0x02030000 00176 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00177 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0, 00178 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED \ 00179 0, 00180 #elif PY_VERSION_HEX >= 0x02020000 00181 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED \ 00182 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 00183 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED 00184 #else 00185 #define VTK_PYTHON_UTIL_SUPRESS_UNINITIALIZED 00186 #define VTK_WRAP_PYTHON_SUPRESS_UNINITIALIZED 00187 #endif 00188 00189 #if PY_VERSION_HEX < 0x02050000 00190 typedef int Py_ssize_t; 00191 #endif 00192 00193 #endif