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
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.
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.
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.
22 //eap: Tue Aug 29 11:02:56 2000: Shape Processing moved to upper levels
24 #include <BRepToIGES_BREntity.ixx>
26 #include <BRepToIGES_BRWire.hxx>
27 #include <BRepToIGES_BRShell.hxx>
28 #include <BRepToIGES_BRSolid.hxx>
30 #include <BRep_Builder.hxx>
32 #include <gp_Trsf.hxx>
34 #include <Geom_Geometry.hxx>
36 #include <IGESData_IGESEntity.hxx>
38 #include <Interface_Macros.hxx>
39 #include <Interface_Static.hxx>
41 //#include <ShapeCustom.hxx>
43 #include <TopLoc_Location.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>
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>
64 //=======================================================================
65 //function : BRepToIGES_BREntity
67 //=======================================================================
69 BRepToIGES_BREntity::BRepToIGES_BREntity()
74 //=======================================================================
77 //=======================================================================
79 void BRepToIGES_BREntity::Init()
81 TheMap = new Transfer_FinderProcess();
83 myConvSurface = Interface_Static::IVal("write.convertsurface.mode");
84 myPCurveMode = Interface_Static::IVal("write.surfacecurve.mode");
87 //=======================================================================
90 //=======================================================================
91 void BRepToIGES_BREntity::SetModel(const Handle(IGESData_IGESModel)& model)
94 Standard_Real unitfactor = TheModel->GlobalSection().UnitValue();
96 TheUnitFactor = unitfactor;
100 //=======================================================================
101 //function : GetModel
103 //=======================================================================
104 Handle(IGESData_IGESModel) BRepToIGES_BREntity::GetModel() const
108 //=======================================================================
111 //=======================================================================
112 Standard_Real BRepToIGES_BREntity::GetUnit() const
114 return TheUnitFactor;
118 //=======================================================================
119 //function : SetTransferProcess
121 //=======================================================================
122 void BRepToIGES_BREntity::SetTransferProcess(const Handle(Transfer_FinderProcess)& TP)
126 //=======================================================================
127 //function : GetTransferProcess
129 //=======================================================================
130 Handle(Transfer_FinderProcess) BRepToIGES_BREntity::GetTransferProcess() const
134 //=======================================================================
135 //function : TransferShape
137 //=======================================================================
138 Handle(IGESData_IGESEntity) BRepToIGES_BREntity::TransferShape
139 (const TopoDS_Shape& start)
141 Handle(IGESData_IGESEntity) res;
142 // TopoDS_Shape theShape;
143 //Standard_Integer Nb = 1; //szv#4:S4163:12Mar99 not needed
145 if (start.IsNull()) return res;
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);
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);
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);
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);
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);
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);
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);
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);
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);
211 //=======================================================================
214 //=======================================================================
216 void BRepToIGES_BREntity::AddFail
217 (const TopoDS_Shape& start,
218 const Standard_CString amess)
220 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
221 TheMap->AddFail(Mapper, amess);
225 //=======================================================================
226 //function : AddWarning
228 //=======================================================================
230 void BRepToIGES_BREntity::AddWarning
231 (const TopoDS_Shape& start,
232 const Standard_CString amess)
234 Handle(TransferBRep_ShapeMapper) Mapper = new TransferBRep_ShapeMapper(start);
235 TheMap->AddWarning(Mapper, amess);
239 //=======================================================================
242 //=======================================================================
244 void BRepToIGES_BREntity::AddFail
245 (const Handle(Standard_Transient)& start,
246 const Standard_CString amess)
248 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
249 TheMap->AddFail(Mapper, amess);
253 //=======================================================================
254 //function : AddWarning
256 //=======================================================================
258 void BRepToIGES_BREntity::AddWarning
259 (const Handle(Standard_Transient)& start,
260 const Standard_CString amess)
262 Handle(Transfer_TransientMapper) Mapper = new Transfer_TransientMapper(start);
263 TheMap->AddWarning(Mapper, amess);
267 //=======================================================================
268 //function : HasShapeResult
270 //=======================================================================
272 Standard_Boolean BRepToIGES_BREntity::HasShapeResult
273 (const TopoDS_Shape& start) const
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();
282 //=======================================================================
283 //function : GetShapeResult
285 //=======================================================================
287 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult
288 (const TopoDS_Shape& start) const
290 Handle(Standard_Transient) res;
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();
301 //=======================================================================
302 //function : SetShapeResult
304 //=======================================================================
306 void BRepToIGES_BREntity::SetShapeResult
307 ( const TopoDS_Shape& start,
308 const Handle(Standard_Transient)& result)
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);
316 //=======================================================================
317 //function : HasShapeResult
319 //=======================================================================
321 Standard_Boolean BRepToIGES_BREntity::HasShapeResult
322 (const Handle(Standard_Transient)& start) const
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();
331 //=======================================================================
332 //function : GetShapeResult
334 //=======================================================================
336 Handle(Standard_Transient) BRepToIGES_BREntity::GetShapeResult
337 (const Handle(Standard_Transient)& start) const
339 Handle(Standard_Transient) res;
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();
350 //=======================================================================
351 //function : SetShapeResult
353 //=======================================================================
355 void BRepToIGES_BREntity::SetShapeResult
356 ( const Handle(Standard_Transient)& start,
357 const Handle(Standard_Transient)& result)
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);
365 //=======================================================================
366 //function : GetConvertSurfaceMode
368 //=======================================================================
370 Standard_Boolean BRepToIGES_BREntity::GetConvertSurfaceMode () const
372 return myConvSurface;
375 //=======================================================================
376 //function : GetPCurveMode
378 //=======================================================================
380 Standard_Boolean BRepToIGES_BREntity::GetPCurveMode () const
385 //=======================================================================
388 //=======================================================================
390 void BRepToIGES_BREntity::Delete()