0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / LocOpe / LocOpe_FindEdgesInFace.cxx
1 // Created on: 1996-02-15
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1996-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 #include <LocOpe_FindEdgesInFace.hxx>
18
19 #include <BRep_Tool.hxx>
20 #include <BRepAdaptor_Surface.hxx>
21 #include <BRepTopAdaptor_TopolTool.hxx>
22 #include <ElCLib.hxx>
23 #include <ElSLib.hxx>
24 #include <Geom_Circle.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom_CylindricalSurface.hxx>
27 #include <Geom_Line.hxx>
28 #include <Geom_Plane.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_Surface.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <Precision.hxx>
33 #include <Standard_ConstructionError.hxx>
34 #include <Standard_NoMoreObject.hxx>
35 #include <Standard_NoSuchObject.hxx>
36 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41
42 //=======================================================================
43 //function : Set
44 //purpose  : 
45 //=======================================================================
46 void LocOpe_FindEdgesInFace::Set(const TopoDS_Shape& Sh,
47                                  const TopoDS_Face& F)
48 {
49   myShape = Sh;
50   myFace = F;
51   myList.Clear();
52
53   TopTools_MapOfShape M;
54   TopExp_Explorer exp,expf;
55   Handle(Geom_Curve) C;
56   Handle(Geom_Surface) S;
57   TopLoc_Location Loc;
58   Standard_Real f,l;
59   Handle(Standard_Type) Tc,Ts;
60   Standard_Boolean ToAdd;
61   gp_Pln pl;
62   gp_Cylinder cy;
63
64
65   Standard_Real Tol = Precision::Confusion();
66   Standard_Real TolAng = Precision::Angular();
67
68   S = BRep_Tool::Surface(F);
69   Ts = S->DynamicType();
70   if (Ts == STANDARD_TYPE(Geom_RectangularTrimmedSurface)) {
71     S = Handle(Geom_RectangularTrimmedSurface)::DownCast(S)->BasisSurface();
72     Ts = S->DynamicType();
73   }
74
75   if (Ts != STANDARD_TYPE(Geom_Plane) && Ts != STANDARD_TYPE(Geom_CylindricalSurface)) {
76     return; // pour le moment
77   }
78
79   Handle(BRepAdaptor_Surface) HS = new BRepAdaptor_Surface(myFace);
80   BRepTopAdaptor_TopolTool TPT(HS);
81
82   for (exp.Init(myShape,TopAbs_EDGE); exp.More(); exp.Next()) {
83     ToAdd = Standard_False;
84     const TopoDS_Edge& edg = TopoDS::Edge(exp.Current());
85     if (M.Contains(edg)) {
86       continue;
87     }
88
89     for (expf.Init(myFace,TopAbs_EDGE); expf.More();expf.Next()) {
90       if (expf.Current().IsSame(edg)) {
91         break;
92       }
93     }
94     if (expf.More()) { // partage d`edge
95       M.Add(edg);
96       myList.Append(edg);
97       continue;
98     }
99
100     C = BRep_Tool::Curve(edg,Loc,f,l);
101     C = Handle(Geom_Curve)::DownCast(C->Transformed(Loc.Transformation()));
102     Tc = C->DynamicType();
103     if (Tc == STANDARD_TYPE(Geom_TrimmedCurve)) {
104       C = Handle(Geom_TrimmedCurve)::DownCast(C)->BasisCurve();
105       Tc = C->DynamicType();
106     }
107     if (Tc != STANDARD_TYPE(Geom_Line) && Tc != STANDARD_TYPE(Geom_Circle)) {
108       continue; // pour le moment
109     }
110     if (Ts == STANDARD_TYPE(Geom_Plane)) {
111       pl = Handle(Geom_Plane)::DownCast(S)->Pln();
112     }
113     else {
114       cy = Handle(Geom_CylindricalSurface)::DownCast(S)->Cylinder();
115     }
116
117     if (Tc == STANDARD_TYPE(Geom_Line)) {
118       gp_Lin li = Handle(Geom_Line)::DownCast(C)->Lin();
119       if (Ts == STANDARD_TYPE(Geom_Plane)) {
120         if (pl.Contains(li,Tol,TolAng)) {
121           ToAdd = Standard_True;
122         }
123       }
124       else { //Ts == STANDARD_TYPE(Geom_CylindricalSurface)
125         if (cy.Axis().IsParallel(li.Position(),TolAng) &&
126             Abs(li.Distance(cy.Location())-cy.Radius()) < Tol) {
127           ToAdd = Standard_True;
128         }
129       }
130     }
131     else { // Tt == STANDARD_TYPE(Geom_Circle)
132       gp_Circ ci = Handle(Geom_Circle)::DownCast(C)->Circ();
133       if (Ts == STANDARD_TYPE(Geom_Plane)) {
134         if (pl.Position().IsCoplanar(ci.Position(),Tol,TolAng)) {
135           ToAdd = Standard_True;
136         }
137       }
138       else {
139         if (Abs(cy.Radius()-ci.Radius()) < Tol &&
140             cy.Axis().IsCoaxial(ci.Axis(),TolAng,Tol)) {
141           ToAdd = Standard_True;
142         }
143       }
144     }
145
146     if (ToAdd) {
147       // On classifie 3 points.
148       gp_Pnt p[3];
149       Standard_Real U,V;
150       p[0] = C->Value(f);
151       p[1] = C->Value(l);
152       p[2] = C->Value((f+l)/2.);
153 //      for (Standard_Integer i=0; i<3; i++) {
154       Standard_Integer i;
155       for ( i=0; i<3; i++) {
156         if (Ts == STANDARD_TYPE(Geom_Plane)) {
157           ElSLib::Parameters(pl,p[i],U,V);
158         }
159         else {
160           ElSLib::Parameters(cy,p[i],U,V);
161         }
162         if (TPT.Classify(gp_Pnt2d(U,V),Precision::Confusion())== TopAbs_OUT) {
163           break;
164         }
165       }
166       if (i >= 3) { 
167         M.Add(edg);
168         myList.Append(edg);
169       }
170     }
171   }
172 }