1 // Copyright (C) 2007-2013 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
23 // File: BlockFix_CheckTool.cxx
24 // Created: 17.12.04 11:15:25
25 // Author: Sergey KUUL
27 #include <BlockFix_CheckTool.hxx>
29 #include <BRep_Tool.hxx>
32 #include <TopExp_Explorer.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Solid.hxx>
38 #include <TopoDS_Shape.hxx>
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
41 #include <TopTools_MapOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 //=======================================================================
46 //function : BlockFix_CheckTool()
47 //purpose : Constructor
48 //=======================================================================
49 BlockFix_CheckTool::BlockFix_CheckTool( )
51 myHasCheck = Standard_False;
52 myPossibleBlocks.Clear();
55 //=======================================================================
58 //=======================================================================
59 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
61 myHasCheck = Standard_False;
63 myPossibleBlocks.Clear();
66 //=======================================================================
69 //=======================================================================
70 void BlockFix_CheckTool::Perform()
79 TopExp_Explorer exps (myShape, TopAbs_SOLID);
80 TopTools_MapOfShape mapS;
81 for (; exps.More(); exps.Next()) {
82 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
83 if (!mapS.Add(aSolid)) continue;
85 Standard_Boolean IsBlock=Standard_True;
86 Standard_Boolean MayBeUF=Standard_False;
87 Standard_Boolean MayBeUE=Standard_False;
88 Standard_Integer nf=0;
89 TopExp_Explorer expf (aSolid, TopAbs_FACE);
90 TopTools_MapOfShape mapF;
91 for (; expf.More(); expf.Next()) {
92 if (mapF.Add(expf.Current()))
97 IsBlock = Standard_False;
100 IsBlock = Standard_False;
101 // check faces unification
102 TopTools_SequenceOfShape faces;
104 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
105 if (mapF.Add(expf.Current())) {
106 TopoDS_Face aFace = TopoDS::Face(expf.Current());
110 Standard_Boolean HasFacesForUnification = Standard_False;
111 for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
112 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
113 TopTools_MapOfShape Edges;
114 for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
115 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
117 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
118 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
119 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
121 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
122 if( S1==S2 && L1==L2 ) {
123 // faces have equal based surface
124 // now check common edge
125 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
126 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
127 HasFacesForUnification = Standard_True;
134 if (HasFacesForUnification) {
135 MayBeUF=Standard_True;
139 Standard_Integer nbe=0;
140 TopTools_MapOfShape DegenEdges;
141 TopExp_Explorer expe (aSolid, TopAbs_EDGE);
142 TopTools_MapOfShape mapE;
143 for (; expe.More(); expe.Next()) {
144 TopoDS_Edge E = TopoDS::Edge(expe.Current());
145 if (!mapE.Add(E)) continue;
146 if (BRep_Tool::Degenerated(E)) {
153 if (nbe == 12 && DegenEdges.Extent() > 0) {
154 IsBlock = Standard_False;
156 myPossibleBlocks.Append(aSolid);
160 IsBlock = Standard_False;
162 IsBlock = Standard_False;
163 // check edges unification
164 // creating map of edge faces
165 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
166 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
169 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
170 TopoDS_Face aFace = TopoDS::Face(expf.Current());
171 if (!mapF.Add(aFace)) continue;
172 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
174 TopTools_MapOfShape mapEe;
175 for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
176 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
177 if (!mapEe.Add(edge)) continue;
178 if (!aMapEdgeFaces.Contains(edge)) continue;
179 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
180 TopTools_ListIteratorOfListOfShape anIter (aList);
181 for (; anIter.More(); anIter.Next()) {
182 TopoDS_Face face = TopoDS::Face(anIter.Value());
183 if (face.IsSame(aFace)) continue;
184 if (aMapFacesEdges.Contains(face)) {
185 aMapFacesEdges.ChangeFromKey(face).Append(edge);
188 TopTools_ListOfShape ListEdges;
189 ListEdges.Append(edge);
190 aMapFacesEdges.Add(face,ListEdges);
194 Standard_Integer i = 1;
195 for (; i <= aMapFacesEdges.Extent(); i++) {
196 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
197 if (ListEdges.Extent() > 1) break;
199 if (i <= aMapFacesEdges.Extent()) {
200 MayBeUE = Standard_True;
210 myPossibleBlocks.Append(aSolid);
218 myPossibleBlocks.Append(aSolid);
223 myHasCheck = Standard_True;
226 //=======================================================================
227 //function : NbPossibleBlocks
229 //=======================================================================
230 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
232 return myPossibleBlocks.Length();
235 //=======================================================================
236 //function : PossibleBlock
238 //=======================================================================
239 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
242 if( num>0 && num<=myPossibleBlocks.Length() )
243 res = myPossibleBlocks.Value(num);
247 //=======================================================================
248 //function : DumpCheckResult
250 //=======================================================================
251 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
254 S<<"Check not performed!"<<endl;
256 S<<"dump results of check:"<<endl;
257 S<<" total number of solids = "<<myNbSolids<<endl;
258 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
259 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
260 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
261 S<<" need unionfaces = "<<myNbUF<<endl;
262 S<<" need unionedges = "<<myNbUE<<endl;
263 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
264 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
265 S<<" number of impossible blocks = "<<nbtmp<<endl;