+//=======================================================================
+/*!
+ * \brief Convert elements contained in a submesh to quadratic
+ * \retval int - nb of checked elements
+ */
+//=======================================================================
+
+int SMESH_MeshEditor::convertElemToQuadratic(SMESHDS_SubMesh * theSm,
+ SMESH_MesherHelper& theHelper,
+ const bool theForce3d)
+{
+ int nbElem = 0;
+ if( !theSm ) return nbElem;
+ SMDS_ElemIteratorPtr ElemItr = theSm->GetElements();
+ while(ElemItr->more())
+ {
+ nbElem++;
+ const SMDS_MeshElement* elem = ElemItr->next();
+ if( !elem || elem->IsQuadratic() ) continue;
+
+ int id = elem->GetID();
+ int nbNodes = elem->NbNodes();
+ vector<const SMDS_MeshNode *> aNds (nbNodes);
+
+ for(int i = 0; i < nbNodes; i++)
+ {
+ aNds[i] = elem->GetNode(i);
+ }
+ SMDSAbs_ElementType aType = elem->GetType();
+
+ theSm->RemoveElement(elem);
+ GetMeshDS()->SMDS_Mesh::RemoveFreeElement(elem);
+
+ const SMDS_MeshElement* NewElem = 0;
+
+ switch( aType )
+ {
+ case SMDSAbs_Edge :
+ {
+ NewElem = theHelper.AddEdge(aNds[0], aNds[1], id, theForce3d);
+ break;
+ }
+ case SMDSAbs_Face :
+ {
+ switch(nbNodes)
+ {
+ case 3:
+ NewElem = theHelper.AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
+ break;
+ case 4:
+ NewElem = theHelper.AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
+ break;
+ default:
+ continue;
+ }
+ break;
+ }
+ case SMDSAbs_Volume :
+ {
+ switch(nbNodes)
+ {
+ case 4:
+ NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], id, true);
+ break;
+ case 6:
+ NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3], aNds[4], aNds[5], id, true);
+ break;
+ case 8:
+ NewElem = theHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
+ aNds[4], aNds[5], aNds[6], aNds[7], id, true);
+ break;
+ default:
+ continue;
+ }
+ break;
+ }
+ default :
+ continue;
+ }
+ if( NewElem )
+ {
+ AddToSameGroups( NewElem, elem, GetMeshDS());
+ theSm->AddElement( NewElem );
+ }
+ if ( NewElem != elem )
+ RemoveElemFromGroups (elem, GetMeshDS());
+ }
+ return nbElem;
+}
+
+//=======================================================================
+//function : ConvertToQuadratic
+//purpose :
+//=======================================================================
+void SMESH_MeshEditor::ConvertToQuadratic(const bool theForce3d)
+{
+ SMESHDS_Mesh* meshDS = GetMeshDS();
+
+ SMESH_MesherHelper aHelper(*myMesh);
+ aHelper.SetIsQuadratic( true );
+
+ int nbCheckedElems = 0;
+ if ( myMesh->HasShapeToMesh() )
+ {
+ if ( SMESH_subMesh *aSubMesh = myMesh->GetSubMeshContaining(myMesh->GetShapeToMesh()))
+ {
+ SMESH_subMeshIteratorPtr smIt = aSubMesh->getDependsOnIterator(true,false);
+ while ( smIt->more() ) {
+ SMESH_subMesh* sm = smIt->next();
+ if ( SMESHDS_SubMesh *smDS = sm->GetSubMeshDS() ) {
+ aHelper.SetSubShape( sm->GetSubShape() );
+ nbCheckedElems += convertElemToQuadratic(smDS, aHelper, theForce3d);
+ }
+ }
+ }
+ }
+ int totalNbElems = meshDS->NbEdges() + meshDS->NbFaces() + meshDS->NbVolumes();
+ if ( nbCheckedElems < totalNbElems ) // not all elements in submeshes
+ {
+ SMDS_EdgeIteratorPtr aEdgeItr = meshDS->edgesIterator();
+ while(aEdgeItr->more())
+ {
+ const SMDS_MeshEdge* edge = aEdgeItr->next();
+ if(edge && !edge->IsQuadratic())
+ {
+ int id = edge->GetID();
+ const SMDS_MeshNode* n1 = edge->GetNode(0);
+ const SMDS_MeshNode* n2 = edge->GetNode(1);
+
+ meshDS->SMDS_Mesh::RemoveFreeElement(edge);
+
+ const SMDS_MeshEdge* NewEdge = aHelper.AddEdge(n1, n2, id, theForce3d);
+ if ( NewEdge )
+ AddToSameGroups(NewEdge, edge, meshDS);
+ if ( NewEdge != edge )
+ RemoveElemFromGroups (edge, meshDS);
+ }
+ }
+ SMDS_FaceIteratorPtr aFaceItr = meshDS->facesIterator();
+ while(aFaceItr->more())
+ {
+ const SMDS_MeshFace* face = aFaceItr->next();
+ if(!face || face->IsQuadratic() ) continue;
+
+ int id = face->GetID();
+ int nbNodes = face->NbNodes();
+ vector<const SMDS_MeshNode *> aNds (nbNodes);
+
+ for(int i = 0; i < nbNodes; i++)
+ {
+ aNds[i] = face->GetNode(i);
+ }
+
+ meshDS->SMDS_Mesh::RemoveFreeElement(face);
+
+ SMDS_MeshFace * NewFace = 0;
+ switch(nbNodes)
+ {
+ case 3:
+ NewFace = aHelper.AddFace(aNds[0], aNds[1], aNds[2], id, theForce3d);
+ break;
+ case 4:
+ NewFace = aHelper.AddFace(aNds[0], aNds[1], aNds[2], aNds[3], id, theForce3d);
+ break;
+ default:
+ continue;
+ }
+ if ( NewFace )
+ AddToSameGroups(NewFace, face, meshDS);
+ if ( NewFace != face )
+ RemoveElemFromGroups (face, meshDS);
+ }
+ SMDS_VolumeIteratorPtr aVolumeItr = meshDS->volumesIterator();
+ while(aVolumeItr->more())
+ {
+ const SMDS_MeshVolume* volume = aVolumeItr->next();
+ if(!volume || volume->IsQuadratic() ) continue;
+
+ int id = volume->GetID();
+ int nbNodes = volume->NbNodes();
+ vector<const SMDS_MeshNode *> aNds (nbNodes);
+
+ for(int i = 0; i < nbNodes; i++)
+ {
+ aNds[i] = volume->GetNode(i);
+ }
+
+ meshDS->SMDS_Mesh::RemoveFreeElement(volume);
+
+ SMDS_MeshVolume * NewVolume = 0;
+ switch(nbNodes)
+ {
+ case 4:
+ NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2],
+ aNds[3], id, true );
+ break;
+ case 6:
+ NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2],
+ aNds[3], aNds[4], aNds[5], id, true);
+ break;
+ case 8:
+ NewVolume = aHelper.AddVolume(aNds[0], aNds[1], aNds[2], aNds[3],
+ aNds[4], aNds[5], aNds[6], aNds[7], id, true);
+ break;
+ default:
+ continue;
+ }
+ if ( NewVolume )
+ AddToSameGroups(NewVolume, volume, meshDS);
+ if ( NewVolume != volume )
+ RemoveElemFromGroups (volume, meshDS);
+ }
+ }
+}
+
+//=======================================================================
+/*!
+ * \brief Convert quadratic elements to linear ones and remove quadratic nodes
+ * \retval int - nb of checked elements
+ */
+//=======================================================================
+
+int SMESH_MeshEditor::removeQuadElem(SMESHDS_SubMesh * theSm,
+ SMDS_ElemIteratorPtr theItr,
+ const int theShapeID)
+{
+ int nbElem = 0;
+ SMESHDS_Mesh* meshDS = GetMeshDS();
+ while( theItr->more() )
+ {
+ const SMDS_MeshElement* elem = theItr->next();
+ nbElem++;
+ if( elem && elem->IsQuadratic())
+ {
+ int id = elem->GetID();
+ int nbNodes = elem->NbNodes();
+ vector<const SMDS_MeshNode *> aNds, mediumNodes;
+ aNds.reserve( nbNodes );
+ mediumNodes.reserve( nbNodes );
+
+ for(int i = 0; i < nbNodes; i++)
+ {
+ const SMDS_MeshNode* n = elem->GetNode(i);
+
+ if( elem->IsMediumNode( n ) )
+ mediumNodes.push_back( n );
+ else
+ aNds.push_back( n );
+ }
+ if( aNds.empty() ) continue;
+ SMDSAbs_ElementType aType = elem->GetType();
+
+ //remove old quadratic element
+ meshDS->SMDS_Mesh::RemoveFreeElement( elem );
+ if ( theSm )
+ theSm->RemoveElement( elem );
+
+ SMDS_MeshElement * NewElem = AddElement( aNds, aType, false, id );
+ if ( NewElem )
+ AddToSameGroups(NewElem, elem, meshDS);
+ if ( NewElem != elem )
+ RemoveElemFromGroups (elem, meshDS);
+ if( theSm && NewElem )
+ theSm->AddElement( NewElem );
+
+ // remove medium nodes
+ vector<const SMDS_MeshNode*>::iterator nIt = mediumNodes.begin();
+ for ( ; nIt != mediumNodes.end(); ++nIt ) {
+ const SMDS_MeshNode* n = *nIt;
+ if ( n->NbInverseElements() == 0 ) {
+ if ( n->GetPosition()->GetShapeId() != theShapeID )
+ meshDS->RemoveFreeNode( n, meshDS->MeshElements
+ ( n->GetPosition()->GetShapeId() ));
+ else
+ meshDS->RemoveFreeNode( n, theSm );
+ }
+ }
+ }
+ }
+ return nbElem;
+}
+
+//=======================================================================
+//function : ConvertFromQuadratic
+//purpose :
+//=======================================================================
+bool SMESH_MeshEditor::ConvertFromQuadratic()
+{
+ int nbCheckedElems = 0;
+ if ( myMesh->HasShapeToMesh() )
+ {
+ if ( SMESH_subMesh *aSubMesh = myMesh->GetSubMeshContaining(myMesh->GetShapeToMesh()))
+ {
+ SMESH_subMeshIteratorPtr smIt = aSubMesh->getDependsOnIterator(true,false);
+ while ( smIt->more() ) {
+ SMESH_subMesh* sm = smIt->next();
+ if ( SMESHDS_SubMesh *smDS = sm->GetSubMeshDS() )
+ nbCheckedElems += removeQuadElem( smDS, smDS->GetElements(), sm->GetId() );
+ }
+ }
+ }
+
+ int totalNbElems =
+ GetMeshDS()->NbEdges() + GetMeshDS()->NbFaces() + GetMeshDS()->NbVolumes();
+ if ( nbCheckedElems < totalNbElems ) // not all elements in submeshes
+ {
+ SMESHDS_SubMesh *aSM = 0;
+ removeQuadElem( aSM, GetMeshDS()->elementsIterator(), 0 );
+ }
+
+ return true;
+}
+