1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
19 #include <ShapeAnalysis_Shell.ixx>
21 #include <BRep_Builder.hxx>
22 #include <BRep_Tool.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Iterator.hxx>
27 #include <TopExp_Explorer.hxx>
29 //=======================================================================
32 //=======================================================================
34 void ShapeAnalysis_Shell::Clear()
39 myConex = Standard_False;
42 //=======================================================================
43 //function : LoadShells
45 //=======================================================================
47 void ShapeAnalysis_Shell::LoadShells(const TopoDS_Shape& shape)
49 if (shape.IsNull()) return;
51 if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape); //szv#4:S4163:12Mar99 i =
53 for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
54 TopoDS_Shape sh = exs.Current();
55 myShells.Add (sh); //szv#4:S4163:12Mar99 i =
61 // CheckOrientedShells : alimente BadEdges et FreeEdges
62 // BadEdges : edges presentes plus d une fois dans une meme orientation
63 // FreeEdges : edges presentes une seule fois
64 // On utilise pour cela une fonction auxiliaire : CheckEdges
65 // Qui alimente 2 maps auxiliaires : les edges directes et les inverses
67 static Standard_Boolean CheckEdges(const TopoDS_Shape& shape,
68 TopTools_IndexedMapOfShape& bads,
69 TopTools_IndexedMapOfShape& dirs,
70 TopTools_IndexedMapOfShape& revs,
71 TopTools_IndexedMapOfShape& ints)
73 Standard_Boolean res = Standard_False;
75 if (shape.ShapeType() != TopAbs_EDGE) {
76 for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
77 if (CheckEdges (it.Value(),bads,dirs,revs,ints)) res = Standard_True;
81 TopoDS_Edge E = TopoDS::Edge(shape);
82 if (BRep_Tool::Degenerated(E)) return Standard_False;
84 if (shape.Orientation() == TopAbs_FORWARD) {
85 //szv#4:S4163:12Mar99 optimized
86 if (dirs.FindIndex (shape) == 0) dirs.Add (shape);
87 else { bads.Add (shape); res = Standard_True; }
89 if (shape.Orientation() == TopAbs_REVERSED) {
90 //szv#4:S4163:12Mar99 optimized
91 if (revs.FindIndex (shape) == 0) revs.Add (shape);
92 else { bads.Add (shape); res = Standard_True; }
94 if (shape.Orientation() == TopAbs_INTERNAL) {
95 if (ints.FindIndex (shape) == 0) ints.Add (shape);
96 //else { bads.Add (shape); res = Standard_True; }
103 //=======================================================================
104 //function : CheckOrientedShells
106 //=======================================================================
108 Standard_Boolean ShapeAnalysis_Shell::CheckOrientedShells(const TopoDS_Shape& shape,
109 const Standard_Boolean alsofree,
110 const Standard_Boolean checkinternaledges)
112 myConex = Standard_False;
113 if (shape.IsNull()) return Standard_False;
114 Standard_Boolean res = Standard_False;
116 TopTools_IndexedMapOfShape dirs, revs, ints;
117 for (TopExp_Explorer exs(shape,TopAbs_SHELL); exs.More(); exs.Next()) {
118 TopoDS_Shape sh = exs.Current();
119 //szv#4:S4163:12Mar99 optimized
120 if (CheckEdges (sh,myBad,dirs,revs,ints))
121 if (myShells.Add (sh)) res = Standard_True;
124 // Resteraient a faire les FreeEdges
125 if (!alsofree) return res;
127 // Free Edges . Ce sont les edges d une map pas dans l autre
128 // et lycee de Versailles (les maps dirs et revs)
129 Standard_Integer nb = dirs.Extent();
130 Standard_Integer i; // svv Jan11 2000 : porting on DEC
131 for (i = 1; i <= nb; i ++) {
132 TopoDS_Shape sh = dirs.FindKey (i);
133 if (!myBad.Contains(sh)) {
134 if (!revs.Contains(sh)) {
135 if(checkinternaledges) {
136 if (!ints.Contains(sh)) {
139 else myConex = Standard_True;
145 else myConex = Standard_True;
147 else myConex = Standard_True;
151 for (i = 1; i <= nb; i ++) {
152 TopoDS_Shape sh = revs.FindKey (i);
153 if (!myBad.Contains(sh)) {
154 if (!dirs.Contains(sh)) {
155 if(checkinternaledges) {
156 if (!ints.Contains(sh)) {
159 else myConex = Standard_True;
165 else myConex = Standard_True;
167 else myConex = Standard_True;
173 //=======================================================================
174 //function : IsLoaded
176 //=======================================================================
178 Standard_Boolean ShapeAnalysis_Shell::IsLoaded(const TopoDS_Shape& shape) const
180 if (shape.IsNull()) return Standard_False;
181 return myShells.Contains (shape);
184 //=======================================================================
185 //function : NbLoaded
187 //=======================================================================
189 Standard_Integer ShapeAnalysis_Shell::NbLoaded() const
191 return myShells.Extent();
194 //=======================================================================
197 //=======================================================================
199 TopoDS_Shape ShapeAnalysis_Shell::Loaded(const Standard_Integer num) const
201 return myShells.FindKey (num);
204 //=======================================================================
205 //function : HasBadEdges
207 //=======================================================================
209 Standard_Boolean ShapeAnalysis_Shell::HasBadEdges() const
211 return (myBad.Extent() > 0);
214 //=======================================================================
215 //function : BadEdges
217 //=======================================================================
219 TopoDS_Compound ShapeAnalysis_Shell::BadEdges() const
224 Standard_Integer n = myBad.Extent();
225 for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myBad.FindKey(i));
229 //=======================================================================
230 //function : HasFreeEdges
232 //=======================================================================
234 Standard_Boolean ShapeAnalysis_Shell::HasFreeEdges() const
236 return (myFree.Extent() > 0);
239 //=======================================================================
240 //function : FreeEdges
242 //=======================================================================
244 TopoDS_Compound ShapeAnalysis_Shell::FreeEdges() const
249 Standard_Integer n = myFree.Extent();
250 for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myFree.FindKey(i));
254 //=======================================================================
255 //function : HasConnectedEdges
257 //=======================================================================
259 Standard_Boolean ShapeAnalysis_Shell::HasConnectedEdges() const