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