Salome HOME
ef500ac8eab896f3570e468c9a8502e9a97735c4
[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  *  IsReversedInChain
970  */
971 //=============================================================================
972
973 bool SMESH_Mesh::IsReversedInChain (const TopoDS_Shape& theEdge,
974                                     const TopoDS_Shape& theMainEdge)
975 {
976   if ( !theMainEdge.IsNull() && !theEdge.IsNull() &&
977       _mapPropagationChains.Contains( theMainEdge ))
978   {
979     const TopTools_IndexedMapOfShape& aChain =
980       _mapPropagationChains.FindFromKey( theMainEdge );
981     int index = aChain.FindIndex( theEdge );
982     if ( index )
983       return aChain(index).Orientation() == TopAbs_REVERSED;
984   }
985   return false;
986 }
987
988 //=============================================================================
989 /*!
990  *  CleanMeshOnPropagationChain
991  */
992 //=============================================================================
993 void SMESH_Mesh::CleanMeshOnPropagationChain (const TopoDS_Shape& theMainEdge)
994 {
995   const TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.FindFromKey(theMainEdge);
996   int i, nbEdges = aChain.Extent();
997   for (i = 1; i <= nbEdges; i++) {
998     TopoDS_Shape anEdge = aChain.FindKey(i);
999     SMESH_subMesh *subMesh = GetSubMesh(anEdge);
1000     SMESHDS_SubMesh *subMeshDS = subMesh->GetSubMeshDS();
1001     if (subMeshDS && subMeshDS->NbElements() > 0) {
1002       subMesh->ComputeStateEngine(SMESH_subMesh::CLEANDEP);
1003     }
1004   }
1005 }
1006
1007 //=============================================================================
1008 /*!
1009  *  RebuildPropagationChains
1010  *  Rebuild all existing propagation chains.
1011  *  Have to be used, if 1D hypothesis have been assigned/removed to/from any edge
1012  */
1013 //=============================================================================
1014 bool SMESH_Mesh::RebuildPropagationChains()
1015 {
1016   bool ret = true;
1017
1018   // Clean all chains, because they can be not up-to-date
1019   int i, nbChains = _mapPropagationChains.Extent();
1020   for (i = 1; i <= nbChains; i++) {
1021     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1022     CleanMeshOnPropagationChain(aMainEdge);
1023     _mapPropagationChains.ChangeFromIndex(i).Clear();
1024   }
1025
1026   // Build all chains
1027   for (i = 1; i <= nbChains; i++) {
1028     TopoDS_Shape aMainEdge = _mapPropagationChains.FindKey(i);
1029     if (!BuildPropagationChain(aMainEdge))
1030       ret = false;
1031     CleanMeshOnPropagationChain(aMainEdge);
1032   }
1033
1034   return ret;
1035 }
1036
1037 //=============================================================================
1038 /*!
1039  *  RemovePropagationChain
1040  *  Have to be used, if Propagation hypothesis is removed from <theMainEdge>
1041  */
1042 //=============================================================================
1043 bool SMESH_Mesh::RemovePropagationChain (const TopoDS_Shape& theMainEdge)
1044 {
1045   if (!_mapPropagationChains.Contains(theMainEdge))
1046     return false;
1047
1048   // Clean mesh elements and nodes, built on the chain
1049   CleanMeshOnPropagationChain(theMainEdge);
1050
1051   // Clean the chain
1052   _mapPropagationChains.ChangeFromKey(theMainEdge).Clear();
1053
1054   // Remove the chain from the map
1055   int i = _mapPropagationChains.FindIndex(theMainEdge);
1056   TopoDS_Vertex anEmptyShape;
1057   BRep_Builder BB;
1058   BB.MakeVertex(anEmptyShape, gp_Pnt(0,0,0), 0.1);
1059   TopTools_IndexedMapOfShape anEmptyMap;
1060   _mapPropagationChains.Substitute(i, anEmptyShape, anEmptyMap);
1061
1062   return true;
1063 }
1064
1065 //=============================================================================
1066 /*!
1067  *  BuildPropagationChain
1068  */
1069 //=============================================================================
1070 bool SMESH_Mesh::BuildPropagationChain (const TopoDS_Shape& theMainEdge)
1071 {
1072   if (theMainEdge.ShapeType() != TopAbs_EDGE) return true;
1073
1074   // Add new chain, if there is no
1075   if (!_mapPropagationChains.Contains(theMainEdge)) {
1076     TopTools_IndexedMapOfShape aNewChain;
1077     _mapPropagationChains.Add(theMainEdge, aNewChain);
1078   }
1079
1080   // Check presence of 1D hypothesis to be propagated
1081   if (!IsLocal1DHypothesis(theMainEdge)) {
1082     MESSAGE("Warning: There is no 1D hypothesis to propagate. Please, assign.");
1083     return true;
1084   }
1085
1086   // Edges, on which the 1D hypothesis will be propagated from <theMainEdge>
1087   TopTools_IndexedMapOfShape& aChain = _mapPropagationChains.ChangeFromKey(theMainEdge);
1088   if (aChain.Extent() > 0) {
1089     CleanMeshOnPropagationChain(theMainEdge);
1090     aChain.Clear();
1091   }
1092
1093   // At first put <theMainEdge> in the chain
1094   aChain.Add(theMainEdge);
1095
1096   // List of edges, added to chain on the previous cycle pass
1097   TopTools_ListOfShape listPrevEdges;
1098   listPrevEdges.Append(theMainEdge.Oriented( TopAbs_FORWARD ));
1099
1100 //   5____4____3____4____5____6
1101 //   |    |    |    |    |    |
1102 //   |    |    |    |    |    |
1103 //   4____3____2____3____4____5
1104 //   |    |    |    |    |    |      Number in the each knot of
1105 //   |    |    |    |    |    |      grid indicates cycle pass,
1106 //   3____2____1____2____3____4      on which corresponding edge
1107 //   |    |    |    |    |    |      (perpendicular to the plane
1108 //   |    |    |    |    |    |      of view) will be found.
1109 //   2____1____0____1____2____3
1110 //   |    |    |    |    |    |
1111 //   |    |    |    |    |    |
1112 //   3____2____1____2____3____4
1113
1114   // Collect all edges pass by pass
1115   while (listPrevEdges.Extent() > 0) {
1116     // List of edges, added to chain on this cycle pass
1117     TopTools_ListOfShape listCurEdges;
1118
1119     // Find the next portion of edges
1120     TopTools_ListIteratorOfListOfShape itE (listPrevEdges);
1121     for (; itE.More(); itE.Next()) {
1122       TopoDS_Shape anE = itE.Value();
1123
1124       // Iterate on faces, having edge <anE>
1125       TopTools_ListIteratorOfListOfShape itA (GetAncestors(anE));
1126       for (; itA.More(); itA.Next()) {
1127         TopoDS_Shape aW = itA.Value();
1128
1129         // There are objects of different type among the ancestors of edge
1130         if (aW.ShapeType() == TopAbs_WIRE) {
1131           TopoDS_Shape anOppE;
1132
1133           BRepTools_WireExplorer aWE (TopoDS::Wire(aW));
1134           Standard_Integer nb = 1, found = 0;
1135           TopTools_Array1OfShape anEdges (1,4);
1136           for (; aWE.More(); aWE.Next(), nb++) {
1137             if (nb > 4) {
1138               found = 0;
1139               break;
1140             }
1141             anEdges(nb) = aWE.Current();
1142             if (!_mapAncestors.Contains(anEdges(nb))) {
1143               MESSAGE("WIRE EXPLORER HAVE GIVEN AN INVALID EDGE !!!");
1144               break;
1145             }
1146             if (anEdges(nb).IsSame(anE)) found = nb;
1147           }
1148
1149           if (nb == 5 && found > 0) {
1150             // Quadrangle face found, get an opposite edge
1151             Standard_Integer opp = found + 2;
1152             if (opp > 4) opp -= 4;
1153             anOppE = anEdges(opp);
1154
1155             if (!aChain.Contains(anOppE)) {
1156               if (!IsLocal1DHypothesis(anOppE)) {
1157                 TopoDS_Shape aMainEdgeForOppEdge;
1158                 if (IsPropagatedHypothesis(anOppE, aMainEdgeForOppEdge)) {
1159                   // Collision!
1160                   MESSAGE("Error: Collision between propagated hypotheses");
1161                   CleanMeshOnPropagationChain(theMainEdge);
1162                   aChain.Clear();
1163                   return false;
1164                 } else {
1165                   // Add found edge to the chain oriented so that to
1166                   // have it in aChain co-directed with theMainEdge
1167                   TopAbs_Orientation ori = anE.Orientation();
1168                   if ( anEdges(opp).Orientation() == anEdges(found).Orientation() )
1169                     ori = TopAbs::Reverse( ori );
1170                   anOppE.Orientation( ori );
1171                   aChain.Add(anOppE);
1172                   listCurEdges.Append(anOppE);
1173                 }
1174               }
1175             }
1176           } // if (nb == 5 && found > 0)
1177         } // if (aF.ShapeType() == TopAbs_WIRE)
1178       } // for (; itF.More(); itF.Next())
1179     } // for (; itE.More(); itE.Next())
1180
1181     listPrevEdges = listCurEdges;
1182   } // while (listPrevEdges.Extent() > 0)
1183
1184   CleanMeshOnPropagationChain(theMainEdge);
1185   return true;
1186 }
1187
1188 //=======================================================================
1189 //function : GetAncestors
1190 //purpose  : return list of ancestors of theSubShape in the order
1191 //           that lower dimention shapes come first.
1192 //=======================================================================
1193
1194 const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS)
1195 {
1196   if ( _mapAncestors.IsEmpty() )
1197   {
1198     // fill _mapAncestors
1199     int desType, ancType;
1200     for ( desType = TopAbs_EDGE; desType > TopAbs_COMPOUND; desType-- )
1201       for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
1202         TopExp::MapShapesAndAncestors (_myMeshDS->ShapeToMesh(),
1203                                        (TopAbs_ShapeEnum) desType,
1204                                        (TopAbs_ShapeEnum) ancType,
1205                                        _mapAncestors );
1206   }
1207
1208   if ( _mapAncestors.Contains( theS ) )
1209     return _mapAncestors.FindFromKey( theS );
1210
1211   static TopTools_ListOfShape emptyList;
1212   return emptyList;
1213 }
1214
1215 //=======================================================================
1216 //function : Dump
1217 //purpose  : dumps contents of mesh to stream [ debug purposes ]
1218 //=======================================================================
1219 ostream& SMESH_Mesh::Dump(ostream& save)
1220 {
1221   save << "========================== Dump contents of mesh ==========================" << endl;
1222   save << "1) Total number of nodes:     " << NbNodes() << endl;
1223   save << "2) Total number of edges:     " << NbEdges() << endl;
1224   save << "3) Total number of faces:     " << NbFaces() << endl;
1225   if ( NbFaces() > 0 ) {
1226     int nb3 = NbTriangles();
1227     int nb4 = NbQuadrangles();
1228     save << "3.1.) Number of triangles:    " << nb3 << endl;
1229     save << "3.2.) Number of quadrangles:  " << nb4 << endl;
1230     if ( nb3 + nb4 !=  NbFaces() ) {
1231       map<int,int> myFaceMap;
1232       SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
1233       while( itFaces->more( ) ) {
1234         int nbNodes = itFaces->next()->NbNodes();
1235         if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
1236           myFaceMap[ nbNodes ] = 0;
1237         myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
1238       }
1239       save << "3.3.) Faces in detail: " << endl;
1240       map <int,int>::iterator itF;
1241       for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
1242         save << "--> nb nodes: " << itF->first << " - nb elemens: " << itF->second << endl;
1243     }
1244   }
1245   save << "4) Total number of volumes:   " << NbVolumes() << endl;
1246   if ( NbVolumes() > 0 ) {
1247     int nb8 = NbHexas();
1248     int nb4 = NbTetras();
1249     int nb5 = NbPyramids();
1250     int nb6 = NbPrisms();
1251     save << "4.1.) Number of hexahedrons:  " << nb8 << endl;
1252     save << "4.2.) Number of tetrahedrons: " << nb4 << endl;
1253     save << "4.3.) Number of prisms:       " << nb6 << endl;
1254     save << "4.4.) Number of pyramides:    " << nb5 << endl;
1255     if ( nb8 + nb4 + nb5 + nb6 != NbVolumes() ) {
1256       map<int,int> myVolumesMap;
1257       SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
1258       while( itVolumes->more( ) ) {
1259         int nbNodes = itVolumes->next()->NbNodes();
1260         if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
1261           myVolumesMap[ nbNodes ] = 0;
1262         myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
1263       }
1264       save << "4.5.) Volumes in detail: " << endl;
1265       map <int,int>::iterator itV;
1266       for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
1267         save << "--> nb nodes: " << itV->first << " - nb elemens: " << itV->second << endl;
1268     }
1269   }
1270   save << "===========================================================================" << endl;
1271   return save;
1272 }