Warnings on vc14 were eliminated
[occt.git] / src / StepToTopoDS / StepToTopoDS_TranslateCurveBoundedSurface.cxx
1 // Created on: 1999-02-12
2 // Created by: Andrey BETENEV
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //#4  szv          S4163: optimization
18 //:   abv 07.04.99 S4136: turn off fixing intersection of non-adjacent edges
19
20 #include <BRep_Builder.hxx>
21 #include <BRepBuilderAPI_MakeFace.hxx>
22 #include <Geom_BoundedSurface.hxx>
23 #include <Precision.hxx>
24 #include <ShapeAlgo.hxx>
25 #include <ShapeAlgo_AlgoContainer.hxx>
26 #include <StepGeom_BoundaryCurve.hxx>
27 #include <StepGeom_BSplineSurface.hxx>
28 #include <StepGeom_CurveBoundedSurface.hxx>
29 #include <StepGeom_HArray1OfSurfaceBoundary.hxx>
30 #include <StepToGeom.hxx>
31 #include <StepToTopoDS_TranslateCompositeCurve.hxx>
32 #include <StepToTopoDS_TranslateCurveBoundedSurface.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Iterator.hxx>
37 #include <Transfer_TransientProcess.hxx>
38
39 //=======================================================================
40 //function : StepToTopoDS_TranslateCurveBoundedSurface
41 //purpose  : 
42 //=======================================================================
43 StepToTopoDS_TranslateCurveBoundedSurface::StepToTopoDS_TranslateCurveBoundedSurface ()
44 {
45 }
46
47 //=======================================================================
48 //function : StepToTopoDS_TranslateCurveBoundedSurface
49 //purpose  : 
50 //=======================================================================
51
52 StepToTopoDS_TranslateCurveBoundedSurface::StepToTopoDS_TranslateCurveBoundedSurface (
53                                            const Handle(StepGeom_CurveBoundedSurface) &CBS, 
54                                            const Handle(Transfer_TransientProcess) &TP)
55 {
56   Init ( CBS, TP );
57 }
58
59 Standard_Boolean StepToTopoDS_TranslateCurveBoundedSurface::Init (
60                  const Handle(StepGeom_CurveBoundedSurface) &CBS, 
61                  const Handle(Transfer_TransientProcess) &TP)
62 {
63   myFace.Nullify();
64   if ( CBS.IsNull() ) return Standard_False;
65   
66   // translate basis surface 
67   Handle(StepGeom_Surface) S = CBS->BasisSurface();
68   Handle(Geom_Surface) Surf = StepToGeom::MakeSurface (S);
69   if (Surf.IsNull())
70   {
71     TP->AddFail ( CBS, "Basis surface not translated" );
72     return Standard_False;
73   }
74
75   // abv 30.06.00: trj4_k1_geo-tu.stp #108: do as in TranslateFace
76   // pdn to force bsplsurf to be periodic
77   Handle(StepGeom_BSplineSurface) sgbss = Handle(StepGeom_BSplineSurface)::DownCast(S);
78   if (!sgbss.IsNull()) {
79 /*
80     StepGeom_BSplineSurfaceForm form = sgbss->SurfaceForm();
81     if ((form == StepGeom_bssfCylindricalSurf)||
82         (form == StepGeom_bssfConicalSurf)||
83         (form == StepGeom_bssfSphericalSurf)||
84         (form == StepGeom_bssfToroidalSurf)||
85         (form == StepGeom_bssfSurfOfRevolution)||
86         (form == StepGeom_bssfGeneralisedCone)||
87         (form == StepGeom_bssfUnspecified)) 
88 */
89     {
90       Handle(Geom_Surface) periodicSurf = ShapeAlgo::AlgoContainer()->ConvertToPeriodic (Surf);
91       if(!periodicSurf.IsNull()) {
92         TP->AddWarning(S,"Surface forced to be periodic");
93         Surf = periodicSurf;
94       }
95     }
96   }
97     
98   // create face
99   BRep_Builder B;
100   B.MakeFace ( myFace, Surf, Precision::Confusion() );
101
102   // add natural bound if implicit
103   if ( CBS->ImplicitOuter() ) { 
104     if ( Surf->IsKind(STANDARD_TYPE(Geom_BoundedSurface)) ) {
105       BRepBuilderAPI_MakeFace mf (Surf, Precision::Confusion());
106       myFace = mf.Face();
107     }
108     else TP->AddWarning ( CBS, "Cannot make natural bounds on infinite surface" );
109   }
110
111   // translate boundaries 
112   Handle(StepGeom_HArray1OfSurfaceBoundary) bnd = CBS->Boundaries();
113   Standard_Integer nb = bnd->Length();
114   for ( Standard_Integer i=1; i <= nb; i++ ) {
115     Handle(StepGeom_CompositeCurve) cc = bnd->Value ( i ).BoundaryCurve();
116     if ( cc.IsNull() ) continue;
117     StepToTopoDS_TranslateCompositeCurve TrCC ( cc, TP, S, Surf );
118     if ( ! TrCC.IsDone() ) {
119       TP->AddWarning ( CBS, "Boundary not translated" );
120       continue;
121     }
122     B.Add ( myFace, TrCC.Value() );
123   }
124
125   done = ! myFace.IsNull();
126   return done;
127 }
128         
129 //=======================================================================
130 //function : Value
131 //purpose  : 
132 //=======================================================================
133
134 const TopoDS_Face &StepToTopoDS_TranslateCurveBoundedSurface::Value () const
135 {
136   return myFace;
137 }