0024135: Result of reading step file is invalid.
[occt.git] / src / StepToGeom / StepToGeom_MakeSurface.cxx
CommitLineData
b311480e 1// Created on: 1993-07-05
2// Created by: Martine LANGLOIS
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21//:n7 abv 15.02.99: S4132: adding translation of surface_replica
22//:p0 abv 19.02.99: management of 'done' flag improved
23//:s5 abv 22.04.99 Adding debug printouts in catch {} blocks
24//sln 03.10.01. BUC61003. creation of offset surface is corrected
25
26#include <StepToGeom_MakeSurface.ixx>
27#include <Standard_ErrorHandler.hxx>
28#include <Standard_Failure.hxx>
29#include <StepGeom_Surface.hxx>
30#include <StepToGeom_MakeSurface.hxx>
31#include <StepGeom_BoundedSurface.hxx>
32#include <StepToGeom_MakeBoundedSurface.hxx>
33#include <StepGeom_ElementarySurface.hxx>
34#include <StepToGeom_MakeElementarySurface.hxx>
35#include <StepGeom_SweptSurface.hxx>
36#include <StepToGeom_MakeSweptSurface.hxx>
37
38//:d4
39#include <StepGeom_OffsetSurface.hxx>
40#include <Geom_OffsetSurface.hxx>
41#include <StepGeom_SurfaceReplica.hxx>
42#include <StepGeom_CartesianTransformationOperator3d.hxx>
43#include <StepToGeom_MakeTransformation3d.hxx>
44#include <UnitsMethods.hxx>
b311480e 45
7fd59977 46#include <BRepBuilderAPI_MakeFace.hxx>
47#include <TopoDS_Face.hxx>
48#include <ShapeAlgo.hxx>
49#include <ShapeAlgo_AlgoContainer.hxx>
50#include <TopoDS.hxx>
51#include <BRep_Tool.hxx>
52#include <gp_Trsf.hxx>
1c72dff6 53#include <Precision.hxx>
7fd59977 54
55//=============================================================================
56// Creation d' une Surface de Geom a partir d' une Surface de Step
57//=============================================================================
58
59Standard_Boolean StepToGeom_MakeSurface::Convert (const Handle(StepGeom_Surface)& SS, Handle(Geom_Surface)& CS)
60{
61 // sln 01.10.2001 BUC61003. If entry shell is NULL do nothing
62 if(SS.IsNull()) {
63//#ifdef DEB
64// cout<<"Warning: StepToGeom_MakeSurface: Null Surface:";
65//#endif
66 return Standard_False;
67 }
68
69 try {
70 OCC_CATCH_SIGNALS
71 if (SS->IsKind(STANDARD_TYPE(StepGeom_BoundedSurface))) {
72 const Handle(StepGeom_BoundedSurface) S1 = Handle(StepGeom_BoundedSurface)::DownCast(SS);
73 return StepToGeom_MakeBoundedSurface::Convert(S1,*((Handle(Geom_BoundedSurface)*)&CS));
74 }
75 if (SS->IsKind(STANDARD_TYPE(StepGeom_ElementarySurface))) {
76 const Handle(StepGeom_ElementarySurface) S1 = Handle(StepGeom_ElementarySurface)::DownCast(SS);
77 return StepToGeom_MakeElementarySurface::Convert(S1,*((Handle(Geom_ElementarySurface)*)&CS));
78 }
79 if (SS->IsKind(STANDARD_TYPE(StepGeom_SweptSurface))) {
80 const Handle(StepGeom_SweptSurface) S1 = Handle(StepGeom_SweptSurface)::DownCast(SS);
81 return StepToGeom_MakeSweptSurface::Convert(S1,*((Handle(Geom_SweptSurface)*)&CS));
82 }
83 if (SS->IsKind(STANDARD_TYPE(StepGeom_OffsetSurface))) { //:d4 abv 12 Mar 98
84 const Handle(StepGeom_OffsetSurface) OS = Handle(StepGeom_OffsetSurface)::DownCast(SS);
85 Handle(Geom_Surface) aBasisSurface;
86 if (StepToGeom_MakeSurface::Convert(OS->BasisSurface(),aBasisSurface))
87 {
88 // sln 03.10.01. BUC61003. creation of offset surface is corrected
89 const Standard_Real anOffset = OS->Distance() * UnitsMethods::LengthFactor();
90 if (aBasisSurface->Continuity() == GeomAbs_C0)
91 {
1c72dff6 92 const BRepBuilderAPI_MakeFace aBFace(aBasisSurface, Precision::Confusion());
7fd59977 93 if (aBFace.IsDone())
94 {
95 const TopoDS_Shape aResult = ShapeAlgo::AlgoContainer()->C0ShapeToC1Shape(aBFace.Face(), Abs(anOffset));
96 if (aResult.ShapeType() == TopAbs_FACE)
97 {
98 aBasisSurface = BRep_Tool::Surface(TopoDS::Face(aResult));
99 }
100 }
101 }
102 if(aBasisSurface->Continuity() != GeomAbs_C0)
103 {
104 CS = new Geom_OffsetSurface ( aBasisSurface, anOffset );
105 return Standard_True;
106 }
107 }
108 }
109 else if (SS->IsKind(STANDARD_TYPE(StepGeom_SurfaceReplica))) { //:n7 abv 16 Feb 99
110 const Handle(StepGeom_SurfaceReplica) SR = Handle(StepGeom_SurfaceReplica)::DownCast(SS);
111 const Handle(StepGeom_Surface) PS = SR->ParentSurface();
112 const Handle(StepGeom_CartesianTransformationOperator3d) T =
113 Handle(StepGeom_CartesianTransformationOperator3d)::DownCast(SR->Transformation());
114 // protect against cyclic references and wrong type of cartop
115 if ( !T.IsNull() && PS != SS ) {
116 Handle(Geom_Surface) S1;
117 if (StepToGeom_MakeSurface::Convert(PS,S1))
118 {
119 gp_Trsf T1;
120 if (StepToGeom_MakeTransformation3d::Convert(T,T1))
121 {
122 S1->Transform ( T1 );
123 CS = S1;
124 return Standard_True;
125 }
126 }
127 }
128 }
129 }
130 catch(Standard_Failure) {
131// ShapeTool_DB ?
132#ifdef DEB //:s5
133 cout<<"Warning: StepToGeom_MakeSurface: Exception:";
134 Standard_Failure::Caught()->Print(cout); cout << endl;
135#endif
136 }
137 return Standard_False;
138}