1 // File: BlockFix_CheckTool.cxx
2 // Created: 17.12.04 11:15:25
4 // Copyright: Open CASCADE SA 2004
6 #include <BlockFix_CheckTool.ixx>
8 #include <BRep_Tool.hxx>
9 #include <BlockFix_UnionEdges.hxx>
10 #include <BlockFix_UnionFaces.hxx>
12 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Face.hxx>
16 #include <TopoDS_Solid.hxx>
17 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
18 #include <TopTools_MapOfShape.hxx>
19 #include <TopTools_ListOfShape.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
23 //=======================================================================
24 //function : BlockFix_CheckTool()
25 //purpose : Constructor
26 //=======================================================================
28 BlockFix_CheckTool::BlockFix_CheckTool( )
30 myHasCheck = Standard_False;
31 myPossibleBlocks.Clear();
35 //=======================================================================
38 //=======================================================================
40 void BlockFix_CheckTool::SetShape(const TopoDS_Shape& aShape)
42 myHasCheck = Standard_False;
44 myPossibleBlocks.Clear();
48 //=======================================================================
51 //=======================================================================
53 void BlockFix_CheckTool::Perform()
61 for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) {
62 TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
64 Standard_Boolean IsBlock=Standard_True;
65 Standard_Boolean MayBeUF=Standard_False;
66 Standard_Boolean MayBeUE=Standard_False;
67 Standard_Integer nf=0;
69 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++;
72 IsBlock=Standard_False;
75 IsBlock=Standard_False;
76 // check faces unification
77 TopTools_SequenceOfShape faces;
78 for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
79 TopoDS_Face aFace = TopoDS::Face(expf.Current());
82 Standard_Boolean HasFacesForUnification = Standard_False;
83 for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
84 TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
85 TopTools_MapOfShape Edges;
86 for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
87 Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
89 Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
90 for(Standard_Integer j=i+1; j<=faces.Length() && !HasFacesForUnification; j++) {
91 TopoDS_Face F2 = TopoDS::Face(faces.Value(j));
93 Handle(Geom_Surface) S2 = BRep_Tool::Surface(F2,L2);
94 if( S1==S2 && L1==L2 ) {
95 // faces have equal based surface
96 // now check common edge
97 for(TopExp_Explorer expe2(F2,TopAbs_EDGE); expe2.More(); expe2.Next()) {
98 if(Edges.Contains(expe2.Current().Oriented(TopAbs_FORWARD))) {
99 HasFacesForUnification = Standard_True;
106 if(HasFacesForUnification) {
107 MayBeUF=Standard_True;
111 Standard_Integer ne=0;
112 TopExp_Explorer expe;
113 for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) ne++;
116 IsBlock=Standard_False;
118 IsBlock=Standard_False;
119 // check edges unification
120 // creating map of edge faces
121 TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
122 TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
123 for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
124 TopoDS_Face aFace = TopoDS::Face(expf.Current());
125 TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
126 for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
127 TopoDS_Edge edge = TopoDS::Edge(expe.Current());
128 if(!aMapEdgeFaces.Contains(edge)) continue;
129 const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
130 TopTools_ListIteratorOfListOfShape anIter(aList);
131 for( ; anIter.More(); anIter.Next()) {
132 TopoDS_Face face = TopoDS::Face(anIter.Value());
133 if(face.IsSame(aFace)) continue;
134 if(aMapFacesEdges.Contains(face)) {
135 aMapFacesEdges.ChangeFromKey(face).Append(edge);
138 TopTools_ListOfShape ListEdges;
139 ListEdges.Append(edge);
140 aMapFacesEdges.Add(face,ListEdges);
144 Standard_Integer i = 1;
145 for (; i <= aMapFacesEdges.Extent(); i++) {
146 const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
147 if (ListEdges.Extent() > 1) break;
149 if (i <= aMapFacesEdges.Extent()) {
150 MayBeUE = Standard_True;
160 myPossibleBlocks.Append(aSolid);
168 myPossibleBlocks.Append(aSolid);
174 myHasCheck = Standard_True;
178 //=======================================================================
179 //function : NbPossibleBlocks
181 //=======================================================================
183 Standard_Integer BlockFix_CheckTool::NbPossibleBlocks() const
185 return myPossibleBlocks.Length();
189 //=======================================================================
190 //function : PossibleBlock
192 //=======================================================================
194 TopoDS_Shape BlockFix_CheckTool::PossibleBlock(const Standard_Integer num) const
197 if( num>0 && num<=myPossibleBlocks.Length() )
198 res = myPossibleBlocks.Value(num);
203 //=======================================================================
204 //function : DumpCheckResult
206 //=======================================================================
208 void BlockFix_CheckTool::DumpCheckResult(Standard_OStream& S) const
211 S<<"Check not performed!"<<endl;
213 S<<"dump results of check:"<<endl;
214 S<<" total number of solids = "<<myNbSolids<<endl;
215 S<<" including: number of good blocks = "<<myNbBlocks<<endl;
216 S<<" number of possible blocks = "<<NbPossibleBlocks()<<endl;
217 Standard_Integer nbtmp = myNbSolids - myNbBlocks - NbPossibleBlocks();
218 S<<" number of impossible blocks = "<<nbtmp<<endl;
219 S<<" including: need unionfaces = "<<myNbUF<<endl;
220 S<<" need unionedges = "<<myNbUE<<endl;
221 S<<" need both unionfaces and unionedges = "<<myNbUFUE<<endl;