00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESH_Mesh.hxx"
00029 #include "SMESH_subMesh.hxx"
00030 #include "SMESH_Gen.hxx"
00031 #include "SMESH_Hypothesis.hxx"
00032 #include "SMESH_Group.hxx"
00033 #include "SMESH_HypoFilter.hxx"
00034 #include "SMESHDS_Group.hxx"
00035 #include "SMESHDS_Script.hxx"
00036 #include "SMESHDS_GroupOnGeom.hxx"
00037 #include "SMESHDS_Document.hxx"
00038 #include "SMDS_MeshVolume.hxx"
00039 #include "SMDS_SetIterator.hxx"
00040
00041 #include "utilities.h"
00042
00043 #include "DriverMED_W_SMESHDS_Mesh.h"
00044 #include "DriverDAT_W_SMDS_Mesh.h"
00045 #include "DriverUNV_W_SMDS_Mesh.h"
00046 #include "DriverSTL_W_SMDS_Mesh.h"
00047
00048 #include "DriverMED_R_SMESHDS_Mesh.h"
00049 #include "DriverUNV_R_SMDS_Mesh.h"
00050 #include "DriverSTL_R_SMDS_Mesh.h"
00051
00052 #undef _Precision_HeaderFile
00053 #include <BRepBndLib.hxx>
00054 #include <BRepPrimAPI_MakeBox.hxx>
00055 #include <Bnd_Box.hxx>
00056 #include <TopExp.hxx>
00057 #include <TopExp_Explorer.hxx>
00058 #include <TopTools_ListIteratorOfListOfShape.hxx>
00059 #include <TopTools_ListOfShape.hxx>
00060 #include <TopTools_MapOfShape.hxx>
00061 #include <TopoDS_Iterator.hxx>
00062
00063 #include "Utils_ExceptHandlers.hxx"
00064
00065 using namespace std;
00066
00067
00068 #define MAX_MED_GROUP_NAME_LENGTH 80
00069
00070 #ifdef _DEBUG_
00071 static int MYDEBUG = 0;
00072 #else
00073 static int MYDEBUG = 0;
00074 #endif
00075
00076 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
00077
00078 typedef SMESH_HypoFilter THypType;
00079
00080
00084
00085
00086 SMESH_Mesh::SMESH_Mesh(int theLocalId,
00087 int theStudyId,
00088 SMESH_Gen* theGen,
00089 bool theIsEmbeddedMode,
00090 SMESHDS_Document* theDocument):
00091 _groupId( 0 ), _nbSubShapes( 0 )
00092 {
00093 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
00094 _id = theLocalId;
00095 _studyId = theStudyId;
00096 _gen = theGen;
00097 _myDocument = theDocument;
00098 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
00099 _myMeshDS = theDocument->GetMesh(_idDoc);
00100 _isShapeToMesh = false;
00101 _isAutoColor = false;
00102 _isModified = false;
00103 _shapeDiagonal = 0.0;
00104 _rmGroupCallUp = 0;
00105 _myMeshDS->ShapeToMesh( PseudoShape() );
00106 }
00107
00108
00112
00113
00114 SMESH_Mesh::SMESH_Mesh():
00115 _groupId( 0 ), _nbSubShapes( 0 )
00116 {
00117 _myMeshDS = 0;
00118 _isShapeToMesh = false;
00119 _isAutoColor = false;
00120 _isModified = false;
00121 _shapeDiagonal = 0.0;
00122 _rmGroupCallUp = 0;
00123 }
00124
00125
00129
00130
00131 SMESH_Mesh::~SMESH_Mesh()
00132 {
00133 MESSAGE("SMESH_Mesh::~SMESH_Mesh");
00134
00135
00136
00137 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
00138 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
00139
00140
00141 map < int, SMESH_Group * >::iterator itg;
00142 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
00143 SMESH_Group *aGroup = (*itg).second;
00144 delete aGroup;
00145 }
00146 _mapGroup.clear();
00147
00148 if ( _rmGroupCallUp) delete _rmGroupCallUp;
00149 _rmGroupCallUp = 0;
00150 }
00151
00152
00156
00157
00158 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
00159 {
00160 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
00161
00162 if ( !aShape.IsNull() && _isShapeToMesh ) {
00163 if ( aShape.ShapeType() != TopAbs_COMPOUND &&
00164 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
00165 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
00166 }
00167
00168 if ( !_myMeshDS->ShapeToMesh().IsNull() )
00169 {
00170
00171
00172 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
00173 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
00174 delete i_sm->second;
00175 _mapSubMesh.clear();
00176
00177 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
00178 while ( i_gr != _mapGroup.end() ) {
00179 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
00180 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
00181 delete i_gr->second;
00182 _mapGroup.erase( i_gr++ );
00183 }
00184 else
00185 i_gr++;
00186 }
00187 _mapAncestors.Clear();
00188
00189
00190 TopoDS_Shape aNullShape;
00191 _myMeshDS->ShapeToMesh( aNullShape );
00192
00193 _shapeDiagonal = 0.0;
00194 }
00195
00196
00197 if ( !aShape.IsNull() )
00198 {
00199 _myMeshDS->ShapeToMesh(aShape);
00200 _isShapeToMesh = true;
00201 _nbSubShapes = _myMeshDS->MaxShapeIndex();
00202
00203
00204 fillAncestorsMap(aShape);
00205 }
00206 else
00207 {
00208 _isShapeToMesh = false;
00209 _shapeDiagonal = 0.0;
00210 _myMeshDS->ShapeToMesh( PseudoShape() );
00211 }
00212 _isModified = false;
00213 }
00214
00215
00219
00220
00221 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
00222 {
00223 return _myMeshDS->ShapeToMesh();
00224 }
00225
00226
00231
00232
00233 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
00234 {
00235 static TopoDS_Solid aSolid;
00236 if ( aSolid.IsNull() )
00237 {
00238 aSolid = BRepPrimAPI_MakeBox(1,1,1);
00239 }
00240 return aSolid;
00241 }
00242
00243
00247
00248
00249 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
00250 {
00251 if ( !aShape.IsNull() ) {
00252 Bnd_Box Box;
00253 BRepBndLib::Add(aShape, Box);
00254 return sqrt( Box.SquareExtent() );
00255 }
00256 return 0;
00257 }
00258
00259
00263
00264
00265 double SMESH_Mesh::GetShapeDiagonalSize() const
00266 {
00267 if ( _shapeDiagonal == 0. && _isShapeToMesh )
00268 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
00269
00270 return _shapeDiagonal;
00271 }
00272
00273
00277
00278
00279 void SMESH_Mesh::Clear()
00280 {
00281
00282 _myMeshDS->ClearMesh();
00283
00284
00285 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
00286 {
00287 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
00288 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
00289 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
00290 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
00291 }
00292 _isModified = false;
00293 }
00294
00295
00299
00300
00301 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
00302 {
00303
00304 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
00305 {
00306 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(true,
00307 false);
00308 while ( smIt->more() )
00309 {
00310 sm = smIt->next();
00311 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
00312 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
00313
00314 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
00315
00316 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
00317 }
00318 }
00319 }
00320
00321
00322
00323
00324
00325
00326 int SMESH_Mesh::UNVToMesh(const char* theFileName)
00327 {
00328 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
00329 if(_isShapeToMesh)
00330 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
00331 _isShapeToMesh = false;
00332 DriverUNV_R_SMDS_Mesh myReader;
00333 myReader.SetMesh(_myMeshDS);
00334 myReader.SetFile(theFileName);
00335 myReader.SetMeshId(-1);
00336 myReader.Perform();
00337 if(MYDEBUG){
00338 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
00339 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
00340 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
00341 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
00342 }
00343 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
00344 if (aGroup != 0) {
00345 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
00346
00347 aGroup->InitSubGroupsIterator();
00348 while (aGroup->MoreSubGroups()) {
00349 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
00350 string aName = aGroupNames[aSubGroup];
00351 int aId;
00352
00353 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
00354 if ( aSMESHGroup ) {
00355 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
00356 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
00357 if ( aGroupDS ) {
00358 aGroupDS->SetStoreName(aName.c_str());
00359 aSubGroup->InitIterator();
00360 const SMDS_MeshElement* aElement = 0;
00361 while (aSubGroup->More()) {
00362 aElement = aSubGroup->Next();
00363 if (aElement) {
00364 aGroupDS->SMDSGroup().Add(aElement);
00365 }
00366 }
00367 if (aElement)
00368 aGroupDS->SetType(aElement->GetType());
00369 }
00370 }
00371 }
00372 }
00373 return 1;
00374 }
00375
00376
00377
00378
00379
00380
00381 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
00382 {
00383 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
00384 if(_isShapeToMesh)
00385 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
00386 _isShapeToMesh = false;
00387 DriverMED_R_SMESHDS_Mesh myReader;
00388 myReader.SetMesh(_myMeshDS);
00389 myReader.SetMeshId(-1);
00390 myReader.SetFile(theFileName);
00391 myReader.SetMeshName(theMeshName);
00392 Driver_Mesh::Status status = myReader.Perform();
00393 if(MYDEBUG){
00394 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
00395 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
00396 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
00397 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
00398 }
00399
00400
00401 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
00402 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
00403 int anId;
00404 list<TNameAndType>::iterator name_type = aGroupNames.begin();
00405 for ( ; name_type != aGroupNames.end(); name_type++ ) {
00406 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
00407 if ( aGroup ) {
00408 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
00409 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
00410 if ( aGroupDS ) {
00411 aGroupDS->SetStoreName( name_type->first.c_str() );
00412 myReader.GetGroup( aGroupDS );
00413 }
00414 }
00415 }
00416 return (int) status;
00417 }
00418
00419
00420
00421
00422
00423
00424 int SMESH_Mesh::STLToMesh(const char* theFileName)
00425 {
00426 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
00427 if(_isShapeToMesh)
00428 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
00429 _isShapeToMesh = false;
00430 DriverSTL_R_SMDS_Mesh myReader;
00431 myReader.SetMesh(_myMeshDS);
00432 myReader.SetFile(theFileName);
00433 myReader.SetMeshId(-1);
00434 myReader.Perform();
00435 if(MYDEBUG){
00436 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
00437 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
00438 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
00439 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
00440 }
00441 return 1;
00442 }
00443
00444
00448
00449
00450 SMESH_Hypothesis::Hypothesis_Status
00451 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
00452 int anHypId ) throw(SALOME_Exception)
00453 {
00454 Unexpect aCatch(SalomeException);
00455 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
00456
00457 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
00458 if ( !subMesh || !subMesh->GetId())
00459 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
00460
00461 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
00462 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
00463 {
00464 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
00465 if(MYDEBUG) {
00466 SCRUTE(_studyId);
00467 SCRUTE(anHypId);
00468 }
00469 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
00470 }
00471
00472 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
00473 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
00474
00475 bool isGlobalHyp = IsMainShape( aSubShape );
00476
00477
00478 if ( !isGlobalHyp )
00479 {
00480
00481
00482
00483 string hypName = anHyp->GetName();
00484 if ( hypName == "NotConformAllowed" )
00485 {
00486 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
00487 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
00488 }
00489 }
00490
00491
00492
00493 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
00494 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
00495
00496 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
00497
00498
00499 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
00500 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape))
00501 {
00502 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
00503
00504 SMESH_Hypothesis::Hypothesis_Status ret2 =
00505 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
00506 if (ret2 > ret)
00507 ret = ret2;
00508
00509
00510 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
00511 {
00512 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
00513 while ( smIt->more() ) {
00514 SMESH_subMesh* sm = smIt->next();
00515 if ( sm->IsApplicableHypotesis( anHyp )) {
00516 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
00517 if (ret2 > ret) {
00518 ret = ret2;
00519 break;
00520 }
00521 }
00522 }
00523 }
00524 }
00525 HasModificationsToDiscard();
00526
00527 GetMeshDS()->Modified();
00528
00529 if(MYDEBUG) subMesh->DumpAlgoState(true);
00530 if(MYDEBUG) SCRUTE(ret);
00531 return ret;
00532 }
00533
00534
00538
00539
00540 SMESH_Hypothesis::Hypothesis_Status
00541 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
00542 int anHypId)throw(SALOME_Exception)
00543 {
00544 Unexpect aCatch(SalomeException);
00545 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
00546
00547 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
00548 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
00549 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
00550
00551 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
00552 if(MYDEBUG) {
00553 int hypType = anHyp->GetType();
00554 SCRUTE(hypType);
00555 }
00556
00557
00558
00559 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
00560 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
00561
00562 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
00563
00564 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
00565
00566
00567 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
00568 subMesh->IsApplicableHypotesis( anHyp ) &&
00569 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
00570 ret = SMESH_Hypothesis::HYP_CONCURENT;
00571
00572
00573 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
00574 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape))
00575 {
00576 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
00577
00578 SMESH_Hypothesis::Hypothesis_Status ret2 =
00579 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
00580 if (ret2 > ret)
00581 ret = ret2;
00582
00583
00584 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
00585 {
00586 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
00587 while ( smIt->more() ) {
00588 SMESH_subMesh* sm = smIt->next();
00589 if ( sm->IsApplicableHypotesis( anHyp )) {
00590 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
00591 if (ret2 > ret) {
00592 ret = ret2;
00593 break;
00594 }
00595 }
00596 }
00597 }
00598 }
00599
00600 HasModificationsToDiscard();
00601
00602 GetMeshDS()->Modified();
00603
00604 if(MYDEBUG) subMesh->DumpAlgoState(true);
00605 if(MYDEBUG) SCRUTE(ret);
00606 return ret;
00607 }
00608
00609
00613
00614
00615 const list<const SMESHDS_Hypothesis*>&
00616 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
00617 throw(SALOME_Exception)
00618 {
00619 Unexpect aCatch(SalomeException);
00620 return _myMeshDS->GetHypothesis(aSubShape);
00621 }
00622
00623
00632
00633
00634 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
00635 const SMESH_HypoFilter& aFilter,
00636 const bool andAncestors,
00637 TopoDS_Shape* assignedTo) const
00638 {
00639 {
00640 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
00641 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
00642 for ( ; hyp != hypList.end(); hyp++ ) {
00643 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
00644 if ( aFilter.IsOk( h, aSubShape)) {
00645 if ( assignedTo ) *assignedTo = aSubShape;
00646 return h;
00647 }
00648 }
00649 }
00650 if ( andAncestors )
00651 {
00652
00653 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
00654 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
00655 for ( ; smIt != smList.end(); smIt++ )
00656 {
00657 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
00658 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
00659 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
00660 for ( ; hyp != hypList.end(); hyp++ ) {
00661 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
00662 if (aFilter.IsOk( h, curSh )) {
00663 if ( assignedTo ) *assignedTo = curSh;
00664 return h;
00665 }
00666 }
00667 }
00668 }
00669 return 0;
00670 }
00671
00672
00681
00682
00683 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
00684 const SMESH_HypoFilter& aFilter,
00685 list <const SMESHDS_Hypothesis * >& aHypList,
00686 const bool andAncestors) const
00687 {
00688 set<string> hypTypes;
00689 int nbHyps = 0;
00690
00691
00692 bool mainHypFound = false;
00693
00694
00695 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
00696 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
00697 if ( hypTypes.insert( (*hyp)->GetName() ).second )
00698 nbHyps++;
00699 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
00700 mainHypFound = true;
00701 }
00702
00703
00704 {
00705 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
00706 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
00707 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
00708 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
00709 hypTypes.insert( (*hyp)->GetName() ).second )
00710 {
00711 aHypList.push_back( *hyp );
00712 nbHyps++;
00713 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
00714 mainHypFound = true;
00715 }
00716 }
00717
00718
00719 if ( andAncestors )
00720 {
00721 TopTools_MapOfShape map;
00722
00723
00724 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
00725 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
00726 for ( ; smIt != smList.end(); smIt++ )
00727 {
00728 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
00729 if ( !map.Add( curSh ))
00730 continue;
00731 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
00732 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
00733 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) &&
00734 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
00735 hypTypes.insert( (*hyp)->GetName() ).second )
00736 {
00737 aHypList.push_back( *hyp );
00738 nbHyps++;
00739 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
00740 mainHypFound = true;
00741 }
00742 }
00743 }
00744 return nbHyps;
00745 }
00746
00747
00751
00752
00753 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
00754 {
00755 Unexpect aCatch(SalomeException);
00756 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
00757 return _myMeshDS->GetScript()->GetCommands();
00758 }
00759
00760
00764
00765 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
00766 {
00767 Unexpect aCatch(SalomeException);
00768 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
00769 _myMeshDS->GetScript()->Clear();
00770 }
00771
00772
00776
00777
00778 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
00779 throw(SALOME_Exception)
00780 {
00781 Unexpect aCatch(SalomeException);
00782 SMESH_subMesh *aSubMesh;
00783 int index = _myMeshDS->ShapeToIndex(aSubShape);
00784
00785
00786 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
00787 TopoDS_Iterator it( aSubShape );
00788 if ( it.More() )
00789 {
00790 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
00791 if ( index > _nbSubShapes ) _nbSubShapes = index;
00792
00793
00794 fillAncestorsMap(aSubShape);
00795 }
00796 }
00797
00798
00799
00800 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
00801 if ( i_sm != _mapSubMesh.end())
00802 {
00803 aSubMesh = i_sm->second;
00804 }
00805 else
00806 {
00807 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
00808 _mapSubMesh[index] = aSubMesh;
00809 ClearMeshOrder();
00810 }
00811 return aSubMesh;
00812 }
00813
00814
00819
00820
00821 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
00822 throw(SALOME_Exception)
00823 {
00824 Unexpect aCatch(SalomeException);
00825 SMESH_subMesh *aSubMesh = NULL;
00826
00827 int index = _myMeshDS->ShapeToIndex(aSubShape);
00828
00829 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
00830 if ( i_sm != _mapSubMesh.end())
00831 aSubMesh = i_sm->second;
00832
00833 return aSubMesh;
00834 }
00835
00840
00841
00842 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
00843 throw(SALOME_Exception)
00844 {
00845 Unexpect aCatch(SalomeException);
00846
00847 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
00848 if (i_sm == _mapSubMesh.end())
00849 return NULL;
00850 return i_sm->second;
00851 }
00852
00856
00857
00858 list<SMESH_subMesh*>
00859 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
00860 throw(SALOME_Exception)
00861 {
00862 Unexpect aCatch(SalomeException);
00863 list<SMESH_subMesh*> found;
00864
00865 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
00866 if ( !subMesh )
00867 return found;
00868
00869
00870 map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
00871 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
00872 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
00873 if ( ds && ds->IsComplexSubmesh() ) {
00874 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
00875 for ( ; exp.More(); exp.Next() ) {
00876 if ( aSubShape.IsSame( exp.Current() )) {
00877 found.push_back( i_sm->second );
00878 break;
00879 }
00880 }
00881 } else {
00882 break;
00883 }
00884 }
00885 return found;
00886 }
00887
00888
00889
00890
00891
00892 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
00893 const SMESH_subMesh* aSubMesh)
00894 {
00895 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
00896
00897
00898 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
00899 return false;
00900
00901 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
00902
00903 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
00904
00905
00906 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
00907 return ( anHyp == algo );
00908
00909
00910 if (algo)
00911 {
00912
00913 SMESH_HypoFilter hypoKind;
00914 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
00915 list <const SMESHDS_Hypothesis * > usedHyps;
00916 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
00917 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
00918 }
00919 }
00920
00921
00922
00923 return false;
00924 }
00925
00926
00930
00931
00932 const list < SMESH_subMesh * >&
00933 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
00934 throw(SALOME_Exception)
00935 {
00936 Unexpect aCatch(SalomeException);
00937 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
00938 map < int, SMESH_subMesh * >::iterator itsm;
00939 _subMeshesUsingHypothesisList.clear();
00940 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
00941 {
00942 SMESH_subMesh *aSubMesh = (*itsm).second;
00943 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
00944 _subMeshesUsingHypothesisList.push_back(aSubMesh);
00945 }
00946 return _subMeshesUsingHypothesisList;
00947 }
00948
00949
00950
00951
00952
00953
00954 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
00955 {
00956 Unexpect aCatch(SalomeException);
00957
00958 const SMESH_Algo *foundAlgo = 0;
00959 SMESH_HypoFilter algoKind, compatibleHypoKind;
00960 list <const SMESHDS_Hypothesis * > usedHyps;
00961
00962
00963 map < int, SMESH_subMesh * >::iterator itsm;
00964 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
00965 {
00966 SMESH_subMesh *aSubMesh = (*itsm).second;
00967 if ( aSubMesh->IsApplicableHypotesis( hyp ))
00968 {
00969 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
00970
00971 if ( !foundAlgo )
00972 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
00973
00974 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
00975 ( GetHypothesis( aSubShape, algoKind, true ));
00976
00977 if ( algo )
00978 {
00979 bool sameAlgo = ( algo == foundAlgo );
00980 if ( !sameAlgo && foundAlgo )
00981 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
00982
00983 if ( !sameAlgo ) {
00984 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
00985 continue;
00986 foundAlgo = algo;
00987 }
00988
00989
00990 usedHyps.clear();
00991 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
00992 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
00993 {
00994 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
00995 const_cast< SMESH_Hypothesis*>( hyp ));
00996 }
00997 }
00998 }
00999 }
01000 HasModificationsToDiscard();
01001 GetMeshDS()->Modified();
01002 }
01003
01004
01008
01009 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
01010 {
01011 Unexpect aCatch(SalomeException);
01012 _isAutoColor = theAutoColor;
01013 }
01014
01015 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
01016 {
01017 Unexpect aCatch(SalomeException);
01018 return _isAutoColor;
01019 }
01020
01021
01022
01023
01024
01025
01026 void SMESH_Mesh::SetIsModified(bool isModified)
01027 {
01028 _isModified = isModified;
01029
01030 if ( _isModified )
01031
01032 HasModificationsToDiscard();
01033 }
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043 bool SMESH_Mesh::HasModificationsToDiscard() const
01044 {
01045 if ( ! _isModified )
01046 return false;
01047
01048
01049
01050 bool hasComputed = false, hasNotComputed = false;
01051 map <int, SMESH_subMesh*>::const_iterator i_sm = _mapSubMesh.begin();
01052 for ( ; i_sm != _mapSubMesh.end() ; ++i_sm )
01053 switch ( i_sm->second->GetSubShape().ShapeType() )
01054 {
01055 case TopAbs_EDGE:
01056 case TopAbs_FACE:
01057 case TopAbs_SOLID:
01058 if ( i_sm->second->IsMeshComputed() )
01059 hasComputed = true;
01060 else
01061 hasNotComputed = true;
01062 if ( hasComputed && hasNotComputed)
01063 return true;
01064 }
01065
01066 if ( !hasComputed )
01067 const_cast<SMESH_Mesh*>(this)->_isModified = false;
01068
01069 return false;
01070 }
01071
01072
01076
01077
01078 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
01079 {
01080
01081 map< SMDSAbs_ElementType, set<string> > aGroupNames;
01082 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
01083 {
01084 SMESH_Group* aGroup = it->second;
01085 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
01086 string aGroupName = aGroup->GetName();
01087 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
01088 if (!aGroupNames[aType].insert(aGroupName).second)
01089 return true;
01090 }
01091
01092 return false;
01093 }
01094
01095 void SMESH_Mesh::ExportMED(const char *file,
01096 const char* theMeshName,
01097 bool theAutoGroups,
01098 int theVersion)
01099 throw(SALOME_Exception)
01100 {
01101 Unexpect aCatch(SalomeException);
01102
01103 DriverMED_W_SMESHDS_Mesh myWriter;
01104 myWriter.SetFile ( file, MED::EVersion(theVersion) );
01105 myWriter.SetMesh ( _myMeshDS );
01106 if ( !theMeshName )
01107 myWriter.SetMeshId ( _idDoc );
01108 else {
01109 myWriter.SetMeshId ( -1 );
01110 myWriter.SetMeshName( theMeshName );
01111 }
01112
01113 if ( theAutoGroups ) {
01114 myWriter.AddGroupOfNodes();
01115 myWriter.AddGroupOfEdges();
01116 myWriter.AddGroupOfFaces();
01117 myWriter.AddGroupOfVolumes();
01118 }
01119
01120
01121
01122 map< SMDSAbs_ElementType, set<string> > aGroupNames;
01123 char aString [256];
01124 int maxNbIter = 10000;
01125 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
01126 SMESH_Group* aGroup = it->second;
01127 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
01128 if ( aGroupDS ) {
01129 SMDSAbs_ElementType aType = aGroupDS->GetType();
01130 string aGroupName0 = aGroup->GetName();
01131 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
01132 string aGroupName = aGroupName0;
01133 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
01134 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
01135 aGroupName = aString;
01136 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
01137 }
01138 aGroupDS->SetStoreName( aGroupName.c_str() );
01139 myWriter.AddGroup( aGroupDS );
01140 }
01141 }
01142
01143
01144 myWriter.Perform();
01145 }
01146
01147 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
01148 {
01149 Unexpect aCatch(SalomeException);
01150 DriverDAT_W_SMDS_Mesh myWriter;
01151 myWriter.SetFile(string(file));
01152 myWriter.SetMesh(_myMeshDS);
01153 myWriter.SetMeshId(_idDoc);
01154 myWriter.Perform();
01155 }
01156
01157 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
01158 {
01159 Unexpect aCatch(SalomeException);
01160 DriverUNV_W_SMDS_Mesh myWriter;
01161 myWriter.SetFile(string(file));
01162 myWriter.SetMesh(_myMeshDS);
01163 myWriter.SetMeshId(_idDoc);
01164
01165
01166 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
01167 SMESH_Group* aGroup = it->second;
01168 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
01169 if ( aGroupDS ) {
01170 string aGroupName = aGroup->GetName();
01171 aGroupDS->SetStoreName( aGroupName.c_str() );
01172 myWriter.AddGroup( aGroupDS );
01173 }
01174 }
01175 myWriter.Perform();
01176 }
01177
01178 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
01179 {
01180 Unexpect aCatch(SalomeException);
01181 DriverSTL_W_SMDS_Mesh myWriter;
01182 myWriter.SetFile(string(file));
01183 myWriter.SetIsAscii( isascii );
01184 myWriter.SetMesh(_myMeshDS);
01185 myWriter.SetMeshId(_idDoc);
01186 myWriter.Perform();
01187 }
01188
01189
01193
01194
01195 int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
01196 {
01197 Unexpect aCatch(SalomeException);
01198 return _myMeshDS->NbNodes();
01199 }
01200
01201
01205
01206
01207 int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
01208 {
01209 Unexpect aCatch(SalomeException);
01210 return _myMeshDS->GetMeshInfo().Nb0DElements();
01211 }
01212
01213
01217
01218
01219 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01220 {
01221 Unexpect aCatch(SalomeException);
01222 return _myMeshDS->GetMeshInfo().NbEdges(order);
01223 }
01224
01225
01229
01230
01231 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01232 {
01233 Unexpect aCatch(SalomeException);
01234 return _myMeshDS->GetMeshInfo().NbFaces(order);
01235 }
01236
01237
01241
01242
01243 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01244 {
01245 Unexpect aCatch(SalomeException);
01246 return _myMeshDS->GetMeshInfo().NbTriangles(order);
01247 }
01248
01249
01253
01254
01255 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01256 {
01257 Unexpect aCatch(SalomeException);
01258 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
01259 }
01260
01261
01265
01266
01267 int SMESH_Mesh::NbPolygons() const throw(SALOME_Exception)
01268 {
01269 Unexpect aCatch(SalomeException);
01270 return _myMeshDS->GetMeshInfo().NbPolygons();
01271 }
01272
01273
01277
01278
01279 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01280 {
01281 Unexpect aCatch(SalomeException);
01282 return _myMeshDS->GetMeshInfo().NbVolumes(order);
01283 }
01284
01285
01289
01290
01291 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01292 {
01293 Unexpect aCatch(SalomeException);
01294 return _myMeshDS->GetMeshInfo().NbTetras(order);
01295 }
01296
01297
01301
01302
01303 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01304 {
01305 Unexpect aCatch(SalomeException);
01306 return _myMeshDS->GetMeshInfo().NbHexas(order);
01307 }
01308
01309
01313
01314
01315 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01316 {
01317 Unexpect aCatch(SalomeException);
01318 return _myMeshDS->GetMeshInfo().NbPyramids(order);
01319 }
01320
01321
01325
01326
01327 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
01328 {
01329 Unexpect aCatch(SalomeException);
01330 return _myMeshDS->GetMeshInfo().NbPrisms(order);
01331 }
01332
01333
01337
01338
01339 int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
01340 {
01341 Unexpect aCatch(SalomeException);
01342 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
01343 }
01344
01345
01349
01350
01351 int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
01352 {
01353 Unexpect aCatch(SalomeException);
01354 return _myMeshDS->NbSubMesh();
01355 }
01356
01357
01358
01359
01360
01361
01362 bool SMESH_Mesh::IsNotConformAllowed() const
01363 {
01364 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
01365
01366 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
01367 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
01368 }
01369
01370
01371
01372
01373
01374
01375 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
01376 {
01377 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
01378 }
01379
01380
01384
01385
01386 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
01387 const char* theName,
01388 int& theId,
01389 const TopoDS_Shape& theShape)
01390 {
01391 if (_mapGroup.find(_groupId) != _mapGroup.end())
01392 return NULL;
01393 theId = _groupId;
01394 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
01395 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
01396 _mapGroup[_groupId++] = aGroup;
01397 return aGroup;
01398 }
01399
01400
01404
01405
01406 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
01407 {
01408 typedef map <int, SMESH_Group *> TMap;
01409 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
01410 }
01411
01412
01416
01417
01418 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
01419 {
01420 if (_mapGroup.find(theGroupID) == _mapGroup.end())
01421 return NULL;
01422 return _mapGroup[theGroupID];
01423 }
01424
01425
01426
01430
01431
01432 list<int> SMESH_Mesh::GetGroupIds() const
01433 {
01434 list<int> anIds;
01435 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
01436 anIds.push_back( it->first );
01437
01438 return anIds;
01439 }
01440
01441
01446
01447
01448 void SMESH_Mesh::SetRemoveGroupCallUp( TRmGroupCallUp* upCaller )
01449 {
01450 if ( _rmGroupCallUp ) delete _rmGroupCallUp;
01451 _rmGroupCallUp = upCaller;
01452 }
01453
01454
01458
01459
01460 bool SMESH_Mesh::RemoveGroup (const int theGroupID)
01461 {
01462 if (_mapGroup.find(theGroupID) == _mapGroup.end())
01463 return false;
01464 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
01465 delete _mapGroup[theGroupID];
01466 _mapGroup.erase (theGroupID);
01467 if (_rmGroupCallUp)
01468 _rmGroupCallUp->RemoveGroup( theGroupID );
01469 return true;
01470 }
01471
01472
01473
01474
01475
01476
01477
01478 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
01479 {
01480 if ( _mapAncestors.Contains( theS ) )
01481 return _mapAncestors.FindFromKey( theS );
01482
01483 static TopTools_ListOfShape emptyList;
01484 return emptyList;
01485 }
01486
01487
01488
01489
01490
01491
01492 ostream& SMESH_Mesh::Dump(ostream& save)
01493 {
01494 int clause = 0;
01495 save << "========================== Dump contents of mesh ==========================" << endl << endl;
01496 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
01497 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
01498 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
01499 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
01500 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
01501 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
01502 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
01503 {
01504 string orderStr = isQuadratic ? "quadratic" : "linear";
01505 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
01506
01507 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
01508 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
01509 if ( NbFaces(order) > 0 ) {
01510 int nb3 = NbTriangles(order);
01511 int nb4 = NbQuadrangles(order);
01512 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
01513 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
01514 if ( nb3 + nb4 != NbFaces(order) ) {
01515 map<int,int> myFaceMap;
01516 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
01517 while( itFaces->more( ) ) {
01518 int nbNodes = itFaces->next()->NbNodes();
01519 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
01520 myFaceMap[ nbNodes ] = 0;
01521 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
01522 }
01523 save << clause << ".3) Faces in detail: " << endl;
01524 map <int,int>::iterator itF;
01525 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
01526 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
01527 }
01528 }
01529 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
01530 if ( NbVolumes(order) > 0 ) {
01531 int nb8 = NbHexas(order);
01532 int nb4 = NbTetras(order);
01533 int nb5 = NbPyramids(order);
01534 int nb6 = NbPrisms(order);
01535 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
01536 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
01537 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
01538 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
01539 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
01540 map<int,int> myVolumesMap;
01541 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
01542 while( itVolumes->more( ) ) {
01543 int nbNodes = itVolumes->next()->NbNodes();
01544 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
01545 myVolumesMap[ nbNodes ] = 0;
01546 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
01547 }
01548 save << clause << ".5) Volumes in detail: " << endl;
01549 map <int,int>::iterator itV;
01550 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
01551 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
01552 }
01553 }
01554 save << endl;
01555 }
01556 save << "===========================================================================" << endl;
01557 return save;
01558 }
01559
01560
01561
01562
01563
01564
01565 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
01566 {
01567 return _myMeshDS->GetElementType( id, iselem );
01568 }
01569
01570
01574
01575
01576 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
01577 {
01578 SMESH_Group* aGroup = 0;
01579 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
01580 if ( itg == _mapGroup.end() )
01581 return aGroup;
01582
01583 SMESH_Group* anOldGrp = (*itg).second;
01584 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
01585 if ( !anOldGrp || !anOldGrpDS )
01586 return aGroup;
01587
01588
01589 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
01590 _mapGroup[theGroupID] = aGroup;
01591
01592 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
01593 GetMeshDS()->RemoveGroup( anOldGrpDS );
01594 GetMeshDS()->AddGroup( aNewGrpDS );
01595
01596
01597 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
01598 while ( anItr->more() )
01599 aNewGrpDS->Add( (anItr->next())->GetID() );
01600
01601
01602 delete anOldGrp;
01603
01604 return aGroup;
01605 }
01606
01607
01611
01612
01613 void SMESH_Mesh::ClearMeshOrder()
01614 {
01615 _mySubMeshOrder.clear();
01616 }
01617
01618
01622
01623
01624 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
01625 {
01626 _mySubMeshOrder = theOrder;
01627 }
01628
01629
01633
01634
01635 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
01636 {
01637 return _mySubMeshOrder;
01638 }
01639
01640
01644
01645
01646 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
01647 {
01648
01649 int desType, ancType;
01650 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
01651 {
01652
01653
01654 int memberType = TopoDS_Iterator( theShape ).Value().ShapeType();
01655 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
01656 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
01657 {
01658 if ( !_mapAncestors.Contains( des.Current() )) continue;
01659 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
01660 TopTools_ListIteratorOfListOfShape ancIt (ancList);
01661 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
01662 ancIt.Next();
01663 if ( ancIt.More() )
01664 ancList.InsertBefore( theShape, ancIt );
01665 }
01666 }
01667 {
01668 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
01669 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
01670 TopExp::MapShapesAndAncestors ( theShape,
01671 (TopAbs_ShapeEnum) desType,
01672 (TopAbs_ShapeEnum) ancType,
01673 _mapAncestors );
01674 }
01675 }
01676
01677
01683
01684
01685 bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
01686 {
01687 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
01688 return true;
01689
01690 bool res = false;
01691 list<SMESH_subMesh*> onlyOrderedList;
01692
01693
01694 typedef list<SMESH_subMesh*>::iterator TPosInList;
01695 map< int, TPosInList > sortedPos;
01696 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
01697 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
01698 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
01699 const TListOfInt& listOfId = *listIddIt;
01700 TListOfInt::const_iterator idIt = listOfId.begin();
01701 for ( ; idIt != listOfId.end(); idIt++ ) {
01702 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
01703 TPosInList smPos = find( smBeg, smEnd, sm );
01704 if ( smPos != smEnd ) {
01705 onlyOrderedList.push_back( sm );
01706 sortedPos[ distance( smBeg, smPos )] = smPos;
01707 }
01708 }
01709 }
01710 }
01711 if (onlyOrderedList.size() < 2)
01712 return res;
01713 res = true;
01714
01715 list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
01716 list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
01717
01718
01719 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
01720 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
01721 *(i_pos->second) = *onlyBIt;
01722
01723 return res;
01724 }
01725
01726
01732
01733
01734 list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
01735 (const TopoDS_Shape& theSubShape) const
01736 {
01737 list<SMESH_subMesh*> listOfSubMesh;
01738 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
01739 for (; it.More(); it.Next() )
01740 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
01741 listOfSubMesh.push_back(sm);
01742
01743
01744 SortByMeshOrder( listOfSubMesh );
01745
01746 return listOfSubMesh;
01747 }