]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchAPI/SketchAPI.i
Salome HOME
Correct projection for periodic B-spline. Update unit tests.
[modules/shaper.git] / src / SketchAPI / SketchAPI.i
1 // Copyright (C) 2014-2019  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 /* SketchAPI.i */
21
22 %module SketchAPI
23
24 %{
25   #include "SketchAPI_swig.h"
26   #include "ModelHighAPI_swig.h"
27
28   // fix for SWIG v2.0.4
29   #define SWIGPY_SLICE_ARG(obj) ((PyObject*)(obj))
30 %}
31
32 %include "doxyhelp.i"
33
34 // import other modules
35 %import "GeomAPI.i"
36 %import "ModelAPI.i"
37 %import "ModelHighAPI.i"
38
39 // to avoid error on this
40 #define SKETCHAPI_EXPORT
41
42 // standard definitions
43 %include "typemaps.i"
44 %include "std_list.i"
45 %include "std_pair.i"
46 %include "std_shared_ptr.i"
47
48 // function with named parameters
49 %feature("kwargs") SketchAPI_BSpline::controlPoles;
50 %feature("kwargs") SketchAPI_BSpline::controlPolygon;
51 %feature("kwargs") SketchAPI_Ellipse::construction;
52 %feature("kwargs") SketchAPI_EllipticArc::construction;
53 %feature("kwargs") SketchAPI_Sketch::addSpline;
54 %feature("kwargs") SketchAPI_Sketch::setAngle;
55
56 // shared pointers
57 %shared_ptr(SketchAPI_Arc)
58 %shared_ptr(SketchAPI_MacroArc)
59 %shared_ptr(SketchAPI_Circle)
60 %shared_ptr(SketchAPI_MacroCircle)
61 %shared_ptr(SketchAPI_Ellipse)
62 %shared_ptr(SketchAPI_MacroEllipse)
63 %shared_ptr(SketchAPI_EllipticArc)
64 %shared_ptr(SketchAPI_MacroEllipticArc)
65 %shared_ptr(SketchAPI_BSpline)
66 %shared_ptr(SketchAPI_BSplinePeriodic)
67 %shared_ptr(SketchAPI_Constraint)
68 %shared_ptr(SketchAPI_ConstraintAngle)
69 %shared_ptr(SketchAPI_IntersectionPoint)
70 %shared_ptr(SketchAPI_Line)
71 %shared_ptr(SketchAPI_Mirror)
72 %shared_ptr(SketchAPI_Sketch)
73 %shared_ptr(SketchAPI_SketchEntity)
74 %shared_ptr(SketchAPI_Point)
75 %shared_ptr(SketchAPI_Projection)
76 %shared_ptr(SketchAPI_Rectangle)
77 %shared_ptr(SketchAPI_Rotation)
78 %shared_ptr(SketchAPI_Translation)
79
80 // std::list -> []
81 %template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
82 %template(EntityList)    std::list<std::shared_ptr<SketchAPI_SketchEntity> >;
83 %template(SketchPointList) std::list<std::shared_ptr<SketchAPI_Point> >;
84 %template(GeomPnt2dList) std::list<std::shared_ptr<GeomAPI_Pnt2d> >;
85 // std::pair -> []
86 %template(PointRefAttrPair) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>;
87
88 %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
89   std::shared_ptr<ModelAPI_Feature> * temp_feature;
90   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
91   int newmem = 0;
92   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
93     if (temp_feature) {
94       $1 = 1;
95     } else {
96       $1 = 0;
97     }
98   } else
99   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
100     if (temp_interface) {
101       $1 = 1;
102     } else {
103       $1 = 0;
104     }
105   } else
106     $1 = 0;
107 }
108
109 %typemap(in) const std::shared_ptr<ModelAPI_Feature> & (std::shared_ptr<ModelAPI_Feature> temp) {
110   std::shared_ptr<ModelAPI_Feature> * temp_feature;
111   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
112   int newmem = 0;
113   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
114     if (!temp_feature) {
115       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
116       return NULL;
117     }
118     temp = (*temp_feature);
119     if (newmem & SWIG_CAST_NEW_MEMORY) {
120       delete temp_feature;
121     }
122     $1 = &temp;
123   } else
124   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
125     if (!temp_interface) {
126       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
127       return NULL;
128     }
129     temp = (*temp_interface)->feature();
130     if (newmem & SWIG_CAST_NEW_MEMORY) {
131       delete temp_interface;
132     }
133     $1 = &temp;
134   } else
135   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
136   } else {
137     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Interface.");
138     return NULL;
139   }
140 }
141
142 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
143   std::shared_ptr<ModelAPI_Object> * temp_object;
144   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
145   ModelHighAPI_Selection* temp_selection;
146   int newmem = 0;
147   if (PySequence_Check($input)) {
148     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
149       PyObject * item = PySequence_GetItem($input, i);
150       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
151         if (!temp_selection) {
152           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
153           return NULL;
154         }
155         temp.push_back(temp_selection->resultSubShapePair().first);
156         if (newmem & SWIG_CAST_NEW_MEMORY) {
157           delete temp_selection;
158         }
159       } else
160       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
161         if (!temp_object) {
162           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
163           return NULL;
164         }
165         temp.push_back(*temp_object);
166         if (newmem & SWIG_CAST_NEW_MEMORY) {
167           delete temp_object;
168         }
169       } else
170       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
171         if (!temp_interface) {
172           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
173           return NULL;
174         }
175         temp.push_back((*temp_interface)->defaultResult());
176         if (newmem & SWIG_CAST_NEW_MEMORY) {
177           delete temp_interface;
178         }
179       }
180       Py_DECREF(item);
181     }
182     $1 = &temp;
183   } else {
184     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
185     return NULL;
186   }
187 }
188
189 %typecheck(SWIG_TYPECHECK_POINTER) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>, const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {
190   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
191   std::shared_ptr<ModelAPI_Object> * temp_object;
192   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
193   ModelHighAPI_Selection* temp_selection;
194   std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
195   std::shared_ptr<GeomAPI_Pnt2d> * temp_point;
196   ModelHighAPI_RefAttr temp_refattr;
197   int newmem = 0;
198   std::list<PyObject*> temp_inputlist;
199   if (PySequence_Check($input)) {
200     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
201       PyObject * temp = PySequence_GetItem($input, i);
202       temp_inputlist.push_back(temp);
203     }
204   } else {
205     temp_inputlist.push_back($input);
206   }
207
208   $1 = 1;
209   for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end() && $1; ++it) {
210     PyObject* item = *it;
211
212     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
213       if (temp_selection) {
214         $1 = 1;
215       } else {
216         $1 = 0;
217       }
218     } else
219     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
220       if (temp_attribute) {
221         $1 = 1;
222       } else {
223         $1 = 0;
224       }
225     } else
226     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
227       if (temp_object) {
228         $1 = 1;
229       } else {
230         $1 = 0;
231       }
232     } else
233     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
234       if (temp_interface) {
235         $1 = 1;
236       } else {
237         $1 = 0;
238       }
239     } else
240     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
241       if (temp_pair) {
242         $1 = 1;
243       } else {
244         $1 = 0;
245       }
246     } else
247     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
248       if (temp_point) {
249         $1 = 1;
250       } else {
251         $1 = 0;
252       }
253     } else {
254       $1 = 0;
255     }
256   }
257 }
258
259 %typemap(in) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & (std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> temp) {
260   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
261   std::shared_ptr<ModelAPI_Object> * temp_object;
262   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
263   ModelHighAPI_Selection* temp_selection;
264   std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
265   std::shared_ptr<GeomAPI_Pnt2d> * temp_point = 0;
266   ModelHighAPI_RefAttr temp_refattr;
267   int newmem = 0;
268   std::list<PyObject*> temp_inputlist;
269   if (PySequence_Check($input)) {
270     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
271       PyObject * temp = PySequence_GetItem($input, i);
272       temp_inputlist.push_back(temp);
273     }
274   } else {
275     temp_inputlist.push_back($input);
276   }
277
278   for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end(); ++it) {
279     PyObject* item = *it;
280
281     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
282       if (temp_selection) {
283         temp_refattr = ModelHighAPI_RefAttr(std::shared_ptr<ModelAPI_Object>(temp_selection->resultSubShapePair().first));
284         if (newmem & SWIG_CAST_NEW_MEMORY) {
285           delete temp_selection;
286         }
287       }
288     } else
289     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
290       if (temp_attribute) {
291         temp_refattr = ModelHighAPI_RefAttr(*temp_attribute);
292         if (newmem & SWIG_CAST_NEW_MEMORY) {
293           delete temp_attribute;
294         }
295       }
296     } else
297     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
298       if (temp_object) {
299         temp_refattr = ModelHighAPI_RefAttr(*temp_object);
300         if (newmem & SWIG_CAST_NEW_MEMORY) {
301           delete temp_object;
302         }
303       }
304     } else
305     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
306       if (temp_interface) {
307         temp_refattr = ModelHighAPI_RefAttr(*temp_interface);
308         if (newmem & SWIG_CAST_NEW_MEMORY) {
309           delete temp_interface;
310         }
311       }
312     } else
313     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
314       if (temp_pair) {
315         temp_point = &temp_pair->first;
316         temp_refattr = temp_pair->second;
317         if (newmem & SWIG_CAST_NEW_MEMORY) {
318           delete temp_pair;
319         }
320       }
321     } else
322     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
323       // fall through
324     }
325   }
326
327   if (temp_point || !temp_refattr.isEmpty()) {
328     if (temp_point) {
329       temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(*temp_point, temp_refattr);
330     } else {
331       temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(std::shared_ptr<GeomAPI_Pnt2d>(), temp_refattr);
332     }
333     if (temp_point && (newmem & SWIG_CAST_NEW_MEMORY)) {
334       delete temp_point;
335     }
336     $1 = &temp;
337   } else {
338     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
339     return NULL;
340   }
341 }
342
343 // fix compilarion error: 'res*' was not declared in this scope
344 %typemap(freearg) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {}
345
346
347 %typemap(in) const std::list<std::shared_ptr<GeomAPI_Pnt2d> > & (std::list<std::shared_ptr<GeomAPI_Pnt2d> > temp) {
348   std::shared_ptr<GeomAPI_Pnt2d> * temp_point = 0;
349   int newmem = 0;
350   if (PySequence_Check($input)) {
351     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
352       PyObject * item = PySequence_GetItem($input, i);
353       if (PyTuple_Check(item)) {
354         if (PyTuple_Size(item) == 2) {
355           double x = (double)PyFloat_AsDouble(PySequence_GetItem(item, 0));
356           double y = (double)PyFloat_AsDouble(PySequence_GetItem(item, 1));
357           temp.push_back(std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(x, y)));
358         } else {
359           PyErr_SetString(PyExc_TypeError, "argument must a list of 2D points.");
360           return NULL;
361         }
362       } else
363       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
364         temp.push_back(*temp_point);
365         if (temp_point && (newmem & SWIG_CAST_NEW_MEMORY)) {
366           delete temp_point;
367         }
368       } else {
369         PyErr_SetString(PyExc_TypeError, "argument must a list of 2D points.");
370         return NULL;
371       }
372       Py_DECREF(item);
373     }
374     $1 = &temp;
375   } else {
376     PyErr_SetString(PyExc_ValueError, "argument must be a tuple of lists.");
377     return NULL;
378   }
379 }
380
381 %typecheck(SWIG_TYPECHECK_POINTER) std::list<std::shared_ptr<GeomAPI_Pnt2d> >, const std::list<std::shared_ptr<GeomAPI_Pnt2d> >& {
382   std::shared_ptr<GeomAPI_Pnt2d> * temp_point = 0;
383   int newmem = 0;
384   if (PySequence_Check($input)) {
385     for (Py_ssize_t i = 0; i < PySequence_Size($input) && $1; ++i) {
386       PyObject * item = PySequence_GetItem($input, i);
387       if (PyTuple_Check(item)) {
388         if (PyTuple_Size(item) == 2) {
389           if (PyNumber_Check(PySequence_GetItem(item, 0)) && PyNumber_Check(PySequence_GetItem(item, 1))) {
390             $1 = 1;
391           } else {
392             $1 = 0;
393           }
394         } else {
395           $1 = 0;
396         }
397       } else
398       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
399         if (temp_point) {
400           $1 = 1;
401         } else {
402           $1 = 0;
403         }
404       }
405       Py_DECREF(item);
406     }
407   } else {
408     $1 = 0;
409   }
410 }
411
412 // fix compilarion error: 'res*' was not declared in this scope
413 %typemap(freearg) const std::list<std::shared_ptr<GeomAPI_Pnt2d> > & {}
414
415
416 // all supported interfaces (the order is very important according dependencies: base class first)
417 %include "SketchAPI_SketchEntity.h"
418 %include "SketchAPI_Point.h"
419 %include "SketchAPI_IntersectionPoint.h"
420 %include "SketchAPI_Line.h"
421 %include "SketchAPI_Circle.h"
422 %include "SketchAPI_MacroCircle.h"
423 %include "SketchAPI_Arc.h"
424 %include "SketchAPI_MacroArc.h"
425 %include "SketchAPI_Ellipse.h"
426 %include "SketchAPI_MacroEllipse.h"
427 %include "SketchAPI_EllipticArc.h"
428 %include "SketchAPI_MacroEllipticArc.h"
429 %include "SketchAPI_BSpline.h"
430 %include "SketchAPI_Projection.h"
431 %include "SketchAPI_Mirror.h"
432 %include "SketchAPI_Translation.h"
433 %include "SketchAPI_Rectangle.h"
434 %include "SketchAPI_Rotation.h"
435 %include "SketchAPI_Sketch.h"
436 %include "SketchAPI_Constraint.h"
437 %include "SketchAPI_ConstraintAngle.h"