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