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