1 //////////////////////////////////////////////////
2 //
3 //   ChModuleIrrlicht.i
4 //
5 //   SWIG configuration file.
6 //   This is processed by SWIG to create the C::E
7 //   wrapper for Python.
8 //
9 ///////////////////////////////////////////////////
10 
11 
12 
13 // Define the module to be used in Python when typing
14 //  'import pychrono.irrlicht'
15 
16 
17 %module(directors="1") irrlicht
18 
19 
20 // Turn on the documentation of members, for more intuitive IDE typing
21 
22 %feature("autodoc", "1");
23 %feature("flatnested", "1");
24 
25 
26 // Turn on the exception handling to intercept C++ exceptions
27 %include "exception.i"
28 
29 %exception {
30   try {
31     $action
catch(const std::exception & e)32   } catch (const std::exception& e) {
33     SWIG_exception(SWIG_RuntimeError, e.what());
34   }
35 }
36 
37 
38 // For optional downcasting of polimorphic objects:
39 %include "../chrono_downcast.i"
40 
41 // For supporting shared pointers:
42 %include <std_shared_ptr.i>
43 
44 
45 
46 // Include C++ headers this way...
47 
48 %{
49 #include "chrono/solver/ChSolver.h"
50 
51 #include <irrlicht.h>
52 #include "chrono_irrlicht/ChIrrAppInterface.h"
53 #include "chrono_irrlicht/ChIrrAssetConverter.h"
54 #include "chrono_irrlicht/ChIrrTools.h"
55 #include "chrono_irrlicht/ChIrrEffects.h"
56 #include "chrono_irrlicht/ChIrrTools.h"
57 #include "chrono_irrlicht/ChIrrUtils.h"
58 #include "chrono_irrlicht/ChIrrCamera.h"
59 using namespace chrono;
60 using namespace chrono::irrlicht;
61 using namespace irr;
62 using namespace core;
63 using namespace scene;
64 using namespace video;
65 using namespace io;
66 using namespace gui;
67 
68 %}
69 
70 
71 // Undefine ChApi and other macros that otherwise SWIG gives a syntax error
72 #define ChApiIrr
73 #define ChApi
74 #define IRRLICHT_API
75 #define _IRR_DEPRECATED_ //
76 #define CH_DEPRECATED(msg)
77 
78 // Include other .i configuration files for SWIG.
79 // These are divided in many .i files, each per a
80 // different c++ class, when possible.
81 
82 %include "std_string.i"
83 %include "std_wstring.i"
84 %include "std_vector.i"
85 %include "typemaps.i"
86 %include "wchar.i"
87 %include "python/cwstring.i"
88 %include "cstring.i"
89 
90 
91 // This is to enable references to double,int,etc. types in function parameters
92 %pointer_class(int,int_ptr);
93 %pointer_class(double,double_ptr);
94 %pointer_class(float,float_ptr);
95 %pointer_class(char,char_ptr);
96 
97 
98 
99 
100 //
101 // For each class, keep updated the  A, B, C sections:
102 //
103 
104 
105 //
106 // A- ENABLE SHARED POINTERS
107 //
108 // Note that this must be done for almost all objects (not only those that are
109 // handled by shered pointers in C++, but all their chidren and parent classes. It
110 // is enough that a single class in an inheritance tree uses %shared_ptr, and all other in the
111 // tree must be promoted to %shared_ptr too).
112 
113 %shared_ptr(chrono::irrlicht::ChIrrNodeAsset)
114 
115 
116 //
117 // B- INCLUDE HEADERS
118 //
119 //
120 // 1)
121 //    When including with %include all the .i files, make sure that
122 // the .i of a derived class is included AFTER the .i of
123 // a base class, otherwise SWIG is not able to build the type
124 // infos.
125 //
126 // 2)
127 //    Then, this said, if one member function in Foo_B.i returns
128 // an object of Foo_A.i (or uses it as a parameter) and yet you must %include
129 // A before B, ex.because of rule 1), a 'forward reference' to A must be done in
130 // B by. Seems that it is enough to write
131 //  mynamespace { class myclass; }
132 // in the .i file, before the %include of the .h, even if already forwarded in .h
133 
134 
135 %import(module = "pychrono.core")  "chrono_python/core/ChClassFactory.i"
136 %import(module = "pychrono.core")  "chrono_python/core/ChSystem.i"
137 %import(module = "pychrono.core")  "chrono_python/core/ChAsset.i"
138 %import(module = "pychrono.core")  "chrono_python/core/ChVector.i"
139 %import(module = "pychrono.core")  "chrono_python/core/ChCoordsys.i"
140 
141 %include "IReferenceCounted.h"
142 %include "IImage.h"
143 %include "IImageWriter.h"
144 %ignore irr::io::createWriteFile;
145 %include "IWriteFile.h"
146 %include "irrTypes.h"
147 %include "vector2d.h"
148 %template(vector2df) irr::core::vector2d<irr::f32>;
149 %template(vector2di) irr::core::vector2d<irr::s32>;
150 %include "vector3d.h"
151 %template(vector3df) irr::core::vector3d<irr::f32>;
152 %template(vector3di) irr::core::vector3d<irr::s32>;
153 %include "rect.h"
154 %template(rectf) irr::core::rect<irr::f32>;
155 %template(recti) irr::core::rect<irr::s32>;
156 %include "SColor.h"
157 %include "SMaterial.h"
158 %include "SMaterialLayer.h"
159 %include "IVideoDriver.h"
160 %include "ISceneNode.h"
161 %include "ICameraSceneNode.h"
162 %include "IrrlichtDevice.h"
163 %include "IMeshSceneNode.h"
164 %include "ISceneManager.h"
165 %include "IGUIEnvironment.h"
166 %include "dimension2d.h"
167 %template(dimension2du) irr::core::dimension2d<irr::u32>;
168 
169 %ignore chrono::irrlicht::ScreenQuadCB;
170 %include "chrono_irrlicht/ChIrrEffects.h"
171 %include "chrono_irrlicht/ChIrrTools.h"
172 %include "chrono_irrlicht/ChIrrCamera.h"
173 %include "chrono_irrlicht/ChIrrUtils.h"
174 %include "ChIrrAppInterface.i"
175 %include "ChIrrAssetConverter.i"
176 %include "ChIrrApp.i"
177 %include "ChIrrNode.i"
178 %include "ChIrrNodeAsset.i"
179 
180 
181 
182 //
183 // C- DOWNCASTING OF SHARED POINTERS
184 //
185 // This is not automatic in Python + SWIG, except if one uses the
186 // %downcast_output_sharedptr(...) macro, as above, but this causes
187 // a lot of code bloat.
188 // Alternatively, in the following we create a set of Python-side
189 // functions to perform casting by hand, thank to the macro
190 // %DefSharedPtrDynamicDowncast(base,derived).
191 // Do not specify the "chrono::" namespace before base or derived!
192 // Later, in python, you can do the following:
193 //  myvis = chrono.CastToChVisualizationShared(myasset)
194 //  print ('Could be cast to visualization object?', !myvis.IsNull())
195 
196 %DefSharedPtrDynamicDowncast2NS(chrono, chrono::irrlicht, ChAsset,ChIrrNodeAsset)
197 
198 
199 //
200 // ADDITIONAL C++ FUNCTIONS / CLASSES THAT ARE USED ONLY FOR PYTHON WRAPPER
201 //
202 
203 /*
204 %inline %{
205 
206 
207 %}
208 */
209 
210 // Add function to support bytes exporting
211 %extend  irr::video::IImage{
212 		%cstring_output_allocate_size(char **buffer, unsigned int *size, free(*$1) );
get_img_bytes(char ** buffer,unsigned int * size)213 		void get_img_bytes(char **buffer, unsigned int *size)
214 					{
215 						*size = self->getImageDataSizeInBytes();
216 						*buffer = (char*)malloc(*size);
217 						//char* dest = (char*)self->lock();
218 						strcpy(*buffer,  (char*)self->lock());
219 						self->unlock();
220 
221 					}
222 		};
223 //
224 // ADD PYTHON CODE
225 //
226 
227 /*
228 %pythoncode %{
229 
230 %}
231 */
232 
233 
234