1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_Mesh.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh.hxx"
28 #include "SMESH_MesherHelper.hxx"
29 #include "SMDS_MeshVolume.hxx"
30 #include "SMDS_SetIterator.hxx"
31 #include "SMESHDS_Document.hxx"
32 #include "SMESHDS_Group.hxx"
33 #include "SMESHDS_GroupOnGeom.hxx"
34 #include "SMESHDS_Script.hxx"
35 #include "SMESHDS_TSubMeshHolder.hxx"
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_Group.hxx"
38 #include "SMESH_HypoFilter.hxx"
39 #include "SMESH_Hypothesis.hxx"
40 #include "SMESH_subMesh.hxx"
42 #include "utilities.h"
44 #include "DriverDAT_W_SMDS_Mesh.h"
45 #include "DriverGMF_Read.hxx"
46 #include "DriverGMF_Write.hxx"
47 #include "DriverMED_R_SMESHDS_Mesh.h"
48 #include "DriverMED_W_SMESHDS_Mesh.h"
49 #include "DriverSTL_R_SMDS_Mesh.h"
50 #include "DriverSTL_W_SMDS_Mesh.h"
51 #include "DriverUNV_R_SMDS_Mesh.h"
52 #include "DriverUNV_W_SMDS_Mesh.h"
54 #include "DriverCGNS_Read.hxx"
55 #include "DriverCGNS_Write.hxx"
58 #include <GEOMUtils.hxx>
60 #undef _Precision_HeaderFile
61 #include <BRepBndLib.hxx>
62 #include <BRepPrimAPI_MakeBox.hxx>
63 #include <Bnd_Box.hxx>
64 #include <TColStd_MapOfInteger.hxx>
66 #include <TopExp_Explorer.hxx>
67 #include <TopTools_ListIteratorOfListOfShape.hxx>
68 #include <TopTools_ListOfShape.hxx>
69 #include <TopTools_MapOfShape.hxx>
70 #include <TopoDS_Iterator.hxx>
72 #include "SMESH_TryCatch.hxx" // include after OCCT headers!
74 #include "Utils_ExceptHandlers.hxx"
77 #include <boost/thread/thread.hpp>
78 #include <boost/bind.hpp>
85 // maximum stored group name length in MED file
86 #define MAX_MED_GROUP_NAME_LENGTH 80
89 static int MYDEBUG = 0;
91 static int MYDEBUG = 0;
94 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
96 typedef SMESH_HypoFilter THypType;
98 class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
102 //=============================================================================
106 //=============================================================================
108 SMESH_Mesh::SMESH_Mesh(int theLocalId,
111 bool theIsEmbeddedMode,
112 SMESHDS_Document* theDocument):
113 _groupId( 0 ), _nbSubShapes( 0 )
115 if(MYDEBUG) MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
117 _studyId = theStudyId;
119 _myDocument = theDocument;
120 _myMeshDS = theDocument->NewMesh(theIsEmbeddedMode,theLocalId);
121 _isShapeToMesh = false;
122 _isAutoColor = false;
124 _shapeDiagonal = 0.0;
126 _myMeshDS->ShapeToMesh( PseudoShape() );
127 _subMeshHolder = new SubMeshHolder;
130 //================================================================================
132 * \brief Constructor of SMESH_Mesh being a base of some descendant class
134 //================================================================================
136 SMESH_Mesh::SMESH_Mesh():
141 _isShapeToMesh( false ),
145 _isAutoColor( false ),
146 _isModified( false ),
147 _shapeDiagonal( 0.0 ),
150 _subMeshHolder = new SubMeshHolder;
156 void deleteMeshDS(SMESHDS_Mesh* meshDS)
158 //cout << "deleteMeshDS( " << meshDS << endl;
162 static void* deleteMeshDS(void* meshDS)
164 //cout << "deleteMeshDS( " << meshDS << endl;
165 SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
174 //=============================================================================
178 //=============================================================================
180 SMESH_Mesh::~SMESH_Mesh()
182 if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh");
184 // avoid usual removal of elements while processing RemoveHypothesis( algo ) event
185 SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes();
186 while ( smIt->more() )
187 const_cast<SMESHDS_SubMesh*>( smIt->next() )->Clear();
189 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
190 // Notify event listeners at least that something happens
191 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
192 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
195 map < int, SMESH_Group * >::iterator itg;
196 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
197 SMESH_Group *aGroup = (*itg).second;
203 delete _subMeshHolder;
205 if ( _callUp) delete _callUp;
208 // remove self from studyContext
211 StudyContextStruct * studyContext = _gen->GetStudyContext( _studyId );
212 studyContext->mapMesh.erase( _id );
215 _myDocument->RemoveMesh( _id );
219 // delete _myMeshDS, in a thread in order not to block closing a study with large meshes
221 boost::thread aThread(boost::bind( & deleteMeshDS, _myMeshDS ));
224 int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_myMeshDS);
229 //================================================================================
231 * \brief Return true if a mesh with given id exists
233 //================================================================================
235 bool SMESH_Mesh::MeshExists( int meshId ) const
237 return _myDocument ? bool( _myDocument->GetMesh( meshId )) : false;
240 //================================================================================
242 * \brief Return a mesh by id
244 //================================================================================
246 SMESH_Mesh* SMESH_Mesh::FindMesh( int meshId ) const
249 return (SMESH_Mesh*) this;
251 if ( StudyContextStruct *aStudyContext = _gen->GetStudyContext( _studyId ))
253 std::map < int, SMESH_Mesh * >::iterator i_m = aStudyContext->mapMesh.find( meshId );
254 if ( i_m != aStudyContext->mapMesh.end() )
260 //=============================================================================
262 * \brief Set geometry to be meshed
264 //=============================================================================
266 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
268 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
270 if ( !aShape.IsNull() && _isShapeToMesh ) {
271 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
272 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
273 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
275 // clear current data
276 if ( !_myMeshDS->ShapeToMesh().IsNull() )
278 // removal of a shape to mesh, delete objects referring to sub-shapes:
280 _subMeshHolder->DeleteAll();
281 // - groups on geometry
282 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
283 while ( i_gr != _mapGroup.end() ) {
284 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
285 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
287 _mapGroup.erase( i_gr++ );
292 _mapAncestors.Clear();
295 TopoDS_Shape aNullShape;
296 _myMeshDS->ShapeToMesh( aNullShape );
298 _shapeDiagonal = 0.0;
301 // set a new geometry
302 if ( !aShape.IsNull() )
304 _myMeshDS->ShapeToMesh(aShape);
305 _isShapeToMesh = true;
306 _nbSubShapes = _myMeshDS->MaxShapeIndex();
308 // fill map of ancestors
309 fillAncestorsMap(aShape);
313 _isShapeToMesh = false;
314 _shapeDiagonal = 0.0;
315 _myMeshDS->ShapeToMesh( PseudoShape() );
320 //=======================================================================
322 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
324 //=======================================================================
326 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
328 return _myMeshDS->ShapeToMesh();
331 //=======================================================================
333 * \brief Return a solid which is returned by GetShapeToMesh() if
334 * a real geometry to be meshed was not set
336 //=======================================================================
338 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
340 static TopoDS_Solid aSolid;
341 if ( aSolid.IsNull() )
343 aSolid = BRepPrimAPI_MakeBox(1,1,1);
348 //=======================================================================
350 * \brief Return diagonal size of bounding box of a shape
352 //=======================================================================
354 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
356 if ( !aShape.IsNull() ) {
358 // avoid too long waiting on large shapes. PreciseBoundingBox() was added
359 // to assure same result which else depends on presence of triangulation (IPAL52557).
360 const int maxNbFaces = 4000;
362 for ( TopExp_Explorer f( aShape, TopAbs_FACE ); f.More() && nbFaces < maxNbFaces; f.Next() )
364 bool isPrecise = false;
365 if ( nbFaces < maxNbFaces )
367 GEOMUtils::PreciseBoundingBox( aShape, Box );
375 BRepBndLib::Add( aShape, Box );
378 return sqrt( Box.SquareExtent() );
383 //=======================================================================
385 * \brief Return diagonal size of bounding box of shape to mesh
387 //=======================================================================
389 double SMESH_Mesh::GetShapeDiagonalSize() const
391 if ( _shapeDiagonal == 0. && _isShapeToMesh )
392 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
394 return _shapeDiagonal;
397 //================================================================================
399 * \brief Load mesh from study file
401 //================================================================================
403 void SMESH_Mesh::Load()
409 //=======================================================================
411 * \brief Remove all nodes and elements
413 //=======================================================================
415 void SMESH_Mesh::Clear()
417 if ( HasShapeToMesh() ) // remove all nodes and elements
420 _myMeshDS->ClearMesh();
422 // update compute state of submeshes
423 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
425 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
426 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
427 sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
428 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
431 else // remove only nodes/elements computed by algorithms
433 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
435 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
436 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
437 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
438 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
444 //=======================================================================
446 * \brief Remove all nodes and elements of indicated shape
448 //=======================================================================
450 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
452 // clear sub-meshes; get ready to re-compute as a side-effect
453 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
455 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
456 /*complexShapeFirst=*/false);
457 while ( smIt->more() )
460 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
461 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
462 // all other shapes depends on vertices so they are already cleaned
463 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
464 // to recompute even if failed
465 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
470 //=======================================================================
471 //function : UNVToMesh
473 //=======================================================================
475 int SMESH_Mesh::UNVToMesh(const char* theFileName)
477 if ( _isShapeToMesh )
478 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
479 _isShapeToMesh = false;
481 DriverUNV_R_SMDS_Mesh myReader;
482 myReader.SetMesh(_myMeshDS);
483 myReader.SetFile(theFileName);
484 myReader.SetMeshId(-1);
487 if ( SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup() )
489 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
490 aGroup->InitSubGroupsIterator();
491 while (aGroup->MoreSubGroups())
493 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
494 string aName = aGroupNames[aSubGroup];
496 if ( SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId ))
498 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
500 aGroupDS->SetStoreName(aName.c_str());
501 aSubGroup->InitIterator();
502 const SMDS_MeshElement* aElement = 0;
503 while ( aSubGroup->More() )
504 if (( aElement = aSubGroup->Next() ))
505 aGroupDS->SMDSGroup().Add( aElement );
508 aGroupDS->SetType( aElement->GetType() );
516 //=======================================================================
517 //function : MEDToMesh
519 //=======================================================================
521 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
523 if ( _isShapeToMesh )
524 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
525 _isShapeToMesh = false;
527 DriverMED_R_SMESHDS_Mesh myReader;
528 myReader.SetMesh(_myMeshDS);
529 myReader.SetMeshId(-1);
530 myReader.SetFile(theFileName);
531 myReader.SetMeshName(theMeshName);
532 Driver_Mesh::Status status = myReader.Perform();
534 SMESH_ComputeErrorPtr er = myReader.GetError();
535 if ( er && !er->IsOK() ) cout << er->myComment << endl;
538 // Reading groups (sub-meshes are out of scope of MED import functionality)
539 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
541 list<TNameAndType>::iterator name_type = aGroupNames.begin();
542 for ( ; name_type != aGroupNames.end(); name_type++ )
544 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
546 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
548 aGroupDS->SetStoreName( name_type->first.c_str() );
549 myReader.GetGroup( aGroupDS );
556 //=======================================================================
557 //function : STLToMesh
559 //=======================================================================
561 int SMESH_Mesh::STLToMesh(const char* theFileName)
564 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
565 _isShapeToMesh = false;
567 DriverSTL_R_SMDS_Mesh myReader;
568 myReader.SetMesh(_myMeshDS);
569 myReader.SetFile(theFileName);
570 myReader.SetMeshId(-1);
576 //================================================================================
578 * \brief Reads the given mesh from the CGNS file
579 * \param theFileName - name of the file
580 * \retval int - Driver_Mesh::Status
582 //================================================================================
584 int SMESH_Mesh::CGNSToMesh(const char* theFileName,
585 const int theMeshIndex,
586 std::string& theMeshName)
588 int res = Driver_Mesh::DRS_FAIL;
591 DriverCGNS_Read myReader;
592 myReader.SetMesh(_myMeshDS);
593 myReader.SetFile(theFileName);
594 myReader.SetMeshId(theMeshIndex);
595 res = myReader.Perform();
596 theMeshName = myReader.GetMeshName();
605 //================================================================================
607 * \brief Fill its data by reading a GMF file
609 //================================================================================
611 SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
612 bool theMakeRequiredGroups)
614 DriverGMF_Read myReader;
615 myReader.SetMesh(_myMeshDS);
616 myReader.SetFile(theFileName);
617 myReader.SetMakeRequiredGroups( theMakeRequiredGroups );
619 //theMeshName = myReader.GetMeshName();
624 return myReader.GetError();
627 //=============================================================================
631 //=============================================================================
633 SMESH_Hypothesis::Hypothesis_Status
634 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
636 std::string* anError ) throw(SALOME_Exception)
638 Unexpect aCatch(SalomeException);
639 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
644 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
645 if ( !subMesh || !subMesh->GetId())
646 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
648 SMESH_Hypothesis *anHyp = GetHypothesis( anHypId );
650 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
652 bool isGlobalHyp = IsMainShape( aSubShape );
654 // NotConformAllowed can be only global
657 // NOTE: this is not a correct way to check a name of hypothesis,
658 // there should be an attribute of hypothesis saying that it can/can't
660 string hypName = anHyp->GetName();
661 if ( hypName == "NotConformAllowed" )
663 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
664 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
670 bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
671 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
673 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
675 if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() )
676 *anError = subMesh->GetComputeError()->myComment;
679 if ( !SMESH_Hypothesis::IsStatusFatal(ret) &&
680 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
682 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
684 SMESH_Hypothesis::Hypothesis_Status ret2 =
685 subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true);
689 if ( SMESH_Hypothesis::IsStatusFatal( ret ))
691 if ( anError && subMesh->GetComputeError() )
692 *anError = subMesh->GetComputeError()->myComment;
694 event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
695 subMesh->AlgoStateEngine(event, anHyp);
699 // check concurent hypotheses on ancestors
700 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
702 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
703 while ( smIt->more() ) {
704 SMESH_subMesh* sm = smIt->next();
705 if ( sm->IsApplicableHypotesis( anHyp )) {
706 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
715 HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
717 if(MYDEBUG) subMesh->DumpAlgoState(true);
718 if(MYDEBUG) SCRUTE(ret);
722 //=============================================================================
726 //=============================================================================
728 SMESH_Hypothesis::Hypothesis_Status
729 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
730 int anHypId) throw( SALOME_Exception )
732 Unexpect aCatch(SalomeException);
733 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
735 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
736 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
737 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
739 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
740 if(MYDEBUG) { SCRUTE(anHyp->GetType()); }
744 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
745 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
747 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
749 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
751 // there may appear concurrent hyps that were covered by the removed hyp
752 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
753 subMesh->IsApplicableHypotesis( anHyp ) &&
754 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
755 ret = SMESH_Hypothesis::HYP_CONCURENT;
758 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
759 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
761 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
763 SMESH_Hypothesis::Hypothesis_Status ret2 =
764 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
765 if (ret2 > ret) // more severe
768 // check concurent hypotheses on ancestors
769 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
771 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
772 while ( smIt->more() ) {
773 SMESH_subMesh* sm = smIt->next();
774 if ( sm->IsApplicableHypotesis( anHyp )) {
775 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
785 HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
787 if(MYDEBUG) subMesh->DumpAlgoState(true);
788 if(MYDEBUG) SCRUTE(ret);
792 //=============================================================================
796 //=============================================================================
798 const list<const SMESHDS_Hypothesis*>&
799 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
800 throw(SALOME_Exception)
802 return _myMeshDS->GetHypothesis(aSubShape);
805 //=======================================================================
807 * \brief Return the hypothesis assigned to the shape
808 * \param aSubShape - the shape to check
809 * \param aFilter - the hypothesis filter
810 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
811 * \param assignedTo - to return the shape the found hypo is assigned to
812 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
814 //=======================================================================
816 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
817 const SMESH_HypoFilter& aFilter,
818 const bool andAncestors,
819 TopoDS_Shape* assignedTo) const
821 return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
822 aFilter, andAncestors, assignedTo );
825 //=======================================================================
827 * \brief Return the hypothesis assigned to the shape of a sub-mesh
828 * \param aSubMesh - the sub-mesh to check
829 * \param aFilter - the hypothesis filter
830 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
831 * \param assignedTo - to return the shape the found hypo is assigned to
832 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
834 //=======================================================================
836 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh * aSubMesh,
837 const SMESH_HypoFilter& aFilter,
838 const bool andAncestors,
839 TopoDS_Shape* assignedTo) const
841 if ( !aSubMesh ) return 0;
844 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
845 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
846 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
847 for ( ; hyp != hypList.end(); hyp++ ) {
848 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
849 if ( aFilter.IsOk( h, aSubShape)) {
850 if ( assignedTo ) *assignedTo = aSubShape;
857 // user sorted submeshes of ancestors, according to stored submesh priority
858 std::vector< SMESH_subMesh * > & ancestors =
859 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
860 SortByMeshOrder( ancestors );
862 vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
863 for ( ; smIt != ancestors.end(); smIt++ )
865 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
866 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
867 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
868 for ( ; hyp != hypList.end(); hyp++ ) {
869 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
870 if (aFilter.IsOk( h, curSh )) {
871 if ( assignedTo ) *assignedTo = curSh;
880 //================================================================================
882 * \brief Return hypotheses assigned to the shape
883 * \param aSubShape - the shape to check
884 * \param aFilter - the hypothesis filter
885 * \param aHypList - the list of the found hypotheses
886 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
887 * \retval int - number of unique hypos in aHypList
889 //================================================================================
891 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
892 const SMESH_HypoFilter& aFilter,
893 list <const SMESHDS_Hypothesis * >& aHypList,
894 const bool andAncestors,
895 list< TopoDS_Shape > * assignedTo/*=0*/) const
897 return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
898 aFilter, aHypList, andAncestors, assignedTo );
901 //================================================================================
903 * \brief Return hypotheses assigned to the shape of a sub-mesh
904 * \param aSubShape - the sub-mesh to check
905 * \param aFilter - the hypothesis filter
906 * \param aHypList - the list of the found hypotheses
907 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
908 * \retval int - number of unique hypos in aHypList
910 //================================================================================
912 int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh,
913 const SMESH_HypoFilter& aFilter,
914 list <const SMESHDS_Hypothesis * >& aHypList,
915 const bool andAncestors,
916 list< TopoDS_Shape > * assignedTo/*=0*/) const
918 if ( !aSubMesh ) return 0;
920 set<string> hypTypes; // to exclude same type hypos from the result list
923 // only one main hypothesis is allowed
924 bool mainHypFound = false;
927 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
928 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
929 if ( hypTypes.insert( (*hyp)->GetName() ).second )
931 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
935 // get hypos from aSubShape
937 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
938 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
939 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
941 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
942 if (( aFilter.IsOk( h, aSubShape )) &&
943 ( h->IsAuxiliary() || !mainHypFound ) &&
944 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
946 aHypList.push_back( *hyp );
948 if ( !h->IsAuxiliary() )
950 if ( assignedTo ) assignedTo->push_back( aSubShape );
955 // get hypos from ancestors of aSubShape
958 // user sorted submeshes of ancestors, according to stored submesh priority
959 std::vector< SMESH_subMesh * > & ancestors =
960 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
961 SortByMeshOrder( ancestors );
963 vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
964 for ( ; smIt != ancestors.end(); smIt++ )
966 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
967 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
968 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
970 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
971 if (( aFilter.IsOk( h, curSh )) &&
972 ( h->IsAuxiliary() || !mainHypFound ) &&
973 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
975 aHypList.push_back( *hyp );
977 if ( !h->IsAuxiliary() )
979 if ( assignedTo ) assignedTo->push_back( curSh );
987 //================================================================================
989 * \brief Return a hypothesis by its ID
991 //================================================================================
993 SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const int anHypId) const
995 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
996 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
999 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
1003 //=============================================================================
1007 //=============================================================================
1009 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
1011 Unexpect aCatch(SalomeException);
1012 return _myMeshDS->GetScript()->GetCommands();
1015 //=============================================================================
1019 //=============================================================================
1020 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
1022 Unexpect aCatch(SalomeException);
1023 _myMeshDS->GetScript()->Clear();
1026 //=============================================================================
1028 * Get or Create the SMESH_subMesh object implementation
1030 //=============================================================================
1032 SMESH_subMesh * SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
1033 throw(SALOME_Exception)
1035 int index = _myMeshDS->ShapeToIndex(aSubShape);
1036 if ( !index && aSubShape.IsNull() )
1039 // for submeshes on GEOM Group
1040 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND )
1042 TopoDS_Iterator it( aSubShape );
1045 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
1046 // fill map of Ancestors
1047 while ( _nbSubShapes < index )
1048 fillAncestorsMap( _myMeshDS->IndexToShape( ++_nbSubShapes ));
1052 // return NULL; // neither sub-shape nor a group
1054 SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index );
1057 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
1058 _subMeshHolder->Add( index, aSubMesh );
1060 // include non-computable sub-meshes in SMESH_subMesh::_ancestors of sub-submeshes
1061 switch ( aSubShape.ShapeType() ) {
1062 case TopAbs_COMPOUND:
1065 for ( TopoDS_Iterator subIt( aSubShape ); subIt.More(); subIt.Next() )
1067 SMESH_subMesh* sm = GetSubMesh( subIt.Value() );
1068 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*inclideSelf=*/true);
1069 while ( smIt->more() )
1070 smIt->next()->ClearAncestors();
1078 //=============================================================================
1080 * Get the SMESH_subMesh object implementation. Dont create it, return null
1081 * if it does not exist.
1083 //=============================================================================
1085 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
1086 throw(SALOME_Exception)
1088 int index = _myMeshDS->ShapeToIndex(aSubShape);
1089 return GetSubMeshContaining( index );
1092 //=============================================================================
1094 * Get the SMESH_subMesh object implementation. Dont create it, return null
1095 * if it does not exist.
1097 //=============================================================================
1099 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
1100 throw(SALOME_Exception)
1102 SMESH_subMesh *aSubMesh = _subMeshHolder->Get( aShapeID );
1107 //================================================================================
1109 * \brief Return sub-meshes of groups containing the given sub-shape
1111 //================================================================================
1113 list<SMESH_subMesh*>
1114 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
1115 throw(SALOME_Exception)
1117 list<SMESH_subMesh*> found;
1119 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
1123 // sub-meshes of groups have max IDs, so search from the map end
1124 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator( /*reverse=*/true ) );
1125 while ( smIt->more() ) {
1126 SMESH_subMesh* sm = smIt->next();
1127 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
1128 if ( ds && ds->IsComplexSubmesh() ) {
1129 if ( SMESH_MesherHelper::IsSubShape( aSubShape, sm->GetSubShape() ))
1131 found.push_back( sm );
1135 break; // the rest sub-meshes are not those of groups
1139 if ( found.empty() ) // maybe the main shape is a COMPOUND (issue 0021530)
1141 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1142 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1144 TopoDS_Iterator it( mainSM->GetSubShape() );
1145 if ( it.Value().ShapeType() == aSubShape.ShapeType() &&
1146 SMESH_MesherHelper::IsSubShape( aSubShape, mainSM->GetSubShape() ))
1147 found.push_back( mainSM );
1150 else // issue 0023068
1152 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1153 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1154 found.push_back( mainSM );
1158 //=======================================================================
1159 //function : IsUsedHypothesis
1160 //purpose : Return True if anHyp is used to mesh aSubShape
1161 //=======================================================================
1163 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
1164 const SMESH_subMesh* aSubMesh)
1166 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
1168 // check if anHyp can be used to mesh aSubMesh
1169 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
1172 SMESH_Algo *algo = aSubMesh->GetAlgo();
1175 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
1176 return ( anHyp == algo );
1178 // algorithm parameter
1181 // look trough hypotheses used by algo
1182 const SMESH_HypoFilter* hypoKind;
1183 if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
1184 list <const SMESHDS_Hypothesis * > usedHyps;
1185 if ( GetHypotheses( aSubMesh, *hypoKind, usedHyps, true ))
1186 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
1193 //=======================================================================
1194 //function : NotifySubMeshesHypothesisModification
1195 //purpose : Say all submeshes using theChangedHyp that it has been modified
1196 //=======================================================================
1198 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
1200 Unexpect aCatch(SalomeException);
1202 if ( !GetMeshDS()->IsUsedHypothesis( hyp ))
1206 _callUp->HypothesisModified();
1209 const SMESH_HypoFilter* compatibleHypoKind;
1210 list <const SMESHDS_Hypothesis * > usedHyps;
1212 // keep sub-meshes not to miss ones whose state can change due to notifying others
1213 vector< SMESH_subMesh* > smToNotify;
1215 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1216 while ( smIt->more() )
1218 SMESH_subMesh* aSubMesh = smIt->next();
1220 // if aSubMesh meshing depends on hyp,
1221 // we call aSubMesh->AlgoStateEngine( MODIF_HYP, hyp ) that causes either
1222 // 1) clearing already computed aSubMesh or
1223 // 2) changing algo_state from MISSING_HYP to HYP_OK when parameters of hyp becomes valid,
1224 // other possible changes are not interesting. (IPAL0052457 - assigning hyp performance pb)
1225 if ( aSubMesh->GetComputeState() != SMESH_subMesh::COMPUTE_OK &&
1226 aSubMesh->GetComputeState() != SMESH_subMesh::FAILED_TO_COMPUTE &&
1227 aSubMesh->GetAlgoState() != SMESH_subMesh::MISSING_HYP &&
1228 !hyp->DataDependOnParams() )
1231 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
1233 if (( aSubMesh->IsApplicableHypotesis( hyp )) &&
1234 ( algo = aSubMesh->GetAlgo() ) &&
1235 ( compatibleHypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() )) &&
1236 ( compatibleHypoKind->IsOk( hyp, aSubShape )))
1238 // check if hyp is used by algo
1240 if ( GetHypotheses( aSubMesh, *compatibleHypoKind, usedHyps, true ) &&
1241 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
1243 smToNotify.push_back( aSubMesh );
1248 for ( size_t i = 0; i < smToNotify.size(); ++i )
1250 smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
1251 const_cast< SMESH_Hypothesis*>( hyp ));
1254 HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
1255 GetMeshDS()->Modified();
1258 //=============================================================================
1260 * Auto color functionality
1262 //=============================================================================
1263 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1265 Unexpect aCatch(SalomeException);
1266 _isAutoColor = theAutoColor;
1269 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1271 Unexpect aCatch(SalomeException);
1272 return _isAutoColor;
1275 //=======================================================================
1276 //function : SetIsModified
1277 //purpose : Set the flag meaning that the mesh has been edited "manually"
1278 //=======================================================================
1280 void SMESH_Mesh::SetIsModified(bool isModified)
1282 _isModified = isModified;
1285 // check if mesh becomes empty as result of modification
1286 HasModificationsToDiscard();
1289 //=======================================================================
1290 //function : HasModificationsToDiscard
1291 //purpose : Return true if the mesh has been edited since a total re-compute
1292 // and those modifications may prevent successful partial re-compute.
1293 // As a side effect reset _isModified flag if mesh is empty
1295 //=======================================================================
1297 bool SMESH_Mesh::HasModificationsToDiscard() const
1299 if ( ! _isModified )
1302 // return true if the next Compute() will be partial and
1303 // existing but changed elements may prevent successful re-compute
1304 bool hasComputed = false, hasNotComputed = false;
1305 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1306 while ( smIt->more() )
1308 const SMESH_subMesh* aSubMesh = smIt->next();
1309 switch ( aSubMesh->GetSubShape().ShapeType() )
1314 if ( aSubMesh->IsMeshComputed() )
1317 hasNotComputed = true;
1318 if ( hasComputed && hasNotComputed)
1324 if ( NbNodes() < 1 )
1325 const_cast<SMESH_Mesh*>(this)->_isModified = false;
1330 //================================================================================
1332 * \brief Check if any groups of the same type have equal names
1334 //================================================================================
1336 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1338 // Corrected for Mantis issue 0020028
1339 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1340 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1342 SMESH_Group* aGroup = it->second;
1343 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1344 string aGroupName = aGroup->GetName();
1345 aGroupName.resize( MAX_MED_GROUP_NAME_LENGTH );
1346 if ( !aGroupNames[aType].insert(aGroupName).second )
1353 //================================================================================
1355 * \brief Export the mesh to a med file
1356 * \param [in] file - name of the MED file
1357 * \param [in] theMeshName - name of this mesh
1358 * \param [in] theAutoGroups - boolean parameter for creating/not creating
1359 * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1360 * the typical use is auto_groups=false.
1361 * \param [in] theVersion - defines the version of format of MED file, that will be created
1362 * \param [in] meshPart - mesh data to export
1363 * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
1364 * - 1D if all mesh nodes lie on OX coordinate axis, or
1365 * - 2D if all mesh nodes lie on XOY coordinate plane, or
1366 * - 3D in the rest cases.
1367 * If \a theAutoDimension is \c false, the space dimension is always 3.
1368 * \return int - mesh index in the file
1370 //================================================================================
1372 void SMESH_Mesh::ExportMED(const char * file,
1373 const char* theMeshName,
1376 const SMESHDS_Mesh* meshPart,
1377 bool theAutoDimension,
1378 bool theAddODOnVertices)
1379 throw(SALOME_Exception)
1383 DriverMED_W_SMESHDS_Mesh myWriter;
1384 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1385 myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1386 myWriter.SetAutoDimension( theAutoDimension );
1387 myWriter.AddODOnVertices ( theAddODOnVertices );
1389 myWriter.SetMeshId ( _id );
1391 myWriter.SetMeshId ( -1 );
1392 myWriter.SetMeshName ( theMeshName );
1395 if ( theAutoGroups ) {
1396 myWriter.AddGroupOfNodes();
1397 myWriter.AddGroupOfEdges();
1398 myWriter.AddGroupOfFaces();
1399 myWriter.AddGroupOfVolumes();
1402 // Pass groups to writer. Provide unique group names.
1403 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1406 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1408 int maxNbIter = 10000; // to guarantee cycle finish
1409 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1410 SMESH_Group* aGroup = it->second;
1411 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1413 SMDSAbs_ElementType aType = aGroupDS->GetType();
1414 string aGroupName0 = aGroup->GetName();
1415 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1416 string aGroupName = aGroupName0;
1417 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1418 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1419 aGroupName = aString;
1420 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1422 aGroupDS->SetStoreName( aGroupName.c_str() );
1423 myWriter.AddGroup( aGroupDS );
1430 SMESH_CATCH( SMESH::throwSalomeEx );
1433 //================================================================================
1435 * \brief Export the mesh to a SAUV file
1437 //================================================================================
1439 void SMESH_Mesh::ExportSAUV(const char *file,
1440 const char* theMeshName,
1442 throw(SALOME_Exception)
1444 std::string medfilename(file);
1445 medfilename += ".med";
1448 cmd = "%PYTHONBIN% ";
1453 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1455 system(cmd.c_str());
1456 ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, 1);
1458 cmd = "%PYTHONBIN% ";
1463 cmd += "from medutilities import convert ; convert(r'" + medfilename + "', 'MED', 'GIBI', 1, r'" + file + "')";
1465 system(cmd.c_str());
1467 cmd = "%PYTHONBIN% ";
1472 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1474 system(cmd.c_str());
1477 //================================================================================
1479 * \brief Export the mesh to a DAT file
1481 //================================================================================
1483 void SMESH_Mesh::ExportDAT(const char * file,
1484 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1486 Unexpect aCatch(SalomeException);
1487 DriverDAT_W_SMDS_Mesh myWriter;
1488 myWriter.SetFile( file );
1489 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1490 myWriter.SetMeshId(_id);
1494 //================================================================================
1496 * \brief Export the mesh to an UNV file
1498 //================================================================================
1500 void SMESH_Mesh::ExportUNV(const char * file,
1501 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1503 Unexpect aCatch(SalomeException);
1504 DriverUNV_W_SMDS_Mesh myWriter;
1505 myWriter.SetFile( file );
1506 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1507 myWriter.SetMeshId(_id);
1508 // myWriter.SetGroups(_mapGroup);
1512 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1513 SMESH_Group* aGroup = it->second;
1514 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1516 string aGroupName = aGroup->GetName();
1517 aGroupDS->SetStoreName( aGroupName.c_str() );
1518 myWriter.AddGroup( aGroupDS );
1525 //================================================================================
1527 * \brief Export the mesh to an STL file
1529 //================================================================================
1531 void SMESH_Mesh::ExportSTL(const char * file,
1533 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1535 Unexpect aCatch(SalomeException);
1536 DriverSTL_W_SMDS_Mesh myWriter;
1537 myWriter.SetFile( file );
1538 myWriter.SetIsAscii( isascii );
1539 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
1540 myWriter.SetMeshId(_id);
1544 //================================================================================
1546 * \brief Export the mesh to the CGNS file
1548 //================================================================================
1550 void SMESH_Mesh::ExportCGNS(const char * file,
1551 const SMESHDS_Mesh* meshDS,
1552 const char * meshName)
1554 int res = Driver_Mesh::DRS_FAIL;
1556 DriverCGNS_Write myWriter;
1557 myWriter.SetFile( file );
1558 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1559 myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
1560 if ( meshName && meshName[0] )
1561 myWriter.SetMeshName( meshName );
1562 res = myWriter.Perform();
1564 if ( res != Driver_Mesh::DRS_OK )
1565 throw SALOME_Exception("Export failed");
1568 //================================================================================
1570 * \brief Export the mesh to a GMF file
1572 //================================================================================
1574 void SMESH_Mesh::ExportGMF(const char * file,
1575 const SMESHDS_Mesh* meshDS,
1576 bool withRequiredGroups)
1578 DriverGMF_Write myWriter;
1579 myWriter.SetFile( file );
1580 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1581 myWriter.SetExportRequiredGroups( withRequiredGroups );
1586 //================================================================================
1588 * \brief Return a ratio of "compute cost" of computed sub-meshes to the whole
1591 //================================================================================
1593 double SMESH_Mesh::GetComputeProgress() const
1595 double totalCost = 1e-100, computedCost = 0;
1596 const SMESH_subMesh* curSM = _gen->GetCurrentSubMesh();
1598 // get progress of a current algo
1599 TColStd_MapOfInteger currentSubIds;
1601 if ( SMESH_Algo* algo = curSM->GetAlgo() )
1603 int algoNotDoneCost = 0, algoDoneCost = 0;
1604 const std::vector<SMESH_subMesh*>& smToCompute = algo->SubMeshesToCompute();
1605 for ( size_t i = 0; i < smToCompute.size(); ++i )
1607 if ( smToCompute[i]->IsEmpty() || smToCompute.size() == 1 )
1608 algoNotDoneCost += smToCompute[i]->GetComputeCost();
1610 algoDoneCost += smToCompute[i]->GetComputeCost();
1611 currentSubIds.Add( smToCompute[i]->GetId() );
1617 rate = algo->GetProgress();
1621 cerr << "Exception in " << algo->GetName() << "::GetProgress()" << endl;
1624 if ( 0. < rate && rate < 1.001 )
1626 computedCost += rate * ( algoDoneCost + algoNotDoneCost );
1630 rate = algo->GetProgressByTic();
1631 computedCost += algoDoneCost + rate * algoNotDoneCost;
1633 // cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
1636 // get cost of already treated sub-meshes
1637 if ( SMESH_subMesh* mainSM = GetSubMeshContaining( 1 ))
1639 SMESH_subMeshIteratorPtr smIt = mainSM->getDependsOnIterator(/*includeSelf=*/true);
1640 while ( smIt->more() )
1642 const SMESH_subMesh* sm = smIt->next();
1643 const int smCost = sm->GetComputeCost();
1644 totalCost += smCost;
1645 if ( !currentSubIds.Contains( sm->GetId() ) )
1647 if (( !sm->IsEmpty() ) ||
1648 ( sm->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
1649 !sm->DependsOn( curSM ) ))
1650 computedCost += smCost;
1654 // cout << "Total: " << totalCost
1655 // << " computed: " << computedCost << " progress: " << computedCost / totalCost
1656 // << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
1657 return computedCost / totalCost;
1660 //================================================================================
1662 * \brief Return number of nodes in the mesh
1664 //================================================================================
1666 int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
1668 Unexpect aCatch(SalomeException);
1669 return _myMeshDS->NbNodes();
1672 //================================================================================
1674 * \brief Return number of edges of given order in the mesh
1676 //================================================================================
1678 int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
1680 Unexpect aCatch(SalomeException);
1681 return _myMeshDS->GetMeshInfo().Nb0DElements();
1684 //================================================================================
1686 * \brief Return number of edges of given order in the mesh
1688 //================================================================================
1690 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1692 Unexpect aCatch(SalomeException);
1693 return _myMeshDS->GetMeshInfo().NbEdges(order);
1696 //================================================================================
1698 * \brief Return number of faces of given order in the mesh
1700 //================================================================================
1702 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1704 Unexpect aCatch(SalomeException);
1705 return _myMeshDS->GetMeshInfo().NbFaces(order);
1708 //================================================================================
1710 * \brief Return the number of faces in the mesh
1712 //================================================================================
1714 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1716 Unexpect aCatch(SalomeException);
1717 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1720 //================================================================================
1722 * \brief Return number of biquadratic triangles in the mesh
1724 //================================================================================
1726 int SMESH_Mesh::NbBiQuadTriangles() const throw(SALOME_Exception)
1728 Unexpect aCatch(SalomeException);
1729 return _myMeshDS->GetMeshInfo().NbBiQuadTriangles();
1732 //================================================================================
1734 * \brief Return the number nodes faces in the mesh
1736 //================================================================================
1738 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1740 Unexpect aCatch(SalomeException);
1741 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1744 //================================================================================
1746 * \brief Return number of biquadratic quadrangles in the mesh
1748 //================================================================================
1750 int SMESH_Mesh::NbBiQuadQuadrangles() const throw(SALOME_Exception)
1752 Unexpect aCatch(SalomeException);
1753 return _myMeshDS->GetMeshInfo().NbBiQuadQuadrangles();
1756 //================================================================================
1758 * \brief Return the number of polygonal faces in the mesh
1760 //================================================================================
1762 int SMESH_Mesh::NbPolygons(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1764 Unexpect aCatch(SalomeException);
1765 return _myMeshDS->GetMeshInfo().NbPolygons(order);
1768 //================================================================================
1770 * \brief Return number of volumes of given order in the mesh
1772 //================================================================================
1774 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1776 Unexpect aCatch(SalomeException);
1777 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1780 //================================================================================
1782 * \brief Return number of tetrahedrons of given order in the mesh
1784 //================================================================================
1786 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1788 Unexpect aCatch(SalomeException);
1789 return _myMeshDS->GetMeshInfo().NbTetras(order);
1792 //================================================================================
1794 * \brief Return number of hexahedrons of given order in the mesh
1796 //================================================================================
1798 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1800 Unexpect aCatch(SalomeException);
1801 return _myMeshDS->GetMeshInfo().NbHexas(order);
1804 //================================================================================
1806 * \brief Return number of triquadratic hexahedrons in the mesh
1808 //================================================================================
1810 int SMESH_Mesh::NbTriQuadraticHexas() const throw(SALOME_Exception)
1812 Unexpect aCatch(SalomeException);
1813 return _myMeshDS->GetMeshInfo().NbTriQuadHexas();
1816 //================================================================================
1818 * \brief Return number of pyramids of given order in the mesh
1820 //================================================================================
1822 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1824 Unexpect aCatch(SalomeException);
1825 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1828 //================================================================================
1830 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1832 //================================================================================
1834 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1836 Unexpect aCatch(SalomeException);
1837 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1840 //================================================================================
1842 * \brief Return number of hexagonal prisms in the mesh
1844 //================================================================================
1846 int SMESH_Mesh::NbHexagonalPrisms() const throw(SALOME_Exception)
1848 Unexpect aCatch(SalomeException);
1849 return _myMeshDS->GetMeshInfo().NbHexPrisms();
1852 //================================================================================
1854 * \brief Return number of polyhedrons in the mesh
1856 //================================================================================
1858 int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
1860 Unexpect aCatch(SalomeException);
1861 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1864 //================================================================================
1866 * \brief Return number of ball elements in the mesh
1868 //================================================================================
1870 int SMESH_Mesh::NbBalls() const throw(SALOME_Exception)
1872 Unexpect aCatch(SalomeException);
1873 return _myMeshDS->GetMeshInfo().NbBalls();
1876 //================================================================================
1878 * \brief Return number of submeshes in the mesh
1880 //================================================================================
1882 int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
1884 Unexpect aCatch(SalomeException);
1885 return _myMeshDS->NbSubMesh();
1888 //================================================================================
1890 * \brief Returns number of meshes in the Study, that is supposed to be
1891 * equal to SMESHDS_Document::NbMeshes()
1893 //================================================================================
1895 int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
1897 return _myDocument->NbMeshes();
1900 //=======================================================================
1901 //function : IsNotConformAllowed
1902 //purpose : check if a hypothesis alowing notconform mesh is present
1903 //=======================================================================
1905 bool SMESH_Mesh::IsNotConformAllowed() const
1907 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1909 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1910 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1913 //=======================================================================
1914 //function : IsMainShape
1916 //=======================================================================
1918 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1920 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1923 //=============================================================================
1927 //=============================================================================
1929 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1930 const char* theName,
1932 const TopoDS_Shape& theShape,
1933 const SMESH_PredicatePtr& thePredicate)
1935 if (_mapGroup.count(_groupId))
1938 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
1939 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1940 _mapGroup[_groupId++] = aGroup;
1944 //================================================================================
1946 * \brief Creates a group based on an existing SMESHDS group. Group ID should be unique
1948 //================================================================================
1950 SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
1953 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
1955 map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
1956 if ( i_g != _mapGroup.end() && i_g->second )
1958 if ( i_g->second->GetGroupDS() == groupDS )
1961 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup() wrong ID of SMESHDS_GroupBase"));
1963 SMESH_Group* aGroup = new SMESH_Group (groupDS);
1964 _mapGroup[ groupDS->GetID() ] = aGroup;
1965 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1967 _groupId = 1 + _mapGroup.rbegin()->first;
1973 //================================================================================
1975 * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
1976 * \retval bool - true if new SMESH_Groups have been created
1979 //================================================================================
1981 bool SMESH_Mesh::SynchronizeGroups()
1983 const size_t nbGroups = _mapGroup.size();
1984 const set<SMESHDS_GroupBase*>& groups = _myMeshDS->GetGroups();
1985 set<SMESHDS_GroupBase*>::const_iterator gIt = groups.begin();
1986 for ( ; gIt != groups.end(); ++gIt )
1988 SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt;
1989 _groupId = groupDS->GetID();
1990 if ( !_mapGroup.count( _groupId ))
1991 _mapGroup[_groupId] = new SMESH_Group( groupDS );
1993 if ( !_mapGroup.empty() )
1994 _groupId = _mapGroup.rbegin()->first + 1;
1996 return nbGroups < _mapGroup.size();
1999 //================================================================================
2001 * \brief Return iterator on all existing groups
2003 //================================================================================
2005 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
2007 typedef map <int, SMESH_Group *> TMap;
2008 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
2011 //=============================================================================
2013 * \brief Return a group by ID
2015 //=============================================================================
2017 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
2019 if (_mapGroup.find(theGroupID) == _mapGroup.end())
2021 return _mapGroup[theGroupID];
2025 //=============================================================================
2027 * \brief Return IDs of all groups
2029 //=============================================================================
2031 list<int> SMESH_Mesh::GetGroupIds() const
2034 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
2035 anIds.push_back( it->first );
2040 //================================================================================
2042 * \brief Set a caller of methods at level of CORBA API implementation.
2043 * The set upCaller will be deleted by SMESH_Mesh
2045 //================================================================================
2047 void SMESH_Mesh::SetCallUp( TCallUp* upCaller )
2049 if ( _callUp ) delete _callUp;
2053 //=============================================================================
2057 //=============================================================================
2059 bool SMESH_Mesh::RemoveGroup( const int theGroupID )
2061 if (_mapGroup.find(theGroupID) == _mapGroup.end())
2063 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
2064 delete _mapGroup[theGroupID];
2065 _mapGroup.erase (theGroupID);
2067 _callUp->RemoveGroup( theGroupID );
2071 //=======================================================================
2072 //function : GetAncestors
2073 //purpose : return list of ancestors of theSubShape in the order
2074 // that lower dimention shapes come first.
2075 //=======================================================================
2077 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
2079 if ( _mapAncestors.Contains( theS ) )
2080 return _mapAncestors.FindFromKey( theS );
2082 static TopTools_ListOfShape emptyList;
2086 //=======================================================================
2088 //purpose : dumps contents of mesh to stream [ debug purposes ]
2089 //=======================================================================
2091 ostream& SMESH_Mesh::Dump(ostream& save)
2094 save << "========================== Dump contents of mesh ==========================" << endl << endl;
2095 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
2096 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
2097 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
2098 save << ++clause << ") Total number of polygons: \t" << NbPolygons() << endl;
2099 save << ++clause << ") Total number of volumes: \t" << NbVolumes() << endl;
2100 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
2101 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
2103 string orderStr = isQuadratic ? "quadratic" : "linear";
2104 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
2106 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
2107 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
2108 if ( NbFaces(order) > 0 ) {
2109 int nb3 = NbTriangles(order);
2110 int nb4 = NbQuadrangles(order);
2111 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
2112 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
2113 if ( nb3 + nb4 != NbFaces(order) ) {
2114 map<int,int> myFaceMap;
2115 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
2116 while( itFaces->more( ) ) {
2117 int nbNodes = itFaces->next()->NbNodes();
2118 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
2119 myFaceMap[ nbNodes ] = 0;
2120 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
2122 save << clause << ".3) Faces in detail: " << endl;
2123 map <int,int>::iterator itF;
2124 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
2125 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
2128 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
2129 if ( NbVolumes(order) > 0 ) {
2130 int nb8 = NbHexas(order);
2131 int nb4 = NbTetras(order);
2132 int nb5 = NbPyramids(order);
2133 int nb6 = NbPrisms(order);
2134 save << clause << ".1) Number of " << orderStr << " hexahedrons: \t" << nb8 << endl;
2135 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
2136 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
2137 save << clause << ".4) Number of " << orderStr << " pyramids: \t" << nb5 << endl;
2138 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
2139 map<int,int> myVolumesMap;
2140 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
2141 while( itVolumes->more( ) ) {
2142 int nbNodes = itVolumes->next()->NbNodes();
2143 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
2144 myVolumesMap[ nbNodes ] = 0;
2145 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
2147 save << clause << ".5) Volumes in detail: " << endl;
2148 map <int,int>::iterator itV;
2149 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
2150 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
2155 save << "===========================================================================" << endl;
2159 //=======================================================================
2160 //function : GetElementType
2161 //purpose : Returns type of mesh element with certain id
2162 //=======================================================================
2164 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
2166 return _myMeshDS->GetElementType( id, iselem );
2169 //=============================================================================
2171 * \brief Convert group on geometry into standalone group
2173 //=============================================================================
2175 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
2177 SMESH_Group* aGroup = 0;
2178 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
2179 if ( itg == _mapGroup.end() )
2182 SMESH_Group* anOldGrp = (*itg).second;
2183 if ( !anOldGrp || !anOldGrp->GetGroupDS() )
2185 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
2187 // create new standalone group
2188 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
2189 _mapGroup[theGroupID] = aGroup;
2191 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
2192 GetMeshDS()->RemoveGroup( anOldGrpDS );
2193 GetMeshDS()->AddGroup( aNewGrpDS );
2195 // add elements (or nodes) into new created group
2196 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
2197 while ( anItr->more() )
2198 aNewGrpDS->Add( (anItr->next())->GetID() );
2201 aNewGrpDS->SetColor( anOldGrpDS->GetColor() );
2209 //=============================================================================
2211 * \brief remove submesh order from Mesh
2213 //=============================================================================
2215 void SMESH_Mesh::ClearMeshOrder()
2217 _mySubMeshOrder.clear();
2220 //=============================================================================
2222 * \brief remove submesh order from Mesh
2224 //=============================================================================
2226 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
2228 _mySubMeshOrder = theOrder;
2231 //=============================================================================
2233 * \brief return submesh order if any
2235 //=============================================================================
2237 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
2239 return _mySubMeshOrder;
2242 //=============================================================================
2244 * \brief fill _mapAncestors
2246 //=============================================================================
2248 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
2250 int desType, ancType;
2251 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
2253 // a geom group is added. Insert it into lists of ancestors before
2254 // the first ancestor more complex than group members
2255 TopoDS_Iterator subIt( theShape );
2256 if ( !subIt.More() ) return;
2257 int memberType = subIt.Value().ShapeType();
2258 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
2259 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
2261 if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982
2262 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
2263 TopTools_ListIteratorOfListOfShape ancIt (ancList);
2264 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
2266 if ( ancIt.More() ) ancList.InsertBefore( theShape, ancIt );
2267 else ancList.Append( theShape );
2270 else // else added for 52457: Addition of hypotheses is 8 time longer than meshing
2272 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
2273 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
2274 TopExp::MapShapesAndAncestors ( theShape,
2275 (TopAbs_ShapeEnum) desType,
2276 (TopAbs_ShapeEnum) ancType,
2279 // visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
2280 if ( theShape.ShapeType() == TopAbs_COMPOUND )
2282 TopoDS_Iterator sIt(theShape);
2283 if ( sIt.More() && sIt.Value().ShapeType() == TopAbs_COMPOUND )
2284 for ( ; sIt.More(); sIt.Next() )
2285 if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
2286 fillAncestorsMap( sIt.Value() );
2290 //=============================================================================
2292 * \brief sort submeshes according to stored mesh order
2293 * \param theListToSort in out list to be sorted
2294 * \return FALSE if nothing sorted
2296 //=============================================================================
2298 bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
2300 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
2304 vector<SMESH_subMesh*> onlyOrderedList, smVec;
2306 // collect all ordered submeshes in one list as pointers
2307 // and get their positions within theListToSort
2308 typedef vector<SMESH_subMesh*>::iterator TPosInList;
2309 map< int, TPosInList > sortedPos;
2310 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
2311 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2312 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2314 const TListOfInt& listOfId = *listIdsIt;
2315 // convert sm ids to sm's
2317 TListOfInt::const_iterator idIt = listOfId.begin();
2318 for ( ; idIt != listOfId.end(); idIt++ )
2320 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt ))
2322 smVec.push_back( sm );
2323 if ( sm->GetSubMeshDS() && sm->GetSubMeshDS()->IsComplexSubmesh() )
2325 SMESHDS_SubMeshIteratorPtr smdsIt = sm->GetSubMeshDS()->GetSubMeshIterator();
2326 while ( smdsIt->more() )
2328 const SMESHDS_SubMesh* smDS = smdsIt->next();
2329 if (( sm = GetSubMeshContaining( smDS->GetID() )))
2330 smVec.push_back( sm );
2335 // find smVec items in theListToSort
2336 for ( size_t i = 0; i < smVec.size(); ++i )
2338 TPosInList smPos = find( smBeg, smEnd, smVec[i] );
2339 if ( smPos != smEnd ) {
2340 onlyOrderedList.push_back( smVec[i] );
2341 sortedPos[ distance( smBeg, smPos )] = smPos;
2345 if (onlyOrderedList.size() < 2)
2349 vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
2350 vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
2352 // iterate on ordered submeshes and insert them in detected positions
2353 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
2354 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
2355 *(i_pos->second) = *onlyBIt;
2360 //================================================================================
2362 * \brief Return true if given order of sub-meshes is OK
2364 //================================================================================
2366 bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
2367 const SMESH_subMesh* smAfter ) const
2369 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2370 TListOfInt::const_iterator idBef, idAft;
2371 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2373 const TListOfInt& listOfId = *listIdsIt;
2374 idBef = std::find( listOfId.begin(), listOfId.end(), smBefore->GetId() );
2375 if ( idBef != listOfId.end() )
2376 idAft = std::find( listOfId.begin(), listOfId.end(), smAfter->GetId() );
2377 if ( idAft != listOfId.end () )
2378 return ( std::distance( listOfId.begin(), idBef ) <
2379 std::distance( listOfId.begin(), idAft ) );
2381 return true; // no order imposed to given submeshes
2384 //=============================================================================
2386 * \brief sort submeshes according to stored mesh order
2387 * \param theListToSort in out list to be sorted
2388 * \return FALSE if nothing sorted
2390 //=============================================================================
2392 void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape,
2393 std::vector< SMESH_subMesh* >& theSubMeshes) const
2395 theSubMeshes.clear();
2396 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
2397 for (; it.More(); it.Next() )
2398 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
2399 theSubMeshes.push_back(sm);
2401 // sort submeshes according to stored mesh order
2402 SortByMeshOrder( theSubMeshes );