Salome HOME
Merge from V5_1_main 14/05/2010
[modules/geom.git] / src / GEOMAlgo / BlockFix_CheckTool.cxx
index 2c386c961faf38cd532a88223f8a803d4f0e60c1..d80c6fd0dad75415c50ee46f2a56798a75ecfb82 100644 (file)
@@ -1,13 +1,36 @@
-// File:      BlockFix_CheckTool.cxx
-// Created:   17.12.04 11:15:25
-// Author:    Sergey KUUL
-// Copyright: Open CASCADE SA 2004
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
+//  File:      BlockFix_CheckTool.cxx
+//  Created:   17.12.04 11:15:25
+//  Author:    Sergey KUUL
+//
 #include <BlockFix_CheckTool.ixx>
 
+//#include <BlockFix_UnionEdges.hxx>
+//#include <BlockFix_UnionFaces.hxx>
+
 #include <BRep_Tool.hxx>
-#include <BlockFix_UnionEdges.hxx>
-#include <BlockFix_UnionFaces.hxx>
+
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
@@ -58,33 +81,43 @@ void BlockFix_CheckTool::Perform()
   myNbUF=0;
   myNbUE=0;
   myNbUFUE=0;
-  TopExp_Explorer exps;
-  for(exps.Init(myShape, TopAbs_SOLID); exps.More(); exps.Next()) {
+
+  TopExp_Explorer exps (myShape, TopAbs_SOLID);
+  TopTools_MapOfShape mapS;
+  for (; exps.More(); exps.Next()) {
     TopoDS_Solid aSolid = TopoDS::Solid(exps.Current());
+    if (!mapS.Add(aSolid)) continue;
     myNbSolids++;
     Standard_Boolean IsBlock=Standard_True;
     Standard_Boolean MayBeUF=Standard_False;
     Standard_Boolean MayBeUE=Standard_False;
     Standard_Integer nf=0;
-    TopExp_Explorer expf;
-    for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) nf++;
+    TopExp_Explorer expf (aSolid, TopAbs_FACE);
+    TopTools_MapOfShape mapF;
+    for (; expf.More(); expf.Next()) {
+      if (mapF.Add(expf.Current()))
+        nf++;
+    }
 
-    if(nf<6) {
-      IsBlock=Standard_False;
+    if (nf < 6) {
+      IsBlock = Standard_False;
     }
-    else if(nf>6) {
-      IsBlock=Standard_False;
+    else if (nf > 6) {
+      IsBlock = Standard_False;
       // check faces unification
       TopTools_SequenceOfShape faces;
-      for( expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
-        TopoDS_Face aFace = TopoDS::Face(expf.Current());
-        faces.Append(aFace);
+      mapF.Clear();
+      for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
+        if (mapF.Add(expf.Current())) {
+          TopoDS_Face aFace = TopoDS::Face(expf.Current());
+          faces.Append(aFace);
+        }
       }
       Standard_Boolean HasFacesForUnification = Standard_False;
-      for(Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
+      for (Standard_Integer i=1; i<faces.Length() && !HasFacesForUnification; i++) {
         TopoDS_Face F1 = TopoDS::Face(faces.Value(i));
         TopTools_MapOfShape Edges;
-        for(TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
+        for (TopExp_Explorer expe(F1,TopAbs_EDGE); expe.More(); expe.Next())
           Edges.Add(expe.Current().Oriented(TopAbs_FORWARD));
         TopLoc_Location L1;
         Handle(Geom_Surface) S1 = BRep_Tool::Surface(F1,L1);
@@ -104,51 +137,57 @@ void BlockFix_CheckTool::Perform()
           }
         }
       }
-      if(HasFacesForUnification) {
+      if (HasFacesForUnification) {
         MayBeUF=Standard_True;
       }
     }
 
     Standard_Integer nbe=0;
     TopTools_MapOfShape DegenEdges;
-    TopExp_Explorer expe;
-    for(expe.Init(aSolid, TopAbs_EDGE); expe.More(); expe.Next()) {
+    TopExp_Explorer expe (aSolid, TopAbs_EDGE);
+    TopTools_MapOfShape mapE;
+    for (; expe.More(); expe.Next()) {
       TopoDS_Edge E = TopoDS::Edge(expe.Current());
-      if(BRep_Tool::Degenerated(E)) {
-        if(!DegenEdges.Contains(E)) {
-          DegenEdges.Add(E);
-        }
+      if (!mapE.Add(E)) continue;
+      if (BRep_Tool::Degenerated(E)) {
+        DegenEdges.Add(E);
       }
       else {
         nbe++;
       }
     }
-    if( nbe==24 && DegenEdges.Extent()>0 ) {
-      IsBlock=Standard_False;
+    if (nbe == 12 && DegenEdges.Extent() > 0) {
+      IsBlock = Standard_False;
       myNbDegen++;
       myPossibleBlocks.Append(aSolid);
       continue;
     }
-    if(nbe<24)
-      IsBlock=Standard_False;
-    if(nbe>24) {
-      IsBlock=Standard_False;
+    if (nbe < 12)
+      IsBlock = Standard_False;
+    if (nbe > 12) {
+      IsBlock = Standard_False;
       // check edges unification
       // creating map of edge faces
       TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
       TopExp::MapShapesAndAncestors(aSolid, TopAbs_EDGE, TopAbs_FACE, aMapEdgeFaces);
-      for(expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
+
+      mapF.Clear();
+      for (expf.Init(aSolid, TopAbs_FACE); expf.More(); expf.Next()) {
         TopoDS_Face aFace = TopoDS::Face(expf.Current());
+        if (!mapF.Add(aFace)) continue;
         TopTools_IndexedDataMapOfShapeListOfShape aMapFacesEdges;
-        for(expe.Init(aFace,TopAbs_EDGE); expe.More(); expe.Next()) {
+
+        TopTools_MapOfShape mapEe;
+        for (expe.Init(aFace, TopAbs_EDGE); expe.More(); expe.Next()) {
           TopoDS_Edge edge = TopoDS::Edge(expe.Current());
-          if(!aMapEdgeFaces.Contains(edge)) continue;
+          if (!mapEe.Add(edge)) continue;
+          if (!aMapEdgeFaces.Contains(edge)) continue;
           const TopTools_ListOfShape& aList = aMapEdgeFaces.FindFromKey(edge);
-          TopTools_ListIteratorOfListOfShape anIter(aList);
-          for; anIter.More(); anIter.Next()) {
+          TopTools_ListIteratorOfListOfShape anIter (aList);
+          for (; anIter.More(); anIter.Next()) {
             TopoDS_Face face = TopoDS::Face(anIter.Value());
-            if(face.IsSame(aFace)) continue;
-            if(aMapFacesEdges.Contains(face)) {
+            if (face.IsSame(aFace)) continue;
+            if (aMapFacesEdges.Contains(face)) {
               aMapFacesEdges.ChangeFromKey(face).Append(edge);
             }
             else {
@@ -158,34 +197,33 @@ void BlockFix_CheckTool::Perform()
             }
           }
         }
-        Standard_Integer i=1;
-        for(; i<=aMapFacesEdges.Extent(); i++) {
+        Standard_Integer i = 1;
+        for (; i <= aMapFacesEdges.Extent(); i++) {
           const TopTools_ListOfShape& ListEdges = aMapFacesEdges.FindFromIndex(i);
-          if(ListEdges.Extent()>1) break;
+          if (ListEdges.Extent() > 1) break;
         }
-        if(i<=aMapFacesEdges.Extent()) {
-          MayBeUE=Standard_True;
+        if (i <= aMapFacesEdges.Extent()) {
+          MayBeUE = Standard_True;
           break;
         }
       }
     }
 
-    if(IsBlock) 
+    if (IsBlock) 
       myNbBlocks++;
     else {
-      if(MayBeUF) {
+      if (MayBeUF) {
         myPossibleBlocks.Append(aSolid);
-        if(MayBeUE)
+        if (MayBeUE)
           myNbUFUE++;
         else
           myNbUF++;
       }
-      else if(MayBeUE) {
+      else if (MayBeUE) {
         myNbUE++;
         myPossibleBlocks.Append(aSolid);
       }
     }
-
   }
 
   myHasCheck = Standard_True;