Salome HOME
Porting to SALOME 9.1.0.
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI.i
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 /* ModelHighAPI.i */
22 %module(directors="1") ModelHighAPI
23 %feature("director:except") {
24     if ($error != NULL) {
25       PyErr_Print();
26       std::cerr << std::endl;
27       throw Swig::DirectorMethodException();
28     }
29 }
30
31 %{
32   #include "ModelHighAPI_swig.h"
33
34   // fix for SWIG v2.0.4
35   #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj))
36 %}
37
38 %include "doxyhelp.i"
39
40 // import other modules
41 %import "GeomAPI.i"
42 %import "ModelAPI.i"
43 %import "GeomDataAPI.i"
44
45 // to avoid error on this
46 #define MODELHIGHAPI_EXPORT
47
48 // standard definitions
49 %include "typemaps.i"
50 %include "std_list.i"
51 %include "std_pair.i"
52 %include "std_string.i"
53 %include "std_shared_ptr.i"
54
55 // directors
56 %feature("director") ModelHighAPI_Dumper;
57
58 // shared pointers
59 %shared_ptr(ModelHighAPI_Interface)
60 %shared_ptr(ModelHighAPI_Folder)
61
62 // typemaps
63
64 %typemap(in) const ModelHighAPI_Double & (ModelHighAPI_Double temp) {
65   if (PyFloat_Check($input) || PyLong_Check($input)) {
66     temp = ModelHighAPI_Double(PyFloat_AsDouble($input));
67     $1 = &temp;
68   } else if (PyUnicode_Check($input)) {
69     temp = ModelHighAPI_Double(PyUnicode_AsUTF8($input));
70     $1 = &temp;
71   } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
72   } else {
73     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Double, float, int or string.");
74     return NULL;
75   }
76 }
77 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & {
78   $1 = ((PyFloat_Check($input) || PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0;
79 }
80
81 %typemap(in) const ModelHighAPI_Integer & (ModelHighAPI_Integer temp) {
82   if (PyLong_Check($input)) {
83     temp = ModelHighAPI_Integer(static_cast<int>(PyLong_AsLong($input)));
84     $1 = &temp;
85   } else if (PyUnicode_Check($input)) {
86     temp = ModelHighAPI_Integer(PyUnicode_AsUTF8($input));
87     $1 = &temp;
88   } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
89   } else {
90     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Integer, int or string.");
91     return NULL;
92   }
93 }
94 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & {
95   $1 = ((PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0;
96 }
97
98 %typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
99   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
100   std::shared_ptr<ModelAPI_Object> * temp_object;
101   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
102   int newmem = 0;
103   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
104     if (!temp_attribute) {
105       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
106       return NULL;
107     }
108     temp = ModelHighAPI_RefAttr(*temp_attribute);
109     if (newmem & SWIG_CAST_NEW_MEMORY) {
110       delete temp_attribute;
111     }
112     $1 = &temp;
113   } else
114   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
115     if (!temp_object) {
116       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
117       return NULL;
118     }
119     temp = ModelHighAPI_RefAttr(*temp_object);
120     if (newmem & SWIG_CAST_NEW_MEMORY) {
121       delete temp_object;
122     }
123     $1 = &temp;
124   } else
125   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
126     if (!temp_interface) {
127       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
128       return NULL;
129     }
130     temp = ModelHighAPI_RefAttr(*temp_interface);
131     if (newmem & SWIG_CAST_NEW_MEMORY) {
132       delete temp_interface;
133     }
134     $1 = &temp;
135   } else
136   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
137   } else {
138     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
139     return NULL;
140   }
141 }
142
143 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_RefAttr, const ModelHighAPI_RefAttr & {
144   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
145   std::shared_ptr<ModelAPI_Object> * temp_object;
146   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
147   ModelHighAPI_Selection* temp_selection;
148   int newmem = 0;
149   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
150     if (temp_attribute) {
151       $1 = 1;
152     } else {
153       $1 = 0;
154     }
155   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
156     if (temp_object) {
157       $1 = 1;
158     } else {
159       $1 = 0;
160     }
161   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
162     if (temp_interface) {
163       $1 = 1;
164     } else {
165       $1 = 0;
166     }
167   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
168     if (temp_selection) {
169       $1 = 1;
170     } else {
171       $1 = 0;
172     }
173   } else {
174     $1 = 0;
175   }
176 }
177
178 %typemap(in) const ModelHighAPI_Reference & (ModelHighAPI_Reference temp) {
179   std::shared_ptr<ModelAPI_Object> * temp_object;
180   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
181   int newmem = 0;
182   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
183     if (!temp_object) {
184       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
185       return NULL;
186     }
187     temp = ModelHighAPI_Reference(*temp_object);
188     if (newmem & SWIG_CAST_NEW_MEMORY) {
189       delete temp_object;
190     }
191     $1 = &temp;
192   } else
193   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
194     if (!temp_interface) {
195       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
196       return NULL;
197     }
198     temp = ModelHighAPI_Reference(*temp_interface);
199     if (newmem & SWIG_CAST_NEW_MEMORY) {
200       delete temp_interface;
201     }
202     $1 = &temp;
203   } else
204   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
205   } else {
206     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
207     return NULL;
208   }
209 }
210
211 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Reference, const ModelHighAPI_Reference & {
212   std::shared_ptr<ModelAPI_Object> * temp_object;
213   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
214   int newmem = 0;
215   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
216     if (temp_object) {
217       $1 = 1;
218     } else {
219       $1 = 0;
220     }
221   } else
222   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
223     if (temp_interface) {
224       $1 = 1;
225     } else {
226       $1 = 0;
227     }
228   } else {
229     $1 = 0;
230   }
231 }
232
233 %typemap(out) const ModelHighAPI_Selection & {
234   $1_basetype * ptr = new $1_basetype(*$1);
235   $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
236 }
237
238 %typemap(out) const ModelHighAPI_Reference & {
239   $1_basetype * ptr = new $1_basetype(*$1);
240   $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
241 }
242
243 // std::list -> []
244 %template(SelectionList) std::list<ModelHighAPI_Selection>;
245 %template(RefAttrList) std::list<ModelHighAPI_RefAttr>;
246 %template(RefList) std::list<ModelHighAPI_Reference>;
247
248 // std::pair -> []
249 %template(ResultSubShapePair) std::pair<std::shared_ptr<ModelAPI_Result>, std::shared_ptr<GeomAPI_Shape> >;
250
251
252 // fix compilarion error: 'res*' was not declared in this scope
253 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
254 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
255
256 %typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
257   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
258   int newmem = 0;
259   if (PySequence_Check($input)) {
260     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
261       PyObject * item = PySequence_GetItem($input, i);
262       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
263         if (!temp_attribute) {
264           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
265           return NULL;
266         }
267         temp.push_back(ModelHighAPI_RefAttr(*temp_attribute));
268         if (newmem & SWIG_CAST_NEW_MEMORY) {
269           delete temp_attribute;
270         }
271       }
272       Py_DECREF(item);
273     }
274     $1 = &temp;
275   } else {
276     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
277     return NULL;
278   }
279 }
280
281 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
282   std::shared_ptr<ModelAPI_Object> * temp_object;
283   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
284   int newmem = 0;
285   if (PySequence_Check($input)) {
286     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
287       PyObject * item = PySequence_GetItem($input, i);
288       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
289         if (!temp_object) {
290           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
291           return NULL;
292         }
293         temp.push_back(*temp_object);
294         if (newmem & SWIG_CAST_NEW_MEMORY) {
295           delete temp_object;
296         }
297       } else
298       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
299         if (!temp_interface) {
300           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
301           return NULL;
302         }
303         temp.push_back((*temp_interface)->defaultResult());
304         if (newmem & SWIG_CAST_NEW_MEMORY) {
305           delete temp_interface;
306         }
307       }
308       Py_DECREF(item);
309     }
310     $1 = &temp;
311   } else {
312     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
313     return NULL;
314   }
315 }
316
317 %typecheck(SWIG_TYPECHECK_POINTER) std::list<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
318   std::shared_ptr<ModelAPI_Object> * temp_object;
319   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
320   int newmem = 0;
321   if (PySequence_Check($input)) {
322     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
323       PyObject * item = PySequence_GetItem($input, i);
324       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
325         if (temp_object) {
326           $1 = 1;
327         } else {
328           $1 = 0;
329           break;
330         }
331       } else
332       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
333         if (temp_interface) {
334           $1 = 1;
335         } else {
336           $1 = 0;
337           break;
338         }
339       }
340       Py_DECREF(item);
341     }
342   } else {
343     $1 = 0;
344   }
345 }
346
347 // all supported interfaces
348 %include "ModelHighAPI_Double.h"
349 %include "ModelHighAPI_Dumper.h"
350 %include "ModelHighAPI_Integer.h"
351 %include "ModelHighAPI_Interface.h"
352 %include "ModelHighAPI_Folder.h"
353 %include "ModelHighAPI_RefAttr.h"
354 %include "ModelHighAPI_Reference.h"
355 %include "ModelHighAPI_Selection.h"
356 %include "ModelHighAPI_Services.h"
357 %include "ModelHighAPI_Macro.h"
358 %include "ModelHighAPI_Tools.h"