1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File: BlockFix_CheckTool.cxx
21 // Created: 17.12.04 11:15:25
22 // Author: Sergey KUUL
23 // Copyright: Open CASCADE SA 2004
25 #include <BlockFix_CheckTool.ixx>
27 #include <BRep_Tool.hxx>
28 #include <BlockFix_UnionEdges.hxx>
29 #include <BlockFix_UnionFaces.hxx>
31 #include <TopExp_Explorer.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
37 #include <TopTools_MapOfShape.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
42 //=======================================================================
43 //function : BlockFix_CheckTool()
44 //purpose : Constructor
45 //=======================================================================
47 BlockFix_CheckTool::BlockFix_CheckTool( )
49 myHasCheck = Standard_False;
50 myPossibleBlocks.Clear();
54 //=======================================================================
57 //=======================================================================
59 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
61 myHasCheck = Standard_False;
63 myPossibleBlocks.Clear();
67 //=======================================================================
70 //=======================================================================
72 void BlockFix_CheckTool::Perform()
81 for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) {
82 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
84 Standard_Boolean IsBlock=Standard_True;
85 Standard_Boolean MayBeUF=Standard_False;
86 Standard_Boolean MayBeUE=Standard_False;
87 Standard_Integer nf=0;
89 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++;
92 IsBlock=Standard_False;
95 IsBlock=Standard_False;
96 // check faces unification
97 TopTools_SequenceOfShape faces;
98 for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
99 TopoDS_Face aFace = TopoDS::Face(expf.Current());
102 Standard_Boolean HasFacesForUnification = Standard_False;
103 for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
104 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
105 TopTools_MapOfShape Edges;
106 for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
107 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
109 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
110 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
111 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
113 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
114 if( S1==S2 && L1==L2 ) {
115 // faces have equal based surface
116 // now check common edge
117 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
118 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
119 HasFacesForUnification = Standard_True;
126 if(HasFacesForUnification) {
127 MayBeUF=Standard_True;
131 Standard_Integer nbe=0;
132 TopTools_MapOfShape DegenEdges;
133 TopExp_Explorer expe;
134 for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) {
135 TopoDS_Edge E = TopoDS::Edge(expe.Current());
136 if(BRep_Tool::Degenerated(E)) {
137 if(!DegenEdges.Contains(E)) {
145 if( nbe==24 && DegenEdges.Extent()>0 ) {
146 IsBlock=Standard_False;
148 myPossibleBlocks.Append(aSolid);
152 IsBlock=Standard_False;
154 IsBlock=Standard_False;
155 // check edges unification
156 // creating map of edge faces
157 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
158 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
159 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
160 TopoDS_Face aFace = TopoDS::Face(expf.Current());
161 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
162 for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
163 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
164 if(!aMapEdgeFaces.Contains(edge)) continue;
165 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
166 TopTools_ListIteratorOfListOfShape anIter(aList);
167 for( ; anIter.More(); anIter.Next()) {
168 TopoDS_Face face = TopoDS::Face(anIter.Value());
169 if(face.IsSame(aFace)) continue;
170 if(aMapFacesEdges.Contains(face)) {
171 aMapFacesEdges.ChangeFromKey(face).Append(edge);
174 TopTools_ListOfShape ListEdges;
175 ListEdges.Append(edge);
176 aMapFacesEdges.Add(face,ListEdges);
180 Standard_Integer i=1;
181 for(; i<=aMapFacesEdges.Extent(); i++) {
182 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
183 if(ListEdges.Extent()>1) break;
185 if(i<=aMapFacesEdges.Extent()) {
186 MayBeUE=Standard_True;
196 myPossibleBlocks.Append(aSolid);
204 myPossibleBlocks.Append(aSolid);
210 myHasCheck = Standard_True;
214 //=======================================================================
215 //function : NbPossibleBlocks
217 //=======================================================================
219 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
221 return myPossibleBlocks.Length();
225 //=======================================================================
226 //function : PossibleBlock
228 //=======================================================================
230 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
233 if( num>0 && num<=myPossibleBlocks.Length() )
234 res = myPossibleBlocks.Value(num);
239 //=======================================================================
240 //function : DumpCheckResult
242 //=======================================================================
244 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
247 S<<"Check not performed!"<<endl;
249 S<<"dump results of check:"<<endl;
250 S<<" total number of solids = "<<myNbSolids<<endl;
251 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
252 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
253 S<<" including: need remove degenerative = "<<myNbDegen<<endl;
254 S<<" need unionfaces = "<<myNbUF<<endl;
255 S<<" need unionedges = "<<myNbUE<<endl;
256 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;
257 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
258 S<<" number of impossible blocks = "<<nbtmp<<endl;