973c2be1 |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
2 | // |
973c2be1 |
3 | // This file is part of Open CASCADE Technology software library. |
b311480e |
4 | // |
d5f74e42 |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
10 | // |
973c2be1 |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
b311480e |
13 | |
7fd59977 |
14 | //szv#4 S4163 |
7fd59977 |
15 | |
16 | #include <BRep_Builder.hxx> |
17 | #include <BRep_Tool.hxx> |
42cf5bc1 |
18 | #include <ShapeAnalysis_Shell.hxx> |
19 | #include <TopExp_Explorer.hxx> |
7fd59977 |
20 | #include <TopoDS.hxx> |
42cf5bc1 |
21 | #include <TopoDS_Compound.hxx> |
7fd59977 |
22 | #include <TopoDS_Edge.hxx> |
23 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 |
24 | #include <TopoDS_Shape.hxx> |
7fd59977 |
25 | |
d533dafb |
26 | //======================================================================= |
27 | //function : ShapeAnalysis_Shell |
28 | //purpose : |
29 | //======================================================================= |
30 | ShapeAnalysis_Shell::ShapeAnalysis_Shell() |
31 | : myConex(Standard_False) |
32 | { |
33 | } |
34 | |
7fd59977 |
35 | //======================================================================= |
36 | //function : Clear |
37 | //purpose : |
38 | //======================================================================= |
b311480e |
39 | void ShapeAnalysis_Shell::Clear() |
7fd59977 |
40 | { |
41 | myShells.Clear(); |
42 | myBad.Clear(); |
43 | myFree.Clear(); |
44 | myConex = Standard_False; |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : LoadShells |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | void ShapeAnalysis_Shell::LoadShells(const TopoDS_Shape& shape) |
53 | { |
54 | if (shape.IsNull()) return; |
55 | |
56 | if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape); //szv#4:S4163:12Mar99 i = |
57 | else { |
58 | for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) { |
59 | TopoDS_Shape sh = exs.Current(); |
60 | myShells.Add (sh); //szv#4:S4163:12Mar99 i = |
61 | } |
62 | } |
63 | } |
64 | |
65 | |
66 | // CheckOrientedShells : alimente BadEdges et FreeEdges |
67 | // BadEdges : edges presentes plus d une fois dans une meme orientation |
68 | // FreeEdges : edges presentes une seule fois |
69 | // On utilise pour cela une fonction auxiliaire : CheckEdges |
70 | // Qui alimente 2 maps auxiliaires : les edges directes et les inverses |
71 | |
72 | static Standard_Boolean CheckEdges(const TopoDS_Shape& shape, |
73 | TopTools_IndexedMapOfShape& bads, |
74 | TopTools_IndexedMapOfShape& dirs, |
75 | TopTools_IndexedMapOfShape& revs, |
76 | TopTools_IndexedMapOfShape& ints) |
77 | { |
78 | Standard_Boolean res = Standard_False; |
79 | |
80 | if (shape.ShapeType() != TopAbs_EDGE) { |
81 | for (TopoDS_Iterator it(shape); it.More(); it.Next()) { |
82 | if (CheckEdges (it.Value(),bads,dirs,revs,ints)) res = Standard_True; |
83 | } |
84 | } |
85 | else { |
86 | TopoDS_Edge E = TopoDS::Edge(shape); |
87 | if (BRep_Tool::Degenerated(E)) return Standard_False; |
88 | |
89 | if (shape.Orientation() == TopAbs_FORWARD) { |
90 | //szv#4:S4163:12Mar99 optimized |
91 | if (dirs.FindIndex (shape) == 0) dirs.Add (shape); |
92 | else { bads.Add (shape); res = Standard_True; } |
93 | } |
94 | if (shape.Orientation() == TopAbs_REVERSED) { |
95 | //szv#4:S4163:12Mar99 optimized |
96 | if (revs.FindIndex (shape) == 0) revs.Add (shape); |
97 | else { bads.Add (shape); res = Standard_True; } |
98 | } |
99 | if (shape.Orientation() == TopAbs_INTERNAL) { |
100 | if (ints.FindIndex (shape) == 0) ints.Add (shape); |
101 | //else { bads.Add (shape); res = Standard_True; } |
102 | } |
103 | } |
104 | |
105 | return res; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : CheckOrientedShells |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | Standard_Boolean ShapeAnalysis_Shell::CheckOrientedShells(const TopoDS_Shape& shape, |
114 | const Standard_Boolean alsofree, |
115 | const Standard_Boolean checkinternaledges) |
116 | { |
117 | myConex = Standard_False; |
118 | if (shape.IsNull()) return Standard_False; |
119 | Standard_Boolean res = Standard_False; |
120 | |
121 | TopTools_IndexedMapOfShape dirs, revs, ints; |
122 | for (TopExp_Explorer exs(shape,TopAbs_SHELL); exs.More(); exs.Next()) { |
123 | TopoDS_Shape sh = exs.Current(); |
124 | //szv#4:S4163:12Mar99 optimized |
125 | if (CheckEdges (sh,myBad,dirs,revs,ints)) |
126 | if (myShells.Add (sh)) res = Standard_True; |
127 | } |
128 | |
129 | // Resteraient a faire les FreeEdges |
130 | if (!alsofree) return res; |
131 | |
132 | // Free Edges . Ce sont les edges d une map pas dans l autre |
133 | // et lycee de Versailles (les maps dirs et revs) |
134 | Standard_Integer nb = dirs.Extent(); |
135 | Standard_Integer i; // svv Jan11 2000 : porting on DEC |
136 | for (i = 1; i <= nb; i ++) { |
137 | TopoDS_Shape sh = dirs.FindKey (i); |
138 | if (!myBad.Contains(sh)) { |
139 | if (!revs.Contains(sh)) { |
140 | if(checkinternaledges) { |
141 | if (!ints.Contains(sh)) { |
142 | myFree.Add (sh); |
143 | } |
144 | else myConex = Standard_True; |
145 | } |
146 | else { |
147 | myFree.Add (sh); |
148 | } |
149 | } |
150 | else myConex = Standard_True; |
151 | } |
152 | else myConex = Standard_True; |
153 | } |
154 | |
155 | nb = revs.Extent(); |
156 | for (i = 1; i <= nb; i ++) { |
157 | TopoDS_Shape sh = revs.FindKey (i); |
158 | if (!myBad.Contains(sh)) { |
159 | if (!dirs.Contains(sh)) { |
160 | if(checkinternaledges) { |
161 | if (!ints.Contains(sh)) { |
162 | myFree.Add (sh); |
163 | } |
164 | else myConex = Standard_True; |
165 | } |
166 | else { |
167 | myFree.Add (sh); |
168 | } |
169 | } |
170 | else myConex = Standard_True; |
171 | } |
172 | else myConex = Standard_True; |
173 | } |
174 | |
175 | return res; |
176 | } |
177 | |
178 | //======================================================================= |
179 | //function : IsLoaded |
180 | //purpose : |
181 | //======================================================================= |
182 | |
183 | Standard_Boolean ShapeAnalysis_Shell::IsLoaded(const TopoDS_Shape& shape) const |
184 | { |
185 | if (shape.IsNull()) return Standard_False; |
186 | return myShells.Contains (shape); |
187 | } |
188 | |
189 | //======================================================================= |
190 | //function : NbLoaded |
191 | //purpose : |
192 | //======================================================================= |
193 | |
194 | Standard_Integer ShapeAnalysis_Shell::NbLoaded() const |
195 | { |
196 | return myShells.Extent(); |
197 | } |
198 | |
199 | //======================================================================= |
200 | //function : Loaded |
201 | //purpose : |
202 | //======================================================================= |
203 | |
204 | TopoDS_Shape ShapeAnalysis_Shell::Loaded(const Standard_Integer num) const |
205 | { |
206 | return myShells.FindKey (num); |
207 | } |
208 | |
209 | //======================================================================= |
210 | //function : HasBadEdges |
211 | //purpose : |
212 | //======================================================================= |
213 | |
214 | Standard_Boolean ShapeAnalysis_Shell::HasBadEdges() const |
215 | { |
216 | return (myBad.Extent() > 0); |
217 | } |
218 | |
219 | //======================================================================= |
220 | //function : BadEdges |
221 | //purpose : |
222 | //======================================================================= |
223 | |
224 | TopoDS_Compound ShapeAnalysis_Shell::BadEdges() const |
225 | { |
226 | TopoDS_Compound C; |
227 | BRep_Builder B; |
228 | B.MakeCompound (C); |
229 | Standard_Integer n = myBad.Extent(); |
230 | for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myBad.FindKey(i)); |
231 | return C; |
232 | } |
233 | |
234 | //======================================================================= |
235 | //function : HasFreeEdges |
236 | //purpose : |
237 | //======================================================================= |
238 | |
239 | Standard_Boolean ShapeAnalysis_Shell::HasFreeEdges() const |
240 | { |
241 | return (myFree.Extent() > 0); |
242 | } |
243 | |
244 | //======================================================================= |
245 | //function : FreeEdges |
246 | //purpose : |
247 | //======================================================================= |
248 | |
249 | TopoDS_Compound ShapeAnalysis_Shell::FreeEdges() const |
250 | { |
251 | TopoDS_Compound C; |
252 | BRep_Builder B; |
253 | B.MakeCompound (C); |
254 | Standard_Integer n = myFree.Extent(); |
255 | for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myFree.FindKey(i)); |
256 | return C; |
257 | } |
258 | |
259 | //======================================================================= |
260 | //function : HasConnectedEdges |
261 | //purpose : |
262 | //======================================================================= |
263 | |
264 | Standard_Boolean ShapeAnalysis_Shell::HasConnectedEdges() const |
265 | { |
266 | return myConex; |
267 | } |