1 // Created on: 1995-01-03
2 // Created by: Frederic MAUPAS
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.
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>
29 #include <StepToTopoDS.hxx>
31 #include <StepToGeom_MakeSurface.hxx>
33 #include <StepToTopoDS_TranslateVertexLoop.hxx>
34 #include <StepToTopoDS_TranslatePolyLoop.hxx>
35 #include <StepToTopoDS_TranslateEdgeLoop.hxx>
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>
48 #include <BRep_TEdge.hxx>
49 #include <BRep_TVertex.hxx>
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>
60 #include <Geom2d_Curve.hxx>
63 #include <TopoDS_Edge.hxx>//#3 rln 16/02/98
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Vertex.hxx>
68 #include <TopExp_Explorer.hxx>//rln 28/01/98
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>
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>
88 // To proceed with I-DEAS-like STP (ssv; 15.11.2010)
89 #include <TCollection_HAsciiString.hxx>
93 // ============================================================================
94 // Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
95 // Purpose : Empty Constructor
96 // ============================================================================
98 StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace()
100 done = Standard_False;
103 // ============================================================================
104 // Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
105 // Purpose : Constructor with a FaceSurface and a Tool
106 // ============================================================================
108 StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
109 (const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& T, StepToTopoDS_NMTool& NMTool)
114 // ============================================================================
116 // Purpose : Init with a FaceSurface and a Tool
117 // ============================================================================
119 void StepToTopoDS_TranslateFace::Init
120 (const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& aTool, StepToTopoDS_NMTool& NMTool)
122 done = Standard_True;
123 if (aTool.IsBound(FS)) {
124 myResult = TopoDS::Face(aTool.Find(FS));
125 myError = StepToTopoDS_TranslateFaceDone;
126 done = Standard_True;
130 Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
132 // ----------------------------------------------
133 // Map the Face Geometry and create a TopoDS_Face
134 // ----------------------------------------------
136 Handle(StepGeom_Surface) StepSurf = FS->FaceGeometry();
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;
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;
156 // [END] Added to process non-manifold topology (ssv; 14.11.2010)
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))
163 TP->AddFail(StepSurf," Surface has not been created");
164 myError = StepToTopoDS_TranslateFaceOther;
165 done = Standard_False;
168 // pdn to force bsplsurf to be periodic
169 Handle(StepGeom_BSplineSurface) sgbss = Handle(StepGeom_BSplineSurface)::DownCast(StepSurf);
170 if (!sgbss.IsNull()) {
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))
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;
190 Standard_Boolean sameSense = FS->SameSense();
193 aTool.AddContinuity (GeomSurf);
197 B.MakeFace ( F, GeomSurf, Precision::Confusion() );
199 // ----------------------------------
200 // Iterate on each FaceBounds (Wires)
201 // ----------------------------------
203 Handle(StepShape_FaceBound) FaceBound;
204 Handle(StepShape_Loop) Loop;
206 StepToTopoDS_TranslateVertexLoop myTranVL;
207 StepToTopoDS_TranslatePolyLoop myTranPL;
208 StepToTopoDS_TranslateEdgeLoop myTranEdgeLoop;
210 Standard_Integer NbBnd = FS->NbBounds();
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
220 // TopoDS_Wire W1,W2;
221 // Standard_Boolean fautcoudre =
222 // ( (NbBnd == 2) && (GeomSurf->IsUClosed() || GeomSurf->IsVClosed()) );
224 for (Standard_Integer i = 1; i <= NbBnd; i ++) {
227 cout << " Processing Wire : " << i << endl;
229 FaceBound = FS->BoundsValue(i);
230 Loop = FaceBound->Bound();
232 // ------------------------
233 // The Loop is a VertexLoop
234 // ------------------------
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);
243 // abv 10.07.00 pr1sy.stp: vertex_loop can be wrong; so just make natural bounds
244 if (GeomSurf->IsKind (STANDARD_TYPE(Geom_SphericalSurface)) ||
245 GeomSurf->IsKind (STANDARD_TYPE(Geom_BSplineSurface)) )
247 BRepBuilderAPI_MakeFace mf (GeomSurf, Precision());
248 for (TopoDS_Iterator it(mf); it.More(); it.Next())
249 B.Add (F, it.Value());
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");
259 if (GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)) ) {
260 TP->AddWarning(VL,"VertexLoop on plane is ignored");
261 continue; //smh : BUC60809
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() );
270 TP->AddWarning(VL," a VertexLoop not mapped to TopoDS");
274 // ----------------------
275 // The Loop is a PolyLoop
276 // ----------------------
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);
291 TP->AddWarning(PL," a PolyLoop not mapped to TopoDS");
295 // -----------------------
296 // The Loop is an EdgeLoop
297 // -----------------------
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;
307 myTranEdgeLoop.SetPrecision(Precision()); //gka
308 myTranEdgeLoop.SetMaxTol(MaxTol());
309 myTranEdgeLoop.Init(FaceBound, F, GeomSurf, StepSurf, sameSense, aTool, NMTool);
311 if (myTranEdgeLoop.IsDone()) {
313 W = TopoDS::Wire(myTranEdgeLoop.Value());
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);
326 // *DTH* if (sameSense || GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
327 W.Orientation (sameSense ? TopAbs_REVERSED : TopAbs_FORWARD);
329 // -----------------------------
330 // The Wire is added to the Face
331 // -----------------------------
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;
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");
362 // myError = StepToTopoDS_TranslateFaceOther;
363 // done = Standard_False;
369 // Type not yet implemented or non sens
370 TP->AddFail(Loop," Type of loop not yet implemented");
372 cout << Loop->DynamicType() << endl;
375 // done = Standard_False;
376 // myError = StepToTopoDS_TranslateFaceOther;
381 F.Orientation ( FS->SameSense() ? TopAbs_FORWARD : TopAbs_REVERSED);
384 // Register face in NM tool (ssv; 14.11.2010)
385 if ( NMTool.IsActive() )
386 NMTool.Bind(StepSurf, F);
389 myError = StepToTopoDS_TranslateFaceDone;
390 done = Standard_True;
394 // ============================================================================
396 // Purpose : Return the mapped Shape
397 // ============================================================================
399 const TopoDS_Shape& StepToTopoDS_TranslateFace::Value() const
401 StdFail_NotDone_Raise_if(!done,"");
405 // ============================================================================
407 // Purpose : Return the TranslateFace error
408 // ============================================================================
410 StepToTopoDS_TranslateFaceError StepToTopoDS_TranslateFace::Error() const