1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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
24 // File : SMESH_Mesh.cxx
25 // Author : Paul RASCLE, EDF
29 #include "SMESH_Mesh.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_Group.hxx"
34 #include "SMESH_HypoFilter.hxx"
35 #include "SMESHDS_Group.hxx"
36 #include "SMESHDS_Script.hxx"
37 #include "SMESHDS_GroupOnGeom.hxx"
38 #include "SMESHDS_Document.hxx"
39 #include "SMDS_MeshVolume.hxx"
40 #include "SMDS_SetIterator.hxx"
42 #include "utilities.h"
44 #include "DriverMED_W_SMESHDS_Mesh.h"
45 #include "DriverDAT_W_SMDS_Mesh.h"
46 #include "DriverUNV_W_SMDS_Mesh.h"
47 #include "DriverSTL_W_SMDS_Mesh.h"
49 #include "DriverMED_R_SMESHDS_Mesh.h"
50 #include "DriverUNV_R_SMDS_Mesh.h"
51 #include "DriverSTL_R_SMDS_Mesh.h"
53 #include <BRepPrimAPI_MakeBox.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TopTools_ListOfShape.hxx>
58 #include <TopTools_MapOfShape.hxx>
59 #include <TopoDS_Iterator.hxx>
61 #include "Utils_ExceptHandlers.hxx"
63 // maximum stored group name length in MED file
64 #define MAX_MED_GROUP_NAME_LENGTH 80
67 static int MYDEBUG = 0;
69 static int MYDEBUG = 0;
72 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
74 typedef SMESH_HypoFilter THypType;
76 //=============================================================================
80 //=============================================================================
82 SMESH_Mesh::SMESH_Mesh(int theLocalId,
85 bool theIsEmbeddedMode,
86 SMESHDS_Document* theDocument):
89 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
91 _studyId = theStudyId;
93 _myDocument = theDocument;
94 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
95 _myMeshDS = theDocument->GetMesh(_idDoc);
96 _isShapeToMesh = false;
98 _myMeshDS->ShapeToMesh( PseudoShape() );
101 //=============================================================================
105 //=============================================================================
107 SMESH_Mesh::~SMESH_Mesh()
109 INFOS("SMESH_Mesh::~SMESH_Mesh");
112 std::map < int, SMESH_Group * >::iterator itg;
113 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
114 SMESH_Group *aGroup = (*itg).second;
120 //=============================================================================
122 * \brief Set geometry to be meshed
124 //=============================================================================
126 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
128 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
130 if ( !aShape.IsNull() && _isShapeToMesh )
131 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
133 // clear current data
134 if ( !_myMeshDS->ShapeToMesh().IsNull() )
136 // removal of a shape to mesh, delete objects referring to sub-shapes:
138 std::map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
139 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
142 // - groups on geometry
143 std::map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
144 while ( i_gr != _mapGroup.end() ) {
145 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
146 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
148 _mapGroup.erase( i_gr++ );
153 _mapAncestors.Clear();
156 TopoDS_Shape aNullShape;
157 _myMeshDS->ShapeToMesh( aNullShape );
160 // set a new geometry
161 if ( !aShape.IsNull() )
163 _myMeshDS->ShapeToMesh(aShape);
164 _isShapeToMesh = true;
166 // fill _mapAncestors
167 int desType, ancType;
168 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
169 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
170 TopExp::MapShapesAndAncestors ( aShape,
171 (TopAbs_ShapeEnum) desType,
172 (TopAbs_ShapeEnum) ancType,
177 //=======================================================================
179 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
181 //=======================================================================
183 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
185 return _myMeshDS->ShapeToMesh();
188 //=======================================================================
190 * \brief Return a solid which is returned by GetShapeToMesh() if
191 * a real geometry to be meshed was not set
193 //=======================================================================
195 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
197 static TopoDS_Solid aSolid;
198 if ( aSolid.IsNull() )
200 aSolid = BRepPrimAPI_MakeBox(1,1,1);
205 //=======================================================================
207 * \brief Remove all nodes and elements
209 //=======================================================================
211 void SMESH_Mesh::Clear()
214 _myMeshDS->ClearMesh();
216 // update compute state of submeshes
217 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
218 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
219 /*complexShapeFirst=*/false);
220 while ( smIt->more() ) {
222 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
226 // // clear sub-meshes; get ready to re-compute as a side-effect
228 // if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
230 // SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
231 // /*complexShapeFirst=*/false);
232 // while ( smIt->more() )
234 // sm = smIt->next();
235 // TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
236 // if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
237 // // all other shapes depends on vertices so they are already cleaned
238 // sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
239 // // to recompute even if failed
240 // sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
244 // // clear entities not on sub-meshes
246 // SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
247 // while ( vIt->more() )
248 // _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
250 // SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
251 // while ( fIt->more() )
252 // _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
254 // SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
255 // while ( eIt->more() )
256 // _myMeshDS->RemoveFreeElement( eIt->next(), 0 );
258 // SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator();
259 // while ( nIt->more() ) {
260 // const SMDS_MeshNode * node = nIt->next();
261 // if ( node->NbInverseElements() == 0 )
262 // _myMeshDS->RemoveFreeNode( node, 0 );
264 // _myMeshDS->RemoveNode(node);
268 //=======================================================================
270 * \brief Remove all nodes and elements of indicated shape
272 //=======================================================================
274 void SMESH_Mesh::ClearSubMesh(const int theShapeId)
276 // clear sub-meshes; get ready to re-compute as a side-effect
277 if ( SMESH_subMesh *sm = GetSubMeshContaining( theShapeId ) )
279 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
280 /*complexShapeFirst=*/false);
281 while ( smIt->more() )
284 TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
285 if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
286 // all other shapes depends on vertices so they are already cleaned
287 sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
288 // to recompute even if failed
289 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
294 //=======================================================================
295 //function : UNVToMesh
297 //=======================================================================
299 int SMESH_Mesh::UNVToMesh(const char* theFileName)
301 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
303 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
304 _isShapeToMesh = false;
305 DriverUNV_R_SMDS_Mesh myReader;
306 myReader.SetMesh(_myMeshDS);
307 myReader.SetFile(theFileName);
308 myReader.SetMeshId(-1);
311 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
312 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
313 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
314 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
316 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
318 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
319 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
320 aGroup->InitSubGroupsIterator();
321 while (aGroup->MoreSubGroups()) {
322 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
323 std::string aName = aGroupNames[aSubGroup];
326 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
328 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
329 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
331 aGroupDS->SetStoreName(aName.c_str());
332 aSubGroup->InitIterator();
333 const SMDS_MeshElement* aElement = 0;
334 while (aSubGroup->More()) {
335 aElement = aSubGroup->Next();
337 aGroupDS->SMDSGroup().Add(aElement);
341 aGroupDS->SetType(aElement->GetType());
349 //=======================================================================
350 //function : MEDToMesh
352 //=======================================================================
354 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
356 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
358 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
359 _isShapeToMesh = false;
360 DriverMED_R_SMESHDS_Mesh myReader;
361 myReader.SetMesh(_myMeshDS);
362 myReader.SetMeshId(-1);
363 myReader.SetFile(theFileName);
364 myReader.SetMeshName(theMeshName);
365 Driver_Mesh::Status status = myReader.Perform();
367 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
368 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
369 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
370 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
373 // Reading groups (sub-meshes are out of scope of MED import functionality)
374 std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
375 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
377 std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
378 for ( ; name_type != aGroupNames.end(); name_type++ ) {
379 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
381 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
382 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
384 aGroupDS->SetStoreName( name_type->first.c_str() );
385 myReader.GetGroup( aGroupDS );
392 //=======================================================================
393 //function : STLToMesh
395 //=======================================================================
397 int SMESH_Mesh::STLToMesh(const char* theFileName)
399 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
401 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
402 _isShapeToMesh = false;
403 DriverSTL_R_SMDS_Mesh myReader;
404 myReader.SetMesh(_myMeshDS);
405 myReader.SetFile(theFileName);
406 myReader.SetMeshId(-1);
409 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
410 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
411 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
412 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
417 //=============================================================================
421 //=============================================================================
423 SMESH_Hypothesis::Hypothesis_Status
424 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
425 int anHypId ) throw(SALOME_Exception)
427 Unexpect aCatch(SalomeException);
428 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
430 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
431 if ( !subMesh || !subMesh->GetId())
432 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
434 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
435 if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub-
437 MESSAGE("AddHypothesis() to complex submesh");
438 // return the worst but not fatal state of all group memebers
439 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
440 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
441 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
442 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
444 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
445 continue; // not sub-shape
446 ret = AddHypothesis( itS.Value(), anHypId );
447 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
448 aWorstNotFatal = ret;
449 if ( ret < aBestRet )
452 // bind hypotheses to a group just to know
453 SMESH_Hypothesis *anHyp = _gen->GetStudyContext(_studyId)->mapHypothesis[anHypId];
454 GetMeshDS()->AddHypothesis( aSubShape, anHyp );
456 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
458 return aWorstNotFatal;
461 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
462 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
464 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
469 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
472 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
473 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
475 bool isGlobalHyp = IsMainShape( aSubShape );
477 // NotConformAllowed can be only global
480 string hypName = anHyp->GetName();
481 if ( hypName == "NotConformAllowed" )
483 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
484 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
490 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
491 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
493 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
496 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
497 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
499 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
501 SMESH_Hypothesis::Hypothesis_Status ret2 =
502 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
506 // check concurent hypotheses on ansestors
507 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
509 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
510 while ( smIt->more() ) {
511 SMESH_subMesh* sm = smIt->next();
512 if ( sm->IsApplicableHypotesis( anHyp )) {
513 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
523 if(MYDEBUG) subMesh->DumpAlgoState(true);
528 //=============================================================================
532 //=============================================================================
534 SMESH_Hypothesis::Hypothesis_Status
535 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
536 int anHypId)throw(SALOME_Exception)
538 Unexpect aCatch(SalomeException);
539 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
541 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
542 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
543 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
545 // return the worst but not fatal state of all group memebers
546 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
547 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
548 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
549 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
551 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
552 continue; // not sub-shape
553 ret = RemoveHypothesis( itS.Value(), anHypId );
554 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
555 aWorstNotFatal = ret;
556 if ( ret < aBestRet )
559 SMESH_Hypothesis *anHyp = _gen->GetStudyContext(_studyId)->mapHypothesis[anHypId];
560 GetMeshDS()->RemoveHypothesis( aSubShape, anHyp );
562 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
564 return aWorstNotFatal;
567 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
568 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
569 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
571 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
572 int hypType = anHyp->GetType();
573 if(MYDEBUG) SCRUTE(hypType);
577 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
578 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
580 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
582 // there may appear concurrent hyps that were covered by the removed hyp
583 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
584 subMesh->IsApplicableHypotesis( anHyp ) &&
585 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
586 ret = SMESH_Hypothesis::HYP_CONCURENT;
589 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
590 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
592 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
594 SMESH_Hypothesis::Hypothesis_Status ret2 =
595 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
596 if (ret2 > ret) // more severe
599 // check concurent hypotheses on ansestors
600 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
602 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
603 while ( smIt->more() ) {
604 SMESH_subMesh* sm = smIt->next();
605 if ( sm->IsApplicableHypotesis( anHyp )) {
606 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
616 if(MYDEBUG) subMesh->DumpAlgoState(true);
617 if(MYDEBUG) SCRUTE(ret);
621 //=============================================================================
625 //=============================================================================
627 const std::list<const SMESHDS_Hypothesis*>&
628 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
629 throw(SALOME_Exception)
631 Unexpect aCatch(SalomeException);
632 return _myMeshDS->GetHypothesis(aSubShape);
635 //=======================================================================
637 * \brief Return the hypothesis assigned to the shape
638 * \param aSubShape - the shape to check
639 * \param aFilter - the hypothesis filter
640 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
641 * \param assignedTo - to return the shape the found hypo is assigned to
642 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
644 //=======================================================================
646 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
647 const SMESH_HypoFilter& aFilter,
648 const bool andAncestors,
649 TopoDS_Shape* assignedTo) const
652 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
653 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
654 for ( ; hyp != hypList.end(); hyp++ ) {
655 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
656 if ( aFilter.IsOk( h, aSubShape)) {
657 if ( assignedTo ) *assignedTo = aSubShape;
664 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
665 for (; it.More(); it.Next() )
667 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
668 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
669 for ( ; hyp != hypList.end(); hyp++ ) {
670 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
671 if (aFilter.IsOk( h, it.Value() )) {
672 if ( assignedTo ) *assignedTo = it.Value();
681 //================================================================================
683 * \brief Return hypothesis assigned to the shape
684 * \param aSubShape - the shape to check
685 * \param aFilter - the hypothesis filter
686 * \param aHypList - the list of the found hypotheses
687 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
688 * \retval int - number of unique hypos in aHypList
690 //================================================================================
692 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
693 const SMESH_HypoFilter& aFilter,
694 list <const SMESHDS_Hypothesis * >& aHypList,
695 const bool andAncestors) const
697 set<string> hypTypes; // to exclude same type hypos from the result list
700 // only one main hypothesis is allowed
701 bool mainHypFound = false;
704 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp;
705 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
706 if ( hypTypes.insert( (*hyp)->GetName() ).second )
708 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
712 // get hypos from aSubShape
714 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
715 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
716 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
717 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
718 hypTypes.insert( (*hyp)->GetName() ).second )
720 aHypList.push_back( *hyp );
722 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
727 // get hypos from ancestors of aSubShape
730 TopTools_MapOfShape map;
731 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
732 for (; it.More(); it.Next() )
734 if ( !map.Add( it.Value() ))
736 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
737 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
738 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), it.Value() ) &&
739 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
740 hypTypes.insert( (*hyp)->GetName() ).second )
742 aHypList.push_back( *hyp );
744 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
752 //=============================================================================
756 //=============================================================================
758 const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
760 Unexpect aCatch(SalomeException);
761 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
762 return _myMeshDS->GetScript()->GetCommands();
765 //=============================================================================
769 //=============================================================================
770 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
772 Unexpect aCatch(SalomeException);
773 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
774 _myMeshDS->GetScript()->Clear();
777 //=============================================================================
779 * Get or Create the SMESH_subMesh object implementation
781 //=============================================================================
783 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
784 throw(SALOME_Exception)
786 Unexpect aCatch(SalomeException);
787 SMESH_subMesh *aSubMesh;
788 int index = _myMeshDS->ShapeToIndex(aSubShape);
790 // for submeshes on GEOM Group
791 if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
792 TopoDS_Iterator it( aSubShape );
794 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
797 // return NULL; // neither sub-shape nor a group
799 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
800 if ( i_sm != _mapSubMesh.end())
802 aSubMesh = i_sm->second;
806 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
807 _mapSubMesh[index] = aSubMesh;
812 //=============================================================================
814 * Get the SMESH_subMesh object implementation. Dont create it, return null
815 * if it does not exist.
817 //=============================================================================
819 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
820 throw(SALOME_Exception)
822 Unexpect aCatch(SalomeException);
823 SMESH_subMesh *aSubMesh = NULL;
825 int index = _myMeshDS->ShapeToIndex(aSubShape);
827 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
828 if ( i_sm != _mapSubMesh.end())
829 aSubMesh = i_sm->second;
833 //=============================================================================
835 * Get the SMESH_subMesh object implementation. Dont create it, return null
836 * if it does not exist.
838 //=============================================================================
840 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
841 throw(SALOME_Exception)
843 Unexpect aCatch(SalomeException);
845 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
846 if (i_sm == _mapSubMesh.end())
850 //================================================================================
852 * \brief Return submeshes of groups containing the given subshape
854 //================================================================================
856 std::list<SMESH_subMesh*>
857 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
858 throw(SALOME_Exception)
860 Unexpect aCatch(SalomeException);
861 std::list<SMESH_subMesh*> found;
863 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
867 // submeshes of groups have max IDs, so search from the map end
868 std::map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
869 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
870 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
871 if ( ds && ds->IsComplexSubmesh() ) {
872 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
873 for ( ; exp.More(); exp.Next() ) {
874 if ( aSubShape.IsSame( exp.Current() )) {
875 found.push_back( i_sm->second );
885 //=======================================================================
886 //function : IsUsedHypothesis
887 //purpose : Return True if anHyp is used to mesh aSubShape
888 //=======================================================================
890 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
891 const SMESH_subMesh* aSubMesh)
893 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
895 // check if anHyp can be used to mesh aSubMesh
896 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
899 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
901 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
904 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
905 return ( anHyp == algo );
907 // algorithm parameter
910 // look trough hypotheses used by algo
911 SMESH_HypoFilter hypoKind;
912 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
913 list <const SMESHDS_Hypothesis * > usedHyps;
914 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
915 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
919 // look through all assigned hypotheses
920 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
921 return false; //GetHypothesis( aSubShape, filter, true );
924 //=============================================================================
928 //=============================================================================
930 const list < SMESH_subMesh * >&
931 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
932 throw(SALOME_Exception)
934 Unexpect aCatch(SalomeException);
935 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
936 map < int, SMESH_subMesh * >::iterator itsm;
937 _subMeshesUsingHypothesisList.clear();
938 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
940 SMESH_subMesh *aSubMesh = (*itsm).second;
941 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
942 _subMeshesUsingHypothesisList.push_back(aSubMesh);
944 return _subMeshesUsingHypothesisList;
947 //=======================================================================
948 //function : NotifySubMeshesHypothesisModification
949 //purpose : Say all submeshes using theChangedHyp that it has been modified
950 //=======================================================================
952 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
954 Unexpect aCatch(SalomeException);
956 const SMESH_Algo *foundAlgo = 0;
957 SMESH_HypoFilter algoKind, compatibleHypoKind;
958 list <const SMESHDS_Hypothesis * > usedHyps;
961 map < int, SMESH_subMesh * >::iterator itsm;
962 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
964 SMESH_subMesh *aSubMesh = (*itsm).second;
965 if ( aSubMesh->IsApplicableHypotesis( hyp ))
967 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
969 if ( !foundAlgo ) // init filter for algo search
970 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
972 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
973 ( GetHypothesis( aSubShape, algoKind, true ));
977 bool sameAlgo = ( algo == foundAlgo );
978 if ( !sameAlgo && foundAlgo )
979 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
981 if ( !sameAlgo ) { // init filter for used hypos search
982 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
983 continue; // algo does not use any hypothesis
987 // check if hyp is used by algo
989 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
990 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
992 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
993 const_cast< SMESH_Hypothesis*>( hyp ));
1000 //=============================================================================
1002 * Auto color functionality
1004 //=============================================================================
1005 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
1007 Unexpect aCatch(SalomeException);
1008 _isAutoColor = theAutoColor;
1011 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
1013 Unexpect aCatch(SalomeException);
1014 return _isAutoColor;
1017 //=============================================================================
1018 /*! Export* methods.
1019 * To store mesh contents on disk in different formats.
1021 //=============================================================================
1023 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1025 set<string> aGroupNames;
1026 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1027 SMESH_Group* aGroup = it->second;
1028 std::string aGroupName = aGroup->GetName();
1029 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1030 if (!aGroupNames.insert(aGroupName).second)
1037 void SMESH_Mesh::ExportMED(const char *file,
1038 const char* theMeshName,
1041 throw(SALOME_Exception)
1043 Unexpect aCatch(SalomeException);
1045 DriverMED_W_SMESHDS_Mesh myWriter;
1046 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1047 myWriter.SetMesh ( _myMeshDS );
1049 myWriter.SetMeshId ( _idDoc );
1051 myWriter.SetMeshId ( -1 );
1052 myWriter.SetMeshName( theMeshName );
1055 if ( theAutoGroups ) {
1056 myWriter.AddGroupOfNodes();
1057 myWriter.AddGroupOfEdges();
1058 myWriter.AddGroupOfFaces();
1059 myWriter.AddGroupOfVolumes();
1062 // Pass groups to writer. Provide unique group names.
1063 set<string> aGroupNames;
1065 int maxNbIter = 10000; // to guarantee cycle finish
1066 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1067 SMESH_Group* aGroup = it->second;
1068 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1070 string aGroupName0 = aGroup->GetName();
1071 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1072 string aGroupName = aGroupName0;
1073 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
1074 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1075 aGroupName = aString;
1076 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1078 aGroupDS->SetStoreName( aGroupName.c_str() );
1079 myWriter.AddGroup( aGroupDS );
1087 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1089 Unexpect aCatch(SalomeException);
1090 DriverDAT_W_SMDS_Mesh myWriter;
1091 myWriter.SetFile(string(file));
1092 myWriter.SetMesh(_myMeshDS);
1093 myWriter.SetMeshId(_idDoc);
1097 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1099 Unexpect aCatch(SalomeException);
1100 DriverUNV_W_SMDS_Mesh myWriter;
1101 myWriter.SetFile(string(file));
1102 myWriter.SetMesh(_myMeshDS);
1103 myWriter.SetMeshId(_idDoc);
1104 // myWriter.SetGroups(_mapGroup);
1106 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1107 SMESH_Group* aGroup = it->second;
1108 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1110 std::string aGroupName = aGroup->GetName();
1111 aGroupDS->SetStoreName( aGroupName.c_str() );
1112 myWriter.AddGroup( aGroupDS );
1118 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1120 Unexpect aCatch(SalomeException);
1121 DriverSTL_W_SMDS_Mesh myWriter;
1122 myWriter.SetFile(string(file));
1123 myWriter.SetIsAscii( isascii );
1124 myWriter.SetMesh(_myMeshDS);
1125 myWriter.SetMeshId(_idDoc);
1129 //================================================================================
1131 * \brief Return number of nodes in the mesh
1133 //================================================================================
1135 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1137 Unexpect aCatch(SalomeException);
1138 return _myMeshDS->NbNodes();
1141 //================================================================================
1143 * \brief Return number of edges of given order in the mesh
1145 //================================================================================
1147 int SMESH_Mesh::NbEdges(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1149 Unexpect aCatch(SalomeException);
1150 return _myMeshDS->GetMeshInfo().NbEdges(order);
1153 //================================================================================
1155 * \brief Return number of faces of given order in the mesh
1157 //================================================================================
1159 int SMESH_Mesh::NbFaces(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1161 Unexpect aCatch(SalomeException);
1162 return _myMeshDS->GetMeshInfo().NbFaces(order);
1165 //================================================================================
1167 * \brief Return the number of faces in the mesh
1169 //================================================================================
1171 int SMESH_Mesh::NbTriangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1173 Unexpect aCatch(SalomeException);
1174 return _myMeshDS->GetMeshInfo().NbTriangles(order);
1177 //================================================================================
1179 * \brief Return the number nodes faces in the mesh
1181 //================================================================================
1183 int SMESH_Mesh::NbQuadrangles(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1185 Unexpect aCatch(SalomeException);
1186 return _myMeshDS->GetMeshInfo().NbQuadrangles(order);
1189 //================================================================================
1191 * \brief Return the number of polygonal faces in the mesh
1193 //================================================================================
1195 int SMESH_Mesh::NbPolygons() throw(SALOME_Exception)
1197 Unexpect aCatch(SalomeException);
1198 return _myMeshDS->GetMeshInfo().NbPolygons();
1201 //================================================================================
1203 * \brief Return number of volumes of given order in the mesh
1205 //================================================================================
1207 int SMESH_Mesh::NbVolumes(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1209 Unexpect aCatch(SalomeException);
1210 return _myMeshDS->GetMeshInfo().NbVolumes(order);
1213 //================================================================================
1215 * \brief Return number of tetrahedrons of given order in the mesh
1217 //================================================================================
1219 int SMESH_Mesh::NbTetras(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1221 Unexpect aCatch(SalomeException);
1222 return _myMeshDS->GetMeshInfo().NbTetras(order);
1225 //================================================================================
1227 * \brief Return number of hexahedrons of given order in the mesh
1229 //================================================================================
1231 int SMESH_Mesh::NbHexas(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1233 Unexpect aCatch(SalomeException);
1234 return _myMeshDS->GetMeshInfo().NbHexas(order);
1237 //================================================================================
1239 * \brief Return number of pyramids of given order in the mesh
1241 //================================================================================
1243 int SMESH_Mesh::NbPyramids(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1245 Unexpect aCatch(SalomeException);
1246 return _myMeshDS->GetMeshInfo().NbPyramids(order);
1249 //================================================================================
1251 * \brief Return number of prisms (penthahedrons) of given order in the mesh
1253 //================================================================================
1255 int SMESH_Mesh::NbPrisms(SMDSAbs_ElementOrder order) throw(SALOME_Exception)
1257 Unexpect aCatch(SalomeException);
1258 return _myMeshDS->GetMeshInfo().NbPrisms(order);
1261 //================================================================================
1263 * \brief Return number of polyhedrons in the mesh
1265 //================================================================================
1267 int SMESH_Mesh::NbPolyhedrons() throw(SALOME_Exception)
1269 Unexpect aCatch(SalomeException);
1270 return _myMeshDS->GetMeshInfo().NbPolyhedrons();
1273 //================================================================================
1275 * \brief Return number of submeshes in the mesh
1277 //================================================================================
1279 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
1281 Unexpect aCatch(SalomeException);
1282 return _myMeshDS->NbSubMesh();
1285 //=======================================================================
1286 //function : IsNotConformAllowed
1287 //purpose : check if a hypothesis alowing notconform mesh is present
1288 //=======================================================================
1290 bool SMESH_Mesh::IsNotConformAllowed() const
1292 if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
1294 static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
1295 return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
1298 //=======================================================================
1299 //function : IsMainShape
1301 //=======================================================================
1303 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
1305 return theShape.IsSame(_myMeshDS->ShapeToMesh() );
1308 //=============================================================================
1312 //=============================================================================
1314 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
1315 const char* theName,
1317 const TopoDS_Shape& theShape)
1319 if (_mapGroup.find(_groupId) != _mapGroup.end())
1322 SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
1323 GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
1324 _mapGroup[_groupId++] = aGroup;
1328 //================================================================================
1330 * \brief Return iterator on all existing groups
1332 //================================================================================
1334 SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
1336 typedef map <int, SMESH_Group *> TMap;
1337 return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
1340 //=============================================================================
1342 * \brief Return a group by ID
1344 //=============================================================================
1346 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
1348 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1350 return _mapGroup[theGroupID];
1354 //=============================================================================
1356 * \brief Return IDs of all groups
1358 //=============================================================================
1360 std::list<int> SMESH_Mesh::GetGroupIds() const
1362 std::list<int> anIds;
1363 for ( std::map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
1364 anIds.push_back( it->first );
1370 //=============================================================================
1374 //=============================================================================
1376 void SMESH_Mesh::RemoveGroup (const int theGroupID)
1378 if (_mapGroup.find(theGroupID) == _mapGroup.end())
1380 GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
1381 delete _mapGroup[theGroupID];
1382 _mapGroup.erase (theGroupID);
1385 //=======================================================================
1386 //function : GetAncestors
1387 //purpose : return list of ancestors of theSubShape in the order
1388 // that lower dimention shapes come first.
1389 //=======================================================================
1391 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
1393 if ( _mapAncestors.Contains( theS ) )
1394 return _mapAncestors.FindFromKey( theS );
1396 static TopTools_ListOfShape emptyList;
1400 //=======================================================================
1402 //purpose : dumps contents of mesh to stream [ debug purposes ]
1403 //=======================================================================
1405 ostream& SMESH_Mesh::Dump(ostream& save)
1408 save << "========================== Dump contents of mesh ==========================" << endl << endl;
1409 save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
1410 save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
1411 save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
1412 save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
1413 save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
1414 save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
1415 for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
1417 string orderStr = isQuadratic ? "quadratic" : "linear";
1418 SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
1420 save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
1421 save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
1422 if ( NbFaces(order) > 0 ) {
1423 int nb3 = NbTriangles(order);
1424 int nb4 = NbQuadrangles(order);
1425 save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
1426 save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
1427 if ( nb3 + nb4 != NbFaces(order) ) {
1428 std::map<int,int> myFaceMap;
1429 SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1430 while( itFaces->more( ) ) {
1431 int nbNodes = itFaces->next()->NbNodes();
1432 if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1433 myFaceMap[ nbNodes ] = 0;
1434 myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1436 save << clause << ".3) Faces in detail: " << endl;
1437 map <int,int>::iterator itF;
1438 for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1439 save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
1442 save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
1443 if ( NbVolumes(order) > 0 ) {
1444 int nb8 = NbHexas(order);
1445 int nb4 = NbTetras(order);
1446 int nb5 = NbPyramids(order);
1447 int nb6 = NbPrisms(order);
1448 save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
1449 save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
1450 save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
1451 save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
1452 if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
1453 std::map<int,int> myVolumesMap;
1454 SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1455 while( itVolumes->more( ) ) {
1456 int nbNodes = itVolumes->next()->NbNodes();
1457 if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1458 myVolumesMap[ nbNodes ] = 0;
1459 myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1461 save << clause << ".5) Volumes in detail: " << endl;
1462 map <int,int>::iterator itV;
1463 for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1464 save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
1469 save << "===========================================================================" << endl;
1473 //=======================================================================
1474 //function : GetElementType
1475 //purpose : Returns type of mesh element with certain id
1476 //=======================================================================
1478 SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
1480 return _myMeshDS->GetElementType( id, iselem );