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