0024624: Lost word in license statement in source files
[occt.git] / src / BRepClass / BRepClass_FaceExplorer.cxx
1 // Created on: 1992-11-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-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 //  Modified by skv - Thu Jul 13 17:42:58 2006 OCC12627
18 //  Total rewriting of the method Segment; add the method OtherSegment.
19
20 #include <BRepClass_FaceExplorer.ixx>
21 #include <Precision.hxx>
22 #include <Geom2d_Curve.hxx>
23 #include <TopoDS.hxx>
24 #include <BRep_Tool.hxx>
25
26 //=======================================================================
27 //function : BRepClass_FaceExplorer
28 //purpose  : 
29 //=======================================================================
30
31 BRepClass_FaceExplorer::BRepClass_FaceExplorer(const TopoDS_Face& F) :
32        myFace(F),
33        myCurEdgeInd(1),
34        myCurEdgePar(0.123)
35 {
36   myFace.Orientation(TopAbs_FORWARD);
37 }
38
39 //=======================================================================
40 //function : Reject
41 //purpose  : 
42 //=======================================================================
43
44 Standard_Boolean  BRepClass_FaceExplorer::Reject(const gp_Pnt2d&)const 
45 {
46   return Standard_False;
47 }
48
49 //=======================================================================
50 //function : Segment
51 //purpose  : 
52 //=======================================================================
53
54 Standard_Boolean BRepClass_FaceExplorer::Segment(const gp_Pnt2d& P, 
55                                                  gp_Lin2d& L,
56                                                  Standard_Real& Par)
57 {
58   myCurEdgeInd = 1;
59   myCurEdgePar = 0.123;
60
61   return OtherSegment(P, L, Par);
62 }
63
64 //=======================================================================
65 //function : OtherSegment
66 //purpose  : 
67 //=======================================================================
68
69 Standard_Boolean BRepClass_FaceExplorer::OtherSegment(const gp_Pnt2d& P, 
70                                                       gp_Lin2d& L,
71                                                       Standard_Real& Par)
72 {
73   TopExp_Explorer      anExpF(myFace,TopAbs_EDGE);
74   Standard_Integer     i;
75   Standard_Real        aFPar;
76   Standard_Real        aLPar;
77   Handle(Geom2d_Curve) aC2d;
78   Standard_Real        aTolParConf = Precision::PConfusion();
79   gp_Pnt2d             aPOnC;
80   Standard_Real        aParamIn;
81
82   for (i = 1; anExpF.More(); anExpF.Next(), i++) {
83     if (i != myCurEdgeInd)
84       continue;
85
86     const TopoDS_Shape       &aLocalShape   = anExpF.Current();
87     const TopAbs_Orientation  anOrientation = aLocalShape.Orientation();
88
89     if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED) {
90       const TopoDS_Edge &anEdge = TopoDS::Edge(aLocalShape);
91
92       aC2d = BRep_Tool::CurveOnSurface(anEdge, myFace, aFPar, aLPar);
93
94       if (!aC2d.IsNull()) {
95         // Treatment of infinite cases.
96         if (Precision::IsNegativeInfinite(aFPar)) {
97           if (Precision::IsPositiveInfinite(aLPar)) {
98             aFPar = -1.;
99             aLPar =  1.;
100           } else {
101             aFPar = aLPar - 1.;
102           }
103         } else if (Precision::IsPositiveInfinite(aLPar))
104           aLPar = aFPar + 1.;
105
106         for (; myCurEdgePar < 0.7 ;myCurEdgePar += 0.2111) {
107           aParamIn = myCurEdgePar*aFPar + (1. - myCurEdgePar)*aLPar;
108
109           aC2d->D0(aParamIn, aPOnC);
110           Par = aPOnC.Distance(P);
111
112           if (Par > aTolParConf) {
113             gp_Vec2d aLinVec(P, aPOnC);
114             gp_Dir2d aLinDir(aLinVec);
115
116             L = gp_Lin2d(P, aLinDir);
117
118             // Check if ends of a curve lie on a line.
119             aC2d->D0(aFPar, aPOnC);
120
121             if (L.Distance(aPOnC) > aTolParConf) {
122               aC2d->D0(aLPar, aPOnC);
123
124               if (L.Distance(aPOnC) > aTolParConf) {
125                 myCurEdgePar += 0.2111;
126
127                 if (myCurEdgePar >= 0.7) {
128                   myCurEdgeInd++;
129                   myCurEdgePar = 0.123;
130                 }
131
132                 return Standard_True;
133               }
134             }
135           }
136         }
137       } // if (!aC2d.IsNull()) {
138     } // if (anOrientation == TopAbs_FORWARD ...
139
140     // This curve is not valid for line construction. Go to another edge.
141     myCurEdgeInd++;
142     myCurEdgePar = 0.123;
143   }
144
145   // nothing found, return an horizontal line
146   Par = RealLast();
147   L   = gp_Lin2d(P,gp_Dir2d(1,0));
148
149   return Standard_False;
150 }
151
152 //=======================================================================
153 //function : InitWires
154 //purpose  : 
155 //=======================================================================
156
157 void  BRepClass_FaceExplorer::InitWires()
158 {
159   myWExplorer.Init(myFace,TopAbs_WIRE);
160 }
161
162 //=======================================================================
163 //function : RejectWire NYI
164 //purpose  : 
165 //=======================================================================
166
167 Standard_Boolean  BRepClass_FaceExplorer::RejectWire
168   (const gp_Lin2d& , 
169    const Standard_Real)const 
170 {
171   return Standard_False;
172 }
173
174 //=======================================================================
175 //function : InitEdges
176 //purpose  : 
177 //=======================================================================
178
179 void  BRepClass_FaceExplorer::InitEdges()
180 {
181   myEExplorer.Init(myWExplorer.Current(),TopAbs_EDGE);
182 }
183
184 //=======================================================================
185 //function : RejectEdge NYI
186 //purpose  : 
187 //=======================================================================
188
189 Standard_Boolean  BRepClass_FaceExplorer::RejectEdge
190   (const gp_Lin2d& , 
191    const Standard_Real )const 
192 {
193   return Standard_False;
194 }
195
196
197 //=======================================================================
198 //function : CurrentEdge
199 //purpose  : 
200 //=======================================================================
201
202 void  BRepClass_FaceExplorer::CurrentEdge(BRepClass_Edge& E, 
203                                           TopAbs_Orientation& Or) const 
204 {
205   E.Edge() = TopoDS::Edge(myEExplorer.Current());
206   E.Face() = myFace;
207   Or = E.Edge().Orientation();
208 }
209