1 // Copyright (C) 2007-2008 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
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_Mesh.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Mesh.hxx"
28 #include "SMESH_subMesh.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_Hypothesis.hxx"
31 #include "SMESH_Group.hxx"
32 #include "SMESH_HypoFilter.hxx"
33 #include "SMESHDS_Group.hxx"
34 #include "SMESHDS_Script.hxx"
35 #include "SMESHDS_GroupOnGeom.hxx"
36 #include "SMESHDS_Document.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_SetIterator.hxx"
40 #include "utilities.h"
42 #include "DriverMED_W_SMESHDS_Mesh.h"
43 #include "DriverDAT_W_SMDS_Mesh.h"
44 #include "DriverUNV_W_SMDS_Mesh.h"
45 #include "DriverSTL_W_SMDS_Mesh.h"
47 #include "DriverMED_R_SMESHDS_Mesh.h"
48 #include "DriverUNV_R_SMDS_Mesh.h"
49 #include "DriverSTL_R_SMDS_Mesh.h"
51 #undef _Precision_HeaderFile
52 #include <BRepPrimAPI_MakeBox.hxx>
54 #include <TopExp_Explorer.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
57 #include <TopTools_MapOfShape.hxx>
58 #include <TopoDS_Iterator.hxx>
60 #include "Utils_ExceptHandlers.hxx"
62 // maximum stored group name length in MED file
63 #define MAX_MED_GROUP_NAME_LENGTH 80
66 static int MYDEBUG = 0;
68 static int MYDEBUG = 0;
73 #define cSMESH_Hyp(h) static_cast<const SMESH_Hypothesis*>(h)
75 typedef SMESH_HypoFilter THypType;
77 //=============================================================================
81 //=============================================================================
83 SMESH_Mesh::SMESH_Mesh(int theLocalId,
86 bool theIsEmbeddedMode,
87 SMESHDS_Document* theDocument):
88 _groupId( 0 ), _nbSubShapes( 0 )
90 MESSAGE("SMESH_Mesh::SMESH_Mesh(int localId)");
92 _studyId = theStudyId;
94 _myDocument = theDocument;
95 _idDoc = theDocument->NewMesh(theIsEmbeddedMode);
96 _myMeshDS = theDocument->GetMesh(_idDoc);
97 _isShapeToMesh = false;
99 _myMeshDS->ShapeToMesh( PseudoShape() );
102 //=============================================================================
106 //=============================================================================
108 SMESH_Mesh::~SMESH_Mesh()
110 INFOS("SMESH_Mesh::~SMESH_Mesh");
112 // issue 0020340: EDF 1022 SMESH : Crash with FindNodeClosestTo in a second new study
113 // Notify event listeners at least that something happens
114 if ( SMESH_subMesh * sm = GetSubMeshContaining(1))
115 sm->ComputeStateEngine( SMESH_subMesh::MESH_ENTITY_REMOVED );
118 std::map < int, SMESH_Group * >::iterator itg;
119 for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
120 SMESH_Group *aGroup = (*itg).second;
126 //=============================================================================
128 * \brief Set geometry to be meshed
130 //=============================================================================
132 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape)
134 if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
136 if ( !aShape.IsNull() && _isShapeToMesh )
137 throw SALOME_Exception(LOCALIZED ("a shape to mesh has already been defined"));
139 // clear current data
140 if ( !_myMeshDS->ShapeToMesh().IsNull() )
142 // removal of a shape to mesh, delete objects referring to sub-shapes:
144 std::map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.begin();
145 for ( ; i_sm != _mapSubMesh.end(); ++i_sm )
148 // - groups on geometry
149 std::map <int, SMESH_Group *>::iterator i_gr = _mapGroup.begin();
150 while ( i_gr != _mapGroup.end() ) {
151 if ( dynamic_cast<SMESHDS_GroupOnGeom*>( i_gr->second->GetGroupDS() )) {
152 _myMeshDS->RemoveGroup( i_gr->second->GetGroupDS() );
154 _mapGroup.erase( i_gr++ );
159 _mapAncestors.Clear();
162 TopoDS_Shape aNullShape;
163 _myMeshDS->ShapeToMesh( aNullShape );
166 // set a new geometry
167 if ( !aShape.IsNull() )
169 _myMeshDS->ShapeToMesh(aShape);
170 _isShapeToMesh = true;
171 _nbSubShapes = _myMeshDS->MaxShapeIndex();
173 // fill _mapAncestors
174 int desType, ancType;
175 for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
176 for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
177 TopExp::MapShapesAndAncestors ( aShape,
178 (TopAbs_ShapeEnum) desType,
179 (TopAbs_ShapeEnum) ancType,
184 _isShapeToMesh = false;
185 _myMeshDS->ShapeToMesh( PseudoShape() );
189 //=======================================================================
191 * \brief Return geometry to be meshed. (It may be a PseudoShape()!)
193 //=======================================================================
195 TopoDS_Shape SMESH_Mesh::GetShapeToMesh() const
197 return _myMeshDS->ShapeToMesh();
200 //=======================================================================
202 * \brief Return a solid which is returned by GetShapeToMesh() if
203 * a real geometry to be meshed was not set
205 //=======================================================================
207 const TopoDS_Solid& SMESH_Mesh::PseudoShape()
209 static TopoDS_Solid aSolid;
210 if ( aSolid.IsNull() )
212 aSolid = BRepPrimAPI_MakeBox(1,1,1);
217 //=======================================================================
219 * \brief Remove all nodes and elements
221 //=======================================================================
223 void SMESH_Mesh::Clear()
226 _myMeshDS->ClearMesh();
228 // update compute state of submeshes
229 if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) ) {
230 SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
231 /*complexShapeFirst=*/false);
232 while ( smIt->more() ) {
234 sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
238 // // clear sub-meshes; get ready to re-compute as a side-effect
240 // if ( SMESH_subMesh *sm = GetSubMeshContaining( GetShapeToMesh() ) )
242 // SMESH_subMeshIteratorPtr smIt = sm->getDependsOnIterator(/*includeSelf=*/true,
243 // /*complexShapeFirst=*/false);
244 // while ( smIt->more() )
246 // sm = smIt->next();
247 // TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
248 // if ( shapeType == TopAbs_VERTEX || shapeType < TopAbs_SOLID )
249 // // all other shapes depends on vertices so they are already cleaned
250 // sm->ComputeStateEngine( SMESH_subMesh::CLEAN );
251 // // to recompute even if failed
252 // sm->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
256 // // clear entities not on sub-meshes
258 // SMDS_VolumeIteratorPtr vIt = _myMeshDS->volumesIterator();
259 // while ( vIt->more() )
260 // _myMeshDS->RemoveFreeElement( vIt->next(), 0 );
262 // SMDS_FaceIteratorPtr fIt = _myMeshDS->facesIterator();
263 // while ( fIt->more() )
264 // _myMeshDS->RemoveFreeElement( fIt->next(), 0 );
266 // SMDS_EdgeIteratorPtr eIt = _myMeshDS->edgesIterator();
267 // while ( eIt->more() )
268 // _myMeshDS->RemoveFreeElement( eIt->next(), 0 );
270 // SMDS_NodeIteratorPtr nIt = _myMeshDS->nodesIterator();
271 // while ( nIt->more() ) {
272 // const SMDS_MeshNode * node = nIt->next();
273 // if ( node->NbInverseElements() == 0 )
274 // _myMeshDS->RemoveFreeNode( node, 0 );
276 // _myMeshDS->RemoveNode(node);
280 //=======================================================================
281 //function : UNVToMesh
283 //=======================================================================
285 int SMESH_Mesh::UNVToMesh(const char* theFileName)
287 if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
289 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
290 _isShapeToMesh = false;
291 DriverUNV_R_SMDS_Mesh myReader;
292 myReader.SetMesh(_myMeshDS);
293 myReader.SetFile(theFileName);
294 myReader.SetMeshId(-1);
297 MESSAGE("UNVToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
298 MESSAGE("UNVToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
299 MESSAGE("UNVToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
300 MESSAGE("UNVToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
302 SMDS_MeshGroup* aGroup = (SMDS_MeshGroup*) myReader.GetGroup();
304 TGroupNamesMap aGroupNames = myReader.GetGroupNamesMap();
305 //const TGroupIdMap& aGroupId = myReader.GetGroupIdMap();
306 aGroup->InitSubGroupsIterator();
307 while (aGroup->MoreSubGroups()) {
308 SMDS_MeshGroup* aSubGroup = (SMDS_MeshGroup*) aGroup->NextSubGroup();
309 std::string aName = aGroupNames[aSubGroup];
312 SMESH_Group* aSMESHGroup = AddGroup( aSubGroup->GetType(), aName.c_str(), aId );
314 if(MYDEBUG) MESSAGE("UNVToMesh - group added: "<<aName);
315 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aSMESHGroup->GetGroupDS() );
317 aGroupDS->SetStoreName(aName.c_str());
318 aSubGroup->InitIterator();
319 const SMDS_MeshElement* aElement = 0;
320 while (aSubGroup->More()) {
321 aElement = aSubGroup->Next();
323 aGroupDS->SMDSGroup().Add(aElement);
327 aGroupDS->SetType(aElement->GetType());
335 //=======================================================================
336 //function : MEDToMesh
338 //=======================================================================
340 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
342 if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
344 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
345 _isShapeToMesh = false;
346 DriverMED_R_SMESHDS_Mesh myReader;
347 myReader.SetMesh(_myMeshDS);
348 myReader.SetMeshId(-1);
349 myReader.SetFile(theFileName);
350 myReader.SetMeshName(theMeshName);
351 Driver_Mesh::Status status = myReader.Perform();
353 MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
354 MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
355 MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
356 MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
359 // Reading groups (sub-meshes are out of scope of MED import functionality)
360 std::list<TNameAndType> aGroupNames = myReader.GetGroupNamesAndTypes();
361 if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size());
363 std::list<TNameAndType>::iterator name_type = aGroupNames.begin();
364 for ( ; name_type != aGroupNames.end(); name_type++ ) {
365 SMESH_Group* aGroup = AddGroup( name_type->second, name_type->first.c_str(), anId );
367 if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<name_type->first.c_str());
368 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
370 aGroupDS->SetStoreName( name_type->first.c_str() );
371 myReader.GetGroup( aGroupDS );
378 //=======================================================================
379 //function : STLToMesh
381 //=======================================================================
383 int SMESH_Mesh::STLToMesh(const char* theFileName)
385 if(MYDEBUG) MESSAGE("STLToMesh - theFileName = "<<theFileName);
387 throw SALOME_Exception(LOCALIZED("a shape to mesh has already been defined"));
388 _isShapeToMesh = false;
389 DriverSTL_R_SMDS_Mesh myReader;
390 myReader.SetMesh(_myMeshDS);
391 myReader.SetFile(theFileName);
392 myReader.SetMeshId(-1);
395 MESSAGE("STLToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
396 MESSAGE("STLToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
397 MESSAGE("STLToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
398 MESSAGE("STLToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
403 //=============================================================================
407 //=============================================================================
409 SMESH_Hypothesis::Hypothesis_Status
410 SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
411 int anHypId ) throw(SALOME_Exception)
413 Unexpect aCatch(SalomeException);
414 if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
416 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
417 if ( !subMesh || !subMesh->GetId())
418 return SMESH_Hypothesis::HYP_BAD_SUBSHAPE;
420 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
421 if ( subMeshDS && subMeshDS->IsComplexSubmesh() ) // group of sub-shapes and maybe of not sub-
423 MESSAGE("AddHypothesis() to complex submesh");
424 // return the worst but not fatal state of all group memebers
425 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
426 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
427 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
428 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
430 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
431 continue; // not sub-shape
432 ret = AddHypothesis( itS.Value(), anHypId );
433 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
434 aWorstNotFatal = ret;
435 if ( ret < aBestRet )
438 // bind hypotheses to a group just to know
439 SMESH_Hypothesis *anHyp = _gen->GetStudyContext(_studyId)->mapHypothesis[anHypId];
440 GetMeshDS()->AddHypothesis( aSubShape, anHyp );
442 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
444 return aWorstNotFatal;
447 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
448 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
450 if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
455 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
458 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
459 MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
461 bool isGlobalHyp = IsMainShape( aSubShape );
463 // NotConformAllowed can be only global
466 string hypName = anHyp->GetName();
467 if ( hypName == "NotConformAllowed" )
469 if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
470 return SMESH_Hypothesis::HYP_INCOMPATIBLE;
476 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
477 int event = isAlgo ? SMESH_subMesh::ADD_ALGO : SMESH_subMesh::ADD_HYP;
479 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
482 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
483 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is added on father
485 event = isAlgo ? SMESH_subMesh::ADD_FATHER_ALGO : SMESH_subMesh::ADD_FATHER_HYP;
487 SMESH_Hypothesis::Hypothesis_Status ret2 =
488 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
492 // check concurent hypotheses on ansestors
493 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
495 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
496 while ( smIt->more() ) {
497 SMESH_subMesh* sm = smIt->next();
498 if ( sm->IsApplicableHypotesis( anHyp )) {
499 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
509 if(MYDEBUG) subMesh->DumpAlgoState(true);
514 //=============================================================================
518 //=============================================================================
520 SMESH_Hypothesis::Hypothesis_Status
521 SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
522 int anHypId)throw(SALOME_Exception)
524 Unexpect aCatch(SalomeException);
525 if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
527 SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
528 SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
529 if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
531 // return the worst but not fatal state of all group memebers
532 SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
533 aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
534 aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
535 for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
537 if ( !GetMeshDS()->ShapeToIndex( itS.Value() ))
538 continue; // not sub-shape
539 ret = RemoveHypothesis( itS.Value(), anHypId );
540 if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
541 aWorstNotFatal = ret;
542 if ( ret < aBestRet )
545 SMESH_Hypothesis *anHyp = _gen->GetStudyContext(_studyId)->mapHypothesis[anHypId];
546 GetMeshDS()->RemoveHypothesis( aSubShape, anHyp );
548 if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
550 return aWorstNotFatal;
553 StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
554 if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
555 throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
557 SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
558 int hypType = anHyp->GetType();
559 if(MYDEBUG) SCRUTE(hypType);
563 bool isAlgo = ( !anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO );
564 int event = isAlgo ? SMESH_subMesh::REMOVE_ALGO : SMESH_subMesh::REMOVE_HYP;
566 SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
568 // there may appear concurrent hyps that were covered by the removed hyp
569 if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
570 subMesh->IsApplicableHypotesis( anHyp ) &&
571 subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
572 ret = SMESH_Hypothesis::HYP_CONCURENT;
575 if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
576 anHyp->GetDim() <= SMESH_Gen::GetShapeDim(aSubShape)) // is removed from father
578 event = isAlgo ? SMESH_subMesh::REMOVE_FATHER_ALGO : SMESH_subMesh::REMOVE_FATHER_HYP;
580 SMESH_Hypothesis::Hypothesis_Status ret2 =
581 subMesh->SubMeshesAlgoStateEngine(event, anHyp);
582 if (ret2 > ret) // more severe
585 // check concurent hypotheses on ansestors
586 if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
588 SMESH_subMeshIteratorPtr smIt = subMesh->getDependsOnIterator(false,false);
589 while ( smIt->more() ) {
590 SMESH_subMesh* sm = smIt->next();
591 if ( sm->IsApplicableHypotesis( anHyp )) {
592 ret2 = sm->CheckConcurentHypothesis( anHyp->GetType() );
602 if(MYDEBUG) subMesh->DumpAlgoState(true);
603 if(MYDEBUG) SCRUTE(ret);
607 //=============================================================================
611 //=============================================================================
613 const std::list<const SMESHDS_Hypothesis*>&
614 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
615 throw(SALOME_Exception)
617 Unexpect aCatch(SalomeException);
618 return _myMeshDS->GetHypothesis(aSubShape);
621 //=======================================================================
623 * \brief Return the hypothesis assigned to the shape
624 * \param aSubShape - the shape to check
625 * \param aFilter - the hypothesis filter
626 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
627 * \param assignedTo - to return the shape the found hypo is assigned to
628 * \retval SMESH_Hypothesis* - the first hypo passed through aFilter
630 //=======================================================================
632 const SMESH_Hypothesis * SMESH_Mesh::GetHypothesis(const TopoDS_Shape & aSubShape,
633 const SMESH_HypoFilter& aFilter,
634 const bool andAncestors,
635 TopoDS_Shape* assignedTo) const
638 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
639 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
640 for ( ; hyp != hypList.end(); hyp++ ) {
641 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
642 if ( aFilter.IsOk( h, aSubShape)) {
643 if ( assignedTo ) *assignedTo = aSubShape;
650 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
651 for (; it.More(); it.Next() )
653 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
654 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp = hypList.begin();
655 for ( ; hyp != hypList.end(); hyp++ ) {
656 const SMESH_Hypothesis * h = cSMESH_Hyp( *hyp );
657 if (aFilter.IsOk( h, it.Value() )) {
658 if ( assignedTo ) *assignedTo = it.Value();
667 //================================================================================
669 * \brief Return hypothesis assigned to the shape
670 * \param aSubShape - the shape to check
671 * \param aFilter - the hypothesis filter
672 * \param aHypList - the list of the found hypotheses
673 * \param andAncestors - flag to check hypos assigned to ancestors of the shape
674 * \retval int - number of unique hypos in aHypList
676 //================================================================================
678 int SMESH_Mesh::GetHypotheses(const TopoDS_Shape & aSubShape,
679 const SMESH_HypoFilter& aFilter,
680 list <const SMESHDS_Hypothesis * >& aHypList,
681 const bool andAncestors) const
683 set<string> hypTypes; // to exclude same type hypos from the result list
686 // only one main hypothesis is allowed
687 bool mainHypFound = false;
690 std::list<const SMESHDS_Hypothesis*>::const_iterator hyp;
691 for ( hyp = aHypList.begin(); hyp != aHypList.end(); hyp++ ) {
692 if ( hypTypes.insert( (*hyp)->GetName() ).second )
694 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
698 // get hypos from aSubShape
700 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(aSubShape);
701 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
702 if ( aFilter.IsOk (cSMESH_Hyp( *hyp ), aSubShape) &&
703 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
704 hypTypes.insert( (*hyp)->GetName() ).second )
706 aHypList.push_back( *hyp );
708 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
713 // get hypos from ancestors of aSubShape
716 TopTools_MapOfShape map;
717 TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
718 for (; it.More(); it.Next() )
720 if ( !map.Add( it.Value() ))
722 const std::list<const SMESHDS_Hypothesis*>& hypList = _myMeshDS->GetHypothesis(it.Value());
723 for ( hyp = hypList.begin(); hyp != hypList.end(); hyp++ )
724 if (aFilter.IsOk( cSMESH_Hyp( *hyp ), it.Value() ) &&
725 ( cSMESH_Hyp(*hyp)->IsAuxiliary() || !mainHypFound ) &&
726 hypTypes.insert( (*hyp)->GetName() ).second )
728 aHypList.push_back( *hyp );
730 if ( !cSMESH_Hyp(*hyp)->IsAuxiliary() )
738 //=============================================================================
742 //=============================================================================
744 const std::list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
746 Unexpect aCatch(SalomeException);
747 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
748 return _myMeshDS->GetScript()->GetCommands();
751 //=============================================================================
755 //=============================================================================
756 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
758 Unexpect aCatch(SalomeException);
759 if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
760 _myMeshDS->GetScript()->Clear();
763 //=============================================================================
765 * Get or Create the SMESH_subMesh object implementation
767 //=============================================================================
769 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
770 throw(SALOME_Exception)
772 Unexpect aCatch(SalomeException);
773 SMESH_subMesh *aSubMesh;
774 int index = _myMeshDS->ShapeToIndex(aSubShape);
776 // for submeshes on GEOM Group
777 if (( !index || index > _nbSubShapes ) && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
778 TopoDS_Iterator it( aSubShape );
780 index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
783 // return NULL; // neither sub-shape nor a group
785 map <int, SMESH_subMesh *>::iterator i_sm = _mapSubMesh.find(index);
786 if ( i_sm != _mapSubMesh.end())
788 aSubMesh = i_sm->second;
792 aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
793 _mapSubMesh[index] = aSubMesh;
798 //=============================================================================
800 * Get the SMESH_subMesh object implementation. Dont create it, return null
801 * if it does not exist.
803 //=============================================================================
805 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape) const
806 throw(SALOME_Exception)
808 Unexpect aCatch(SalomeException);
809 SMESH_subMesh *aSubMesh = NULL;
811 int index = _myMeshDS->ShapeToIndex(aSubShape);
813 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
814 if ( i_sm != _mapSubMesh.end())
815 aSubMesh = i_sm->second;
819 //=============================================================================
821 * Get the SMESH_subMesh object implementation. Dont create it, return null
822 * if it does not exist.
824 //=============================================================================
826 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const int aShapeID) const
827 throw(SALOME_Exception)
829 Unexpect aCatch(SalomeException);
831 map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(aShapeID);
832 if (i_sm == _mapSubMesh.end())
836 //================================================================================
838 * \brief Return submeshes of groups containing the given subshape
840 //================================================================================
842 std::list<SMESH_subMesh*>
843 SMESH_Mesh::GetGroupSubMeshesContaining(const TopoDS_Shape & aSubShape) const
844 throw(SALOME_Exception)
846 Unexpect aCatch(SalomeException);
847 std::list<SMESH_subMesh*> found;
849 SMESH_subMesh * subMesh = GetSubMeshContaining(aSubShape);
853 // submeshes of groups have max IDs, so search from the map end
854 std::map<int, SMESH_subMesh *>::const_reverse_iterator i_sm;
855 for ( i_sm = _mapSubMesh.rbegin(); i_sm != _mapSubMesh.rend(); ++i_sm) {
856 SMESHDS_SubMesh * ds = i_sm->second->GetSubMeshDS();
857 if ( ds && ds->IsComplexSubmesh() ) {
858 TopExp_Explorer exp( i_sm->second->GetSubShape(), aSubShape.ShapeType() );
859 for ( ; exp.More(); exp.Next() ) {
860 if ( aSubShape.IsSame( exp.Current() )) {
861 found.push_back( i_sm->second );
871 //=======================================================================
872 //function : IsUsedHypothesis
873 //purpose : Return True if anHyp is used to mesh aSubShape
874 //=======================================================================
876 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
877 const SMESH_subMesh* aSubMesh)
879 SMESH_Hypothesis* hyp = static_cast<SMESH_Hypothesis*>(anHyp);
881 // check if anHyp can be used to mesh aSubMesh
882 if ( !aSubMesh || !aSubMesh->IsApplicableHypotesis( hyp ))
885 const TopoDS_Shape & aSubShape = const_cast<SMESH_subMesh*>( aSubMesh )->GetSubShape();
887 SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape );
890 if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
891 return ( anHyp == algo );
893 // algorithm parameter
896 // look trough hypotheses used by algo
897 SMESH_HypoFilter hypoKind;
898 if ( algo->InitCompatibleHypoFilter( hypoKind, !hyp->IsAuxiliary() )) {
899 list <const SMESHDS_Hypothesis * > usedHyps;
900 if ( GetHypotheses( aSubShape, hypoKind, usedHyps, true ))
901 return ( find( usedHyps.begin(), usedHyps.end(), anHyp ) != usedHyps.end() );
905 // look through all assigned hypotheses
906 //SMESH_HypoFilter filter( SMESH_HypoFilter::Is( hyp ));
907 return false; //GetHypothesis( aSubShape, filter, true );
910 //=============================================================================
914 //=============================================================================
916 const list < SMESH_subMesh * >&
917 SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
918 throw(SALOME_Exception)
920 Unexpect aCatch(SalomeException);
921 if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
922 map < int, SMESH_subMesh * >::iterator itsm;
923 _subMeshesUsingHypothesisList.clear();
924 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
926 SMESH_subMesh *aSubMesh = (*itsm).second;
927 if ( IsUsedHypothesis ( anHyp, aSubMesh ))
928 _subMeshesUsingHypothesisList.push_back(aSubMesh);
930 return _subMeshesUsingHypothesisList;
933 //=======================================================================
934 //function : NotifySubMeshesHypothesisModification
935 //purpose : Say all submeshes using theChangedHyp that it has been modified
936 //=======================================================================
938 void SMESH_Mesh::NotifySubMeshesHypothesisModification(const SMESH_Hypothesis* hyp)
940 Unexpect aCatch(SalomeException);
942 const SMESH_Algo *foundAlgo = 0;
943 SMESH_HypoFilter algoKind, compatibleHypoKind;
944 list <const SMESHDS_Hypothesis * > usedHyps;
947 map < int, SMESH_subMesh * >::iterator itsm;
948 for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
950 SMESH_subMesh *aSubMesh = (*itsm).second;
951 if ( aSubMesh->IsApplicableHypotesis( hyp ))
953 const TopoDS_Shape & aSubShape = aSubMesh->GetSubShape();
955 if ( !foundAlgo ) // init filter for algo search
956 algoKind.Init( THypType::IsAlgo() ).And( THypType::IsApplicableTo( aSubShape ));
958 const SMESH_Algo *algo = static_cast<const SMESH_Algo*>
959 ( GetHypothesis( aSubShape, algoKind, true ));
963 bool sameAlgo = ( algo == foundAlgo );
964 if ( !sameAlgo && foundAlgo )
965 sameAlgo = ( strcmp( algo->GetName(), foundAlgo->GetName() ) == 0);
967 if ( !sameAlgo ) { // init filter for used hypos search
968 if ( !algo->InitCompatibleHypoFilter( compatibleHypoKind, !hyp->IsAuxiliary() ))
969 continue; // algo does not use any hypothesis
973 // check if hyp is used by algo
975 if ( GetHypotheses( aSubShape, compatibleHypoKind, usedHyps, true ) &&
976 find( usedHyps.begin(), usedHyps.end(), hyp ) != usedHyps.end() )
978 aSubMesh->AlgoStateEngine(SMESH_subMesh::MODIF_HYP,
979 const_cast< SMESH_Hypothesis*>( hyp ));
986 //=============================================================================
988 * Auto color functionality
990 //=============================================================================
991 void SMESH_Mesh::SetAutoColor(bool theAutoColor) throw(SALOME_Exception)
993 Unexpect aCatch(SalomeException);
994 _isAutoColor = theAutoColor;
997 bool SMESH_Mesh::GetAutoColor() throw(SALOME_Exception)
999 Unexpect aCatch(SalomeException);
1000 return _isAutoColor;
1003 //=============================================================================
1004 /*! Export* methods.
1005 * To store mesh contents on disk in different formats.
1007 //=============================================================================
1009 bool SMESH_Mesh::HasDuplicatedGroupNamesMED()
1011 set<string> aGroupNames;
1012 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1013 SMESH_Group* aGroup = it->second;
1014 std::string aGroupName = aGroup->GetName();
1015 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1016 if (!aGroupNames.insert(aGroupName).second)
1023 void SMESH_Mesh::ExportMED(const char *file,
1024 const char* theMeshName,
1027 throw(SALOME_Exception)
1029 Unexpect aCatch(SalomeException);
1031 DriverMED_W_SMESHDS_Mesh myWriter;
1032 myWriter.SetFile ( file, MED::EVersion(theVersion) );
1033 myWriter.SetMesh ( _myMeshDS );
1035 myWriter.SetMeshId ( _idDoc );
1037 myWriter.SetMeshId ( -1 );
1038 myWriter.SetMeshName( theMeshName );
1041 if ( theAutoGroups ) {
1042 myWriter.AddGroupOfNodes();
1043 myWriter.AddGroupOfEdges();
1044 myWriter.AddGroupOfFaces();
1045 myWriter.AddGroupOfVolumes();
1048 // Pass groups to writer. Provide unique group names.
1049 set<string> aGroupNames;
1051 int maxNbIter = 10000; // to guarantee cycle finish
1052 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1053 SMESH_Group* aGroup = it->second;
1054 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1056 string aGroupName0 = aGroup->GetName();
1057 aGroupName0.resize(MAX_MED_GROUP_NAME_LENGTH);
1058 string aGroupName = aGroupName0;
1059 for (int i = 1; !aGroupNames.insert(aGroupName).second && i < maxNbIter; i++) {
1060 sprintf(&aString[0], "GR_%d_%s", i, aGroupName0.c_str());
1061 aGroupName = aString;
1062 aGroupName.resize(MAX_MED_GROUP_NAME_LENGTH);
1064 aGroupDS->SetStoreName( aGroupName.c_str() );
1065 myWriter.AddGroup( aGroupDS );
1073 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
1075 Unexpect aCatch(SalomeException);
1076 DriverDAT_W_SMDS_Mesh myWriter;
1077 myWriter.SetFile(string(file));
1078 myWriter.SetMesh(_myMeshDS);
1079 myWriter.SetMeshId(_idDoc);
1083 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
1085 Unexpect aCatch(SalomeException);
1086 DriverUNV_W_SMDS_Mesh myWriter;
1087 myWriter.SetFile(string(file));
1088 myWriter.SetMesh(_myMeshDS);
1089 myWriter.SetMeshId(_idDoc);
1090 // myWriter.SetGroups(_mapGroup);
1092 for ( std::map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
1093 SMESH_Group* aGroup = it->second;
1094 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
1096 std::string aGroupName = aGroup->GetName();
1097 aGroupDS->SetStoreName( aGroupName.c_str() );
1098 myWriter.AddGroup( aGroupDS );
1104 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
1106 Unexpect aCatch(SalomeException);
1107 DriverSTL_W_SMDS_Mesh myWriter;
1108 myWriter.SetFile(string(file));
1109 myWriter.SetIsAscii( isascii );
1110 myWriter.SetMesh(_myMeshDS);
1111 myWriter.SetMeshId(_idDoc);
1115 //================================================================================
1117 * \brief Return number of nodes in the mesh
1119 //================================================================================
1121 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
1123 Unexpect aCatch(SalomeException);
1124 return _myMeshDS->NbNodes();
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 std::list<int> SMESH_Mesh::GetGroupIds() const
1348 std::list<int> anIds;
1349 for ( std::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 std::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 std::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 );