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 );
441 GetMeshDS()->Modified();
445 //=======================================================================
447 * \brief Remove all nodes and elements of indicated shape
449 //=======================================================================
451 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
453 // clear sub-meshes; get ready to re-compute as a side-effect
454 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
456 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
457 /*complexShapeFirst=*/false);
458 while ( smIt->more() )
461 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
462 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
463 // all other shapes depends on vertices so they are already cleaned
464 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
465 // to recompute even if failed
466 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
471 //=======================================================================
472 //function : UNVToMesh
474 //=======================================================================
476 int SMESH_Mesh::UNVToMesh(const char* theFileName)
478 if ( _isShapeToMesh )
479 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
480 _isShapeToMesh = false;
482 DriverUNV_R_SMDS_Mesh myReader;
483 myReader.SetMesh(_myMeshDS);
484 myReader.SetFile(theFileName);
485 myReader.SetMeshId(-1);
488 if ( SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup() )
490 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
491 aGroup->InitSubGroupsIterator();
492 while (aGroup->MoreSubGroups())
494 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
495 string aName = aGroupNames[aSubGroup];
497 if ( SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId ))
499 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
501 aGroupDS->SetStoreName(aName.c_str());
502 aSubGroup->InitIterator();
503 const SMDS_MeshElement* aElement = 0;
504 while ( aSubGroup->More() )
505 if (( aElement = aSubGroup->Next() ))
506 aGroupDS->SMDSGroup().Add( aElement );
509 aGroupDS->SetType( aElement->GetType() );
517 //=======================================================================
518 //function : MEDToMesh
520 //=======================================================================
522 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
524 if ( _isShapeToMesh )
525 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
526 _isShapeToMesh = false;
528 DriverMED_R_SMESHDS_Mesh myReader;
529 myReader.SetMesh(_myMeshDS);
530 myReader.SetMeshId(-1);
531 myReader.SetFile(theFileName);
532 myReader.SetMeshName(theMeshName);
533 Driver_Mesh::Status status = myReader.Perform();
535 SMESH_ComputeErrorPtr er = myReader.GetError();
536 if ( er && !er->IsOK() ) cout << er->myComment << endl;
539 // Reading groups (sub-meshes are out of scope of MED import functionality)
540 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
542 list<TNameAndType>::iterator name_type = aGroupNames.begin();
543 for ( ; name_type != aGroupNames.end(); name_type++ )
545 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
547 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
549 aGroupDS->SetStoreName( name_type->first.c_str() );
550 myReader.GetGroup( aGroupDS );
557 //=======================================================================
558 //function : STLToMesh
560 //=======================================================================
562 int SMESH_Mesh::STLToMesh(const char* theFileName)
565 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
566 _isShapeToMesh = false;
568 DriverSTL_R_SMDS_Mesh myReader;
569 myReader.SetMesh(_myMeshDS);
570 myReader.SetFile(theFileName);
571 myReader.SetMeshId(-1);
577 //================================================================================
579 * \brief Reads the given mesh from the CGNS file
580 * \param theFileName - name of the file
581 * \retval int - Driver_Mesh::Status
583 //================================================================================
585 int SMESH_Mesh::CGNSToMesh(const char* theFileName,
586 const int theMeshIndex,
587 std::string& theMeshName)
589 int res = Driver_Mesh::DRS_FAIL;
592 DriverCGNS_Read myReader;
593 myReader.SetMesh(_myMeshDS);
594 myReader.SetFile(theFileName);
595 myReader.SetMeshId(theMeshIndex);
596 res = myReader.Perform();
597 theMeshName = myReader.GetMeshName();
606 //================================================================================
608 * \brief Fill its data by reading a GMF file
610 //================================================================================
612 SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
613 bool theMakeRequiredGroups)
615 DriverGMF_Read myReader;
616 myReader.SetMesh(_myMeshDS);
617 myReader.SetFile(theFileName);
618 myReader.SetMakeRequiredGroups( theMakeRequiredGroups );
620 //theMeshName = myReader.GetMeshName();
625 return myReader.GetError();
628 //=============================================================================
632 //=============================================================================
634 SMESH_Hypothesis::Hypothesis_Status
635 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
637 std::string* anError ) throw(SALOME_Exception)
639 Unexpect aCatch(SalomeException);
640 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
645 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
646 if ( !subMesh || !subMesh->GetId())
647 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
649 SMESH_Hypothesis *anHyp = GetHypothesis( anHypId );
651 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
653 bool isGlobalHyp = IsMainShape( aSubShape );
655 // NotConformAllowed can be only global
658 // NOTE: this is not a correct way to check a name of hypothesis,
659 // there should be an attribute of hypothesis saying that it can/can't
661 string hypName = anHyp->GetName();
662 if ( hypName == "NotConformAllowed" )
664 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
665 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
671 bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
672 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
674 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
676 if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() )
677 *anError = subMesh->GetComputeError()->myComment;
680 if ( !SMESH_Hypothesis::IsStatusFatal(ret) &&
681 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
683 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
685 SMESH_Hypothesis::Hypothesis_Status ret2 =
686 subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true);
690 if ( SMESH_Hypothesis::IsStatusFatal( ret ))
692 if ( anError && subMesh->GetComputeError() )
693 *anError = subMesh->GetComputeError()->myComment;
695 event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
696 subMesh->AlgoStateEngine(event, anHyp);
700 // check concurent hypotheses on ancestors
701 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
703 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
704 while ( smIt->more() ) {
705 SMESH_subMesh* sm = smIt->next();
706 if ( sm->IsApplicableHypotesis( anHyp )) {
707 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
716 HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
718 if(MYDEBUG) subMesh->DumpAlgoState(true);
719 if(MYDEBUG) SCRUTE(ret);
723 //=============================================================================
727 //=============================================================================
729 SMESH_Hypothesis::Hypothesis_Status
730 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
731 int anHypId) throw( SALOME_Exception )
733 Unexpect aCatch(SalomeException);
734 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
736 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
737 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
738 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
740 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
741 if(MYDEBUG) { SCRUTE(anHyp->GetType()); }
745 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
746 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
748 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
750 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
752 // there may appear concurrent hyps that were covered by the removed hyp
753 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
754 subMesh->IsApplicableHypotesis( anHyp ) &&
755 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
756 ret = SMESH_Hypothesis::HYP_CONCURENT;
759 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
760 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
762 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
764 SMESH_Hypothesis::Hypothesis_Status ret2 =
765 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
766 if (ret2 > ret) // more severe
769 // check concurent hypotheses on ancestors
770 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
772 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
773 while ( smIt->more() ) {
774 SMESH_subMesh* sm = smIt->next();
775 if ( sm->IsApplicableHypotesis( anHyp )) {
776 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
786 HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
788 if(MYDEBUG) subMesh->DumpAlgoState(true);
789 if(MYDEBUG) SCRUTE(ret);
793 //=============================================================================
797 //=============================================================================
799 const list<const SMESHDS_Hypothesis*>&
800 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
801 throw(SALOME_Exception)
803 return _myMeshDS->GetHypothesis(aSubShape);
806 //=======================================================================
808 * \brief Return the hypothesis assigned to the shape
809 * \param aSubShape - the shape to check
810 * \param aFilter - the hypothesis filter
811 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
812 * \param assignedTo - to return the shape the found hypo is assigned to
813 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
815 //=======================================================================
817 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
818 const SMESH_HypoFilter& aFilter,
819 const bool andAncestors,
820 TopoDS_Shape* assignedTo) const
822 return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
823 aFilter, andAncestors, assignedTo );
826 //=======================================================================
828 * \brief Return the hypothesis assigned to the shape of a sub-mesh
829 * \param aSubMesh - the sub-mesh to check
830 * \param aFilter - the hypothesis filter
831 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
832 * \param assignedTo - to return the shape the found hypo is assigned to
833 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
835 //=======================================================================
837 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh * aSubMesh,
838 const SMESH_HypoFilter& aFilter,
839 const bool andAncestors,
840 TopoDS_Shape* assignedTo) const
842 if ( !aSubMesh ) return 0;
845 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
846 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
847 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
848 for ( ; hyp != hypList.end(); hyp++ ) {
849 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
850 if ( aFilter.IsOk( h, aSubShape)) {
851 if ( assignedTo ) *assignedTo = aSubShape;
858 // user sorted submeshes of ancestors, according to stored submesh priority
859 std::vector< SMESH_subMesh * > & ancestors =
860 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
861 SortByMeshOrder( ancestors );
863 vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
864 for ( ; smIt != ancestors.end(); smIt++ )
866 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
867 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
868 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
869 for ( ; hyp != hypList.end(); hyp++ ) {
870 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
871 if (aFilter.IsOk( h, curSh )) {
872 if ( assignedTo ) *assignedTo = curSh;
881 //================================================================================
883 * \brief Return hypotheses assigned to the shape
884 * \param aSubShape - the shape to check
885 * \param aFilter - the hypothesis filter
886 * \param aHypList - the list of the found hypotheses
887 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
888 * \retval int - number of unique hypos in aHypList
890 //================================================================================
892 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
893 const SMESH_HypoFilter& aFilter,
894 list <const SMESHDS_Hypothesis * >& aHypList,
895 const bool andAncestors,
896 list< TopoDS_Shape > * assignedTo/*=0*/) const
898 return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
899 aFilter, aHypList, andAncestors, assignedTo );
902 //================================================================================
904 * \brief Return hypotheses assigned to the shape of a sub-mesh
905 * \param aSubShape - the sub-mesh to check
906 * \param aFilter - the hypothesis filter
907 * \param aHypList - the list of the found hypotheses
908 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
909 * \retval int - number of unique hypos in aHypList
911 //================================================================================
913 int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh,
914 const SMESH_HypoFilter& aFilter,
915 list <const SMESHDS_Hypothesis * >& aHypList,
916 const bool andAncestors,
917 list< TopoDS_Shape > * assignedTo/*=0*/) const
919 if ( !aSubMesh ) return 0;
921 set<string> hypTypes; // to exclude same type hypos from the result list
924 // only one main hypothesis is allowed
925 bool mainHypFound = false;
928 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
929 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
930 if ( hypTypes.insert( (*hyp)->GetName() ).second )
932 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
936 // get hypos from aSubShape
938 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
939 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
940 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
942 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
943 if (( aFilter.IsOk( h, aSubShape )) &&
944 ( h->IsAuxiliary() || !mainHypFound ) &&
945 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
947 aHypList.push_back( *hyp );
949 if ( !h->IsAuxiliary() )
951 if ( assignedTo ) assignedTo->push_back( aSubShape );
956 // get hypos from ancestors of aSubShape
959 // user sorted submeshes of ancestors, according to stored submesh priority
960 std::vector< SMESH_subMesh * > & ancestors =
961 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
962 SortByMeshOrder( ancestors );
964 vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
965 for ( ; smIt != ancestors.end(); smIt++ )
967 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
968 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
969 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
971 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
972 if (( aFilter.IsOk( h, curSh )) &&
973 ( h->IsAuxiliary() || !mainHypFound ) &&
974 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
976 aHypList.push_back( *hyp );
978 if ( !h->IsAuxiliary() )
980 if ( assignedTo ) assignedTo->push_back( curSh );
988 //================================================================================
990 * \brief Return a hypothesis by its ID
992 //================================================================================
994 SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const int anHypId) const
996 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
997 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
1000 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
1004 //=============================================================================
1008 //=============================================================================
1010 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
1012 Unexpect aCatch(SalomeException);
1013 return _myMeshDS->GetScript()->GetCommands();
1016 //=============================================================================
1020 //=============================================================================
1021 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
1023 Unexpect aCatch(SalomeException);
1024 _myMeshDS->GetScript()->Clear();
1027 //=============================================================================
1029 * Get or Create the SMESH_subMesh object implementation
1031 //=============================================================================
1033 SMESH_subMesh * SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
1034 throw(SALOME_Exception)
1036 int index = _myMeshDS->ShapeToIndex(aSubShape);
1037 if ( !index && aSubShape.IsNull() )
1040 // for submeshes on GEOM Group
1041 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND )
1043 TopoDS_Iterator it( aSubShape );
1046 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
1047 // fill map of Ancestors
1048 while ( _nbSubShapes < index )
1049 fillAncestorsMap( _myMeshDS->IndexToShape( ++_nbSubShapes ));
1053 // return NULL; // neither sub-shape nor a group
1055 SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index );
1058 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
1059 _subMeshHolder->Add( index, aSubMesh );
1061 // include non-computable sub-meshes in SMESH_subMesh::_ancestors of sub-submeshes
1062 switch ( aSubShape.ShapeType() ) {
1063 case TopAbs_COMPOUND:
1066 for ( TopoDS_Iterator subIt( aSubShape ); subIt.More(); subIt.Next() )
1068 SMESH_subMesh* sm = GetSubMesh( subIt.Value() );
1069 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*inclideSelf=*/true);
1070 while ( smIt->more() )
1071 smIt->next()->ClearAncestors();
1079 //=============================================================================
1081 * Get the SMESH_subMesh object implementation. Dont create it, return null
1082 * if it does not exist.
1084 //=============================================================================
1086 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
1087 throw(SALOME_Exception)
1089 int index = _myMeshDS->ShapeToIndex(aSubShape);
1090 return GetSubMeshContaining( index );
1093 //=============================================================================
1095 * Get the SMESH_subMesh object implementation. Dont create it, return null
1096 * if it does not exist.
1098 //=============================================================================
1100 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
1101 throw(SALOME_Exception)
1103 SMESH_subMesh *aSubMesh = _subMeshHolder->Get( aShapeID );
1108 //================================================================================
1110 * \brief Return sub-meshes of groups containing the given sub-shape
1112 //================================================================================
1114 list<SMESH_subMesh*>
1115 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
1116 throw(SALOME_Exception)
1118 list<SMESH_subMesh*> found;
1120 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
1124 // sub-meshes of groups have max IDs, so search from the map end
1125 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator( /*reverse=*/true ) );
1126 while ( smIt->more() ) {
1127 SMESH_subMesh* sm = smIt->next();
1128 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
1129 if ( ds && ds->IsComplexSubmesh() ) {
1130 if ( SMESH_MesherHelper::IsSubShape( aSubShape, sm->GetSubShape() ))
1132 found.push_back( sm );
1136 break; // the rest sub-meshes are not those of groups
1140 if ( found.empty() ) // maybe the main shape is a COMPOUND (issue 0021530)
1142 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1143 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1145 TopoDS_Iterator it( mainSM->GetSubShape() );
1146 if ( it.Value().ShapeType() == aSubShape.ShapeType() &&
1147 SMESH_MesherHelper::IsSubShape( aSubShape, mainSM->GetSubShape() ))
1148 found.push_back( mainSM );
1151 else // issue 0023068
1153 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1154 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1155 found.push_back( mainSM );
1159 //=======================================================================
1160 //function : IsUsedHypothesis
1161 //purpose : Return True if anHyp is used to mesh aSubShape
1162 //=======================================================================
1164 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
1165 const SMESH_subMesh* aSubMesh)
1167 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
1169 // check if anHyp can be used to mesh aSubMesh
1170 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
1173 SMESH_Algo *algo = aSubMesh->GetAlgo();
1176 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
1177 return ( anHyp == algo );
1179 // algorithm parameter
1182 // look trough hypotheses used by algo
1183 const SMESH_HypoFilter* hypoKind;
1184 if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
1185 list <const SMESHDS_Hypothesis * > usedHyps;
1186 if ( GetHypotheses( aSubMesh, *hypoKind, usedHyps, true ))
1187 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
1194 //=======================================================================
1195 //function : NotifySubMeshesHypothesisModification
1196 //purpose : Say all submeshes using theChangedHyp that it has been modified
1197 //=======================================================================
1199 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
1201 Unexpect aCatch(SalomeException);
1203 if ( !GetMeshDS()->IsUsedHypothesis( hyp ))
1207 _callUp->HypothesisModified();
1210 const SMESH_HypoFilter* compatibleHypoKind;
1211 list <const SMESHDS_Hypothesis * > usedHyps;
1212 vector< SMESH_subMesh* > smToNotify;
1213 bool allMeshedEdgesNotified = true;
1215 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1216 while ( smIt->more() )
1218 SMESH_subMesh* aSubMesh = smIt->next();
1219 bool toNotify = false;
1221 // if aSubMesh meshing depends on hyp,
1222 // we call aSubMesh->AlgoStateEngine( MODIF_HYP, hyp ) that causes either
1223 // 1) clearing already computed aSubMesh or
1224 // 2) changing algo_state from MISSING_HYP to HYP_OK when parameters of hyp becomes valid,
1225 // other possible changes are not interesting. (IPAL0052457 - assigning hyp performance pb)
1226 if ( aSubMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK ||
1227 aSubMesh->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE ||
1228 aSubMesh->GetAlgoState() == SMESH_subMesh::MISSING_HYP ||
1229 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 toNotify = ( GetHypotheses( aSubMesh, *compatibleHypoKind, usedHyps, true ) &&
1241 std::find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() );
1246 smToNotify.push_back( aSubMesh );
1247 if ( aSubMesh->GetAlgoState() == SMESH_subMesh::MISSING_HYP )
1248 allMeshedEdgesNotified = false; // update of algo state needed, not mesh clearing
1252 if ( !aSubMesh->IsEmpty() &&
1253 aSubMesh->GetSubShape().ShapeType() == TopAbs_EDGE )
1254 allMeshedEdgesNotified = false;
1257 if ( smToNotify.empty() )
1260 // if all meshed EDGEs will be notified then the notification is equivalent
1261 // to the whole mesh clearing, which is usually faster
1262 if ( allMeshedEdgesNotified && NbNodes() > 0 )
1268 // notify in reverse order to avoid filling the pool of IDs
1269 for ( int i = smToNotify.size()-1; i >= 0; --i )
1270 smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
1271 const_cast< SMESH_Hypothesis*>( hyp ));
1273 HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
1274 GetMeshDS()->Modified();
1277 //=============================================================================
1279 * Auto color functionality
1281 //=============================================================================
1282 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1284 Unexpect aCatch(SalomeException);
1285 _isAutoColor = theAutoColor;
1288 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1290 Unexpect aCatch(SalomeException);
1291 return _isAutoColor;
1294 //=======================================================================
1295 //function : SetIsModified
1296 //purpose : Set the flag meaning that the mesh has been edited "manually"
1297 //=======================================================================
1299 void SMESH_Mesh::SetIsModified(bool isModified)
1301 _isModified = isModified;
1304 // check if mesh becomes empty as result of modification
1305 HasModificationsToDiscard();
1308 //=======================================================================
1309 //function : HasModificationsToDiscard
1310 //purpose : Return true if the mesh has been edited since a total re-compute
1311 // and those modifications may prevent successful partial re-compute.
1312 // As a side effect reset _isModified flag if mesh is empty
1314 //=======================================================================
1316 bool SMESH_Mesh::HasModificationsToDiscard() const
1318 if ( ! _isModified )
1321 // return true if the next Compute() will be partial and
1322 // existing but changed elements may prevent successful re-compute
1323 bool hasComputed = false, hasNotComputed = false;
1324 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1325 while ( smIt->more() )
1327 const SMESH_subMesh* aSubMesh = smIt->next();
1328 switch ( aSubMesh->GetSubShape().ShapeType() )
1333 if ( aSubMesh->IsMeshComputed() )
1336 hasNotComputed = true;
1337 if ( hasComputed && hasNotComputed)
1343 if ( NbNodes() < 1 )
1344 const_cast<SMESH_Mesh*>(this)->_isModified = false;
1349 //================================================================================
1351 * \brief Check if any groups of the same type have equal names
1353 //================================================================================
1355 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1357 // Corrected for Mantis issue 0020028
1358 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1359 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1361 SMESH_Group* aGroup = it->second;
1362 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1363 string aGroupName = aGroup->GetName();
1364 aGroupName.resize( MAX_MED_GROUP_NAME_LENGTH );
1365 if ( !aGroupNames[aType].insert(aGroupName).second )
1372 //================================================================================
1374 * \brief Export the mesh to a med file
1375 * \param [in] file - name of the MED file
1376 * \param [in] theMeshName - name of this mesh
1377 * \param [in] theAutoGroups - boolean parameter for creating/not creating
1378 * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1379 * the typical use is auto_groups=false.
1380 * \param [in] theVersion - defines the version of format of MED file, that will be created
1381 * \param [in] meshPart - mesh data to export
1382 * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
1383 * - 1D if all mesh nodes lie on OX coordinate axis, or
1384 * - 2D if all mesh nodes lie on XOY coordinate plane, or
1385 * - 3D in the rest cases.
1386 * If \a theAutoDimension is \c false, the space dimension is always 3.
1387 * \return int - mesh index in the file
1389 //================================================================================
1391 void SMESH_Mesh::ExportMED(const char * file,
1392 const char* theMeshName,
1395 const SMESHDS_Mesh* meshPart,
1396 bool theAutoDimension,
1397 bool theAddODOnVertices)
1398 throw(SALOME_Exception)
1402 DriverMED_W_SMESHDS_Mesh myWriter;
1403 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1404 myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1405 myWriter.SetAutoDimension( theAutoDimension );
1406 myWriter.AddODOnVertices ( theAddODOnVertices );
1408 myWriter.SetMeshId ( _id );
1410 myWriter.SetMeshId ( -1 );
1411 myWriter.SetMeshName ( theMeshName );
1414 if ( theAutoGroups ) {
1415 myWriter.AddGroupOfNodes();
1416 myWriter.AddGroupOfEdges();
1417 myWriter.AddGroupOfFaces();
1418 myWriter.AddGroupOfVolumes();
1421 // Pass groups to writer. Provide unique group names.
1422 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1425 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1427 int maxNbIter = 10000; // to guarantee cycle finish
1428 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1429 SMESH_Group* aGroup = it->second;
1430 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1432 SMDSAbs_ElementType aType = aGroupDS->GetType();
1433 string aGroupName0 = aGroup->GetName();
1434 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1435 string aGroupName = aGroupName0;
1436 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1437 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1438 aGroupName = aString;
1439 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1441 aGroupDS->SetStoreName( aGroupName.c_str() );
1442 myWriter.AddGroup( aGroupDS );
1449 SMESH_CATCH( SMESH::throwSalomeEx );
1452 //================================================================================
1454 * \brief Export the mesh to a SAUV file
1456 //================================================================================
1458 void SMESH_Mesh::ExportSAUV(const char *file,
1459 const char* theMeshName,
1461 throw(SALOME_Exception)
1463 std::string medfilename(file);
1464 medfilename += ".med";
1467 cmd = "%PYTHONBIN% ";
1472 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1474 system(cmd.c_str());
1475 ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, 1);
1477 cmd = "%PYTHONBIN% ";
1482 cmd += "from medutilities import convert ; convert(r'" + medfilename + "', 'MED', 'GIBI', 1, r'" + file + "')";
1484 system(cmd.c_str());
1486 cmd = "%PYTHONBIN% ";
1491 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1493 system(cmd.c_str());
1496 //================================================================================
1498 * \brief Export the mesh to a DAT file
1500 //================================================================================
1502 void SMESH_Mesh::ExportDAT(const char * file,
1503 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1505 Unexpect aCatch(SalomeException);
1506 DriverDAT_W_SMDS_Mesh myWriter;
1507 myWriter.SetFile( file );
1508 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1509 myWriter.SetMeshId(_id);
1513 //================================================================================
1515 * \brief Export the mesh to an UNV file
1517 //================================================================================
1519 void SMESH_Mesh::ExportUNV(const char * file,
1520 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1522 Unexpect aCatch(SalomeException);
1523 DriverUNV_W_SMDS_Mesh myWriter;
1524 myWriter.SetFile( file );
1525 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1526 myWriter.SetMeshId(_id);
1527 // myWriter.SetGroups(_mapGroup);
1531 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1532 SMESH_Group* aGroup = it->second;
1533 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1535 string aGroupName = aGroup->GetName();
1536 aGroupDS->SetStoreName( aGroupName.c_str() );
1537 myWriter.AddGroup( aGroupDS );
1544 //================================================================================
1546 * \brief Export the mesh to an STL file
1548 //================================================================================
1550 void SMESH_Mesh::ExportSTL(const char * file,
1552 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1554 Unexpect aCatch(SalomeException);
1555 DriverSTL_W_SMDS_Mesh myWriter;
1556 myWriter.SetFile( file );
1557 myWriter.SetIsAscii( isascii );
1558 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
1559 myWriter.SetMeshId(_id);
1563 //================================================================================
1565 * \brief Export the mesh to the CGNS file
1567 //================================================================================
1569 void SMESH_Mesh::ExportCGNS(const char * file,
1570 const SMESHDS_Mesh* meshDS,
1571 const char * meshName)
1573 int res = Driver_Mesh::DRS_FAIL;
1575 DriverCGNS_Write myWriter;
1576 myWriter.SetFile( file );
1577 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1578 myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
1579 if ( meshName && meshName[0] )
1580 myWriter.SetMeshName( meshName );
1581 res = myWriter.Perform();
1583 if ( res != Driver_Mesh::DRS_OK )
1584 throw SALOME_Exception("Export failed");
1587 //================================================================================
1589 * \brief Export the mesh to a GMF file
1591 //================================================================================
1593 void SMESH_Mesh::ExportGMF(const char * file,
1594 const SMESHDS_Mesh* meshDS,
1595 bool withRequiredGroups)
1597 DriverGMF_Write myWriter;
1598 myWriter.SetFile( file );
1599 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1600 myWriter.SetExportRequiredGroups( withRequiredGroups );
1605 //================================================================================
1607 * \brief Return a ratio of "compute cost" of computed sub-meshes to the whole
1610 //================================================================================
1612 double SMESH_Mesh::GetComputeProgress() const
1614 double totalCost = 1e-100, computedCost = 0;
1615 const SMESH_subMesh* curSM = _gen->GetCurrentSubMesh();
1617 // get progress of a current algo
1618 TColStd_MapOfInteger currentSubIds;
1620 if ( SMESH_Algo* algo = curSM->GetAlgo() )
1622 int algoNotDoneCost = 0, algoDoneCost = 0;
1623 const std::vector<SMESH_subMesh*>& smToCompute = algo->SubMeshesToCompute();
1624 for ( size_t i = 0; i < smToCompute.size(); ++i )
1626 if ( smToCompute[i]->IsEmpty() || smToCompute.size() == 1 )
1627 algoNotDoneCost += smToCompute[i]->GetComputeCost();
1629 algoDoneCost += smToCompute[i]->GetComputeCost();
1630 currentSubIds.Add( smToCompute[i]->GetId() );
1636 rate = algo->GetProgress();
1640 cerr << "Exception in " << algo->GetName() << "::GetProgress()" << endl;
1643 if ( 0. < rate && rate < 1.001 )
1645 computedCost += rate * ( algoDoneCost + algoNotDoneCost );
1649 rate = algo->GetProgressByTic();
1650 computedCost += algoDoneCost + rate * algoNotDoneCost;
1652 // cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
1655 // get cost of already treated sub-meshes
1656 if ( SMESH_subMesh* mainSM = GetSubMeshContaining( 1 ))
1658 SMESH_subMeshIteratorPtr smIt = mainSM->getDependsOnIterator(/*includeSelf=*/true);
1659 while ( smIt->more() )
1661 const SMESH_subMesh* sm = smIt->next();
1662 const int smCost = sm->GetComputeCost();
1663 totalCost += smCost;
1664 if ( !currentSubIds.Contains( sm->GetId() ) )
1666 if (( !sm->IsEmpty() ) ||
1667 ( sm->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
1668 !sm->DependsOn( curSM ) ))
1669 computedCost += smCost;
1673 // cout << "Total: " << totalCost
1674 // << " computed: " << computedCost << " progress: " << computedCost / totalCost
1675 // << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
1676 return computedCost / totalCost;
1679 //================================================================================
1681 * \brief Return number of nodes in the mesh
1683 //================================================================================
1685 int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
1687 Unexpect aCatch(SalomeException);
1688 return _myMeshDS->NbNodes();
1691 //================================================================================
1693 * \brief Return number of edges of given order in the mesh
1695 //================================================================================
1697 int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
1699 Unexpect aCatch(SalomeException);
1700 return _myMeshDS->GetMeshInfo().Nb0DElements();
1703 //================================================================================
1705 * \brief Return number of edges of given order in the mesh
1707 //================================================================================
1709 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1711 Unexpect aCatch(SalomeException);
1712 return _myMeshDS->GetMeshInfo().NbEdges(order);
1715 //================================================================================
1717 * \brief Return number of faces of given order in the mesh
1719 //================================================================================
1721 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1723 Unexpect aCatch(SalomeException);
1724 return _myMeshDS->GetMeshInfo().NbFaces(order);
1727 //================================================================================
1729 * \brief Return the number of faces in the mesh
1731 //================================================================================
1733 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1735 Unexpect aCatch(SalomeException);
1736 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1739 //================================================================================
1741 * \brief Return number of biquadratic triangles in the mesh
1743 //================================================================================
1745 int SMESH_Mesh::NbBiQuadTriangles() const throw(SALOME_Exception)
1747 Unexpect aCatch(SalomeException);
1748 return _myMeshDS->GetMeshInfo().NbBiQuadTriangles();
1751 //================================================================================
1753 * \brief Return the number nodes faces in the mesh
1755 //================================================================================
1757 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1759 Unexpect aCatch(SalomeException);
1760 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1763 //================================================================================
1765 * \brief Return number of biquadratic quadrangles in the mesh
1767 //================================================================================
1769 int SMESH_Mesh::NbBiQuadQuadrangles() const throw(SALOME_Exception)
1771 Unexpect aCatch(SalomeException);
1772 return _myMeshDS->GetMeshInfo().NbBiQuadQuadrangles();
1775 //================================================================================
1777 * \brief Return the number of polygonal faces in the mesh
1779 //================================================================================
1781 int SMESH_Mesh::NbPolygons(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1783 Unexpect aCatch(SalomeException);
1784 return _myMeshDS->GetMeshInfo().NbPolygons(order);
1787 //================================================================================
1789 * \brief Return number of volumes of given order in the mesh
1791 //================================================================================
1793 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1795 Unexpect aCatch(SalomeException);
1796 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1799 //================================================================================
1801 * \brief Return number of tetrahedrons of given order in the mesh
1803 //================================================================================
1805 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1807 Unexpect aCatch(SalomeException);
1808 return _myMeshDS->GetMeshInfo().NbTetras(order);
1811 //================================================================================
1813 * \brief Return number of hexahedrons of given order in the mesh
1815 //================================================================================
1817 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1819 Unexpect aCatch(SalomeException);
1820 return _myMeshDS->GetMeshInfo().NbHexas(order);
1823 //================================================================================
1825 * \brief Return number of triquadratic hexahedrons in the mesh
1827 //================================================================================
1829 int SMESH_Mesh::NbTriQuadraticHexas() const throw(SALOME_Exception)
1831 Unexpect aCatch(SalomeException);
1832 return _myMeshDS->GetMeshInfo().NbTriQuadHexas();
1835 //================================================================================
1837 * \brief Return number of pyramids of given order in the mesh
1839 //================================================================================
1841 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1843 Unexpect aCatch(SalomeException);
1844 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1847 //================================================================================
1849 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1851 //================================================================================
1853 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1855 Unexpect aCatch(SalomeException);
1856 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1859 //================================================================================
1861 * \brief Return number of hexagonal prisms in the mesh
1863 //================================================================================
1865 int SMESH_Mesh::NbHexagonalPrisms() const throw(SALOME_Exception)
1867 Unexpect aCatch(SalomeException);
1868 return _myMeshDS->GetMeshInfo().NbHexPrisms();
1871 //================================================================================
1873 * \brief Return number of polyhedrons in the mesh
1875 //================================================================================
1877 int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
1879 Unexpect aCatch(SalomeException);
1880 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1883 //================================================================================
1885 * \brief Return number of ball elements in the mesh
1887 //================================================================================
1889 int SMESH_Mesh::NbBalls() const throw(SALOME_Exception)
1891 Unexpect aCatch(SalomeException);
1892 return _myMeshDS->GetMeshInfo().NbBalls();
1895 //================================================================================
1897 * \brief Return number of submeshes in the mesh
1899 //================================================================================
1901 int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
1903 Unexpect aCatch(SalomeException);
1904 return _myMeshDS->NbSubMesh();
1907 //================================================================================
1909 * \brief Returns number of meshes in the Study, that is supposed to be
1910 * equal to SMESHDS_Document::NbMeshes()
1912 //================================================================================
1914 int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
1916 return _myDocument->NbMeshes();
1919 //=======================================================================
1920 //function : IsNotConformAllowed
1921 //purpose : check if a hypothesis alowing notconform mesh is present
1922 //=======================================================================
1924 bool SMESH_Mesh::IsNotConformAllowed() const
1926 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1928 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1929 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1932 //=======================================================================
1933 //function : IsMainShape
1935 //=======================================================================
1937 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1939 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1942 //=============================================================================
1946 //=============================================================================
1948 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1949 const char* theName,
1951 const TopoDS_Shape& theShape,
1952 const SMESH_PredicatePtr& thePredicate)
1954 if (_mapGroup.count(_groupId))
1957 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
1958 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1959 _mapGroup[_groupId++] = aGroup;
1963 //================================================================================
1965 * \brief Creates a group based on an existing SMESHDS group. Group ID should be unique
1967 //================================================================================
1969 SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
1972 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
1974 map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
1975 if ( i_g != _mapGroup.end() && i_g->second )
1977 if ( i_g->second->GetGroupDS() == groupDS )
1980 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup() wrong ID of SMESHDS_GroupBase"));
1982 SMESH_Group* aGroup = new SMESH_Group (groupDS);
1983 _mapGroup[ groupDS->GetID() ] = aGroup;
1984 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1986 _groupId = 1 + _mapGroup.rbegin()->first;
1992 //================================================================================
1994 * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
1995 * \retval bool - true if new SMESH_Groups have been created
1998 //================================================================================
2000 bool SMESH_Mesh::SynchronizeGroups()
2002 const size_t nbGroups = _mapGroup.size();
2003 const set<SMESHDS_GroupBase*>& groups = _myMeshDS->GetGroups();
2004 set<SMESHDS_GroupBase*>::const_iterator gIt = groups.begin();
2005 for ( ; gIt != groups.end(); ++gIt )
2007 SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt;
2008 _groupId = groupDS->GetID();
2009 if ( !_mapGroup.count( _groupId ))
2010 _mapGroup[_groupId] = new SMESH_Group( groupDS );
2012 if ( !_mapGroup.empty() )
2013 _groupId = _mapGroup.rbegin()->first + 1;
2015 return nbGroups < _mapGroup.size();
2018 //================================================================================
2020 * \brief Return iterator on all existing groups
2022 //================================================================================
2024 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
2026 typedef map <int, SMESH_Group *> TMap;
2027 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
2030 //=============================================================================
2032 * \brief Return a group by ID
2034 //=============================================================================
2036 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
2038 if (_mapGroup.find(theGroupID) == _mapGroup.end())
2040 return _mapGroup[theGroupID];
2044 //=============================================================================
2046 * \brief Return IDs of all groups
2048 //=============================================================================
2050 list<int> SMESH_Mesh::GetGroupIds() const
2053 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
2054 anIds.push_back( it->first );
2059 //================================================================================
2061 * \brief Set a caller of methods at level of CORBA API implementation.
2062 * The set upCaller will be deleted by SMESH_Mesh
2064 //================================================================================
2066 void SMESH_Mesh::SetCallUp( TCallUp* upCaller )
2068 if ( _callUp ) delete _callUp;
2072 //=============================================================================
2076 //=============================================================================
2078 bool SMESH_Mesh::RemoveGroup( const int theGroupID )
2080 if (_mapGroup.find(theGroupID) == _mapGroup.end())
2082 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
2083 delete _mapGroup[theGroupID];
2084 _mapGroup.erase (theGroupID);
2086 _callUp->RemoveGroup( theGroupID );
2090 //=======================================================================
2091 //function : GetAncestors
2092 //purpose : return list of ancestors of theSubShape in the order
2093 // that lower dimention shapes come first.
2094 //=======================================================================
2096 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
2098 if ( _mapAncestors.Contains( theS ) )
2099 return _mapAncestors.FindFromKey( theS );
2101 static TopTools_ListOfShape emptyList;
2105 //=======================================================================
2107 //purpose : dumps contents of mesh to stream [ debug purposes ]
2108 //=======================================================================
2110 ostream& SMESH_Mesh::Dump(ostream& save)
2113 save << "========================== Dump contents of mesh ==========================" << endl << endl;
2114 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
2115 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
2116 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
2117 save << ++clause << ") Total number of polygons: \t" << NbPolygons() << endl;
2118 save << ++clause << ") Total number of volumes: \t" << NbVolumes() << endl;
2119 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
2120 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
2122 string orderStr = isQuadratic ? "quadratic" : "linear";
2123 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
2125 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
2126 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
2127 if ( NbFaces(order) > 0 ) {
2128 int nb3 = NbTriangles(order);
2129 int nb4 = NbQuadrangles(order);
2130 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
2131 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
2132 if ( nb3 + nb4 != NbFaces(order) ) {
2133 map<int,int> myFaceMap;
2134 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
2135 while( itFaces->more( ) ) {
2136 int nbNodes = itFaces->next()->NbNodes();
2137 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
2138 myFaceMap[ nbNodes ] = 0;
2139 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
2141 save << clause << ".3) Faces in detail: " << endl;
2142 map <int,int>::iterator itF;
2143 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
2144 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
2147 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
2148 if ( NbVolumes(order) > 0 ) {
2149 int nb8 = NbHexas(order);
2150 int nb4 = NbTetras(order);
2151 int nb5 = NbPyramids(order);
2152 int nb6 = NbPrisms(order);
2153 save << clause << ".1) Number of " << orderStr << " hexahedrons: \t" << nb8 << endl;
2154 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
2155 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
2156 save << clause << ".4) Number of " << orderStr << " pyramids: \t" << nb5 << endl;
2157 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
2158 map<int,int> myVolumesMap;
2159 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
2160 while( itVolumes->more( ) ) {
2161 int nbNodes = itVolumes->next()->NbNodes();
2162 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
2163 myVolumesMap[ nbNodes ] = 0;
2164 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
2166 save << clause << ".5) Volumes in detail: " << endl;
2167 map <int,int>::iterator itV;
2168 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
2169 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
2174 save << "===========================================================================" << endl;
2178 //=======================================================================
2179 //function : GetElementType
2180 //purpose : Returns type of mesh element with certain id
2181 //=======================================================================
2183 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
2185 return _myMeshDS->GetElementType( id, iselem );
2188 //=============================================================================
2190 * \brief Convert group on geometry into standalone group
2192 //=============================================================================
2194 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
2196 SMESH_Group* aGroup = 0;
2197 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
2198 if ( itg == _mapGroup.end() )
2201 SMESH_Group* anOldGrp = (*itg).second;
2202 if ( !anOldGrp || !anOldGrp->GetGroupDS() )
2204 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
2206 // create new standalone group
2207 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
2208 _mapGroup[theGroupID] = aGroup;
2210 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
2211 GetMeshDS()->RemoveGroup( anOldGrpDS );
2212 GetMeshDS()->AddGroup( aNewGrpDS );
2214 // add elements (or nodes) into new created group
2215 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
2216 while ( anItr->more() )
2217 aNewGrpDS->Add( (anItr->next())->GetID() );
2220 aNewGrpDS->SetColor( anOldGrpDS->GetColor() );
2228 //=============================================================================
2230 * \brief remove submesh order from Mesh
2232 //=============================================================================
2234 void SMESH_Mesh::ClearMeshOrder()
2236 _mySubMeshOrder.clear();
2239 //=============================================================================
2241 * \brief remove submesh order from Mesh
2243 //=============================================================================
2245 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
2247 _mySubMeshOrder = theOrder;
2250 //=============================================================================
2252 * \brief return submesh order if any
2254 //=============================================================================
2256 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
2258 return _mySubMeshOrder;
2261 //=============================================================================
2263 * \brief fill _mapAncestors
2265 //=============================================================================
2267 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
2269 int desType, ancType;
2270 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
2272 // a geom group is added. Insert it into lists of ancestors before
2273 // the first ancestor more complex than group members
2274 TopoDS_Iterator subIt( theShape );
2275 if ( !subIt.More() ) return;
2276 int memberType = subIt.Value().ShapeType();
2277 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
2278 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
2280 if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982
2281 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
2282 TopTools_ListIteratorOfListOfShape ancIt (ancList);
2283 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
2285 if ( ancIt.More() ) ancList.InsertBefore( theShape, ancIt );
2286 else ancList.Append( theShape );
2289 else // else added for 52457: Addition of hypotheses is 8 time longer than meshing
2291 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
2292 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
2293 TopExp::MapShapesAndAncestors ( theShape,
2294 (TopAbs_ShapeEnum) desType,
2295 (TopAbs_ShapeEnum) ancType,
2298 // visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
2299 if ( theShape.ShapeType() == TopAbs_COMPOUND )
2301 TopoDS_Iterator sIt(theShape);
2302 if ( sIt.More() && sIt.Value().ShapeType() == TopAbs_COMPOUND )
2303 for ( ; sIt.More(); sIt.Next() )
2304 if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
2305 fillAncestorsMap( sIt.Value() );
2309 //=============================================================================
2311 * \brief sort submeshes according to stored mesh order
2312 * \param theListToSort in out list to be sorted
2313 * \return FALSE if nothing sorted
2315 //=============================================================================
2317 bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
2319 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
2323 vector<SMESH_subMesh*> onlyOrderedList, smVec;
2325 // collect all ordered submeshes in one list as pointers
2326 // and get their positions within theListToSort
2327 typedef vector<SMESH_subMesh*>::iterator TPosInList;
2328 map< int, TPosInList > sortedPos;
2329 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
2330 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2331 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2333 const TListOfInt& listOfId = *listIdsIt;
2334 // convert sm ids to sm's
2336 TListOfInt::const_iterator idIt = listOfId.begin();
2337 for ( ; idIt != listOfId.end(); idIt++ )
2339 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt ))
2341 smVec.push_back( sm );
2342 if ( sm->GetSubMeshDS() && sm->GetSubMeshDS()->IsComplexSubmesh() )
2344 SMESHDS_SubMeshIteratorPtr smdsIt = sm->GetSubMeshDS()->GetSubMeshIterator();
2345 while ( smdsIt->more() )
2347 const SMESHDS_SubMesh* smDS = smdsIt->next();
2348 if (( sm = GetSubMeshContaining( smDS->GetID() )))
2349 smVec.push_back( sm );
2354 // find smVec items in theListToSort
2355 for ( size_t i = 0; i < smVec.size(); ++i )
2357 TPosInList smPos = find( smBeg, smEnd, smVec[i] );
2358 if ( smPos != smEnd ) {
2359 onlyOrderedList.push_back( smVec[i] );
2360 sortedPos[ distance( smBeg, smPos )] = smPos;
2364 if (onlyOrderedList.size() < 2)
2368 vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
2369 vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
2371 // iterate on ordered sub-meshes and insert them in detected positions
2372 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
2373 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
2374 *(i_pos->second) = *onlyBIt;
2379 //================================================================================
2381 * \brief Return true if given order of sub-meshes is OK
2383 //================================================================================
2385 bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
2386 const SMESH_subMesh* smAfter ) const
2388 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2389 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2391 const TListOfInt& listOfId = *listIdsIt;
2392 int iB = -1, iA = -1, i = 0;
2393 for ( TListOfInt::const_iterator id = listOfId.begin(); id != listOfId.end(); ++id, ++i )
2395 if ( *id == smBefore->GetId() )
2401 else if ( *id == smAfter->GetId() )
2409 return true; // no order imposed to given sub-meshes
2412 //=============================================================================
2414 * \brief sort submeshes according to stored mesh order
2415 * \param theListToSort in out list to be sorted
2416 * \return FALSE if nothing sorted
2418 //=============================================================================
2420 void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape,
2421 std::vector< SMESH_subMesh* >& theSubMeshes) const
2423 theSubMeshes.clear();
2424 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
2425 for (; it.More(); it.Next() )
2426 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
2427 theSubMeshes.push_back(sm);
2429 // sort submeshes according to stored mesh order
2430 SortByMeshOrder( theSubMeshes );