]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src/gp.i
Gitignores
[simantics/3d.git] / org.jcae.opencascade / src / gp.i
1 /*\r
2  * Project Info:  http://jcae.sourceforge.net\r
3  * \r
4  * This program is free software; you can redistribute it and/or modify it under\r
5  * the terms of the GNU Lesser General Public License as published by the Free\r
6  * Software Foundation; either version 2.1 of the License, or (at your option)\r
7  * any later version.\r
8  *\r
9  * This program is distributed in the hope that it will be useful, but WITHOUT\r
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
11  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more\r
12  * details.\r
13  *\r
14  * You should have received a copy of the GNU Lesser General Public License\r
15  * along with this program; if not, write to the Free Software Foundation, Inc.,\r
16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\r
17  *\r
18  * (C) Copyright 2005, by EADS CRC\r
19  */\r
20 \r
21 %{\r
22         jdoubleArray XYZtoDoubleArray(JNIEnv* jenv, const gp_XYZ & xyz)\r
23         {\r
24             jdouble nativeArray[]={xyz.X(), xyz.Y(), xyz.Z()};\r
25                 jdoubleArray toReturn=jenv->NewDoubleArray(3);\r
26                 jenv->SetDoubleArrayRegion(toReturn, 0, 3, nativeArray);\r
27                 return toReturn;\r
28         }\r
29 %}\r
30 \r
31 /**\r
32  * gp_Pnt\r
33  */\r
34 \r
35 %typemap(jni) gp_Pnt, const gp_Pnt&  "jdoubleArray"\r
36 %typemap(jtype) gp_Pnt, const gp_Pnt& "double[]"\r
37 %typemap(jstype) gp_Pnt, const gp_Pnt& "double[]"\r
38 \r
39 %typemap(in) gp_Pnt, const gp_Pnt&\r
40 {\r
41         if(JCALL1(GetArrayLength, jenv, $input)!=3)\r
42                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 3");\r
43         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
44         $1=new gp_Pnt(naxe[0],naxe[1],naxe[2]);\r
45 }\r
46 \r
47 %typemap(out) const gp_Pnt&\r
48 {\r
49     $result=XYZtoDoubleArray(jenv, $1->XYZ());\r
50 }\r
51 \r
52 %typemap(out) gp_Pnt\r
53 {\r
54     $result=XYZtoDoubleArray(jenv, $1.XYZ());\r
55 }\r
56 \r
57 %typemap(freearg) gp_Pnt, const gp_Pnt&\r
58 {\r
59         delete $1;\r
60 }\r
61 \r
62 %typemap(javain) gp_Pnt, const gp_Pnt& "$javainput"\r
63 %typemap(javaout) gp_Pnt, const gp_Pnt&\r
64 {\r
65         return $jnicall;\r
66 }\r
67 \r
68 /**\r
69  * gp_Pnt2d\r
70  */\r
71 \r
72 %typemap(jni) gp_Pnt2d, const gp_Pnt2d&  "jdoubleArray"\r
73 %typemap(jtype) gp_Pnt2d, const gp_Pnt2d& "double[]"\r
74 %typemap(jstype) gp_Pnt2d, const gp_Pnt2d& "double[]"\r
75 \r
76 %typemap(in) gp_Pnt2d, const gp_Pnt2d&\r
77 {\r
78         if(JCALL1(GetArrayLength, jenv, $input)!=2)\r
79                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 2");\r
80         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
81         $1=new gp_Pnt2d(naxe[0],naxe[1]);\r
82 }\r
83 \r
84 %typemap(freearg) gp_Pnt2d, const gp_Pnt2d&\r
85 {\r
86         delete $1;\r
87 }\r
88 \r
89 %typemap(javain) gp_Pnt2d, const gp_Pnt2d& "$javainput"\r
90 %typemap(javaout) gp_Pnt2d, const gp_Pnt2d&\r
91 {\r
92         return $jnicall;\r
93 }\r
94 \r
95 %typemap(out) gp_Pnt2d, const gp_Pnt2d&\r
96 {\r
97     jdouble nativeArray[]={$1.X(), $1.Y()};\r
98         jdoubleArray toReturn=JCALL1(NewDoubleArray, jenv, 2);\r
99         JCALL4(SetDoubleArrayRegion, jenv, toReturn, 0, 2, nativeArray);\r
100         $result=toReturn;\r
101 }\r
102 /**\r
103  * gp_Pln\r
104  */\r
105 %typemap(jni) gp_Pln, const gp_Pln&  "jdoubleArray"\r
106 %typemap(jtype) gp_Pln, const gp_Pln& "double[]"\r
107 %typemap(jstype) gp_Pln, const gp_Pln& "double[]"\r
108 \r
109 %typemap(in) gp_Pln, const gp_Pln&\r
110 {\r
111         if(JCALL1(GetArrayLength, jenv, $input)!=4)\r
112                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 4");\r
113         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
114         $1=new gp_Pln(naxe[0],naxe[1],naxe[2],naxe[4]);\r
115 }\r
116 \r
117 %typemap(freearg) gp_Pln, const gp_Pln&\r
118 {\r
119         delete $1;\r
120 }\r
121 \r
122 %typemap(javain) gp_Pln, const gp_Pln& "$javainput"\r
123 %typemap(javaout) gp_Pln, const gp_Pln&\r
124 {\r
125         return $jnicall;\r
126 }\r
127 \r
128 %typemap(out) gp_Pln, const gp_Pln &\r
129 {\r
130         double a, b, c, d;\r
131         $1.Coefficients(a, b, c, d);\r
132         jdouble nativeArray[] = {a, b, c, d};\r
133         jdoubleArray toReturn = JCALL1(NewDoubleArray, jenv, 4);\r
134         JCALL4(SetDoubleArrayRegion, jenv, toReturn, 0, 4, nativeArray);\r
135         $result=toReturn;\r
136 }\r
137 \r
138 /**\r
139  * gp_Vec\r
140  */\r
141 %typemap(jni) gp_Vec, const gp_Vec&  "jdoubleArray"\r
142 %typemap(jtype) gp_Vec, const gp_Vec& "double[]"\r
143 %typemap(jstype) gp_Vec, const gp_Vec& "double[]"\r
144 \r
145 %typemap(in) gp_Vec, const gp_Vec&\r
146 {\r
147         if(JCALL1(GetArrayLength, jenv, $input)!=3)\r
148                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 3");\r
149         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
150         $1=new gp_Vec(naxe[0],naxe[1],naxe[2]);\r
151 }\r
152 \r
153 %typemap(freearg) gp_Vec, const gp_Vec&\r
154 {\r
155         delete $1;\r
156 }\r
157 \r
158 %typemap(javain) gp_Vec, const gp_Vec& "$javainput"\r
159 %typemap(javaout) gp_Vec, const gp_Vec&\r
160 {\r
161         return $jnicall;\r
162 }\r
163 \r
164 %typemap(out) gp_Vec, const gp_Vec&\r
165 {\r
166         $result=XYZtoDoubleArray(jenv, $1->XYZ());\r
167 }\r
168 \r
169 /**\r
170  * gp_Dir\r
171  */\r
172 %typemap(jni) gp_Dir, const gp_Dir&, gp_Dir&  "jdoubleArray"\r
173 %typemap(jtype) gp_Dir, const gp_Dir&, gp_Dir& "double[]"\r
174 %typemap(jstype) gp_Dir, const gp_Dir&, gp_Dir& "double[]"\r
175 \r
176 %typemap(in) gp_Dir, const gp_Dir&\r
177 {\r
178         if(JCALL1(GetArrayLength, jenv, $input)!=3)\r
179                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 3");\r
180         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
181         $1=new gp_Dir(naxe[0],naxe[1],naxe[2]);\r
182 }\r
183 \r
184 %typemap(freearg) gp_Dir, const gp_Dir&\r
185 {\r
186         delete $1;\r
187 }\r
188 \r
189 %typemap(out) const gp_Dir&\r
190 {\r
191     $result=XYZtoDoubleArray(jenv, $1->XYZ());\r
192 }\r
193 \r
194 %typemap(out) gp_Dir\r
195 {\r
196     $result=XYZtoDoubleArray(jenv, $1.XYZ());\r
197 }\r
198 \r
199 %typemap(javain) gp_Dir, const gp_Dir&, gp_Dir&  "$javainput"\r
200 %typemap(javaout) gp_Dir, const gp_Dir&, gp_Dir&\r
201 {\r
202         return $jnicall;\r
203 }\r
204 \r
205 /**\r
206  * gp_Ax2\r
207  */\r
208 %typemap(jni) gp_Ax2, const gp_Ax2&  "jdoubleArray"\r
209 %typemap(jtype) gp_Ax2, const gp_Ax2& "double[]"\r
210 %typemap(jstype) gp_Ax2, const gp_Ax2& "double[]"\r
211 \r
212 %typemap(in) gp_Ax2, const gp_Ax2&\r
213 {\r
214     int len = JCALL1(GetArrayLength, jenv, $input);\r
215         if(len !=6 && len != 9)\r
216                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 6 or 9");\r
217         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
218         if (len == 6)\r
219                 $1=new gp_Ax2(gp_Pnt(naxe[0],naxe[1],naxe[2]), gp_Dir(naxe[3], naxe[4], naxe[5]));\r
220         else\r
221                 $1=new gp_Ax2(gp_Pnt(naxe[0],naxe[1],naxe[2]), gp_Dir(naxe[3], naxe[4], naxe[5]), gp_Dir(naxe[6], naxe[7], naxe[8]));\r
222 }\r
223 \r
224 %typemap(freearg) gp_Ax2, const gp_Ax2&\r
225 {\r
226         delete $1;\r
227 }\r
228 \r
229 %typemap(out) gp_Ax2, const gp_Ax2&\r
230 {\r
231         ##error TODO\r
232 }\r
233 \r
234 %typemap(javain) gp_Ax2, const gp_Ax2& "$javainput"\r
235 %typemap(javaout) gp_Ax2, const gp_Ax2&\r
236 {\r
237         return $jnicall;\r
238 }\r
239 \r
240 /**\r
241  * gp_Ax1\r
242  */\r
243 %typemap(jni) gp_Ax1, const gp_Ax1&  "jdoubleArray"\r
244 %typemap(jtype) gp_Ax1, const gp_Ax1& "double[]"\r
245 %typemap(jstype) gp_Ax1, const gp_Ax1& "double[]"\r
246 \r
247 %typemap(in) gp_Ax1, const gp_Ax1&\r
248 {\r
249         if(JCALL1(GetArrayLength, jenv, $input)!=6)\r
250                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 6");\r
251         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
252         $1=new gp_Ax1(gp_Pnt(naxe[0],naxe[1],naxe[2]), gp_Dir(naxe[3], naxe[4], naxe[5]));\r
253 }\r
254 \r
255 %typemap(freearg) gp_Ax1, const gp_Ax1&\r
256 {\r
257         delete $1;\r
258 }\r
259 \r
260 %typemap(out) gp_Ax1, const gp_Ax1&\r
261 {\r
262         ##error TODO\r
263 }\r
264 \r
265 %typemap(javain) gp_Ax1, const gp_Ax1& "$javainput"\r
266 %typemap(javaout) gp_Ax1, const gp_Ax1&\r
267 {\r
268         return $jnicall;\r
269 }\r
270 \r
271 /**\r
272  * gp_Trsf\r
273  */\r
274  %{#include <gp_Trsf.hxx>%}\r
275  \r
276 %rename(GP_Trsf) gp_Trsf;\r
277 \r
278 %typemap(javacode) gp_Trsf\r
279 %{\r
280         public void setValues(double[] matrix, double tolAng, double tolDist)\r
281         {\r
282                 if(matrix.length!=12)\r
283                         throw new IllegalArgumentException("matrix length must be 12");\r
284                 setValues(\r
285                         matrix[0], matrix[1], matrix[2], matrix[3],\r
286                         matrix[4], matrix[5], matrix[6], matrix[7],\r
287                         matrix[8], matrix[9], matrix[10], matrix[11],\r
288                         tolAng, tolDist);\r
289         }       \r
290 %}\r
291 \r
292 class gp_Trsf\r
293 {\r
294         %rename(setRotation) SetRotation;\r
295         %rename(setTranslation) SetTranslation;\r
296         %rename(setValues) SetValues;\r
297         public:\r
298         gp_Trsf();\r
299         void SetRotation(const gp_Ax1& A1,const Standard_Real Ang) ;\r
300         void SetTranslation(const gp_Vec& V) ;\r
301         void SetValues(const Standard_Real a11,const Standard_Real a12,\r
302                 const Standard_Real a13,const Standard_Real a14,const Standard_Real a21,\r
303                 const Standard_Real a22,const Standard_Real a23,const Standard_Real a24,\r
304                 const Standard_Real a31,const Standard_Real a32,const Standard_Real a33,\r
305                 const Standard_Real a34,const Standard_Real Tolang,\r
306                 const Standard_Real TolDist);\r
307 };\r
308 \r
309 %extend gp_Trsf\r
310 {\r
311         /** Easy to use with javax.vecmath.Matrix4D */\r
312         void getValues(double matrix[16])\r
313         {\r
314                 int k=0;\r
315                 for(int i=1; i<=3; i++)\r
316                         for(int j=1; j<=4; j++)\r
317                                 matrix[k++]=self->Value(i,j);\r
318                 matrix[12]=0;\r
319                 matrix[13]=0;\r
320                 matrix[14]=0;\r
321                 matrix[15]=1;\r
322         }\r
323 }\r
324 \r
325 /**\r
326  * GP_Circ\r
327  */\r
328 %{#include <gp_Circ.hxx>%}\r
329 %rename(GP_Circ) gp_Circ;\r
330 class gp_Circ\r
331 {\r
332     public:\r
333     gp_Circ(const gp_Ax2& axis, const Standard_Real radius);\r
334 };\r
335 \r
336 /**\r
337  * GP_Parab\r
338  */\r
339 %{#include <gp_Parab.hxx>%}\r
340 %rename(GP_Parab) gp_Parab;\r
341 class gp_Parab\r
342 {\r
343     public:\r
344         gp_Parab(const gp_Ax2& A2,const Standard_Real Focal);\r
345         gp_Parab(const gp_Ax1& D,const gp_Pnt& F);\r
346 };\r
347 \r
348 \r
349 /*******************************************************************\r
350  *                                                                 *\r
351  *  VTT                                                            *\r
352  *                                                                 *\r
353  *******************************************************************/\r
354 \r
355 /**\r
356  * GP_Ellips\r
357  */\r
358 %{#include <gp_Elips.hxx>%}\r
359  \r
360  %rename(GP_Elips) gp_Elips;\r
361  \r
362  class gp_Elips\r
363 {\r
364 \r
365         public:\r
366         gp_Elips(const gp_Ax2& A2,const Standard_Real MajorRadius,const Standard_Real MinorRadius);\r
367 };\r
368 \r
369 /**\r
370  * GP_Lin\r
371  */\r
372 \r
373  %{#include <gp_Lin.hxx>%}\r
374  \r
375  %rename(GP_Lin) gp_Lin;\r
376  \r
377  class gp_Lin\r
378 {\r
379         public:\r
380         gp_Lin(const gp_Ax1& A1);\r
381 };\r
382 \r
383 \r
384 /**\r
385  * gp_Mat\r
386  */\r
387   %{#include <gp_Mat.hxx>%}\r
388 %typemap(jni) gp_Mat, const gp_Mat&  "jdoubleArray"\r
389 %typemap(jtype) gp_Mat, const gp_Mat& "double[]"\r
390 %typemap(jstype) gp_Mat, const gp_Mat& "double[]"\r
391 \r
392 %typemap(in) gp_Mat, const gp_Mat&\r
393 {\r
394         if(JCALL1(GetArrayLength, jenv, $input)!=9)\r
395                 SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, "array length must be 9");\r
396         jdouble * naxe=JCALL2(GetDoubleArrayElements, jenv, $input, NULL);\r
397         $1=new gp_Mat(naxe[0],naxe[1],naxe[2],naxe[3],naxe[4],naxe[5],naxe[6],naxe[7],naxe[8]);\r
398 }\r
399 \r
400 %typemap(freearg) gp_Mat, const gp_Mat&\r
401 {\r
402         delete $1;\r
403 }\r
404 \r
405 %typemap(javain) gp_Mat, const gp_Mat& "$javainput"\r
406 %typemap(javaout) gp_Mat, const gp_Mat&\r
407 {\r
408         return $jnicall;\r
409 }\r
410 \r
411 %{\r
412         jdoubleArray MatToDoubleArray(JNIEnv* jenv, const gp_Mat & mat)\r
413         {\r
414             jdouble nativeArray[]={mat.Value(1,1), mat.Value(1,2), mat.Value(1,3),\r
415                                        mat.Value(2,1), mat.Value(2,2), mat.Value(2,3),\r
416                                                            mat.Value(3,1), mat.Value(3,2), mat.Value(3,3)};\r
417                 jdoubleArray toReturn=jenv->NewDoubleArray(9);\r
418                 jenv->SetDoubleArrayRegion(toReturn, 0, 9, nativeArray);\r
419                 return toReturn;\r
420         }\r
421 %}\r
422 \r
423 %typemap(out) gp_Mat, const gp_Mat&\r
424 {\r
425         $result=MatToDoubleArray(jenv, $1);\r
426 }