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