1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: BlockFix_CheckTool.cxx
23 // Created: 17.12.04 11:15:25
24 // Author: Sergey KUUL
26 #include <BlockFix_CheckTool.hxx>
28 #include <BRep_Tool.hxx>
31 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Solid.hxx>
37 #include <TopoDS_Shape.hxx>
39 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 //=======================================================================
45 //function : BlockFix_CheckTool()
46 //purpose : Constructor
47 //=======================================================================
48 BlockFix_CheckTool::BlockFix_CheckTool( )
50 myHasCheck = Standard_False;
51 myPossibleBlocks.Clear();
54 //=======================================================================
57 //=======================================================================
58 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
60 myHasCheck = Standard_False;
62 myPossibleBlocks.Clear();
65 //=======================================================================
68 //=======================================================================
69 void BlockFix_CheckTool::Perform()
78 TopExp_Explorer exps (myShape, TopAbs_SOLID);
79 TopTools_MapOfShape mapS;
80 for (; exps.More(); exps.Next()) {
81 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
82 if (!mapS.Add(aSolid)) continue;
84 Standard_Boolean IsBlock=Standard_True;
85 Standard_Boolean MayBeUF=Standard_False;
86 Standard_Boolean MayBeUE=Standard_False;
87 Standard_Integer nf=0;
88 TopExp_Explorer expf (aSolid, TopAbs_FACE);
89 TopTools_MapOfShape mapF;
90 for (; expf.More(); expf.Next()) {
91 if (mapF.Add(expf.Current()))
96 IsBlock = Standard_False;
99 IsBlock = Standard_False;
100 // check faces unification
101 TopTools_SequenceOfShape faces;
103 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
104 if (mapF.Add(expf.Current())) {
105 TopoDS_Face aFace = TopoDS::Face(expf.Current());
109 Standard_Boolean HasFacesForUnification = Standard_False;
110 for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
111 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
112 TopTools_MapOfShape Edges;
113 for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
114 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
116 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
117 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
118 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
120 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
121 if( S1==S2 && L1==L2 ) {
122 // faces have equal based surface
123 // now check common edge
124 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
125 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
126 HasFacesForUnification = Standard_True;
133 if (HasFacesForUnification) {
134 MayBeUF=Standard_True;
138 Standard_Integer nbe=0;
139 TopTools_MapOfShape DegenEdges;
140 TopExp_Explorer expe (aSolid, TopAbs_EDGE);
141 TopTools_MapOfShape mapE;
142 for (; expe.More(); expe.Next()) {
143 TopoDS_Edge E = TopoDS::Edge(expe.Current());
144 if (!mapE.Add(E)) continue;
145 if (BRep_Tool::Degenerated(E)) {
152 if (nbe == 12 && DegenEdges.Extent() > 0) {
153 IsBlock = Standard_False;
155 myPossibleBlocks.Append(aSolid);
159 IsBlock = Standard_False;
161 IsBlock = Standard_False;
162 // check edges unification
163 // creating map of edge faces
164 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
165 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
168 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
169 TopoDS_Face aFace = TopoDS::Face(expf.Current());
170 if (!mapF.Add(aFace)) continue;
171 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
173 TopTools_MapOfShape mapEe;
174 for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
175 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
176 if (!mapEe.Add(edge)) continue;
177 if (!aMapEdgeFaces.Contains(edge)) continue;
178 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
179 TopTools_ListIteratorOfListOfShape anIter (aList);
180 for (; anIter.More(); anIter.Next()) {
181 TopoDS_Face face = TopoDS::Face(anIter.Value());
182 if (face.IsSame(aFace)) continue;
183 if (aMapFacesEdges.Contains(face)) {
184 aMapFacesEdges.ChangeFromKey(face).Append(edge);
187 TopTools_ListOfShape ListEdges;
188 ListEdges.Append(edge);
189 aMapFacesEdges.Add(face,ListEdges);
193 Standard_Integer i = 1;
194 for (; i <= aMapFacesEdges.Extent(); i++) {
195 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
196 if (ListEdges.Extent() > 1) break;
198 if (i <= aMapFacesEdges.Extent()) {
199 MayBeUE = Standard_True;
209 myPossibleBlocks.Append(aSolid);
217 myPossibleBlocks.Append(aSolid);
222 myHasCheck = Standard_True;
225 //=======================================================================
226 //function : NbPossibleBlocks
228 //=======================================================================
229 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
231 return myPossibleBlocks.Length();
234 //=======================================================================
235 //function : PossibleBlock
237 //=======================================================================
238 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
241 if( num>0 && num<=myPossibleBlocks.Length() )
242 res = myPossibleBlocks.Value(num);
246 //=======================================================================
247 //function : DumpCheckResult
249 //=======================================================================
250 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
253 S<<"Check not performed!"<<endl;
255 S<<"dump results of check:"<<endl;
256 S<<" total number of solids = "<<myNbSolids<<endl;
257 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
258 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
259 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
260 S<<" need unionfaces = "<<myNbUF<<endl;
261 S<<" need unionedges = "<<myNbUE<<endl;
262 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
263 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
264 S<<" number of impossible blocks = "<<nbtmp<<endl;