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