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