Salome HOME
Copyright update 2020
[modules/shaper.git] / src / FiltersAPI / FiltersAPI.i
1 // Copyright (C) 2014-2020  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 (!PyUnicode_Check(item) && !PyBool_Check(item))
78         $1 = 0;
79     }
80   }
81 }
82
83 %typemap(in) const std::list<FiltersAPI_Argument> & (std::list<FiltersAPI_Argument> temp) {
84   ModelHighAPI_Selection* temp_selection;
85   std::string* temp_string;
86   int newmem = 0;
87   if (PySequence_Check($input)) {
88     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
89       PyObject * item = PySequence_GetItem($input, i);
90       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
91         if (!temp_selection) {
92           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string or boolean.");
93           return NULL;
94         }
95         temp.push_back(FiltersAPI_Argument(*temp_selection));
96         if (newmem & SWIG_CAST_NEW_MEMORY) {
97           delete temp_selection;
98         }
99       } else
100       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_string, $descriptor(std::string*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
101         if (!temp_string) {
102           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string or boolean.");
103           return NULL;
104         }
105         temp.push_back(FiltersAPI_Argument(*temp_string));
106         if (newmem & SWIG_CAST_NEW_MEMORY) {
107           delete temp_string;
108         }
109       } else
110       if (PyUnicode_Check(item)) {
111         temp.push_back(FiltersAPI_Argument(std::string(PyUnicode_AsUTF8(item))));
112       } else
113       if (PyBool_Check(item)) {
114         temp.push_back(FiltersAPI_Argument(item == Py_True));
115       } else {
116         PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string or boolean.");
117         return NULL;
118       }
119       Py_DECREF(item);
120     }
121     $1 = &temp;
122   } else {
123     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Selection, string or boolean.");
124     return NULL;
125   }
126 }
127
128
129 // all supported interfaces
130 %include "FiltersAPI_Argument.h"
131 %include "FiltersAPI_Feature.h"
132 %include "FiltersAPI_Filter.h"
133 %include "FiltersAPI_Selection.h"