Salome HOME
Update of CheckDone
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
1 // Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : implementation of SMESH idl descriptions
24 //  File   : SMESH_Gen.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28
29 //#define CHRONODEF
30
31 #include "SMESH_Gen.hxx"
32
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMESHDS_Document.hxx"
37 #include "SMESH_HypoFilter.hxx"
38 #include "SMESH_Mesh.hxx"
39 #include "SMESH_MesherHelper.hxx"
40 #include "SMESH_subMesh.hxx"
41
42 #include "utilities.h"
43 #include "OpUtil.hxx"
44 #include "Utils_ExceptHandlers.hxx"
45
46 #include <TopoDS_Iterator.hxx>
47 #include <TopoDS.hxx>
48
49 #include "memoire.h"
50
51 #ifdef WIN32
52   #include <windows.h>
53 #endif
54
55 #include <Basics_Utils.hxx>
56
57 using namespace std;
58
59 // Environment variable separator
60 #ifdef WIN32
61   #define env_sep ';'
62 #else
63   #define env_sep ':'
64 #endif
65
66 namespace
67 {
68   // a structure used to nullify SMESH_Gen field of SMESH_Hypothesis,
69   // which is needed for SMESH_Hypothesis not deleted before ~SMESH_Gen()
70   struct _Hyp : public SMESH_Hypothesis
71   {
72     void NullifyGen()
73     {
74       _gen = 0;
75     }
76   };
77
78   //================================================================================
79   /*!
80    * \brief Fill a map of shapes with all sub-shape of a sub-mesh
81    */
82   //================================================================================
83
84   TopTools_IndexedMapOfShape * fillAllowed( SMESH_subMesh*               sm,
85                                             const bool                   toFill,
86                                             TopTools_IndexedMapOfShape * allowedSub )
87   {
88     if ( !toFill || !allowedSub )
89     {
90       return nullptr;
91     }
92     if ( allowedSub->IsEmpty() )
93     {
94       allowedSub->ReSize( sm->DependsOn().size() + 1 );
95       allowedSub->Add( sm->GetSubShape() );
96       for ( const auto & key_sm : sm->DependsOn() )
97         allowedSub->Add( key_sm.second->GetSubShape() );
98     }
99     return allowedSub;
100   }
101 }
102
103 //=============================================================================
104 /*!
105  *  Constructor
106  */
107 //=============================================================================
108
109 SMESH_Gen::SMESH_Gen()
110 {
111   _studyContext = new StudyContextStruct;
112   _studyContext->myDocument = new SMESHDS_Document();
113   _localId = 0;
114   _hypId   = 0;
115   _segmentation = _nbSegments = 10;
116   _compute_canceled = false;
117 }
118
119 //=============================================================================
120 /*!
121  * Destructor
122  */
123 //=============================================================================
124
125 SMESH_Gen::~SMESH_Gen()
126 {
127   std::map < int, SMESH_Hypothesis * >::iterator i_hyp = _studyContext->mapHypothesis.begin();
128   for ( ; i_hyp != _studyContext->mapHypothesis.end(); ++i_hyp )
129   {
130     if ( _Hyp* h = static_cast< _Hyp*>( i_hyp->second ))
131       h->NullifyGen();
132   }
133   delete _studyContext->myDocument;
134   delete _studyContext;
135 }
136
137 //=============================================================================
138 /*!
139  * Creates a mesh in a study.
140  * if (theIsEmbeddedMode) { mesh modification commands are not logged }
141  */
142 //=============================================================================
143
144 SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
145   throw(SALOME_Exception)
146 {
147   Unexpect aCatch(SalomeException);
148
149   // create a new SMESH_mesh object
150   SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
151                                      this,
152                                      theIsEmbeddedMode,
153                                      _studyContext->myDocument);
154   _studyContext->mapMesh[_localId-1] = aMesh;
155
156   return aMesh;
157 }
158
159 //=============================================================================
160 /*
161  * Compute a mesh
162  */
163 //=============================================================================
164
165 bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
166                         const TopoDS_Shape &        aShape,
167                         const int                   aFlags /*= COMPACT_MESH*/,
168                         const ::MeshDimension       aDim /*=::MeshDim_3D*/,
169                         TSetOfInt*                  aShapesId /*=0*/,
170                         TopTools_IndexedMapOfShape* anAllowedSubShapes/*=0*/)
171 {
172   MEMOSTAT;
173
174   const bool   aShapeOnly = aFlags & SHAPE_ONLY;
175   const bool     anUpward = aFlags & UPWARD;
176   const bool aCompactMesh = aFlags & COMPACT_MESH;
177
178   bool ret = true;
179
180   SMESH_subMesh *sm, *shapeSM = aMesh.GetSubMesh(aShape);
181
182   const bool includeSelf = true;
183   const bool complexShapeFirst = true;
184   const int  globalAlgoDim = 100;
185
186   SMESH_subMeshIteratorPtr smIt;
187
188   // Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
189   // that must be computed by Projection 1D-2D while the Projection asks to compute
190   // one face only.
191   SMESH_subMesh::compute_event computeEvent =
192     aShapeOnly ? SMESH_subMesh::COMPUTE_SUBMESH : SMESH_subMesh::COMPUTE;
193   if ( !aMesh.HasShapeToMesh() )
194     computeEvent = SMESH_subMesh::COMPUTE_NOGEOM; // if several algos and no geometry
195
196   TopTools_IndexedMapOfShape *allowedSubShapes = anAllowedSubShapes, allowedSub;
197   if ( aShapeOnly && !allowedSubShapes )
198     allowedSubShapes = &allowedSub;
199
200   if ( anUpward ) // is called from the below code in this method
201   {
202     // ===============================================
203     // Mesh all the sub-shapes starting from vertices
204     // ===============================================
205
206     smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
207     while ( smIt->more() )
208     {
209       SMESH_subMesh* smToCompute = smIt->next();
210
211       // do not mesh vertices of a pseudo shape
212       const TopoDS_Shape&        shape = smToCompute->GetSubShape();
213       const TopAbs_ShapeEnum shapeType = shape.ShapeType();
214       if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
215         continue;
216
217       // check for preview dimension limitations
218       if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
219       {
220         // clear compute state not to show previous compute errors
221         //  if preview invoked less dimension less than previous
222         smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
223         continue;
224       }
225
226       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
227       {
228         if (_compute_canceled)
229           return false;
230         smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
231         setCurrentSubMesh( smToCompute );
232         smToCompute->ComputeStateEngine( computeEvent );
233         setCurrentSubMesh( nullptr );
234         smToCompute->SetAllowedSubShapes( nullptr );
235       }
236
237       // we check all the sub-meshes here and detect if any of them failed to compute
238       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
239           ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
240         ret = false;
241       else if ( aShapesId )
242         aShapesId->insert( smToCompute->GetId() );
243     }
244     //aMesh.GetMeshDS()->Modified();
245     return ret;
246   }
247   else
248   {
249     // ================================================================
250     // Apply algos that do NOT require discreteized boundaries
251     // ("all-dimensional") and do NOT support sub-meshes, starting from
252     // the most complex shapes and collect sub-meshes with algos that 
253     // DO support sub-meshes
254     // ================================================================
255
256     list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
257
258     // map to sort sm with same dim algos according to dim of
259     // the shape the algo assigned to (issue 0021217).
260     // Other issues influenced the algo applying order:
261     // 21406, 21556, 21893, 20206
262     multimap< int, SMESH_subMesh* > shDim2sm;
263     multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
264     TopoDS_Shape algoShape;
265     int prevShapeDim = -1, aShapeDim;
266
267     smIt = shapeSM->getDependsOnIterator(includeSelf, complexShapeFirst);
268     while ( smIt->more() )
269     {
270       SMESH_subMesh* smToCompute = smIt->next();
271       if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
272         continue;
273
274       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
275       aShapeDim = GetShapeDim( aSubShape );
276       if ( aShapeDim < 1 ) break;
277       
278       // check for preview dimension limitations
279       if ( aShapesId && aShapeDim > (int)aDim )
280         continue;
281
282       SMESH_Algo* algo = GetAlgo( smToCompute, &algoShape );
283       if ( algo && !algo->NeedDiscreteBoundary() )
284       {
285         if ( algo->SupportSubmeshes() )
286         {
287           // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
288           // so that more local algos to go first
289           if ( prevShapeDim != aShapeDim )
290           {
291             prevShapeDim = aShapeDim;
292             for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
293               if ( shDim2smIt->first == globalAlgoDim )
294                 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_back( shDim2smIt->second );
295               else
296                 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_front( shDim2smIt->second );
297             shDim2sm.clear();
298           }
299           // add smToCompute to shDim2sm map
300           if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
301           {
302             aShapeDim = globalAlgoDim; // to compute last
303           }
304           else
305           {
306             aShapeDim = GetShapeDim( algoShape );
307             if ( algoShape.ShapeType() == TopAbs_COMPOUND )
308             {
309               TopoDS_Iterator it( algoShape );
310               aShapeDim += GetShapeDim( it.Value() );
311             }
312           }
313           shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
314         }
315         else // Compute w/o support of sub-meshes
316         {
317           if (_compute_canceled)
318             return false;
319           smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
320           setCurrentSubMesh( smToCompute );
321           smToCompute->ComputeStateEngine( computeEvent );
322           setCurrentSubMesh( nullptr );
323           smToCompute->SetAllowedSubShapes( nullptr );
324           if ( aShapesId )
325             aShapesId->insert( smToCompute->GetId() );
326         }
327       }
328     }
329     // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
330     for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
331       if ( shDim2smIt->first == globalAlgoDim )
332         smWithAlgoSupportingSubmeshes[3].push_back( shDim2smIt->second );
333       else
334         smWithAlgoSupportingSubmeshes[0].push_front( shDim2smIt->second );
335
336     // ======================================================
337     // Apply all-dimensional algorithms supporing sub-meshes
338     // ======================================================
339
340     std::vector< SMESH_subMesh* > smVec;
341     for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim )
342     {
343       // ------------------------------------------------
344       // sort list of sub-meshes according to mesh order
345       // ------------------------------------------------
346       smVec.assign( smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(),
347                     smWithAlgoSupportingSubmeshes[ aShapeDim ].end() );
348       aMesh.SortByMeshOrder( smVec );
349
350       // ------------------------------------------------------------
351       // compute sub-meshes with local uni-dimensional algos under
352       // sub-meshes with all-dimensional algos
353       // ------------------------------------------------------------
354       // start from lower shapes
355       for ( size_t i = 0; i < smVec.size(); ++i )
356       {
357         sm = smVec[i];
358
359         // get a shape the algo is assigned to
360         if ( !GetAlgo( sm, & algoShape ))
361           continue; // strange...
362
363         // look for more local algos
364         smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
365         while ( smIt->more() )
366         {
367           SMESH_subMesh* smToCompute = smIt->next();
368
369           const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
370           const int aShapeDim = GetShapeDim( aSubShape );
371           if ( aShapeDim < 1 ) continue;
372
373           // check for preview dimension limitations
374           if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
375             continue;
376
377           SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
378           filter
379             .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
380             .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
381
382           if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true))
383           {
384             if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
385             TopTools_IndexedMapOfShape* localAllowed = allowedSubShapes;
386             if ( localAllowed && localAllowed->IsEmpty() )
387               localAllowed = 0; // prevent fillAllowed() with  aSubShape
388
389             SMESH_Hypothesis::Hypothesis_Status status;
390             if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
391               // mesh a lower smToCompute starting from vertices
392               Compute( aMesh, aSubShape, aFlags | SHAPE_ONLY_UPWARD, aDim, aShapesId, localAllowed );
393           }
394         }
395       }
396       // --------------------------------
397       // apply the all-dimensional algos
398       // --------------------------------
399       for ( size_t i = 0; i < smVec.size(); ++i )
400       {
401         sm = smVec[i];
402         if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
403         {
404           const TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
405           // check for preview dimension limitations
406           if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
407             continue;
408
409           if (_compute_canceled)
410             return false;
411           sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
412           setCurrentSubMesh( sm );
413           sm->ComputeStateEngine( computeEvent );
414           setCurrentSubMesh( NULL );
415           sm->SetAllowedSubShapes( nullptr );
416           if ( aShapesId )
417             aShapesId->insert( sm->GetId() );
418         }
419       }
420     } // loop on shape dimensions
421
422     // -----------------------------------------------
423     // mesh the rest sub-shapes starting from vertices
424     // -----------------------------------------------
425     ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes );
426   }
427
428   MEMOSTAT;
429
430   // fix quadratic mesh by bending iternal links near concave boundary
431   if ( aCompactMesh && // a final compute
432        aShape.IsSame( aMesh.GetShapeToMesh() ) &&
433        !aShapesId && // not preview
434        ret ) // everything is OK
435   {
436     SMESH_MesherHelper aHelper( aMesh );
437     if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
438     {
439       aHelper.FixQuadraticElements( shapeSM->GetComputeError() );
440     }
441   }
442
443   if ( aCompactMesh )
444   {
445     aMesh.GetMeshDS()->Modified();
446     aMesh.GetMeshDS()->CompactMesh();
447   }
448   return ret;
449 }
450
451 //=============================================================================
452 /*!
453  * Prepare Compute a mesh
454  */
455 //=============================================================================
456 void SMESH_Gen::PrepareCompute(SMESH_Mesh &          aMesh,
457                                const TopoDS_Shape &  aShape)
458 {
459   _compute_canceled = false;
460   resetCurrentSubMesh();
461 }
462
463 //=============================================================================
464 /*!
465  * Cancel Compute a mesh
466  */
467 //=============================================================================
468 void SMESH_Gen::CancelCompute(SMESH_Mesh &          aMesh,
469                               const TopoDS_Shape &  aShape)
470 {
471   _compute_canceled = true;
472   if ( const SMESH_subMesh* sm = GetCurrentSubMesh() )
473   {
474     const_cast< SMESH_subMesh* >( sm )->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
475   }
476   resetCurrentSubMesh();
477 }
478
479 //================================================================================
480 /*!
481  * \brief Returns a sub-mesh being currently computed
482  */
483 //================================================================================
484
485 const SMESH_subMesh* SMESH_Gen::GetCurrentSubMesh() const
486 {
487   return _sm_current.empty() ? 0 : _sm_current.back();
488 }
489
490 //================================================================================
491 /*!
492  * \brief Sets a sub-mesh being currently computed.
493  *
494  * An algorithm can call Compute() for a sub-shape, hence we keep a stack of sub-meshes
495  */
496 //================================================================================
497
498 void SMESH_Gen::setCurrentSubMesh(SMESH_subMesh* sm)
499 {
500   if ( sm )
501     _sm_current.push_back( sm );
502
503   else if ( !_sm_current.empty() )
504     _sm_current.pop_back();
505 }
506
507 void SMESH_Gen::resetCurrentSubMesh()
508 {
509   _sm_current.clear();
510 }
511
512 //=============================================================================
513 /*!
514  * Evaluate a mesh
515  */
516 //=============================================================================
517
518 bool SMESH_Gen::Evaluate(SMESH_Mesh &          aMesh,
519                          const TopoDS_Shape &  aShape,
520                          MapShapeNbElems&      aResMap,
521                          const bool            anUpward,
522                          TSetOfInt*            aShapesId)
523 {
524   bool ret = true;
525
526   SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
527
528   const bool includeSelf = true;
529   const bool complexShapeFirst = true;
530   SMESH_subMeshIteratorPtr smIt;
531
532   if ( anUpward ) { // is called from below code here
533     // -----------------------------------------------
534     // mesh all the sub-shapes starting from vertices
535     // -----------------------------------------------
536     smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
537     while ( smIt->more() ) {
538       SMESH_subMesh* smToCompute = smIt->next();
539
540       // do not mesh vertices of a pseudo shape
541       const TopAbs_ShapeEnum shapeType = smToCompute->GetSubShape().ShapeType();
542       //if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
543       //  continue;
544       if ( !aMesh.HasShapeToMesh() ) {
545         if( shapeType == TopAbs_VERTEX || shapeType == TopAbs_WIRE ||
546             shapeType == TopAbs_SHELL )
547           continue;
548       }
549
550       smToCompute->Evaluate(aResMap);
551       if( aShapesId )
552         aShapesId->insert( smToCompute->GetId() );
553     }
554     return ret;
555   }
556   else {
557     // -----------------------------------------------------------------
558     // apply algos that DO NOT require Discreteized boundaries and DO NOT
559     // support sub-meshes, starting from the most complex shapes
560     // and collect sub-meshes with algos that DO support sub-meshes
561     // -----------------------------------------------------------------
562     list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
563     smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
564     while ( smIt->more() ) {
565       SMESH_subMesh* smToCompute = smIt->next();
566       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
567       const int aShapeDim = GetShapeDim( aSubShape );
568       if ( aShapeDim < 1 ) break;
569       
570       SMESH_Algo* algo = GetAlgo( smToCompute );
571       if ( algo && !algo->NeedDiscreteBoundary() ) {
572         if ( algo->SupportSubmeshes() ) {
573           smWithAlgoSupportingSubmeshes.push_front( smToCompute );
574         }
575         else {
576           smToCompute->Evaluate(aResMap);
577           if ( aShapesId )
578             aShapesId->insert( smToCompute->GetId() );
579         }
580       }
581     }
582
583     // ------------------------------------------------------------
584     // sort list of meshes according to mesh order
585     // ------------------------------------------------------------
586     std::vector< SMESH_subMesh* > smVec( smWithAlgoSupportingSubmeshes.begin(),
587                                          smWithAlgoSupportingSubmeshes.end() );
588     aMesh.SortByMeshOrder( smVec );
589
590     // ------------------------------------------------------------
591     // compute sub-meshes under shapes with algos that DO NOT require
592     // Discreteized boundaries and DO support sub-meshes
593     // ------------------------------------------------------------
594     // start from lower shapes
595     for ( size_t i = 0; i < smVec.size(); ++i )
596     {
597       sm = smVec[i];
598
599       // get a shape the algo is assigned to
600       TopoDS_Shape algoShape;
601       if ( !GetAlgo( sm, & algoShape ))
602         continue; // strange...
603
604       // look for more local algos
605       smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
606       while ( smIt->more() ) {
607         SMESH_subMesh* smToCompute = smIt->next();
608
609         const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
610         const int aShapeDim = GetShapeDim( aSubShape );
611         if ( aShapeDim < 1 ) continue;
612
613         SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
614         filter
615           .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
616           .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
617
618         if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true ))
619         {
620           if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
621           SMESH_Hypothesis::Hypothesis_Status status;
622           if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
623             // mesh a lower smToCompute starting from vertices
624             Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
625         }
626       }
627     }
628     // ----------------------------------------------------------
629     // apply the algos that do not require Discreteized boundaries
630     // ----------------------------------------------------------
631     for ( size_t i = 0; i < smVec.size(); ++i )
632     {
633       sm = smVec[i];
634       sm->Evaluate(aResMap);
635       if ( aShapesId )
636         aShapesId->insert( sm->GetId() );
637     }
638
639     // -----------------------------------------------
640     // mesh the rest sub-shapes starting from vertices
641     // -----------------------------------------------
642     ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
643   }
644
645   return ret;
646 }
647
648
649 //=======================================================================
650 //function : checkConformIgnoredAlgos
651 //purpose  :
652 //=======================================================================
653
654 static bool checkConformIgnoredAlgos(SMESH_Mesh&               aMesh,
655                                      SMESH_subMesh*            aSubMesh,
656                                      const SMESH_Algo*         aGlobIgnoAlgo,
657                                      const SMESH_Algo*         aLocIgnoAlgo,
658                                      bool &                    checkConform,
659                                      set<SMESH_subMesh*>&      aCheckedMap,
660                                      list< SMESH_Gen::TAlgoStateError > & theErrors)
661 {
662   ASSERT( aSubMesh );
663   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
664     return true;
665
666
667   bool ret = true;
668
669   const list<const SMESHDS_Hypothesis*>& listHyp =
670     aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
671   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
672   for ( ; it != listHyp.end(); it++)
673   {
674     const SMESHDS_Hypothesis * aHyp = *it;
675     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
676       continue;
677
678     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
679     ASSERT ( algo );
680
681     if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
682     {
683       theErrors.push_back( SMESH_Gen::TAlgoStateError() );
684       theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, false );
685       INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
686             << aLocIgnoAlgo->GetName() << ">");
687     }
688     else
689     {
690       bool       isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
691       int             dim = algo->GetDim();
692       int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
693       bool    isNeededDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->NeedLowerHyps( dim ) : false );
694
695       if (( dim < aMaxGlobIgnoDim && !isNeededDim ) &&
696           ( isGlobal || !aGlobIgnoAlgo->SupportSubmeshes() ))
697       {
698         // algo is hidden by a global algo
699         theErrors.push_back( SMESH_Gen::TAlgoStateError() );
700         theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, true );
701         INFOS( ( isGlobal ? "Global" : "Local" )
702               << " <" << algo->GetName() << "> is hidden by global <"
703               << aGlobIgnoAlgo->GetName() << ">");
704       }
705       else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
706       {
707         // local algo is not hidden and hides algos on sub-shapes
708         if (checkConform && !aSubMesh->IsConform( algo ))
709         {
710           ret = false;
711           checkConform = false; // no more check conformity
712           INFOS( "ERROR: Local <" << algo->GetName() <<
713                 "> would produce not conform mesh: "
714                 "<Not Conform Mesh Allowed> hypothesis is missing");
715           theErrors.push_back( SMESH_Gen::TAlgoStateError() );
716           theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
717         }
718
719         // sub-algos will be hidden by a local <algo> if <algo> does not support sub-meshes
720         if ( algo->SupportSubmeshes() )
721           algo = 0;
722         SMESH_subMeshIteratorPtr revItSub =
723           aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
724         bool checkConform2 = false;
725         while ( revItSub->more() )
726         {
727           SMESH_subMesh* sm = revItSub->next();
728           checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
729                                     algo, checkConform2, aCheckedMap, theErrors);
730           aCheckedMap.insert( sm );
731         }
732       }
733     }
734   }
735
736   return ret;
737 }
738
739 //=======================================================================
740 //function : checkMissing
741 //purpose  : notify on missing hypothesis
742 //           Return false if algo or hipothesis is missing
743 //=======================================================================
744
745 static bool checkMissing(SMESH_Gen*                aGen,
746                          SMESH_Mesh&               aMesh,
747                          SMESH_subMesh*            aSubMesh,
748                          const int                 aTopAlgoDim,
749                          bool*                     globalChecked,
750                          const bool                checkNoAlgo,
751                          set<SMESH_subMesh*>&      aCheckedMap,
752                          list< SMESH_Gen::TAlgoStateError > & theErrors)
753 {
754   switch ( aSubMesh->GetSubShape().ShapeType() )
755   {
756   case TopAbs_EDGE:
757   case TopAbs_FACE:
758   case TopAbs_SOLID: break; // check this sub-mesh, it can be meshed
759   default:
760     return true; // not meshable sub-mesh
761   }
762   if ( aCheckedMap.count( aSubMesh ))
763     return true;
764
765   int ret = true;
766   SMESH_Algo* algo = 0;
767
768   switch (aSubMesh->GetAlgoState())
769   {
770   case SMESH_subMesh::NO_ALGO: {
771     if (checkNoAlgo)
772     {
773       // should there be any algo?
774       int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
775       if (aTopAlgoDim > shapeDim)
776       {
777         MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
778         ret = false;
779         theErrors.push_back( SMESH_Gen::TAlgoStateError() );
780         theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
781       }
782     }
783     return ret;
784   }
785   case SMESH_subMesh::MISSING_HYP: {
786     // notify if an algo missing hyp is attached to aSubMesh
787     algo = aSubMesh->GetAlgo();
788     ASSERT( algo );
789     bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
790     if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
791     {
792       TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
793       SMESH_Hypothesis::Hypothesis_Status status;
794       algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
795       if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
796         MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
797                  << "<" << algo->GetName() << "> has a bad parameter value");
798         errName = status;
799       } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
800         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
801                  << "<" << algo->GetName() << "> assigned to mismatching geometry");
802         errName = status;
803       } else {
804         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
805                  << "<" << algo->GetName() << "> misses some hypothesis");
806       }
807       if (IsGlobalHypothesis)
808         globalChecked[ algo->GetDim() ] = true;
809       theErrors.push_back( SMESH_Gen::TAlgoStateError() );
810       theErrors.back().Set( errName, algo, IsGlobalHypothesis );
811     }
812     ret = false;
813     break;
814   }
815   case SMESH_subMesh::HYP_OK:
816     algo = aSubMesh->GetAlgo();
817     ret = true;
818     if (!algo->NeedDiscreteBoundary())
819     {
820       SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
821                                                                        /*complexShapeFirst=*/false);
822       while ( itsub->more() )
823         aCheckedMap.insert( itsub->next() );
824     }
825     break;
826   default: ASSERT(0);
827   }
828
829   // do not check under algo that hides sub-algos or
830   // re-start checking NO_ALGO state
831   ASSERT (algo);
832   bool isTopLocalAlgo =
833     ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
834   if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
835   {
836     bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
837     SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
838                                                                      /*complexShapeFirst=*/true);
839     while ( itsub->more() )
840     {
841       // sub-meshes should not be checked further more
842       SMESH_subMesh* sm = itsub->next();
843
844       if (isTopLocalAlgo)
845       {
846         //check algo on sub-meshes
847         int aTopAlgoDim2 = algo->GetDim();
848         if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
849                            globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
850         {
851           ret = false;
852           if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
853             checkNoAlgo2 = false;
854         }
855       }
856       aCheckedMap.insert( sm );
857     }
858   }
859   return ret;
860 }
861
862 //=======================================================================
863 //function : CheckAlgoState
864 //purpose  : notify on bad state of attached algos, return false
865 //           if Compute() would fail because of some algo bad state
866 //=======================================================================
867
868 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
869 {
870   list< TAlgoStateError > errors;
871   return GetAlgoState( aMesh, aShape, errors );
872 }
873
874 //=======================================================================
875 //function : GetAlgoState
876 //purpose  : notify on bad state of attached algos, return false
877 //           if Compute() would fail because of some algo bad state
878 //           theErrors list contains problems description
879 //=======================================================================
880
881 bool SMESH_Gen::GetAlgoState(SMESH_Mesh&               theMesh,
882                              const TopoDS_Shape&       theShape,
883                              list< TAlgoStateError > & theErrors)
884 {
885   bool ret = true;
886   bool hasAlgo = false;
887
888   SMESH_subMesh*          sm = theMesh.GetSubMesh(theShape);
889   const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
890   TopoDS_Shape     mainShape = meshDS->ShapeToMesh();
891
892   // -----------------
893   // get global algos
894   // -----------------
895
896   const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
897
898   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
899   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
900   for ( ; it != listHyp.end(); it++)
901   {
902     const SMESHDS_Hypothesis * aHyp = *it;
903     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
904       continue;
905
906     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
907     ASSERT ( algo );
908
909     int dim = algo->GetDim();
910     aGlobAlgoArr[ dim ] = algo;
911
912     hasAlgo = true;
913   }
914
915   // --------------------------------------------------------
916   // info on algos that will be ignored because of ones that
917   // don't NeedDiscreteBoundary() attached to super-shapes,
918   // check that a conform mesh will be produced
919   // --------------------------------------------------------
920
921
922   // find a global algo possibly hiding sub-algos
923   int dim;
924   const SMESH_Algo* aGlobIgnoAlgo = 0;
925   for (dim = 3; dim > 0; dim--)
926   {
927     if (aGlobAlgoArr[ dim ] &&
928         !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary() /*&&
929         !aGlobAlgoArr[ dim ]->SupportSubmeshes()*/ )
930     {
931       aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
932       break;
933     }
934   }
935
936   set<SMESH_subMesh*> aCheckedSubs;
937   bool checkConform = ( !theMesh.IsNotConformAllowed() );
938
939   // loop on theShape and its sub-shapes
940   SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
941                                                                 /*complexShapeFirst=*/true);
942   while ( revItSub->more() )
943   {
944     SMESH_subMesh* smToCheck = revItSub->next();
945     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
946       break;
947
948     if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
949       if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
950                                      0, checkConform, aCheckedSubs, theErrors))
951         ret = false;
952
953     if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
954       hasAlgo = true;
955   }
956
957   // ----------------------------------------------------------------
958   // info on missing hypothesis and find out if all needed algos are
959   // well defined
960   // ----------------------------------------------------------------
961
962   // find max dim of global algo
963   int aTopAlgoDim = 0;
964   for (dim = 3; dim > 0; dim--)
965   {
966     if (aGlobAlgoArr[ dim ])
967     {
968       aTopAlgoDim = dim;
969       break;
970     }
971   }
972   bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
973   bool globalChecked[] = { false, false, false, false };
974
975   // loop on theShape and its sub-shapes
976   aCheckedSubs.clear();
977   revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
978   while ( revItSub->more() )
979   {
980     SMESH_subMesh* smToCheck = revItSub->next();
981     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
982       break;
983
984     if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
985                        globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
986     {
987       ret = false;
988       if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
989         checkNoAlgo = false;
990     }
991   }
992
993   if ( !hasAlgo ) {
994     ret = false;
995     theErrors.push_back( TAlgoStateError() );
996     theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, theMesh.HasShapeToMesh() ? 1 : 3, true );
997   }
998
999   return ret;
1000 }
1001
1002 //=======================================================================
1003 //function : IsGlobalHypothesis
1004 //purpose  : check if theAlgo is attached to the main shape
1005 //=======================================================================
1006
1007 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
1008 {
1009   SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
1010   return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
1011 }
1012
1013 //================================================================================
1014 /*!
1015  * \brief Return paths to xml files of plugins
1016  */
1017 //================================================================================
1018
1019 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
1020 {
1021   // Get paths to xml files of plugins
1022   vector< string > xmlPaths;
1023   string sep;
1024   if ( const char* meshersList = getenv("SMESH_MeshersList") )
1025   {
1026     string meshers = meshersList, plugin;
1027     string::size_type from = 0, pos;
1028     while ( from < meshers.size() )
1029     {
1030       // cut off plugin name
1031       pos = meshers.find( env_sep, from );
1032       if ( pos != string::npos )
1033         plugin = meshers.substr( from, pos-from );
1034       else
1035         plugin = meshers.substr( from ), pos = meshers.size();
1036       from = pos + 1;
1037
1038       // get PLUGIN_ROOT_DIR path
1039       string rootDirVar, pluginSubDir = plugin;
1040       if ( plugin == "StdMeshers" )
1041         rootDirVar = "SMESH", pluginSubDir = "smesh";
1042       else
1043         for ( pos = 0; pos < plugin.size(); ++pos )
1044           rootDirVar += toupper( plugin[pos] );
1045       rootDirVar += "_ROOT_DIR";
1046
1047       const char* rootDir = getenv( rootDirVar.c_str() );
1048       if ( !rootDir || strlen(rootDir) == 0 )
1049       {
1050         rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
1051         rootDir = getenv( rootDirVar.c_str() );
1052         if ( !rootDir || strlen(rootDir) == 0 ) continue;
1053       }
1054
1055       // get a separator from rootDir
1056       for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
1057         if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
1058         {
1059           sep = rootDir[pos];
1060           break;
1061         }
1062 #ifdef WIN32
1063       if (sep.empty() ) sep = "\\";
1064 #else
1065       if (sep.empty() ) sep = "/";
1066 #endif
1067
1068       // get a path to resource file
1069       string xmlPath = rootDir;
1070       if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
1071         xmlPath += sep;
1072       xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
1073       for ( pos = 0; pos < pluginSubDir.size(); ++pos )
1074         xmlPath += tolower( pluginSubDir[pos] );
1075       xmlPath += sep + plugin + ".xml";
1076       bool fileOK;
1077 #ifdef WIN32
1078 #ifdef UNICODE
1079       const wchar_t* path = Kernel_Utils::decode_s(xmlPath);
1080 #else
1081       const char* path = xmlPath.c_str();
1082 #endif
1083       fileOK = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
1084 #ifdef UNICODE
1085       delete path;
1086 #endif
1087 #else
1088       fileOK = (access(xmlPath.c_str(), F_OK) == 0);
1089 #endif
1090       if ( fileOK )
1091         xmlPaths.push_back( xmlPath );
1092     }
1093   }
1094
1095   return xmlPaths;
1096 }
1097
1098 //=============================================================================
1099 /*!
1100  * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
1101  */
1102 //=============================================================================
1103
1104 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh &         aMesh,
1105                                const TopoDS_Shape & aShape,
1106                                TopoDS_Shape*        assignedTo)
1107 {
1108   return GetAlgo( aMesh.GetSubMesh( aShape ), assignedTo );
1109 }
1110
1111 //=============================================================================
1112 /*!
1113  * Finds algo to mesh a sub-mesh. Optionally returns a shape the found algo is bound to
1114  */
1115 //=============================================================================
1116
1117 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_subMesh * aSubMesh,
1118                                TopoDS_Shape*   assignedTo)
1119 {
1120   if ( !aSubMesh ) return 0;
1121
1122   const TopoDS_Shape & aShape = aSubMesh->GetSubShape();
1123   SMESH_Mesh&          aMesh  = *aSubMesh->GetFather();
1124
1125   SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
1126   if ( aMesh.HasShapeToMesh() )
1127     filter.And( filter.IsApplicableTo( aShape ));
1128
1129   typedef SMESH_Algo::Features AlgoData;
1130
1131   TopoDS_Shape assignedToShape;
1132   SMESH_Algo* algo =
1133     (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape );
1134
1135   if ( algo &&
1136        aShape.ShapeType() == TopAbs_FACE &&
1137        !aShape.IsSame( assignedToShape ) &&
1138        SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
1139   {
1140     // Issue 0021559. If there is another 2D algo with different types of output
1141     // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
1142     // have different types of input elements, we choose a most appropriate 2D algo.
1143
1144     // try to find a concurrent 2D algo
1145     filter.AndNot( filter.Is( algo ));
1146     TopoDS_Shape assignedToShape2;
1147     SMESH_Algo* algo2 =
1148       (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape2 );
1149     if ( algo2 &&                                                  // algo found
1150          !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) &&     // algo is local
1151          ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
1152            SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
1153          aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ),    // no forced order
1154                           aMesh.GetSubMesh( assignedToShape  )))
1155     {
1156       // get algos on the adjacent SOLIDs
1157       filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
1158       vector< SMESH_Algo* > algos3D;
1159       PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
1160                                                                     TopAbs_SOLID );
1161       while ( const TopoDS_Shape* solid = solidIt->next() )
1162         if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
1163         {
1164           algos3D.push_back( algo3D );
1165           filter.AndNot( filter.HasName( algo3D->GetName() ));
1166         }
1167       // check compatibility of algos
1168       if ( algos3D.size() > 1 )
1169       {
1170         const AlgoData& algoData    = algo->SMESH_Algo::GetFeatures();
1171         const AlgoData& algoData2   = algo2->SMESH_Algo::GetFeatures();
1172         const AlgoData& algoData3d0 = algos3D[0]->SMESH_Algo::GetFeatures();
1173         const AlgoData& algoData3d1 = algos3D[1]->SMESH_Algo::GetFeatures();
1174         if (( algoData2.IsCompatible( algoData3d0 ) &&
1175               algoData2.IsCompatible( algoData3d1 ))
1176             &&
1177             !(algoData.IsCompatible( algoData3d0 ) &&
1178               algoData.IsCompatible( algoData3d1 )))
1179           algo = algo2;
1180       }
1181     }
1182   }
1183
1184   if ( assignedTo && algo )
1185     * assignedTo = assignedToShape;
1186
1187   return algo;
1188 }
1189
1190 //=============================================================================
1191 /*!
1192  * Returns StudyContextStruct for a study
1193  */
1194 //=============================================================================
1195
1196 StudyContextStruct *SMESH_Gen::GetStudyContext()
1197 {
1198   return _studyContext;
1199 }
1200
1201 //================================================================================
1202 /*!
1203  * \brief Return shape dimension by TopAbs_ShapeEnum
1204  */
1205 //================================================================================
1206
1207 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1208 {
1209   static vector<int> dim;
1210   if ( dim.empty() )
1211   {
1212     dim.resize( TopAbs_SHAPE, -1 );
1213     dim[ TopAbs_COMPOUND ]  = MeshDim_3D;
1214     dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1215     dim[ TopAbs_SOLID ]     = MeshDim_3D;
1216     dim[ TopAbs_SHELL ]     = MeshDim_2D;
1217     dim[ TopAbs_FACE  ]     = MeshDim_2D;
1218     dim[ TopAbs_WIRE ]      = MeshDim_1D;
1219     dim[ TopAbs_EDGE ]      = MeshDim_1D;
1220     dim[ TopAbs_VERTEX ]    = MeshDim_0D;
1221   }
1222   return dim[ aShapeType ];
1223 }
1224
1225 //=============================================================================
1226 /*!
1227  * Generate a new id unique within this Gen
1228  */
1229 //=============================================================================
1230
1231 int SMESH_Gen::GetANewId()
1232 {
1233   return _hypId++;
1234 }