X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_Mesh_i.cxx;h=4c5291cb13d39253ffde2291006932d8ef3cc15b;hp=540211542cc35aa31e3e95769d6296654a72dd5d;hb=7b4c10fd0e3bd5f6612582fb9ef39965b8f0055a;hpb=9cef4666a14b0edf129bb94643a841e29e1d4f3a diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 540211542..4c5291cb1 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -96,6 +96,7 @@ static int MYDEBUG = 0; using namespace std; using SMESH::TPythonDump; +using SMESH::TVar; int SMESH_Mesh_i::_idGenerator = 0; @@ -691,9 +692,9 @@ SMESH_Mesh_i::addHypothesis(GEOM::GEOM_Object_ptr aSubShape, //use PseudoShape in case if mesh has no shape if(HasShapeToMesh()) myLocSubShape = _gen_i->GeomObjectToShape( aSubShape); - else + else myLocSubShape = _impl->GetShapeToMesh(); - + const int hypId = anHyp->GetId(); std::string error; status = _impl->AddHypothesis( myLocSubShape, hypId, &error ); @@ -1018,7 +1019,7 @@ SMESH_Mesh_i::CreateGroupFromGEOM (SMESH::ElementType theElemType, TopoDS_Shape aShape = _gen_i->GeomObjectToShape( theGeomObj ); if ( !aShape.IsNull() ) { - aNewGroup = + aNewGroup = SMESH::SMESH_GroupOnGeom::_narrow( createGroup( theElemType, theName, aShape )); if ( _gen_i->CanPublishInStudy( aNewGroup ) ) @@ -1410,7 +1411,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr //============================================================================= /*! - \brief Intersect list of groups. New group is created. All mesh elements that + \brief Intersect list of groups. New group is created. All mesh elements that are present in all initial groups simultaneously are added to the new one. \param theGroups list of groups \param theName name of group to be created @@ -1495,7 +1496,7 @@ SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups, } //============================================================================= -/*! +/*! * New group is created. All mesh elements that are present in * a main group but is not present in a tool group are added to the new one */ @@ -1558,7 +1559,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr //============================================================================= /*! - \brief Cut lists of groups. New group is created. All mesh elements that are + \brief Cut lists of groups. New group is created. All mesh elements that are present in main groups but do not present in tool groups are added to the new one \param theMainGroups list of main groups \param theToolGroups list of tool groups @@ -1567,8 +1568,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr */ //============================================================================= SMESH::SMESH_Group_ptr -SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups, - const SMESH::ListOfGroups& theToolGroups, +SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups, + const SMESH::ListOfGroups& theToolGroups, const char* theName ) throw (SALOME::SALOME_Exception) { @@ -1868,6 +1869,89 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfIDSources& theGroups, return aResGrp._retn(); } +//================================================================================ +/*! + * \brief Distribute all faces of the mesh between groups using sharp edges and optionally + * existing 1D elements as group boundaries. + * \param [in] theSharpAngle - edge is considered sharp if an angle between normals of + * adjacent faces is more than \a sharpAngle in degrees. + * \param [in] theCreateEdges - to create 1D elements for detected sharp edges. + * \param [in] theUseExistingEdges - to use existing edges as group boundaries + * \return ListOfGroups - the created groups + */ +//================================================================================ + +SMESH::ListOfGroups* +SMESH_Mesh_i::FaceGroupsSeparatedByEdges( CORBA::Double theSharpAngle, + CORBA::Boolean theCreateEdges, + CORBA::Boolean theUseExistingEdges ) + throw (SALOME::SALOME_Exception) +{ + if ( theSharpAngle < 0 || theSharpAngle > 180 ) + THROW_SALOME_CORBA_EXCEPTION("Invalid sharp angle, it must be between 0 and 180 degrees", + SALOME::BAD_PARAM); + + SMESH::ListOfGroups_var resultGroups = new SMESH::ListOfGroups; + + TPythonDump pyDump; + + SMESH_TRY; + if ( _preMeshInfo ) + _preMeshInfo->FullLoadFromFile(); + + SMESHDS_Mesh* meshDS = _impl->GetMeshDS(); + + std::vector< SMESH_MeshAlgos::Edge > edges = + SMESH_MeshAlgos::FindSharpEdges( meshDS, theSharpAngle, theUseExistingEdges ); + + if ( theCreateEdges ) + { + std::vector nodes(2); + for ( size_t i = 0; i < edges.size(); ++i ) + { + nodes[0] = edges[i]._node1; + nodes[1] = edges[i]._node2; + if ( meshDS->FindElement( nodes, SMDSAbs_Edge )) + continue; + if ( edges[i]._medium ) + meshDS->AddEdge( edges[i]._node1, edges[i]._node2, edges[i]._medium ); + else + meshDS->AddEdge( edges[i]._node1, edges[i]._node2 ); + } + } + + std::vector< std::vector< const SMDS_MeshElement* > > faceGroups = + SMESH_MeshAlgos::SeparateFacesByEdges( meshDS, edges ); + + SMESH::SMESH_MeshEditor_var( GetMeshEditor() ); // create _editor + + resultGroups->length( faceGroups.size() ); + for ( size_t iG = 0; iG < faceGroups.size(); ++iG ) + { + SMESH::SMESH_Group_var group = CreateGroup( SMESH::FACE, + _editor->GenerateGroupName("Group").c_str()); + resultGroups[iG] = SMESH::SMESH_Group::_duplicate( group ); + + SMESHDS_GroupBase* groupBaseDS = + SMESH::DownCast( group )->GetGroupDS(); + SMDS_MeshGroup& groupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup(); + + std::vector< const SMDS_MeshElement* >& faces = faceGroups[ iG ]; + for ( size_t i = 0; i < faces.size(); ++i ) + groupCore.Add( faces[i] ); + } + + pyDump << resultGroups << " = " << SMESH::SMESH_Mesh_var(_this()) + << ".FaceGroupsSeparatedByEdges( " + << TVar( theSharpAngle ) << ", " + << theCreateEdges << ", " + << theUseExistingEdges << " )"; + + SMESH_CATCH( SMESH::throwCorbaException ); + return resultGroups._retn(); + +} + //================================================================================ /*! * \brief Remember GEOM group data @@ -3079,7 +3163,7 @@ string SMESH_Mesh_i::prepareMeshNameAndGroups(const char* file, void SMESH_Mesh_i::ExportMED(const char* file, CORBA::Boolean auto_groups, - CORBA::Long minor, + CORBA::Long version, CORBA::Boolean overwrite, CORBA::Boolean autoDimension) throw(SALOME::SALOME_Exception) @@ -3090,12 +3174,12 @@ void SMESH_Mesh_i::ExportMED(const char* file, _preMeshInfo->FullLoadFromFile(); string aMeshName = prepareMeshNameAndGroups(file, overwrite); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, 0, autoDimension ); + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, 0, autoDimension ); TPythonDump() << SMESH::SMESH_Mesh_var(_this()) << ".ExportMED( r'" << file << "', " << "auto_groups=" <FullLoadFromFile(); @@ -3262,8 +3347,9 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, SMESH::DownCast< SMESH_Mesh_i* >( meshPart )) { aMeshName = prepareMeshNameAndGroups(file, overwrite); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, - 0, autoDimension, /*addODOnVertices=*/have0dField); + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, + 0, autoDimension, /*addODOnVertices=*/have0dField, + ZTolerance); meshDS = _impl->GetMeshDS(); } else @@ -3280,8 +3366,8 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, } SMESH_MeshPartDS* partDS = new SMESH_MeshPartDS( meshPart ); - _impl->ExportMED( file, aMeshName.c_str(), auto_groups, minor, - partDS, autoDimension, /*addODOnVertices=*/have0dField); + _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, + partDS, autoDimension, /*addODOnVertices=*/have0dField, ZTolerance); meshDS = tmpDSDeleter._obj = partDS; } @@ -3309,11 +3395,13 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart, << meshPart << ", r'" << file << "', " << auto_groups << ", " - << minor << ", " + << version << ", " << overwrite << ", " << autoDimension << ", " << goList << ", '" - << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )"; + << ( geomAssocFields ? geomAssocFields : "" ) << "'," + << TVar( ZTolerance ) + << " )"; SMESH_CATCH( SMESH::throwCorbaException ); } @@ -4296,7 +4384,7 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, return aResult._retn(); } - + //============================================================================= /*! * Returns type of elements for given submesh @@ -4328,9 +4416,9 @@ SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID SMESH_CATCH( SMESH::throwCorbaException ); - return type; + return type; } - + //============================================================================= /*! @@ -4404,7 +4492,7 @@ SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id) // find inverse elements SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator(); - aResult->length( aNode->NbInverseElements() ); + aResult->length( aNode->NbInverseElements() ); for( int i = 0; eIt->more(); ++i ) { const SMDS_MeshElement* elem = eIt->next(); @@ -4540,7 +4628,7 @@ CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id) //============================================================================= /*! - * For given element returns ID of result shape after + * For given element returns ID of result shape after * ::FindShape() from SMESH_MeshEditor * If there is not element for given ID - returns -1 */ @@ -5205,7 +5293,7 @@ void SMESH_Mesh_i::checkGroupNames() int nbGrp = NbGroups(); if ( !nbGrp ) return; - + SMESH::ListOfGroups* grpList = 0; // avoid dump of "GetGroups" { @@ -5401,10 +5489,10 @@ SALOMEDS::TMPFile* SMESH_Mesh_i::GetVtkUgStream() aWriter->Write(); char* str = aWriter->GetOutputString(); int size = aWriter->GetOutputStringLength(); - - //Allocate octect buffer of required size + + //Allocate octet buffer of required size CORBA::Octet* OctetBuf = SALOMEDS::TMPFile::allocbuf(size); - //Copy ostrstream content to the octect buffer + //Copy ostrstream content to the octet buffer memcpy(OctetBuf, str, size); //Create and return TMPFile SeqFile = new SALOMEDS::TMPFile(size, size, OctetBuf, 1); @@ -5735,7 +5823,7 @@ class SMESH_DimHyp } return isShared; } - + //----------------------------------------------------------------------------- //! check algorithms static bool checkAlgo(const SMESHDS_Hypothesis* theA1, @@ -5749,7 +5837,7 @@ class SMESH_DimHyp return strcmp( theA1->GetName(), theA2->GetName() ) == 0; } - + //----------------------------------------------------------------------------- //! Check if sub-shape hypotheses are concurrent bool IsConcurrent(const SMESH_DimHyp* theOther) const @@ -5801,7 +5889,7 @@ class SMESH_DimHyp return ( this->_subMesh->GetId() < theOther->_subMesh->GetId() ); } - + }; // end of SMESH_DimHyp //----------------------------------------------------------------------------- @@ -5809,7 +5897,7 @@ typedef list TDimHypList; //----------------------------------------------------------------------------- -void addDimHypInstance(const int theDim, +void addDimHypInstance(const int theDim, const TopoDS_Shape& theShape, const SMESH_Algo* theAlgo, const SMESH_subMesh* theSubMesh, @@ -5822,7 +5910,7 @@ void addDimHypInstance(const int theDim, dimHyp->_hypotheses.push_front(theAlgo); listOfdimHyp.push_back( dimHyp ); } - + SMESH_DimHyp* dimHyp = const_cast( listOfdimHyp.back() ); dimHyp->_hypotheses.insert( dimHyp->_hypotheses.end(), theHypList.begin(), theHypList.end() ); @@ -5881,7 +5969,7 @@ void unionLists(TListOfInt& theListOfId, if ( find_first_of( theListOfId.begin(), theListOfId.end(), otherListOfId.begin(), otherListOfId.end() ) == theListOfId.end() ) continue; - + // union two lists (from source into target) TListOfInt::iterator it2 = otherListOfId.begin(); for ( ; it2 != otherListOfId.end(); it2++ ) { @@ -6034,7 +6122,7 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes() addDimHypInstance( j, aSubMeshShape, anAlgo, sm, hypList, dimHypListArr ); } } // end iterations on submesh - + // iterate on created dimension-hypotheses and check for concurrents for ( int i = 0; i < 4; i++ ) { const TDimHypList& listOfDimHyp = dimHypListArr[i]; @@ -6059,9 +6147,9 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes() } } } - + removeDimHyps(dimHypListArr); - + // now, minimize the number of concurrent groups // Here we assume that lists of submeshes can have same submesh // in case of multi-dimension algorithms, as result @@ -6130,7 +6218,7 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes() mesh.SetMeshOrder( subMeshOrder ); res = true; - + SMESH::SMESH_Mesh_var me = _this(); _gen_i->UpdateIcons( me ); @@ -6379,5 +6467,3 @@ _GET_ITER_DEFINE( SMDS_VolumeIteratorPtr, volumesIterator, SMDS_MeshVolume, SMDS // END Implementation of SMESH_MeshPartDS // //================================================================================ - -