1 // Created on: 1992-11-19
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1992-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
23 // Modified by skv - Thu Jul 13 17:42:58 2006 OCC12627
24 // Total rewriting of the method Segment; add the method OtherSegment.
26 #include <BRepClass_FaceExplorer.ixx>
27 #include <Precision.hxx>
28 #include <Geom2d_Curve.hxx>
30 #include <BRep_Tool.hxx>
32 //=======================================================================
33 //function : BRepClass_FaceExplorer
35 //=======================================================================
37 BRepClass_FaceExplorer::BRepClass_FaceExplorer(const TopoDS_Face& F) :
42 myFace.Orientation(TopAbs_FORWARD);
45 //=======================================================================
48 //=======================================================================
50 Standard_Boolean BRepClass_FaceExplorer::Reject(const gp_Pnt2d&)const
52 return Standard_False;
55 //=======================================================================
58 //=======================================================================
60 Standard_Boolean BRepClass_FaceExplorer::Segment(const gp_Pnt2d& P,
67 return OtherSegment(P, L, Par);
70 //=======================================================================
71 //function : OtherSegment
73 //=======================================================================
75 Standard_Boolean BRepClass_FaceExplorer::OtherSegment(const gp_Pnt2d& P,
79 TopExp_Explorer anExpF(myFace,TopAbs_EDGE);
83 Handle(Geom2d_Curve) aC2d;
84 Standard_Real aTolParConf = Precision::PConfusion();
86 Standard_Real aParamIn;
88 for (i = 1; anExpF.More(); anExpF.Next(), i++) {
89 if (i != myCurEdgeInd)
92 const TopoDS_Shape &aLocalShape = anExpF.Current();
93 const TopAbs_Orientation anOrientation = aLocalShape.Orientation();
95 if (anOrientation == TopAbs_FORWARD || anOrientation == TopAbs_REVERSED) {
96 const TopoDS_Edge &anEdge = TopoDS::Edge(aLocalShape);
98 aC2d = BRep_Tool::CurveOnSurface(anEdge, myFace, aFPar, aLPar);
100 if (!aC2d.IsNull()) {
101 // Treatment of infinite cases.
102 if (Precision::IsNegativeInfinite(aFPar)) {
103 if (Precision::IsPositiveInfinite(aLPar)) {
109 } else if (Precision::IsPositiveInfinite(aLPar))
112 for (; myCurEdgePar < 0.7 ;myCurEdgePar += 0.2111) {
113 aParamIn = myCurEdgePar*aFPar + (1. - myCurEdgePar)*aLPar;
115 aC2d->D0(aParamIn, aPOnC);
116 Par = aPOnC.Distance(P);
118 if (Par > aTolParConf) {
119 gp_Vec2d aLinVec(P, aPOnC);
120 gp_Dir2d aLinDir(aLinVec);
122 L = gp_Lin2d(P, aLinDir);
124 // Check if ends of a curve lie on a line.
125 aC2d->D0(aFPar, aPOnC);
127 if (L.Distance(aPOnC) > aTolParConf) {
128 aC2d->D0(aLPar, aPOnC);
130 if (L.Distance(aPOnC) > aTolParConf) {
131 myCurEdgePar += 0.2111;
133 if (myCurEdgePar >= 0.7) {
135 myCurEdgePar = 0.123;
138 return Standard_True;
143 } // if (!aC2d.IsNull()) {
144 } // if (anOrientation == TopAbs_FORWARD ...
146 // This curve is not valid for line construction. Go to another edge.
148 myCurEdgePar = 0.123;
151 // nothing found, return an horizontal line
153 L = gp_Lin2d(P,gp_Dir2d(1,0));
155 return Standard_False;
158 //=======================================================================
159 //function : InitWires
161 //=======================================================================
163 void BRepClass_FaceExplorer::InitWires()
165 myWExplorer.Init(myFace,TopAbs_WIRE);
168 //=======================================================================
169 //function : RejectWire NYI
171 //=======================================================================
173 Standard_Boolean BRepClass_FaceExplorer::RejectWire
175 const Standard_Real)const
177 return Standard_False;
180 //=======================================================================
181 //function : InitEdges
183 //=======================================================================
185 void BRepClass_FaceExplorer::InitEdges()
187 myEExplorer.Init(myWExplorer.Current(),TopAbs_EDGE);
190 //=======================================================================
191 //function : RejectEdge NYI
193 //=======================================================================
195 Standard_Boolean BRepClass_FaceExplorer::RejectEdge
197 const Standard_Real )const
199 return Standard_False;
203 //=======================================================================
204 //function : CurrentEdge
206 //=======================================================================
208 void BRepClass_FaceExplorer::CurrentEdge(BRepClass_Edge& E,
209 TopAbs_Orientation& Or) const
211 E.Edge() = TopoDS::Edge(myEExplorer.Current());
213 Or = E.Edge().Orientation();