Salome HOME
Dump Python in the High Level Parameterized Geometry API (issue #1648)
[modules/shaper.git] / src / SketchAPI / SketchAPI.i
1 /* SketchAPI.i */
2
3 %module SketchAPI
4
5 %{
6   #include "SketchAPI_swig.h"
7 %}
8
9 %include "doxyhelp.i"
10
11 // import other modules
12 %import "ModelHighAPI.i"
13
14 // to avoid error on this
15 #define SKETCHAPI_EXPORT
16
17 // standard definitions
18 %include "typemaps.i"
19 %include "std_list.i"
20 %include "std_shared_ptr.i"
21
22 // shared pointers
23 %shared_ptr(SketchAPI_Arc)
24 %shared_ptr(SketchAPI_Circle)
25 %shared_ptr(SketchAPI_Constraint)
26 %shared_ptr(SketchAPI_IntersectionPoint)
27 %shared_ptr(SketchAPI_Line)
28 %shared_ptr(SketchAPI_Mirror)
29 %shared_ptr(SketchAPI_Sketch)
30 %shared_ptr(SketchAPI_SketchEntity)
31 %shared_ptr(SketchAPI_Point)
32 %shared_ptr(SketchAPI_Projection)
33 %shared_ptr(SketchAPI_Rectangle)
34 %shared_ptr(SketchAPI_Rotation)
35 %shared_ptr(SketchAPI_Translation)
36
37 // TODO(spo): move typemaps into ModelHighAPI package
38
39 // fix compilarion error: ‘res*’ was not declared in this scope
40 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
41 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
42
43 %typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
44   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
45   int newmem = 0;
46   if (PySequence_Check($input)) {
47     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
48       PyObject * item = PySequence_GetItem($input, i);
49       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
50         if (!temp_attribute) {
51           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
52           return NULL;
53         }
54         temp.push_back(ModelHighAPI_RefAttr(*temp_attribute));
55         if (newmem & SWIG_CAST_NEW_MEMORY) {
56           delete temp_attribute;
57         }
58       }
59       Py_DECREF(item);
60     }
61     $1 = &temp;
62   } else {
63     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
64     return NULL;
65   }
66 }
67
68 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
69   std::shared_ptr<ModelAPI_Object> * temp_object;
70   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
71   int newmem = 0;
72   if (PySequence_Check($input)) {
73     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
74       PyObject * item = PySequence_GetItem($input, i);
75       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
76         if (!temp_object) {
77           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
78           return NULL;
79         }
80         temp.push_back(*temp_object);
81         if (newmem & SWIG_CAST_NEW_MEMORY) {
82           delete temp_object;
83         }
84       } else
85       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
86         if (!temp_interface) {
87           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
88           return NULL;
89         }
90         temp.push_back((*temp_interface)->defaultResult());
91         if (newmem & SWIG_CAST_NEW_MEMORY) {
92           delete temp_interface;
93         }
94       }
95       Py_DECREF(item);
96     }
97     $1 = &temp;
98   } else {
99     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
100     return NULL;
101   }
102 }
103
104 // all supported interfaces (the order is very important according dependencies: base class first)
105 %include "SketchAPI_SketchEntity.h"
106 %include "SketchAPI_Point.h"
107 %include "SketchAPI_IntersectionPoint.h"
108 %include "SketchAPI_Line.h"
109 %include "SketchAPI_Circle.h"
110 %include "SketchAPI_Arc.h"
111 %include "SketchAPI_Projection.h"
112 %include "SketchAPI_Mirror.h"
113 %include "SketchAPI_Translation.h"
114 %include "SketchAPI_Rectangle.h"
115 %include "SketchAPI_Rotation.h"
116 %include "SketchAPI_Sketch.h"
117 %include "SketchAPI_Constraint.h"