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=d7afbed39f5ec69c7c73eefbbf905161daf70672;hp=6dfd0d61efad2b128085bfbe0c14785ef70580a1;hb=47e876676d669fed6615392e614a3ff4441a57ef;hpb=0cba9cf88f4fda1d95ea3184e91aa99bfdb5e1f8 diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 6dfd0d61e..d7afbed39 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -64,7 +64,6 @@ #include #include #include -#include #include #include @@ -76,15 +75,8 @@ #include #include -#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 -#define NO_CAS_CATCH -#endif - #include - -#ifdef NO_CAS_CATCH #include -#endif #include #include @@ -173,7 +165,10 @@ namespace MeshEditor_I { } void Remove( SMDSAbs_ElementType type ) { - SMDS_ElemIteratorPtr eIt = GetMeshDS()->elementsIterator( type ); + Remove( GetMeshDS()->elementsIterator( type )); + } + void Remove( SMDS_ElemIteratorPtr eIt ) + { while ( eIt->more() ) GetMeshDS()->RemoveFreeElement( eIt->next(), /*sm=*/0, /*fromGroups=*/false ); } @@ -530,14 +525,14 @@ SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData() SMESH_TRY; const bool hasBadElems = ( getEditor().GetError() && getEditor().GetError()->HasBadElems() ); - if ( myIsPreviewMode || hasBadElems ) { // --- MeshPreviewStruct filling --- - + if ( myIsPreviewMode || hasBadElems ) + { list aNodesConnectivity; typedef map TNodesMap; TNodesMap nodesMap; SMESHDS_Mesh* aMeshDS; - std::auto_ptr< SMESH_MeshPartDS > aMeshPartDS; + std::unique_ptr< SMESH_MeshPartDS > aMeshPartDS; if ( hasBadElems ) { aMeshPartDS.reset( new SMESH_MeshPartDS( getEditor().GetError()->myBadElements )); aMeshDS = aMeshPartDS.get(); @@ -623,9 +618,9 @@ SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes() SMESH::long_array_var myLastCreatedNodes = new SMESH::long_array(); const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedNodes(); - myLastCreatedNodes->length( aSeq.Length() ); - for (int i = 1; i <= aSeq.Length(); i++) - myLastCreatedNodes[i-1] = aSeq.Value(i)->GetID(); + myLastCreatedNodes->length( aSeq.size() ); + for ( size_t i = 0; i < aSeq.size(); i++) + myLastCreatedNodes[i] = aSeq[i]->GetID(); return myLastCreatedNodes._retn(); SMESH_CATCH( SMESH::throwCorbaException ); @@ -646,9 +641,9 @@ SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems() SMESH::long_array_var myLastCreatedElems = new SMESH::long_array(); const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems(); - myLastCreatedElems->length( aSeq.Length() ); - for ( int i = 1; i <= aSeq.Length(); i++ ) - myLastCreatedElems[i-1] = aSeq.Value(i)->GetID(); + myLastCreatedElems->length( aSeq.size() ); + for ( size_t i = 0; i < aSeq.size(); i++ ) + myLastCreatedElems[i] = aSeq[i]->GetID(); return myLastCreatedElems._retn(); SMESH_CATCH( SMESH::throwCorbaException ); @@ -2021,7 +2016,7 @@ CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr th //============================================================================= /*! * Find better splitting of the given quadrangle. - * \param IDOfQuad ID of the quadrangle to be splitted. + * \param IDOfQuad ID of the quadrangle to be split. * \param Criterion A criterion to choose a diagonal for splitting. * \return 1 if 1-3 diagonal is better, 2 if 2-4 * diagonal is better, 0 if error occurs. @@ -3890,7 +3885,6 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, }; gp_Trsf aTrsf; -#if OCC_VERSION_LARGE > 0x06070100 // fight against orthogonalization // aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]), // 0, S[1], 0, thePoint.y * (1-S[1]), @@ -3903,13 +3897,6 @@ SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject, thePoint.z * (1-S[2])); M.SetDiagonal( S[0], S[1], S[2] ); -#else - double tol = std::numeric_limits::max(); - aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]), - 0, S[1], 0, thePoint.y * (1-S[1]), - 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol); -#endif - TIDSortedElemSet copyElements; TIDSortedElemSet* workElements = &elements; if ( myIsPreviewMode ) @@ -4006,7 +3993,7 @@ SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject, // and then "GetGroups" using SMESH_Mesh::GetGroups() TPythonDump pydump; // to prevent dump at mesh creation - mesh = makeMesh( theMeshName ); + mesh = makeMesh( theMeshName ); mesh_i = SMESH::DownCast( mesh ); if ( mesh_i ) @@ -4030,6 +4017,84 @@ SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject, return mesh._retn(); } +//================================================================================ +/*! + * \brief Make an offset mesh from a source 2D mesh + * \param [inout] theObject - source mesh. New elements are added to this mesh + * if \a theMeshName is empty. + * \param [in] theValue - offset value + * \param [in] theCopyGroups - to generate groups + * \param [in] theMeshName - optional name of a new mesh + * \param [out] theGroups - new groups + * \return SMESH::SMESH_Mesh_ptr - the modified mesh + */ +//================================================================================ + +SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::Offset( SMESH::SMESH_IDSource_ptr theObject, + CORBA::Double theValue, + CORBA::Boolean theCopyGroups, + const char* theMeshName, + SMESH::ListOfGroups_out theGroups) + throw (SALOME::SALOME_Exception) +{ + SMESH_TRY; + initData(); + + SMESHDS_Mesh* aMeshDS = getMeshDS(); + + SMESH::SMESH_Mesh_var mesh_var; + ::SMESH_MeshEditor::PGroupIDs groupIds; + + TPythonDump pyDump; + + TIDSortedElemSet elements, copyElements; + if ( idSourceToSet( theObject, aMeshDS, elements, SMDSAbs_Face, + /*emptyIfIsMesh=*/ !myIsPreviewMode )) + { + // mesh to modify + SMESH_Mesh* tgtMesh = 0; + if ( myIsPreviewMode ) + { + TPreviewMesh * tmpMesh = getPreviewMesh(); + tgtMesh = tmpMesh; + tmpMesh->Copy( elements, copyElements ); + theCopyGroups = false; + } + else + { + mesh_var = + *theMeshName ? makeMesh( theMeshName ) : SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() ); + SMESH_Mesh_i* mesh_i = SMESH::DownCast( mesh_var ); + tgtMesh = & mesh_i->GetImpl(); + } + groupIds = getEditor().Offset( elements, theValue, tgtMesh, theCopyGroups, !myIsPreviewMode ); + + tgtMesh->GetMeshDS()->Modified(); + } + + if ( myIsPreviewMode ) + { + getPreviewMesh()->Remove( SMESHUtils::elemSetIterator( copyElements )); + } + else + { + theGroups = theCopyGroups ? getGroups( groupIds.get() ) : new SMESH::ListOfGroups; + + // 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( " + << theValue << ", " + << theCopyGroups << ", " + << "'" << theMeshName<< "')"; + } + + return mesh_var._retn(); + + SMESH_CATCH( SMESH::throwCorbaException ); + return SMESH::SMESH_Mesh::_nil(); +} //======================================================================= //function : findCoincidentNodes @@ -4593,6 +4658,150 @@ CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x, return 0; } +//======================================================================= +//function : IsManifold +//purpose : Check if a 2D mesh is manifold +//======================================================================= + +CORBA::Boolean SMESH_MeshEditor_i::IsManifold() + throw (SALOME::SALOME_Exception) +{ + 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() + throw (SALOME::SALOME_Exception) +{ + 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 : FindFreeBorders +//purpose : Returns all or only closed FreeBorder's. +//======================================================================= + +SMESH::ListOfFreeBorders* SMESH_MeshEditor_i::FindFreeBorders(CORBA::Boolean closedOnly) + throw (SALOME::SALOME_Exception) +{ + 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. +//======================================================================= + +void SMESH_MeshEditor_i::FillHole(const SMESH::FreeBorder& theHole) + throw (SALOME::SALOME_Exception) +{ + initData(); + + if ( theHole.nodeIDs.length() < 4 ) + THROW_SALOME_CORBA_EXCEPTION("A hole should be bound by at least 3 nodes", SALOME::BAD_PARAM); + if ( theHole.nodeIDs[0] != theHole.nodeIDs[ theHole.nodeIDs.length()-1 ] ) + THROW_SALOME_CORBA_EXCEPTION("Not closed hole boundary. " + "First and last nodes must be same", SALOME::BAD_PARAM); + + SMESH_MeshAlgos::TFreeBorder bordNodes; + bordNodes.resize( theHole.nodeIDs.length() ); + for ( size_t iN = 0; iN < theHole.nodeIDs.length(); ++iN ) + { + bordNodes[ iN ] = getMeshDS()->FindNode( theHole.nodeIDs[ iN ]); + if ( !bordNodes[ iN ] ) + THROW_SALOME_CORBA_EXCEPTION(SMESH_Comment("Node #") << theHole.nodeIDs[ iN ] + << " does not exist", SALOME::BAD_PARAM); + } + + SMESH_TRY; + + MeshEditor_I::TPreviewMesh* previewMesh = 0; + SMDS_Mesh* meshDS = getMeshDS(); + if ( myIsPreviewMode ) + { + // copy faces sharing nodes of theHole + TIDSortedElemSet holeFaces; + previewMesh = getPreviewMesh( SMDSAbs_Face ); + for ( size_t i = 0; i < bordNodes.size(); ++i ) + { + SMDS_ElemIteratorPtr fIt = bordNodes[i]->GetInverseElementIterator( SMDSAbs_Face ); + while ( fIt->more() ) + { + const SMDS_MeshElement* face = fIt->next(); + if ( holeFaces.insert( face ).second ) + previewMesh->Copy( face ); + } + bordNodes[i] = previewMesh->GetMeshDS()->FindNode( bordNodes[i]->GetID() ); + ASSERT( bordNodes[i] ); + } + meshDS = previewMesh->GetMeshDS(); + } + + std::vector newFaces; + SMESH_MeshAlgos::FillHole( bordNodes, *meshDS, newFaces ); + + if ( myIsPreviewMode ) + { + previewMesh->Clear(); + for ( size_t i = 0; i < newFaces.size(); ++i ) + previewMesh->Copy( newFaces[i] ); + } + else + { + getEditor().ClearLastCreated(); + SMESH_SequenceOfElemPtr& aSeq = + const_cast( getEditor().GetLastCreatedElems() ); + aSeq.swap( newFaces ); + + TPythonDump() << this << ".FillHole( SMESH.FreeBorder(" << theHole.nodeIDs << " ))"; + } + + SMESH_CATCH( SMESH::throwCorbaException ); +} + //======================================================================= //function : convError //purpose : @@ -5400,7 +5609,7 @@ bool SMESH_MeshEditor_i::idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource, * \param theElements - container of elements to duplicate. * \param theGroupName - a name of group to contain the generated elements. * If a group with such a name already exists, the new elements - * are added to the existng group, else a new group is created. + * are added to the existing group, else a new group is created. * If \a theGroupName is empty, new elements are not added * in any group. * \return a group where the new elements are added. NULL if theGroupName == "". @@ -5425,11 +5634,11 @@ SMESH_MeshEditor_i::DoubleElements(SMESH::SMESH_IDSource_ptr theElements, { getEditor().DoubleElements( elems ); - if ( strlen( theGroupName ) && !getEditor().GetLastCreatedElems().IsEmpty() ) + if ( strlen( theGroupName ) && !getEditor().GetLastCreatedElems().empty() ) { // group type SMESH::ElementType type = - SMESH::ElementType( getEditor().GetLastCreatedElems().Value(1)->GetType() ); + SMESH::ElementType( getEditor().GetLastCreatedElems()[0]->GetType() ); // find existing group SMESH::ListOfGroups_var groups = myMesh_i->GetGroups(); for ( size_t i = 0; i < groups->length(); ++i ) @@ -5449,8 +5658,8 @@ SMESH_MeshEditor_i::DoubleElements(SMESH::SMESH_IDSource_ptr theElements, { SMESHDS_Group* groupDS = static_cast< SMESHDS_Group* >( group_i->GetGroupDS() ); const SMESH_SequenceOfElemPtr& aSeq = getEditor().GetLastCreatedElems(); - for ( int i = 1; i <= aSeq.Length(); i++ ) - groupDS->SMDSGroup().Add( aSeq(i) ); + for ( size_t i = 0; i < aSeq.size(); i++ ) + groupDS->SMDSGroup().Add( aSeq[i] ); } } } @@ -5562,10 +5771,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr th if ( !CORBA::is_nil( theModifiedElems ) ) aModifiedElems = theModifiedElems->GetListOfID(); else - { aModifiedElems = new SMESH::long_array; - aModifiedElems->length( 0 ); - } TPythonDump pyDump; // suppress dump by the next line @@ -5944,14 +6150,14 @@ SMESH_MeshEditor_i::DoubleNodeElemGroup2New(SMESH::SMESH_GroupBase_ptr theElems, // Create group with newly created elements CORBA::String_var elemGroupName = theElems->GetName(); std::string aNewName = generateGroupName( std::string(elemGroupName.in()) + "_double"); - if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded ) + if ( !getEditor().GetLastCreatedElems().empty() && theElemGroupNeeded ) { SMESH::long_array_var anIds = GetLastCreatedElems(); SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true); aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); aNewElemGroup->Add(anIds); } - if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded ) + if ( !getEditor().GetLastCreatedNodes().empty() && theNodeGroupNeeded ) { SMESH::long_array_var anIds = GetLastCreatedNodes(); aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); @@ -6176,14 +6382,14 @@ SMESH_MeshEditor_i::DoubleNodeElemGroups2New(const SMESH::ListOfGroups& theElems // Create group with newly created elements CORBA::String_var elemGroupName = theElems[0]->GetName(); std::string aNewName = generateGroupName( std::string(elemGroupName.in()) + "_double"); - if ( !getEditor().GetLastCreatedElems().IsEmpty() && theElemGroupNeeded ) + if ( !getEditor().GetLastCreatedElems().empty() && theElemGroupNeeded ) { SMESH::long_array_var anIds = GetLastCreatedElems(); SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true); aNewElemGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str()); aNewElemGroup->Add(anIds); } - if ( !getEditor().GetLastCreatedNodes().IsEmpty() && theNodeGroupNeeded ) + if ( !getEditor().GetLastCreatedNodes().empty() && theNodeGroupNeeded ) { SMESH::long_array_var anIds = GetLastCreatedNodes(); aNewNodeGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str()); @@ -6278,12 +6484,9 @@ SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theEl { SMESH_TRY; SMESH::ListOfGroups_var aListOfGroups = new SMESH::ListOfGroups(); - bool isEdgeGroup = false; - bool isFaceGroup = false; - bool isVolumeGroup = false; - SMESH::SMESH_Group_var aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, "affectedEdges"); - SMESH::SMESH_Group_var aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, "affectedFaces"); - SMESH::SMESH_Group_var aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, "affectedVolumes"); + SMESH::SMESH_Group_var aNewEdgeGroup = SMESH::SMESH_Group::_nil(); + SMESH::SMESH_Group_var aNewFaceGroup = SMESH::SMESH_Group::_nil(); + SMESH::SMESH_Group_var aNewVolumeGroup = SMESH::SMESH_Group::_nil(); initData(); @@ -6291,75 +6494,75 @@ SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theEl SMESHDS_Mesh* aMeshDS = getMeshDS(); TIDSortedElemSet anElems, aNodes; - listOfGroupToSet(theElems, aMeshDS, anElems, false); + bool isNodeGrp = theElems.length() ? theElems[0]->GetType() == SMESH::NODE : false; + listOfGroupToSet(theElems, aMeshDS, anElems, isNodeGrp); listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true); TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape(theShape); TIDSortedElemSet anAffected; bool aResult = aMeshEditor.AffectedElemGroupsInRegion(anElems, aNodes, aShape, anAffected); - declareMeshModified( /*isReComputeSafe=*/ !aResult ); TPythonDump pyDump; - if (aResult) + if ( aResult && anAffected.size() > 0 ) { - int lg = anAffected.size(); SMESH::long_array_var volumeIds = new SMESH::long_array; - volumeIds->length(lg); - SMESH::long_array_var faceIds = new SMESH::long_array; - faceIds->length(lg); - SMESH::long_array_var edgeIds = new SMESH::long_array; - edgeIds->length(lg); + SMESH::long_array_var faceIds = new SMESH::long_array; + SMESH::long_array_var edgeIds = new SMESH::long_array; + volumeIds->length( anAffected.size() ); + faceIds ->length( anAffected.size() ); + edgeIds ->length( anAffected.size() ); + int ivol = 0; int iface = 0; int iedge = 0; - TIDSortedElemSet::const_iterator eIt = anAffected.begin(); for (; eIt != anAffected.end(); ++eIt) { const SMDS_MeshElement* anElem = *eIt; - if (!anElem) - continue; int elemId = anElem->GetID(); - if (myMesh->GetElementType(elemId, true) == SMDSAbs_Volume) - volumeIds[ivol++] = elemId; - else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Face) - faceIds[iface++] = elemId; - else if (myMesh->GetElementType(elemId, true) == SMDSAbs_Edge) - edgeIds[iedge++] = elemId; + switch ( anElem->GetType() ) { + case SMDSAbs_Volume: volumeIds[ivol++] = elemId; break; + case SMDSAbs_Face: faceIds[iface++] = elemId; break; + case SMDSAbs_Edge: edgeIds[iedge++] = elemId; break; + default:; + } } volumeIds->length(ivol); faceIds->length(iface); edgeIds->length(iedge); - aNewVolumeGroup->Add(volumeIds); - aNewFaceGroup->Add(faceIds); - aNewEdgeGroup->Add(edgeIds); - isVolumeGroup = (aNewVolumeGroup->Size() > 0); - isFaceGroup = (aNewFaceGroup->Size() > 0); - isEdgeGroup = (aNewEdgeGroup->Size() > 0); + int nbGroups = 0; + if ( ivol > 0 ) + { + aNewVolumeGroup = myMesh_i->CreateGroup(SMESH::VOLUME, + generateGroupName("affectedVolumes").c_str()); + aNewVolumeGroup->Add(volumeIds); + aListOfGroups->length( nbGroups+1 ); + aListOfGroups[ nbGroups++ ] = aNewVolumeGroup._retn(); + } + if ( iface > 0 ) + { + aNewFaceGroup = myMesh_i->CreateGroup(SMESH::FACE, + generateGroupName("affectedFaces").c_str()); + aNewFaceGroup->Add(faceIds); + aListOfGroups->length( nbGroups+1 ); + aListOfGroups[ nbGroups++ ] = aNewFaceGroup._retn(); + } + if ( iedge > 0 ) + { + aNewEdgeGroup = myMesh_i->CreateGroup(SMESH::EDGE, + generateGroupName("affectedEdges").c_str()); + aNewEdgeGroup->Add(edgeIds); + aListOfGroups->length( nbGroups+1 ); + aListOfGroups[ nbGroups++ ] = aNewEdgeGroup._retn(); + } } - int nbGroups = 0; - if (isEdgeGroup) nbGroups++; - if (isFaceGroup) nbGroups++; - if (isVolumeGroup) nbGroups++; - aListOfGroups->length(nbGroups); - - int i = 0; - if (isEdgeGroup) aListOfGroups[i++] = aNewEdgeGroup._retn(); - if (isFaceGroup) aListOfGroups[i++] = aNewFaceGroup._retn(); - if (isVolumeGroup) aListOfGroups[i++] = aNewVolumeGroup._retn(); - // Update Python script - pyDump << "[ "; - if (isEdgeGroup) pyDump << aNewEdgeGroup << ", "; - if (isFaceGroup) pyDump << aNewFaceGroup << ", "; - if (isVolumeGroup) pyDump << aNewVolumeGroup << ", "; - pyDump << "] = "; - pyDump << this << ".AffectedElemGroupsInRegion( " + pyDump << aListOfGroups << " = " << this << ".AffectedElemGroupsInRegion( " << &theElems << ", " << &theNodesNot << ", " << theShape << " )"; return aListOfGroups._retn(); @@ -6371,7 +6574,7 @@ SMESH_MeshEditor_i::AffectedElemGroupsInRegion( const SMESH::ListOfGroups& theEl //================================================================================ /*! \brief Generated skin mesh (containing 2D cells) from 3D mesh - The created 2D mesh elements based on nodes of free faces of boundary volumes + The created 2D mesh elements based on nodes of free faces of boundary volumes \return TRUE if operation has been completed successfully, FALSE otherwise */ //================================================================================ @@ -6828,3 +7031,130 @@ CORBA::Long SMESH_MeshEditor_i::MakeBoundaryElements(SMESH::Bnd_Dimension dim, SMESH_CATCH( SMESH::throwCorbaException ); return 0; } + +//================================================================================ +/*! + * \brief Create a polyline consisting of 1D mesh elements each lying on a 2D element of + * the initial mesh. Positions of new nodes are found by cutting the mesh by the + * plane passing through pairs of points specified by each PolySegment structure. + * If there are several paths connecting a pair of points, the shortest path is + * selected by the module. Position of the cutting plane is defined by the two + * points and an optional vector lying on the plane specified by a PolySegment. + * By default the vector is defined by Mesh module as following. A middle point + * of the two given points is computed. The middle point is projected to the mesh. + * The vector goes from the middle point to the projection point. In case of planar + * mesh, the vector is normal to the mesh. + * \param [inout] segments - PolySegment's defining positions of cutting planes. + * Return the used vector and position of the middle point. + * \param [in] groupName - optional name of a group where created mesh segments will + * be added. + */ +//================================================================================ + +void SMESH_MeshEditor_i::MakePolyLine(SMESH::ListOfPolySegments& theSegments, + const char* theGroupName) + throw (SALOME::SALOME_Exception) +{ + if ( theSegments.length() == 0 ) + THROW_SALOME_CORBA_EXCEPTION("No segments given", SALOME::BAD_PARAM ); + if ( myMesh->NbFaces() == 0 ) + THROW_SALOME_CORBA_EXCEPTION("No faces in the mesh", SALOME::BAD_PARAM ); + + SMESH_TRY; + initData(/*deleteSearchers=*/false); + + SMESHDS_Group* groupDS = 0; + SMESHDS_Mesh* meshDS = getMeshDS(); + if ( myIsPreviewMode ) // copy faces to the tmp mesh + { + TPreviewMesh * tmpMesh = getPreviewMesh( SMDSAbs_Edge ); + SMDS_ElemIteratorPtr faceIt = getMeshDS()->elementsIterator( SMDSAbs_Face ); + while ( faceIt->more() ) + tmpMesh->Copy( faceIt->next() ); + meshDS = tmpMesh->GetMeshDS(); + } + else if ( theGroupName[0] ) // find/create a group of segments + { + SMESH_Mesh::GroupIteratorPtr grpIt = myMesh->GetGroups(); + while ( !groupDS && grpIt->more() ) + { + SMESH_Group* group = grpIt->next(); + if ( group->GetGroupDS()->GetType() == SMDSAbs_Edge && + strcmp( group->GetName(), theGroupName ) == 0 ) + { + groupDS = dynamic_cast< SMESHDS_Group* >( group->GetGroupDS() ); + } + } + if ( !groupDS ) + { + SMESH::SMESH_Group_var groupVar = myMesh_i->CreateGroup( SMESH::EDGE, theGroupName ); + + if ( SMESH_Group_i* groupImpl = SMESH::DownCast( groupVar )) + groupDS = dynamic_cast< SMESHDS_Group* >( groupImpl->GetGroupDS() ); + } + } + + // convert input polySegments + ::SMESH_MeshEditor::TListOfPolySegments segments( theSegments.length() ); + for ( CORBA::ULong i = 0; i < theSegments.length(); ++i ) + { + SMESH::PolySegment& segIn = theSegments[ i ]; + ::SMESH_MeshEditor::PolySegment& segOut = segments[ i ]; + segOut.myNode1[0] = meshDS->FindNode( segIn.node1ID1 ); + segOut.myNode2[0] = meshDS->FindNode( segIn.node1ID2 ); + segOut.myNode1[1] = meshDS->FindNode( segIn.node2ID1 ); + segOut.myNode2[1] = meshDS->FindNode( segIn.node2ID2 ); + 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 + SMESH::SMESH_IDSource_var idSource = SMESH::SMESH_IDSource::_narrow( myMesh_i->_this() ); + theSearchersDeleter.Set( myMesh, getPartIOR( idSource, SMESH::FACE )); + if ( !theElementSearcher ) + theElementSearcher = SMESH_MeshAlgos::GetElementSearcher( *getMeshDS() ); + + // compute + getEditor().MakePolyLine( segments, groupDS, theElementSearcher ); + + // return vectors + if ( myIsPreviewMode ) + { + for ( CORBA::ULong i = 0; i < theSegments.length(); ++i ) + { + SMESH::PolySegment& segOut = theSegments[ i ]; + ::SMESH_MeshEditor::PolySegment& segIn = segments[ i ]; + segOut.vector.PS.x = segIn.myVector.X(); + segOut.vector.PS.y = segIn.myVector.Y(); + segOut.vector.PS.z = segIn.myVector.Z(); + } + } + else + { + TPythonDump() << "_segments = []"; + for ( CORBA::ULong i = 0; i < theSegments.length(); ++i ) + { + SMESH::PolySegment& segIn = theSegments[ i ]; + TPythonDump() << "_segments.append( SMESH.PolySegment( " + << segIn.node1ID1 << ", " + << segIn.node1ID2 << ", " + << segIn.node2ID1 << ", " + << segIn.node2ID2 << ", " + << "smeshBuilder.MakeDirStruct( " + << segIn.vector.PS.x << ", " + << segIn.vector.PS.y << ", " + << segIn.vector.PS.z << ")))"; + } + TPythonDump() << this << ".MakePolyLine( _segments, '" << theGroupName << "')"; + } + meshDS->Modified(); + SMESH_CATCH( SMESH::throwCorbaException ); + return; +}