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