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>
83 // maximum stored group name length in MED file
84 #define MAX_MED_GROUP_NAME_LENGTH 80
87 static int MYDEBUG = 0;
89 static int MYDEBUG = 0;
92 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
94 typedef SMESH_HypoFilter THypType;
96 class SMESH_Mesh::SubMeshHolder : public SMESHDS_TSubMeshHolder< SMESH_subMesh >
100 //=============================================================================
104 //=============================================================================
106 SMESH_Mesh::SMESH_Mesh(int theLocalId,
108 bool theIsEmbeddedMode,
109 SMESHDS_Document* theDocument):
110 _groupId( 0 ), _nbSubShapes( 0 )
112 if(MYDEBUG) MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
115 _myDocument = theDocument;
116 _myMeshDS = theDocument->NewMesh(theIsEmbeddedMode,theLocalId);
117 _isShapeToMesh = false;
118 _isAutoColor = false;
120 _shapeDiagonal = 0.0;
122 _myMeshDS->ShapeToMesh( PseudoShape() );
123 _subMeshHolder = new SubMeshHolder;
126 //================================================================================
128 * \brief Constructor of SMESH_Mesh being a base of some descendant class
130 //================================================================================
132 SMESH_Mesh::SMESH_Mesh():
136 _isShapeToMesh( false ),
140 _isAutoColor( false ),
141 _isModified( false ),
142 _shapeDiagonal( 0.0 ),
145 _subMeshHolder = new SubMeshHolder;
151 void deleteMeshDS(SMESHDS_Mesh* meshDS)
153 //cout << "deleteMeshDS( " << meshDS << endl;
157 static void* deleteMeshDS(void* meshDS)
159 //cout << "deleteMeshDS( " << meshDS << endl;
160 SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
169 //=============================================================================
173 //=============================================================================
175 SMESH_Mesh::~SMESH_Mesh()
177 if(MYDEBUG) MESSAGE("SMESH_Mesh::~SMESH_Mesh");
179 // avoid usual removal of elements while processing RemoveHypothesis( algo ) event
180 SMESHDS_SubMeshIteratorPtr smIt = _myMeshDS->SubMeshes();
181 while ( smIt->more() )
182 const_cast<SMESHDS_SubMesh*>( smIt->next() )->Clear();
184 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
185 // Notify event listeners at least that something happens
186 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
187 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
190 std::map < int, SMESH_Group * >::iterator itg;
191 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
192 SMESH_Group *aGroup = (*itg).second;
198 delete _subMeshHolder;
200 if ( _callUp) delete _callUp;
203 // remove self from studyContext
206 StudyContextStruct * studyContext = _gen->GetStudyContext();
207 studyContext->mapMesh.erase( _id );
210 _myDocument->RemoveMesh( _id );
214 // delete _myMeshDS, in a thread in order not to block closing a study with large meshes
216 boost::thread aThread(boost::bind( & deleteMeshDS, _myMeshDS ));
219 int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_myMeshDS);
224 //================================================================================
226 * \brief Return true if a mesh with given id exists
228 //================================================================================
230 bool SMESH_Mesh::MeshExists( int meshId ) const
232 return _myDocument ? bool( _myDocument->GetMesh( meshId )) : false;
235 //================================================================================
237 * \brief Return a mesh by id
239 //================================================================================
241 SMESH_Mesh* SMESH_Mesh::FindMesh( int meshId ) const
244 return (SMESH_Mesh*) this;
246 if ( StudyContextStruct *aStudyContext = _gen->GetStudyContext())
248 std::map < int, SMESH_Mesh * >::iterator i_m = aStudyContext->mapMesh.find( meshId );
249 if ( i_m != aStudyContext->mapMesh.end() )
255 //=============================================================================
257 * \brief Set geometry to be meshed
259 //=============================================================================
261 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
263 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
265 if ( !aShape.IsNull() && _isShapeToMesh ) {
266 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
267 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
268 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
270 // clear current data
271 if ( !_myMeshDS->ShapeToMesh().IsNull() )
273 // removal of a shape to mesh, delete objects referring to sub-shapes:
275 _subMeshHolder->DeleteAll();
276 // - groups on geometry
277 std::map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
278 while ( i_gr != _mapGroup.end() ) {
279 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
280 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
282 _mapGroup.erase( i_gr++ );
287 _mapAncestors.Clear();
290 TopoDS_Shape aNullShape;
291 _myMeshDS->ShapeToMesh( aNullShape );
293 _shapeDiagonal = 0.0;
296 // set a new geometry
297 if ( !aShape.IsNull() )
299 _myMeshDS->ShapeToMesh(aShape);
300 _isShapeToMesh = true;
301 _nbSubShapes = _myMeshDS->MaxShapeIndex();
303 // fill map of ancestors
304 fillAncestorsMap(aShape);
308 _isShapeToMesh = false;
309 _shapeDiagonal = 0.0;
310 _myMeshDS->ShapeToMesh( PseudoShape() );
315 //=======================================================================
317 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
319 //=======================================================================
321 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
323 return _myMeshDS->ShapeToMesh();
326 //=======================================================================
328 * \brief Return a solid which is returned by GetShapeToMesh() if
329 * a real geometry to be meshed was not set
331 //=======================================================================
333 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
335 static TopoDS_Solid aSolid;
336 if ( aSolid.IsNull() )
338 aSolid = BRepPrimAPI_MakeBox(1,1,1);
343 //=======================================================================
345 * \brief Return diagonal size of bounding box of a shape
347 //=======================================================================
349 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
351 if ( !aShape.IsNull() ) {
353 // avoid too long waiting on large shapes. PreciseBoundingBox() was added
354 // to assure same result which else depends on presence of triangulation (IPAL52557).
355 const int maxNbFaces = 4000;
357 for ( TopExp_Explorer f( aShape, TopAbs_FACE ); f.More() && nbFaces < maxNbFaces; f.Next() )
359 bool isPrecise = false;
360 if ( nbFaces < maxNbFaces )
363 GEOMUtils::PreciseBoundingBox( aShape, Box );
371 BRepBndLib::Add( aShape, Box );
374 return sqrt( Box.SquareExtent() );
379 //=======================================================================
381 * \brief Return diagonal size of bounding box of shape to mesh
383 //=======================================================================
385 double SMESH_Mesh::GetShapeDiagonalSize() const
387 if ( _shapeDiagonal == 0. && _isShapeToMesh )
388 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
390 return _shapeDiagonal;
393 //================================================================================
395 * \brief Load mesh from study file
397 //================================================================================
399 void SMESH_Mesh::Load()
405 //=======================================================================
407 * \brief Remove all nodes and elements
409 //=======================================================================
411 void SMESH_Mesh::Clear()
413 if ( HasShapeToMesh() ) // remove all nodes and elements
416 _myMeshDS->ClearMesh();
418 // update compute state of submeshes
419 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
421 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
422 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
423 sm->ComputeStateEngine( SMESH_subMesh::CLEAN ); // for event listeners (issue 0020918)
424 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
427 else // remove only nodes/elements computed by algorithms
429 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
431 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
432 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CLEAN );
433 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
434 sm->ComputeSubMeshStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
437 GetMeshDS()->Modified();
441 //=======================================================================
443 * \brief Remove all nodes and elements of indicated shape
445 //=======================================================================
447 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
449 // clear sub-meshes; get ready to re-compute as a side-effect
450 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
452 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
453 /*complexShapeFirst=*/false);
454 while ( smIt->more() )
457 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
458 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
459 // all other shapes depends on vertices so they are already cleaned
460 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
461 // to recompute even if failed
462 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
467 //=======================================================================
468 //function : UNVToMesh
470 //=======================================================================
472 int SMESH_Mesh::UNVToMesh(const char* theFileName)
474 if ( _isShapeToMesh )
475 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
476 _isShapeToMesh = false;
478 DriverUNV_R_SMDS_Mesh myReader;
479 myReader.SetMesh(_myMeshDS);
480 myReader.SetFile(theFileName);
481 myReader.SetMeshId(-1);
484 TGroupNamesMap& aGroupNames = myReader.GetGroupNamesMap();
485 TGroupNamesMap::iterator gr2names;
486 int anId = 1 + ( _mapGroup.empty() ? 0 : _mapGroup.rbegin()->first );
487 for ( gr2names = aGroupNames.begin(); gr2names != aGroupNames.end(); ++gr2names )
489 SMDS_MeshGroup* aGroup = gr2names->first;
490 const std::string& aName = gr2names->second;
491 SMESHDS_Group* aGroupDS = new SMESHDS_Group( anId++, _myMeshDS, aGroup->GetType() );
492 aGroupDS->SMDSGroup() = std::move( *aGroup );
493 aGroupDS->SetStoreName( aName.c_str() );
494 AddGroup( aGroupDS );
500 //=======================================================================
501 //function : MEDToMesh
503 //=======================================================================
505 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
507 if ( _isShapeToMesh )
508 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
509 _isShapeToMesh = false;
511 DriverMED_R_SMESHDS_Mesh myReader;
512 myReader.SetMesh(_myMeshDS);
513 myReader.SetMeshId(-1);
514 myReader.SetFile(theFileName);
515 myReader.SetMeshName(theMeshName);
516 Driver_Mesh::Status status = myReader.Perform();
518 SMESH_ComputeErrorPtr er = myReader.GetError();
519 if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
522 // Reading groups (sub-meshes are out of scope of MED import functionality)
523 std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
524 std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
525 for ( ; name_type != aGroupNames.end(); name_type++ )
527 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str() );
529 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
531 aGroupDS->SetStoreName( name_type->first.c_str() );
532 myReader.GetGroup( aGroupDS );
537 _myMeshDS->Modified();
538 _myMeshDS->CompactMesh();
543 //=======================================================================
544 //function : STLToMesh
546 //=======================================================================
548 std::string SMESH_Mesh::STLToMesh(const char* theFileName)
551 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
552 _isShapeToMesh = false;
554 DriverSTL_R_SMDS_Mesh myReader;
555 myReader.SetMesh(_myMeshDS);
556 myReader.SetFile(theFileName);
557 myReader.SetMeshId(-1);
560 return myReader.GetName();
563 //================================================================================
565 * \brief Reads the given mesh from the CGNS file
566 * \param theFileName - name of the file
567 * \retval int - Driver_Mesh::Status
569 //================================================================================
571 int SMESH_Mesh::CGNSToMesh(const char* theFileName,
572 const int theMeshIndex,
573 std::string& theMeshName)
575 int res = Driver_Mesh::DRS_FAIL;
578 DriverCGNS_Read myReader;
579 myReader.SetMesh(_myMeshDS);
580 myReader.SetFile(theFileName);
581 myReader.SetMeshId(theMeshIndex);
582 res = myReader.Perform();
583 theMeshName = myReader.GetMeshName();
592 //================================================================================
594 * \brief Fill its data by reading a GMF file
596 //================================================================================
598 SMESH_ComputeErrorPtr SMESH_Mesh::GMFToMesh(const char* theFileName,
599 bool theMakeRequiredGroups)
601 DriverGMF_Read myReader;
602 myReader.SetMesh(_myMeshDS);
603 myReader.SetFile(theFileName);
604 myReader.SetMakeRequiredGroups( theMakeRequiredGroups );
606 //theMeshName = myReader.GetMeshName();
611 return myReader.GetError();
614 //=============================================================================
618 //=============================================================================
620 SMESH_Hypothesis::Hypothesis_Status
621 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
623 std::string* anError ) throw(SALOME_Exception)
625 Unexpect aCatch(SalomeException);
626 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
631 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
632 if ( !subMesh || !subMesh->GetId())
633 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
635 SMESH_Hypothesis *anHyp = GetHypothesis( anHypId );
637 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
639 bool isGlobalHyp = IsMainShape( aSubShape );
641 // NotConformAllowed can be only global
644 // NOTE: this is not a correct way to check a name of hypothesis,
645 // there should be an attribute of hypothesis saying that it can/can't
647 std::string hypName = anHyp->GetName();
648 if ( hypName == "NotConformAllowed" )
650 if(MYDEBUG) MESSAGE( "Hypothesis <NotConformAllowed> can be only global" );
651 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
657 bool isAlgo = ( anHyp->GetType() != SMESHDS_Hypothesis::PARAM_ALGO );
658 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
660 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
662 if ( anError && SMESH_Hypothesis::IsStatusFatal(ret) && subMesh->GetComputeError() )
663 *anError = subMesh->GetComputeError()->myComment;
666 if ( !SMESH_Hypothesis::IsStatusFatal(ret) &&
667 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
669 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
671 SMESH_Hypothesis::Hypothesis_Status ret2 =
672 subMesh->SubMeshesAlgoStateEngine(event, anHyp, /*exitOnFatal=*/true);
676 if ( SMESH_Hypothesis::IsStatusFatal( ret ))
678 if ( anError && subMesh->GetComputeError() )
679 *anError = subMesh->GetComputeError()->myComment;
681 event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
682 subMesh->AlgoStateEngine(event, anHyp);
686 // check concurrent hypotheses on ancestors
687 if (ret < SMESH_Hypothesis::HYP_CONCURRENT && !isGlobalHyp )
689 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
690 while ( smIt->more() ) {
691 SMESH_subMesh* sm = smIt->next();
692 if ( sm->IsApplicableHypothesis( anHyp )) {
693 ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
702 HasModificationsToDiscard(); // to reset _isModified flag if a mesh becomes empty
703 GetMeshDS()->Modified();
705 if(MYDEBUG) subMesh->DumpAlgoState(true);
706 if(MYDEBUG) SCRUTE(ret);
710 //=============================================================================
714 //=============================================================================
716 SMESH_Hypothesis::Hypothesis_Status
717 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
718 int anHypId) throw( SALOME_Exception )
720 Unexpect aCatch(SalomeException);
721 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
723 StudyContextStruct *sc = _gen->GetStudyContext();
724 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
725 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
727 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
728 if(MYDEBUG) { SCRUTE(anHyp->GetType()); }
732 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
733 SMESH_subMesh::algo_event event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
735 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
737 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
739 // there may appear concurrent hyps that were covered by the removed hyp
740 if (ret < SMESH_Hypothesis::HYP_CONCURRENT &&
741 subMesh->IsApplicableHypothesis( anHyp ) &&
742 subMesh->CheckConcurrentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
743 ret = SMESH_Hypothesis::HYP_CONCURRENT;
746 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
747 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
749 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
751 SMESH_Hypothesis::Hypothesis_Status ret2 =
752 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
753 if (ret2 > ret) // more severe
756 // check concurrent hypotheses on ancestors
757 if (ret < SMESH_Hypothesis::HYP_CONCURRENT && !IsMainShape( aSubShape ) )
759 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
760 while ( smIt->more() ) {
761 SMESH_subMesh* sm = smIt->next();
762 if ( sm->IsApplicableHypothesis( anHyp )) {
763 ret2 = sm->CheckConcurrentHypothesis( anHyp->GetType() );
773 HasModificationsToDiscard(); // to reset _isModified flag if mesh become empty
774 GetMeshDS()->Modified();
776 if(MYDEBUG) subMesh->DumpAlgoState(true);
777 if(MYDEBUG) SCRUTE(ret);
781 //=============================================================================
785 //=============================================================================
787 const std::list<const SMESHDS_Hypothesis*>&
788 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
789 throw(SALOME_Exception)
791 return _myMeshDS->GetHypothesis(aSubShape);
794 //=======================================================================
796 * \brief Return the hypothesis assigned to the shape
797 * \param aSubShape - the shape to check
798 * \param aFilter - the hypothesis filter
799 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
800 * \param assignedTo - to return the shape the found hypo is assigned to
801 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
803 //=======================================================================
805 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
806 const SMESH_HypoFilter& aFilter,
807 const bool andAncestors,
808 TopoDS_Shape* assignedTo) const
810 return GetHypothesis( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
811 aFilter, andAncestors, assignedTo );
814 //=======================================================================
816 * \brief Return the hypothesis assigned to the shape of a sub-mesh
817 * \param aSubMesh - the sub-mesh to check
818 * \param aFilter - the hypothesis filter
819 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
820 * \param assignedTo - to return the shape the found hypo is assigned to
821 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
823 //=======================================================================
825 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const SMESH_subMesh * aSubMesh,
826 const SMESH_HypoFilter& aFilter,
827 const bool andAncestors,
828 TopoDS_Shape* assignedTo) const
830 if ( !aSubMesh ) return 0;
833 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
834 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
835 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
836 for ( ; hyp != hypList.end(); hyp++ ) {
837 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
838 if ( aFilter.IsOk( h, aSubShape)) {
839 if ( assignedTo ) *assignedTo = aSubShape;
846 // user sorted submeshes of ancestors, according to stored submesh priority
847 std::vector< SMESH_subMesh * > & ancestors =
848 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
849 SortByMeshOrder( ancestors );
851 std::vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
852 for ( ; smIt != ancestors.end(); smIt++ )
854 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
855 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
856 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
857 for ( ; hyp != hypList.end(); hyp++ ) {
858 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
859 if (aFilter.IsOk( h, curSh )) {
860 if ( assignedTo ) *assignedTo = curSh;
869 //================================================================================
871 * \brief Return hypotheses assigned to the shape
872 * \param aSubShape - the shape to check
873 * \param aFilter - the hypothesis filter
874 * \param aHypList - the list of the found hypotheses
875 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
876 * \retval int - number of unique hypos in aHypList
878 //================================================================================
880 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
881 const SMESH_HypoFilter& aFilter,
882 std::list <const SMESHDS_Hypothesis * >& aHypList,
883 const bool andAncestors,
884 std::list< TopoDS_Shape > * assignedTo/*=0*/) const
886 return GetHypotheses( const_cast< SMESH_Mesh* >(this)->GetSubMesh( aSubShape ),
887 aFilter, aHypList, andAncestors, assignedTo );
890 //================================================================================
892 * \brief Return hypotheses assigned to the shape of a sub-mesh
893 * \param aSubShape - the sub-mesh to check
894 * \param aFilter - the hypothesis filter
895 * \param aHypList - the list of the found hypotheses
896 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
897 * \retval int - number of unique hypos in aHypList
899 //================================================================================
901 int SMESH_Mesh::GetHypotheses(const SMESH_subMesh * aSubMesh,
902 const SMESH_HypoFilter& aFilter,
903 std::list <const SMESHDS_Hypothesis * >& aHypList,
904 const bool andAncestors,
905 std::list< TopoDS_Shape > * assignedTo/*=0*/) const
907 if ( !aSubMesh ) return 0;
909 std::set< std::string > hypTypes; // to exclude same type hypos from the result list
912 // only one main hypothesis is allowed
913 bool mainHypFound = false;
916 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp;
917 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
918 if ( hypTypes.insert( (*hyp)->GetName() ).second )
920 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
924 // get hypos from aSubShape
926 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
927 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
928 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
930 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
931 if (( aFilter.IsOk( h, aSubShape )) &&
932 ( h->IsAuxiliary() || !mainHypFound ) &&
933 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
935 aHypList.push_back( *hyp );
937 if ( !h->IsAuxiliary() )
939 if ( assignedTo ) assignedTo->push_back( aSubShape );
944 // get hypos from ancestors of aSubShape
947 // user sorted submeshes of ancestors, according to stored submesh priority
948 std::vector< SMESH_subMesh * > & ancestors =
949 const_cast< std::vector< SMESH_subMesh * > & > ( aSubMesh->GetAncestors() );
950 SortByMeshOrder( ancestors );
952 std::vector<SMESH_subMesh*>::const_iterator smIt = ancestors.begin();
953 for ( ; smIt != ancestors.end(); smIt++ )
955 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
956 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
957 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
959 const SMESH_Hypothesis* h = cSMESH_Hyp( *hyp );
960 if (( aFilter.IsOk( h, curSh )) &&
961 ( h->IsAuxiliary() || !mainHypFound ) &&
962 ( h->IsAuxiliary() || hypTypes.insert( h->GetName() ).second ))
964 aHypList.push_back( *hyp );
966 if ( !h->IsAuxiliary() )
968 if ( assignedTo ) assignedTo->push_back( curSh );
976 //================================================================================
978 * \brief Return a hypothesis by its ID
980 //================================================================================
982 SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const int anHypId) const
984 StudyContextStruct *sc = _gen->GetStudyContext();
985 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
988 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
992 //=============================================================================
996 //=============================================================================
998 const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
1000 Unexpect aCatch(SalomeException);
1001 return _myMeshDS->GetScript()->GetCommands();
1004 //=============================================================================
1008 //=============================================================================
1009 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
1011 Unexpect aCatch(SalomeException);
1012 _myMeshDS->GetScript()->Clear();
1015 //=============================================================================
1017 * Get or Create the SMESH_subMesh object implementation
1019 //=============================================================================
1021 SMESH_subMesh * SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
1022 throw(SALOME_Exception)
1024 int index = _myMeshDS->ShapeToIndex(aSubShape);
1025 if ( !index && aSubShape.IsNull() )
1028 // for submeshes on GEOM Group
1029 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND )
1031 TopoDS_Iterator it( aSubShape );
1034 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
1035 // fill map of Ancestors
1036 while ( _nbSubShapes < index )
1037 fillAncestorsMap( _myMeshDS->IndexToShape( ++_nbSubShapes ));
1041 // return NULL; // neither sub-shape nor a group
1043 SMESH_subMesh* aSubMesh = _subMeshHolder->Get( index );
1046 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
1047 _subMeshHolder->Add( index, aSubMesh );
1049 // include non-computable sub-meshes in SMESH_subMesh::_ancestors of sub-submeshes
1050 switch ( aSubShape.ShapeType() ) {
1051 case TopAbs_COMPOUND:
1054 for ( TopoDS_Iterator subIt( aSubShape ); subIt.More(); subIt.Next() )
1056 SMESH_subMesh* sm = GetSubMesh( subIt.Value() );
1057 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*inclideSelf=*/true);
1058 while ( smIt->more() )
1059 smIt->next()->ClearAncestors();
1067 //=============================================================================
1069 * Get the SMESH_subMesh object implementation. Don't create it, return null
1070 * if it does not exist.
1072 //=============================================================================
1074 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
1075 throw(SALOME_Exception)
1077 int index = _myMeshDS->ShapeToIndex(aSubShape);
1078 return GetSubMeshContaining( index );
1081 //=============================================================================
1083 * Get the SMESH_subMesh object implementation. Don't create it, return null
1084 * if it does not exist.
1086 //=============================================================================
1088 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
1089 throw(SALOME_Exception)
1091 SMESH_subMesh *aSubMesh = _subMeshHolder->Get( aShapeID );
1096 //================================================================================
1098 * \brief Return sub-meshes of groups containing the given sub-shape
1100 //================================================================================
1102 std::list<SMESH_subMesh*>
1103 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
1104 throw(SALOME_Exception)
1106 std::list<SMESH_subMesh*> found;
1108 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
1112 // sub-meshes of groups have max IDs, so search from the map end
1113 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator( /*reverse=*/true ) );
1114 while ( smIt->more() ) {
1115 SMESH_subMesh* sm = smIt->next();
1116 SMESHDS_SubMesh * ds = sm->GetSubMeshDS();
1117 if ( ds && ds->IsComplexSubmesh() ) {
1118 if ( SMESH_MesherHelper::IsSubShape( aSubShape, sm->GetSubShape() ))
1120 found.push_back( sm );
1124 break; // the rest sub-meshes are not those of groups
1128 if ( found.empty() ) // maybe the main shape is a COMPOUND (issue 0021530)
1130 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1131 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1133 TopoDS_Iterator it( mainSM->GetSubShape() );
1134 if ( it.Value().ShapeType() == aSubShape.ShapeType() &&
1135 SMESH_MesherHelper::IsSubShape( aSubShape, mainSM->GetSubShape() ))
1136 found.push_back( mainSM );
1139 else // issue 0023068
1141 if ( SMESH_subMesh * mainSM = GetSubMeshContaining(1) )
1142 if ( mainSM->GetSubShape().ShapeType() == TopAbs_COMPOUND )
1143 found.push_back( mainSM );
1147 //=======================================================================
1148 //function : IsUsedHypothesis
1149 //purpose : Return True if anHyp is used to mesh aSubShape
1150 //=======================================================================
1152 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
1153 const SMESH_subMesh* aSubMesh)
1155 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
1157 // check if anHyp can be used to mesh aSubMesh
1158 if ( !aSubMesh || !aSubMesh->IsApplicableHypothesis( hyp ))
1161 SMESH_Algo *algo = aSubMesh->GetAlgo();
1164 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
1165 return ( anHyp == algo );
1167 // algorithm parameter
1170 // look trough hypotheses used by algo
1171 const SMESH_HypoFilter* hypoKind;
1172 if (( hypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() ))) {
1173 std::list <const SMESHDS_Hypothesis * > usedHyps;
1174 if ( GetHypotheses( aSubMesh, *hypoKind, usedHyps, true ))
1175 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
1182 //=======================================================================
1183 //function : NotifySubMeshesHypothesisModification
1184 //purpose : Say all submeshes using theChangedHyp that it has been modified
1185 //=======================================================================
1187 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
1189 Unexpect aCatch(SalomeException);
1191 if ( !GetMeshDS()->IsUsedHypothesis( hyp ))
1195 _callUp->HypothesisModified( hyp->GetID() );
1198 const SMESH_HypoFilter* compatibleHypoKind;
1199 std::list <const SMESHDS_Hypothesis * > usedHyps;
1200 std::vector< SMESH_subMesh* > smToNotify;
1201 bool allMeshedEdgesNotified = true;
1203 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1204 while ( smIt->more() )
1206 SMESH_subMesh* aSubMesh = smIt->next();
1207 bool toNotify = false;
1209 // if aSubMesh meshing depends on hyp,
1210 // we call aSubMesh->AlgoStateEngine( MODIF_HYP, hyp ) that causes either
1211 // 1) clearing already computed aSubMesh or
1212 // 2) changing algo_state from MISSING_HYP to HYP_OK when parameters of hyp becomes valid,
1213 // other possible changes are not interesting. (IPAL0052457 - assigning hyp performance pb)
1214 if ( aSubMesh->GetComputeState() == SMESH_subMesh::COMPUTE_OK ||
1215 aSubMesh->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE ||
1216 aSubMesh->GetAlgoState() == SMESH_subMesh::MISSING_HYP ||
1217 hyp->DataDependOnParams() )
1219 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
1221 if (( aSubMesh->IsApplicableHypothesis( hyp )) &&
1222 ( algo = aSubMesh->GetAlgo() ) &&
1223 ( compatibleHypoKind = algo->GetCompatibleHypoFilter( !hyp->IsAuxiliary() )) &&
1224 ( compatibleHypoKind->IsOk( hyp, aSubShape )))
1226 // check if hyp is used by algo
1228 toNotify = ( GetHypotheses( aSubMesh, *compatibleHypoKind, usedHyps, true ) &&
1229 std::find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() );
1234 smToNotify.push_back( aSubMesh );
1235 if ( aSubMesh->GetAlgoState() == SMESH_subMesh::MISSING_HYP )
1236 allMeshedEdgesNotified = false; // update of algo state needed, not mesh clearing
1240 if ( !aSubMesh->IsEmpty() &&
1241 aSubMesh->GetSubShape().ShapeType() == TopAbs_EDGE )
1242 allMeshedEdgesNotified = false;
1245 if ( smToNotify.empty() )
1248 // if all meshed EDGEs will be notified then the notification is equivalent
1249 // to the whole mesh clearing, which is usually faster
1250 if ( allMeshedEdgesNotified && NbNodes() > 0 )
1256 // notify in reverse order to avoid filling the pool of IDs
1257 for ( int i = smToNotify.size()-1; i >= 0; --i )
1258 smToNotify[i]->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
1259 const_cast< SMESH_Hypothesis*>( hyp ));
1261 HasModificationsToDiscard(); // to reset _isModified flag if mesh becomes empty
1262 GetMeshDS()->Modified();
1265 //=============================================================================
1267 * Auto color functionality
1269 //=============================================================================
1270 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1272 Unexpect aCatch(SalomeException);
1273 _isAutoColor = theAutoColor;
1276 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1278 Unexpect aCatch(SalomeException);
1279 return _isAutoColor;
1282 //=======================================================================
1283 //function : SetIsModified
1284 //purpose : Set the flag meaning that the mesh has been edited "manually"
1285 //=======================================================================
1287 void SMESH_Mesh::SetIsModified(bool isModified)
1289 _isModified = isModified;
1292 // check if mesh becomes empty as result of modification
1293 HasModificationsToDiscard();
1296 //=======================================================================
1297 //function : HasModificationsToDiscard
1298 //purpose : Return true if the mesh has been edited since a total re-compute
1299 // and those modifications may prevent successful partial re-compute.
1300 // As a side effect reset _isModified flag if mesh is empty
1302 //=======================================================================
1304 bool SMESH_Mesh::HasModificationsToDiscard() const
1306 if ( ! _isModified )
1309 // return true if the next Compute() will be partial and
1310 // existing but changed elements may prevent successful re-compute
1311 bool hasComputed = false, hasNotComputed = false;
1312 SMESH_subMeshIteratorPtr smIt( _subMeshHolder->GetIterator() );
1313 while ( smIt->more() )
1315 const SMESH_subMesh* aSubMesh = smIt->next();
1316 switch ( aSubMesh->GetSubShape().ShapeType() )
1321 if ( aSubMesh->IsMeshComputed() )
1324 hasNotComputed = true;
1325 if ( hasComputed && hasNotComputed)
1331 if ( NbNodes() < 1 )
1332 const_cast<SMESH_Mesh*>(this)->_isModified = false;
1337 //=============================================================================
1339 * \brief Return true if all sub-meshes are computed OK - to update an icon
1341 //=============================================================================
1343 bool SMESH_Mesh::IsComputedOK()
1345 if ( NbNodes() == 0 )
1348 // if ( !HasShapeToMesh() )
1351 if ( SMESH_subMesh* mainSM = GetSubMeshContaining( 1 ))
1353 SMESH_subMeshIteratorPtr smIt = mainSM->getDependsOnIterator(/*includeSelf=*/true);
1354 while ( smIt->more() )
1356 const SMESH_subMesh* sm = smIt->next();
1357 if ( !sm->IsAlwaysComputed() )
1358 switch ( sm->GetComputeState() )
1360 case SMESH_subMesh::NOT_READY:
1361 case SMESH_subMesh::COMPUTE_OK:
1363 case SMESH_subMesh::FAILED_TO_COMPUTE:
1364 case SMESH_subMesh::READY_TO_COMPUTE:
1372 //================================================================================
1374 * \brief Check if any groups of the same type have equal names
1376 //================================================================================
1378 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1380 // Corrected for Mantis issue 0020028
1381 std::map< SMDSAbs_ElementType, std::set< std::string > > aGroupNames;
1382 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1384 SMESH_Group* aGroup = it->second;
1385 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1386 std::string aGroupName = aGroup->GetName();
1387 aGroupName.resize( MAX_MED_GROUP_NAME_LENGTH );
1388 if ( !aGroupNames[aType].insert(aGroupName).second )
1395 //================================================================================
1397 * \brief Export the mesh to a med file
1398 * \param [in] file - name of the MED file
1399 * \param [in] theMeshName - name of this mesh
1400 * \param [in] theAutoGroups - boolean parameter for creating/not creating
1401 * the groups Group_On_All_Nodes, Group_On_All_Faces, ... ;
1402 * the typical use is auto_groups=false.
1403 * \param [in] theMinor - define the minor version (y, where version is x.y.z) of MED file format.
1404 * The theMinor must be between 0 and the current minor version of MED file library.
1405 * If theMinor is equal to -1, the minor version is not changed (default).
1406 * The major version (x, where version is x.y.z) cannot be changed.
1407 * \param [in] meshPart - mesh data to export
1408 * \param [in] theAutoDimension - if \c true, a space dimension of a MED mesh can be either
1409 * - 1D if all mesh nodes lie on OX coordinate axis, or
1410 * - 2D if all mesh nodes lie on XOY coordinate plane, or
1411 * - 3D in the rest cases.
1412 * If \a theAutoDimension is \c false, the space dimension is always 3.
1413 * \param [in] theAddODOnVertices - to create 0D elements on all vertices
1414 * \param [in] theAllElemsToGroup - to make every element to belong to any group (PAL23413)
1415 * \param [in] ZTolerance - tolerance in Z direction. If Z coordinate of a node is close to zero
1416 * within a given tolerance, the coordinate is set to zero.
1417 * If \a ZTolerance is negative, the node coordinates are kept as is.
1418 * \return int - mesh index in the file
1420 //================================================================================
1422 void SMESH_Mesh::ExportMED(const char * file,
1423 const char* theMeshName,
1426 const SMESHDS_Mesh* meshPart,
1427 bool theAutoDimension,
1428 bool theAddODOnVertices,
1429 double theZTolerance,
1430 bool theAllElemsToGroup)
1431 throw(SALOME_Exception)
1433 MESSAGE("MED_VERSION:"<< theVersion);
1436 DriverMED_W_SMESHDS_Mesh myWriter;
1437 myWriter.SetFile ( file , theVersion);
1438 myWriter.SetMesh ( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1439 myWriter.SetAutoDimension( theAutoDimension );
1440 myWriter.AddODOnVertices ( theAddODOnVertices );
1441 myWriter.SetZTolerance ( theZTolerance );
1443 myWriter.SetMeshId ( _id );
1445 myWriter.SetMeshId ( -1 );
1446 myWriter.SetMeshName ( theMeshName );
1449 if ( theAutoGroups ) {
1450 myWriter.AddGroupOfNodes();
1451 myWriter.AddGroupOfEdges();
1452 myWriter.AddGroupOfFaces();
1453 myWriter.AddGroupOfVolumes();
1454 myWriter.AddGroupOf0DElems();
1455 myWriter.AddGroupOfBalls();
1457 if ( theAllElemsToGroup )
1458 myWriter.AddAllToGroup();
1460 // Pass groups to writer. Provide unique group names.
1461 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1464 std::map< SMDSAbs_ElementType, std::set<std::string> > aGroupNames;
1466 int maxNbIter = 10000; // to guarantee cycle finish
1467 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
1468 it != _mapGroup.end();
1470 SMESH_Group* aGroup = it->second;
1471 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1473 SMDSAbs_ElementType aType = aGroupDS->GetType();
1474 std::string aGroupName0 = aGroup->GetName();
1475 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1476 std::string aGroupName = aGroupName0;
1477 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1478 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1479 aGroupName = aString;
1480 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1482 aGroupDS->SetStoreName( aGroupName.c_str() );
1483 myWriter.AddGroup( aGroupDS );
1490 SMESH_CATCH( SMESH::throwSalomeEx );
1493 //================================================================================
1495 * \brief Export the mesh to a SAUV file
1497 //================================================================================
1499 void SMESH_Mesh::ExportSAUV(const char *file,
1500 const char* theMeshName,
1502 throw(SALOME_Exception)
1504 std::string medfilename(file);
1505 medfilename += ".med";
1508 cmd = "%PYTHONBIN% ";
1513 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1515 system(cmd.c_str());
1516 ExportMED(medfilename.c_str(), theMeshName, theAutoGroups, /*minor=*/-1,
1517 /*meshPart=*/NULL, /*theAutoDimension=*/false, /*theAddODOnVertices=*/false,
1518 /*zTol=*/-1, /*theAllElemsToGroup=*/true ); // theAllElemsToGroup is for PAL0023413
1520 cmd = "%PYTHONBIN% ";
1525 cmd += "from medutilities import convert ; convert(r'" + medfilename + "', 'MED', 'GIBI', 1, r'" + file + "')";
1527 system(cmd.c_str());
1529 cmd = "%PYTHONBIN% ";
1534 cmd += "from medutilities import my_remove ; my_remove(r'" + medfilename + "')";
1536 system(cmd.c_str());
1539 //================================================================================
1541 * \brief Export the mesh to a DAT file
1543 //================================================================================
1545 void SMESH_Mesh::ExportDAT(const char * file,
1546 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1548 Unexpect aCatch(SalomeException);
1549 DriverDAT_W_SMDS_Mesh myWriter;
1550 myWriter.SetFile( file );
1551 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1552 myWriter.SetMeshId(_id);
1556 //================================================================================
1558 * \brief Export the mesh to an UNV file
1560 //================================================================================
1562 void SMESH_Mesh::ExportUNV(const char * file,
1563 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1565 Unexpect aCatch(SalomeException);
1566 DriverUNV_W_SMDS_Mesh myWriter;
1567 myWriter.SetFile( file );
1568 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS );
1569 myWriter.SetMeshId(_id);
1570 // myWriter.SetGroups(_mapGroup);
1572 // pass group names to SMESHDS
1575 std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
1576 for ( ; it != _mapGroup.end(); it++ ) {
1577 SMESH_Group* aGroup = it->second;
1578 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1580 std::string aGroupName = aGroup->GetName();
1581 aGroupDS->SetStoreName( aGroupName.c_str() );
1582 myWriter.AddGroup( aGroupDS );
1589 //================================================================================
1591 * \brief Export the mesh to an STL file
1593 //================================================================================
1595 void SMESH_Mesh::ExportSTL(const char * file,
1598 const SMESHDS_Mesh* meshPart) throw(SALOME_Exception)
1600 Unexpect aCatch(SalomeException);
1601 DriverSTL_W_SMDS_Mesh myWriter;
1602 myWriter.SetFile( file );
1603 myWriter.SetIsAscii( isascii );
1604 myWriter.SetMesh( meshPart ? (SMESHDS_Mesh*) meshPart : _myMeshDS);
1605 myWriter.SetMeshId(_id);
1606 if ( name ) myWriter.SetName( name );
1610 //================================================================================
1612 * \brief Export the mesh to the CGNS file
1614 //================================================================================
1616 void SMESH_Mesh::ExportCGNS(const char * file,
1617 const SMESHDS_Mesh* meshDS,
1618 const char * meshName,
1619 const bool groupElemsByType)
1621 int res = Driver_Mesh::DRS_FAIL;
1623 // pass group names to SMESHDS
1624 std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin();
1625 for ( ; it != _mapGroup.end(); it++ ) {
1626 SMESH_Group* group = it->second;
1627 SMESHDS_GroupBase* groupDS = group->GetGroupDS();
1629 std::string groupName = group->GetName();
1630 groupDS->SetStoreName( groupName.c_str() );
1635 DriverCGNS_Write myWriter;
1636 myWriter.SetFile( file );
1637 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1638 myWriter.SetMeshName( SMESH_Comment("Mesh_") << meshDS->GetPersistentId());
1639 if ( meshName && meshName[0] )
1640 myWriter.SetMeshName( meshName );
1641 myWriter.SetElementsByType( groupElemsByType );
1642 res = myWriter.Perform();
1643 if ( res != Driver_Mesh::DRS_OK )
1645 SMESH_ComputeErrorPtr err = myWriter.GetError();
1646 if ( err && !err->IsOK() && !err->myComment.empty() )
1647 throw SALOME_Exception(("Export failed: " + err->myComment ).c_str() );
1651 if ( res != Driver_Mesh::DRS_OK )
1652 throw SALOME_Exception("Export failed");
1655 //================================================================================
1657 * \brief Export the mesh to a GMF file
1659 //================================================================================
1661 void SMESH_Mesh::ExportGMF(const char * file,
1662 const SMESHDS_Mesh* meshDS,
1663 bool withRequiredGroups)
1665 DriverGMF_Write myWriter;
1666 myWriter.SetFile( file );
1667 myWriter.SetMesh( const_cast<SMESHDS_Mesh*>( meshDS ));
1668 myWriter.SetExportRequiredGroups( withRequiredGroups );
1673 //================================================================================
1675 * \brief Return a ratio of "compute cost" of computed sub-meshes to the whole
1678 //================================================================================
1680 double SMESH_Mesh::GetComputeProgress() const
1682 double totalCost = 1e-100, computedCost = 0;
1683 const SMESH_subMesh* curSM = _gen->GetCurrentSubMesh();
1685 // get progress of a current algo
1686 TColStd_MapOfInteger currentSubIds;
1688 if ( SMESH_Algo* algo = curSM->GetAlgo() )
1690 int algoNotDoneCost = 0, algoDoneCost = 0;
1691 const std::vector<SMESH_subMesh*>& smToCompute = algo->SubMeshesToCompute();
1692 for ( size_t i = 0; i < smToCompute.size(); ++i )
1694 if ( smToCompute[i]->IsEmpty() || smToCompute.size() == 1 )
1695 algoNotDoneCost += smToCompute[i]->GetComputeCost();
1697 algoDoneCost += smToCompute[i]->GetComputeCost();
1698 currentSubIds.Add( smToCompute[i]->GetId() );
1704 rate = algo->GetProgress();
1708 std::cerr << "Exception in " << algo->GetName() << "::GetProgress()" << std::endl;
1711 if ( 0. < rate && rate < 1.001 )
1713 computedCost += rate * ( algoDoneCost + algoNotDoneCost );
1717 rate = algo->GetProgressByTic();
1718 computedCost += algoDoneCost + rate * algoNotDoneCost;
1720 // cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
1723 // get cost of already treated sub-meshes
1724 if ( SMESH_subMesh* mainSM = GetSubMeshContaining( 1 ))
1726 SMESH_subMeshIteratorPtr smIt = mainSM->getDependsOnIterator(/*includeSelf=*/true);
1727 while ( smIt->more() )
1729 const SMESH_subMesh* sm = smIt->next();
1730 const int smCost = sm->GetComputeCost();
1731 totalCost += smCost;
1732 if ( !currentSubIds.Contains( sm->GetId() ) )
1734 if (( !sm->IsEmpty() ) ||
1735 ( sm->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
1736 !sm->DependsOn( curSM ) ))
1737 computedCost += smCost;
1741 // cout << "Total: " << totalCost
1742 // << " computed: " << computedCost << " progress: " << computedCost / totalCost
1743 // << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
1744 return computedCost / totalCost;
1747 //================================================================================
1749 * \brief Return number of nodes in the mesh
1751 //================================================================================
1753 int SMESH_Mesh::NbNodes() const throw(SALOME_Exception)
1755 Unexpect aCatch(SalomeException);
1756 return _myMeshDS->NbNodes();
1759 //================================================================================
1761 * \brief Return number of edges of given order in the mesh
1763 //================================================================================
1765 int SMESH_Mesh::Nb0DElements() const throw(SALOME_Exception)
1767 Unexpect aCatch(SalomeException);
1768 return _myMeshDS->GetMeshInfo().Nb0DElements();
1771 //================================================================================
1773 * \brief Return number of edges of given order in the mesh
1775 //================================================================================
1777 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1779 Unexpect aCatch(SalomeException);
1780 return _myMeshDS->GetMeshInfo().NbEdges(order);
1783 //================================================================================
1785 * \brief Return number of faces of given order in the mesh
1787 //================================================================================
1789 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1791 Unexpect aCatch(SalomeException);
1792 return _myMeshDS->GetMeshInfo().NbFaces(order);
1795 //================================================================================
1797 * \brief Return the number of faces in the mesh
1799 //================================================================================
1801 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1803 Unexpect aCatch(SalomeException);
1804 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1807 //================================================================================
1809 * \brief Return number of biquadratic triangles in the mesh
1811 //================================================================================
1813 int SMESH_Mesh::NbBiQuadTriangles() const throw(SALOME_Exception)
1815 Unexpect aCatch(SalomeException);
1816 return _myMeshDS->GetMeshInfo().NbBiQuadTriangles();
1819 //================================================================================
1821 * \brief Return the number nodes faces in the mesh
1823 //================================================================================
1825 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1827 Unexpect aCatch(SalomeException);
1828 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1831 //================================================================================
1833 * \brief Return number of biquadratic quadrangles in the mesh
1835 //================================================================================
1837 int SMESH_Mesh::NbBiQuadQuadrangles() const throw(SALOME_Exception)
1839 Unexpect aCatch(SalomeException);
1840 return _myMeshDS->GetMeshInfo().NbBiQuadQuadrangles();
1843 //================================================================================
1845 * \brief Return the number of polygonal faces in the mesh
1847 //================================================================================
1849 int SMESH_Mesh::NbPolygons(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1851 Unexpect aCatch(SalomeException);
1852 return _myMeshDS->GetMeshInfo().NbPolygons(order);
1855 //================================================================================
1857 * \brief Return number of volumes of given order in the mesh
1859 //================================================================================
1861 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1863 Unexpect aCatch(SalomeException);
1864 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1867 //================================================================================
1869 * \brief Return number of tetrahedrons of given order in the mesh
1871 //================================================================================
1873 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1875 Unexpect aCatch(SalomeException);
1876 return _myMeshDS->GetMeshInfo().NbTetras(order);
1879 //================================================================================
1881 * \brief Return number of hexahedrons of given order in the mesh
1883 //================================================================================
1885 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1887 Unexpect aCatch(SalomeException);
1888 return _myMeshDS->GetMeshInfo().NbHexas(order);
1891 //================================================================================
1893 * \brief Return number of triquadratic hexahedrons in the mesh
1895 //================================================================================
1897 int SMESH_Mesh::NbTriQuadraticHexas() const throw(SALOME_Exception)
1899 Unexpect aCatch(SalomeException);
1900 return _myMeshDS->GetMeshInfo().NbTriQuadHexas();
1903 //================================================================================
1905 * \brief Return number of pyramids of given order in the mesh
1907 //================================================================================
1909 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1911 Unexpect aCatch(SalomeException);
1912 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1915 //================================================================================
1917 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1919 //================================================================================
1921 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) const throw(SALOME_Exception)
1923 Unexpect aCatch(SalomeException);
1924 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1927 int SMESH_Mesh::NbQuadPrisms() const throw (SALOME_Exception)
1929 Unexpect aCatch(SalomeException);
1930 return _myMeshDS->GetMeshInfo().NbQuadPrisms();
1933 int SMESH_Mesh::NbBiQuadPrisms() const throw (SALOME_Exception)
1935 Unexpect aCatch(SalomeException);
1936 return _myMeshDS->GetMeshInfo().NbBiQuadPrisms();
1940 //================================================================================
1942 * \brief Return number of hexagonal prisms in the mesh
1944 //================================================================================
1946 int SMESH_Mesh::NbHexagonalPrisms() const throw(SALOME_Exception)
1948 Unexpect aCatch(SalomeException);
1949 return _myMeshDS->GetMeshInfo().NbHexPrisms();
1952 //================================================================================
1954 * \brief Return number of polyhedrons in the mesh
1956 //================================================================================
1958 int SMESH_Mesh::NbPolyhedrons() const throw(SALOME_Exception)
1960 Unexpect aCatch(SalomeException);
1961 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1964 //================================================================================
1966 * \brief Return number of ball elements in the mesh
1968 //================================================================================
1970 int SMESH_Mesh::NbBalls() const throw(SALOME_Exception)
1972 Unexpect aCatch(SalomeException);
1973 return _myMeshDS->GetMeshInfo().NbBalls();
1976 //================================================================================
1978 * \brief Return number of submeshes in the mesh
1980 //================================================================================
1982 int SMESH_Mesh::NbSubMesh() const throw(SALOME_Exception)
1984 Unexpect aCatch(SalomeException);
1985 return _myMeshDS->NbSubMesh();
1988 //================================================================================
1990 * \brief Returns number of meshes in the Study, that is supposed to be
1991 * equal to SMESHDS_Document::NbMeshes()
1993 //================================================================================
1995 int SMESH_Mesh::NbMeshes() const // nb meshes in the Study
1997 return _myDocument->NbMeshes();
2000 //=======================================================================
2001 //function : IsNotConformAllowed
2002 //purpose : check if a hypothesis allowing notconform mesh is present
2003 //=======================================================================
2005 bool SMESH_Mesh::IsNotConformAllowed() const
2007 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
2009 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
2010 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
2013 //=======================================================================
2014 //function : IsMainShape
2016 //=======================================================================
2018 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
2020 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
2023 //=============================================================================
2027 //=============================================================================
2029 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
2030 const char* theName,
2032 const TopoDS_Shape& theShape,
2033 const SMESH_PredicatePtr& thePredicate)
2035 if ( _mapGroup.count( theId ))
2037 int id = ( theId < 0 ) ? _groupId : theId;
2038 SMESH_Group* aGroup = new SMESH_Group ( id, this, theType, theName, theShape, thePredicate );
2039 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
2040 _mapGroup[ id ] = aGroup;
2041 _groupId = 1 + _mapGroup.rbegin()->first;
2045 //================================================================================
2047 * \brief Creates a group based on an existing SMESHDS group. Group ID should be unique
2049 //================================================================================
2051 SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
2054 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
2056 std::map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
2057 if ( i_g != _mapGroup.end() && i_g->second )
2059 if ( i_g->second->GetGroupDS() == groupDS )
2062 throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup() wrong ID of SMESHDS_GroupBase"));
2064 SMESH_Group* aGroup = new SMESH_Group (groupDS);
2065 _mapGroup[ groupDS->GetID() ] = aGroup;
2066 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
2068 _groupId = 1 + _mapGroup.rbegin()->first;
2074 //================================================================================
2076 * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
2077 * \retval bool - true if new SMESH_Groups have been created
2080 //================================================================================
2082 bool SMESH_Mesh::SynchronizeGroups()
2084 const size_t nbGroups = _mapGroup.size();
2085 const std::set<SMESHDS_GroupBase*>& groups = _myMeshDS->GetGroups();
2086 std::set<SMESHDS_GroupBase*>::const_iterator gIt = groups.begin();
2087 for ( ; gIt != groups.end(); ++gIt )
2089 SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt;
2090 _groupId = groupDS->GetID();
2091 if ( !_mapGroup.count( _groupId ))
2092 _mapGroup[_groupId] = new SMESH_Group( groupDS );
2094 if ( !_mapGroup.empty() )
2095 _groupId = 1 + _mapGroup.rbegin()->first;
2097 return nbGroups < _mapGroup.size();
2100 //================================================================================
2102 * \brief Return iterator on all existing groups
2104 //================================================================================
2106 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
2108 typedef std::map <int, SMESH_Group *> TMap;
2109 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
2112 //=============================================================================
2114 * \brief Return a group by ID
2116 //=============================================================================
2118 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID) const
2120 std::map <int, SMESH_Group*>::const_iterator id_grp = _mapGroup.find( theGroupID );
2121 if ( id_grp == _mapGroup.end() )
2123 return id_grp->second;
2127 //=============================================================================
2129 * \brief Return IDs of all groups
2131 //=============================================================================
2133 std::list<int> SMESH_Mesh::GetGroupIds() const
2135 std::list<int> anIds;
2136 std::map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin();
2137 for ( ; it != _mapGroup.end(); it++ )
2138 anIds.push_back( it->first );
2143 //================================================================================
2145 * \brief Set a caller of methods at level of CORBA API implementation.
2146 * The set upCaller will be deleted by SMESH_Mesh
2148 //================================================================================
2150 void SMESH_Mesh::SetCallUp( TCallUp* upCaller )
2152 if ( _callUp ) delete _callUp;
2156 //=============================================================================
2160 //=============================================================================
2162 bool SMESH_Mesh::RemoveGroup( const int theGroupID )
2164 if (_mapGroup.find(theGroupID) == _mapGroup.end())
2166 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
2167 delete _mapGroup[theGroupID];
2168 _mapGroup.erase (theGroupID);
2170 _callUp->RemoveGroup( theGroupID );
2174 //=======================================================================
2175 //function : GetAncestors
2176 //purpose : return list of ancestors of theSubShape in the order
2177 // that lower dimension shapes come first.
2178 //=======================================================================
2180 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
2182 if ( _mapAncestors.Contains( theS ) )
2183 return _mapAncestors.FindFromKey( theS );
2185 static TopTools_ListOfShape emptyList;
2189 //=======================================================================
2191 //purpose : dumps contents of mesh to stream [ debug purposes ]
2192 //=======================================================================
2194 ostream& SMESH_Mesh::Dump(ostream& save)
2197 save << "========================== Dump contents of mesh ==========================" << endl << endl;
2198 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
2199 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
2200 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
2201 save << ++clause << ") Total number of polygons: \t" << NbPolygons() << endl;
2202 save << ++clause << ") Total number of volumes: \t" << NbVolumes() << endl;
2203 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
2204 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
2206 std::string orderStr = isQuadratic ? "quadratic" : "linear";
2207 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
2209 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
2210 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
2211 if ( NbFaces(order) > 0 ) {
2212 int nb3 = NbTriangles(order);
2213 int nb4 = NbQuadrangles(order);
2214 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
2215 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
2216 if ( nb3 + nb4 != NbFaces(order) ) {
2217 std::map<int,int> myFaceMap;
2218 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
2219 while( itFaces->more( ) ) {
2220 int nbNodes = itFaces->next()->NbNodes();
2221 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
2222 myFaceMap[ nbNodes ] = 0;
2223 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
2225 save << clause << ".3) Faces in detail: " << endl;
2226 std::map <int,int>::iterator itF;
2227 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
2228 save << "--> nb nodes: " << itF->first << " - nb elements:\t" << itF->second << endl;
2231 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
2232 if ( NbVolumes(order) > 0 ) {
2233 int nb8 = NbHexas(order);
2234 int nb4 = NbTetras(order);
2235 int nb5 = NbPyramids(order);
2236 int nb6 = NbPrisms(order);
2237 save << clause << ".1) Number of " << orderStr << " hexahedrons: \t" << nb8 << endl;
2238 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
2239 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
2240 save << clause << ".4) Number of " << orderStr << " pyramids: \t" << nb5 << endl;
2241 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
2242 std::map<int,int> myVolumesMap;
2243 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
2244 while( itVolumes->more( ) ) {
2245 int nbNodes = itVolumes->next()->NbNodes();
2246 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
2247 myVolumesMap[ nbNodes ] = 0;
2248 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
2250 save << clause << ".5) Volumes in detail: " << endl;
2251 std::map <int,int>::iterator itV;
2252 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
2253 save << "--> nb nodes: " << itV->first << " - nb elements:\t" << itV->second << endl;
2258 save << "===========================================================================" << endl;
2262 //=======================================================================
2263 //function : GetElementType
2264 //purpose : Returns type of mesh element with certain id
2265 //=======================================================================
2267 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
2269 return _myMeshDS->GetElementType( id, iselem );
2272 //=============================================================================
2274 * \brief Convert group on geometry into standalone group
2276 //=============================================================================
2278 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
2280 SMESH_Group* aGroup = 0;
2281 std::map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
2282 if ( itg == _mapGroup.end() )
2285 SMESH_Group* anOldGrp = (*itg).second;
2286 if ( !anOldGrp || !anOldGrp->GetGroupDS() )
2288 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
2290 // create new standalone group
2291 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
2292 _mapGroup[theGroupID] = aGroup;
2294 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
2295 GetMeshDS()->RemoveGroup( anOldGrpDS );
2296 GetMeshDS()->AddGroup( aNewGrpDS );
2298 // add elements (or nodes) into new created group
2299 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
2300 while ( anItr->more() )
2301 aNewGrpDS->Add( (anItr->next())->GetID() );
2304 aNewGrpDS->SetColor( anOldGrpDS->GetColor() );
2312 //=============================================================================
2314 * \brief remove submesh order from Mesh
2316 //=============================================================================
2318 void SMESH_Mesh::ClearMeshOrder()
2320 _mySubMeshOrder.clear();
2323 //=============================================================================
2325 * \brief remove submesh order from Mesh
2327 //=============================================================================
2329 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
2331 _mySubMeshOrder = theOrder;
2334 //=============================================================================
2336 * \brief return submesh order if any
2338 //=============================================================================
2340 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
2342 return _mySubMeshOrder;
2345 //=============================================================================
2347 * \brief fill _mapAncestors
2349 //=============================================================================
2351 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
2353 int desType, ancType;
2354 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
2356 // a geom group is added. Insert it into lists of ancestors before
2357 // the first ancestor more complex than group members
2358 TopoDS_Iterator subIt( theShape );
2359 if ( !subIt.More() ) return;
2360 int memberType = subIt.Value().ShapeType();
2361 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
2362 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
2364 if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982
2365 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
2366 TopTools_ListIteratorOfListOfShape ancIt (ancList);
2367 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
2369 if ( ancIt.More() ) ancList.InsertBefore( theShape, ancIt );
2370 else ancList.Append( theShape );
2373 else // else added for 52457: Addition of hypotheses is 8 time longer than meshing
2375 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
2376 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
2377 TopExp::MapShapesAndAncestors ( theShape,
2378 (TopAbs_ShapeEnum) desType,
2379 (TopAbs_ShapeEnum) ancType,
2382 // visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
2383 if ( theShape.ShapeType() == TopAbs_COMPOUND )
2385 TopoDS_Iterator sIt(theShape);
2386 if ( sIt.More() && sIt.Value().ShapeType() == TopAbs_COMPOUND )
2387 for ( ; sIt.More(); sIt.Next() )
2388 if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
2389 fillAncestorsMap( sIt.Value() );
2393 //=============================================================================
2395 * \brief sort submeshes according to stored mesh order
2396 * \param theListToSort in out list to be sorted
2397 * \return FALSE if nothing sorted
2399 //=============================================================================
2401 bool SMESH_Mesh::SortByMeshOrder(std::vector<SMESH_subMesh*>& theListToSort) const
2403 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
2407 std::vector<SMESH_subMesh*> onlyOrderedList, smVec;
2409 // collect all ordered submeshes in one list as pointers
2410 // and get their positions within theListToSort
2411 typedef std::vector<SMESH_subMesh*>::iterator TPosInList;
2412 std::map< int, TPosInList > sortedPos;
2413 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
2414 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2415 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2417 const TListOfInt& listOfId = *listIdsIt;
2418 // convert sm ids to sm's
2420 TListOfInt::const_iterator idIt = listOfId.begin();
2421 for ( ; idIt != listOfId.end(); idIt++ )
2423 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt ))
2425 smVec.push_back( sm );
2426 if ( sm->GetSubMeshDS() && sm->GetSubMeshDS()->IsComplexSubmesh() )
2428 SMESHDS_SubMeshIteratorPtr smdsIt = sm->GetSubMeshDS()->GetSubMeshIterator();
2429 while ( smdsIt->more() )
2431 const SMESHDS_SubMesh* smDS = smdsIt->next();
2432 if (( sm = GetSubMeshContaining( smDS->GetID() )))
2433 smVec.push_back( sm );
2438 // find smVec items in theListToSort
2439 for ( size_t i = 0; i < smVec.size(); ++i )
2441 TPosInList smPos = find( smBeg, smEnd, smVec[i] );
2442 if ( smPos != smEnd ) {
2443 sortedPos[ std::distance( smBeg, smPos )] = smPos;
2444 if ( sortedPos.size() > onlyOrderedList.size() )
2445 onlyOrderedList.push_back( smVec[i] );
2449 if (onlyOrderedList.size() < 2)
2453 std::vector<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
2454 std::vector<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
2456 // iterate on ordered sub-meshes and insert them in detected positions
2457 std::map< int, TPosInList >::iterator i_pos = sortedPos.begin();
2458 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
2459 *(i_pos->second) = *onlyBIt;
2464 //================================================================================
2466 * \brief Return true if given order of sub-meshes is OK
2468 //================================================================================
2470 bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
2471 const SMESH_subMesh* smAfter ) const
2473 TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
2474 for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
2476 const TListOfInt& listOfId = *listIdsIt;
2477 int iB = -1, iA = -1, i = 0;
2478 for ( TListOfInt::const_iterator id = listOfId.begin(); id != listOfId.end(); ++id, ++i )
2480 if ( *id == smBefore->GetId() )
2486 else if ( *id == smAfter->GetId() )
2494 return true; // no order imposed to given sub-meshes
2497 //=============================================================================
2499 * \brief sort submeshes according to stored mesh order
2500 * \param theListToSort in out list to be sorted
2501 * \return FALSE if nothing sorted
2503 //=============================================================================
2505 void SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape,
2506 std::vector< SMESH_subMesh* >& theSubMeshes) const
2508 theSubMeshes.clear();
2509 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
2510 for (; it.More(); it.Next() )
2511 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
2512 theSubMeshes.push_back(sm);
2514 // sort submeshes according to stored mesh order
2515 SortByMeshOrder( theSubMeshes );