+ prepareIdSource( elementIDs );
+ if ( type != SMESH::NODE )
+ {
+ SMESH::array_of_ElementType_var types = elementIDs->GetTypes();
+ if ( types->length() == 1 && // a part contains only nodes or 0D elements
+ ( types[0] == SMESH::NODE || types[0] == SMESH::ELEM0D || types[0] == SMESH::BALL) &&
+ type != types[0] ) // but search of elements of dim > 0
+ return res._retn();
+ }
+
+ SMESH::SMESH_Mesh_var mesh = elementIDs->GetMesh();
+ SMESH_Mesh_i* mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
+ if ( mesh_i != myMesh_i )
+ {
+ SMESH::SMESH_MeshEditor_var editor=
+ myIsPreviewMode ? mesh_i->GetMeshEditPreviewer() : mesh_i->GetMeshEditor();
+ return editor->FindAmongElementsByPoint( elementIDs, x,y,z, type );
+ }
+
+ if ( SMESH::DownCast<SMESH_Mesh_i*>( elementIDs )) // elementIDs is the whole mesh
+ return FindElementsByPoint( x,y,z, type );
+
+ TIDSortedElemSet elements; // elems should live until FindElementsByPoint() finishes
+
+ theSearchersDeleter.Set( myMesh, getPartIOR( elementIDs, type ));
+ if ( !theElementSearcher )
+ {
+ // create a searcher from elementIDs
+ SMDS_ElemIteratorPtr elemIt;
+ if ( ! SMESH::DownCast<SMESH_Mesh_i*>( elementIDs ))
+ {
+ //prepareIdSource( elementIDs );
+ elemIt = myMesh_i->GetElements( elementIDs, type );
+ if ( !elemIt )
+ return res._retn();
+ }
+ theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS(), elemIt );
+ }
+
+ vector< const SMDS_MeshElement* > foundElems;
+
+ theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
+ SMDSAbs_ElementType( type ),
+ foundElems);
+ res->length( foundElems.size() );
+ for ( size_t i = 0; i < foundElems.size(); ++i )
+ res[i] = foundElems[i]->GetID();
+
+ return res._retn();
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+ 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::ElementType type,
+ SMESH::SMESH_IDSource_ptr meshObject,
+ SMESH::double_array_out projecton)
+{
+ 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<SMESH_Mesh_i*>( mesh );
+ if ( mesh_i != myMesh_i )
+ {
+ SMESH::SMESH_MeshEditor_var editor=
+ myIsPreviewMode ? mesh_i->GetMeshEditPreviewer() : mesh_i->GetMeshEditor();
+ return editor->ProjectPoint( x,y,z, type, meshObject, projecton );
+ }
+
+
+ theSearchersDeleter.Set( myMesh, getPartIOR( meshObject, type ));
+ if ( !theElementSearcher )
+ {
+ // create a searcher from meshObject
+
+ SMDS_ElemIteratorPtr elemIt;
+ if ( ! SMESH::DownCast<SMESH_Mesh_i*>( meshObject ))
+ {
+ prepareIdSource( meshObject );
+ elemIt = myMesh_i->GetElements( meshObject, type );
+ if ( !elemIt )
+ return -1;
+ }
+ 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.
+// TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
+//=======================================================================
+
+CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
+ CORBA::Double y,
+ CORBA::Double z)
+{
+ SMESH_TRY;
+ theSearchersDeleter.Set( myMesh );
+ if ( !theElementSearcher ) {
+ theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() );
+ }
+ return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+ return 0;
+}
+
+//=======================================================================
+//function : IsManifold
+//purpose : Check if a 2D mesh is manifold
+//=======================================================================
+
+CORBA::Boolean SMESH_MeshEditor_i::IsManifold()
+{
+ bool isManifold = true;
+
+ SMESH_TRY;
+ SMESH_MeshAlgos::TFreeBorderVec foundFreeBordes;
+ SMESH_MeshAlgos::FindFreeBorders( *getMeshDS(),
+ foundFreeBordes,
+ /*closedOnly=*/true,
+ &isManifold );
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return isManifold;
+}
+
+//=======================================================================
+//function : IsCoherentOrientation2D
+//purpose : Check if orientation of 2D elements is coherent
+//=======================================================================
+
+CORBA::Boolean SMESH_MeshEditor_i::IsCoherentOrientation2D()
+{
+ bool isGoodOri = true;
+
+ SMESH_TRY;
+ SMESH_MeshAlgos::TFreeBorderVec foundFreeBordes;
+ SMESH_MeshAlgos::FindFreeBorders( *getMeshDS(),
+ foundFreeBordes,
+ /*closedOnly=*/true,
+ /*isManifold=*/0,
+ &isGoodOri);
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return isGoodOri;
+}
+
+//=======================================================================
+//function : Get1DBranches
+//purpose : Partition given 1D elements into groups of contiguous edges.
+// A node where number of meeting edges != 2 is a group end.
+// An optional startNode is used to orient groups it belongs to.
+//return : a list of edge groups and a list of corresponding node groups.
+// If a group is closed, the first and last nodes of the group are same.
+//=======================================================================
+
+SMESH::array_of_long_array*
+SMESH_MeshEditor_i::Get1DBranches( SMESH::SMESH_IDSource_ptr theEdges,
+ CORBA::Long theStartNode,
+ SMESH::array_of_long_array_out theNodeGroups )
+{
+ if ( CORBA::is_nil( theEdges ))
+ THROW_SALOME_CORBA_EXCEPTION("Get1DBranches(): NULL group given", SALOME::BAD_PARAM);
+
+ SMESH::array_of_long_array_var edgeGroupArray = new SMESH::array_of_long_array;
+ theNodeGroups = new SMESH::array_of_long_array;
+
+ SMESH_TRY;
+
+ prepareIdSource( theEdges );
+
+ SMESH_MeshAlgos::TElemGroupVector edgeBranches;
+ SMESH_MeshAlgos::TNodeGroupVector nodeBranches;
+ SMESH_MeshAlgos::Get1DBranches( SMESH_Mesh_i::GetElements( theEdges, SMESH::EDGE ),
+ edgeBranches,
+ nodeBranches,
+ getMeshDS()->FindNode( theStartNode ));
+
+ edgeGroupArray->length( edgeBranches.size() );
+ for ( size_t iG = 0; iG < edgeBranches.size(); ++iG )
+ {
+ edgeGroupArray[ iG ].length( edgeBranches[ iG ].size() );
+ for ( size_t i = 0; i < edgeBranches[ iG ].size(); ++i )
+ edgeGroupArray[ iG ][ i ] = edgeBranches[ iG ][ i ]->GetID();
+ }
+
+ theNodeGroups->length( nodeBranches.size() );
+ for ( size_t iG = 0; iG < nodeBranches.size(); ++iG )
+ {
+ theNodeGroups[ iG ].length( nodeBranches[ iG ].size() );
+ for ( size_t i = 0; i < nodeBranches[ iG ].size(); ++i )
+ theNodeGroups[ iG ][ i ] = nodeBranches[ iG ][ i ]->GetID();
+ }
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return edgeGroupArray._retn();
+}
+
+//=======================================================================
+//function : FindSharpEdges
+//purpose : Return sharp edges of faces and non-manifold ones. Optionally add existing edges.
+//=======================================================================
+
+SMESH::ListOfEdges* SMESH_MeshEditor_i::FindSharpEdges(CORBA::Double theAngle,
+ CORBA::Boolean theAddExisting)
+{
+ SMESH::ListOfEdges_var resultEdges = new SMESH::ListOfEdges;
+ SMESH_TRY;
+
+ initData();
+
+ std::vector< SMESH_MeshAlgos::Edge > edges =
+ SMESH_MeshAlgos::FindSharpEdges( getMeshDS(), theAngle, theAddExisting );
+
+ if ( myIsPreviewMode ) // fill a preview mesh with edges
+ {
+ TPreviewMesh* mesh = getPreviewMesh( SMDSAbs_Edge );
+ SMDS_Mesh* meshDS = mesh->GetMeshDS();
+ for ( size_t i = 0; i < edges.size(); ++i )
+ {
+ SMESH_NodeXYZ xyz1( edges[i]._node1), xyz2( edges[i]._node2);
+ SMDS_MeshNode* n1 = meshDS->AddNode( xyz1.X(), xyz1.Y(), xyz1.Z() );
+ SMDS_MeshNode* n2 = meshDS->AddNode( xyz2.X(), xyz2.Y(), xyz2.Z() );
+ if ( edges[i]._medium )
+ {
+ xyz1.Set( edges[i]._medium );
+ SMDS_MeshNode* nm = meshDS->AddNode( xyz1.X(), xyz1.Y(), xyz1.Z() );
+ mesh->GetMeshDS()->AddEdge( n1, n2, nm );
+ }
+ else
+ {
+ mesh->GetMeshDS()->AddEdge( n1, n2 );
+ }
+ }
+ }
+ else
+ {
+ resultEdges->length( edges.size() );
+ for ( size_t i = 0; i < edges.size(); ++i )
+ {
+ resultEdges[ i ].node1 = edges[i]._node1->GetID();
+ resultEdges[ i ].node2 = edges[i]._node2->GetID();
+ resultEdges[ i ].medium = edges[i]._medium ? edges[i]._medium->GetID() : 0;
+ }
+ }
+ SMESH_CATCH( SMESH::throwCorbaException );
+ return resultEdges._retn();
+}
+
+//=======================================================================
+//function : FindFreeBorders
+//purpose : Returns all or only closed FreeBorder's.
+//=======================================================================
+
+SMESH::ListOfFreeBorders* SMESH_MeshEditor_i::FindFreeBorders(CORBA::Boolean closedOnly)
+{
+ SMESH::ListOfFreeBorders_var resBorders = new SMESH::ListOfFreeBorders;
+ SMESH_TRY;
+
+ SMESH_MeshAlgos::TFreeBorderVec foundFreeBordes;
+ SMESH_MeshAlgos::FindFreeBorders( *getMeshDS(), foundFreeBordes, closedOnly );
+
+ resBorders->length( foundFreeBordes.size() );
+ for ( size_t i = 0; i < foundFreeBordes.size(); ++i )
+ {
+ const SMESH_MeshAlgos::TFreeBorder& bordNodes = foundFreeBordes[i];
+ SMESH::FreeBorder& bordOut = resBorders[i];
+ bordOut.nodeIDs.length( bordNodes.size() );
+ for ( size_t iN = 0; iN < bordNodes.size(); ++iN )
+ bordOut.nodeIDs[ iN ] = bordNodes[ iN ]->GetID();
+ }
+
+ SMESH_CATCH( SMESH::throwCorbaException );
+
+ return resBorders._retn();
+}
+
+//=======================================================================
+//function : FillHole
+//purpose : Fill with 2D elements a hole defined by a FreeBorder.
+//=======================================================================