Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / ModelAPI / ModelAPI.i
1 /* ModelAPI.i */
2 %module(directors="1") ModelAPI
3 %feature("director:except") {
4     if ($error != NULL) {
5       PyErr_Print();
6       std::cerr << std::endl;
7       throw Swig::DirectorMethodException();
8     }
9 }
10
11 %{
12   #include "ModelAPI_swig.h"
13
14   // fix for SWIG v2.0.4
15   #define SWIGPY_SLICE_ARG(obj) ((PySliceObject*)(obj))
16 %}
17
18 // import other modules
19 %import "GeomAPI.i"
20
21 // to avoid error on this
22 #define MODELAPI_EXPORT
23
24 // standard definitions
25 %include "typemaps.i"
26 %include "std_string.i"
27 %include "std_list.i"
28 %include "std_shared_ptr.i"
29 %include "std_set.i"
30
31 // directors
32 %feature("director") ModelAPI_Plugin;
33 %feature("director") ModelAPI_Object;
34 %feature("director") ModelAPI_Feature;
35 %feature("director") ModelAPI_CompositeFeature;
36 %feature("director") ModelAPI_Data;
37
38 // shared pointers
39 // For ModelAPI_ResultConstruction.shape()
40 %shared_ptr(ModelAPI_Entity)
41 %shared_ptr(ModelAPI_Document)
42 %shared_ptr(ModelAPI_Session)
43 %shared_ptr(ModelAPI_Plugin)
44 %shared_ptr(ModelAPI_Object)
45 %shared_ptr(ModelAPI_Feature)
46 %shared_ptr(ModelAPI_CompositeFeature)
47 %shared_ptr(ModelAPI_Data)
48 %shared_ptr(ModelAPI_Attribute)
49 %shared_ptr(ModelAPI_AttributeDocRef)
50 %shared_ptr(ModelAPI_AttributeDouble)
51 %shared_ptr(ModelAPI_AttributeDoubleArray)
52 %shared_ptr(ModelAPI_AttributeInteger)
53 %shared_ptr(ModelAPI_AttributeIntArray)
54 %shared_ptr(ModelAPI_AttributeString)
55 %shared_ptr(ModelAPI_AttributeStringArray)
56 %shared_ptr(ModelAPI_AttributeReference)
57 %shared_ptr(ModelAPI_AttributeRefAttr)
58 %shared_ptr(ModelAPI_AttributeRefList)
59 %shared_ptr(ModelAPI_AttributeRefAttrList)
60 %shared_ptr(ModelAPI_AttributeBoolean)
61 %shared_ptr(ModelAPI_AttributeSelection)
62 %shared_ptr(ModelAPI_AttributeSelectionList)
63 %shared_ptr(ModelAPI_AttributeTables)
64 %shared_ptr(ModelAPI_Validator)
65 %shared_ptr(ModelAPI_AttributeValidator)
66 %shared_ptr(ModelAPI_FeatureValidator)
67 %shared_ptr(ModelAPI_Result)
68 %shared_ptr(ModelAPI_ResultConstruction)
69 %shared_ptr(ModelAPI_ResultBody)
70 %shared_ptr(ModelAPI_ResultPart)
71 %shared_ptr(ModelAPI_ResultGroup)
72 %shared_ptr(ModelAPI_ResultField)
73 %shared_ptr(ModelAPI_ResultParameter)
74 %shared_ptr(ModelAPI_ResultCompSolid)
75
76 %typecheck(SWIG_TYPECHECK_POINTER) const ModelAPI_AttributeTables::Value {
77   $1 = (PyFloat_Check($input) || PyInt_Check($input) || PyLong_Check($input) || PyString_Check($input) || PyBool_Check($input)) ? 1 : 0;
78 }
79
80 // Tables Value reading as int, double, boolean or string
81 %typemap(in) const ModelAPI_AttributeTables::Value {
82   if (PyInt_Check($input)) {
83     $1.myInt = int(PyInt_AsLong($input));
84     $1.myDouble = double(PyInt_AsLong($input));
85     $1.myBool = PyInt_AsLong($input) != 0;
86   } else if (PyFloat_Check($input)) {
87     $1.myInt = int(PyFloat_AsDouble($input));
88     $1.myDouble = PyFloat_AsDouble($input);
89   } else if (PyBool_Check($input)) {
90     $1.myBool = $input == Py_True;
91   } else if (PyString_Check($input)) {
92     $1.myStr = PyString_AsString($input);
93   } else if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
94   } else {
95     PyErr_SetString(PyExc_ValueError, "Tables value must be int, double, string or bool.");
96     return NULL;
97   }
98 }
99
100 // all supported interfaces
101 %include "ModelAPI_Entity.h"
102 %include "ModelAPI_Document.h"
103 %include "ModelAPI_Session.h"
104 %include "ModelAPI_Plugin.h"
105 %include "ModelAPI_Object.h"
106 %include "ModelAPI_Feature.h"
107 %include "ModelAPI_CompositeFeature.h"
108 %include "ModelAPI_Data.h"
109 %include "ModelAPI_Attribute.h"
110 %include "ModelAPI_AttributeDocRef.h"
111 %include "ModelAPI_AttributeDouble.h"
112 %include "ModelAPI_AttributeDoubleArray.h"
113 %include "ModelAPI_AttributeInteger.h"
114 %include "ModelAPI_AttributeIntArray.h"
115 %include "ModelAPI_AttributeString.h"
116 %include "ModelAPI_AttributeStringArray.h"
117 %include "ModelAPI_AttributeReference.h"
118 %include "ModelAPI_AttributeRefAttr.h"
119 %include "ModelAPI_AttributeBoolean.h"
120 %include "ModelAPI_AttributeSelection.h"
121 %include "ModelAPI_AttributeSelectionList.h"
122 %include "ModelAPI_AttributeRefList.h"
123 %include "ModelAPI_AttributeRefAttrList.h"
124 %include "ModelAPI_AttributeTables.h"
125 %include "ModelAPI_Validator.h"
126 %include "ModelAPI_AttributeValidator.h"
127 %include "ModelAPI_FeatureValidator.h"
128 %include "ModelAPI_Result.h"
129 %include "ModelAPI_ResultConstruction.h"
130 %include "ModelAPI_ResultBody.h"
131 %include "ModelAPI_ResultPart.h"
132 %include "ModelAPI_ResultGroup.h"
133 %include "ModelAPI_ResultField.h"
134 %include "ModelAPI_ResultParameter.h"
135 %include "ModelAPI_Tools.h"
136 %include "ModelAPI_ResultCompSolid.h"
137
138 // std::list -> []
139 %template(StringList) std::list<std::string>;
140 %template(ObjectList) std::list<std::shared_ptr<ModelAPI_Object> >;
141 %template(FeatureList) std::list<std::shared_ptr<ModelAPI_Feature> >;
142 %template(ResultList) std::list<std::shared_ptr<ModelAPI_Result> >;
143 %template(DocumentList) std::list<std::shared_ptr<ModelAPI_Document> >;
144 // std::set -> []
145 %template(AttributeSet) std::set<std::shared_ptr<ModelAPI_Attribute> >;
146 %template(FeatureSet) std::set<std::shared_ptr<ModelAPI_Feature> >;
147
148 // std::dynamic_pointer_cast
149 template<class T1, class T2> std::shared_ptr<T1> shared_ptr_cast(std::shared_ptr<T2> theObject);
150 %template(featureToCompositeFeature) shared_ptr_cast<ModelAPI_CompositeFeature, ModelAPI_Feature>;
151 %template(objectToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_Object>;
152 %template(objectToResult) shared_ptr_cast<ModelAPI_Result, ModelAPI_Object>;
153 %template(compositeFeatureToFeature) shared_ptr_cast<ModelAPI_Feature, ModelAPI_CompositeFeature>;
154
155 %template(modelAPI_Result) shared_ptr_cast<ModelAPI_Result, ModelAPI_Object>;
156 %template(modelAPI_ResultConstruction) shared_ptr_cast<ModelAPI_ResultConstruction, ModelAPI_Result>;
157 %template(modelAPI_ResultBody) shared_ptr_cast<ModelAPI_ResultBody, ModelAPI_Result>;
158 %template(modelAPI_ResultPart) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_Result>;
159 %template(modelAPI_ResultParameter) shared_ptr_cast<ModelAPI_ResultParameter, ModelAPI_Result>;
160 %template(modelAPI_ResultGroup) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_ResultGroup>;
161 %template(modelAPI_ResultField) shared_ptr_cast<ModelAPI_ResultPart, ModelAPI_ResultField>;
162 %template(modelAPI_ResultCompSolid) shared_ptr_cast<ModelAPI_ResultCompSolid, ModelAPI_ResultBody>;
163
164 // Attribute casts
165 %template(modelAPI_AttributeDocRef)        shared_ptr_cast<ModelAPI_AttributeDocRef, ModelAPI_Attribute>;
166 %template(modelAPI_AttributeDouble)        shared_ptr_cast<ModelAPI_AttributeDouble, ModelAPI_Attribute>;
167 %template(modelAPI_AttributeDoubleArray)   shared_ptr_cast<ModelAPI_AttributeDoubleArray, ModelAPI_Attribute>;
168 %template(modelAPI_AttributeInteger)       shared_ptr_cast<ModelAPI_AttributeInteger, ModelAPI_Attribute>;
169 %template(modelAPI_AttributeIntArray)      shared_ptr_cast<ModelAPI_AttributeIntArray, ModelAPI_Attribute>;
170 %template(modelAPI_AttributeString)        shared_ptr_cast<ModelAPI_AttributeString, ModelAPI_Attribute>;
171 %template(modelAPI_AttributeStringArray)   shared_ptr_cast<ModelAPI_AttributeStringArray, ModelAPI_Attribute>;
172 %template(modelAPI_AttributeReference)     shared_ptr_cast<ModelAPI_AttributeReference, ModelAPI_Attribute>;
173 %template(modelAPI_AttributeRefAttr)       shared_ptr_cast<ModelAPI_AttributeRefAttr, ModelAPI_Attribute>;
174 %template(modelAPI_AttributeBoolean)       shared_ptr_cast<ModelAPI_AttributeBoolean, ModelAPI_Attribute>;
175 %template(modelAPI_AttributeSelection)     shared_ptr_cast<ModelAPI_AttributeSelection, ModelAPI_Attribute>;
176 %template(modelAPI_AttributeSelectionList) shared_ptr_cast<ModelAPI_AttributeSelectionList, ModelAPI_Attribute>;
177 %template(modelAPI_AttributeRefList)       shared_ptr_cast<ModelAPI_AttributeRefList, ModelAPI_Attribute>;
178 %template(modelAPI_AttributeRefAttrList)   shared_ptr_cast<ModelAPI_AttributeRefAttrList, ModelAPI_Attribute>;
179 %template(modelAPI_AttributeTables)        shared_ptr_cast<ModelAPI_AttributeTables, ModelAPI_Attribute>;
180
181 // Geometry casts
182 %template(shapeToEdge) shared_ptr_cast<GeomAPI_Edge, GeomAPI_Shape>;