0024440: Regressions in products test group sat/doc_1
[occt.git] / src / ShapeFix / ShapeFix_Shell.cxx
index 65d95dd..e6cd54f 100755 (executable)
@@ -1,7 +1,23 @@
-// File:       ShapeFix_Shell.cxx
-// Created:    Wed Aug 12 11:07:12 1998
-// Author:     Galina KULIKOVA
-//             <gka@nnov.matra-dtv.fr>
+// Created on: 1998-08-12
+// Created by: Galina KULIKOVA
+// Copyright (c) 1998-1999 Matra Datavision
+// Copyright (c) 1999-2012 OPEN CASCADE SAS
+//
+// The content of this file is subject to the Open CASCADE Technology Public
+// License Version 6.5 (the "License"). You may not use the content of this file
+// except in compliance with the License. Please obtain a copy of the License
+// at http://www.opencascade.org and read it completely before using this file.
+//
+// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
+// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
+//
+// The Original Code and all software distributed under the License is
+// distributed on an "AS IS" basis, without warranty of any kind, and the
+// Initial Developer hereby disclaims all such warranties, including without
+// limitation, any warranties of merchantability, fitness for a particular
+// purpose or non-infringement. Please see the License for the specific terms
+// and conditions governing the rights and limitations under the License.
+
 // pdn 17.12.98 ie_exhaust-A.stp
 
 #include <ShapeFix_Shell.ixx>
@@ -30,6 +46,7 @@
 #include <BRep_Builder.hxx>
 #include <BRep_Tool.hxx>
 
+#include <ShapeAnalysis_Shell.hxx>
 #include <ShapeExtend.hxx>
 #include <ShapeBuild_ReShape.hxx> 
 #include <Message_Msg.hxx>
@@ -132,6 +149,25 @@ Standard_Boolean ShapeFix_Shell::Perform(const Handle(Message_ProgressIndicator)
   TopoDS_Shape newsh = Context()->Apply(myShell);
   if ( NeedFix ( myFixOrientationMode) )
     FixFaceOrientation(TopoDS::Shell(newsh));
+
+  TopoDS_Shape aNewsh = Context()->Apply (newsh);
+  ShapeAnalysis_Shell aSas;
+  for (TopExp_Explorer aShellExp (aNewsh, TopAbs_SHELL); aShellExp.More(); aShellExp.Next())
+  {
+    TopoDS_Shell aCurShell = TopoDS::Shell (aShellExp.Current());
+    if (aCurShell.Closed())
+    {
+      aSas.LoadShells (aCurShell);
+      aSas.CheckOrientedShells (aCurShell, Standard_True);
+      if (aSas.HasFreeEdges())
+      {
+        aCurShell.Closed (Standard_False);
+        SendWarning (Message_Msg ("FixAdvShell.FixClosedFlag.MSG0"));//Shell has incorrect flag isClosed
+      }
+      aSas.Clear();
+       }
+  }
+
   if ( status )
     myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
   if(Status(ShapeExtend_DONE2))
@@ -835,12 +871,22 @@ Standard_Boolean ShapeFix_Shell::FixFaceOrientation(const TopoDS_Shell& shell,co
   TopTools_IndexedDataMapOfShapeListOfShape aMapEdgeFaces;
   TopExp::MapShapesAndAncestors(myShell,TopAbs_EDGE,TopAbs_FACE,aMapEdgeFaces);
   TopTools_MapOfShape aMapMultiConnectEdges;
-  if(isAccountMultiConex) {
-    //Finds multishared edges
-    for(Standard_Integer k = 1; k <= aMapEdgeFaces.Extent(); k++) {
-      if(aMapEdgeFaces.FindFromIndex(k).Extent() >2)
-        aMapMultiConnectEdges.Add(aMapEdgeFaces.FindKey(k));
+  Standard_Boolean isFreeBoundaries = Standard_False;
+  for(Standard_Integer k = 1; k <= aMapEdgeFaces.Extent(); k++) {
+    const Standard_Integer aFaceCount = aMapEdgeFaces.FindFromIndex(k).Extent();
+    if (!isFreeBoundaries && aFaceCount == 1) {
+      TopoDS_Edge E = TopoDS::Edge(aMapEdgeFaces.FindKey(k));
+      if (!BRep_Tool::Degenerated(E))
+        isFreeBoundaries = Standard_True;
     }
+    //Finds multishared edges
+    else if (isAccountMultiConex && aFaceCount > 2)
+      aMapMultiConnectEdges.Add(aMapEdgeFaces.FindKey(k));
+  }
+  if (BRep_Tool::IsClosed(myShell)? isFreeBoundaries : !isFreeBoundaries)
+  {
+    myShell.Closed (!isFreeBoundaries);
+    SendWarning (Message_Msg ("FixAdvShell.FixClosedFlag.MSG0"));//Shell has incorrect flag isClosed
   }
   Standard_Boolean isGetShells = Standard_True;
   //Gets possible shells with taking in account of multiconnexity.