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