1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
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
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.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
16 #include <BRep_Builder.hxx>
17 #include <BRep_Tool.hxx>
18 #include <ShapeAnalysis_Shell.hxx>
19 #include <TopExp_Explorer.hxx>
21 #include <TopoDS_Compound.hxx>
22 #include <TopoDS_Edge.hxx>
23 #include <TopoDS_Iterator.hxx>
24 #include <TopoDS_Shape.hxx>
26 //=======================================================================
29 //=======================================================================
30 void ShapeAnalysis_Shell::Clear()
35 myConex = Standard_False;
38 //=======================================================================
39 //function : LoadShells
41 //=======================================================================
43 void ShapeAnalysis_Shell::LoadShells(const TopoDS_Shape& shape)
45 if (shape.IsNull()) return;
47 if (shape.ShapeType() == TopAbs_SHELL) myShells.Add (shape); //szv#4:S4163:12Mar99 i =
49 for (TopExp_Explorer exs (shape,TopAbs_SHELL); exs.More(); exs.Next()) {
50 TopoDS_Shape sh = exs.Current();
51 myShells.Add (sh); //szv#4:S4163:12Mar99 i =
57 // CheckOrientedShells : alimente BadEdges et FreeEdges
58 // BadEdges : edges presentes plus d une fois dans une meme orientation
59 // FreeEdges : edges presentes une seule fois
60 // On utilise pour cela une fonction auxiliaire : CheckEdges
61 // Qui alimente 2 maps auxiliaires : les edges directes et les inverses
63 static Standard_Boolean CheckEdges(const TopoDS_Shape& shape,
64 TopTools_IndexedMapOfShape& bads,
65 TopTools_IndexedMapOfShape& dirs,
66 TopTools_IndexedMapOfShape& revs,
67 TopTools_IndexedMapOfShape& ints)
69 Standard_Boolean res = Standard_False;
71 if (shape.ShapeType() != TopAbs_EDGE) {
72 for (TopoDS_Iterator it(shape); it.More(); it.Next()) {
73 if (CheckEdges (it.Value(),bads,dirs,revs,ints)) res = Standard_True;
77 TopoDS_Edge E = TopoDS::Edge(shape);
78 if (BRep_Tool::Degenerated(E)) return Standard_False;
80 if (shape.Orientation() == TopAbs_FORWARD) {
81 //szv#4:S4163:12Mar99 optimized
82 if (dirs.FindIndex (shape) == 0) dirs.Add (shape);
83 else { bads.Add (shape); res = Standard_True; }
85 if (shape.Orientation() == TopAbs_REVERSED) {
86 //szv#4:S4163:12Mar99 optimized
87 if (revs.FindIndex (shape) == 0) revs.Add (shape);
88 else { bads.Add (shape); res = Standard_True; }
90 if (shape.Orientation() == TopAbs_INTERNAL) {
91 if (ints.FindIndex (shape) == 0) ints.Add (shape);
92 //else { bads.Add (shape); res = Standard_True; }
99 //=======================================================================
100 //function : CheckOrientedShells
102 //=======================================================================
104 Standard_Boolean ShapeAnalysis_Shell::CheckOrientedShells(const TopoDS_Shape& shape,
105 const Standard_Boolean alsofree,
106 const Standard_Boolean checkinternaledges)
108 myConex = Standard_False;
109 if (shape.IsNull()) return Standard_False;
110 Standard_Boolean res = Standard_False;
112 TopTools_IndexedMapOfShape dirs, revs, ints;
113 for (TopExp_Explorer exs(shape,TopAbs_SHELL); exs.More(); exs.Next()) {
114 TopoDS_Shape sh = exs.Current();
115 //szv#4:S4163:12Mar99 optimized
116 if (CheckEdges (sh,myBad,dirs,revs,ints))
117 if (myShells.Add (sh)) res = Standard_True;
120 // Resteraient a faire les FreeEdges
121 if (!alsofree) return res;
123 // Free Edges . Ce sont les edges d une map pas dans l autre
124 // et lycee de Versailles (les maps dirs et revs)
125 Standard_Integer nb = dirs.Extent();
126 Standard_Integer i; // svv Jan11 2000 : porting on DEC
127 for (i = 1; i <= nb; i ++) {
128 TopoDS_Shape sh = dirs.FindKey (i);
129 if (!myBad.Contains(sh)) {
130 if (!revs.Contains(sh)) {
131 if(checkinternaledges) {
132 if (!ints.Contains(sh)) {
135 else myConex = Standard_True;
141 else myConex = Standard_True;
143 else myConex = Standard_True;
147 for (i = 1; i <= nb; i ++) {
148 TopoDS_Shape sh = revs.FindKey (i);
149 if (!myBad.Contains(sh)) {
150 if (!dirs.Contains(sh)) {
151 if(checkinternaledges) {
152 if (!ints.Contains(sh)) {
155 else myConex = Standard_True;
161 else myConex = Standard_True;
163 else myConex = Standard_True;
169 //=======================================================================
170 //function : IsLoaded
172 //=======================================================================
174 Standard_Boolean ShapeAnalysis_Shell::IsLoaded(const TopoDS_Shape& shape) const
176 if (shape.IsNull()) return Standard_False;
177 return myShells.Contains (shape);
180 //=======================================================================
181 //function : NbLoaded
183 //=======================================================================
185 Standard_Integer ShapeAnalysis_Shell::NbLoaded() const
187 return myShells.Extent();
190 //=======================================================================
193 //=======================================================================
195 TopoDS_Shape ShapeAnalysis_Shell::Loaded(const Standard_Integer num) const
197 return myShells.FindKey (num);
200 //=======================================================================
201 //function : HasBadEdges
203 //=======================================================================
205 Standard_Boolean ShapeAnalysis_Shell::HasBadEdges() const
207 return (myBad.Extent() > 0);
210 //=======================================================================
211 //function : BadEdges
213 //=======================================================================
215 TopoDS_Compound ShapeAnalysis_Shell::BadEdges() const
220 Standard_Integer n = myBad.Extent();
221 for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myBad.FindKey(i));
225 //=======================================================================
226 //function : HasFreeEdges
228 //=======================================================================
230 Standard_Boolean ShapeAnalysis_Shell::HasFreeEdges() const
232 return (myFree.Extent() > 0);
235 //=======================================================================
236 //function : FreeEdges
238 //=======================================================================
240 TopoDS_Compound ShapeAnalysis_Shell::FreeEdges() const
245 Standard_Integer n = myFree.Extent();
246 for (Standard_Integer i = 1; i <= n; i ++) B.Add (C,myFree.FindKey(i));
250 //=======================================================================
251 //function : HasConnectedEdges
253 //=======================================================================
255 Standard_Boolean ShapeAnalysis_Shell::HasConnectedEdges() const