Salome HOME
PAL7912. Fix SaveTo(ostream)
[modules/smesh.git] / src / SMESH / SMESH_MeshEditor.cxx
index f6b3c05205013e1fd013d7f9499bce430060b7a8..b884dcd533a7937fa902133b0c0abfe7072457db 100644 (file)
@@ -470,34 +470,40 @@ bool SMESH_MeshEditor::DeleteDiag (const SMDS_MeshNode * theNode1,
 
 //=======================================================================
 //function : Reorient
-//purpose  : Reverse the normal of theFace
-//           Return false if theFace is null
+//purpose  : Reverse theElement orientation
 //=======================================================================
 
-bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theFace)
+bool SMESH_MeshEditor::Reorient (const SMDS_MeshElement * theElem)
 {
-  if (!theFace) return false;
-  const SMDS_FaceOfNodes* F = dynamic_cast<const SMDS_FaceOfNodes*>( theFace );
-  if (!F) return false;
-
-  const SMDS_MeshNode* aNodes [4], *tmpNode;
-  int i = 0;
-  SMDS_ElemIteratorPtr it = theFace->nodesIterator();
-  while ( it->more() )
-    aNodes[ i++ ] = static_cast<const SMDS_MeshNode*>( it->next() );
-
-  // exchange nodes with indeces 0 and 2
-  tmpNode = aNodes[ 0 ];
-  aNodes[ 0 ] = aNodes[ 2 ];
-  aNodes[ 2 ] = tmpNode;
-
-  //MESSAGE( theFace );
-
-  GetMeshDS()->ChangeElementNodes( theFace, aNodes, theFace->NbNodes() );
+  if (!theElem)
+    return false;
+  SMDS_ElemIteratorPtr it = theElem->nodesIterator();
+  if ( !it || !it->more() )
+    return false;
 
-  //MESSAGE( theFace );
+  switch ( theElem->GetType() ) {
+    
+  case SMDSAbs_Edge:
+  case SMDSAbs_Face:
+  {
+    int i = theElem->NbNodes();
+    vector<const SMDS_MeshNode*> aNodes( i );
+    while ( it->more() )
+      aNodes[ --i ]= static_cast<const SMDS_MeshNode*>( it->next() );
+    return GetMeshDS()->ChangeElementNodes( theElem, &aNodes[0], theElem->NbNodes() );
+  }
+  case SMDSAbs_Volume:
+  {
+    SMDS_VolumeTool vTool;
+    if ( !vTool.Set( theElem ))
+      return false;
+    vTool.Inverse();
+    return GetMeshDS()->ChangeElementNodes( theElem, vTool.GetNodes(), vTool.NbNodes() );
+  }
+  default:;
+  }
 
-  return true;
+  return false;
 }
 
 //=======================================================================
@@ -2085,7 +2091,7 @@ SMESH_MeshEditor::Extrusion_Error
   
   if ( theHasAngles ) {
     aItD = theAngles.begin();
-    for ( j=0; (aItD != theAngles.end()) && (j<aNbTP); ++aItD, ++j ) {
+    for ( j=1; (aItD != theAngles.end()) && (j<aNbTP); ++aItD, ++j ) {
       aAngle = *aItD;
       aAngles[j] = aAngle;
     }