0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TopoDSToStep / TopoDSToStep_FacetedTool.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <BRep_Tool.hxx>
16 #include <Geom2d_BezierCurve.hxx>
17 #include <Geom2d_BSplineCurve.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom_BezierSurface.hxx>
21 #include <Geom_BSplineSurface.hxx>
22 #include <Geom_Plane.hxx>
23 #include <Geom_Surface.hxx>
24 #include <TopExp_Explorer.hxx>
25 #include <TopoDS.hxx>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Shape.hxx>
29 #include <TopoDSToStep_FacetedTool.hxx>
30
31 // ============================================================================
32 // Method  :
33 // Purpose :
34 // ============================================================================
35 TopoDSToStep_FacetedError TopoDSToStep_FacetedTool::CheckTopoDSShape
36 (const TopoDS_Shape& aShape)
37 {
38   TopExp_Explorer FaceExp, EdgeExp;
39   FaceExp.Init(aShape,TopAbs_FACE);
40   while (FaceExp.More()) {
41     const TopoDS_Face aFace = TopoDS::Face(FaceExp.Current());
42     FaceExp.Next();
43     
44     Handle(Geom_Surface) Su = BRep_Tool::Surface(aFace);
45     
46     if (Su->IsKind(STANDARD_TYPE(Geom_Plane))) {
47       // OK -> no further check
48     }
49     else if (Su->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
50       Handle(Geom_BSplineSurface) aBsplS =
51         Handle(Geom_BSplineSurface)::DownCast(Su);
52       Standard_Integer uDeg, vDeg, nUPol, nVPol;
53       uDeg = aBsplS->UDegree();
54       if (uDeg == 1) {
55         vDeg = aBsplS->VDegree();
56         if (vDeg == 1) {
57           nUPol = aBsplS->NbUPoles();
58           nVPol = aBsplS->NbVPoles();
59           if (nUPol != 2  ||  nVPol != 2) {
60             return TopoDSToStep_SurfaceNotPlane;
61           }
62         }
63         else {
64           // Degree in v != 1
65           return TopoDSToStep_SurfaceNotPlane;
66         }
67       }
68       else {
69         // Degree in u != 1
70         return TopoDSToStep_SurfaceNotPlane;
71       }
72     }
73     else if (Su->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
74       Handle(Geom_BezierSurface) aBzS = 
75         Handle(Geom_BezierSurface)::DownCast(Su);
76       Standard_Integer uDeg, vDeg, nUPol, nVPol;
77       uDeg = aBzS->UDegree();
78       if (uDeg == 1) {
79         vDeg = aBzS->VDegree();
80         if (vDeg == 1) {
81           nUPol = aBzS->NbUPoles();
82           nVPol = aBzS->NbVPoles();
83           if (nUPol != 2  ||  nVPol != 2) {
84             return TopoDSToStep_SurfaceNotPlane;
85           }
86         }
87         else {
88           // Degree in v != 1
89           return TopoDSToStep_SurfaceNotPlane;
90         }
91       }
92       else {
93         // Degree in u != 1
94         return TopoDSToStep_SurfaceNotPlane;
95       }
96     }
97     else {
98       // the surface is neither a Plane nor a flat BSpline or Beziersurface
99       return  TopoDSToStep_SurfaceNotPlane;
100     }
101     
102     // surface is flat; now check, if the PCurves are linear
103     
104     EdgeExp.Init(aFace,TopAbs_EDGE);
105     while (EdgeExp.More()) {
106       const TopoDS_Edge anEdge = TopoDS::Edge(EdgeExp.Current());
107       EdgeExp.Next();
108       
109       Standard_Real cf, cl;
110       Handle(Geom2d_Curve) C2d = 
111         BRep_Tool::CurveOnSurface(anEdge, aFace, cf, cl);
112       
113       if (C2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
114         return  TopoDSToStep_FacetedDone;
115       }
116       else if (C2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
117         Handle(Geom2d_BSplineCurve) aBspl2d = 
118           Handle(Geom2d_BSplineCurve)::DownCast(C2d);
119         if ((aBspl2d->Degree() != 1) || (aBspl2d->NbPoles() != 2)) {
120           return  TopoDSToStep_PCurveNotLinear;
121         }
122       }
123       else if (C2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
124         Handle(Geom2d_BezierCurve) aBzC2d = 
125           Handle(Geom2d_BezierCurve)::DownCast(C2d);
126         if ((aBzC2d->Degree() != 1) || (aBzC2d->NbPoles() != 2)) {
127           return  TopoDSToStep_PCurveNotLinear;
128         }
129       }
130       else {
131         return  TopoDSToStep_PCurveNotLinear;
132       }
133     }  // end while (EdgeExp.More())
134   }  // end while (FaceExp.More())
135  
136   return  TopoDSToStep_FacetedDone;
137 }