]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src/TopoDS.i
Compiler warning elimination
[simantics/3d.git] / org.jcae.opencascade / src / TopoDS.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  * (C) Copyright 2009, by EADS France
20  */
21
22 %{
23 #include <TopoDS_CompSolid.hxx>
24 #include <TopoDS_Solid.hxx>
25 #include <TopoDS_Shell.hxx>
26 #include <TopoDS_Compound.hxx>
27 #include <TopoDS_Wire.hxx>
28 #include <TopoDS_Iterator.hxx>
29 #include <TopoDS_Builder.hxx>
30 %}
31
32 /** 
33  * TopoDS_Shape
34  */
35 // Ensure that the Java class will always be the good one, so we can use
36 // instanceof operator.
37 // Problem: Returning a shape require 2 initialisation (the TopoDS_Shape
38 // and after the real TopoDS_XXXXX. It may reduce performance comparing
39 // to libOccJava.
40
41 %typemap(out) TopoDS_Shape
42 {
43         if($1.IsNull())
44         {
45                 $result=0L; //NULL
46         }
47         else
48         {
49                 TopoDS_Shape * tsp=new TopoDS_Shape();
50                 tsp->TShape($1.TShape());
51                 tsp->Location($1.Location());
52                 tsp->Orientation($1.Orientation());
53                 $result=(jlong)tsp;
54         }
55 }
56
57 %typemap(out) const TopoDS_Shape &, const TopoDS_Compound &
58 {
59         if($1->IsNull())
60         {
61                 $result=0L; //NULL
62         }
63         else
64         {
65                 $1_basetype * tsp=new $1_basetype();
66                 tsp->TShape($1->TShape());
67                 tsp->Location($1->Location());
68                 tsp->Orientation($1->Orientation());
69                 $result=(jlong)tsp;
70         }
71 }
72
73 %typemap(javaout) TopoDS_Shape*, TopoDS_Shape, const TopoDS_Shape&, const TopoDS_Compound &
74 {
75     long cPtr = $jnicall;
76     return ($javaclassname)TopoDS_Shape.create(cPtr);
77 }
78
79 %typemap(javacode) TopoDS_Shape
80 %{
81         private long myTShape;
82         protected static TopoDS_Shape downcast(TopoDS_Shape in)
83         {
84                 TopoDS_Shape toReturn = create(getCPtr(in));
85                 in.swigCMemOwn=false;
86                 return toReturn;
87         }
88
89         protected static TopoDS_Shape create(long in)
90         {
91                 if(in==0)
92                         return null;
93                 //second argument is not use in swig
94                 TopAbs_ShapeEnum type = TopAbs_ShapeEnum.swigToEnum(OccJavaJNI.TopoDS_Shape_shapeType(in, null));
95                 return create(in, type);
96         }
97
98         protected static TopoDS_Shape create(long in, TopAbs_ShapeEnum type)
99         {
100                 TopoDS_Shape toReturn=null;
101                 if(in==0)
102                         return null;
103                 switch(type)
104                 {
105                         case COMPOUND:
106                                 toReturn=new TopoDS_Compound(in, true);
107                                 break;
108                         case COMPSOLID:
109                                 toReturn=new TopoDS_CompSolid(in, true);
110                                 break;
111                         case SOLID:
112                                 toReturn=new TopoDS_Solid(in, true);
113                                 break;
114                         case SHELL:
115                                 toReturn=new TopoDS_Shell(in, true);
116                                 break;
117                         case FACE:
118                                 toReturn=new TopoDS_Face(in, true);
119                                 break;
120                         case WIRE:
121                                 toReturn=new TopoDS_Wire(in, true);
122                                 break;
123                         case EDGE:
124                                 toReturn=new TopoDS_Edge(in, true);
125                                 break;
126                         case VERTEX:
127                                 toReturn=new TopoDS_Vertex(in, true);
128                                 break;
129                 }
130                 toReturn.myTShape=toReturn.getTShape();
131                 return toReturn;
132     }
133     public boolean isSame(TopoDS_Shape s)
134     {
135         /*if(myTShape==0)
136                         myTShape=getTShape();
137                 
138                 if(s.myTShape==0)
139                         s.myTShape=s.getTShape();
140                 
141                 if(myTShape==s.myTShape)
142         {
143             return nativeIsSame(s);
144         }
145         else return false;*/
146                 return nativeIsSame(s);
147     }
148         
149     /**
150      * Alias on the isSame method for an easy use of this class in java
151      * collections
152      */
153     public boolean equals(Object o)
154     {
155         if (o instanceof TopoDS_Shape)
156         {
157             return isSame((TopoDS_Shape)o);
158         }
159         else return false;
160     }
161
162         public int hashCode()
163         {
164                 return hashCode(Integer.MAX_VALUE);
165         }
166
167         protected static TopoDS_Shape[] cArrayWrap(long[] ptrs)
168         {
169                 TopoDS_Shape[] toReturn = new TopoDS_Shape[ptrs.length/2];
170                 long ptr;
171                 int type;
172                 for (int i=0, j=0; i<toReturn.length; i++)
173                 {  
174                         ptr = ptrs[j++];
175                         type = (int)ptrs[j++];
176                         toReturn[i] = create(ptr, TopAbs_ShapeEnum.swigToEnum(type));
177                 }
178                 return toReturn;
179         }
180
181         protected static long[] cArrayUnwrap(TopoDS_Shape[] arrayWrapper)
182         {
183                 long[] cArray = new long[arrayWrapper.length];
184                 for (int i=0; i<arrayWrapper.length; i++)
185                 cArray[i] = TopoDS_Shape.getCPtr(arrayWrapper[i]);
186                 return cArray;
187         }
188 %}
189
190 // Note that TopoDS_Shape is no longer abstract (it was in libOccJava)
191 class TopoDS_Shape
192 {
193         public:
194         %rename(free) Free;
195         %rename(shapeType) ShapeType;
196         %rename(nativeIsSame) IsSame;
197         %rename(orientation) Orientation;
198         %rename(reverse) Reverse;
199         %rename(reversed) Reversed;
200         %rename(hashCode) HashCode;
201         TopAbs_ShapeEnum ShapeType();
202         Standard_Boolean IsSame(const TopoDS_Shape& other) const;
203         TopAbs_Orientation Orientation() const;
204         void Reverse() ;
205         TopoDS_Shape Reversed() const;
206         Standard_Integer HashCode(const Standard_Integer Upper) const;
207         Standard_Boolean Free() const;
208         void Free(const Standard_Boolean F) ;
209 };
210
211 %extend TopoDS_Shape
212 {
213         public:
214         //This will be used to speedup the equal operator as in libOccJava
215         jlong getTShape()
216         {
217                 return (jlong)&*self->TShape();
218         }       
219 }
220
221 class TopoDS_Compound: public TopoDS_Shape
222 {
223 };
224
225 class TopoDS_CompSolid: public TopoDS_Shape
226 {
227 };
228
229 class TopoDS_Solid: public TopoDS_Shape
230 {
231 };
232
233 class TopoDS_Shell: public TopoDS_Shape
234 {
235 };
236
237 class TopoDS_Face: public TopoDS_Shape
238 {
239 };
240
241 class TopoDS_Wire: public TopoDS_Shape
242 {
243 };
244
245 class TopoDS_Edge: public TopoDS_Shape
246 {
247 };
248
249 class TopoDS_Vertex: public TopoDS_Shape
250 {
251 };
252
253 class TopoDS_Iterator
254 {
255         %rename(initialize) Initialize;
256         %rename(more) More;
257         %rename(next) Next;
258         %rename(value) Value;
259         public:
260         TopoDS_Iterator();
261         TopoDS_Iterator(const TopoDS_Shape& S,
262                 const Standard_Boolean cumOri = Standard_True,
263                 const Standard_Boolean cumLoc = Standard_True);
264         void Initialize(const TopoDS_Shape& S,
265                 const Standard_Boolean cumOri = Standard_True,
266                 const Standard_Boolean cumLoc = Standard_True) ;
267         Standard_Boolean More() const;
268         void Next() ;
269         const TopoDS_Shape& Value() const;
270 };
271
272 class TopoDS_Builder
273 {
274         %rename(makeWire) MakeWire;
275         %rename(makeCompound) MakeCompound;
276         %rename(add) Add;
277         %rename(remove) Remove;
278         
279         TopoDS_Builder()=0;
280         public:
281         void MakeWire(TopoDS_Wire& W) const;
282         void MakeCompound(TopoDS_Compound& C) const;
283         void Add(TopoDS_Shape& S,const TopoDS_Shape& C) const;
284         void Remove(TopoDS_Shape& S,const TopoDS_Shape& C) const;       
285 };
286