0024157: Parallelization of assembly part of BO
[occt.git] / src / TopoDSToStep / TopoDSToStep_FacetedTool.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18#include <TopoDSToStep_FacetedTool.ixx>
19
20#include <BRep_Tool.hxx>
21
22#include <TopExp_Explorer.hxx>
23#include <TopoDS.hxx>
24#include <TopoDS_Face.hxx>
25#include <TopoDS_Edge.hxx>
26
27#include <Geom_Plane.hxx>
28#include <Geom_Surface.hxx>
29#include <Geom_BezierSurface.hxx>
30#include <Geom_BSplineSurface.hxx>
31#include <Geom2d_Curve.hxx>
32#include <Geom2d_Line.hxx>
33#include <Geom2d_BezierCurve.hxx>
34#include <Geom2d_BSplineCurve.hxx>
35
36// ============================================================================
37// Method :
38// Purpose :
39// ============================================================================
40
41TopoDSToStep_FacetedError TopoDSToStep_FacetedTool::CheckTopoDSShape
42(const TopoDS_Shape& aShape)
43{
44 TopExp_Explorer FaceExp, EdgeExp;
45 FaceExp.Init(aShape,TopAbs_FACE);
46 while (FaceExp.More()) {
47 const TopoDS_Face aFace = TopoDS::Face(FaceExp.Current());
48 FaceExp.Next();
49
50 Handle(Geom_Surface) Su = BRep_Tool::Surface(aFace);
51
52 if (Su->IsKind(STANDARD_TYPE(Geom_Plane))) {
53 // OK -> no further check
54 }
55 else if (Su->IsKind(STANDARD_TYPE(Geom_BSplineSurface))) {
56 Handle(Geom_BSplineSurface) aBsplS =
57 Handle(Geom_BSplineSurface)::DownCast(Su);
58 Standard_Integer uDeg, vDeg, nUPol, nVPol;
59 uDeg = aBsplS->UDegree();
60 if (uDeg == 1) {
61 vDeg = aBsplS->VDegree();
62 if (vDeg == 1) {
63 nUPol = aBsplS->NbUPoles();
64 nVPol = aBsplS->NbVPoles();
65 if (nUPol != 2 || nVPol != 2) {
66 return TopoDSToStep_SurfaceNotPlane;
67 }
68 }
69 else {
70 // Degree in v != 1
71 return TopoDSToStep_SurfaceNotPlane;
72 }
73 }
74 else {
75 // Degree in u != 1
76 return TopoDSToStep_SurfaceNotPlane;
77 }
78 }
79 else if (Su->IsKind(STANDARD_TYPE(Geom_BezierSurface))) {
80 Handle(Geom_BezierSurface) aBzS =
81 Handle(Geom_BezierSurface)::DownCast(Su);
82 Standard_Integer uDeg, vDeg, nUPol, nVPol;
83 uDeg = aBzS->UDegree();
84 if (uDeg == 1) {
85 vDeg = aBzS->VDegree();
86 if (vDeg == 1) {
87 nUPol = aBzS->NbUPoles();
88 nVPol = aBzS->NbVPoles();
89 if (nUPol != 2 || nVPol != 2) {
90 return TopoDSToStep_SurfaceNotPlane;
91 }
92 }
93 else {
94 // Degree in v != 1
95 return TopoDSToStep_SurfaceNotPlane;
96 }
97 }
98 else {
99 // Degree in u != 1
100 return TopoDSToStep_SurfaceNotPlane;
101 }
102 }
103 else {
104 // the surface is neither a Plane nor a flat BSpline or Beziersurface
105 return TopoDSToStep_SurfaceNotPlane;
106 }
107
108 // surface is flat; now check, if the PCurves are linear
109
110 EdgeExp.Init(aFace,TopAbs_EDGE);
111 while (EdgeExp.More()) {
112 const TopoDS_Edge anEdge = TopoDS::Edge(EdgeExp.Current());
113 EdgeExp.Next();
114
115 Standard_Real cf, cl;
116 Handle(Geom2d_Curve) C2d =
117 BRep_Tool::CurveOnSurface(anEdge, aFace, cf, cl);
118
119 if (C2d->IsKind(STANDARD_TYPE(Geom2d_Line))) {
120 return TopoDSToStep_FacetedDone;
121 }
122 else if (C2d->IsKind(STANDARD_TYPE(Geom2d_BSplineCurve))) {
123 Handle(Geom2d_BSplineCurve) aBspl2d =
124 Handle(Geom2d_BSplineCurve)::DownCast(C2d);
125 if ((aBspl2d->Degree() != 1) || (aBspl2d->NbPoles() != 2)) {
126 return TopoDSToStep_PCurveNotLinear;
127 }
128 }
129 else if (C2d->IsKind(STANDARD_TYPE(Geom2d_BezierCurve))) {
130 Handle(Geom2d_BezierCurve) aBzC2d =
131 Handle(Geom2d_BezierCurve)::DownCast(C2d);
132 if ((aBzC2d->Degree() != 1) || (aBzC2d->NbPoles() != 2)) {
133 return TopoDSToStep_PCurveNotLinear;
134 }
135 }
136 else {
137 return TopoDSToStep_PCurveNotLinear;
138 }
139 } // end while (EdgeExp.More())
140 } // end while (FaceExp.More())
141
142 return TopoDSToStep_FacetedDone;
143}