X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_MeshEditor_i.cxx;h=bd08f9d67785800357512b06fb0b24fe07213f70;hp=34f31094000370d775badcc4c79dbb4bb328ae93;hb=5b3023e6cb8002da05c9cbd36fac7ce1b67bc461;hpb=02ac54c6f33c5437c1d2204d704cf3da6fd31a8e diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 34f310940..bd08f9d67 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -285,13 +285,13 @@ namespace MeshEditor_I { SMDS_MeshElement::Filter & filter = *aFilter; if ( aType == SMDSAbs_Node ) - for (int i=0; iFindNode( IDs[i] ); if ( filter( elem )) aMap.insert( aMap.end(), elem ); } else - for (int i=0; iFindElement( IDs[i] ); if ( filter( elem )) aMap.insert( aMap.end(), elem ); @@ -315,7 +315,7 @@ namespace MeshEditor_I { SMESH::long_array_var aElementsId = theObject->GetIDs(); if ( types->length() == 1 && types[0] == SMESH::NODE) { - for(int i = 0; i < aElementsId->length(); i++) + for ( CORBA::ULong i = 0; i < aElementsId->length(); i++ ) if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] )) theNodeSet.insert( theNodeSet.end(), n); } @@ -323,13 +323,13 @@ namespace MeshEditor_I { { SMDS_NodeIteratorPtr nIt = theMeshDS->nodesIterator(); while ( nIt->more( )) - if( const SMDS_MeshElement * elem = nIt->next() ) + if ( const SMDS_MeshElement * elem = nIt->next() ) theNodeSet.insert( elem->begin_nodes(), elem->end_nodes()); } else { - for(int i = 0; i < aElementsId->length(); i++) - if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] )) + for ( CORBA::ULong i = 0; i < aElementsId->length(); i++ ) + if ( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] )) theNodeSet.insert( elem->begin_nodes(), elem->end_nodes()); } } @@ -349,7 +349,7 @@ namespace MeshEditor_I { SMDSAbs_ElementType elemType = (*theElements.begin())->GetType(); bool sameElemType = ( elemType == (*theElements.rbegin())->GetType() ); if ( sameElemType && - theMeshDS->GetMeshInfo().NbElements( elemType ) == theElements.size() ) + theMeshDS->GetMeshInfo().NbElements( elemType ) == (int) theElements.size() ) return; // all the elements are in theElements if ( !sameElemType ) @@ -794,7 +794,7 @@ SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements) list< int > IdList; - for (int i = 0; i < IDsOfElements.length(); i++) + for ( CORBA::ULong i = 0; i < IDsOfElements.length(); i++ ) IdList.push_back( IDsOfElements[i] ); // Update Python script @@ -823,7 +823,7 @@ CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNo initData(); list< int > IdList; - for (int i = 0; i < IDsOfNodes.length(); i++) + for ( CORBA::ULong i = 0; i < IDsOfNodes.length(); i++) IdList.push_back( IDsOfNodes[i] ); // Update Python script @@ -859,9 +859,7 @@ CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes() SMESH::Controls::Filter::GetElementsId( getMeshDS(), predicate, seq ); // remove orphan nodes (if there are any) - list< int > IdList; - for ( int i = 0; i < seq.size(); i++ ) - IdList.push_back( seq[i] ); + list< int > IdList( seq.begin(), seq.end() ); int nbNodesBefore = myMesh->NbNodes(); getEditor().Remove( IdList, true ); @@ -1584,7 +1582,7 @@ CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfEleme SMESH_TRY; initData(); - for (int i = 0; i < IDsOfElements.length(); i++) + for ( CORBA::ULong i = 0; i < IDsOfElements.length(); i++ ) { CORBA::Long index = IDsOfElements[i]; const SMDS_MeshElement * elem = getMeshDS()->FindElement(index); @@ -2273,7 +2271,7 @@ SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements, arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face); set fixedNodes; - for (int i = 0; i < IDsOfFixedNodes.length(); i++) { + for ( CORBA::ULong i = 0; i < IDsOfFixedNodes.length(); i++) { CORBA::Long index = IDsOfFixedNodes[i]; const SMDS_MeshNode * node = aMesh->FindNode(index); if ( node ) @@ -2844,7 +2842,7 @@ SMESH_MeshEditor_i::ExtrusionAlongPathObjects(const SMESH::ListOfIDSources & the if ( !aMeshImp ) return aGroups._retn(); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape ); aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape ); - if ( !aSubMesh || !aSubMesh->GetSubMeshDS() ) + if ( !aSubMesh /*|| !aSubMesh->GetSubMeshDS()*/ ) return aGroups._retn(); } @@ -2866,7 +2864,7 @@ SMESH_MeshEditor_i::ExtrusionAlongPathObjects(const SMESH::ListOfIDSources & the idSourceToSet( theFaces[i], getMeshDS(), elemsNodes[0], SMDSAbs_Face ); list angles; - for (int i = 0; i < theAngles.length(); i++) { + for ( CORBA::ULong i = 0; i < theAngles.length(); i++ ) { angles.push_back( theAngles[i] ); } @@ -4091,7 +4089,7 @@ FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject, TIDSortedNodeSet nodes; idSourceToNodeSet( theObject, getMeshDS(), nodes ); - for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i ) + for ( CORBA::ULong i = 0; i < theExceptSubMeshOrGroups.length(); ++i ) { SMDS_ElemIteratorPtr nodeIt = myMesh_i->GetElements( theExceptSubMeshOrGroups[i], SMESH::NODE ); @@ -4127,7 +4125,7 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN aTPythonDump << this << ".MergeNodes(["; TIDSortedNodeSet setOfNodesToKeep; - for ( int i = 0; i < NodesToKeep.length(); ++i ) + for ( CORBA::ULong i = 0; i < NodesToKeep.length(); ++i ) { prepareIdSource( NodesToKeep[i] ); SMDS_ElemIteratorPtr nodeIt = myMesh_i->GetElements( NodesToKeep[i], SMESH::NODE ); @@ -4136,12 +4134,12 @@ void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfN } ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes; - for (int i = 0; i < GroupsOfNodes.length(); i++) + for ( CORBA::ULong i = 0; i < GroupsOfNodes.length(); i++ ) { const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ]; aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() ); list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back(); - for ( int j = 0; j < aNodeGroup.length(); j++ ) + for ( CORBA::ULong j = 0; j < aNodeGroup.length(); j++ ) { CORBA::Long index = aNodeGroup[ j ]; if ( const SMDS_MeshNode * node = aMesh->FindNode( index )) @@ -4227,11 +4225,11 @@ void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsO ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID; - for (int i = 0; i < GroupsOfElementsID.length(); i++) { + for ( CORBA::ULong i = 0; i < GroupsOfElementsID.length(); i++ ) { const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ]; aListOfListOfElementsID.push_back( list< int >() ); list< int >& aListOfElemsID = aListOfListOfElementsID.back(); - for ( int j = 0; j < anElemsIDGroup.length(); j++ ) { + for ( CORBA::ULong j = 0; j < anElemsIDGroup.length(); j++ ) { CORBA::Long id = anElemsIDGroup[ j ]; aListOfElemsID.push_back( id ); } @@ -4456,7 +4454,7 @@ SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x, SMDSAbs_ElementType( type ), foundElems); res->length( foundElems.size() ); - for ( int i = 0; i < foundElems.size(); ++i ) + for ( size_t i = 0; i < foundElems.size(); ++i ) res[i] = foundElems[i]->GetID(); return res._retn(); @@ -4517,7 +4515,7 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID SMDSAbs_ElementType( type ), foundElems); res->length( foundElems.size() ); - for ( int i = 0; i < foundElems.size(); ++i ) + for ( size_t i = 0; i < foundElems.size(); ++i ) res[i] = foundElems[i]->GetID(); return res._retn(); @@ -4568,6 +4566,7 @@ static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Se RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS ); RETCASE( SEW_BAD_SIDE1_NODES ); RETCASE( SEW_BAD_SIDE2_NODES ); + RETCASE( SEW_INTERNAL_ERROR ); } return SMESH::SMESH_MeshEditor::SEW_OK; } @@ -4641,25 +4640,26 @@ SewCoincidentFreeBorders(const SMESH::CoincidentFreeBorders& freeBorders, CORBA::Short nbSewed = 0; SMESH_MeshAlgos::TFreeBorderVec groups; - SMESH_MeshAlgos::TFreeBorder borderNodes; // triples on nodes for every FreeBorderPart + SMESH_MeshAlgos::TFreeBorder borderNodes; // triples of nodes for every FreeBorderPart - // check the input + // check the input and collect nodes for ( CORBA::ULong i = 0; i < freeBorders.coincidentGroups.length(); ++i ) { + borderNodes.clear(); const SMESH::FreeBordersGroup& aGRP = freeBorders.coincidentGroups[ i ]; for ( CORBA::ULong iP = 0; iP < aGRP.length(); ++iP ) { const SMESH::FreeBorderPart& aPART = aGRP[ iP ]; - if ( aPART.border < 0 || aPART.border >= freeBorders.borders.length() ) + if ( aPART.border < 0 || aPART.border >= (int) freeBorders.borders.length() ) THROW_SALOME_CORBA_EXCEPTION("Invalid FreeBorderPart::border index", SALOME::BAD_PARAM); const SMESH::FreeBorder& aBRD = freeBorders.borders[ aPART.border ]; - if ( aPART.node1 < 0 || aPART.node1 > aBRD.nodeIDs.length() ) + if ( aPART.node1 < 0 || aPART.node1 > (int) aBRD.nodeIDs.length() ) THROW_SALOME_CORBA_EXCEPTION("Invalid FreeBorderPart::node1", SALOME::BAD_PARAM); - if ( aPART.node2 < 0 || aPART.node2 > aBRD.nodeIDs.length() ) + if ( aPART.node2 < 0 || aPART.node2 > (int) aBRD.nodeIDs.length() ) THROW_SALOME_CORBA_EXCEPTION("Invalid FreeBorderPart::node2", SALOME::BAD_PARAM); - if ( aPART.nodeLast < 0 || aPART.nodeLast > aBRD.nodeIDs.length() ) + if ( aPART.nodeLast < 0 || aPART.nodeLast > (int) aBRD.nodeIDs.length() ) THROW_SALOME_CORBA_EXCEPTION("Invalid FreeBorderPart::nodeLast", SALOME::BAD_PARAM); // do not keep these nodes for further sewing as nodes can be removed by the sewing @@ -4672,71 +4672,99 @@ SewCoincidentFreeBorders(const SMESH::CoincidentFreeBorders& freeBorders, THROW_SALOME_CORBA_EXCEPTION("Nonexistent FreeBorderPart::node2", SALOME::BAD_PARAM); if ( !n3 ) THROW_SALOME_CORBA_EXCEPTION("Nonexistent FreeBorderPart::nodeLast", SALOME::BAD_PARAM); + + borderNodes.push_back( n1 ); + borderNodes.push_back( n2 ); + borderNodes.push_back( n3 ); } + groups.push_back( borderNodes ); } - //TIDSortedElemSet dummy; + // SewFreeBorder() can merge nodes, thus nodes stored in 'groups' can become dead; + // to get nodes that replace other nodes during merge we create 0D elements + // on each node and MergeNodes() will replace underlying nodes of 0D elements by + // new ones. - ::SMESH_MeshEditor::Sew_Error res, ok = ::SMESH_MeshEditor::SEW_OK; - for ( CORBA::ULong i = 0; i < freeBorders.coincidentGroups.length(); ++i ) + vector< const SMDS_MeshElement* > tmp0Delems; + for ( size_t i = 0; i < groups.size(); ++i ) { - const SMESH::FreeBordersGroup& aGRP = freeBorders.coincidentGroups[ i ]; - if ( aGRP.length() < 2 ) - continue; - - //int n1bord2, n2bord2; - - bool groupSewed = false; - for ( CORBA::ULong iP = 1; iP < aGRP.length(); ++iP ) + SMESH_MeshAlgos::TFreeBorder& nodes = groups[i]; + for ( size_t iN = 0; iN < nodes.size(); ++iN ) { - const SMESH::FreeBorderPart& aPART_0 = aGRP[ 0 ]; - const SMESH::FreeBorder& aBRD_0 = freeBorders.borders[ aPART_0.border ]; + SMDS_ElemIteratorPtr it0D = nodes[iN]->GetInverseElementIterator(SMDSAbs_0DElement); + if ( it0D->more() ) + tmp0Delems.push_back( it0D->next() ); + else + tmp0Delems.push_back( getMeshDS()->Add0DElement( nodes[iN] )); + } + } - const SMDS_MeshNode* n0 = getMeshDS()->FindNode( aBRD_0.nodeIDs[ aPART_0.node1 ]); - const SMDS_MeshNode* n1 = getMeshDS()->FindNode( aBRD_0.nodeIDs[ aPART_0.node2 ]); - const SMDS_MeshNode* n2 = getMeshDS()->FindNode( aBRD_0.nodeIDs[ aPART_0.nodeLast ]); + // cout << endl << "INIT" << endl; + // for ( size_t i = 0; i < tmp0Delems.size(); ++i ) + // { + // cout << i << " "; + // if ( i % 3 == 0 ) cout << "^ "; + // tmp0Delems[i]->GetNode(0)->Print( cout ); + // } - const SMESH::FreeBorderPart& aPART = aGRP[ iP ]; - const SMESH::FreeBorder& aBRD = freeBorders.borders[ aPART.border ]; + SMESH_TRY; - const SMDS_MeshNode* n3 = getMeshDS()->FindNode( aBRD.nodeIDs[ aPART.node1 ]); - const SMDS_MeshNode* n4 = getMeshDS()->FindNode( aBRD.nodeIDs[ aPART.node2 ]); - const SMDS_MeshNode* n5 = getMeshDS()->FindNode( aBRD.nodeIDs[ aPART.nodeLast ]); + ::SMESH_MeshEditor::Sew_Error res, ok = ::SMESH_MeshEditor::SEW_OK; + int i0D = 0; + for ( size_t i = 0; i < groups.size(); ++i ) + { + bool isBordToBord = true; + bool groupSewed = false; + SMESH_MeshAlgos::TFreeBorder& nodes = groups[i]; + for ( size_t iN = 3; iN+2 < nodes.size(); iN += 3 ) + { + const SMDS_MeshNode* n0 = tmp0Delems[ i0D + 0 ]->GetNode( 0 ); + const SMDS_MeshNode* n1 = tmp0Delems[ i0D + 1 ]->GetNode( 0 ); + const SMDS_MeshNode* n2 = tmp0Delems[ i0D + 2 ]->GetNode( 0 ); + + const SMDS_MeshNode* n3 = tmp0Delems[ i0D + 0 + iN ]->GetNode( 0 ); + const SMDS_MeshNode* n4 = tmp0Delems[ i0D + 1 + iN ]->GetNode( 0 ); + const SMDS_MeshNode* n5 = tmp0Delems[ i0D + 2 + iN ]->GetNode( 0 ); if ( !n0 || !n1 || !n2 || !n3 || !n4 || !n5 ) continue; - // if ( iP == 1 ) + // TIDSortedElemSet emptySet, avoidSet; + // if ( !SMESH_MeshAlgos::FindFaceInSet( n0, n1, emptySet, avoidSet)) // { - // n1bord2 = aBRD.nodeIDs[ aPART.node1 ]; - // n2bord2 = aBRD.nodeIDs[ aPART.node2 ]; + // cout << "WRONG 2nd 1" << endl; + // n0->Print( cout ); + // n1->Print( cout ); // } - // else if ( !SMESH_MeshAlgos::FindFaceInSet( n0, n1, dummy, dummy )) + // if ( !SMESH_MeshAlgos::FindFaceInSet( n3, n4, emptySet, avoidSet)) // { - // // a face including n0 and n1 was split; - // // find a new face starting at n0 in order to get a new n1 - // const SMDS_MeshNode* n1test = getMeshDS()->FindNode( n1bord2 ); - // const SMDS_MeshNode* n2test = getMeshDS()->FindNode( n2bord2 ); - // if ( n1test && SMESH_MeshAlgos::FindFaceInSet( n0, n1test, dummy, dummy )) - // n1 = n1test; - // else if ( n2test && SMESH_MeshAlgos::FindFaceInSet( n0, n2test, dummy, dummy )) - // n1 = n2test; - // // else continue; ?????? + // cout << "WRONG 2nd 2" << endl; + // n3->Print( cout ); + // n4->Print( cout ); // } - if ( iP > 1 ) + if ( !isBordToBord ) { n1 = n2; // at border-to-side sewing only last side node (n1) is needed n2 = 0; // and n2 is not used } - // 1st border moves to 2nd res = getEditor().SewFreeBorder( n3, n4, n5 ,// 1st n0 ,n1 ,n2 ,// 2nd - /*2ndIsFreeBorder=*/ iP == 1, + /*2ndIsFreeBorder=*/ isBordToBord, createPolygons, createPolyhedra); groupSewed = ( res == ok ); + + isBordToBord = false; + // cout << endl << "SEWED GROUP " << i << " PART " << iN / 3 << endl; + // for ( size_t t = 0; t < tmp0Delems.size(); ++t ) + // { + // cout << t << " "; + // if ( t % 3 == 0 ) cout << "^ "; + // tmp0Delems[t]->GetNode(0)->Print( cout ); + // } } + i0D += nodes.size(); nbSewed += groupSewed; } @@ -4745,6 +4773,20 @@ SewCoincidentFreeBorders(const SMESH::CoincidentFreeBorders& freeBorders, << createPolygons << ", " << createPolyhedra << " )"; + SMESH_CATCH( SMESH::doNothing ); + + declareMeshModified( /*isReComputeSafe=*/false ); + + // remove tmp 0D elements + SMESH_TRY; + set< const SMDS_MeshElement* > removed0D; + for ( size_t i = 0; i < tmp0Delems.size(); ++i ) + { + if ( removed0D.insert( tmp0Delems[i] ).second ) + getMeshDS()->RemoveFreeElement( tmp0Delems[i], /*sm=*/0, /*fromGroups=*/false ); + } + SMESH_CATCH( SMESH::throwCorbaException ); + return nbSewed; } @@ -5262,7 +5304,7 @@ bool SMESH_MeshEditor_i::idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource, { if ( error ) *error = IDSource_OK; - if ( CORBA::is_nil( theIDSource ) ) + if ( CORBA::is_nil( theIDSource )) { if ( error ) *error = IDSource_INVALID; return false; @@ -6457,7 +6499,7 @@ void SMESH_MeshEditor_i::CreateHoleSkin(CORBA::Double radius, theNodeSearcher = SMESH_MeshAlgos::GetNodeSearcher( *getMeshDS() ); vector nodesCoords; - for (int i = 0; i < theNodesCoords.length(); i++) + for ( CORBA::ULong i = 0; i < theNodesCoords.length(); i++) { nodesCoords.push_back( theNodesCoords[i] ); } @@ -6623,7 +6665,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, groupsOfThisMesh ->length( groups.length() ); groupsOfOtherMesh->length( groups.length() ); int nbGroups = 0, nbGroupsOfOtherMesh = 0; - for ( int i = 0; i < groups.length(); ++i ) + for ( CORBA::ULong i = 0; i < groups.length(); ++i ) { SMESH::SMESH_Mesh_var m = groups[i]->GetMesh(); if ( myMesh_i != SMESH::DownCast( m ))