0023024: Update headers of OCCT files
[occt.git] / src / BRepToIGES / BRepToIGES_BREntity.cxx
1 // Created on: 1995-01-30
2 // Created by: Marie Jose MARTZ
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21 //szv#4 S4163
22 //eap: Tue Aug 29 11:02:56 2000: Shape Processing moved to upper levels
23
24 #include <BRepToIGES_BREntity.ixx>
25
26 #include <BRepToIGES_BRWire.hxx>
27 #include <BRepToIGES_BRShell.hxx>
28 #include <BRepToIGES_BRSolid.hxx>
29
30 #include <BRep_Builder.hxx>
31
32 #include <gp_Trsf.hxx>
33
34 #include <Geom_Geometry.hxx>
35
36 #include <IGESData_IGESEntity.hxx>
37
38 #include <Interface_Macros.hxx>
39 #include <Interface_Static.hxx>
40
41 //#include <ShapeCustom.hxx>
42
43 #include <TopLoc_Location.hxx>
44
45 #include <TopoDS.hxx>
46 #include <TopoDS_Compound.hxx>
47 #include <TopoDS_CompSolid.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Solid.hxx>
51 #include <TopoDS_Shape.hxx>
52 #include <TopoDS_Shell.hxx>
53 #include <TopoDS_Vertex.hxx>
54 #include <TopoDS_Wire.hxx>
55
56 #include <Transfer_FinderProcess.hxx>
57 #include <TransferBRep_ShapeMapper.hxx>
58 #include <TransferBRep_OrientedShapeMapper.hxx>
59 #include <Transfer_TransientMapper.hxx>
60 #include <Transfer_SimpleBinderOfTransient.hxx>
61
62 char Name[100];
63
64 //=======================================================================
65 //function : BRepToIGES_BREntity
66 //purpose  : 
67 //=======================================================================
68
69 BRepToIGES_BREntity::BRepToIGES_BREntity()
70 {  
71   Init();
72 }
73
74 //=======================================================================
75 //function : Init
76 //purpose  : 
77 //=======================================================================
78
79 void BRepToIGES_BREntity::Init()
80 {  
81   TheMap = new Transfer_FinderProcess();
82   TheUnitFactor = 1.;
83   myConvSurface = Interface_Static::IVal("write.convertsurface.mode");
84   myPCurveMode = Interface_Static::IVal("write.surfacecurve.mode");
85 }
86
87 //=======================================================================
88 //function : SetModel
89 //purpose  : 
90 //=======================================================================
91 void BRepToIGES_BREntity::SetModel(const Handle(IGESData_IGESModel)& model)
92 {  
93   TheModel = model;  
94   Standard_Real unitfactor = TheModel->GlobalSection().UnitValue();
95   if (unitfactor != 1.)
96     TheUnitFactor = unitfactor;
97 }
98
99
100 //=======================================================================
101 //function : GetModel
102 //purpose  : 
103 //=======================================================================
104 Handle(IGESData_IGESModel) BRepToIGES_BREntity::GetModel() const
105 { return TheModel; }
106
107
108 //=======================================================================
109 //function : GetUnit
110 //purpose  : 
111 //=======================================================================
112 Standard_Real BRepToIGES_BREntity::GetUnit() const
113 {
114   return TheUnitFactor;
115 }  
116
117
118 //=======================================================================
119 //function : SetTransferProcess
120 //purpose  : 
121 //=======================================================================
122 void BRepToIGES_BREntity::SetTransferProcess(const Handle(Transfer_FinderProcess)& TP)
123 {  TheMap = TP;  }
124
125
126 //=======================================================================
127 //function : GetTransferProcess
128 //purpose  : 
129 //=======================================================================
130 Handle(Transfer_FinderProcess) BRepToIGES_BREntity::GetTransferProcess() const
131 { return TheMap; }
132
133
134 //=======================================================================
135 //function : TransferShape
136 //purpose  : 
137 //=======================================================================
138 Handle(IGESData_IGESEntity) BRepToIGES_BREntity::TransferShape
139 (const TopoDS_Shape& start)
140 {
141   Handle(IGESData_IGESEntity) res;
142 //  TopoDS_Shape theShape;
143   //Standard_Integer Nb = 1; //szv#4:S4163:12Mar99 not needed
144
145   if (start.IsNull()) return res;
146
147   if (start.ShapeType() == TopAbs_VERTEX) {
148     TopoDS_Vertex V = TopoDS::Vertex(start);
149     BRepToIGES_BRWire BW(*this);
150     BW.SetModel(GetModel());
151     res = BW.TransferVertex(V);
152   }  
153   else if (start.ShapeType() == TopAbs_EDGE) {
154     TopoDS_Edge E =  TopoDS::Edge(start);
155     BRepToIGES_BRWire BW(*this);
156     BW.SetModel(GetModel());
157     res = BW.TransferEdge(E, Standard_False);
158   }  
159   else if (start.ShapeType() == TopAbs_WIRE) {
160     TopoDS_Wire W =  TopoDS::Wire(start);
161     BRepToIGES_BRWire BW(*this);
162     BW.SetModel(GetModel());
163     res = BW.TransferWire(W);
164   }  
165   else { 
166     //    la fonction suivante force les surfaces indirectes en
167     //    surfaces directes (obligatoire dans IGES) 
168 //    theShape = ShapeCustom::DirectFaces(start);  
169     //sprintf(Name,"res_%d",Nb++);
170     //DBRep::Set(Name,theShape);
171
172     if (start.ShapeType() == TopAbs_FACE) {
173       TopoDS_Face F =  TopoDS::Face(start);
174       BRepToIGES_BRShell BS(*this);
175       BS.SetModel(GetModel());
176       res = BS.TransferFace(F);
177     }  
178     else if (start.ShapeType() == TopAbs_SHELL) {
179       TopoDS_Shell S =  TopoDS::Shell(start);
180       BRepToIGES_BRShell BS(*this);
181       BS.SetModel(GetModel());
182       res = BS.TransferShell(S);
183     }  
184     else if (start.ShapeType() == TopAbs_SOLID) {
185       TopoDS_Solid M =  TopoDS::Solid(start);
186       BRepToIGES_BRSolid BS(*this);
187       BS.SetModel(GetModel());
188       res = BS.TransferSolid(M);
189     }  
190     else if (start.ShapeType() == TopAbs_COMPSOLID) {
191       TopoDS_CompSolid C =  TopoDS::CompSolid(start);
192       BRepToIGES_BRSolid BS(*this);
193       BS.SetModel(GetModel());
194       res = BS.TransferCompSolid(C);
195     }  
196     else if (start.ShapeType() == TopAbs_COMPOUND) {
197       TopoDS_Compound C =  TopoDS::Compound(start);
198       BRepToIGES_BRSolid BS(*this);
199       BS.SetModel(GetModel());
200       res = BS.TransferCompound(C);
201     }  
202     else {
203       // message d`erreur
204     }  
205   }
206
207   return res;
208 }
209
210
211 //=======================================================================
212 //function : AddFail
213 //purpose  : 
214 //=======================================================================
215
216 void BRepToIGES_BREntity::AddFail 
217   (const TopoDS_Shape& start,
218    const Standard_CString amess)
219 {
220   Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
221   TheMap->AddFail(Mapper, amess);
222 }
223
224
225 //=======================================================================
226 //function : AddWarning
227 //purpose  : 
228 //=======================================================================
229
230 void BRepToIGES_BREntity::AddWarning 
231   (const TopoDS_Shape& start,
232    const Standard_CString amess)
233 {
234   Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
235   TheMap->AddWarning(Mapper, amess);
236 }
237
238
239 //=======================================================================
240 //function : AddFail
241 //purpose  : 
242 //=======================================================================
243
244 void BRepToIGES_BREntity::AddFail 
245   (const Handle(Standard_Transient)& start,
246    const Standard_CString amess)
247 {
248   Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
249   TheMap->AddFail(Mapper, amess);
250 }
251
252
253 //=======================================================================
254 //function : AddWarning
255 //purpose  : 
256 //=======================================================================
257
258 void BRepToIGES_BREntity::AddWarning 
259   (const Handle(Standard_Transient)& start,
260    const Standard_CString amess)
261 {
262   Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
263   TheMap->AddWarning(Mapper, amess);
264 }
265
266
267 //=======================================================================
268 //function : HasShapeResult
269 //purpose  : 
270 //=======================================================================
271
272 Standard_Boolean BRepToIGES_BREntity::HasShapeResult 
273   (const TopoDS_Shape& start) const
274 {
275   Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
276   DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
277   if (binder.IsNull()) return Standard_False;
278   return binder->HasResult();
279 }
280
281
282 //=======================================================================
283 //function : GetShapeResult
284 //purpose  : 
285 //=======================================================================
286
287 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult 
288   (const TopoDS_Shape& start) const
289 {
290   Handle(Standard_Transient) res;
291
292   Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
293   DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
294   if (binder.IsNull()) return res;
295   if (binder->HasResult())
296     res = binder->Result();
297   return res;
298 }
299
300
301 //=======================================================================
302 //function : SetShapeResult
303 //purpose  : 
304 //=======================================================================
305
306 void BRepToIGES_BREntity::SetShapeResult 
307   ( const TopoDS_Shape& start,
308     const Handle(Standard_Transient)& result)
309 {
310   Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
311   Handle(Transfer_SimpleBinderOfTransient) binder = new Transfer_SimpleBinderOfTransient;
312   binder->SetResult(result);
313   TheMap->Bind(Mapper,binder);
314 }
315
316 //=======================================================================
317 //function : HasShapeResult
318 //purpose  : 
319 //=======================================================================
320
321 Standard_Boolean BRepToIGES_BREntity::HasShapeResult 
322   (const Handle(Standard_Transient)& start) const
323 {
324   Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
325   DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
326   if (binder.IsNull()) return Standard_False;
327   return binder->HasResult();
328 }
329
330
331 //=======================================================================
332 //function : GetShapeResult
333 //purpose  : 
334 //=======================================================================
335
336 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult 
337   (const Handle(Standard_Transient)& start) const
338 {
339   Handle(Standard_Transient) res;
340
341   Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
342   DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
343   if (binder.IsNull()) return res;
344   if (binder->HasResult())
345     res = binder->Result();
346   return res;
347 }
348
349
350 //=======================================================================
351 //function : SetShapeResult
352 //purpose  : 
353 //=======================================================================
354
355 void BRepToIGES_BREntity::SetShapeResult 
356   ( const Handle(Standard_Transient)& start,
357     const Handle(Standard_Transient)& result)
358 {
359   Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
360   Handle(Transfer_SimpleBinderOfTransient) binder = new Transfer_SimpleBinderOfTransient;
361   TheMap->Bind(Mapper,binder);
362   binder->SetResult(result);
363 }
364
365 //=======================================================================
366 //function : GetConvertSurfaceMode
367 //purpose  : 
368 //=======================================================================
369
370 Standard_Boolean BRepToIGES_BREntity::GetConvertSurfaceMode () const
371 {
372   return myConvSurface;
373 }
374             
375 //=======================================================================
376 //function : GetPCurveMode
377 //purpose  : 
378 //=======================================================================
379
380 Standard_Boolean BRepToIGES_BREntity::GetPCurveMode () const
381 {
382   return myPCurveMode;
383 }
384             
385 //=======================================================================
386 //function : Delete
387 //purpose  : 
388 //=======================================================================
389
390 void BRepToIGES_BREntity::Delete() 
391 {}