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