0025418: Debug output to be limited to OCC development environment
[occt.git] / src / StepToGeom / StepToGeom_MakeSurface.cxx
1 // Created on: 1993-07-05
2 // Created by: Martine LANGLOIS
3 // Copyright (c) 1993-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 //:n7 abv 15.02.99: S4132: adding translation of surface_replica
18 //:p0 abv 19.02.99: management of 'done' flag improved
19 //:s5 abv 22.04.99  Adding debug printouts in catch {} blocks
20 //sln 03.10.01. BUC61003. creation of  offset surface is corrected
21
22 #include <StepToGeom_MakeSurface.ixx>
23 #include <Standard_ErrorHandler.hxx>
24 #include <Standard_Failure.hxx>
25 #include <StepGeom_Surface.hxx>
26 #include <StepToGeom_MakeSurface.hxx>
27 #include <StepGeom_BoundedSurface.hxx>
28 #include <StepToGeom_MakeBoundedSurface.hxx>
29 #include <StepGeom_ElementarySurface.hxx>
30 #include <StepToGeom_MakeElementarySurface.hxx>
31 #include <StepGeom_SweptSurface.hxx>
32 #include <StepToGeom_MakeSweptSurface.hxx>
33
34 //:d4
35 #include <StepGeom_OffsetSurface.hxx>
36 #include <Geom_OffsetSurface.hxx>
37 #include <StepGeom_SurfaceReplica.hxx>
38 #include <StepGeom_CartesianTransformationOperator3d.hxx>
39 #include <StepToGeom_MakeTransformation3d.hxx>
40 #include <UnitsMethods.hxx>
41
42 #include <BRepBuilderAPI_MakeFace.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <ShapeAlgo.hxx>
45 #include <ShapeAlgo_AlgoContainer.hxx>
46 #include <TopoDS.hxx>
47 #include <BRep_Tool.hxx>  
48 #include <gp_Trsf.hxx>
49 #include <Precision.hxx>
50
51 //=============================================================================
52 // Creation d' une Surface de Geom a partir d' une Surface de Step
53 //=============================================================================
54
55 Standard_Boolean StepToGeom_MakeSurface::Convert (const Handle(StepGeom_Surface)& SS, Handle(Geom_Surface)& CS)
56 {
57    // sln 01.10.2001 BUC61003. If entry shell is NULL do nothing
58   if(SS.IsNull()) {
59     return Standard_False;
60   }
61
62   try {
63     OCC_CATCH_SIGNALS
64     if (SS->IsKind(STANDARD_TYPE(StepGeom_BoundedSurface))) {
65       const Handle(StepGeom_BoundedSurface) S1 = Handle(StepGeom_BoundedSurface)::DownCast(SS);
66       return StepToGeom_MakeBoundedSurface::Convert(S1,*((Handle(Geom_BoundedSurface)*)&CS));
67     }
68     if (SS->IsKind(STANDARD_TYPE(StepGeom_ElementarySurface))) {
69       const Handle(StepGeom_ElementarySurface) S1 = Handle(StepGeom_ElementarySurface)::DownCast(SS);
70       if(S1->Position().IsNull())
71         return Standard_False;
72
73       return StepToGeom_MakeElementarySurface::Convert(S1,*((Handle(Geom_ElementarySurface)*)&CS));
74     }
75     if (SS->IsKind(STANDARD_TYPE(StepGeom_SweptSurface))) {
76       const Handle(StepGeom_SweptSurface) S1 = Handle(StepGeom_SweptSurface)::DownCast(SS);
77       return StepToGeom_MakeSweptSurface::Convert(S1,*((Handle(Geom_SweptSurface)*)&CS));
78     }
79     if (SS->IsKind(STANDARD_TYPE(StepGeom_OffsetSurface))) { //:d4 abv 12 Mar 98
80       const Handle(StepGeom_OffsetSurface) OS = Handle(StepGeom_OffsetSurface)::DownCast(SS);
81       Handle(Geom_Surface) aBasisSurface;
82       if (StepToGeom_MakeSurface::Convert(OS->BasisSurface(),aBasisSurface))
83       {
84         // sln 03.10.01. BUC61003. creation of  offset surface is corrected
85         const Standard_Real anOffset = OS->Distance() * UnitsMethods::LengthFactor();
86         if (aBasisSurface->Continuity() == GeomAbs_C0)
87         {
88           const BRepBuilderAPI_MakeFace aBFace(aBasisSurface, Precision::Confusion());
89           if (aBFace.IsDone())
90           {
91             const TopoDS_Shape aResult = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape(aBFace.Face(), Abs(anOffset));
92             if (aResult.ShapeType() == TopAbs_FACE) 
93             {
94               aBasisSurface = BRep_Tool::Surface(TopoDS::Face(aResult));
95             }
96           }
97         }
98         if(aBasisSurface->Continuity() != GeomAbs_C0)
99         {
100           CS = new Geom_OffsetSurface ( aBasisSurface, anOffset );
101           return Standard_True;
102         }
103       }
104     }
105     else if (SS->IsKind(STANDARD_TYPE(StepGeom_SurfaceReplica))) { //:n7 abv 16 Feb 99
106       const Handle(StepGeom_SurfaceReplica) SR = Handle(StepGeom_SurfaceReplica)::DownCast(SS);
107       const Handle(StepGeom_Surface) PS = SR->ParentSurface();
108       const Handle(StepGeom_CartesianTransformationOperator3d) T = 
109         Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(SR->Transformation());
110       // protect against cyclic references and wrong type of cartop
111       if ( !T.IsNull() && PS != SS ) {
112         Handle(Geom_Surface) S1;
113         if (StepToGeom_MakeSurface::Convert(PS,S1))
114         {
115           gp_Trsf T1;
116           if (StepToGeom_MakeTransformation3d::Convert(T,T1))
117           {
118             S1->Transform ( T1 );
119             CS = S1;
120             return Standard_True;
121                   }
122         }
123       }
124     }
125   }
126   catch(Standard_Failure) {
127 //   ShapeTool_DB ?
128 #ifdef OCCT_DEBUG //:s5
129     cout<<"Warning: StepToGeom_MakeSurface: Exception:"; 
130     Standard_Failure::Caught()->Print(cout); cout << endl;
131 #endif
132   }
133   return Standard_False;
134 }