]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Implement ConvertFromQuadratic()
authoreap <eap@opencascade.com>
Thu, 4 May 2006 09:28:59 +0000 (09:28 +0000)
committereap <eap@opencascade.com>
Thu, 4 May 2006 09:28:59 +0000 (09:28 +0000)
src/SMESH/SMESH_MeshEditor.cxx
src/SMESH/SMESH_MeshEditor.hxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_I/SMESH_MeshEditor_i.hxx

index ca4d2c72c4943b916c90f8f174a6fabf0da2876e..731cbfdf52a8622d7489369fbf9731e57fefad34 100644 (file)
@@ -5858,14 +5858,14 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
     }
 
     SMDSAbs_ElementType aType = elem->GetType();
+    const SMDS_MeshElement* NewElem = 0;
 
     switch( aType )
     {
     case SMDSAbs_Edge :
     {
       meshDS->RemoveFreeElement(elem, theSm);  
-      const SMDS_QuadraticEdge* NewEdge = theHelper->AddQuadraticEdge(aNds[0], aNds[1], id, theForce3d);
-      AddToSameGroups(NewEdge, elem, meshDS);
+      NewElem = theHelper->AddQuadraticEdge(aNds[0], aNds[1], id, theForce3d);
       break;
     }
     case SMDSAbs_Face :
@@ -5873,19 +5873,17 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
       if(elem->IsQuadratic()) continue;
 
       meshDS->RemoveFreeElement(elem, theSm);
-      SMDS_MeshFace * NewFace = 0;
       switch(nbNodes)
       {
       case 3:
-       NewFace = theHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
+       NewElem = theHelper->AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
        break;
       case 4:
-       NewFace = theHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
+       NewElem = theHelper->AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
        break;
       default:
        continue;
       }
-      AddToSameGroups(NewFace, elem, meshDS);
       break;  
     }
     case SMDSAbs_Volume :
@@ -5893,28 +5891,31 @@ void SMESH_MeshEditor::ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
       if( elem->IsQuadratic() ) continue;
 
       meshDS->RemoveFreeElement(elem, theSm);
-      SMDS_MeshVolume * NewVolume = 0;
       switch(nbNodes)
       {
       case 4:
-       NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true);
+       NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true);
        break;
       case 6:
-       NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true);
+       NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true);
        break;
       case 8:
-       NewVolume = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
-                                        aNds[4], aNds[5], aNds[6], aNds[7], id, true);
+       NewElem = theHelper->AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
+                                      aNds[4], aNds[5], aNds[6], aNds[7], id, true);
        break;
       default:
        continue;
       }
-      AddToSameGroups(NewVolume, elem, meshDS);
       break;  
     }
     default :
       continue;
     }
+    if( NewElem )
+    {
+      AddToSameGroups( NewElem, elem, meshDS);
+      theSm->AddElement( NewElem );
+    }
   }
 }
 
@@ -6037,12 +6038,131 @@ void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
   delete aHelper;
 }
 
+//=======================================================================
+//function : RemoveQuadElem
+//purpose  :
+//=======================================================================
+void SMESH_MeshEditor::RemoveQuadElem(SMESHDS_SubMesh *theSm, 
+                                     SMDS_ElemIteratorPtr theItr)
+{
+  SMESHDS_Mesh* meshDS = GetMeshDS();
+  while( theItr->more() )
+  {
+    const SMDS_MeshElement* elem = theItr->next();
+    if( elem )
+    {
+      if( !elem->IsQuadratic() )
+        continue;
+      
+      int id = elem->GetID();
+
+      int nbNodes = elem->NbNodes(), idx = 0;
+      vector<const SMDS_MeshNode *> aNds; 
+      vector<const SMDS_MeshNode *> aQuadNds; 
+
+      //remove all quadratic nodes 
+      for(int i = 0; i < nbNodes; i++)
+      {
+       const SMDS_MeshNode* n = elem->GetNode(i);
+
+       if( elem->IsMediumNode( n ) )
+       {
+         aQuadNds.push_back( n );
+         /*  ItRemoveQuadNodeMap itRNM = myRemoveNodeMap.find( n );
+           if( itRNM == myRemoveNodeMap.end() )
+           {
+             aQuadNds.push_back( n );
+             myRemoveNodeMap.insert(RemoveQuadNodeMap::value_type( n,theSm ));
+             }*/
+       }
+       else 
+         aNds.push_back( n );
+      }
+
+      idx = aNds.size();
+      if( !idx ) continue;
+      SMDSAbs_ElementType aType = elem->GetType();      
+
+      //remove old quadratic elements
+      meshDS->RemoveFreeElement( elem, theSm );
+
+      for( int j = 0; j < aQuadNds.size(); j++ )
+      {
+       meshDS->RemoveFreeNode( aQuadNds[j], theSm );   
+      }
+      SMDS_MeshElement * NewElem = 0;
+      switch(aType)
+      {
+        case SMDSAbs_Edge:
+         NewElem = meshDS->AddEdgeWithID( aNds[0], aNds[1] ,id );
+         break;
+       case SMDSAbs_Face:
+         if( idx==3 ) NewElem = meshDS->AddFaceWithID( aNds[0],
+                                   aNds[1], aNds[2], id );
+         if( idx==4 ) NewElem = meshDS->AddFaceWithID( aNds[0],
+                                  aNds[1], aNds[2], aNds[3],id );
+         break;
+       case SMDSAbs_Volume:
+         if( idx==4 ) NewElem = meshDS->AddVolumeWithID( aNds[0],
+                                  aNds[1], aNds[2], aNds[3], id );
+         if( idx==6 ) NewElem = meshDS->AddVolumeWithID( aNds[0],
+                                  aNds[1], aNds[2], aNds[3],
+                                  aNds[4], aNds[5], id );
+         if( idx==8 ) NewElem = meshDS->AddVolumeWithID(aNds[0],
+                                  aNds[1], aNds[2], aNds[3],
+                                  aNds[4], aNds[5], aNds[6],
+                                  aNds[7] ,id );
+         break;
+       default:
+         break;
+      }
+
+      AddToSameGroups(NewElem, elem, meshDS);
+      if( theSm )
+       theSm->AddElement( NewElem );
+    }
+  }
+}
 //=======================================================================
 //function : ConvertFromQuadratic
 //purpose  :
 //=======================================================================
 bool  SMESH_MeshEditor::ConvertFromQuadratic()
 {
+  SMESHDS_Mesh* meshDS = GetMeshDS();
+  //  myRemoveNodeMap.clear();
+
+  const TopoDS_Shape& aShape = meshDS->ShapeToMesh();
+
+  if ( !aShape.IsNull() && GetMesh()->GetSubMeshContaining(aShape) )
+  {
+    SMESH_subMesh *aSubMesh = GetMesh()->GetSubMeshContaining(aShape);
+    
+    const map < int, SMESH_subMesh * >& aMapSM = aSubMesh->DependsOn();
+    map < int, SMESH_subMesh * >::const_iterator itsub;
+    for (itsub = aMapSM.begin(); itsub != aMapSM.end(); itsub++)
+    {
+      SMESHDS_SubMesh *sm = ((*itsub).second)->GetSubMeshDS();
+      if( sm )
+       RemoveQuadElem( sm, sm->GetElements() );
+    }
+    SMESHDS_SubMesh *Sm = aSubMesh->GetSubMeshDS();
+    if( Sm )
+      RemoveQuadElem( Sm, Sm->GetElements() );
+  }
+  else
+  {
+    SMESHDS_SubMesh *aSM = 0;
+    RemoveQuadElem( aSM, meshDS->elementsIterator() );
+  }
+
+  /*  ItRemoveQuadNodeMap itRNM = myRemoveNodeMap.begin();
+  for ( ; itRNM != myRemoveNodeMap.end(); itRNM++ ) {
+  {
+    meshDS->RemoveFreeNode( (*itRNM), (*itRNM).second  );      
+    }*/
+
+  return true;
 }
 
 //=======================================================================
index bd284c5749fb931bff35ea7f0c0d49e2db7de43f..c95ded87b7d4dc44695016bf910a0daa3a254060 100644 (file)
@@ -394,6 +394,7 @@ class SMESH_MeshEditor {
   SMESH_Mesh * GetMesh() { return myMesh; }
 
   SMESHDS_Mesh * GetMeshDS() { return myMesh->GetMeshDS(); }
+
 private:
 
   void ConvertElemToQuadratic(SMESHDS_SubMesh *theSm,
@@ -402,7 +403,12 @@ private:
   //Auxiliary function for "ConvertToQuadratic" is intended to convert
   //elements contained in submesh to quadratic
 
- private:
+  void RemoveQuadElem( SMESHDS_SubMesh *theSm,
+                      SMDS_ElemIteratorPtr theItr);
+  //Auxiliary function for "ConvertFromQuadratic" is intended to convert quadratic
+  //element to ordinary and for removing quadratic nodes
+
+private:
 
   SMESH_Mesh * myMesh;
 
index d85ee629583f5dc52507718c637a61aa0b3290a7..f17fbdd21ba1c929c5f90f63c53759c1ec993f32 100644 (file)
@@ -1743,5 +1743,19 @@ void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
   anEditor.ConvertToQuadratic(theForce3d);
  // Update Python script
   TPythonDump() << this << ".ConvertToQuadratic( "
-                << theForce3d << ") ";
+                << theForce3d << " )";
+}
+
+//=======================================================================
+//function : ConvertFromQuadratic
+//purpose  :
+//=======================================================================
+
+CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
+{
+  ::SMESH_MeshEditor anEditor( _myMesh );
+  CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
+  // Update Python script
+  TPythonDump() << this << ".ConvertFromQuadratic( )";
+  return isDone;
 }
index f5f12943c2511fa02d91b818a245faa75501c1fc..4b50c66cf686c8bfcaa37cc25f3bfe60b56d6e0d 100644 (file)
@@ -118,6 +118,7 @@ class SMESH_MeshEditor_i: public POA_SMESH::SMESH_MeshEditor
 
 
   void ConvertToQuadratic(CORBA::Boolean Force3d);
+  CORBA::Boolean ConvertFromQuadratic();
 
   void RenumberNodes();
   void RenumberElements();