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=9ca11239b8daa1167a563fd2ee3cc978b1cb3136;hp=d7afbed39f5ec69c7c73eefbbf905161daf70672;hb=441a2df90cb97ea7d035771a49e28dc53469e3d6;hpb=47e876676d669fed6615392e614a3ff4441a57ef diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index d7afbed39..9ca11239b 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -42,7 +42,6 @@ #include "SMDS_Mesh0DElement.hxx" #include "SMDS_MeshFace.hxx" #include "SMDS_MeshVolume.hxx" -#include "SMDS_PolyhedralVolumeOfNodes.hxx" #include "SMDS_SetIterator.hxx" #include "SMDS_VolumeTool.hxx" #include "SMESHDS_Group.hxx" @@ -102,7 +101,7 @@ namespace MeshEditor_I { SMDSAbs_ElementType myPreviewType; // type to show //!< Constructor TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) { - _isShapeToMesh = (_id =_studyId = 0); + _isShapeToMesh = (_id = 0); _myMeshDS = new SMESHDS_Mesh( _id, true ); myPreviewType = previewElements; } @@ -179,7 +178,7 @@ namespace MeshEditor_I { //============================================================================= /*! - * \brief Deleter of theNodeSearcher at any compute event occurred + * \brief Deleter of theNodeSearcher and theElementSearcher at any compute event occurred */ //============================================================================= @@ -382,7 +381,7 @@ namespace MeshEditor_I { */ //================================================================================ - string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type) + string getPartIOR( SMESH::SMESH_IDSource_ptr theMeshPart, SMESH::ElementType type = SMESH::ALL ) { string partIOR = SMESH_Gen_i::GetORB()->object_to_string( theMeshPart ); if ( SMESH_Group_i* group_i = SMESH::DownCast( theMeshPart )) @@ -534,7 +533,9 @@ SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData() SMESHDS_Mesh* aMeshDS; std::unique_ptr< SMESH_MeshPartDS > aMeshPartDS; if ( hasBadElems ) { - aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements )); + const list& badElems = + static_cast( getEditor().GetError().get() )->myBadElements; + aMeshPartDS.reset( new SMESH_MeshPartDS( badElems )); aMeshDS = aMeshPartDS.get(); } else { @@ -680,7 +681,7 @@ SMESH::ComputeError* SMESH_MeshEditor_i::GetLastError() errOut->code = -( errIn->myName < 0 ? errIn->myName + 1: errIn->myName ); // -1 -> 0 errOut->comment = errIn->myComment.c_str(); errOut->subShapeID = -1; - errOut->hasBadMesh = !errIn->myBadElements.empty(); + errOut->hasBadMesh = errIn->HasBadElems(); } else { @@ -2596,7 +2597,7 @@ namespace MeshEditor_I * \param [in] nbOfSteps - number of elements to generate from one element * \param [in] toMakeGroups - if true, new elements will be included into new groups * corresponding to groups the input elements included in. - * \return ListOfGroups - new groups craeted if \a toMakeGroups is true + * \return ListOfGroups - new groups created if \a toMakeGroups is true */ //======================================================================= @@ -4033,6 +4034,7 @@ SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject, SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theObject, CORBA::Double theValue, CORBA::Boolean theCopyGroups, + CORBA::Boolean theCopyElements, const char* theMeshName, SMESH::ListOfGroups_out theGroups) throw (SALOME::SALOME_Exception) @@ -4058,7 +4060,9 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theO TPreviewMesh * tmpMesh = getPreviewMesh(); tgtMesh = tmpMesh; tmpMesh->Copy( elements, copyElements ); + elements.swap( copyElements ); theCopyGroups = false; + theCopyElements = false; } else { @@ -4067,26 +4071,38 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theO SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh_var ); tgtMesh = & mesh_i->GetImpl(); } - groupIds = getEditor().Offset( elements, theValue, tgtMesh, theCopyGroups, !myIsPreviewMode ); + groupIds = getEditor().Offset( elements, theValue, tgtMesh, + theCopyGroups, theCopyElements, !myIsPreviewMode ); tgtMesh->GetMeshDS()->Modified(); } if ( myIsPreviewMode ) { - getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements )); + //getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements )); } else { theGroups = theCopyGroups ? getGroups( groupIds.get() ) : new SMESH::ListOfGroups; + if ( *theMeshName && mesh_var->NbFaces() == 0 ) + { + // new mesh empty, remove it + SALOMEDS::Study_var study = SMESH_Gen_i::getStudyServant(); + SALOMEDS::StudyBuilder_var builder = study->NewBuilder(); + SALOMEDS::SObject_wrap meshSO = SMESH_Gen_i::ObjectToSObject( mesh_var ); + builder->RemoveObjectWithChildren( meshSO ); + THROW_SALOME_CORBA_EXCEPTION("Offset failed", SALOME::INTERNAL_ERROR); + } + // result of Offset() is a tuple (mesh, groups) if ( mesh_var->_is_nil() ) pyDump << myMesh_i->_this() << ", "; else pyDump << mesh_var << ", "; - pyDump << theGroups << " = " - << this << ".Offset( " + pyDump << theGroups << " = " << this << ".Offset( " + << theObject << ", " << theValue << ", " << theCopyGroups << ", " + << theCopyElements << ", " << "'" << theMeshName<< "')"; } @@ -4178,7 +4194,7 @@ FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject, //================================================================================ /*! - * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within + * \brief Finds nodes coincident with Tolerance within Object excluding nodes within * ExceptSubMeshOrGroups */ //================================================================================ @@ -4636,6 +4652,68 @@ SMESH_MeshEditor_i::FindAmongElementsByPoint(SMESH::SMESH_IDSource_ptr elementID return 0; } +//======================================================================= +//function : ProjectPoint +//purpose : Project a point to a mesh object. +// Return ID of an element of given type where the given point is projected +// and coordinates of the projection point. +// In the case if nothing found, return -1 and [] +//======================================================================= + +CORBA::Long SMESH_MeshEditor_i::ProjectPoint(CORBA::Double x, + CORBA::Double y, + CORBA::Double z, + SMESH::SMESH_IDSource_ptr meshObject, + SMESH::ElementType type, + SMESH::double_array_out projecton) + throw (SALOME::SALOME_Exception) +{ + if ( CORBA::is_nil( meshObject )) + THROW_SALOME_CORBA_EXCEPTION("NULL meshObject", SALOME::BAD_PARAM); + + SMESH_TRY; + + SMESH::SMESH_Mesh_var mesh = meshObject->GetMesh(); + SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh ); + if ( mesh_i != myMesh_i ) + { + SMESH::SMESH_MeshEditor_var editor= + myIsPreviewMode ? mesh_i->GetMeshEditPreviewer() : mesh_i->GetMeshEditor(); + return editor->ProjectPoint( x,y,z, meshObject, type, projecton ); + } + + + theSearchersDeleter.Set( myMesh, getPartIOR( meshObject )); + if ( !theElementSearcher ) + { + // create a searcher from meshObject + + SMDS_ElemIteratorPtr elemIt; + if ( ! SMESH::DownCast( meshObject )) + elemIt = myMesh_i->GetElements( meshObject, type ); + + theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS(), elemIt ); + } + + const SMDS_MeshElement* elem = 0; + gp_XYZ pProj = theElementSearcher->Project( gp_Pnt( x,y,z ), + SMDSAbs_ElementType( type ), + &elem ); + + projecton = new SMESH::double_array(); + if ( elem && !elem->IsNull() ) + { + projecton->length( 3 ); + projecton[0] = pProj.X(); + projecton[1] = pProj.Y(); + projecton[2] = pProj.Z(); + return elem->GetID(); + } + + SMESH_CATCH( SMESH::throwCorbaException ); + return -1; +} + //======================================================================= //function : GetPointState //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration. @@ -4735,7 +4813,9 @@ SMESH::ListOfFreeBorders* SMESH_MeshEditor_i::FindFreeBorders(CORBA::Boolean clo //purpose : Fill with 2D elements a hole defined by a FreeBorder. //======================================================================= -void SMESH_MeshEditor_i::FillHole(const SMESH::FreeBorder& theHole) +SMESH::SMESH_Group_ptr +SMESH_MeshEditor_i::FillHole(const SMESH::FreeBorder& theHole, + const char* theGroupName) throw (SALOME::SALOME_Exception) { initData(); @@ -4758,6 +4838,7 @@ void SMESH_MeshEditor_i::FillHole(const SMESH::FreeBorder& theHole) SMESH_TRY; + // prepare a preview mesh MeshEditor_I::TPreviewMesh* previewMesh = 0; SMDS_Mesh* meshDS = getMeshDS(); if ( myIsPreviewMode ) @@ -4780,26 +4861,66 @@ void SMESH_MeshEditor_i::FillHole(const SMESH::FreeBorder& theHole) meshDS = previewMesh->GetMeshDS(); } + // fill the hole std::vector newFaces; SMESH_MeshAlgos::FillHole( bordNodes, *meshDS, newFaces ); if ( myIsPreviewMode ) { + // show new faces previewMesh->Clear(); for ( size_t i = 0; i < newFaces.size(); ++i ) previewMesh->Copy( newFaces[i] ); } else { + // return new faces via a group + SMESH::SMESH_Group_var group; + if ( theGroupName && theGroupName[0] && !newFaces.empty() ) + { + SMESH::ListOfGroups_var groups = myMesh_i->GetGroups(); + for ( CORBA::ULong i = 0; i < groups->length(); ++i ) + { + SMESH::SMESH_GroupBase_var g = groups[ i ]; + if ( g->GetType() != SMESH::FACE ) continue; + SMESH::SMESH_Group_var standalone = SMESH::SMESH_Group::_narrow( g ); + if ( standalone->_is_nil() ) continue; + CORBA::String_var name = g->GetName(); + if ( strcmp( theGroupName, name.in() ) == 0 ) + { + group = standalone; + break; + } + } + if ( group->_is_nil() ) + group = myMesh_i->CreateGroup( SMESH::FACE, theGroupName ); + + if ( !group->_is_nil() ) + { + SMESH_GroupBase_i * grpI = SMESH::DownCast< SMESH_GroupBase_i* >( group ); + SMESHDS_Group* grpDS = static_cast< SMESHDS_Group* >( grpI->GetGroupDS() ); + for ( size_t i = 0; i < newFaces.size(); ++i ) + grpDS->Add( newFaces[ i ]); + } + } + + // fill LastCreated getEditor().ClearLastCreated(); SMESH_SequenceOfElemPtr& aSeq = const_cast( getEditor().GetLastCreatedElems() ); aSeq.swap( newFaces ); - TPythonDump() << this << ".FillHole( SMESH.FreeBorder(" << theHole.nodeIDs << " ))"; + TPythonDump pyDump; + if ( group->_is_nil() ) pyDump << "_group = "; + else pyDump << group << " = "; + pyDump << this << ".FillHole( SMESH.FreeBorder(" << theHole.nodeIDs << " ))"; + + return group._retn(); } SMESH_CATCH( SMESH::throwCorbaException ); + + return SMESH::SMESH_Group::_nil(); } //======================================================================= @@ -5475,8 +5596,7 @@ SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName) { SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen(); SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh(); - SALOMEDS::Study_var study = gen->GetCurrentStudy(); - SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( study, mesh ); + SALOMEDS::SObject_wrap meshSO = gen->ObjectToSObject( mesh ); gen->SetName( meshSO, theMeshName, "Mesh" ); gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED"); @@ -6963,7 +7083,7 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, // group of boundary elements SMESH_Group* smesh_group = 0; SMDSAbs_ElementType elemType = (dim == SMESH::BND_2DFROM3D) ? SMDSAbs_Volume : SMDSAbs_Face; - if ( strlen(groupName) ) + if ( strlen( groupName )) { SMESH::ElementType groupType = SMESH::ElementType( int(elemType)-1 ); group_var = mesh_i->CreateGroup( groupType, groupName ); @@ -7104,15 +7224,15 @@ void SMESH_MeshEditor_i::MakePolyLine(SMESH::ListOfPolySegments& theSegments, segOut.myNode2[0] = meshDS->FindNode( segIn.node1ID2 ); segOut.myNode1[1] = meshDS->FindNode( segIn.node2ID1 ); segOut.myNode2[1] = meshDS->FindNode( segIn.node2ID2 ); + segOut.myXYZ[0].SetCoord( segIn.xyz1.x, + segIn.xyz1.y, + segIn.xyz1.z); + segOut.myXYZ[1].SetCoord( segIn.xyz2.x, + segIn.xyz2.y, + segIn.xyz2.z); segOut.myVector.SetCoord( segIn.vector.PS.x, segIn.vector.PS.y, segIn.vector.PS.z ); - if ( !segOut.myNode1[0] ) - THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid node ID: ") << segIn.node1ID1, - SALOME::BAD_PARAM ); - if ( !segOut.myNode1[1] ) - THROW_SALOME_CORBA_EXCEPTION( SMESH_Comment( "Invalid node ID: ") << segIn.node2ID1, - SALOME::BAD_PARAM ); } // get a static ElementSearcher