0029814: Modeling Data - add method TopoDS_Shape::NbChildren() for simple check of...
[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 <Transfer_TransientProcess.hxx>
37
38 //=======================================================================
39 //function : StepToTopoDS_TranslateCurveBoundedSurface
40 //purpose  : 
41 //=======================================================================
42 StepToTopoDS_TranslateCurveBoundedSurface::StepToTopoDS_TranslateCurveBoundedSurface ()
43 {
44 }
45
46 //=======================================================================
47 //function : StepToTopoDS_TranslateCurveBoundedSurface
48 //purpose  : 
49 //=======================================================================
50
51 StepToTopoDS_TranslateCurveBoundedSurface::StepToTopoDS_TranslateCurveBoundedSurface (
52                                            const Handle(StepGeom_CurveBoundedSurface) &CBS, 
53                                            const Handle(Transfer_TransientProcess) &TP)
54 {
55   Init ( CBS, TP );
56 }
57
58 //=======================================================================
59 //function : Init
60 //purpose  : 
61 //=======================================================================
62
63 Standard_Boolean StepToTopoDS_TranslateCurveBoundedSurface::Init (
64                  const Handle(StepGeom_CurveBoundedSurface) &CBS, 
65                  const Handle(Transfer_TransientProcess) &TP)
66 {
67   myFace.Nullify();
68   if ( CBS.IsNull() ) return Standard_False;
69   
70   // translate basis surface 
71   Handle(StepGeom_Surface) S = CBS->BasisSurface();
72   Handle(Geom_Surface) Surf = StepToGeom::MakeSurface (S);
73   if (Surf.IsNull())
74   {
75     TP->AddFail ( CBS, "Basis surface not translated" );
76     return Standard_False;
77   }
78
79   // abv 30.06.00: trj4_k1_geo-tu.stp #108: do as in TranslateFace
80   // pdn to force bsplsurf to be periodic
81   Handle(StepGeom_BSplineSurface) sgbss = Handle(StepGeom_BSplineSurface)::DownCast(S);
82   if (!sgbss.IsNull()) {
83     Handle(Geom_Surface) periodicSurf = ShapeAlgo::AlgoContainer()->ConvertToPeriodic(Surf);
84     if (!periodicSurf.IsNull()) {
85       TP->AddWarning(S, "Surface forced to be periodic");
86       Surf = periodicSurf;
87     }
88   }
89     
90   // create face
91   BRep_Builder B;
92   B.MakeFace ( myFace, Surf, Precision::Confusion() );
93
94   // add natural bound if implicit
95   if ( CBS->ImplicitOuter() ) { 
96     if ( Surf->IsKind(STANDARD_TYPE(Geom_BoundedSurface)) ) {
97       BRepBuilderAPI_MakeFace mf (Surf, Precision::Confusion());
98       myFace = mf.Face();
99     }
100     else TP->AddWarning ( CBS, "Cannot make natural bounds on infinite surface" );
101   }
102
103   // translate boundaries 
104   Handle(StepGeom_HArray1OfSurfaceBoundary) bnd = CBS->Boundaries();
105   Standard_Integer nb = bnd->Length();
106   for ( Standard_Integer i=1; i <= nb; i++ ) {
107     Handle(StepGeom_CompositeCurve) cc = bnd->Value ( i ).BoundaryCurve();
108     if ( cc.IsNull() ) continue;
109     StepToTopoDS_TranslateCompositeCurve TrCC ( cc, TP, S, Surf );
110     if ( ! TrCC.IsDone() ) {
111       TP->AddWarning ( CBS, "Boundary not translated" );
112       continue;
113     }
114     B.Add ( myFace, TrCC.Value() );
115   }
116
117   done = ! myFace.IsNull();
118   return done;
119 }
120         
121 //=======================================================================
122 //function : Value
123 //purpose  : 
124 //=======================================================================
125
126 const TopoDS_Face &StepToTopoDS_TranslateCurveBoundedSurface::Value () const
127 {
128   return myFace;
129 }