1 // Copyright (C) 2007-2010 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.
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 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_Mesh.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_Mesh.hxx"
29 #include "SMESH_subMesh.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_Hypothesis.hxx"
32 #include "SMESH_Group.hxx"
33 #include "SMESH_HypoFilter.hxx"
34 #include "SMESHDS_Group.hxx"
35 #include "SMESHDS_Script.hxx"
36 #include "SMESHDS_GroupOnGeom.hxx"
37 #include "SMESHDS_Document.hxx"
38 #include "SMDS_MeshVolume.hxx"
39 #include "SMDS_SetIterator.hxx"
41 #include "utilities.h"
43 #include "DriverMED_W_SMESHDS_Mesh.h"
44 #include "DriverDAT_W_SMDS_Mesh.h"
45 #include "DriverUNV_W_SMDS_Mesh.h"
46 #include "DriverSTL_W_SMDS_Mesh.h"
48 #include "DriverMED_R_SMESHDS_Mesh.h"
49 #include "DriverUNV_R_SMDS_Mesh.h"
50 #include "DriverSTL_R_SMDS_Mesh.h"
52 #undef _Precision_HeaderFile
53 #include <BRepBndLib.hxx>
54 #include <BRepPrimAPI_MakeBox.hxx>
55 #include <Bnd_Box.hxx>
57 #include <TopExp_Explorer.hxx>
58 #include <TopTools_ListIteratorOfListOfShape.hxx>
59 #include <TopTools_ListOfShape.hxx>
60 #include <TopTools_MapOfShape.hxx>
61 #include <TopoDS_Iterator.hxx>
63 #include "Utils_ExceptHandlers.hxx"
67 // maximum stored group name length in MED file
68 #define MAX_MED_GROUP_NAME_LENGTH 80
71 static int MYDEBUG = 0;
73 static int MYDEBUG = 0;
76 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
78 typedef SMESH_HypoFilter THypType;
80 //=============================================================================
84 //=============================================================================
86 SMESH_Mesh::SMESH_Mesh(int theLocalId,
89 bool theIsEmbeddedMode,
90 SMESHDS_Document* theDocument):
91 _groupId( 0 ), _nbSubShapes( 0 )
93 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
95 _studyId = theStudyId;
97 _myDocument = theDocument;
98 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
99 _myMeshDS = theDocument->GetMesh(_idDoc);
100 _isShapeToMesh = false;
101 _isAutoColor = false;
102 _shapeDiagonal = 0.0;
103 _myMeshDS->ShapeToMesh( PseudoShape() );
106 //=============================================================================
110 //=============================================================================
112 SMESH_Mesh::~SMESH_Mesh()
114 INFOS("SMESH_Mesh::~SMESH_Mesh");
116 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
117 // Notify event listeners at least that something happens
118 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
119 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
122 map < int, SMESH_Group * >::iterator itg;
123 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
124 SMESH_Group *aGroup = (*itg).second;
130 //=============================================================================
132 * \brief Set geometry to be meshed
134 //=============================================================================
136 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
138 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
140 if ( !aShape.IsNull() && _isShapeToMesh ) {
141 if ( aShape.ShapeType() != TopAbs_COMPOUND && // group contents is allowed to change
142 _myMeshDS->ShapeToMesh().ShapeType() != TopAbs_COMPOUND )
143 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
145 // clear current data
146 if ( !_myMeshDS->ShapeToMesh().IsNull() )
148 // removal of a shape to mesh, delete objects referring to sub-shapes:
150 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
151 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
154 // - groups on geometry
155 map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
156 while ( i_gr != _mapGroup.end() ) {
157 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
158 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
160 _mapGroup.erase( i_gr++ );
165 _mapAncestors.Clear();
168 TopoDS_Shape aNullShape;
169 _myMeshDS->ShapeToMesh( aNullShape );
171 _shapeDiagonal = 0.0;
174 // set a new geometry
175 if ( !aShape.IsNull() )
177 _myMeshDS->ShapeToMesh(aShape);
178 _isShapeToMesh = true;
179 _nbSubShapes = _myMeshDS->MaxShapeIndex();
181 // fill map of ancestors
182 fillAncestorsMap(aShape);
186 _isShapeToMesh = false;
187 _shapeDiagonal = 0.0;
188 _myMeshDS->ShapeToMesh( PseudoShape() );
192 //=======================================================================
194 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
196 //=======================================================================
198 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
200 return _myMeshDS->ShapeToMesh();
203 //=======================================================================
205 * \brief Return a solid which is returned by GetShapeToMesh() if
206 * a real geometry to be meshed was not set
208 //=======================================================================
210 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
212 static TopoDS_Solid aSolid;
213 if ( aSolid.IsNull() )
215 aSolid = BRepPrimAPI_MakeBox(1,1,1);
220 //=======================================================================
222 * \brief Return diagonal size of bounding box of a shape
224 //=======================================================================
226 double SMESH_Mesh::GetShapeDiagonalSize(const TopoDS_Shape & aShape)
228 if ( !aShape.IsNull() ) {
230 BRepBndLib::Add(aShape, Box);
231 return sqrt( Box.SquareExtent() );
236 //=======================================================================
238 * \brief Return diagonal size of bounding box of shape to mesh
240 //=======================================================================
242 double SMESH_Mesh::GetShapeDiagonalSize() const
244 if ( _shapeDiagonal == 0. && _isShapeToMesh )
245 const_cast<SMESH_Mesh*>(this)->_shapeDiagonal = GetShapeDiagonalSize( GetShapeToMesh() );
247 return _shapeDiagonal;
250 //=======================================================================
252 * \brief Remove all nodes and elements
254 //=======================================================================
256 void SMESH_Mesh::Clear()
259 _myMeshDS->ClearMesh();
261 // update compute state of submeshes
262 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
263 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
264 /*complexShapeFirst=*/false);
265 while ( smIt->more() ) {
267 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
272 //=======================================================================
274 * \brief Remove all nodes and elements of indicated shape
276 //=======================================================================
278 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
280 // clear sub-meshes; get ready to re-compute as a side-effect
281 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
283 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
284 /*complexShapeFirst=*/false);
285 while ( smIt->more() )
288 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
289 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
290 // all other shapes depends on vertices so they are already cleaned
291 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
292 // to recompute even if failed
293 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
298 //=======================================================================
299 //function : UNVToMesh
301 //=======================================================================
303 int SMESH_Mesh::UNVToMesh(const char* theFileName)
305 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
307 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
308 _isShapeToMesh = false;
309 DriverUNV_R_SMDS_Mesh myReader;
310 myReader.SetMesh(_myMeshDS);
311 myReader.SetFile(theFileName);
312 myReader.SetMeshId(-1);
315 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
316 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
317 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
318 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
320 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
322 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
323 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
324 aGroup->InitSubGroupsIterator();
325 while (aGroup->MoreSubGroups()) {
326 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
327 string aName = aGroupNames[aSubGroup];
330 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
332 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
333 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
335 aGroupDS->SetStoreName(aName.c_str());
336 aSubGroup->InitIterator();
337 const SMDS_MeshElement* aElement = 0;
338 while (aSubGroup->More()) {
339 aElement = aSubGroup->Next();
341 aGroupDS->SMDSGroup().Add(aElement);
345 aGroupDS->SetType(aElement->GetType());
353 //=======================================================================
354 //function : MEDToMesh
356 //=======================================================================
358 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
360 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
362 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
363 _isShapeToMesh = false;
364 DriverMED_R_SMESHDS_Mesh myReader;
365 myReader.SetMesh(_myMeshDS);
366 myReader.SetMeshId(-1);
367 myReader.SetFile(theFileName);
368 myReader.SetMeshName(theMeshName);
369 Driver_Mesh::Status status = myReader.Perform();
371 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
372 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
373 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
374 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
377 // Reading groups (sub-meshes are out of scope of MED import functionality)
378 list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
379 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
381 list<TNameAndType>::iterator name_type = aGroupNames.begin();
382 for ( ; name_type != aGroupNames.end(); name_type++ ) {
383 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
385 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
386 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
388 aGroupDS->SetStoreName( name_type->first.c_str() );
389 myReader.GetGroup( aGroupDS );
396 //=======================================================================
397 //function : STLToMesh
399 //=======================================================================
401 int SMESH_Mesh::STLToMesh(const char* theFileName)
403 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
405 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
406 _isShapeToMesh = false;
407 DriverSTL_R_SMDS_Mesh myReader;
408 myReader.SetMesh(_myMeshDS);
409 myReader.SetFile(theFileName);
410 myReader.SetMeshId(-1);
413 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
414 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
415 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
416 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
421 //=============================================================================
425 //=============================================================================
427 SMESH_Hypothesis::Hypothesis_Status
428 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
429 int anHypId ) throw(SALOME_Exception)
431 Unexpect aCatch(SalomeException);
432 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
434 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
435 if ( !subMesh || !subMesh->GetId())
436 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
438 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
439 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
441 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
446 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
449 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
450 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
452 bool isGlobalHyp = IsMainShape( aSubShape );
454 // NotConformAllowed can be only global
457 string hypName = anHyp->GetName();
458 if ( hypName == "NotConformAllowed" )
460 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
461 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
467 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
468 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
470 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
473 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
474 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
476 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
478 SMESH_Hypothesis::Hypothesis_Status ret2 =
479 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
483 // check concurent hypotheses on ancestors
484 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
486 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
487 while ( smIt->more() ) {
488 SMESH_subMesh* sm = smIt->next();
489 if ( sm->IsApplicableHypotesis( anHyp )) {
490 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
500 if(MYDEBUG) subMesh->DumpAlgoState(true);
501 if(MYDEBUG) SCRUTE(ret);
505 //=============================================================================
509 //=============================================================================
511 SMESH_Hypothesis::Hypothesis_Status
512 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
513 int anHypId)throw(SALOME_Exception)
515 Unexpect aCatch(SalomeException);
516 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
518 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
519 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
520 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
522 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
524 int hypType = anHyp->GetType();
530 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
531 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
533 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
535 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
537 // there may appear concurrent hyps that were covered by the removed hyp
538 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
539 subMesh->IsApplicableHypotesis( anHyp ) &&
540 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
541 ret = SMESH_Hypothesis::HYP_CONCURENT;
544 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
545 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
547 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
549 SMESH_Hypothesis::Hypothesis_Status ret2 =
550 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
551 if (ret2 > ret) // more severe
554 // check concurent hypotheses on ancestors
555 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
557 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
558 while ( smIt->more() ) {
559 SMESH_subMesh* sm = smIt->next();
560 if ( sm->IsApplicableHypotesis( anHyp )) {
561 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
571 if(MYDEBUG) subMesh->DumpAlgoState(true);
572 if(MYDEBUG) SCRUTE(ret);
576 //=============================================================================
580 //=============================================================================
582 const list<const SMESHDS_Hypothesis*>&
583 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
584 throw(SALOME_Exception)
586 Unexpect aCatch(SalomeException);
587 return _myMeshDS->GetHypothesis(aSubShape);
590 //=======================================================================
592 * \brief Return the hypothesis assigned to the shape
593 * \param aSubShape - the shape to check
594 * \param aFilter - the hypothesis filter
595 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
596 * \param assignedTo - to return the shape the found hypo is assigned to
597 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
599 //=======================================================================
601 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
602 const SMESH_HypoFilter& aFilter,
603 const bool andAncestors,
604 TopoDS_Shape* assignedTo) const
607 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
608 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
609 for ( ; hyp != hypList.end(); hyp++ ) {
610 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
611 if ( aFilter.IsOk( h, aSubShape)) {
612 if ( assignedTo ) *assignedTo = aSubShape;
619 // user sorted submeshes of ancestors, according to stored submesh priority
620 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
621 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
622 for ( ; smIt != smList.end(); smIt++ )
624 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
625 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
626 list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
627 for ( ; hyp != hypList.end(); hyp++ ) {
628 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
629 if (aFilter.IsOk( h, curSh )) {
630 if ( assignedTo ) *assignedTo = curSh;
639 //================================================================================
641 * \brief Return hypothesis assigned to the shape
642 * \param aSubShape - the shape to check
643 * \param aFilter - the hypothesis filter
644 * \param aHypList - the list of the found hypotheses
645 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
646 * \retval int - number of unique hypos in aHypList
648 //================================================================================
650 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
651 const SMESH_HypoFilter& aFilter,
652 list <const SMESHDS_Hypothesis * >& aHypList,
653 const bool andAncestors) const
655 set<string> hypTypes; // to exclude same type hypos from the result list
658 // only one main hypothesis is allowed
659 bool mainHypFound = false;
662 list<const SMESHDS_Hypothesis*>::const_iterator hyp;
663 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
664 if ( hypTypes.insert( (*hyp)->GetName() ).second )
666 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
670 // get hypos from aSubShape
672 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
673 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
674 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
675 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
676 hypTypes.insert( (*hyp)->GetName() ).second )
678 aHypList.push_back( *hyp );
680 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
685 // get hypos from ancestors of aSubShape
688 TopTools_MapOfShape map;
690 // user sorted submeshes of ancestors, according to stored submesh priority
691 const list<SMESH_subMesh*> smList = getAncestorsSubMeshes( aSubShape );
692 list<SMESH_subMesh*>::const_iterator smIt = smList.begin();
693 for ( ; smIt != smList.end(); smIt++ )
695 const TopoDS_Shape& curSh = (*smIt)->GetSubShape();
696 if ( !map.Add( curSh ))
698 const list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(curSh);
699 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
700 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), curSh ) &&
701 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
702 hypTypes.insert( (*hyp)->GetName() ).second )
704 aHypList.push_back( *hyp );
706 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
714 //=============================================================================
718 //=============================================================================
720 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
722 Unexpect aCatch(SalomeException);
723 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
724 return _myMeshDS->GetScript()->GetCommands();
727 //=============================================================================
731 //=============================================================================
732 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
734 Unexpect aCatch(SalomeException);
735 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
736 _myMeshDS->GetScript()->Clear();
739 //=============================================================================
741 * Get or Create the SMESH_subMesh object implementation
743 //=============================================================================
745 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
746 throw(SALOME_Exception)
748 Unexpect aCatch(SalomeException);
749 SMESH_subMesh *aSubMesh;
750 int index = _myMeshDS->ShapeToIndex(aSubShape);
752 // for submeshes on GEOM Group
753 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
754 TopoDS_Iterator it( aSubShape );
757 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
758 if ( index > _nbSubShapes ) _nbSubShapes = index; // not to create sm for this group again
760 // fill map of Ancestors
761 fillAncestorsMap(aSubShape);
765 // return NULL; // neither sub-shape nor a group
767 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
768 if ( i_sm != _mapSubMesh.end())
770 aSubMesh = i_sm->second;
774 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
775 _mapSubMesh[index] = aSubMesh;
781 //=============================================================================
783 * Get the SMESH_subMesh object implementation. Dont create it, return null
784 * if it does not exist.
786 //=============================================================================
788 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
789 throw(SALOME_Exception)
791 Unexpect aCatch(SalomeException);
792 SMESH_subMesh *aSubMesh = NULL;
794 int index = _myMeshDS->ShapeToIndex(aSubShape);
796 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
797 if ( i_sm != _mapSubMesh.end())
798 aSubMesh = i_sm->second;
802 //=============================================================================
804 * Get the SMESH_subMesh object implementation. Dont create it, return null
805 * if it does not exist.
807 //=============================================================================
809 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
810 throw(SALOME_Exception)
812 Unexpect aCatch(SalomeException);
814 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
815 if (i_sm == _mapSubMesh.end())
819 //================================================================================
821 * \brief Return submeshes of groups containing the given subshape
823 //================================================================================
826 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
827 throw(SALOME_Exception)
829 Unexpect aCatch(SalomeException);
830 list<SMESH_subMesh*> found;
832 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
836 // submeshes of groups have max IDs, so search from the map end
837 map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
838 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
839 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
840 if ( ds && ds->IsComplexSubmesh() ) {
841 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
842 for ( ; exp.More(); exp.Next() ) {
843 if ( aSubShape.IsSame( exp.Current() )) {
844 found.push_back( i_sm->second );
854 //=======================================================================
855 //function : IsUsedHypothesis
856 //purpose : Return True if anHyp is used to mesh aSubShape
857 //=======================================================================
859 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
860 const SMESH_subMesh* aSubMesh)
862 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
864 // check if anHyp can be used to mesh aSubMesh
865 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
868 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
870 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
873 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
874 return ( anHyp == algo );
876 // algorithm parameter
879 // look trough hypotheses used by algo
880 SMESH_HypoFilter hypoKind;
881 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
882 list <const SMESHDS_Hypothesis * > usedHyps;
883 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
884 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
888 // look through all assigned hypotheses
889 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
890 return false; //GetHypothesis( aSubShape, filter, true );
893 //=============================================================================
897 //=============================================================================
899 const list < SMESH_subMesh * >&
900 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
901 throw(SALOME_Exception)
903 Unexpect aCatch(SalomeException);
904 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
905 map < int, SMESH_subMesh * >::iterator itsm;
906 _subMeshesUsingHypothesisList.clear();
907 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
909 SMESH_subMesh *aSubMesh = (*itsm).second;
910 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
911 _subMeshesUsingHypothesisList.push_back(aSubMesh);
913 return _subMeshesUsingHypothesisList;
916 //=======================================================================
917 //function : NotifySubMeshesHypothesisModification
918 //purpose : Say all submeshes using theChangedHyp that it has been modified
919 //=======================================================================
921 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
923 Unexpect aCatch(SalomeException);
925 const SMESH_Algo *foundAlgo = 0;
926 SMESH_HypoFilter algoKind, compatibleHypoKind;
927 list <const SMESHDS_Hypothesis * > usedHyps;
930 map < int, SMESH_subMesh * >::iterator itsm;
931 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
933 SMESH_subMesh *aSubMesh = (*itsm).second;
934 if ( aSubMesh->IsApplicableHypotesis( hyp ))
936 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
938 if ( !foundAlgo ) // init filter for algo search
939 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
941 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
942 ( GetHypothesis( aSubShape, algoKind, true ));
946 bool sameAlgo = ( algo == foundAlgo );
947 if ( !sameAlgo && foundAlgo )
948 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
950 if ( !sameAlgo ) { // init filter for used hypos search
951 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
952 continue; // algo does not use any hypothesis
956 // check if hyp is used by algo
958 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
959 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
961 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
962 const_cast< SMESH_Hypothesis*>( hyp ));
969 //=============================================================================
971 * Auto color functionality
973 //=============================================================================
974 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
976 Unexpect aCatch(SalomeException);
977 _isAutoColor = theAutoColor;
980 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
982 Unexpect aCatch(SalomeException);
986 //=============================================================================
988 * To store mesh contents on disk in different formats.
990 //=============================================================================
992 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
994 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
995 map< SMDSAbs_ElementType, set<string> > aGroupNames;
996 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
998 SMESH_Group* aGroup = it->second;
999 SMDSAbs_ElementType aType = aGroup->GetGroupDS()->GetType();
1000 string aGroupName = aGroup->GetName();
1001 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1002 if (!aGroupNames[aType].insert(aGroupName).second)
1009 void SMESH_Mesh::ExportMED(const char *file,
1010 const char* theMeshName,
1013 throw(SALOME_Exception)
1015 Unexpect aCatch(SalomeException);
1017 DriverMED_W_SMESHDS_Mesh myWriter;
1018 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1019 myWriter.SetMesh ( _myMeshDS );
1021 myWriter.SetMeshId ( _idDoc );
1023 myWriter.SetMeshId ( -1 );
1024 myWriter.SetMeshName( theMeshName );
1027 if ( theAutoGroups ) {
1028 myWriter.AddGroupOfNodes();
1029 myWriter.AddGroupOfEdges();
1030 myWriter.AddGroupOfFaces();
1031 myWriter.AddGroupOfVolumes();
1034 // Pass groups to writer. Provide unique group names.
1035 //set<string> aGroupNames; // Corrected for Mantis issue 0020028
1036 map< SMDSAbs_ElementType, set<string> > aGroupNames;
1038 int maxNbIter = 10000; // to guarantee cycle finish
1039 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1040 SMESH_Group* aGroup = it->second;
1041 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1043 SMDSAbs_ElementType aType = aGroupDS->GetType();
1044 string aGroupName0 = aGroup->GetName();
1045 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1046 string aGroupName = aGroupName0;
1047 for (int i = 1; !aGroupNames[aType].insert(aGroupName).second && i < maxNbIter; i++) {
1048 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1049 aGroupName = aString;
1050 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1052 aGroupDS->SetStoreName( aGroupName.c_str() );
1053 myWriter.AddGroup( aGroupDS );
1061 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1063 Unexpect aCatch(SalomeException);
1064 DriverDAT_W_SMDS_Mesh myWriter;
1065 myWriter.SetFile(string(file));
1066 myWriter.SetMesh(_myMeshDS);
1067 myWriter.SetMeshId(_idDoc);
1071 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1073 Unexpect aCatch(SalomeException);
1074 DriverUNV_W_SMDS_Mesh myWriter;
1075 myWriter.SetFile(string(file));
1076 myWriter.SetMesh(_myMeshDS);
1077 myWriter.SetMeshId(_idDoc);
1078 // myWriter.SetGroups(_mapGroup);
1080 for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1081 SMESH_Group* aGroup = it->second;
1082 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1084 string aGroupName = aGroup->GetName();
1085 aGroupDS->SetStoreName( aGroupName.c_str() );
1086 myWriter.AddGroup( aGroupDS );
1092 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1094 Unexpect aCatch(SalomeException);
1095 DriverSTL_W_SMDS_Mesh myWriter;
1096 myWriter.SetFile(string(file));
1097 myWriter.SetIsAscii( isascii );
1098 myWriter.SetMesh(_myMeshDS);
1099 myWriter.SetMeshId(_idDoc);
1103 //================================================================================
1105 * \brief Return number of nodes in the mesh
1107 //================================================================================
1109 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1111 Unexpect aCatch(SalomeException);
1112 return _myMeshDS->NbNodes();
1115 //================================================================================
1117 * \brief Return number of edges of given order in the mesh
1119 //================================================================================
1121 int SMESH_Mesh::Nb0DElements() throw(SALOME_Exception)
1123 Unexpect aCatch(SalomeException);
1124 return _myMeshDS->GetMeshInfo().Nb0DElements();
1127 //================================================================================
1129 * \brief Return number of edges of given order in the mesh
1131 //================================================================================
1133 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1135 Unexpect aCatch(SalomeException);
1136 return _myMeshDS->GetMeshInfo().NbEdges(order);
1139 //================================================================================
1141 * \brief Return number of faces of given order in the mesh
1143 //================================================================================
1145 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1147 Unexpect aCatch(SalomeException);
1148 return _myMeshDS->GetMeshInfo().NbFaces(order);
1151 //================================================================================
1153 * \brief Return the number of faces in the mesh
1155 //================================================================================
1157 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1159 Unexpect aCatch(SalomeException);
1160 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1163 //================================================================================
1165 * \brief Return the number nodes faces in the mesh
1167 //================================================================================
1169 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1171 Unexpect aCatch(SalomeException);
1172 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1175 //================================================================================
1177 * \brief Return the number of polygonal faces in the mesh
1179 //================================================================================
1181 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1183 Unexpect aCatch(SalomeException);
1184 return _myMeshDS->GetMeshInfo().NbPolygons();
1187 //================================================================================
1189 * \brief Return number of volumes of given order in the mesh
1191 //================================================================================
1193 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1195 Unexpect aCatch(SalomeException);
1196 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1199 //================================================================================
1201 * \brief Return number of tetrahedrons of given order in the mesh
1203 //================================================================================
1205 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1207 Unexpect aCatch(SalomeException);
1208 return _myMeshDS->GetMeshInfo().NbTetras(order);
1211 //================================================================================
1213 * \brief Return number of hexahedrons of given order in the mesh
1215 //================================================================================
1217 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1219 Unexpect aCatch(SalomeException);
1220 return _myMeshDS->GetMeshInfo().NbHexas(order);
1223 //================================================================================
1225 * \brief Return number of pyramids of given order in the mesh
1227 //================================================================================
1229 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1231 Unexpect aCatch(SalomeException);
1232 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1235 //================================================================================
1237 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1239 //================================================================================
1241 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1243 Unexpect aCatch(SalomeException);
1244 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1247 //================================================================================
1249 * \brief Return number of polyhedrons in the mesh
1251 //================================================================================
1253 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1255 Unexpect aCatch(SalomeException);
1256 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1259 //================================================================================
1261 * \brief Return number of submeshes in the mesh
1263 //================================================================================
1265 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1267 Unexpect aCatch(SalomeException);
1268 return _myMeshDS->NbSubMesh();
1271 //=======================================================================
1272 //function : IsNotConformAllowed
1273 //purpose : check if a hypothesis alowing notconform mesh is present
1274 //=======================================================================
1276 bool SMESH_Mesh::IsNotConformAllowed() const
1278 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1280 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1281 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1284 //=======================================================================
1285 //function : IsMainShape
1287 //=======================================================================
1289 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1291 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1294 //=============================================================================
1298 //=============================================================================
1300 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1301 const char* theName,
1303 const TopoDS_Shape& theShape)
1305 if (_mapGroup.find(_groupId) != _mapGroup.end())
1308 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1309 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1310 _mapGroup[_groupId++] = aGroup;
1314 //================================================================================
1316 * \brief Return iterator on all existing groups
1318 //================================================================================
1320 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1322 typedef map <int, SMESH_Group *> TMap;
1323 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1326 //=============================================================================
1328 * \brief Return a group by ID
1330 //=============================================================================
1332 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1334 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1336 return _mapGroup[theGroupID];
1340 //=============================================================================
1342 * \brief Return IDs of all groups
1344 //=============================================================================
1346 list<int> SMESH_Mesh::GetGroupIds() const
1349 for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1350 anIds.push_back( it->first );
1356 //=============================================================================
1360 //=============================================================================
1362 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1364 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1366 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1367 delete _mapGroup[theGroupID];
1368 _mapGroup.erase (theGroupID);
1371 //=======================================================================
1372 //function : GetAncestors
1373 //purpose : return list of ancestors of theSubShape in the order
1374 // that lower dimention shapes come first.
1375 //=======================================================================
1377 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1379 if ( _mapAncestors.Contains( theS ) )
1380 return _mapAncestors.FindFromKey( theS );
1382 static TopTools_ListOfShape emptyList;
1386 //=======================================================================
1388 //purpose : dumps contents of mesh to stream [ debug purposes ]
1389 //=======================================================================
1391 ostream& SMESH_Mesh::Dump(ostream& save)
1394 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1395 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1396 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1397 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1398 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1399 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1400 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1401 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1403 string orderStr = isQuadratic ? "quadratic" : "linear";
1404 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1406 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1407 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1408 if ( NbFaces(order) > 0 ) {
1409 int nb3 = NbTriangles(order);
1410 int nb4 = NbQuadrangles(order);
1411 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1412 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1413 if ( nb3 + nb4 != NbFaces(order) ) {
1414 map<int,int> myFaceMap;
1415 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1416 while( itFaces->more( ) ) {
1417 int nbNodes = itFaces->next()->NbNodes();
1418 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1419 myFaceMap[ nbNodes ] = 0;
1420 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1422 save << clause << ".3) Faces in detail: " << endl;
1423 map <int,int>::iterator itF;
1424 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1425 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1428 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1429 if ( NbVolumes(order) > 0 ) {
1430 int nb8 = NbHexas(order);
1431 int nb4 = NbTetras(order);
1432 int nb5 = NbPyramids(order);
1433 int nb6 = NbPrisms(order);
1434 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1435 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1436 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1437 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1438 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1439 map<int,int> myVolumesMap;
1440 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1441 while( itVolumes->more( ) ) {
1442 int nbNodes = itVolumes->next()->NbNodes();
1443 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1444 myVolumesMap[ nbNodes ] = 0;
1445 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1447 save << clause << ".5) Volumes in detail: " << endl;
1448 map <int,int>::iterator itV;
1449 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1450 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1455 save << "===========================================================================" << endl;
1459 //=======================================================================
1460 //function : GetElementType
1461 //purpose : Returns type of mesh element with certain id
1462 //=======================================================================
1464 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1466 return _myMeshDS->GetElementType( id, iselem );
1469 //=============================================================================
1471 * \brief Convert group on geometry into standalone group
1473 //=============================================================================
1475 SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
1477 SMESH_Group* aGroup = 0;
1478 map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
1479 if ( itg == _mapGroup.end() )
1482 SMESH_Group* anOldGrp = (*itg).second;
1483 SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
1484 if ( !anOldGrp || !anOldGrpDS )
1487 // create new standalone group
1488 aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
1489 _mapGroup[theGroupID] = aGroup;
1491 SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
1492 GetMeshDS()->RemoveGroup( anOldGrpDS );
1493 GetMeshDS()->AddGroup( aNewGrpDS );
1495 // add elements (or nodes) into new created group
1496 SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
1497 while ( anItr->more() )
1498 aNewGrpDS->Add( (anItr->next())->GetID() );
1506 //=============================================================================
1508 * \brief remove submesh order from Mesh
1510 //=============================================================================
1512 void SMESH_Mesh::ClearMeshOrder()
1514 _mySubMeshOrder.clear();
1517 //=============================================================================
1519 * \brief remove submesh order from Mesh
1521 //=============================================================================
1523 void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
1525 _mySubMeshOrder = theOrder;
1528 //=============================================================================
1530 * \brief return submesh order if any
1532 //=============================================================================
1534 const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
1536 return _mySubMeshOrder;
1539 //=============================================================================
1541 * \brief fill _mapAncestors
1543 //=============================================================================
1545 void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
1548 int desType, ancType;
1549 if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
1551 // a geom group is added. Insert it into lists of ancestors before
1552 // the first ancestor more complex than group members
1553 int memberType = TopoDS_Iterator( theShape ).Value().ShapeType();
1554 for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
1555 for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
1557 TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
1558 TopTools_ListIteratorOfListOfShape ancIt (ancList);
1559 while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
1562 ancList.InsertBefore( theShape, ancIt );
1566 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
1567 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1568 TopExp::MapShapesAndAncestors ( theShape,
1569 (TopAbs_ShapeEnum) desType,
1570 (TopAbs_ShapeEnum) ancType,
1575 //=============================================================================
1577 * \brief sort submeshes according to stored mesh order
1578 * \param theListToSort in out list to be sorted
1579 * \return FALSE if nothing sorted
1581 //=============================================================================
1583 bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
1585 if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
1589 list<SMESH_subMesh*> onlyOrderedList;
1590 // collect all ordered submeshes in one list as pointers
1591 // and get their positions within theListToSort
1592 typedef list<SMESH_subMesh*>::iterator TPosInList;
1593 map< int, TPosInList > sortedPos;
1594 TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
1595 TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
1596 for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
1597 const TListOfInt& listOfId = *listIddIt;
1598 TListOfInt::const_iterator idIt = listOfId.begin();
1599 for ( ; idIt != listOfId.end(); idIt++ ) {
1600 if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
1601 TPosInList smPos = find( smBeg, smEnd, sm );
1602 if ( smPos != smEnd ) {
1603 onlyOrderedList.push_back( sm );
1604 sortedPos[ distance( smBeg, smPos )] = smPos;
1609 if (onlyOrderedList.size() < 2)
1613 list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
1614 list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
1616 // iterates on ordered submeshes and insert them in detected positions
1617 map< int, TPosInList >::iterator i_pos = sortedPos.begin();
1618 for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
1619 *(i_pos->second) = *onlyBIt;
1624 //=============================================================================
1626 * \brief sort submeshes according to stored mesh order
1627 * \param theListToSort in out list to be sorted
1628 * \return FALSE if nothing sorted
1630 //=============================================================================
1632 list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
1633 (const TopoDS_Shape& theSubShape) const
1635 list<SMESH_subMesh*> listOfSubMesh;
1636 TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
1637 for (; it.More(); it.Next() )
1638 if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
1639 listOfSubMesh.push_back(sm);
1641 // sort submeshes according to stored mesh order
1642 SortByMeshOrder( listOfSubMesh );
1644 return listOfSubMesh;