]> gerrit.simantics Code Review - simantics/3d.git/blob - org.jcae.opencascade/src/XSControl.i
Compiler warning elimination
[simantics/3d.git] / org.jcae.opencascade / src / XSControl.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 2007, by EADS France
19  */
20
21 //A workaround for charset encoding problems
22 %typemap(jni) jbyte[]  "jbyteArray"
23 %typemap(jtype) jbyte[] "byte[]"
24 %typemap(jstype) jbyte[] "byte[]"
25 %typemap(in) jbyte[]
26 {
27         int length = JCALL1(GetArrayLength, jenv, $input);
28         jbyte * name = new jbyte[length+1];
29         JCALL4(GetByteArrayRegion, jenv, $input, 0, length, name); 
30         name[length] = '\0';
31         $1 = name;
32 }
33 %typemap(javain) jbyte[] "$javainput"
34
35
36 /**
37  * XSControl_Reader
38  */
39  %{
40 #include <STEPControl_Reader.hxx>
41 #include <IGESControl_Reader.hxx>
42 #include <XSControl_WorkSession.hxx>
43 #include <XSControl_TransferReader.hxx>
44 #include <StepRepr_RepresentationItem.hxx>
45 #include <TCollection_HAsciiString.hxx>
46 #include <IGESData_IGESEntity.hxx>
47 #include <TransferBRep.hxx>
48 #include <Transfer_Binder.hxx>
49 #include <Transfer_TransientProcess.hxx>
50 #include <Interface_InterfaceModel.hxx>
51 #include <iostream>
52
53 #include <Interface_Static.hxx>
54
55  %}
56 class XSControl_Reader
57 {
58         %javamethodmodifiers ReadFile(const Standard_CString filename)"
59         /**
60          * @deprecated May segfault if path name include none-ASCII caracters. Use
61          * readFile(stringPath.getBytes()) instead.
62          */
63         public";
64
65         XSControl_Reader()=0;
66         %rename(readFile) ReadFile;
67         %rename(transferRoots) TransferRoots;
68         %rename(clearShapes) ClearShapes;
69         %rename(nbRootsForTransfer) NbRootsForTransfer;
70         %rename(oneShape) OneShape;
71         public:
72         IFSelect_ReturnStatus ReadFile(const Standard_CString filename);
73         //IFSelect_ReturnStatus ReadFile(jbyte filename[]);
74         Standard_Integer TransferRoots() ;
75         void ClearShapes();
76         Standard_Integer NbRootsForTransfer();
77         TopoDS_Shape OneShape() const;
78
79 };
80
81 %extend XSControl_Reader
82 {
83         //A workaround for charset encoding problems
84         IFSelect_ReturnStatus readFile(jbyte filename[])
85         {
86                 return self->ReadFile((char*)filename);
87         }
88 };
89
90
91
92 %extend XSControl_Reader
93 {
94         
95
96         bool setReadUnitM() {
97                 //return Interface_Static::SetCVal("read.scale.unit","M");
98                 return Interface_Static::SetCVal("xstep.cascade.unit","M");
99         }
100
101         bool setReadUnitMM() {
102                 //return Interface_Static::SetCVal("read.scale.unit","MM");
103                 return Interface_Static::SetCVal("xstep.cascade.unit","MM");
104         }
105 }
106
107 class STEPControl_Reader: public XSControl_Reader
108 {
109         public:
110         STEPControl_Reader();
111 };
112
113 %extend STEPControl_Reader
114 {
115 //dirty quick implementation of label step reading
116 //find how to generalize this to IGES
117         const char * getLabel(TopoDS_Shape * theShape)
118         {
119                 const Handle(XSControl_WorkSession)& theSession = self->WS();
120                 const Handle(XSControl_TransferReader)& aReader = theSession->TransferReader();
121                 Handle(Standard_Transient) anEntity = aReader->EntityFromShapeResult(*theShape, 1);
122                 if (anEntity.IsNull()) {
123                         // as just mapped
124                         anEntity = aReader->EntityFromShapeResult (*theShape,-1);
125                 }
126
127                 if (anEntity.IsNull()) {
128                         // as anything
129                         anEntity = aReader->EntityFromShapeResult (*theShape,4);
130                 }
131
132                 if (anEntity.IsNull()) {
133                         cout<<"Warning: XSInterface_STEPReader::ReadAttributes() entity not found"<<endl;
134                         return NULL;
135                 }
136                 else 
137                 {
138                         Handle(StepRepr_RepresentationItem) aReprItem;
139                         aReprItem = Handle(StepRepr_RepresentationItem)::DownCast(anEntity);
140
141                         if (aReprItem.IsNull()) {
142                                 cout<<"Error: STEPReader::ReadAttributes(): StepRepr_RepresentationItem Is NULL"<<endl;
143                                 return NULL;
144                         }
145                         else 
146                                 return aReprItem->Name()->ToCString();
147                 }
148         }
149 };
150
151 class IGESControl_Reader: public XSControl_Reader
152 {
153         public:
154         IGESControl_Reader();
155 };
156
157 %extend IGESControl_Reader 
158 {
159         //dirty quick implementation of label iges reading 
160         const char * getLabel(TopoDS_Shape theShape) 
161         {
162                 const Handle(XSControl_WorkSession)& theSession = self->WS();
163                 const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
164                 const Handle(XSControl_TransferReader)& aReader = theSession->TransferReader();
165                 const Handle(Transfer_TransientProcess)& tp = aReader->TransientProcess();
166                 Standard_Integer nb = theModel->NbEntities(); 
167                 for(Standard_Integer i=1; i<=nb; i++) 
168                 {
169                         Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(theModel->Value(i));
170
171                         if (ent.IsNull())
172                                 continue;
173
174                         Handle(Transfer_Binder) binder = tp->Find(ent); 
175
176                         if (binder.IsNull())
177                                 continue;
178                         TopoDS_Shape oneShape = TransferBRep::ShapeResult(binder);
179                         if (oneShape.IsNull())
180                                 continue;
181                         if (oneShape.IsEqual(theShape))
182                         {
183                                 if (ent->HasName())
184                                         return ent->NameValue()->String().ToCString();
185                                 else
186                                         return NULL; 
187                         }
188                 }
189                 return NULL; 
190         }
191
192         //get shape for label 
193         TopoDS_Shape getShape(char* shapeName)
194         {
195                 const TCollection_AsciiString ascShapeName(shapeName);
196                 const Handle(XSControl_WorkSession)& theSession = self->WS();
197                 const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
198                 const Handle(XSControl_TransferReader)& aReader = theSession->TransferReader();
199                 const Handle(Transfer_TransientProcess)& tp = aReader->TransientProcess();
200                 Standard_Integer nb = theModel->NbEntities();
201                 TopoDS_Shape retShape; 
202                 for(Standard_Integer i=1; i<=nb; i++)
203                 {
204                         Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(theModel->Value(i));
205
206                         if (ent.IsNull())
207                                 continue;
208                         Handle(Transfer_Binder) binder = tp->Find(ent);
209
210                         if (binder.IsNull())
211                                 continue;
212                         TopoDS_Shape oneShape = TransferBRep::ShapeResult(binder);
213
214                         if (oneShape.IsNull())
215                                 continue;
216
217                         if (ent->HasName() && ent->NameValue()->String().IsEqual(ascShapeName))
218                                 retShape = oneShape;
219                 }
220                 return retShape; 
221         }
222
223         //dump all labels 
224         void dumpLabels()
225         {
226                 const Handle(XSControl_WorkSession)& theSession = self->WS();
227                 const Handle(Interface_InterfaceModel)& theModel = theSession->Model();
228                 Standard_Integer nb = theModel->NbEntities();
229                 for(Standard_Integer i=1; i<=nb; i++)
230                 {
231                         Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(theModel->Value(i));
232                         if (ent.IsNull()) continue;
233                         if (ent->HasName())
234                         {
235                                 std::cout << ent->NameValue()->String().ToCString() << std::endl;
236                         }
237                 }
238         }
239 };
240
241 /**
242  * STEPControl_Writer
243  * Usage:
244  *    STEPControl_Writer aWriter = new STEPControl_Writer()
245  *    aWriter.transfer(shape, STEPControl_StepModelType.AsIs)
246  *    aWriter.write("foo.stp")
247  */
248  %{
249 //#include <APIHeaderSection_MakeHeader.hxx>
250 #include <STEPControl_Writer.hxx>
251  %}
252 class STEPControl_Writer
253 {
254         %rename(write) Write;
255         %rename(transfer) Transfer;
256         %rename(model) Model;
257         public:
258         STEPControl_Writer();
259         IFSelect_ReturnStatus Write(const Standard_CString filename);
260         IFSelect_ReturnStatus Transfer(TopoDS_Shape theShape, STEPControl_StepModelType mode);
261         // FIXME: 7.3.0 Handle_StepData_StepModel cannot be resolved
262         //Handle_StepData_StepModel Model(const Standard_Boolean newone);
263         //Handle(StepData_StepModel) Model(const Standard_Boolean newone);
264 };
265
266
267 %rename(AsIs) STEPControl_AsIs;
268 %rename(ManifoldSolidBrep) STEPControl_ManifoldSolidBrep;
269 %rename(BrepWithVoids) STEPControl_BrepWithVoids;
270 %rename(FacetedBrep) STEPControl_FacetedBrep;
271 %rename(FacetedBrepAndBrepWithVoids) STEPControl_FacetedBrepAndBrepWithVoids;
272 %rename(ShellBasedSurfaceModel) STEPControl_ShellBasedSurfaceModel;
273 %rename(GeometricCurveSet) STEPControl_GeometricCurveSet;
274 %rename(Hybrid) STEPControl_Hybrid;
275 enum STEPControl_StepModelType {
276  STEPControl_AsIs,
277  STEPControl_ManifoldSolidBrep,
278  STEPControl_BrepWithVoids,
279  STEPControl_FacetedBrep,
280  STEPControl_FacetedBrepAndBrepWithVoids,
281  STEPControl_ShellBasedSurfaceModel,
282  STEPControl_GeometricCurveSet,
283  STEPControl_Hybrid
284 };
285
286 /**
287  * IGESControl_Writer
288  * Usage:
289  *   new IGESControl_Controller().init()
290  *   IGESControl_Writer aWriter = new IGESControl_Writer("MM", 0)
291  *   aWriter.addShape(shape)
292  *   aWriter.computeModel()
293  *   aWriter.write("foo.igs")
294  */
295  %{
296 #include <IGESControl_Writer.hxx>
297  %}
298 class IGESControl_Writer
299 {
300         %rename(write) Write;
301         %rename(addShape) AddShape;
302         %rename(computeModel) ComputeModel;
303         public:
304         IGESControl_Writer();
305         IGESControl_Writer(const Standard_CString unit, const Standard_Integer modecr = 0);
306         Standard_Boolean Write(const Standard_CString filename);
307         Standard_Boolean AddShape(const TopoDS_Shape& sh);
308         void ComputeModel();
309 };
310
311  %{
312 #include <IGESControl_Controller.hxx>
313  %}
314 class IGESControl_Controller
315 {
316         %rename(init) Init;
317         public:
318         IGESControl_Controller();
319         void Init();
320 };
321
322