Salome HOME
Merge with OCC_development_01
[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, 
635                            const char* theMeshName, 
636                            bool theAutoGroups,
637                            int theVersion) 
638   throw(SALOME_Exception)
639 {
640   Unexpect aCatch(SalomeException);
641   DriverMED_W_SMESHDS_Mesh myWriter;
642   myWriter.SetFile    ( file, MED::EVersion(theVersion) );
643   myWriter.SetMesh    ( _myMeshDS   );
644   if ( !theMeshName ) 
645     myWriter.SetMeshId  ( _idDoc      );
646   else {
647     myWriter.SetMeshId  ( -1          );
648     myWriter.SetMeshName( theMeshName );
649   }
650
651   if ( theAutoGroups ) {
652     myWriter.AddGroupOfNodes();
653     myWriter.AddGroupOfEdges();
654     myWriter.AddGroupOfFaces();
655     myWriter.AddGroupOfVolumes();
656   }
657
658   for ( map<int, SMESH_Group*>::iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ ) {
659     SMESH_Group*       aGroup   = it->second;
660     SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
661     if ( aGroupDS ) {
662       aGroupDS->SetStoreName( aGroup->GetName() );
663       myWriter.AddGroup( aGroupDS );
664     }
665   }
666
667   myWriter.Perform();
668 }
669
670 void SMESH_Mesh::ExportDAT(const char *file) throw(SALOME_Exception)
671 {
672   Unexpect aCatch(SalomeException);
673   DriverDAT_W_SMDS_Mesh myWriter;
674   myWriter.SetFile(string(file));
675   myWriter.SetMesh(_myMeshDS);
676   myWriter.SetMeshId(_idDoc);
677   myWriter.Perform();
678 }
679
680 void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
681 {
682   Unexpect aCatch(SalomeException);
683   DriverUNV_W_SMDS_Mesh myWriter;
684   myWriter.SetFile(string(file));
685   myWriter.SetMesh(_myMeshDS);
686   myWriter.SetMeshId(_idDoc);
687   myWriter.Perform();
688 }
689
690 void SMESH_Mesh::ExportSTL(const char *file, const bool isascii) throw(SALOME_Exception)
691 {
692   Unexpect aCatch(SalomeException);
693   DriverSTL_W_SMDS_Mesh myWriter;
694   myWriter.SetFile(string(file));
695   myWriter.SetIsAscii( isascii );
696   myWriter.SetMesh(_myMeshDS);
697   myWriter.SetMeshId(_idDoc);
698   myWriter.Perform();
699 }
700
701 //=============================================================================
702 /*!
703  *  
704  */
705 //=============================================================================
706 int SMESH_Mesh::NbNodes() throw(SALOME_Exception)
707 {
708   Unexpect aCatch(SalomeException);
709   return _myMeshDS->NbNodes();
710 }
711
712 //=============================================================================
713 /*!
714  *  
715  */
716 //=============================================================================
717 int SMESH_Mesh::NbEdges() throw(SALOME_Exception)
718 {
719   Unexpect aCatch(SalomeException);
720   return _myMeshDS->NbEdges();
721 }
722
723 //=============================================================================
724 /*!
725  *  
726  */
727 //=============================================================================
728 int SMESH_Mesh::NbFaces() throw(SALOME_Exception)
729 {
730   Unexpect aCatch(SalomeException);
731   return _myMeshDS->NbFaces();
732 }
733
734 ///////////////////////////////////////////////////////////////////////////////
735 /// Return the number of 3 nodes faces in the mesh. This method run in O(n)
736 ///////////////////////////////////////////////////////////////////////////////
737 int SMESH_Mesh::NbTriangles() throw(SALOME_Exception)
738 {
739   Unexpect aCatch(SalomeException);
740   int Nb = 0;
741   
742   SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
743   while(itFaces->more()) if(itFaces->next()->NbNodes()==3) Nb++;
744   return Nb;
745 }
746
747 ///////////////////////////////////////////////////////////////////////////////
748 /// Return the number of 4 nodes faces in the mesh. This method run in O(n)
749 ///////////////////////////////////////////////////////////////////////////////
750 int SMESH_Mesh::NbQuadrangles() throw(SALOME_Exception)
751 {
752   Unexpect aCatch(SalomeException);
753   int Nb = 0;
754   
755   SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
756   while(itFaces->more()) if(itFaces->next()->NbNodes()==4) Nb++;
757   return Nb;
758 }
759
760 //=============================================================================
761 /*!
762  *  
763  */
764 //=============================================================================
765 int SMESH_Mesh::NbVolumes() throw(SALOME_Exception)
766 {
767   Unexpect aCatch(SalomeException);
768   return _myMeshDS->NbVolumes();
769 }
770
771 int SMESH_Mesh::NbTetras() throw(SALOME_Exception)
772 {
773   Unexpect aCatch(SalomeException);
774   int Nb = 0;
775   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
776   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==4) Nb++;
777   return Nb;
778 }
779
780 int SMESH_Mesh::NbHexas() throw(SALOME_Exception)
781 {
782   Unexpect aCatch(SalomeException);
783   int Nb = 0;
784   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
785   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==8) Nb++;
786   return Nb;
787 }
788
789 int SMESH_Mesh::NbPyramids() throw(SALOME_Exception)
790 {
791   Unexpect aCatch(SalomeException);
792   int Nb = 0;
793   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
794   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==5) Nb++;
795   return Nb;
796 }
797
798 int SMESH_Mesh::NbPrisms() throw(SALOME_Exception)
799 {
800   Unexpect aCatch(SalomeException);
801   int Nb = 0;
802   SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
803   while(itVolumes->more()) if(itVolumes->next()->NbNodes()==6) Nb++;
804   return Nb;
805 }
806
807 //=============================================================================
808 /*!
809  *  
810  */
811 //=============================================================================
812 int SMESH_Mesh::NbSubMesh() throw(SALOME_Exception)
813 {
814   Unexpect aCatch(SalomeException);
815   return _myMeshDS->NbSubMesh();
816 }
817
818 //=======================================================================
819 //function : IsNotConformAllowed
820 //purpose  : check if a hypothesis alowing notconform mesh is present
821 //=======================================================================
822
823 bool SMESH_Mesh::IsNotConformAllowed() const
824 {
825   if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
826
827   const list<const SMESHDS_Hypothesis*>& listHyp =
828     _myMeshDS->GetHypothesis( _myMeshDS->ShapeToMesh() );
829   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
830   while (it!=listHyp.end())
831   {
832     const SMESHDS_Hypothesis *aHyp = *it;
833     string hypName = aHyp->GetName();
834     if ( hypName == "NotConformAllowed" )
835       return true;
836     it++;
837   }
838   return false;
839 }
840
841 //=======================================================================
842 //function : IsMainShape
843 //purpose  : 
844 //=======================================================================
845
846 bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
847 {
848   return theShape.IsSame(_myMeshDS->ShapeToMesh() );
849 }
850
851 //=============================================================================
852 /*!
853  *  
854  */
855 //=============================================================================
856
857 SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
858                                    const char*               theName,
859                                    int&                      theId,
860                                    const TopoDS_Shape&       theShape)
861 {
862   if (_mapGroup.find(_groupId) != _mapGroup.end())
863     return NULL;
864   theId = _groupId;
865   SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape);
866   GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
867   _mapGroup[_groupId++] = aGroup;
868   return aGroup;
869 }
870
871 //=============================================================================
872 /*!
873  *  
874  */
875 //=============================================================================
876
877 SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
878 {
879   if (_mapGroup.find(theGroupID) == _mapGroup.end())
880     return NULL;
881   return _mapGroup[theGroupID];
882 }
883
884
885 //=============================================================================
886 /*!
887  *  
888  */
889 //=============================================================================
890
891 list<int> SMESH_Mesh::GetGroupIds()
892 {
893   list<int> anIds;
894   for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
895     anIds.push_back( it->first );
896   
897   return anIds;
898 }
899
900
901 //=============================================================================
902 /*!
903  *  
904  */
905 //=============================================================================
906
907 void SMESH_Mesh::RemoveGroup (const int theGroupID)
908 {
909   if (_mapGroup.find(theGroupID) == _mapGroup.end())
910     return;
911   GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
912   _mapGroup.erase (theGroupID);
913   delete _mapGroup[theGroupID];
914 }
915
916 //=============================================================================
917 /*!
918  *  IsLocal1DHypothesis
919  *  Check, if there is 1D hypothesis assigned directly on <theEdge>
920  */
921 //=============================================================================
922 bool SMESH_Mesh::IsLocal1DHypothesis (const TopoDS_Shape& theEdge)
923 {
924   const SMESHDS_Mesh* meshDS = GetMeshDS();
925   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis(theEdge);
926   list<const SMESHDS_Hypothesis*>::const_iterator it = listHyp.begin();
927
928   for (; it != listHyp.end(); it++) {
929     const SMESH_Hypothesis * aHyp = static_cast<const SMESH_Hypothesis*>(*it);
930     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO &&
931         aHyp->GetDim() == 1) { // 1D Hypothesis found
932       return true;
933     }
934   }
935   return false;
936 }
937
938 //=============================================================================
939 /*!
940  *  IsPropagationHypothesis
941  */
942 //=============================================================================
943 bool SMESH_Mesh::IsPropagationHypothesis (const TopoDS_Shape& theEdge)
944 {
945   return _mapPropagationChains.Contains(theEdge);
946 }
947
948 //=============================================================================
949 /*!
950  *  IsPropagatedHypothesis
951  */
952 //=============================================================================
953 bool SMESH_Mesh::IsPropagatedHypothesis (const TopoDS_Shape& theEdge,
954                                          TopoDS_Shape&       theMainEdge)
955 {
956   int nbChains = _mapPropagationChains.Extent();
957   for (int i = 1; i <= nbChains; i++) {
958     const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromIndex(i);
959     if (aChain.Contains(theEdge)) {
960       theMainEdge = _mapPropagationChains.FindKey(i);
961       return true;
962     }
963   }
964
965   return false;
966 }
967
968 //=============================================================================
969 /*!
970  *  CleanMeshOnPropagationChain
971  */
972 //=============================================================================
973 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
974 {
975   const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
976   int i, nbEdges = aChain.Extent();
977   for (i = 1; i <= nbEdges; i++) {
978     TopoDS_Shape anEdge = aChain.FindKey(i);
979     SMESH_subMesh *subMesh = GetSubMesh(anEdge);
980     SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
981     if (subMeshDS && subMeshDS->NbElements() > 0) {
982       subMesh->ComputeStateEngine(SMESH_subMesh::CLEANDEP);
983     }
984   }
985 }
986
987 //=============================================================================
988 /*!
989  *  RebuildPropagationChains
990  *  Rebuild all existing propagation chains.
991  *  Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
992  */
993 //=============================================================================
994 bool SMESH_Mesh::RebuildPropagationChains()
995 {
996   bool ret = true;
997
998   // Clean all chains, because they can be not up-to-date
999   int i, nbChains = _mapPropagationChains.Extent();
1000   for (i = 1; i <= nbChains; i++) {
1001     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1002     CleanMeshOnPropagationChain(aMainEdge);
1003     _mapPropagationChains.ChangeFromIndex(i).Clear();
1004   }
1005
1006   // Build all chains
1007   for (i = 1; i <= nbChains; i++) {
1008     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1009     if (!BuildPropagationChain(aMainEdge))
1010       ret = false;
1011     CleanMeshOnPropagationChain(aMainEdge);
1012   }
1013
1014   return ret;
1015 }
1016
1017 //=============================================================================
1018 /*!
1019  *  RemovePropagationChain
1020  *  Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1021  */
1022 //=============================================================================
1023 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1024 {
1025   if (!_mapPropagationChains.Contains(theMainEdge))
1026     return false;
1027
1028   // Clean mesh elements and nodes, built on the chain
1029   CleanMeshOnPropagationChain(theMainEdge);
1030
1031   // Clean the chain
1032   _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1033
1034   // Remove the chain from the map
1035   int i = _mapPropagationChains.FindIndex(theMainEdge);
1036   TopoDS_Vertex anEmptyShape;
1037   BRep_Builder BB;
1038   BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1039   TopTools_IndexedMapOfShape anEmptyMap;
1040   _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1041
1042   return true;
1043 }
1044
1045 //=============================================================================
1046 /*!
1047  *  BuildPropagationChain
1048  */
1049 //=============================================================================
1050 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1051 {
1052   if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1053
1054   // Add new chain, if there is no
1055   if (!_mapPropagationChains.Contains(theMainEdge)) {
1056     TopTools_IndexedMapOfShape aNewChain;
1057     _mapPropagationChains.Add(theMainEdge, aNewChain);
1058   }
1059
1060   // Check presence of 1D hypothesis to be propagated
1061   if (!IsLocal1DHypothesis(theMainEdge)) {
1062     MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1063     return true;
1064   }
1065
1066   // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1067   TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1068   if (aChain.Extent() > 0) {
1069     CleanMeshOnPropagationChain(theMainEdge);
1070     aChain.Clear();
1071   }
1072
1073   // At first put <theMainEdge> in the chain
1074   aChain.Add(theMainEdge);
1075
1076   // List of edges, added to chain on the previous cycle pass
1077   TopTools_ListOfShape listPrevEdges;
1078   listPrevEdges.Append(theMainEdge);
1079
1080 //   5____4____3____4____5____6
1081 //   |    |    |    |    |    |
1082 //   |    |    |    |    |    |
1083 //   4____3____2____3____4____5
1084 //   |    |    |    |    |    |      Number in the each knot of
1085 //   |    |    |    |    |    |      grid indicates cycle pass,
1086 //   3____2____1____2____3____4      on which corresponding edge
1087 //   |    |    |    |    |    |      (perpendicular to the plane
1088 //   |    |    |    |    |    |      of view) will be found.
1089 //   2____1____0____1____2____3
1090 //   |    |    |    |    |    |
1091 //   |    |    |    |    |    |
1092 //   3____2____1____2____3____4
1093
1094   // Collect all edges pass by pass
1095   while (listPrevEdges.Extent() > 0) {
1096     // List of edges, added to chain on this cycle pass
1097     TopTools_ListOfShape listCurEdges;
1098
1099     // Find the next portion of edges
1100     TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1101     for (; itE.More(); itE.Next()) {
1102       TopoDS_Shape anE = itE.Value();
1103
1104       // Iterate on faces, having edge <anE>
1105       TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1106       for (; itA.More(); itA.Next()) {
1107         TopoDS_Shape aW = itA.Value();
1108
1109         // There are objects of different type among the ancestors of edge
1110         if (aW.ShapeType() == TopAbs_WIRE) {
1111           TopoDS_Shape anOppE;
1112
1113           BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1114           Standard_Integer nb = 1, found = 0;
1115           TopTools_Array1OfShape anEdges (1,4);
1116           for (; aWE.More(); aWE.Next(), nb++) {
1117             if (nb > 4) {
1118               found = 0;
1119               break;
1120             }
1121             anEdges(nb) = aWE.Current();
1122             if (!_mapAncestors.Contains(anEdges(nb))) {
1123               MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1124               break;
1125             } else {
1126               int ind = _mapAncestors.FindIndex(anEdges(nb));
1127               anEdges(nb) = _mapAncestors.FindKey(ind);
1128             }
1129             if (anEdges(nb).IsSame(anE)) found = nb;
1130           }
1131
1132           if (nb == 5 && found > 0) {
1133             // Quadrangle face found, get an opposite edge
1134             Standard_Integer opp = found + 2;
1135             if (opp > 4) opp -= 4;
1136             anOppE = anEdges(opp);
1137
1138             if (!aChain.Contains(anOppE)) {
1139               if (!IsLocal1DHypothesis(anOppE)) {
1140                 TopoDS_Shape aMainEdgeForOppEdge;
1141                 if (IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge)) {
1142                   // Collision!
1143                   MESSAGE("Error: Collision between propagated hypotheses");
1144                   CleanMeshOnPropagationChain(theMainEdge);
1145                   aChain.Clear();
1146                   return false;
1147                 } else {
1148                   // Add found edge to the chain
1149                   aChain.Add(anOppE);
1150                   listCurEdges.Append(anOppE);
1151                 }
1152               }
1153             }
1154           } // if (nb == 5 && found > 0)
1155         } // if (aF.ShapeType() == TopAbs_WIRE)
1156       } // for (; itF.More(); itF.Next())
1157     } // for (; itE.More(); itE.Next())
1158
1159     listPrevEdges = listCurEdges;
1160   } // while (listPrevEdges.Extent() > 0)
1161
1162   CleanMeshOnPropagationChain(theMainEdge);
1163   return true;
1164 }
1165
1166 //=======================================================================
1167 //function : GetAncestors
1168 //purpose  : return list of ancestors of theSubShape in the order
1169 //           that lower dimention shapes come first.
1170 //=======================================================================
1171
1172 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS)
1173 {
1174   if ( _mapAncestors.IsEmpty() )
1175   {
1176     // fill _mapAncestors
1177     int desType, ancType;
1178     for ( desType = TopAbs_EDGE; desType > TopAbs_COMPOUND; desType-- )
1179       for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1180         TopExp::MapShapesAndAncestors (_myMeshDS->ShapeToMesh(),
1181                                        (TopAbs_ShapeEnum) desType,
1182                                        (TopAbs_ShapeEnum) ancType,
1183                                        _mapAncestors );
1184   }
1185
1186   if ( _mapAncestors.Contains( theS ) )
1187     return _mapAncestors.FindFromKey( theS );
1188
1189   static TopTools_ListOfShape emptyList;
1190   return emptyList;
1191 }
1192
1193 //=======================================================================
1194 //function : Dump
1195 //purpose  : dumps contents of mesh to stream [ debug purposes ]
1196 //=======================================================================
1197 ostream& SMESH_Mesh::Dump(ostream& save)
1198 {
1199   save << "========================== Dump contents of mesh ==========================" << endl;
1200   save << "1) Total number of nodes:     " << NbNodes() << endl;
1201   save << "2) Total number of edges:     " << NbEdges() << endl;
1202   save << "3) Total number of faces:     " << NbFaces() << endl;
1203   if ( NbFaces() > 0 ) {
1204     int nb3 = NbTriangles();
1205     int nb4 = NbQuadrangles();
1206     save << "3.1.) Number of triangles:    " << nb3 << endl;
1207     save << "3.2.) Number of quadrangles:  " << nb4 << endl;
1208     if ( nb3 + nb4 !=  NbFaces() ) {
1209       map<int,int> myFaceMap;
1210       SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1211       while( itFaces->more( ) ) {
1212         int nbNodes = itFaces->next()->NbNodes();
1213         if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1214           myFaceMap[ nbNodes ] = 0;
1215         myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1216       }
1217       save << "3.3.) Faces in detail: " << endl;
1218       map <int,int>::iterator itF;
1219       for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1220         save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
1221     }
1222   }
1223   save << "4) Total number of volumes:   " << NbVolumes() << endl;
1224   if ( NbVolumes() > 0 ) {
1225     int nb8 = NbHexas();
1226     int nb4 = NbTetras();
1227     int nb5 = NbPyramids();
1228     int nb6 = NbPrisms();
1229     save << "4.1.) Number of hexahedrons:  " << nb8 << endl;
1230     save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
1231     save << "4.3.) Number of prisms:       " << nb6 << endl;
1232     save << "4.4.) Number of pyramides:    " << nb5 << endl;
1233     if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
1234       map<int,int> myVolumesMap;
1235       SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1236       while( itVolumes->more( ) ) {
1237         int nbNodes = itVolumes->next()->NbNodes();
1238         if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1239           myVolumesMap[ nbNodes ] = 0;
1240         myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1241       }
1242       save << "4.5.) Volumes in detail: " << endl;
1243       map <int,int>::iterator itV;
1244       for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1245         save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
1246     }
1247   }
1248   save << "===========================================================================" << endl;
1249   return save;
1250 }