Salome HOME
Add Rectangle
[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_IntersectionPoint)
26 %shared_ptr(SketchAPI_Line)
27 %shared_ptr(SketchAPI_Mirror)
28 %shared_ptr(SketchAPI_Sketch)
29 %shared_ptr(SketchAPI_SketchEntity)
30 %shared_ptr(SketchAPI_Point)
31 %shared_ptr(SketchAPI_Projection)
32 %shared_ptr(SketchAPI_Rectangle)
33 %shared_ptr(SketchAPI_Rotation)
34 %shared_ptr(SketchAPI_Translation)
35
36 // TODO(spo): move typemaps into ModelHighAPI package
37
38 // fix compilarion error: ‘res*’ was not declared in this scope
39 %typemap(freearg) const std::list<ModelHighAPI_RefAttr> & {}
40 %typemap(freearg) const std::list<std::shared_ptr<ModelAPI_Object> > & {}
41
42 %typemap(in) const std::list<ModelHighAPI_RefAttr> & (std::list<ModelHighAPI_RefAttr> temp) {
43   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
44   int newmem = 0;
45   if (PySequence_Check($input)) {
46     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
47       PyObject * item = PySequence_GetItem($input, i);
48       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
49         if (!temp_attribute) {
50           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
51           return NULL;
52         }
53         temp.push_back(ModelHighAPI_RefAttr(*temp_attribute));
54         if (newmem & SWIG_CAST_NEW_MEMORY) {
55           delete temp_attribute;
56         }
57       }
58       Py_DECREF(item);
59     }
60     $1 = &temp;
61   } else {
62     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
63     return NULL;
64   }
65 }
66
67 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
68   std::shared_ptr<ModelAPI_Object> * temp_object;
69   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
70   int newmem = 0;
71   if (PySequence_Check($input)) {
72     for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
73       PyObject * item = PySequence_GetItem($input, i);
74       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
75         if (!temp_object) {
76           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
77           return NULL;
78         }
79         temp.push_back(*temp_object);
80         if (newmem & SWIG_CAST_NEW_MEMORY) {
81           delete temp_object;
82         }
83       } else
84       if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
85         if (!temp_interface) {
86           PyErr_SetString(PyExc_TypeError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
87           return NULL;
88         }
89         temp.push_back((*temp_interface)->defaultResult());
90         if (newmem & SWIG_CAST_NEW_MEMORY) {
91           delete temp_interface;
92         }
93       }
94       Py_DECREF(item);
95     }
96     $1 = &temp;
97   } else {
98     PyErr_SetString(PyExc_ValueError, "argument must be list of ModelHighAPI_Interface or ModelAPI_Object.");
99     return NULL;
100   }
101 }
102
103 // all supported interfaces (the order is very important according dependencies: base class first)
104 %include "SketchAPI_SketchEntity.h"
105 %include "SketchAPI_Point.h"
106 %include "SketchAPI_IntersectionPoint.h"
107 %include "SketchAPI_Line.h"
108 %include "SketchAPI_Circle.h"
109 %include "SketchAPI_Arc.h"
110 %include "SketchAPI_Projection.h"
111 %include "SketchAPI_Mirror.h"
112 %include "SketchAPI_Translation.h"
113 %include "SketchAPI_Rectangle.h"
114 %include "SketchAPI_Rotation.h"
115 %include "SketchAPI_Sketch.h"