1 // Created on: 1995-01-30
2 // Created by: Marie Jose MARTZ
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 //eap: Tue Aug 29 11:02:56 2000: Shape Processing moved to upper levels
20 #include <BRep_Builder.hxx>
21 #include <BRepToIGES_BREntity.hxx>
22 #include <BRepToIGES_BRShell.hxx>
23 #include <BRepToIGES_BRSolid.hxx>
24 #include <BRepToIGES_BRWire.hxx>
25 #include <Geom_Geometry.hxx>
26 #include <gp_Trsf.hxx>
27 #include <IGESData_IGESEntity.hxx>
28 #include <IGESData_IGESModel.hxx>
29 #include <Interface_Macros.hxx>
30 #include <Interface_Static.hxx>
31 #include <Standard_Transient.hxx>
32 #include <TopLoc_Location.hxx>
34 #include <TopoDS_Compound.hxx>
35 #include <TopoDS_CompSolid.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Shell.hxx>
40 #include <TopoDS_Solid.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Wire.hxx>
43 #include <Transfer_FinderProcess.hxx>
44 #include <Transfer_SimpleBinderOfTransient.hxx>
45 #include <Transfer_TransientMapper.hxx>
46 #include <TransferBRep_OrientedShapeMapper.hxx>
47 #include <TransferBRep_ShapeMapper.hxx>
49 //#include <ShapeCustom.hxx>
52 //=======================================================================
53 //function : BRepToIGES_BREntity
55 //=======================================================================
57 BRepToIGES_BREntity::BRepToIGES_BREntity()
59 myConvSurface(Interface_Static::IVal("write.convertsurface.mode") != 0),
60 myPCurveMode (Interface_Static::IVal("write.surfacecurve.mode") != 0),
61 TheMap (new Transfer_FinderProcess())
65 //=======================================================================
68 //=======================================================================
70 void BRepToIGES_BREntity::Init()
72 TheMap = new Transfer_FinderProcess();
74 myConvSurface = Interface_Static::IVal("write.convertsurface.mode") != 0;
75 myPCurveMode = Interface_Static::IVal("write.surfacecurve.mode") != 0;
78 //=======================================================================
81 //=======================================================================
82 void BRepToIGES_BREntity::SetModel(const Handle(IGESData_IGESModel)& model)
85 Standard_Real unitfactor = TheModel->GlobalSection().UnitValue();
87 TheUnitFactor = unitfactor;
91 //=======================================================================
94 //=======================================================================
95 Handle(IGESData_IGESModel) BRepToIGES_BREntity::GetModel() const
99 //=======================================================================
102 //=======================================================================
103 Standard_Real BRepToIGES_BREntity::GetUnit() const
105 return TheUnitFactor;
109 //=======================================================================
110 //function : SetTransferProcess
112 //=======================================================================
113 void BRepToIGES_BREntity::SetTransferProcess(const Handle(Transfer_FinderProcess)& TP)
117 //=======================================================================
118 //function : GetTransferProcess
120 //=======================================================================
121 Handle(Transfer_FinderProcess) BRepToIGES_BREntity::GetTransferProcess() const
125 //=======================================================================
126 //function : TransferShape
128 //=======================================================================
129 Handle(IGESData_IGESEntity) BRepToIGES_BREntity::TransferShape
130 (const TopoDS_Shape& start)
132 Handle(IGESData_IGESEntity) res;
133 // TopoDS_Shape theShape;
134 //Standard_Integer Nb = 1; //szv#4:S4163:12Mar99 not needed
136 if (start.IsNull()) return res;
138 if (start.ShapeType() == TopAbs_VERTEX) {
139 TopoDS_Vertex V = TopoDS::Vertex(start);
140 BRepToIGES_BRWire BW(*this);
141 BW.SetModel(GetModel());
142 res = BW.TransferVertex(V);
144 else if (start.ShapeType() == TopAbs_EDGE) {
145 TopoDS_Edge E = TopoDS::Edge(start);
146 BRepToIGES_BRWire BW(*this);
147 BW.SetModel(GetModel());
148 res = BW.TransferEdge(E, Standard_False);
150 else if (start.ShapeType() == TopAbs_WIRE) {
151 TopoDS_Wire W = TopoDS::Wire(start);
152 BRepToIGES_BRWire BW(*this);
153 BW.SetModel(GetModel());
154 res = BW.TransferWire(W);
157 // la fonction suivante force les surfaces indirectes en
158 // surfaces directes (obligatoire dans IGES)
159 // theShape = ShapeCustom::DirectFaces(start);
160 //sprintf(Name,"res_%d",Nb++);
161 //DBRep::Set(Name,theShape);
163 if (start.ShapeType() == TopAbs_FACE) {
164 TopoDS_Face F = TopoDS::Face(start);
165 BRepToIGES_BRShell BS(*this);
166 BS.SetModel(GetModel());
167 res = BS.TransferFace(F);
169 else if (start.ShapeType() == TopAbs_SHELL) {
170 TopoDS_Shell S = TopoDS::Shell(start);
171 BRepToIGES_BRShell BS(*this);
172 BS.SetModel(GetModel());
173 res = BS.TransferShell(S);
175 else if (start.ShapeType() == TopAbs_SOLID) {
176 TopoDS_Solid M = TopoDS::Solid(start);
177 BRepToIGES_BRSolid BS(*this);
178 BS.SetModel(GetModel());
179 res = BS.TransferSolid(M);
181 else if (start.ShapeType() == TopAbs_COMPSOLID) {
182 TopoDS_CompSolid C = TopoDS::CompSolid(start);
183 BRepToIGES_BRSolid BS(*this);
184 BS.SetModel(GetModel());
185 res = BS.TransferCompSolid(C);
187 else if (start.ShapeType() == TopAbs_COMPOUND) {
188 TopoDS_Compound C = TopoDS::Compound(start);
189 BRepToIGES_BRSolid BS(*this);
190 BS.SetModel(GetModel());
191 res = BS.TransferCompound(C);
202 //=======================================================================
205 //=======================================================================
207 void BRepToIGES_BREntity::AddFail
208 (const TopoDS_Shape& start,
209 const Standard_CString amess)
211 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
212 TheMap->AddFail(Mapper, amess);
216 //=======================================================================
217 //function : AddWarning
219 //=======================================================================
221 void BRepToIGES_BREntity::AddWarning
222 (const TopoDS_Shape& start,
223 const Standard_CString amess)
225 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
226 TheMap->AddWarning(Mapper, amess);
230 //=======================================================================
233 //=======================================================================
235 void BRepToIGES_BREntity::AddFail
236 (const Handle(Standard_Transient)& start,
237 const Standard_CString amess)
239 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
240 TheMap->AddFail(Mapper, amess);
244 //=======================================================================
245 //function : AddWarning
247 //=======================================================================
249 void BRepToIGES_BREntity::AddWarning
250 (const Handle(Standard_Transient)& start,
251 const Standard_CString amess)
253 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
254 TheMap->AddWarning(Mapper, amess);
258 //=======================================================================
259 //function : HasShapeResult
261 //=======================================================================
263 Standard_Boolean BRepToIGES_BREntity::HasShapeResult
264 (const TopoDS_Shape& start) const
266 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
267 DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
268 if (binder.IsNull()) return Standard_False;
269 return binder->HasResult();
273 //=======================================================================
274 //function : GetShapeResult
276 //=======================================================================
278 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult
279 (const TopoDS_Shape& start) const
281 Handle(Standard_Transient) res;
283 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
284 DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
285 if (binder.IsNull()) return res;
286 if (binder->HasResult())
287 res = binder->Result();
292 //=======================================================================
293 //function : SetShapeResult
295 //=======================================================================
297 void BRepToIGES_BREntity::SetShapeResult
298 ( const TopoDS_Shape& start,
299 const Handle(Standard_Transient)& result)
301 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
302 Handle(Transfer_SimpleBinderOfTransient) binder = new Transfer_SimpleBinderOfTransient;
303 binder->SetResult(result);
304 TheMap->Bind(Mapper,binder);
307 //=======================================================================
308 //function : HasShapeResult
310 //=======================================================================
312 Standard_Boolean BRepToIGES_BREntity::HasShapeResult
313 (const Handle(Standard_Transient)& start) const
315 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
316 DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
317 if (binder.IsNull()) return Standard_False;
318 return binder->HasResult();
322 //=======================================================================
323 //function : GetShapeResult
325 //=======================================================================
327 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult
328 (const Handle(Standard_Transient)& start) const
330 Handle(Standard_Transient) res;
332 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
333 DeclareAndCast(Transfer_SimpleBinderOfTransient, binder, TheMap->Find(Mapper));
334 if (binder.IsNull()) return res;
335 if (binder->HasResult())
336 res = binder->Result();
341 //=======================================================================
342 //function : SetShapeResult
344 //=======================================================================
346 void BRepToIGES_BREntity::SetShapeResult
347 ( const Handle(Standard_Transient)& start,
348 const Handle(Standard_Transient)& result)
350 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
351 Handle(Transfer_SimpleBinderOfTransient) binder = new Transfer_SimpleBinderOfTransient;
352 TheMap->Bind(Mapper,binder);
353 binder->SetResult(result);
356 //=======================================================================
357 //function : GetConvertSurfaceMode
359 //=======================================================================
361 Standard_Boolean BRepToIGES_BREntity::GetConvertSurfaceMode () const
363 return myConvSurface;
366 //=======================================================================
367 //function : GetPCurveMode
369 //=======================================================================
371 Standard_Boolean BRepToIGES_BREntity::GetPCurveMode () const
376 //=======================================================================
377 //function : ~BRepToIGES_BREntity
379 //=======================================================================
381 BRepToIGES_BREntity::~BRepToIGES_BREntity()