1 // Copyright (C) 2007-2010 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.ixx>
29 //#include <BlockFix_UnionEdges.hxx>
30 //#include <BlockFix_UnionFaces.hxx>
32 #include <BRep_Tool.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Solid.hxx>
40 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
41 #include <TopTools_MapOfShape.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
46 //=======================================================================
47 //function : BlockFix_CheckTool()
48 //purpose : Constructor
49 //=======================================================================
51 BlockFix_CheckTool::BlockFix_CheckTool( )
53 myHasCheck = Standard_False;
54 myPossibleBlocks.Clear();
58 //=======================================================================
61 //=======================================================================
63 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
65 myHasCheck = Standard_False;
67 myPossibleBlocks.Clear();
71 //=======================================================================
74 //=======================================================================
76 void BlockFix_CheckTool::Perform()
85 TopExp_Explorer exps (myShape, TopAbs_SOLID);
86 TopTools_MapOfShape mapS;
87 for (; exps.More(); exps.Next()) {
88 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
89 if (!mapS.Add(aSolid)) continue;
91 Standard_Boolean IsBlock=Standard_True;
92 Standard_Boolean MayBeUF=Standard_False;
93 Standard_Boolean MayBeUE=Standard_False;
94 Standard_Integer nf=0;
95 TopExp_Explorer expf (aSolid, TopAbs_FACE);
96 TopTools_MapOfShape mapF;
97 for (; expf.More(); expf.Next()) {
98 if (mapF.Add(expf.Current()))
103 IsBlock = Standard_False;
106 IsBlock = Standard_False;
107 // check faces unification
108 TopTools_SequenceOfShape faces;
110 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
111 if (mapF.Add(expf.Current())) {
112 TopoDS_Face aFace = TopoDS::Face(expf.Current());
116 Standard_Boolean HasFacesForUnification = Standard_False;
117 for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
118 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
119 TopTools_MapOfShape Edges;
120 for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
121 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
123 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
124 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
125 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
127 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
128 if( S1==S2 && L1==L2 ) {
129 // faces have equal based surface
130 // now check common edge
131 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
132 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
133 HasFacesForUnification = Standard_True;
140 if (HasFacesForUnification) {
141 MayBeUF=Standard_True;
145 Standard_Integer nbe=0;
146 TopTools_MapOfShape DegenEdges;
147 TopExp_Explorer expe (aSolid, TopAbs_EDGE);
148 TopTools_MapOfShape mapE;
149 for (; expe.More(); expe.Next()) {
150 TopoDS_Edge E = TopoDS::Edge(expe.Current());
151 if (!mapE.Add(E)) continue;
152 if (BRep_Tool::Degenerated(E)) {
159 if (nbe == 12 && DegenEdges.Extent() > 0) {
160 IsBlock = Standard_False;
162 myPossibleBlocks.Append(aSolid);
166 IsBlock = Standard_False;
168 IsBlock = Standard_False;
169 // check edges unification
170 // creating map of edge faces
171 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
172 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
175 for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
176 TopoDS_Face aFace = TopoDS::Face(expf.Current());
177 if (!mapF.Add(aFace)) continue;
178 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
180 TopTools_MapOfShape mapEe;
181 for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
182 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
183 if (!mapEe.Add(edge)) continue;
184 if (!aMapEdgeFaces.Contains(edge)) continue;
185 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
186 TopTools_ListIteratorOfListOfShape anIter (aList);
187 for (; anIter.More(); anIter.Next()) {
188 TopoDS_Face face = TopoDS::Face(anIter.Value());
189 if (face.IsSame(aFace)) continue;
190 if (aMapFacesEdges.Contains(face)) {
191 aMapFacesEdges.ChangeFromKey(face).Append(edge);
194 TopTools_ListOfShape ListEdges;
195 ListEdges.Append(edge);
196 aMapFacesEdges.Add(face,ListEdges);
200 Standard_Integer i = 1;
201 for (; i <= aMapFacesEdges.Extent(); i++) {
202 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
203 if (ListEdges.Extent() > 1) break;
205 if (i <= aMapFacesEdges.Extent()) {
206 MayBeUE = Standard_True;
216 myPossibleBlocks.Append(aSolid);
224 myPossibleBlocks.Append(aSolid);
229 myHasCheck = Standard_True;
233 //=======================================================================
234 //function : NbPossibleBlocks
236 //=======================================================================
238 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
240 return myPossibleBlocks.Length();
244 //=======================================================================
245 //function : PossibleBlock
247 //=======================================================================
249 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
252 if( num>0 && num<=myPossibleBlocks.Length() )
253 res = myPossibleBlocks.Value(num);
258 //=======================================================================
259 //function : DumpCheckResult
261 //=======================================================================
263 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
266 S<<"Check not performed!"<<endl;
268 S<<"dump results of check:"<<endl;
269 S<<" total number of solids = "<<myNbSolids<<endl;
270 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
271 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
272 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
273 S<<" need unionfaces = "<<myNbUF<<endl;
274 S<<" need unionedges = "<<myNbUE<<endl;
275 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
276 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
277 S<<" number of impossible blocks = "<<nbtmp<<endl;