Salome HOME
1be2156ed81a4a6976d383c992a36daa9fdc7390
[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 %typecheck(SWIG_TYPECHECK_POINTER) std::list<std::shared_ptr<ModelAPI_Object> >, const std::list<std::shared_ptr<ModelAPI_Object> >& {
105   std::shared_ptr<ModelAPI_Object> * temp_object;
106   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
107   int newmem = 0;
108   if (PySequence_Check($input)) {
109     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
110       PyObject * item = PySequence_GetItem($input, i);
111       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
112         if (temp_object) {
113           $1 = 1;
114         } else {
115           $1 = 0;
116           break;
117         }
118       } else
119       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
120         if (temp_interface) {
121           $1 = 1;
122         } else {
123           $1 = 0;
124           break;
125         }
126       }
127       Py_DECREF(item);
128     }
129   } else {
130     $1 = 0;
131   }
132 }
133
134 // all supported interfaces (the order is very important according dependencies: base class first)
135 %include "SketchAPI_SketchEntity.h"
136 %include "SketchAPI_Point.h"
137 %include "SketchAPI_IntersectionPoint.h"
138 %include "SketchAPI_Line.h"
139 %include "SketchAPI_Circle.h"
140 %include "SketchAPI_Arc.h"
141 %include "SketchAPI_Projection.h"
142 %include "SketchAPI_Mirror.h"
143 %include "SketchAPI_Translation.h"
144 %include "SketchAPI_Rectangle.h"
145 %include "SketchAPI_Rotation.h"
146 %include "SketchAPI_Sketch.h"
147 %include "SketchAPI_Constraint.h"