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