Salome HOME
Issue #2971: Naming issue in a group when loading a dump file
[modules/shaper.git] / src / ModelHighAPI / ModelHighAPI.i
1 // Copyright (C) 2014-2019  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 email : webmaster.salome@opencascade.com
18 //
19
20 /* ModelHighAPI.i */
21 %module(directors="1") ModelHighAPI
22 %feature("director:except") {
23     if ($error != NULL) {
24       PyErr_Print();
25       std::cerr << std::endl;
26       throw Swig::DirectorMethodException();
27     }
28 }
29
30 %{
31   #include "ModelHighAPI_swig.h"
32
33   // fix for SWIG v2.0.4
34   #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj))
35 %}
36
37 %include "doxyhelp.i"
38
39 // import other modules
40 %import "GeomAPI.i"
41 %import "ModelAPI.i"
42 %import "GeomDataAPI.i"
43
44 // to avoid error on this
45 #define MODELHIGHAPI_EXPORT
46
47 // standard definitions
48 %include "typemaps.i"
49 %include "std_list.i"
50 %include "std_pair.i"
51 %include "std_string.i"
52 %include "std_shared_ptr.i"
53
54 // directors
55 %feature("director") ModelHighAPI_Dumper;
56
57 // shared pointers
58 %shared_ptr(ModelHighAPI_Interface)
59 %shared_ptr(ModelHighAPI_Folder)
60
61 // typemaps
62
63 %typemap(in) const ModelHighAPI_Double & (ModelHighAPI_Double temp) {
64   if (PyFloat_Check($input) || PyLong_Check($input)) {
65     temp = ModelHighAPI_Double(PyFloat_AsDouble($input));
66     $1 = &temp;
67   } else if (PyUnicode_Check($input)) {
68     temp = ModelHighAPI_Double(PyUnicode_AsUTF8($input));
69     $1 = &temp;
70   } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
71   } else {
72     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Double, float, int or string.");
73     return NULL;
74   }
75 }
76 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Double, const ModelHighAPI_Double & {
77   $1 = ((PyFloat_Check($input) || PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0;
78 }
79
80 %typemap(in) const ModelHighAPI_Integer & (ModelHighAPI_Integer temp) {
81   if (PyLong_Check($input)) {
82     temp = ModelHighAPI_Integer(static_cast<int>(PyLong_AsLong($input)));
83     $1 = &temp;
84   } else if (PyUnicode_Check($input)) {
85     temp = ModelHighAPI_Integer(PyUnicode_AsUTF8($input));
86     $1 = &temp;
87   } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
88   } else {
89     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Integer, int or string.");
90     return NULL;
91   }
92 }
93 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Integer, const ModelHighAPI_Integer & {
94   $1 = ((PyLong_Check($input) || PyUnicode_Check($input)) && !PyBool_Check($input)) ? 1 : 0;
95 }
96
97 %typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
98   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
99   std::shared_ptr<ModelAPI_Object> * temp_object;
100   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
101   int newmem = 0;
102   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
103     if (!temp_attribute) {
104       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
105       return NULL;
106     }
107     temp = ModelHighAPI_RefAttr(*temp_attribute);
108     if (newmem & SWIG_CAST_NEW_MEMORY) {
109       delete temp_attribute;
110     }
111     $1 = &temp;
112   } else
113   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
114     if (!temp_object) {
115       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
116       return NULL;
117     }
118     temp = ModelHighAPI_RefAttr(*temp_object);
119     if (newmem & SWIG_CAST_NEW_MEMORY) {
120       delete temp_object;
121     }
122     $1 = &temp;
123   } else
124   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
125     if (!temp_interface) {
126       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
127       return NULL;
128     }
129     temp = ModelHighAPI_RefAttr(*temp_interface);
130     if (newmem & SWIG_CAST_NEW_MEMORY) {
131       delete temp_interface;
132     }
133     $1 = &temp;
134   } else
135   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
136   } else {
137     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
138     return NULL;
139   }
140 }
141
142 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_RefAttr, const ModelHighAPI_RefAttr & {
143   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
144   std::shared_ptr<ModelAPI_Object> * temp_object;
145   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
146   ModelHighAPI_Selection* temp_selection;
147   int newmem = 0;
148   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
149     if (temp_attribute) {
150       $1 = 1;
151     } else {
152       $1 = 0;
153     }
154   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
155     if (temp_object) {
156       $1 = 1;
157     } else {
158       $1 = 0;
159     }
160   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
161     if (temp_interface) {
162       $1 = 1;
163     } else {
164       $1 = 0;
165     }
166   } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
167     if (temp_selection) {
168       $1 = 1;
169     } else {
170       $1 = 0;
171     }
172   } else {
173     $1 = 0;
174   }
175 }
176
177 %typemap(in) const ModelHighAPI_Reference & (ModelHighAPI_Reference temp) {
178   std::shared_ptr<ModelAPI_Object> * temp_object;
179   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
180   int newmem = 0;
181   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
182     if (!temp_object) {
183       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
184       return NULL;
185     }
186     temp = ModelHighAPI_Reference(*temp_object);
187     if (newmem & SWIG_CAST_NEW_MEMORY) {
188       delete temp_object;
189     }
190     $1 = &temp;
191   } else
192   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
193     if (!temp_interface) {
194       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
195       return NULL;
196     }
197     temp = ModelHighAPI_Reference(*temp_interface);
198     if (newmem & SWIG_CAST_NEW_MEMORY) {
199       delete temp_interface;
200     }
201     $1 = &temp;
202   } else
203   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
204   } else {
205     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface or ModelAPI_Object.");
206     return NULL;
207   }
208 }
209
210 %typecheck(SWIG_TYPECHECK_POINTER) ModelHighAPI_Reference, const ModelHighAPI_Reference & {
211   std::shared_ptr<ModelAPI_Object> * temp_object;
212   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
213   int newmem = 0;
214   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
215     if (temp_object) {
216       $1 = 1;
217     } else {
218       $1 = 0;
219     }
220   } else
221   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
222     if (temp_interface) {
223       $1 = 1;
224     } else {
225       $1 = 0;
226     }
227   } else {
228     $1 = 0;
229   }
230 }
231
232 %typemap(out) const ModelHighAPI_Selection & {
233   $1_basetype * ptr = new $1_basetype(*$1);
234   $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
235 }
236
237 %typemap(out) const ModelHighAPI_Reference & {
238   $1_basetype * ptr = new $1_basetype(*$1);
239   $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
240 }
241
242 // std::list -> []
243 %template(SelectionList) std::list<ModelHighAPI_Selection>;
244 %template(SelectionListList) std::list<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 %template(StringsPair) std::pair<std::string, std::string>;
251
252
253 // fix compilarion error: 'res*' was not declared in this scope
254 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
255 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
256
257 %typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
258   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
259   int newmem = 0;
260   if (PySequence_Check($input)) {
261     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
262       PyObject * item = PySequence_GetItem($input, i);
263       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
264         if (!temp_attribute) {
265           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
266           return NULL;
267         }
268         temp.push_back(ModelHighAPI_RefAttr(*temp_attribute));
269         if (newmem & SWIG_CAST_NEW_MEMORY) {
270           delete temp_attribute;
271         }
272       }
273       Py_DECREF(item);
274     }
275     $1 = &temp;
276   } else {
277     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
278     return NULL;
279   }
280 }
281
282 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
283   std::shared_ptr<ModelAPI_Object> * temp_object;
284   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
285   int newmem = 0;
286   if (PySequence_Check($input)) {
287     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
288       PyObject * item = PySequence_GetItem($input, i);
289       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
290         if (!temp_object) {
291           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
292           return NULL;
293         }
294         temp.push_back(*temp_object);
295         if (newmem & SWIG_CAST_NEW_MEMORY) {
296           delete temp_object;
297         }
298       } else
299       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
300         if (!temp_interface) {
301           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
302           return NULL;
303         }
304         temp.push_back((*temp_interface)->defaultResult());
305         if (newmem & SWIG_CAST_NEW_MEMORY) {
306           delete temp_interface;
307         }
308       }
309       Py_DECREF(item);
310     }
311     $1 = &temp;
312   } else {
313     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
314     return NULL;
315   }
316 }
317
318 %typecheck(SWIG_TYPECHECK_POINTER) std::list<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
319   std::shared_ptr<ModelAPI_Object> * temp_object;
320   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
321   int newmem = 0;
322   if (PySequence_Check($input)) {
323     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
324       PyObject * item = PySequence_GetItem($input, i);
325       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
326         if (temp_object) {
327           $1 = 1;
328         } else {
329           $1 = 0;
330           break;
331         }
332       } else
333       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
334         if (temp_interface) {
335           $1 = 1;
336         } else {
337           $1 = 0;
338           break;
339         }
340       }
341       Py_DECREF(item);
342     }
343   } else {
344     $1 = 0;
345   }
346 }
347
348 %typemap(in) const std::list<double> & (std::list<double> temp) {
349   double * temp_attribute;
350   int newmem = 0;
351   if (PyTuple_Check($input)) {
352     for (Py_ssize_t i = 0; i < PyTuple_Size($input); ++i) {
353       PyObject * item = PySequence_GetItem($input, i);
354       if (PyNumber_Check(item)) {
355         temp.push_back((double)PyFloat_AsDouble(item));
356       } else {
357         PyErr_SetString(PyExc_TypeError, "argument must double value.");
358         return NULL;
359       }
360       Py_DECREF(item);
361     }
362     $1 = &temp;
363   } else {
364     PyErr_SetString(PyExc_ValueError, "argument must be a tuple of double values.");
365     return NULL;
366   }
367 }
368
369 %typecheck(SWIG_TYPECHECK_POINTER) std::list<double>, const std::list<double>& {
370   double * temp_object;
371   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
372   int newmem = 0;
373   if (PyTuple_Check($input)) {
374     for (Py_ssize_t i = 0; i < PyTuple_Size($input); ++i) {
375       PyObject * item = PySequence_GetItem($input, i);
376       if (PyNumber_Check(item)) {
377         $1 = 1;
378       } else {
379         $1 = 0;
380         break;
381       }
382       Py_DECREF(item);
383     }
384   } else {
385     $1 = 0;
386   }
387 }
388
389 // all supported interfaces
390 %include "ModelHighAPI_Double.h"
391 %include "ModelHighAPI_Dumper.h"
392 %include "ModelHighAPI_Integer.h"
393 %include "ModelHighAPI_Interface.h"
394 %include "ModelHighAPI_Folder.h"
395 %include "ModelHighAPI_RefAttr.h"
396 %include "ModelHighAPI_Reference.h"
397 %include "ModelHighAPI_Selection.h"
398 %include "ModelHighAPI_Services.h"
399 %include "ModelHighAPI_Macro.h"
400 %include "ModelHighAPI_Tools.h"