Salome HOME
90c2a768159d9604d52ec59847209ca2b900db0b
[modules/shaper.git] / src / FiltersAPI / FiltersAPI.i
1 // Copyright (C) 2014-2021  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 /* FiltersAPI.i */
21
22 %module FiltersAPI
23
24 %{
25   #include "FiltersAPI_swig.h"
26
27   // fix for SWIG v2.0.4
28   #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj))
29 %}
30
31 %include "doxyhelp.i"
32
33 // import other modules
34 %import "ModelHighAPI.i"
35
36 // to avoid error on this
37 #define FILTERSAPI_EXPORT
38
39 // standard definitions
40 %include "typemaps.i"
41 %include "std_list.i"
42 %include "std_shared_ptr.i"
43
44 // shared pointers
45 %shared_ptr(FiltersAPI_Feature)
46 %shared_ptr(FiltersAPI_Filter)
47
48 // function with named parameters
49 %feature("kwargs") addFilter;
50
51
52 // std::list -> []
53 %template(FilterAPIList) std::list<std::shared_ptr<FiltersAPI_Filter> >;
54 %template(ArgumentList) std::list<FiltersAPI_Argument>;
55
56 // fix compilarion error: 'res*' was not declared in this scope
57 %typemap(freearg) const std::list<FiltersAPI_Argument> & {}
58
59 %typecheck(SWIG_TYPECHECK_POINTER) std::list<FiltersAPI_Argument>, const std::list<FiltersAPI_Argument> & {
60   ModelHighAPI_Selection* temp_selection;
61   std::string* temp_string;
62   int newmem = 0;
63   $1 = 1;
64   if (PySequence_Check($input)) {
65     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
66       PyObject * item = PySequence_GetItem($input, i);
67       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
68         if (!temp_selection) {
69           $1 = 0;
70         }
71       } else
72       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_string, $descriptor(std::string *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
73         if (!temp_string) {
74           $1 = 0;
75         }
76       } else
77       if (!PyFloat_Check(item) && PyLong_Check(item))
78         $1 = 0;
79       else
80       if (!PyUnicode_Check(item) && !PyBool_Check(item))
81         $1 = 0;
82     }
83   }
84 }
85
86 %typemap(in) const std::list<FiltersAPI_Argument> & (std::list<FiltersAPI_Argument> temp) {
87   ModelHighAPI_Selection* temp_selection;
88   std::string* temp_string;
89   ModelHighAPI_Double* temp_double;
90   int newmem = 0;
91   if (PySequence_Check($input)) {
92     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
93       PyObject * item = PySequence_GetItem($input, i);
94       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
95         if (!temp_selection) {
96           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string, double or boolean.1");
97           return NULL;
98         }
99         temp.push_back(FiltersAPI_Argument(*temp_selection));
100         if (newmem & SWIG_CAST_NEW_MEMORY) {
101           delete temp_selection;
102         }
103       } else
104       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_string, $descriptor(std::string*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
105         if (!temp_string) {
106           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string, double or boolean.2");
107           return NULL;
108         }
109         temp.push_back(FiltersAPI_Argument(*temp_string));
110         if (newmem & SWIG_CAST_NEW_MEMORY) {
111           delete temp_string;
112         }
113       } else
114       if (PyUnicode_Check(item)) {
115         temp.push_back(FiltersAPI_Argument(std::string(PyUnicode_AsUTF8(item))));
116       } else
117       if (PyBool_Check(item)) {
118         temp.push_back(FiltersAPI_Argument(item == Py_True));
119       } else
120       if (PyFloat_Check(item) || PyLong_Check(item)) {
121         temp.push_back(FiltersAPI_Argument(ModelHighAPI_Double(PyFloat_AsDouble(item))));
122       } else {
123         PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string, double or boolean.4");
124         return NULL;
125       }
126       Py_DECREF(item);
127     }
128     $1 = &temp;
129   } else {
130     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string, double or boolean.5");
131     return NULL;
132   }
133 }
134
135
136 // all supported interfaces
137 %include "FiltersAPI_Argument.h"
138 %include "FiltersAPI_Feature.h"
139 %include "FiltersAPI_Filter.h"
140 %include "FiltersAPI_Selection.h"