Salome HOME
0c05113cf685d51b73c737d8a702e69d9d58edda
[modules/smesh.git] / src / SMESH / SMESH_Mesh.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Mesh.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
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 "SMESHDS_Group.hxx"
35 #include "SMESHDS_Script.hxx"
36 #include "SMDS_MeshVolume.hxx"
37
38 #include "utilities.h"
39
40 #include "DriverMED_W_SMESHDS_Mesh.h"
41 #include "DriverDAT_W_SMDS_Mesh.h"
42 #include "DriverUNV_W_SMDS_Mesh.h"
43 #include "DriverSTL_W_SMDS_Mesh.h"
44
45 #include "DriverMED_R_SMESHDS_Mesh.h"
46 #include "DriverUNV_R_SMDS_Mesh.h"
47 #include "DriverSTL_R_SMDS_Mesh.h"
48
49 #include <BRepTools_WireExplorer.hxx>
50 #include <BRep_Builder.hxx>
51 #include <gp_Pnt.hxx>
52
53 #include <TCollection_AsciiString.hxx>
54 #include <TopExp.hxx>
55 #include <TopTools_ListOfShape.hxx>
56 #include <TopTools_Array1OfShape.hxx>
57 #include <TopTools_ListIteratorOfListOfShape.hxx>
58
59 #include <memory>
60
61 #include "Utils_ExceptHandlers.hxx"
62
63 #ifdef _DEBUG_
64 static int MYDEBUG = 0;
65 #else
66 static int MYDEBUG = 0;
67 #endif
68
69
70 //=============================================================================
71 /*!
72  * 
73  */
74 //=============================================================================
75
76 SMESH_Mesh::SMESH_Mesh(int localId, int studyId, SMESH_Gen * gen, SMESHDS_Document * myDocument)
77 : _groupId( 0 )
78 {
79   INFOS("SMESH_Mesh::SMESH_Mesh(int localId)");
80         _id = localId;
81         _studyId = studyId;
82         _gen = gen;
83         _myDocument = myDocument;
84         _idDoc = _myDocument->NewMesh();
85         _myMeshDS = _myDocument->GetMesh(_idDoc);
86         _isShapeToMesh = false;
87 }
88
89 //=============================================================================
90 /*!
91  * 
92  */
93 //=============================================================================
94
95 SMESH_Mesh::~SMESH_Mesh()
96 {
97   INFOS("SMESH_Mesh::~SMESH_Mesh");
98
99   // delete groups
100   map < int, SMESH_Group * >::iterator itg;
101   for (itg = _mapGroup.begin(); itg != _mapGroup.end(); itg++) {
102     SMESH_Group *aGroup = (*itg).second;
103     delete aGroup;
104   }
105 }
106
107 //=============================================================================
108 /*!
109  * 
110  */
111 //=============================================================================
112
113 void SMESH_Mesh::ShapeToMesh(const TopoDS_Shape & aShape){
114   if(MYDEBUG) MESSAGE("SMESH_Mesh::ShapeToMesh");
115   if (_isShapeToMesh)
116     throw
117       SALOME_Exception(LOCALIZED
118                        ("a shape to mesh as already been defined"));
119   _isShapeToMesh = true;
120   _myMeshDS->ShapeToMesh(aShape);
121   
122   // NRI : 24/02/03
123   //EAP: 1/9/04 TopExp::MapShapes(aShape, _subShapes); USE the same map of _myMeshDS
124 }
125
126 //=======================================================================
127 //function : UNVToMesh
128 //purpose  : 
129 //=======================================================================
130
131 int SMESH_Mesh::UNVToMesh(const char* theFileName)
132 {
133   if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
134   if(_isShapeToMesh)
135     throw SALOME_Exception(LOCALIZED("a shape to mesh as already been defined"));
136   _isShapeToMesh = true;
137   DriverUNV_R_SMDS_Mesh myReader;
138   myReader.SetMesh(_myMeshDS);
139   myReader.SetFile(theFileName);
140   myReader.SetMeshId(-1);
141   myReader.Perform();
142   if(MYDEBUG){
143     MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
144     MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
145     MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
146     MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
147   }
148   return 1;
149 }
150
151 //=======================================================================
152 //function : MEDToMesh
153 //purpose  : 
154 //=======================================================================
155
156 int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
157 {
158   if(MYDEBUG) MESSAGE("MEDToMesh - theFileName = "<<theFileName<<", mesh name = "<<theMeshName);
159   if(_isShapeToMesh)
160     throw SALOME_Exception(LOCALIZED("a shape to mesh as already been defined"));
161   _isShapeToMesh = true;
162   DriverMED_R_SMESHDS_Mesh myReader;
163   myReader.SetMesh(_myMeshDS);
164   myReader.SetMeshId(-1);
165   myReader.SetFile(theFileName);
166   myReader.SetMeshName(theMeshName);
167   Driver_Mesh::Status status = myReader.Perform();
168   if(MYDEBUG){
169     MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
170     MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
171     MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
172     MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
173   }
174
175   // Reading groups (sub-meshes are out of scope of MED import functionality)
176   list<string> aGroupNames = myReader.GetGroupNames();
177   if(MYDEBUG) MESSAGE("MEDToMesh - Nb groups = "<<aGroupNames.size()); 
178   int anId;
179   for ( list<string>::iterator it = aGroupNames.begin(); it != aGroupNames.end(); it++ ) {
180     SMESH_Group* aGroup = AddGroup( SMDSAbs_All, it->c_str(), anId );
181     if ( aGroup ) {
182       if(MYDEBUG) MESSAGE("MEDToMesh - group added: "<<it->c_str());      
183       SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
184       if ( aGroupDS ) {
185         aGroupDS->SetStoreName( it->c_str() );
186         myReader.GetGroup( aGroupDS );
187       }
188     }
189   }
190   return (int) status;
191 }
192
193 //=======================================================================
194 //function : STLToMesh
195 //purpose  : 
196 //=======================================================================
197
198 int SMESH_Mesh::STLToMesh(const char* theFileName)
199 {
200   if(MYDEBUG) MESSAGE("UNVToMesh - theFileName = "<<theFileName);
201   if(_isShapeToMesh)
202     throw SALOME_Exception(LOCALIZED("a shape to mesh as already been defined"));
203   _isShapeToMesh = true;
204   DriverSTL_R_SMDS_Mesh myReader;
205   myReader.SetMesh(_myMeshDS);
206   myReader.SetFile(theFileName);
207   myReader.SetMeshId(-1);
208   myReader.Perform();
209   if(MYDEBUG){
210     MESSAGE("MEDToMesh - _myMeshDS->NbNodes() = "<<_myMeshDS->NbNodes());
211     MESSAGE("MEDToMesh - _myMeshDS->NbEdges() = "<<_myMeshDS->NbEdges());
212     MESSAGE("MEDToMesh - _myMeshDS->NbFaces() = "<<_myMeshDS->NbFaces());
213     MESSAGE("MEDToMesh - _myMeshDS->NbVolumes() = "<<_myMeshDS->NbVolumes());
214   }
215   return 1;
216 }
217
218 //=============================================================================
219 /*!
220  * 
221  */
222 //=============================================================================
223
224 SMESH_Hypothesis::Hypothesis_Status
225   SMESH_Mesh::AddHypothesis(const TopoDS_Shape & aSubShape,
226                             int                  anHypId  ) throw(SALOME_Exception)
227 {
228   Unexpect aCatch(SalomeException);
229   if(MYDEBUG) MESSAGE("SMESH_Mesh::AddHypothesis");
230
231   SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
232   SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
233   if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
234   {
235     // return the worst but not fatal state of all group memebers
236     SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
237     aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
238     aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
239     for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
240     {
241       ret = AddHypothesis( itS.Value(), anHypId );
242       if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
243         aWorstNotFatal = ret;
244       if ( ret < aBestRet )
245         aBestRet = ret;
246     }
247     if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
248       return aBestRet;
249     return aWorstNotFatal;
250   }
251
252   StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
253   if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
254   {
255     if(MYDEBUG) MESSAGE("Hypothesis ID does not give an hypothesis");
256     if(MYDEBUG) {
257       SCRUTE(_studyId);
258       SCRUTE(anHypId);
259     }
260     throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
261   }
262
263   SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
264   MESSAGE( "SMESH_Mesh::AddHypothesis " << anHyp->GetName() );
265
266   bool isGlobalHyp = IsMainShape( aSubShape );
267
268   // NotConformAllowed can be only global
269   if ( !isGlobalHyp )
270   {
271     string hypName = anHyp->GetName();
272     if ( hypName == "NotConformAllowed" )
273     {
274       if(MYDEBUG) MESSAGE( "Hypotesis <NotConformAllowed> can be only global" );
275       return SMESH_Hypothesis::HYP_INCOMPATIBLE;
276     }
277   }
278
279   // shape 
280
281   int event;
282   if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
283     event = SMESH_subMesh::ADD_HYP;
284   else
285     event = SMESH_subMesh::ADD_ALGO;
286   SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
287
288   // subShapes
289   if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
290       !subMesh->IsApplicableHypotesis( anHyp )) // is added on father
291   {
292     if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
293       event = SMESH_subMesh::ADD_FATHER_HYP;
294     else
295       event = SMESH_subMesh::ADD_FATHER_ALGO;
296     SMESH_Hypothesis::Hypothesis_Status ret2 =
297       subMesh->SubMeshesAlgoStateEngine(event, anHyp);
298     if (ret2 > ret)
299       ret = ret2;
300
301     // check concurent hypotheses on ansestors
302     if (ret < SMESH_Hypothesis::HYP_CONCURENT && !isGlobalHyp )
303     {
304       const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
305       map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
306       for ( ; smIt != smMap.end(); smIt++ ) {
307         if ( smIt->second->IsApplicableHypotesis( anHyp )) {
308           ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
309           if (ret2 > ret) {
310             ret = ret2;
311             break;
312           }
313         }
314       }
315     }
316   }
317
318   if(MYDEBUG) subMesh->DumpAlgoState(true);
319   SCRUTE(ret);
320   return ret;
321 }
322
323 //=============================================================================
324 /*!
325  * 
326  */
327 //=============================================================================
328
329 SMESH_Hypothesis::Hypothesis_Status
330   SMESH_Mesh::RemoveHypothesis(const TopoDS_Shape & aSubShape,
331                                int anHypId)throw(SALOME_Exception)
332 {
333   Unexpect aCatch(SalomeException);
334   if(MYDEBUG) MESSAGE("SMESH_Mesh::RemoveHypothesis");
335   
336   SMESH_subMesh *subMesh = GetSubMesh(aSubShape);
337   SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
338   if ( subMeshDS && subMeshDS->IsComplexSubmesh() )
339   {
340     // return the worst but not fatal state of all group memebers
341     SMESH_Hypothesis::Hypothesis_Status aBestRet, aWorstNotFatal, ret;
342     aBestRet = SMESH_Hypothesis::HYP_BAD_DIM;
343     aWorstNotFatal = SMESH_Hypothesis::HYP_OK;
344     for ( TopoDS_Iterator itS ( aSubShape ); itS.More(); itS.Next())
345     {
346       ret = RemoveHypothesis( itS.Value(), anHypId );
347       if ( !SMESH_Hypothesis::IsStatusFatal( ret ) && ret > aWorstNotFatal )
348         aWorstNotFatal = ret;
349       if ( ret < aBestRet )
350         aBestRet = ret;
351     }
352     if ( SMESH_Hypothesis::IsStatusFatal( aBestRet ))
353       return aBestRet;
354     return aWorstNotFatal;
355   }
356
357   StudyContextStruct *sc = _gen->GetStudyContext(_studyId);
358   if (sc->mapHypothesis.find(anHypId) == sc->mapHypothesis.end())
359     throw SALOME_Exception(LOCALIZED("hypothesis does not exist"));
360   
361   SMESH_Hypothesis *anHyp = sc->mapHypothesis[anHypId];
362   int hypType = anHyp->GetType();
363   if(MYDEBUG) SCRUTE(hypType);
364   int event;
365   
366   // shape 
367   
368   if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
369     event = SMESH_subMesh::REMOVE_HYP;
370   else
371     event = SMESH_subMesh::REMOVE_ALGO;
372   SMESH_Hypothesis::Hypothesis_Status ret = subMesh->AlgoStateEngine(event, anHyp);
373
374   // there may appear concurrent hyps that were covered by the removed hyp
375   if (ret < SMESH_Hypothesis::HYP_CONCURENT &&
376       subMesh->IsApplicableHypotesis( anHyp ) &&
377       subMesh->CheckConcurentHypothesis( anHyp->GetType() ) != SMESH_Hypothesis::HYP_OK)
378     ret = SMESH_Hypothesis::HYP_CONCURENT;
379
380   // subShapes
381   if (!SMESH_Hypothesis::IsStatusFatal(ret) &&
382       !subMesh->IsApplicableHypotesis( anHyp )) // is removed from father
383   {
384     if (anHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
385       event = SMESH_subMesh::REMOVE_FATHER_HYP;
386     else
387       event = SMESH_subMesh::REMOVE_FATHER_ALGO;
388     SMESH_Hypothesis::Hypothesis_Status ret2 =
389       subMesh->SubMeshesAlgoStateEngine(event, anHyp);
390     if (ret2 > ret) // more severe
391       ret = ret2;
392
393     // check concurent hypotheses on ansestors
394     if (ret < SMESH_Hypothesis::HYP_CONCURENT && !IsMainShape( aSubShape ) )
395     {
396       const map < int, SMESH_subMesh * >& smMap = subMesh->DependsOn();
397       map < int, SMESH_subMesh * >::const_iterator smIt = smMap.begin();
398       for ( ; smIt != smMap.end(); smIt++ ) {
399         if ( smIt->second->IsApplicableHypotesis( anHyp )) {
400           ret2 = smIt->second->CheckConcurentHypothesis( anHyp->GetType() );
401           if (ret2 > ret) {
402             ret = ret2;
403             break;
404           }
405         }
406       }
407     }
408   }
409   
410   if(MYDEBUG) subMesh->DumpAlgoState(true);
411   if(MYDEBUG) SCRUTE(ret);
412   return ret;
413 }
414
415 //=============================================================================
416 /*!
417  * 
418  */
419 //=============================================================================
420
421 SMESHDS_Mesh * SMESH_Mesh::GetMeshDS()
422 {
423   return _myMeshDS;
424 }
425
426 //=============================================================================
427 /*!
428  * 
429  */
430 //=============================================================================
431
432 const list<const SMESHDS_Hypothesis*>&
433 SMESH_Mesh::GetHypothesisList(const TopoDS_Shape & aSubShape) const
434   throw(SALOME_Exception)
435 {
436   Unexpect aCatch(SalomeException);
437   return _myMeshDS->GetHypothesis(aSubShape);
438 }
439
440 //=============================================================================
441 /*!
442  * 
443  */
444 //=============================================================================
445
446 const list<SMESHDS_Command*> & SMESH_Mesh::GetLog() throw(SALOME_Exception)
447 {
448   Unexpect aCatch(SalomeException);
449   if(MYDEBUG) MESSAGE("SMESH_Mesh::GetLog");
450   return _myMeshDS->GetScript()->GetCommands();
451 }
452
453 //=============================================================================
454 /*!
455  * 
456  */
457 //=============================================================================
458 void SMESH_Mesh::ClearLog() throw(SALOME_Exception)
459 {
460   Unexpect aCatch(SalomeException);
461   if(MYDEBUG) MESSAGE("SMESH_Mesh::ClearLog");
462   _myMeshDS->GetScript()->Clear();
463 }
464
465 //=============================================================================
466 /*!
467  * 
468  */
469 //=============================================================================
470
471 int SMESH_Mesh::GetId()
472 {
473   if(MYDEBUG) MESSAGE("SMESH_Mesh::GetId");
474   return _id;
475 }
476
477 //=============================================================================
478 /*!
479  * 
480  */
481 //=============================================================================
482
483 SMESH_Gen *SMESH_Mesh::GetGen()
484 {
485   return _gen;
486 }
487
488 //=============================================================================
489 /*!
490  * Get or Create the SMESH_subMesh object implementation
491  */
492 //=============================================================================
493
494 SMESH_subMesh *SMESH_Mesh::GetSubMesh(const TopoDS_Shape & aSubShape)
495 throw(SALOME_Exception)
496 {
497   Unexpect aCatch(SalomeException);
498   SMESH_subMesh *aSubMesh;
499   int index = _myMeshDS->ShapeToIndex(aSubShape);
500   
501   // for submeshes on GEOM Group
502   if ( !index && aSubShape.ShapeType() == TopAbs_COMPOUND ) {
503     TopoDS_Iterator it( aSubShape );
504     if ( it.More() )
505       index = _myMeshDS->AddCompoundSubmesh( aSubShape, it.Value().ShapeType() );
506   }
507
508   if (_mapSubMesh.find(index) != _mapSubMesh.end())
509     {
510       aSubMesh = _mapSubMesh[index];
511     }
512   else
513     {
514       aSubMesh = new SMESH_subMesh(index, this, _myMeshDS, aSubShape);
515       _mapSubMesh[index] = aSubMesh;
516     }
517   return aSubMesh;
518 }
519
520 //=============================================================================
521 /*!
522  * Get the SMESH_subMesh object implementation. Dont create it, return null
523  * if it does not exist.
524  */
525 //=============================================================================
526
527 SMESH_subMesh *SMESH_Mesh::GetSubMeshContaining(const TopoDS_Shape & aSubShape)
528 throw(SALOME_Exception)
529 {
530   Unexpect aCatch(SalomeException);
531   bool isFound = false;
532   SMESH_subMesh *aSubMesh = NULL;
533   
534   int index = _myMeshDS->ShapeToIndex(aSubShape);
535   if (_mapSubMesh.find(index) != _mapSubMesh.end())
536     {
537       aSubMesh = _mapSubMesh[index];
538       isFound = true;
539     }
540   if (!isFound)
541     aSubMesh = NULL;
542   return aSubMesh;
543 }
544
545 //=======================================================================
546 //function : IsUsedHypothesis
547 //purpose  : Return True if anHyp is used to mesh aSubShape
548 //=======================================================================
549
550 bool SMESH_Mesh::IsUsedHypothesis(SMESHDS_Hypothesis * anHyp,
551                                   const TopoDS_Shape & aSubShape)
552 {
553   // check if anHyp is applicable to aSubShape
554   SMESH_subMesh * subMesh = GetSubMeshContaining( aSubShape );
555   if (!subMesh ||
556       !subMesh->IsApplicableHypotesis(static_cast<SMESH_Hypothesis*>(anHyp)))
557     return false;
558
559   SMESH_Algo *algo = _gen->GetAlgo(*this, aSubShape);
560
561   // algorithm
562   if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO)
563     return ( anHyp == algo );
564
565   // algorithm parameter
566   if (algo)
567   {
568     // look trough hypotheses used by algo
569     const list <const SMESHDS_Hypothesis * >&usedHyps =
570       algo->GetUsedHypothesis(*this, aSubShape);
571     list <const SMESHDS_Hypothesis * >::const_iterator itl;
572     for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
573       if (anHyp == (*itl))
574         return true;
575   }
576   else
577   {
578     // look through all assigned hypotheses
579     {
580       const list <const SMESHDS_Hypothesis * >&usedHyps =
581         _myMeshDS->GetHypothesis( aSubShape );
582       list <const SMESHDS_Hypothesis * >::const_iterator itl;
583       for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
584         if (anHyp == (*itl))
585           return true;
586     }
587
588     // on ancestors
589     TopTools_ListIteratorOfListOfShape it( GetAncestors( aSubShape ));
590     for (; it.More(); it.Next())
591     {
592       const list <const SMESHDS_Hypothesis * >&usedHyps =
593         _myMeshDS->GetHypothesis( aSubShape );
594       list <const SMESHDS_Hypothesis * >::const_iterator itl;
595       for (itl = usedHyps.begin(); itl != usedHyps.end(); itl++)
596         if (anHyp == (*itl))
597           return true;
598     }
599   }
600     
601   return false;
602 }
603
604
605 //=============================================================================
606 /*!
607  *
608  */
609 //=============================================================================
610
611 const list < SMESH_subMesh * >&
612         SMESH_Mesh::GetSubMeshUsingHypothesis(SMESHDS_Hypothesis * anHyp)
613 throw(SALOME_Exception)
614 {
615   Unexpect aCatch(SalomeException);
616         if(MYDEBUG) MESSAGE("SMESH_Mesh::GetSubMeshUsingHypothesis");
617         map < int, SMESH_subMesh * >::iterator itsm;
618         _subMeshesUsingHypothesisList.clear();
619         for (itsm = _mapSubMesh.begin(); itsm != _mapSubMesh.end(); itsm++)
620         {
621                 SMESH_subMesh *aSubMesh = (*itsm).second;
622                 if ( IsUsedHypothesis ( anHyp, aSubMesh->GetSubShape() ))
623                         _subMeshesUsingHypothesisList.push_back(aSubMesh);
624         }
625         return _subMeshesUsingHypothesisList;
626 }
627
628 //=============================================================================
629 /*!
630  *
631  */
632 //=============================================================================
633
634 void SMESH_Mesh::ExportMED(const char *file, const char* theMeshName, bool theAutoGroups) throw(SALOME_Exception)
635 {
636   Unexpect aCatch(SalomeException);
637   DriverMED_W_SMESHDS_Mesh myWriter;
638   myWriter.SetFile    ( file        );
639   myWriter.SetMesh    ( _myMeshDS   );
640   if ( !theMeshName ) 
641     myWriter.SetMeshId  ( _idDoc      );
642   else {
643     myWriter.SetMeshId  ( -1          );
644     myWriter.SetMeshName( theMeshName );
645   }
646
647   if ( theAutoGroups ) {
648     myWriter.AddGroupOfNodes();
649     myWriter.AddGroupOfEdges();
650     myWriter.AddGroupOfFaces();
651     myWriter.AddGroupOfVolumes();
652   }
653
654   for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
655     SMESH_Group*       aGroup   = it->second;
656     SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
657     if ( aGroupDS ) {
658       aGroupDS->SetStoreName( aGroup->GetName() );
659       myWriter.AddGroup( aGroupDS );
660     }
661   }
662
663   myWriter.Perform();
664 }
665
666 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
667 {
668   Unexpect aCatch(SalomeException);
669   DriverDAT_W_SMDS_Mesh myWriter;
670   myWriter.SetFile(string(file));
671   myWriter.SetMesh(_myMeshDS);
672   myWriter.SetMeshId(_idDoc);
673   myWriter.Perform();
674 }
675
676 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
677 {
678   Unexpect aCatch(SalomeException);
679   DriverUNV_W_SMDS_Mesh myWriter;
680   myWriter.SetFile(string(file));
681   myWriter.SetMesh(_myMeshDS);
682   myWriter.SetMeshId(_idDoc);
683   myWriter.Perform();
684 }
685
686 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
687 {
688   Unexpect aCatch(SalomeException);
689   DriverSTL_W_SMDS_Mesh myWriter;
690   myWriter.SetFile(string(file));
691   myWriter.SetIsAscii( isascii );
692   myWriter.SetMesh(_myMeshDS);
693   myWriter.SetMeshId(_idDoc);
694   myWriter.Perform();
695 }
696
697 //=============================================================================
698 /*!
699  *  
700  */
701 //=============================================================================
702 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
703 {
704   Unexpect aCatch(SalomeException);
705   return _myMeshDS->NbNodes();
706 }
707
708 //=============================================================================
709 /*!
710  *  
711  */
712 //=============================================================================
713 int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
714 {
715   Unexpect aCatch(SalomeException);
716   return _myMeshDS->NbEdges();
717 }
718
719 //=============================================================================
720 /*!
721  *  
722  */
723 //=============================================================================
724 int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
725 {
726   Unexpect aCatch(SalomeException);
727   return _myMeshDS->NbFaces();
728 }
729
730 ///////////////////////////////////////////////////////////////////////////////
731 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
732 ///////////////////////////////////////////////////////////////////////////////
733 int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
734 {
735   Unexpect aCatch(SalomeException);
736   int Nb = 0;
737   
738   SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
739   while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
740   return Nb;
741 }
742
743 ///////////////////////////////////////////////////////////////////////////////
744 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
745 ///////////////////////////////////////////////////////////////////////////////
746 int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
747 {
748   Unexpect aCatch(SalomeException);
749   int Nb = 0;
750   
751   SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
752   while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
753   return Nb;
754 }
755
756 //=============================================================================
757 /*!
758  *  
759  */
760 //=============================================================================
761 int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
762 {
763   Unexpect aCatch(SalomeException);
764   return _myMeshDS->NbVolumes();
765 }
766
767 int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
768 {
769   Unexpect aCatch(SalomeException);
770   int Nb = 0;
771   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
772   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
773   return Nb;
774 }
775
776 int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
777 {
778   Unexpect aCatch(SalomeException);
779   int Nb = 0;
780   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
781   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
782   return Nb;
783 }
784
785 int SMESH_Mesh::NbPyramids() throw(SALOME_Exception)
786 {
787   Unexpect aCatch(SalomeException);
788   int Nb = 0;
789   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
790   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++;
791   return Nb;
792 }
793
794 int SMESH_Mesh::NbPrisms() throw(SALOME_Exception)
795 {
796   Unexpect aCatch(SalomeException);
797   int Nb = 0;
798   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
799   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++;
800   return Nb;
801 }
802
803 //=============================================================================
804 /*!
805  *  
806  */
807 //=============================================================================
808 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
809 {
810   Unexpect aCatch(SalomeException);
811   return _myMeshDS->NbSubMesh();
812 }
813
814 //=======================================================================
815 //function : IsNotConformAllowed
816 //purpose  : check if a hypothesis alowing notconform mesh is present
817 //=======================================================================
818
819 bool SMESH_Mesh::IsNotConformAllowed() const
820 {
821   if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
822
823   const list<const SMESHDS_Hypothesis*>& listHyp =
824     _myMeshDS->GetHypothesis( _myMeshDS->ShapeToMesh() );
825   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
826   while (it!=listHyp.end())
827   {
828     const SMESHDS_Hypothesis *aHyp = *it;
829     string hypName = aHyp->GetName();
830     if ( hypName == "NotConformAllowed" )
831       return true;
832     it++;
833   }
834   return false;
835 }
836
837 //=======================================================================
838 //function : IsMainShape
839 //purpose  : 
840 //=======================================================================
841
842 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
843 {
844   return theShape.IsSame(_myMeshDS->ShapeToMesh() );
845 }
846
847 //=============================================================================
848 /*!
849  *  
850  */
851 //=============================================================================
852
853 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
854                                    const char*               theName,
855                                    int&                      theId,
856                                    const TopoDS_Shape&       theShape)
857 {
858   if (_mapGroup.find(_groupId) != _mapGroup.end())
859     return NULL;
860   theId = _groupId;
861   SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
862   GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
863   _mapGroup[_groupId++] = aGroup;
864   return aGroup;
865 }
866
867 //=============================================================================
868 /*!
869  *  
870  */
871 //=============================================================================
872
873 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
874 {
875   if (_mapGroup.find(theGroupID) == _mapGroup.end())
876     return NULL;
877   return _mapGroup[theGroupID];
878 }
879
880
881 //=============================================================================
882 /*!
883  *  
884  */
885 //=============================================================================
886
887 list<int> SMESH_Mesh::GetGroupIds()
888 {
889   list<int> anIds;
890   for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
891     anIds.push_back( it->first );
892   
893   return anIds;
894 }
895
896
897 //=============================================================================
898 /*!
899  *  
900  */
901 //=============================================================================
902
903 void SMESH_Mesh::RemoveGroup (const int theGroupID)
904 {
905   if (_mapGroup.find(theGroupID) == _mapGroup.end())
906     return;
907   GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
908   _mapGroup.erase (theGroupID);
909   delete _mapGroup[theGroupID];
910 }
911
912 //=============================================================================
913 /*!
914  *  IsLocal1DHypothesis
915  *  Check, if there is 1D hypothesis assigned directly on <theEdge>
916  */
917 //=============================================================================
918 bool SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
919 {
920   const SMESHDS_Mesh* meshDS = GetMeshDS();
921   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis(theEdge);
922   list<const SMESHDS_Hypothesis*>::const_iterator it = listHyp.begin();
923
924   for (; it != listHyp.end(); it++) {
925     const SMESH_Hypothesis * aHyp = static_cast<const SMESH_Hypothesis*>(*it);
926     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO &&
927         aHyp->GetDim() == 1) { // 1D Hypothesis found
928       return true;
929     }
930   }
931   return false;
932 }
933
934 //=============================================================================
935 /*!
936  *  IsPropagationHypothesis
937  */
938 //=============================================================================
939 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
940 {
941   return _mapPropagationChains.Contains(theEdge);
942 }
943
944 //=============================================================================
945 /*!
946  *  IsPropagatedHypothesis
947  */
948 //=============================================================================
949 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
950                                          TopoDS_Shape&       theMainEdge)
951 {
952   int nbChains = _mapPropagationChains.Extent();
953   for (int i = 1; i <= nbChains; i++) {
954     const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
955     if (aChain.Contains(theEdge)) {
956       theMainEdge = _mapPropagationChains.FindKey(i);
957       return true;
958     }
959   }
960
961   return false;
962 }
963
964 //=============================================================================
965 /*!
966  *  CleanMeshOnPropagationChain
967  */
968 //=============================================================================
969 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
970 {
971   const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
972   int i, nbEdges = aChain.Extent();
973   for (i = 1; i <= nbEdges; i++) {
974     TopoDS_Shape anEdge = aChain.FindKey(i);
975     SMESH_subMesh *subMesh = GetSubMesh(anEdge);
976     SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
977     if (subMeshDS && subMeshDS->NbElements() > 0) {
978       subMesh->ComputeStateEngine(SMESH_subMesh::CLEANDEP);
979     }
980   }
981 }
982
983 //=============================================================================
984 /*!
985  *  RebuildPropagationChains
986  *  Rebuild all existing propagation chains.
987  *  Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
988  */
989 //=============================================================================
990 bool SMESH_Mesh::RebuildPropagationChains()
991 {
992   bool ret = true;
993
994   // Clean all chains, because they can be not up-to-date
995   int i, nbChains = _mapPropagationChains.Extent();
996   for (i = 1; i <= nbChains; i++) {
997     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
998     CleanMeshOnPropagationChain(aMainEdge);
999     _mapPropagationChains.ChangeFromIndex(i).Clear();
1000   }
1001
1002   // Build all chains
1003   for (i = 1; i <= nbChains; i++) {
1004     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1005     if (!BuildPropagationChain(aMainEdge))
1006       ret = false;
1007     CleanMeshOnPropagationChain(aMainEdge);
1008   }
1009
1010   return ret;
1011 }
1012
1013 //=============================================================================
1014 /*!
1015  *  RemovePropagationChain
1016  *  Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1017  */
1018 //=============================================================================
1019 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1020 {
1021   if (!_mapPropagationChains.Contains(theMainEdge))
1022     return false;
1023
1024   // Clean mesh elements and nodes, built on the chain
1025   CleanMeshOnPropagationChain(theMainEdge);
1026
1027   // Clean the chain
1028   _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1029
1030   // Remove the chain from the map
1031   int i = _mapPropagationChains.FindIndex(theMainEdge);
1032   TopoDS_Vertex anEmptyShape;
1033   BRep_Builder BB;
1034   BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1035   TopTools_IndexedMapOfShape anEmptyMap;
1036   _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1037
1038   return true;
1039 }
1040
1041 //=============================================================================
1042 /*!
1043  *  BuildPropagationChain
1044  */
1045 //=============================================================================
1046 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1047 {
1048   if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1049
1050   // Add new chain, if there is no
1051   if (!_mapPropagationChains.Contains(theMainEdge)) {
1052     TopTools_IndexedMapOfShape aNewChain;
1053     _mapPropagationChains.Add(theMainEdge, aNewChain);
1054   }
1055
1056   // Check presence of 1D hypothesis to be propagated
1057   if (!IsLocal1DHypothesis(theMainEdge)) {
1058     MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1059     return true;
1060   }
1061
1062   // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1063   TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1064   if (aChain.Extent() > 0) {
1065     CleanMeshOnPropagationChain(theMainEdge);
1066     aChain.Clear();
1067   }
1068
1069   // At first put <theMainEdge> in the chain
1070   aChain.Add(theMainEdge);
1071
1072   // List of edges, added to chain on the previous cycle pass
1073   TopTools_ListOfShape listPrevEdges;
1074   listPrevEdges.Append(theMainEdge);
1075
1076 //   5____4____3____4____5____6
1077 //   |    |    |    |    |    |
1078 //   |    |    |    |    |    |
1079 //   4____3____2____3____4____5
1080 //   |    |    |    |    |    |      Number in the each knot of
1081 //   |    |    |    |    |    |      grid indicates cycle pass,
1082 //   3____2____1____2____3____4      on which corresponding edge
1083 //   |    |    |    |    |    |      (perpendicular to the plane
1084 //   |    |    |    |    |    |      of view) will be found.
1085 //   2____1____0____1____2____3
1086 //   |    |    |    |    |    |
1087 //   |    |    |    |    |    |
1088 //   3____2____1____2____3____4
1089
1090   // Collect all edges pass by pass
1091   while (listPrevEdges.Extent() > 0) {
1092     // List of edges, added to chain on this cycle pass
1093     TopTools_ListOfShape listCurEdges;
1094
1095     // Find the next portion of edges
1096     TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1097     for (; itE.More(); itE.Next()) {
1098       TopoDS_Shape anE = itE.Value();
1099
1100       // Iterate on faces, having edge <anE>
1101       TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1102       for (; itA.More(); itA.Next()) {
1103         TopoDS_Shape aW = itA.Value();
1104
1105         // There are objects of different type among the ancestors of edge
1106         if (aW.ShapeType() == TopAbs_WIRE) {
1107           TopoDS_Shape anOppE;
1108
1109           BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1110           Standard_Integer nb = 1, found = 0;
1111           TopTools_Array1OfShape anEdges (1,4);
1112           for (; aWE.More(); aWE.Next(), nb++) {
1113             if (nb > 4) {
1114               found = 0;
1115               break;
1116             }
1117             anEdges(nb) = aWE.Current();
1118             if (!_mapAncestors.Contains(anEdges(nb))) {
1119               MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1120               break;
1121             } else {
1122               int ind = _mapAncestors.FindIndex(anEdges(nb));
1123               anEdges(nb) = _mapAncestors.FindKey(ind);
1124             }
1125             if (anEdges(nb).IsSame(anE)) found = nb;
1126           }
1127
1128           if (nb == 5 && found > 0) {
1129             // Quadrangle face found, get an opposite edge
1130             Standard_Integer opp = found + 2;
1131             if (opp > 4) opp -= 4;
1132             anOppE = anEdges(opp);
1133
1134             if (!aChain.Contains(anOppE)) {
1135               if (!IsLocal1DHypothesis(anOppE)) {
1136                 TopoDS_Shape aMainEdgeForOppEdge;
1137                 if (IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge)) {
1138                   // Collision!
1139                   MESSAGE("Error: Collision between propagated hypotheses");
1140                   CleanMeshOnPropagationChain(theMainEdge);
1141                   aChain.Clear();
1142                   return false;
1143                 } else {
1144                   // Add found edge to the chain
1145                   aChain.Add(anOppE);
1146                   listCurEdges.Append(anOppE);
1147                 }
1148               }
1149             }
1150           } // if (nb == 5 && found > 0)
1151         } // if (aF.ShapeType() == TopAbs_WIRE)
1152       } // for (; itF.More(); itF.Next())
1153     } // for (; itE.More(); itE.Next())
1154
1155     listPrevEdges = listCurEdges;
1156   } // while (listPrevEdges.Extent() > 0)
1157
1158   CleanMeshOnPropagationChain(theMainEdge);
1159   return true;
1160 }
1161
1162 //=======================================================================
1163 //function : GetAncestors
1164 //purpose  : return list of ancestors of theSubShape in the order
1165 //           that lower dimention shapes come first.
1166 //=======================================================================
1167
1168 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS)
1169 {
1170   if ( _mapAncestors.IsEmpty() )
1171   {
1172     // fill _mapAncestors
1173     int desType, ancType;
1174     for ( desType = TopAbs_EDGE; desType > TopAbs_COMPOUND; desType-- )
1175       for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1176         TopExp::MapShapesAndAncestors (_myMeshDS->ShapeToMesh(),
1177                                        (TopAbs_ShapeEnum) desType,
1178                                        (TopAbs_ShapeEnum) ancType,
1179                                        _mapAncestors );
1180   }
1181
1182   if ( _mapAncestors.Contains( theS ) )
1183     return _mapAncestors.FindFromKey( theS );
1184
1185   static TopTools_ListOfShape emptyList;
1186   return emptyList;
1187 }
1188
1189 //=======================================================================
1190 //function : Dump
1191 //purpose  : dumps contents of mesh to stream [ debug purposes ]
1192 //=======================================================================
1193 ostream& SMESH_Mesh::Dump(ostream& save)
1194 {
1195   save << "========================== Dump contents of mesh ==========================" << endl;
1196   save << "1) Total number of nodes:     " << NbNodes() << endl;
1197   save << "2) Total number of edges:     " << NbEdges() << endl;
1198   save << "3) Total number of faces:     " << NbFaces() << endl;
1199   if ( NbFaces() > 0 ) {
1200     int nb3 = NbTriangles();
1201     int nb4 = NbQuadrangles();
1202     save << "3.1.) Number of triangles:    " << nb3 << endl;
1203     save << "3.2.) Number of quadrangles:  " << nb4 << endl;
1204     if ( nb3 + nb4 !=  NbFaces() ) {
1205       map<int,int> myFaceMap;
1206       SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1207       while( itFaces->more( ) ) {
1208         int nbNodes = itFaces->next()->NbNodes();
1209         if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1210           myFaceMap[ nbNodes ] = 0;
1211         myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1212       }
1213       save << "3.3.) Faces in detail: " << endl;
1214       map <int,int>::iterator itF;
1215       for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1216         save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
1217     }
1218   }
1219   save << "4) Total number of volumes:   " << NbVolumes() << endl;
1220   if ( NbVolumes() > 0 ) {
1221     int nb8 = NbHexas();
1222     int nb4 = NbTetras();
1223     int nb5 = NbPyramids();
1224     int nb6 = NbPrisms();
1225     save << "4.1.) Number of hexahedrons:  " << nb8 << endl;
1226     save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
1227     save << "4.3.) Number of prisms:       " << nb6 << endl;
1228     save << "4.4.) Number of pyramides:    " << nb5 << endl;
1229     if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
1230       map<int,int> myVolumesMap;
1231       SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1232       while( itVolumes->more( ) ) {
1233         int nbNodes = itVolumes->next()->NbNodes();
1234         if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1235           myVolumesMap[ nbNodes ] = 0;
1236         myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1237       }
1238       save << "4.5.) Volumes in detail: " << endl;
1239       map <int,int>::iterator itV;
1240       for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1241         save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
1242     }
1243   }
1244   save << "===========================================================================" << endl;
1245   return save;
1246 }