1 // File: StepToTopoDS_TranslateFace.cxx
2 // Created: Tue Jan 3 13:55:11 1995
3 // Author: Frederic MAUPAS
5 // pdn 30.11.98: fixes improved
6 // pdn 20.12.98: to keep pcurves
7 // pdn 28.12.98: PRO10366 shifting pcurve between two singularities
8 //:p4 abv, pdn 23.02.99: PRO9234 #15720: call BRepTools::Update() for faces
9 //:q7 abv 23.03.99: bm4_al_eye.stp #53710: remove pseudo-seams
10 // rln 31.03.99 S4135: prohibit fixing intersection of non-adjacent edges (temporarily)
11 //#4 szv S4163: optimization
12 //%19 pdn 17.04.99 using ShapeFix_Wire::FixEdgeCurves instead of ShapeFix_PCurves
13 // smh 31.01.01 Bad data in file : case of vertex loop on plane face
14 // sln 01.10.2001 BUC61003. StepToTopoDS_TranslateFace::Init function is corrected (verifying Handle(...).IsNull() is added)
15 #include <StepToTopoDS_TranslateFace.ixx>
17 #include <StepToTopoDS.hxx>
19 #include <StepToGeom_MakeSurface.hxx>
21 #include <StepToTopoDS_TranslateVertexLoop.hxx>
22 #include <StepToTopoDS_TranslatePolyLoop.hxx>
23 #include <StepToTopoDS_TranslateEdgeLoop.hxx>
25 #include <StepShape_EdgeCurve.hxx>
26 #include <StepShape_VertexLoop.hxx>
27 #include <StepShape_EdgeLoop.hxx>
28 #include <StepShape_PolyLoop.hxx>
29 #include <StepGeom_Surface.hxx>
30 #include <StepShape_FaceBound.hxx>
31 #include <StepShape_FaceOuterBound.hxx>
32 #include <StepShape_OrientedEdge.hxx>
33 #include <StepShape_Edge.hxx>
36 #include <BRep_TEdge.hxx>
37 #include <BRep_TVertex.hxx>
39 #include <Geom_BoundedSurface.hxx>
40 #include <Geom_Plane.hxx>
41 #include <Geom_Surface.hxx>
42 #include <GeomAbs_Shape.hxx>
43 #include <GeomAdaptor_Surface.hxx>
44 #include <GeomAdaptor_HSurface.hxx>
45 //#include <GeomAdaptor_Curve.hxx>
46 //#include <GeomAdaptor_CurveOnSurface.hxx>
48 #include <Geom2d_Curve.hxx>
51 #include <TopoDS_Edge.hxx>//#3 rln 16/02/98
52 #include <TopoDS_Face.hxx>
53 #include <TopoDS_Vertex.hxx>
56 #include <TopExp_Explorer.hxx>//rln 28/01/98
58 #include <TopoDS_Wire.hxx>
59 #include <BRepTools.hxx>
60 #include <BRepBuilderAPI_MakeFace.hxx>
61 #include <BRep_Builder.hxx>//rln 28/01/98
62 #include <BRep_Tool.hxx>
63 #include <Transfer_TransientProcess.hxx>
64 #include <Precision.hxx>
66 // Provisoire, pour VertexLoop
67 #include <Geom_SphericalSurface.hxx>
68 #include <Geom_ToroidalSurface.hxx>
69 #include <StepGeom_OffsetSurface.hxx> //:d4
70 #include <StepGeom_BSplineSurfaceForm.hxx>
71 #include <StepGeom_BSplineSurface.hxx>
72 #include <ShapeAlgo.hxx>
73 #include <ShapeAlgo_AlgoContainer.hxx>
74 #include <TopoDS_Iterator.hxx>
76 // To proceed with I-DEAS-like STP (ssv; 15.11.2010)
77 #include <TCollection_HAsciiString.hxx>
81 // ============================================================================
82 // Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
83 // Purpose : Empty Constructor
84 // ============================================================================
86 StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace()
88 done = Standard_False;
91 // ============================================================================
92 // Method : StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
93 // Purpose : Constructor with a FaceSurface and a Tool
94 // ============================================================================
96 StepToTopoDS_TranslateFace::StepToTopoDS_TranslateFace
97 (const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& T, StepToTopoDS_NMTool& NMTool)
102 // ============================================================================
104 // Purpose : Init with a FaceSurface and a Tool
105 // ============================================================================
107 void StepToTopoDS_TranslateFace::Init
108 (const Handle(StepShape_FaceSurface)& FS, StepToTopoDS_Tool& aTool, StepToTopoDS_NMTool& NMTool)
110 done = Standard_True;
111 if (aTool.IsBound(FS)) {
112 myResult = TopoDS::Face(aTool.Find(FS));
113 myError = StepToTopoDS_TranslateFaceDone;
114 done = Standard_True;
118 Handle(Transfer_TransientProcess) TP = aTool.TransientProcess();
120 // ----------------------------------------------
121 // Map the Face Geometry and create a TopoDS_Face
122 // ----------------------------------------------
124 Handle(StepGeom_Surface) StepSurf = FS->FaceGeometry();
126 // sln 01.10.2001 BUC61003. If corresponding entity was read with error StepSurface may be NULL. In this case we exit from function
127 if ( StepSurf.IsNull() ) {
128 TP->AddFail(StepSurf," Surface has not been created");
129 myError = StepToTopoDS_TranslateFaceOther;
130 done = Standard_False;
134 // [BEGIN] Added to process non-manifold topology (ssv; 14.11.2010)
135 if ( NMTool.IsActive() && NMTool.IsBound(StepSurf) ) {
136 TopoDS_Shape existingShape = NMTool.Find(StepSurf);
137 // Reverse shape's orientation for the next shell
138 existingShape.Reverse();
139 myResult = existingShape;
140 myError = StepToTopoDS_TranslateFaceDone;
141 done = Standard_True;
144 // [END] Added to process non-manifold topology (ssv; 14.11.2010)
146 if (StepSurf->IsKind(STANDARD_TYPE(StepGeom_OffsetSurface))) //:d4 abv 12 Mar 98
147 TP->AddWarning(StepSurf," Type OffsetSurface is out of scope of AP 214");
148 Handle(Geom_Surface) GeomSurf;
149 if (!StepToGeom_MakeSurface::Convert(StepSurf,GeomSurf))
151 TP->AddFail(StepSurf," Surface has not been created");
152 myError = StepToTopoDS_TranslateFaceOther;
153 done = Standard_False;
156 // pdn to force bsplsurf to be periodic
157 Handle(StepGeom_BSplineSurface) sgbss = Handle(StepGeom_BSplineSurface)::DownCast(StepSurf);
158 if (!sgbss.IsNull()) {
160 StepGeom_BSplineSurfaceForm form = sgbss->SurfaceForm();
161 if ((form == StepGeom_bssfCylindricalSurf)||
162 (form == StepGeom_bssfConicalSurf)||
163 (form == StepGeom_bssfSphericalSurf)||
164 (form == StepGeom_bssfToroidalSurf)||
165 (form == StepGeom_bssfSurfOfRevolution)||
166 (form == StepGeom_bssfGeneralisedCone)||
167 (form == StepGeom_bssfUnspecified))
170 Handle(Geom_Surface) periodicSurf = ShapeAlgo::AlgoContainer()->ConvertToPeriodic (GeomSurf);
171 if(!periodicSurf.IsNull()) {
172 TP->AddWarning(StepSurf,"Surface forced to be periodic");
173 GeomSurf = periodicSurf;
178 Standard_Boolean sameSense = FS->SameSense();
181 aTool.AddContinuity (GeomSurf);
185 B.MakeFace ( F, GeomSurf, Precision::Confusion() );
187 // ----------------------------------
188 // Iterate on each FaceBounds (Wires)
189 // ----------------------------------
191 Handle(StepShape_FaceBound) FaceBound;
192 Handle(StepShape_Loop) Loop;
194 StepToTopoDS_TranslateVertexLoop myTranVL;
195 StepToTopoDS_TranslatePolyLoop myTranPL;
196 StepToTopoDS_TranslateEdgeLoop myTranEdgeLoop;
198 Standard_Integer NbBnd = FS->NbBounds();
200 // -- Critere de couture simple (CKY, JAN97)
201 // surface periodique (typiquement un cylindre)
202 // 2 face bounds, chacun avec un edge loop d une seule edge
203 // cette edge est fermee, c-a-d vtx-deb = vtx-fin (pour les deux edges)
204 // est-ce suffisant (verifier que ce sont deux outer-bounds ... ?? comment ?)
205 // Alors on peut dire : face a deux bords dont la couture manque
206 // La couture est entre les deux vertex
208 // TopoDS_Wire W1,W2;
209 // Standard_Boolean fautcoudre =
210 // ( (NbBnd == 2) && (GeomSurf->IsUClosed() || GeomSurf->IsVClosed()) );
212 for (Standard_Integer i = 1; i <= NbBnd; i ++) {
215 cout << " Processing Wire : " << i << endl;
217 FaceBound = FS->BoundsValue(i);
218 Loop = FaceBound->Bound();
220 // ------------------------
221 // The Loop is a VertexLoop
222 // ------------------------
224 if (Loop->IsKind(STANDARD_TYPE(StepShape_VertexLoop))) {
225 //:S4136 STF.Closed() = Standard_False;
226 // PROBLEME si SPHERE ou TORE
227 // Il faudra faire un wire complet, a condition que le point porte sur la face
228 // En attendant, on ne fait rien
229 Handle(StepShape_VertexLoop) VL = Handle(StepShape_VertexLoop)::DownCast(Loop);
231 // abv 10.07.00 pr1sy.stp: vertex_loop can be wrong; so just make natural bounds
232 if (GeomSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface))) {
233 BRepBuilderAPI_MakeFace mf (GeomSurf);
234 for (TopoDS_Iterator it(mf); it.More(); it.Next() )
235 B.Add ( F, it.Value() );
239 if (//GeomSurf->IsKind(STANDARD_TYPE(Geom_SphericalSurface)) ||
240 GeomSurf->IsKind(STANDARD_TYPE(Geom_ToroidalSurface)) ) {
241 // TP->AddWarning(VL," VertexLoop on Cone or Torus NOT YET IMPLEMENTED");
244 if (GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)) ) {
245 TP->AddWarning(VL,"VertexLoop on plane is ignored");
246 continue; //smh : BUC60809
248 myTranVL.SetPrecision(Precision());//gka
249 myTranVL.SetMaxTol(MaxTol());
250 myTranVL.Init(VL, aTool, NMTool);
251 if (myTranVL.IsDone()) {
252 B.Add ( F, myTranVL.Value() );
255 TP->AddWarning(VL," a VertexLoop not mapped to TopoDS");
259 // ----------------------
260 // The Loop is a PolyLoop
261 // ----------------------
263 else if (Loop->IsKind(STANDARD_TYPE(StepShape_PolyLoop))) {
264 //:S4136 STF.Closed() = Standard_False;
265 Handle(StepShape_PolyLoop) PL = Handle(StepShape_PolyLoop)::DownCast(Loop);
266 F.Orientation ( FS->SameSense() ? TopAbs_FORWARD : TopAbs_REVERSED);
267 myTranPL.SetPrecision(Precision()); //gka
268 myTranPL.SetMaxTol(MaxTol());
269 myTranPL.Init(PL, aTool, GeomSurf, F);
270 if (myTranPL.IsDone()) {
271 TopoDS_Wire W = TopoDS::Wire(myTranPL.Value());
272 W.Orientation ( FaceBound->Orientation() ? TopAbs_FORWARD : TopAbs_REVERSED);
276 TP->AddWarning(PL," a PolyLoop not mapped to TopoDS");
280 // -----------------------
281 // The Loop is an EdgeLoop
282 // -----------------------
284 else if (Loop->IsKind(STANDARD_TYPE(StepShape_EdgeLoop))) {
285 //:S4136 if (STF.Closed()) {
286 //:S4136 Handle(StepShape_EdgeLoop) EL =
287 //:S4136 Handle(StepShape_EdgeLoop)::DownCast(FaceBound->Bound());
288 //:S4136 if (EL->NbEdgeList() != 1) STF.Closed() = Standard_False;
292 myTranEdgeLoop.SetPrecision(Precision()); //gka
293 myTranEdgeLoop.SetMaxTol(MaxTol());
294 myTranEdgeLoop.Init(FaceBound, F, GeomSurf, StepSurf, sameSense, aTool, NMTool);
296 if (myTranEdgeLoop.IsDone()) {
298 W = TopoDS::Wire(myTranEdgeLoop.Value());
300 // STEP Face_Surface orientation :
301 // if the topological orientation is opposite to the geometric
302 // orientation of the surface => the underlying topological
303 // orientation are not implicitly reversed
304 // this is the case in CAS.CADE => If the face_surface is reversed,
305 // the wire orientation has to be explictly reversed
306 if (FaceBound->Orientation()) {
307 // *DTH* if (sameSense || GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
308 W.Orientation (sameSense ? TopAbs_FORWARD : TopAbs_REVERSED);
311 // *DTH* if (sameSense || GeomSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
312 W.Orientation (sameSense ? TopAbs_REVERSED : TopAbs_FORWARD);
314 // -----------------------------
315 // The Wire is added to the Face
316 // -----------------------------
321 // Il y a eu un probleme dans le mapping : On perd la Face
322 // (facon de parler ...) Pas de moyen aujourd hui de recuperer
323 // au moins toutes les geometries (Points, Courbes 3D, Surface)
324 TP->AddFail(Loop," EdgeLoop not mapped to TopoDS");
325 //if(GeomSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface))) {
326 //Standard_Real su1, sv1, su2, sv2;
327 //GeomSurf->Bounds(su1, su2, sv1, sv2);
328 //if(sv1 == -Precision::Infinite()) sv1 = 0.;
329 //if(sv2 == Precision::Infinite()) sv2 = 1.;
330 //BRepBuilderAPI_MakeFace mkf(GeomSurf,su1,su2,sv1,sv2);
331 //if (mkf.IsDone()) {
332 // done shall be standard false but no recipient to
333 // to store uncompletally mapped topology
334 // see Improvment Resquest DPA/126/95
335 //myResult = mkf.Face();
336 //done = Standard_True;
340 // CKY JAN-97 : un Wire manque, eh bien on continue quand meme !!
341 // sauf si OuterBound : la c est quand meme pas bien normal ...
342 if (FaceBound->IsKind(STANDARD_TYPE(StepShape_FaceOuterBound))) {
343 TP->AddWarning(FS,"No Outer Bound : Face not done");
347 // myError = StepToTopoDS_TranslateFaceOther;
348 // done = Standard_False;
354 // Type not yet implemented or non sens
355 TP->AddFail(Loop," Type of loop not yet implemented");
357 cout << Loop->DynamicType() << endl;
360 // done = Standard_False;
361 // myError = StepToTopoDS_TranslateFaceOther;
366 F.Orientation ( FS->SameSense() ? TopAbs_FORWARD : TopAbs_REVERSED);
369 // Register face in NM tool (ssv; 14.11.2010)
370 if ( NMTool.IsActive() )
371 NMTool.Bind(StepSurf, F);
374 myError = StepToTopoDS_TranslateFaceDone;
375 done = Standard_True;
379 // ============================================================================
381 // Purpose : Return the mapped Shape
382 // ============================================================================
384 const TopoDS_Shape& StepToTopoDS_TranslateFace::Value() const
386 StdFail_NotDone_Raise_if(!done,"");
390 // ============================================================================
392 // Purpose : Return the TranslateFace error
393 // ============================================================================
395 StepToTopoDS_TranslateFaceError StepToTopoDS_TranslateFace::Error() const