Salome HOME
9cde425da08595ca54d99e3ee6f6e7cfe8d59889
[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 // shared pointers
48 %shared_ptr(SketchAPI_Arc)
49 %shared_ptr(SketchAPI_MacroArc)
50 %shared_ptr(SketchAPI_Circle)
51 %shared_ptr(SketchAPI_MacroCircle)
52 %shared_ptr(SketchAPI_Ellipse)
53 %shared_ptr(SketchAPI_MacroEllipse)
54 %shared_ptr(SketchAPI_Constraint)
55 %shared_ptr(SketchAPI_ConstraintAngle)
56 %shared_ptr(SketchAPI_IntersectionPoint)
57 %shared_ptr(SketchAPI_Line)
58 %shared_ptr(SketchAPI_Mirror)
59 %shared_ptr(SketchAPI_Sketch)
60 %shared_ptr(SketchAPI_SketchEntity)
61 %shared_ptr(SketchAPI_Point)
62 %shared_ptr(SketchAPI_Projection)
63 %shared_ptr(SketchAPI_Rectangle)
64 %shared_ptr(SketchAPI_Rotation)
65 %shared_ptr(SketchAPI_Translation)
66
67 // std::list -> []
68 %template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
69 %template(EntityList)    std::list<std::shared_ptr<SketchAPI_SketchEntity> >;
70 %template(SketchPointList) std::list<std::shared_ptr<SketchAPI_Point> >;
71 // std::pair -> []
72 %template(PointRefAttrPair) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>;
73
74 %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
75   std::shared_ptr<ModelAPI_Feature> * temp_feature;
76   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
77   int newmem = 0;
78   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
79     if (temp_feature) {
80       $1 = 1;
81     } else {
82       $1 = 0;
83     }
84   } else
85   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
86     if (temp_interface) {
87       $1 = 1;
88     } else {
89       $1 = 0;
90     }
91   } else
92     $1 = 0;
93 }
94
95 %typemap(in) const std::shared_ptr<ModelAPI_Feature> & (std::shared_ptr<ModelAPI_Feature> temp) {
96   std::shared_ptr<ModelAPI_Feature> * temp_feature;
97   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
98   int newmem = 0;
99   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_feature, $descriptor(std::shared_ptr<ModelAPI_Feature> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
100     if (!temp_feature) {
101       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
102       return NULL;
103     }
104     temp = (*temp_feature);
105     if (newmem & SWIG_CAST_NEW_MEMORY) {
106       delete temp_feature;
107     }
108     $1 = &temp;
109   } else
110   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
111     if (!temp_interface) {
112       PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface.");
113       return NULL;
114     }
115     temp = (*temp_interface)->feature();
116     if (newmem & SWIG_CAST_NEW_MEMORY) {
117       delete temp_interface;
118     }
119     $1 = &temp;
120   } else
121   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
122   } else {
123     PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_Interface.");
124     return NULL;
125   }
126 }
127
128 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
129   std::shared_ptr<ModelAPI_Object> * temp_object;
130   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
131   ModelHighAPI_Selection* temp_selection;
132   int newmem = 0;
133   if (PySequence_Check($input)) {
134     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
135       PyObject * item = PySequence_GetItem($input, i);
136       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
137         if (!temp_selection) {
138           PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
139           return NULL;
140         }
141         temp.push_back(temp_selection->resultSubShapePair().first);
142         if (newmem & SWIG_CAST_NEW_MEMORY) {
143           delete temp_selection;
144         }
145       } else
146       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
147         if (!temp_object) {
148           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
149           return NULL;
150         }
151         temp.push_back(*temp_object);
152         if (newmem & SWIG_CAST_NEW_MEMORY) {
153           delete temp_object;
154         }
155       } else
156       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
157         if (!temp_interface) {
158           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface, ModelHighAPI_Selection or ModelAPI_Object.");
159           return NULL;
160         }
161         temp.push_back((*temp_interface)->defaultResult());
162         if (newmem & SWIG_CAST_NEW_MEMORY) {
163           delete temp_interface;
164         }
165       }
166       Py_DECREF(item);
167     }
168     $1 = &temp;
169   } else {
170     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
171     return NULL;
172   }
173 }
174
175 %typecheck(SWIG_TYPECHECK_POINTER) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>, const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {
176   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
177   std::shared_ptr<ModelAPI_Object> * temp_object;
178   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
179   ModelHighAPI_Selection* temp_selection;
180   std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
181   std::shared_ptr<GeomAPI_Pnt2d> * temp_point;
182   ModelHighAPI_RefAttr temp_refattr;
183   int newmem = 0;
184   std::list<PyObject*> temp_inputlist;
185   if (PySequence_Check($input)) {
186     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
187       PyObject * temp = PySequence_GetItem($input, i);
188       temp_inputlist.push_back(temp);
189     }
190   } else {
191     temp_inputlist.push_back($input);
192   }
193
194   $1 = 1;
195   for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end() && $1; ++it) {
196     PyObject* item = *it;
197
198     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
199       if (temp_selection) {
200         $1 = 1;
201       } else {
202         $1 = 0;
203       }
204     } else
205     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
206       if (temp_attribute) {
207         $1 = 1;
208       } else {
209         $1 = 0;
210       }
211     } else
212     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
213       if (temp_object) {
214         $1 = 1;
215       } else {
216         $1 = 0;
217       }
218     } else
219     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
220       if (temp_interface) {
221         $1 = 1;
222       } else {
223         $1 = 0;
224       }
225     } else
226     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
227       if (temp_pair) {
228         $1 = 1;
229       } else {
230         $1 = 0;
231       }
232     } else
233     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
234       if (temp_point) {
235         $1 = 1;
236       } else {
237         $1 = 0;
238       }
239     } else {
240       $1 = 0;
241     }
242   }
243 }
244
245 %typemap(in) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & (std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> temp) {
246   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
247   std::shared_ptr<ModelAPI_Object> * temp_object;
248   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
249   ModelHighAPI_Selection* temp_selection;
250   std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
251   std::shared_ptr<GeomAPI_Pnt2d> * temp_point = 0;
252   ModelHighAPI_RefAttr temp_refattr;
253   int newmem = 0;
254   std::list<PyObject*> temp_inputlist;
255   if (PySequence_Check($input)) {
256     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
257       PyObject * temp = PySequence_GetItem($input, i);
258       temp_inputlist.push_back(temp);
259     }
260   } else {
261     temp_inputlist.push_back($input);
262   }
263
264   for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end(); ++it) {
265     PyObject* item = *it;
266
267     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
268       if (temp_selection) {
269         temp_refattr = ModelHighAPI_RefAttr(std::shared_ptr<ModelAPI_Object>(temp_selection->resultSubShapePair().first));
270         if (newmem & SWIG_CAST_NEW_MEMORY) {
271           delete temp_selection;
272         }
273       }
274     } else
275     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
276       if (temp_attribute) {
277         temp_refattr = ModelHighAPI_RefAttr(*temp_attribute);
278         if (newmem & SWIG_CAST_NEW_MEMORY) {
279           delete temp_attribute;
280         }
281       }
282     } else
283     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
284       if (temp_object) {
285         temp_refattr = ModelHighAPI_RefAttr(*temp_object);
286         if (newmem & SWIG_CAST_NEW_MEMORY) {
287           delete temp_object;
288         }
289       }
290     } else
291     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
292       if (temp_interface) {
293         temp_refattr = ModelHighAPI_RefAttr(*temp_interface);
294         if (newmem & SWIG_CAST_NEW_MEMORY) {
295           delete temp_interface;
296         }
297       }
298     } else
299     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
300       if (temp_pair) {
301         temp_point = &temp_pair->first;
302         temp_refattr = temp_pair->second;
303         if (newmem & SWIG_CAST_NEW_MEMORY) {
304           delete temp_pair;
305         }
306       }
307     } else
308     if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
309       // fall through
310     }
311   }
312
313   if (temp_point || !temp_refattr.isEmpty()) {
314     if (temp_point) {
315       temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(*temp_point, temp_refattr);
316     } else {
317       temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(std::shared_ptr<GeomAPI_Pnt2d>(), temp_refattr);
318     }
319     if (temp_point && (newmem & SWIG_CAST_NEW_MEMORY)) {
320       delete temp_point;
321     }
322     $1 = &temp;
323   } else {
324     PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
325     return NULL;
326   }
327 }
328
329 // fix compilarion error: 'res*' was not declared in this scope
330 %typemap(freearg) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {}
331
332 // all supported interfaces (the order is very important according dependencies: base class first)
333 %include "SketchAPI_SketchEntity.h"
334 %include "SketchAPI_Point.h"
335 %include "SketchAPI_IntersectionPoint.h"
336 %include "SketchAPI_Line.h"
337 %include "SketchAPI_Circle.h"
338 %include "SketchAPI_MacroCircle.h"
339 %include "SketchAPI_Arc.h"
340 %include "SketchAPI_MacroArc.h"
341 %include "SketchAPI_Ellipse.h"
342 %include "SketchAPI_MacroEllipse.h"
343 %include "SketchAPI_Projection.h"
344 %include "SketchAPI_Mirror.h"
345 %include "SketchAPI_Translation.h"
346 %include "SketchAPI_Rectangle.h"
347 %include "SketchAPI_Rotation.h"
348 %include "SketchAPI_Sketch.h"
349 %include "SketchAPI_Constraint.h"
350 %include "SketchAPI_ConstraintAngle.h"