Salome HOME
Update copyright
[modules/smesh.git] / src / SMESH / SMESH_Block.cxx
index fd4edab3265c9dbc468fc264a3ebe3a363f6be8b..b036993a515f88b9d983c90de38a70090c3dd75e 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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
+// 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 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // File      : SMESH_Pattern.hxx
 // Created   : Mon Aug  2 10:30:00 2004
 // Author    : Edward AGAPOV (eap)
@@ -382,8 +383,8 @@ bool SMESH_Block::ShellPoint(const gp_XYZ&         theParams,
   if ( thePointOnShape.size() < ID_F1yz )
     return false;
 
-  double x = theParams.X(), y = theParams.Y(), z = theParams.Z();
-  double x1 = 1. - x,       y1 = 1. - y,       z1 = 1. - z;
+  const double x = theParams.X(), y = theParams.Y(), z = theParams.Z();
+  const double x1 = 1. - x,       y1 = 1. - y,       z1 = 1. - z;
   const vector<gp_XYZ>& p = thePointOnShape;
 
   thePoint = 
@@ -952,29 +953,45 @@ int SMESH_Block::GetShapeIDByParams ( const gp_XYZ& theCoord )
   return id + 1; // shape ids start at 1
 }
 
-//=======================================================================
-//function : GetOrderedEdges
-//purpose  : return nb wires and a list of oredered edges
-//=======================================================================
+//================================================================================
+/*!
+ * \brief Return number of wires and a list of oredered edges.
+ *  \param theFace - the face to process
+ *  \param theFirstVertex - the vertex of the outer wire to set first in the returned
+ *         list ( theFirstVertex may be NULL )
+ *  \param theEdges - all ordered edges of theFace (outer edges goes first).
+ *  \param theNbEdgesInWires - nb of edges (== nb of vertices in closed wire) in each wire
+ *  \param theShapeAnalysisAlgo - if true, ShapeAnalysis::OuterWire() is used to find
+ *         the outer wire else BRepTools::OuterWire() is used.
+ *  \retval int - nb of wires
+ * 
+ * Always try to set a seam edge first.
+ * BRepTools::OuterWire() fails e.g. in the case of issue 0020184,
+ * ShapeAnalysis::OuterWire() fails in the case of issue 0020452
+ */
+//================================================================================
 
 int SMESH_Block::GetOrderedEdges (const TopoDS_Face&   theFace,
                                   TopoDS_Vertex        theFirstVertex,
                                   list< TopoDS_Edge >& theEdges,
-                                  list< int >  &       theNbVertexInWires)
+                                  list< int >  &       theNbEdgesInWires,
+                                  const bool           theShapeAnalysisAlgo)
 {
   // put wires in a list, so that an outer wire comes first
   list<TopoDS_Wire> aWireList;
-  //TopoDS_Wire anOuterWire = BRepTools::OuterWire( theFace ); ### issue 0020184
-  TopoDS_Wire anOuterWire = ShapeAnalysis::OuterWire( theFace );
-  //aWireList.push_back( anOuterWire ); ### issue 0020184
+  TopoDS_Wire anOuterWire =
+    theShapeAnalysisAlgo ? ShapeAnalysis::OuterWire( theFace ) : BRepTools::OuterWire( theFace );
   for ( TopoDS_Iterator wIt (theFace); wIt.More(); wIt.Next() )
-    if ( !anOuterWire.IsSame( wIt.Value() ))
-      aWireList.push_back( TopoDS::Wire( wIt.Value() ));
-    else
-      aWireList.push_front( TopoDS::Wire( wIt.Value() ));// ### issue 0020184
+    if ( wIt.Value().ShapeType() == TopAbs_WIRE ) // it can be internal vertex!
+    {
+      if ( !anOuterWire.IsSame( wIt.Value() ))
+        aWireList.push_back( TopoDS::Wire( wIt.Value() ));
+      else
+        aWireList.push_front( TopoDS::Wire( wIt.Value() ));
+    }
 
   // loop on edges of wires
-  theNbVertexInWires.clear();
+  theNbEdgesInWires.clear();
   list<TopoDS_Wire>::iterator wlIt = aWireList.begin();
   for ( ; wlIt != aWireList.end(); wlIt++ )
   {
@@ -983,10 +1000,16 @@ int SMESH_Block::GetOrderedEdges (const TopoDS_Face&   theFace,
     for ( iE = 0; wExp.More(); wExp.Next(), iE++ )
     {
       TopoDS_Edge edge = wExp.Current();
-      edge = TopoDS::Edge( edge.Oriented( wExp.Orientation() ));
+      // commented for issue 0020557, other related ones: 0020526, PAL19080
+      // edge = TopoDS::Edge( edge.Oriented( wExp.Orientation() ));
       theEdges.push_back( edge );
     }
-    theNbVertexInWires.push_back( iE );
+    if ( iE == 0 ) // wExp returns nothing if e.g. the wire contains one internal edge
+    { // Issue 0020676
+      for ( TopoDS_Iterator e( *wlIt ); e.More(); e.Next(), ++iE )
+        theEdges.push_back( TopoDS::Edge( e.Value() ));
+    }
+    theNbEdgesInWires.push_back( iE );
     iE = 0;
     if ( wlIt == aWireList.begin() && theEdges.size() > 1 ) { // the outer wire
       // orient closed edges
@@ -1024,7 +1047,7 @@ int SMESH_Block::GetOrderedEdges (const TopoDS_Face&   theFace,
           theEdges.splice(theEdges.end(), theEdges,
                           theEdges.begin(), ++theEdges.begin());
           TopExp::Vertices( theEdges.front(), vv[0], vv[1], true );
-          if ( iE++ > theNbVertexInWires.back() ) {
+          if ( iE++ > theNbEdgesInWires.back() ) {
 #ifdef _DEBUG_
             gp_Pnt p = BRep_Tool::Pnt( theFirstVertex );
             MESSAGE ( " : Warning : vertex "<< theFirstVertex.TShape().operator->()