0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / StepToTopoDS / StepToTopoDS_TranslateFace.cxx
CommitLineData
b311480e 1// Created on: 1995-01-03
2// Created by: Frederic MAUPAS
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// pdn 30.11.98: fixes improved
18// pdn 20.12.98: to keep pcurves
19// pdn 28.12.98: PRO10366 shifting pcurve between two singularities
20//:p4 abv, pdn 23.02.99: PRO9234 #15720: call BRepTools::Update() for faces
21//:q7 abv 23.03.99: bm4_al_eye.stp #53710: remove pseudo-seams
22// rln 31.03.99 S4135: prohibit fixing intersection of non-adjacent edges (temporarily)
23//#4 szv S4163: optimization
24//%19 pdn 17.04.99 using ShapeFix_Wire::FixEdgeCurves instead of ShapeFix_PCurves
25// smh 31.01.01 Bad data in file : case of vertex loop on plane face
26// sln 01.10.2001 BUC61003. StepToTopoDS_TranslateFace::Init function is corrected (verifying Handle(...).IsNull() is added)
27#include <StepToTopoDS_TranslateFace.ixx>
28
29#include <StepToTopoDS.hxx>
30
31#include <StepToGeom_MakeSurface.hxx>
32
33#include <StepToTopoDS_TranslateVertexLoop.hxx>
34#include <StepToTopoDS_TranslatePolyLoop.hxx>
35#include <StepToTopoDS_TranslateEdgeLoop.hxx>
36
37#include <StepShape_EdgeCurve.hxx>
38#include <StepShape_VertexLoop.hxx>
39#include <StepShape_EdgeLoop.hxx>
40#include <StepShape_PolyLoop.hxx>
41#include <StepGeom_Surface.hxx>
42#include <StepShape_FaceBound.hxx>
43#include <StepShape_FaceOuterBound.hxx>
44#include <StepShape_OrientedEdge.hxx>
45#include <StepShape_Edge.hxx>
46
47//#3 rln 16/02/98
48#include <BRep_TEdge.hxx>
49#include <BRep_TVertex.hxx>
50
51#include <Geom_BoundedSurface.hxx>
52#include <Geom_Plane.hxx>
53#include <Geom_Surface.hxx>
54#include <GeomAbs_Shape.hxx>
55#include <GeomAdaptor_Surface.hxx>
56#include <GeomAdaptor_HSurface.hxx>
57//#include <GeomAdaptor_Curve.hxx>
58//#include <GeomAdaptor_CurveOnSurface.hxx>
59
60#include <Geom2d_Curve.hxx>
61
62#include <TopoDS.hxx>
63#include <TopoDS_Edge.hxx>//#3 rln 16/02/98
64#include <TopoDS_Face.hxx>
65#include <TopoDS_Vertex.hxx>
66
67#include <TopExp.hxx>
68#include <TopExp_Explorer.hxx>//rln 28/01/98
69
70#include <TopoDS_Wire.hxx>
71#include <BRepTools.hxx>
72#include <BRepBuilderAPI_MakeFace.hxx>
73#include <BRep_Builder.hxx>//rln 28/01/98
74#include <BRep_Tool.hxx>
75#include <Transfer_TransientProcess.hxx>
76#include <Precision.hxx>
77
78// Provisoire, pour VertexLoop
79#include <Geom_SphericalSurface.hxx>
80#include <Geom_ToroidalSurface.hxx>
81#include <StepGeom_OffsetSurface.hxx> //:d4
82#include <StepGeom_BSplineSurfaceForm.hxx>
83#include <StepGeom_BSplineSurface.hxx>
84#include <ShapeAlgo.hxx>
85#include <ShapeAlgo_AlgoContainer.hxx>
86#include <TopoDS_Iterator.hxx>
87
88// To proceed with I-DEAS-like STP (ssv; 15.11.2010)
89#include <TCollection_HAsciiString.hxx>
90
91//#define DEBUG
92
93// ============================================================================
94// Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
95// Purpose : Empty Constructor
96// ============================================================================
97
98StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace()
99{
100 done = Standard_False;
101}
102
103// ============================================================================
104// Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
105// Purpose : Constructor with a FaceSurface and a Tool
106// ============================================================================
107
108StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
109(const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& T, StepToTopoDS_NMTool& NMTool)
110{
111 Init(FS, T, NMTool);
112}
113
114// ============================================================================
115// Method : Init
116// Purpose : Init with a FaceSurface and a Tool
117// ============================================================================
118
119void StepToTopoDS_TranslateFace::Init
120(const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& aTool, StepToTopoDS_NMTool& NMTool)
121{
122 done = Standard_True;
123 if (aTool.IsBound(FS)) {
124 myResult = TopoDS::Face(aTool.Find(FS));
125 myError = StepToTopoDS_TranslateFaceDone;
126 done = Standard_True;
127 return;
128 }
129
130 Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
131
132 // ----------------------------------------------
133 // Map the Face Geometry and create a TopoDS_Face
134 // ----------------------------------------------
135
136 Handle(StepGeom_Surface) StepSurf = FS->FaceGeometry();
137
138 // sln 01.10.2001 BUC61003. If corresponding entity was read with error StepSurface may be NULL. In this case we exit from function
139 if ( StepSurf.IsNull() ) {
140 TP->AddFail(StepSurf," Surface has not been created");
141 myError = StepToTopoDS_TranslateFaceOther;
142 done = Standard_False;
143 return;
144 }
145
146 // [BEGIN] Added to process non-manifold topology (ssv; 14.11.2010)
147 if ( NMTool.IsActive() && NMTool.IsBound(StepSurf) ) {
148 TopoDS_Shape existingShape = NMTool.Find(StepSurf);
149 // Reverse shape's orientation for the next shell
150 existingShape.Reverse();
151 myResult = existingShape;
152 myError = StepToTopoDS_TranslateFaceDone;
153 done = Standard_True;
154 return;
155 }
156 // [END] Added to process non-manifold topology (ssv; 14.11.2010)
157
158 if (StepSurf->IsKind(STANDARD_TYPE(StepGeom_OffsetSurface))) //:d4 abv 12 Mar 98
159 TP->AddWarning(StepSurf," Type OffsetSurface is out of scope of AP 214");
160 Handle(Geom_Surface) GeomSurf;
161 if (!StepToGeom_MakeSurface::Convert(StepSurf,GeomSurf))
162 {
163 TP->AddFail(StepSurf," Surface has not been created");
164 myError = StepToTopoDS_TranslateFaceOther;
165 done = Standard_False;
166 return;
167 }
168 // pdn to force bsplsurf to be periodic
169 Handle(StepGeom_BSplineSurface) sgbss = Handle(StepGeom_BSplineSurface)::DownCast(StepSurf);
170 if (!sgbss.IsNull()) {
171/*
172 StepGeom_BSplineSurfaceForm form = sgbss->SurfaceForm();
173 if ((form == StepGeom_bssfCylindricalSurf)||
174 (form == StepGeom_bssfConicalSurf)||
175 (form == StepGeom_bssfSphericalSurf)||
176 (form == StepGeom_bssfToroidalSurf)||
177 (form == StepGeom_bssfSurfOfRevolution)||
178 (form == StepGeom_bssfGeneralisedCone)||
179 (form == StepGeom_bssfUnspecified))
180*/
181 {
182 Handle(Geom_Surface) periodicSurf = ShapeAlgo::AlgoContainer()->ConvertToPeriodic (GeomSurf);
183 if(!periodicSurf.IsNull()) {
184 TP->AddWarning(StepSurf,"Surface forced to be periodic");
185 GeomSurf = periodicSurf;
186 }
187 }
188 }
189
190 Standard_Boolean sameSense = FS->SameSense();
191
192 // -- Statistics --
193 aTool.AddContinuity (GeomSurf);
194
195 TopoDS_Face F;
196 BRep_Builder B;
197 B.MakeFace ( F, GeomSurf, Precision::Confusion() );
198
199 // ----------------------------------
200 // Iterate on each FaceBounds (Wires)
201 // ----------------------------------
202
203 Handle(StepShape_FaceBound) FaceBound;
204 Handle(StepShape_Loop) Loop;
205
206 StepToTopoDS_TranslateVertexLoop myTranVL;
207 StepToTopoDS_TranslatePolyLoop myTranPL;
208 StepToTopoDS_TranslateEdgeLoop myTranEdgeLoop;
209
210 Standard_Integer NbBnd = FS->NbBounds();
211
212 // -- Critere de couture simple (CKY, JAN97)
213 // surface periodique (typiquement un cylindre)
214 // 2 face bounds, chacun avec un edge loop d une seule edge
215 // cette edge est fermee, c-a-d vtx-deb = vtx-fin (pour les deux edges)
216 // est-ce suffisant (verifier que ce sont deux outer-bounds ... ?? comment ?)
217 // Alors on peut dire : face a deux bords dont la couture manque
218 // La couture est entre les deux vertex
219
220// TopoDS_Wire W1,W2;
221// Standard_Boolean fautcoudre =
222// ( (NbBnd == 2) && (GeomSurf->IsUClosed() || GeomSurf->IsVClosed()) );
223
224 for (Standard_Integer i = 1; i <= NbBnd; i ++) {
225
63c629aa 226#ifdef STEPTOTOPODS_DEB
7fd59977 227 cout << " Processing Wire : " << i << endl;
228#endif
229 FaceBound = FS->BoundsValue(i);
230 Loop = FaceBound->Bound();
231
232 // ------------------------
233 // The Loop is a VertexLoop
234 // ------------------------
235
236 if (Loop->IsKind(STANDARD_TYPE(StepShape_VertexLoop))) {
237//:S4136 STF.Closed() = Standard_False;
238// PROBLEME si SPHERE ou TORE
239// Il faudra faire un wire complet, a condition que le point porte sur la face
240// En attendant, on ne fait rien
241 Handle(StepShape_VertexLoop) VL = Handle(StepShape_VertexLoop)::DownCast(Loop);
242
243 // abv 10.07.00 pr1sy.stp: vertex_loop can be wrong; so just make natural bounds
1c72dff6
S
244 if (GeomSurf->IsKind (STANDARD_TYPE(Geom_SphericalSurface)) ||
245 GeomSurf->IsKind (STANDARD_TYPE(Geom_BSplineSurface)) )
246 {
247 BRepBuilderAPI_MakeFace mf (GeomSurf, Precision());
248 for (TopoDS_Iterator it(mf); it.More(); it.Next())
249 B.Add (F, it.Value());
250
251 continue;
7fd59977 252 }
253
254 if (//GeomSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
255 GeomSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
256// TP->AddWarning(VL," VertexLoop on Cone or Torus NOT YET IMPLEMENTED");
257 continue;
258 }
259 if (GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)) ) {
260 TP->AddWarning(VL,"VertexLoop on plane is ignored");
261 continue; //smh : BUC60809
262 }
263 myTranVL.SetPrecision(Precision());//gka
264 myTranVL.SetMaxTol(MaxTol());
265 myTranVL.Init(VL, aTool, NMTool);
266 if (myTranVL.IsDone()) {
267 B.Add ( F, myTranVL.Value() );
268 }
269 else {
270 TP->AddWarning(VL," a VertexLoop not mapped to TopoDS");
271 }
272 }
273
274 // ----------------------
275 // The Loop is a PolyLoop
276 // ----------------------
277
278 else if (Loop->IsKind(STANDARD_TYPE(StepShape_PolyLoop))) {
279//:S4136 STF.Closed() = Standard_False;
280 Handle(StepShape_PolyLoop) PL = Handle(StepShape_PolyLoop)::DownCast(Loop);
281 F.Orientation ( FS->SameSense() ? TopAbs_FORWARD : TopAbs_REVERSED);
282 myTranPL.SetPrecision(Precision()); //gka
283 myTranPL.SetMaxTol(MaxTol());
284 myTranPL.Init(PL, aTool, GeomSurf, F);
285 if (myTranPL.IsDone()) {
286 TopoDS_Wire W = TopoDS::Wire(myTranPL.Value());
287 W.Orientation ( FaceBound->Orientation() ? TopAbs_FORWARD : TopAbs_REVERSED);
288 B.Add ( F, W );
289 }
290 else {
291 TP->AddWarning(PL," a PolyLoop not mapped to TopoDS");
292 }
293 }
294
295 // -----------------------
296 // The Loop is an EdgeLoop
297 // -----------------------
298
299 else if (Loop->IsKind(STANDARD_TYPE(StepShape_EdgeLoop))) {
300//:S4136 if (STF.Closed()) {
301//:S4136 Handle(StepShape_EdgeLoop) EL =
302//:S4136 Handle(StepShape_EdgeLoop)::DownCast(FaceBound->Bound());
303//:S4136 if (EL->NbEdgeList() != 1) STF.Closed() = Standard_False;
304//:S4136 }
305
306 TopoDS_Wire W;
307 myTranEdgeLoop.SetPrecision(Precision()); //gka
308 myTranEdgeLoop.SetMaxTol(MaxTol());
309 myTranEdgeLoop.Init(FaceBound, F, GeomSurf, StepSurf, sameSense, aTool, NMTool);
310
311 if (myTranEdgeLoop.IsDone()) {
312
313 W = TopoDS::Wire(myTranEdgeLoop.Value());
314
315 // STEP Face_Surface orientation :
316 // if the topological orientation is opposite to the geometric
317 // orientation of the surface => the underlying topological
318 // orientation are not implicitly reversed
319 // this is the case in CAS.CADE => If the face_surface is reversed,
320 // the wire orientation has to be explictly reversed
321 if (FaceBound->Orientation()) {
322// *DTH* if (sameSense || GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
323 W.Orientation (sameSense ? TopAbs_FORWARD : TopAbs_REVERSED);
324 }
325 else {
326// *DTH* if (sameSense || GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
327 W.Orientation (sameSense ? TopAbs_REVERSED : TopAbs_FORWARD);
328 }
329 // -----------------------------
330 // The Wire is added to the Face
331 // -----------------------------
332
333 B.Add ( F, W );
334 }
335 else {
336 // Il y a eu un probleme dans le mapping : On perd la Face
337 // (facon de parler ...) Pas de moyen aujourd hui de recuperer
338 // au moins toutes les geometries (Points, Courbes 3D, Surface)
339 TP->AddFail(Loop," EdgeLoop not mapped to TopoDS");
340 //if(GeomSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) {
341 //Standard_Real su1, sv1, su2, sv2;
342 //GeomSurf->Bounds(su1, su2, sv1, sv2);
343 //if(sv1 == -Precision::Infinite()) sv1 = 0.;
344 //if(sv2 == Precision::Infinite()) sv2 = 1.;
345 //BRepBuilderAPI_MakeFace mkf(GeomSurf,su1,su2,sv1,sv2);
346 //if (mkf.IsDone()) {
347 // done shall be standard false but no recipient to
348 // to store uncompletally mapped topology
349 // see Improvment Resquest DPA/126/95
350 //myResult = mkf.Face();
351 //done = Standard_True;
352 //}
353 //}
354
355 // CKY JAN-97 : un Wire manque, eh bien on continue quand meme !!
356 // sauf si OuterBound : la c est quand meme pas bien normal ...
357 if (FaceBound->IsKind(STANDARD_TYPE(StepShape_FaceOuterBound))) {
358 TP->AddWarning(FS,"No Outer Bound : Face not done");
359// return;
360 }
361 continue;
362// myError = StepToTopoDS_TranslateFaceOther;
363// done = Standard_False;
364// return;
365 }
366 }
367
368 else {
369 // Type not yet implemented or non sens
370 TP->AddFail(Loop," Type of loop not yet implemented");
63c629aa 371#ifdef STEPTOTOPODS_DEB
7fd59977 372 cout << Loop->DynamicType() << endl;
373#endif
374 continue;
375// done = Standard_False;
376// myError = StepToTopoDS_TranslateFaceOther;
377// return;
378 }
379 }
380
381 F.Orientation ( FS->SameSense() ? TopAbs_FORWARD : TopAbs_REVERSED);
382 aTool.Bind(FS,F);
383
384 // Register face in NM tool (ssv; 14.11.2010)
385 if ( NMTool.IsActive() )
386 NMTool.Bind(StepSurf, F);
387
388 myResult = F;
389 myError = StepToTopoDS_TranslateFaceDone;
390 done = Standard_True;
391}
392
393
394// ============================================================================
395// Method : Value
396// Purpose : Return the mapped Shape
397// ============================================================================
398
399const TopoDS_Shape& StepToTopoDS_TranslateFace::Value() const
400{
401 StdFail_NotDone_Raise_if(!done,"");
402 return myResult;
403}
404
405// ============================================================================
406// Method : Error
407// Purpose : Return the TranslateFace error
408// ============================================================================
409
410StepToTopoDS_TranslateFaceError StepToTopoDS_TranslateFace::Error() const
411{
412 return myError;
413}