Salome HOME
3e75454ea3787aea7d3ff048ba1a06938cde761b
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI.i
1 // Copyright (C) 2014-2022  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 /* GeomAPI.i */
21 %module GeomAlgoAPI
22 %{
23   #include "GeomAlgoAPI_swig.h"
24
25 // fix for SWIG v4.1.1
26 #if PY_VERSION_HEX >= 0x03020000
27 # define SWIGPY_SLICEOBJECT PyObject
28 #else
29 # define SWIGPY_SLICEOBJECT PySliceObject
30 #endif
31
32 // fix for SWIG v2.0.4
33 #define SWIGPY_SLICE_ARG(obj)   ((SWIGPY_SLICEOBJECT*)(obj))
34 %}
35
36 // import other modules
37 %import "GeomAPI.i"
38
39 // to avoid error on this
40 #define GEOMALGOAPI_EXPORT
41
42 // standard definitions
43 %include "typemaps.i"
44 %include "std_string.i"
45 %include "std_list.i"
46 %include "std_shared_ptr.i"
47 %include "std_vector.i"
48
49 %exceptionclass GeomAlgoAPI_Exception;
50
51 %exception {
52   try {
53     $action
54   }
55   catch (GeomAlgoAPI_Exception exc) {
56     // Reraise with SWIG_Python_Raise
57     SWIG_Python_Raise(SWIG_NewPointerObj((new GeomAlgoAPI_Exception(static_cast< const GeomAlgoAPI_Exception& >(exc))), SWIGTYPE_p_GeomAlgoAPI_Exception, SWIG_POINTER_OWN), "GeomAlgoAPI_Exception", SWIGTYPE_p_GeomAlgoAPI_Exception);
58     SWIG_fail;
59   }
60 }
61
62 %typemap(out) std::list< std::shared_ptr< GeomAPI_Shape > >::value_type & {
63   $result = SWIG_NewPointerObj(SWIG_as_voidptr(new std::shared_ptr<GeomAPI_Shape>(*$1)), $descriptor(std::shared_ptr<GeomAPI_Shape> *), SWIG_POINTER_OWN | 0 );
64 }
65
66 %template(ShapeList) std::list<std::shared_ptr<GeomAPI_Shape> >;
67 %template(ValuesList) std::list<GeomAlgoAPI_InfoValue>;
68 %template(VectorOfDouble) std::vector<double>;
69
70 %typemap(in) std::vector<double>& (std::vector<double> temp) {
71   if (PyList_Check($input)) {
72     for (Py_ssize_t i = 0; i < PyList_Size($input); ++i) {
73       PyObject * item = PySequence_GetItem($input, i);
74       if (PyNumber_Check(item)) {
75         temp.push_back(PyFloat_AsDouble(item));
76       } else {
77         PyErr_SetString(PyExc_TypeError, "argument must be double value.");
78         return NULL;
79       }
80       Py_DECREF(item);
81     }
82     $1 = &temp;
83   } else {
84     PyErr_SetString(PyExc_ValueError, "argument must be a list of double values.");
85     return NULL;
86   }
87 }
88
89 %typemap(argout) std::vector<double>& {
90     PyObject* outList = PyList_New(0);
91     int error;
92     std::vector<double>::iterator it;
93     for ( it=$1->begin() ; it != $1->end(); it++ )
94     {
95         error = PyList_Append(outList, PyFloat_FromDouble(*it));
96         if (error)
97             SWIG_fail;
98     }
99     if ((!$result) || ($result == Py_None)) {
100         $result = outList;
101     } else {
102         PyObject *aObj1, *aObj2;
103         if (!PyTuple_Check($result)) {
104             PyObject* aObj = $result;
105             $result = PyTuple_New(1);
106             PyTuple_SetItem($result,0,aObj);
107         }
108         aObj2 = PyTuple_New(1);
109         PyTuple_SetItem(aObj2,0,outList);
110         aObj1 = $result;
111         $result = PySequence_Concat(aObj1,aObj2);
112         Py_DECREF(aObj1);
113         Py_DECREF(aObj2);
114     }
115 }
116
117 %typecheck(SWIG_TYPECHECK_POINTER) std::vector<double>, const std::vector<double>& {
118   if (PyTuple_Check($input)) {
119     for (Py_ssize_t i = 0; i < PyTuple_Size($input); ++i) {
120       PyObject * item = PySequence_GetItem($input, i);
121       if (PyNumber_Check(item)) {
122         $1 = 1;
123       } else {
124         $1 = 0;
125         break;
126       }
127       Py_DECREF(item);
128     }
129   } else {
130     $1 = 0;
131   }
132 }
133
134 %typemap(in) double& (double temp) {
135   if (PyFloat_Check($input)) {
136     temp = PyFloat_AsDouble($input);
137     $1 = &temp;
138   } else {
139     PyErr_SetString(PyExc_ValueError, "argument must be a double value.");
140     return NULL;
141   }
142 }
143
144 %typemap(argout) double& {
145     if ((!$result) || ($result == Py_None)) {
146         $result = PyFloat_FromDouble(*$1);
147     } else {
148         PyObject *aObj1, *aObj2;
149         if (!PyTuple_Check($result)) {
150             PyObject* aObj = $result;
151             $result = PyTuple_New(1);
152             PyTuple_SetItem($result,0,aObj);
153         }
154         aObj2 = PyTuple_New(1);
155         PyTuple_SetItem(aObj2,0,PyFloat_FromDouble(*$1));
156         aObj1 = $result;
157         $result = PySequence_Concat(aObj1,aObj2);
158         Py_DECREF(aObj1);
159         Py_DECREF(aObj2);
160     }
161 }
162
163 // shared pointers
164 %shared_ptr(GeomAlgoAPI_Boolean)
165 %shared_ptr(GeomAlgoAPI_Intersection)
166 %shared_ptr(GeomAlgoAPI_MakeShape)
167 %shared_ptr(GeomAlgoAPI_MakeShapeCustom)
168 %shared_ptr(GeomAlgoAPI_MakeShapeList)
169 %shared_ptr(GeomAlgoAPI_MakeSweep)
170 %shared_ptr(GeomAlgoAPI_PaveFiller)
171 %shared_ptr(GeomAlgoAPI_Pipe)
172 %shared_ptr(GeomAlgoAPI_Placement)
173 %shared_ptr(GeomAlgoAPI_Prism)
174 %shared_ptr(GeomAlgoAPI_Revolution)
175 %shared_ptr(GeomAlgoAPI_Rotation)
176 %shared_ptr(GeomAlgoAPI_Sewing)
177 %shared_ptr(GeomAlgoAPI_SketchBuilder)
178 %shared_ptr(GeomAlgoAPI_ShapeBuilder)
179 %shared_ptr(GeomAlgoAPI_Translation)
180 %shared_ptr(GeomAlgoAPI_Transform)
181 %shared_ptr(GeomAlgoAPI_Box)
182 %shared_ptr(GeomAlgoAPI_ConeSegment)
183 %shared_ptr(GeomAlgoAPI_Copy)
184 %shared_ptr(GeomAlgoAPI_Symmetry)
185 %shared_ptr(GeomAlgoAPI_MapShapesAndAncestors)
186 %shared_ptr(GeomAlgoAPI_WireBuilder)
187
188 // all supported interfaces
189 %include "GeomAlgoAPI_MakeShape.h"
190 %include "GeomAlgoAPI_Boolean.h"
191 %include "GeomAlgoAPI_Circ2dBuilder.h"
192 %include "GeomAlgoAPI_CompoundBuilder.h"
193 %include "GeomAlgoAPI_CurveBuilder.h"
194 %include "GeomAlgoAPI_DFLoader.h"
195 %include "GeomAlgoAPI_EdgeBuilder.h"
196 %include "GeomAlgoAPI_FaceBuilder.h"
197 %include "GeomAlgoAPI_MakeShapeCustom.h"
198 %include "GeomAlgoAPI_MakeShapeList.h"
199 %include "GeomAlgoAPI_MakeSweep.h"
200 %include "GeomAlgoAPI_Transform.h"
201 %include "GeomAlgoAPI_Translation.h"
202 %include "GeomAlgoAPI_Placement.h"
203 %include "GeomAlgoAPI_PointBuilder.h"
204 %include "GeomAlgoAPI_Prism.h"
205 %include "GeomAlgoAPI_Revolution.h"
206 %include "GeomAlgoAPI_Rotation.h"
207 %include "GeomAlgoAPI_ShapeTools.h"
208 %include "GeomAlgoAPI_SketchBuilder.h"
209 %include "GeomAlgoAPI_BREPExport.h"
210 %include "GeomAlgoAPI_IGESExport.h"
211 %include "GeomAlgoAPI_STEPExport.h"
212 %include "GeomAlgoAPI_BREPImport.h"
213 %include "GeomAlgoAPI_IGESImport.h"
214 %include "GeomAlgoAPI_STEPImport.h"
215 %include "GeomAlgoAPI_Tools.h"
216 %include "GeomAlgoAPI_PaveFiller.h"
217 %include "GeomAlgoAPI_Intersection.h"
218 %include "GeomAlgoAPI_Pipe.h"
219 %include "GeomAlgoAPI_WireBuilder.h"
220 %include "GeomAlgoAPI_Sewing.h"
221 %include "GeomAlgoAPI_ShapeBuilder.h"
222 %include "GeomAlgoAPI_Exception.h"
223 %include "GeomAlgoAPI_ShapeAPI.h"
224 %include "GeomAlgoAPI_Copy.h"
225 %include "GeomAlgoAPI_Symmetry.h"
226 %include "GeomAlgoAPI_Box.h"
227 %include "GeomAlgoAPI_MapShapesAndAncestors.h"
228 %include "GeomAlgoAPI_ShapeInfo.h"
229 %include "GeomAlgoAPI_CanonicalRecognition.h"