1 // Copyright (C) 2007-2008 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.ixx>
28 #include <BRep_Tool.hxx>
29 #include <BlockFix_UnionEdges.hxx>
30 #include <BlockFix_UnionFaces.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Solid.hxx>
37 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
38 #include <TopTools_MapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 //=======================================================================
44 //function : BlockFix_CheckTool()
45 //purpose : Constructor
46 //=======================================================================
48 BlockFix_CheckTool::BlockFix_CheckTool( )
50 myHasCheck = Standard_False;
51 myPossibleBlocks.Clear();
55 //=======================================================================
58 //=======================================================================
60 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
62 myHasCheck = Standard_False;
64 myPossibleBlocks.Clear();
68 //=======================================================================
71 //=======================================================================
73 void BlockFix_CheckTool::Perform()
82 for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) {
83 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
85 Standard_Boolean IsBlock=Standard_True;
86 Standard_Boolean MayBeUF=Standard_False;
87 Standard_Boolean MayBeUE=Standard_False;
88 Standard_Integer nf=0;
90 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++;
93 IsBlock=Standard_False;
96 IsBlock=Standard_False;
97 // check faces unification
98 TopTools_SequenceOfShape faces;
99 for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
100 TopoDS_Face aFace = TopoDS::Face(expf.Current());
103 Standard_Boolean HasFacesForUnification = Standard_False;
104 for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
105 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
106 TopTools_MapOfShape Edges;
107 for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
108 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
110 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
111 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
112 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
114 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
115 if( S1==S2 && L1==L2 ) {
116 // faces have equal based surface
117 // now check common edge
118 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
119 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
120 HasFacesForUnification = Standard_True;
127 if(HasFacesForUnification) {
128 MayBeUF=Standard_True;
132 Standard_Integer nbe=0;
133 TopTools_MapOfShape DegenEdges;
134 TopExp_Explorer expe;
135 for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) {
136 TopoDS_Edge E = TopoDS::Edge(expe.Current());
137 if(BRep_Tool::Degenerated(E)) {
138 if(!DegenEdges.Contains(E)) {
146 if( nbe==24 && DegenEdges.Extent()>0 ) {
147 IsBlock=Standard_False;
149 myPossibleBlocks.Append(aSolid);
153 IsBlock=Standard_False;
155 IsBlock=Standard_False;
156 // check edges unification
157 // creating map of edge faces
158 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
159 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
160 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
161 TopoDS_Face aFace = TopoDS::Face(expf.Current());
162 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
163 for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
164 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
165 if(!aMapEdgeFaces.Contains(edge)) continue;
166 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
167 TopTools_ListIteratorOfListOfShape anIter(aList);
168 for( ; anIter.More(); anIter.Next()) {
169 TopoDS_Face face = TopoDS::Face(anIter.Value());
170 if(face.IsSame(aFace)) continue;
171 if(aMapFacesEdges.Contains(face)) {
172 aMapFacesEdges.ChangeFromKey(face).Append(edge);
175 TopTools_ListOfShape ListEdges;
176 ListEdges.Append(edge);
177 aMapFacesEdges.Add(face,ListEdges);
181 Standard_Integer i=1;
182 for(; i<=aMapFacesEdges.Extent(); i++) {
183 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
184 if(ListEdges.Extent()>1) break;
186 if(i<=aMapFacesEdges.Extent()) {
187 MayBeUE=Standard_True;
197 myPossibleBlocks.Append(aSolid);
205 myPossibleBlocks.Append(aSolid);
211 myHasCheck = Standard_True;
215 //=======================================================================
216 //function : NbPossibleBlocks
218 //=======================================================================
220 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
222 return myPossibleBlocks.Length();
226 //=======================================================================
227 //function : PossibleBlock
229 //=======================================================================
231 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
234 if( num>0 && num<=myPossibleBlocks.Length() )
235 res = myPossibleBlocks.Value(num);
240 //=======================================================================
241 //function : DumpCheckResult
243 //=======================================================================
245 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
248 S<<"Check not performed!"<<endl;
250 S<<"dump results of check:"<<endl;
251 S<<" total number of solids = "<<myNbSolids<<endl;
252 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
253 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
254 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
255 S<<" need unionfaces = "<<myNbUF<<endl;
256 S<<" need unionedges = "<<myNbUE<<endl;
257 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
258 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
259 S<<" number of impossible blocks = "<<nbtmp<<endl;