Salome HOME
0020053: EDF 868 GEOM: Using sub-meshes
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESH_Gen.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_HypoFilter.hxx"
32 #include "SMESHDS_Document.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35
36 #include "utilities.h"
37 #include "OpUtil.hxx"
38 #include "Utils_ExceptHandlers.hxx"
39
40 #include <gp_Pnt.hxx>
41 #include <BRep_Tool.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44
45 using namespace std;
46
47 //=============================================================================
48 /*!
49  *  default constructor:
50  */
51 //=============================================================================
52
53 SMESH_Gen::SMESH_Gen()
54 {
55         MESSAGE("SMESH_Gen::SMESH_Gen");
56         _localId = 0;
57         _hypId = 0;
58 }
59
60 //=============================================================================
61 /*!
62  *
63  */
64 //=============================================================================
65
66 SMESH_Gen::~SMESH_Gen()
67 {
68         MESSAGE("SMESH_Gen::~SMESH_Gen");
69 }
70
71 //=============================================================================
72 /*!
73  *
74  */
75 //=============================================================================
76
77 /*SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
78         throw(SALOME_Exception)
79 {
80
81         MESSAGE("CreateHypothesis("<<anHyp<<","<<studyId<<")");
82         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
83
84         StudyContextStruct *myStudyContext = GetStudyContext(studyId);
85
86         // create a new hypothesis object, store its ref. in studyContext
87
88         SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId);
89         int hypId = myHypothesis->GetID();
90         myStudyContext->mapHypothesis[hypId] = myHypothesis;
91         SCRUTE(studyId);
92         SCRUTE(hypId);
93
94         // store hypothesis in SMESHDS document
95
96         myStudyContext->myDocument->AddHypothesis(myHypothesis);
97         return myHypothesis;
98 }*/
99
100 //=============================================================================
101 /*!
102  *
103  */
104 //=============================================================================
105
106 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
107   throw(SALOME_Exception)
108 {
109   Unexpect aCatch(SalomeException);
110   MESSAGE("SMESH_Gen::CreateMesh");
111
112   // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
113   StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
114
115   // create a new SMESH_mesh object
116   SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
117                                      theStudyId,
118                                      this,
119                                      theIsEmbeddedMode,
120                                      aStudyContext->myDocument);
121   aStudyContext->mapMesh[_localId] = aMesh;
122
123   return aMesh;
124 }
125
126 //=============================================================================
127 /*!
128  * Compute a mesh
129  */
130 //=============================================================================
131
132 bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
133                         const TopoDS_Shape & aShape,
134                         const bool           anUpward)
135 {
136   MESSAGE("SMESH_Gen::Compute");
137
138   bool ret = true;
139
140   SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
141
142   const bool includeSelf = true;
143   const bool complexShapeFirst = true;
144
145   SMESH_subMeshIteratorPtr smIt;
146
147   if ( anUpward ) // is called from below code here
148   {
149     // -----------------------------------------------
150     // mesh all the subshapes starting from vertices
151     // -----------------------------------------------
152     smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
153     while ( smIt->more() )
154     {
155       SMESH_subMesh* smToCompute = smIt->next();
156
157       // do not mesh vertices of a pseudo shape
158       if ( !aMesh.HasShapeToMesh() &&
159            smToCompute->GetSubShape().ShapeType() == TopAbs_VERTEX )
160         continue;
161
162       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
163         smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
164
165       // we check all the submeshes here and detect if any of them failed to compute
166       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
167         ret = false;
168     }
169     return ret;
170   }
171   else
172   {
173     // -----------------------------------------------------------------
174     // apply algos that DO NOT require descretized boundaries and DO NOT
175     // support submeshes, starting from the most complex shapes
176     // and collect submeshes with algos that DO support submeshes
177     // -----------------------------------------------------------------
178     list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
179     smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
180     while ( smIt->more() )
181     {
182       SMESH_subMesh* smToCompute = smIt->next();
183       if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
184         continue;
185
186       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
187       if ( GetShapeDim( aSubShape ) < 1 ) break;
188
189       SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
190       if ( algo && !algo->NeedDescretBoundary() )
191       {
192         if ( algo->SupportSubmeshes() )
193           smWithAlgoSupportingSubmeshes.push_back( smToCompute );
194         else
195           smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
196       }
197     }
198     // ------------------------------------------------------------
199     // compute submeshes under shapes with algos that DO NOT require
200     // descretized boundaries and DO support submeshes
201     // ------------------------------------------------------------
202     list< SMESH_subMesh* >::reverse_iterator subIt, subEnd;
203     subIt  = smWithAlgoSupportingSubmeshes.rbegin();
204     subEnd = smWithAlgoSupportingSubmeshes.rend();
205     // start from lower shapes
206     for ( ; subIt != subEnd; ++subIt )
207     {
208       sm = *subIt;
209
210       // get a shape the algo is assigned to
211       TopoDS_Shape algoShape;
212       if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
213         continue; // strange...
214
215       // look for more local algos
216       smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
217       while ( smIt->more() )
218       {
219         SMESH_subMesh* smToCompute = smIt->next();
220
221         const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
222         if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
223
224         SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
225         filter
226           .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
227           .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
228
229         if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
230           SMESH_Hypothesis::Hypothesis_Status status;
231           if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
232             // mesh a lower smToCompute
233             Compute( aMesh, aSubShape );
234         }
235       }
236     }
237     // ----------------------------------------------------------
238     // apply the algos that do not require descretized boundaries
239     // ----------------------------------------------------------
240     for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt )
241       if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
242         sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
243
244     // -----------------------------------------------
245     // mesh the rest subshapes starting from vertices
246     // -----------------------------------------------
247     ret = Compute( aMesh, aShape, /*anUpward=*/true );
248   }
249
250   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
251   return ret;
252 }
253
254 //=======================================================================
255 //function : checkConformIgnoredAlgos
256 //purpose  :
257 //=======================================================================
258
259 static bool checkConformIgnoredAlgos(SMESH_Mesh&               aMesh,
260                                      SMESH_subMesh*            aSubMesh,
261                                      const SMESH_Algo*         aGlobIgnoAlgo,
262                                      const SMESH_Algo*         aLocIgnoAlgo,
263                                      bool &                    checkConform,
264                                      map<int, SMESH_subMesh*>& aCheckedMap,
265                                      list< SMESH_Gen::TAlgoStateError > & theErrors)
266 {
267   ASSERT( aSubMesh );
268   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
269     return true;
270
271
272   bool ret = true;
273
274   const list<const SMESHDS_Hypothesis*>& listHyp =
275     aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
276   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
277   for ( ; it != listHyp.end(); it++)
278   {
279     const SMESHDS_Hypothesis * aHyp = *it;
280     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
281       continue;
282
283     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
284     ASSERT ( algo );
285
286     if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
287     {
288       INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
289             << aLocIgnoAlgo->GetName() << ">");
290     }
291     else
292     {
293       bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
294       int dim = algo->GetDim();
295       int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
296
297       if ( dim < aMaxGlobIgnoDim )
298       {
299         // algo is hidden by a global algo
300         INFOS( ( isGlobal ? "Global" : "Local" )
301               << " <" << algo->GetName() << "> is hidden by global <"
302               << aGlobIgnoAlgo->GetName() << ">");
303       }
304       else if ( !algo->NeedDescretBoundary() && !isGlobal)
305       {
306         // local algo is not hidden and hides algos on sub-shapes
307         if (checkConform && !aSubMesh->IsConform( algo ))
308         {
309           ret = false;
310           checkConform = false; // no more check conformity
311           INFOS( "ERROR: Local <" << algo->GetName() <<
312                 "> would produce not conform mesh: "
313                 "<Not Conform Mesh Allowed> hypotesis is missing");
314           theErrors.push_back( SMESH_Gen::TAlgoStateError() );
315           theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
316         }
317
318         // sub-algos will be hidden by a local <algo>
319         const map<int, SMESH_subMesh*>& smMap = aSubMesh->DependsOn();
320         map<int, SMESH_subMesh*>::const_reverse_iterator revItSub;
321         bool checkConform2 = false;
322         for ( revItSub = smMap.rbegin(); revItSub != smMap.rend(); revItSub++)
323         {
324           checkConformIgnoredAlgos (aMesh, (*revItSub).second, aGlobIgnoAlgo,
325                                     algo, checkConform2, aCheckedMap, theErrors);
326           int key = (*revItSub).first;
327           SMESH_subMesh* sm = (*revItSub).second;
328           if ( aCheckedMap.find( key ) == aCheckedMap.end() )
329           {
330             aCheckedMap[ key ] = sm;
331           }
332         }
333       }
334     }
335   }
336
337   return ret;
338 }
339
340 //=======================================================================
341 //function : checkMissing
342 //purpose  : notify on missing hypothesis
343 //           Return false if algo or hipothesis is missing
344 //=======================================================================
345
346 static bool checkMissing(SMESH_Gen*                aGen,
347                          SMESH_Mesh&               aMesh,
348                          SMESH_subMesh*            aSubMesh,
349                          const int                 aTopAlgoDim,
350                          bool*                     globalChecked,
351                          const bool                checkNoAlgo,
352                          map<int, SMESH_subMesh*>& aCheckedMap,
353                          list< SMESH_Gen::TAlgoStateError > & theErrors)
354 {
355   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
356     return true;
357
358   //MESSAGE("=====checkMissing");
359
360   int ret = true;
361   SMESH_Algo* algo = 0;
362
363   switch (aSubMesh->GetAlgoState())
364   {
365   case SMESH_subMesh::NO_ALGO: {
366     if (checkNoAlgo)
367     {
368       // should there be any algo?
369       int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
370       if (aTopAlgoDim > shapeDim)
371       {
372         MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
373         ret = false;
374         theErrors.push_back( SMESH_Gen::TAlgoStateError() );
375         theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
376       }
377     }
378     return ret;
379   }
380   case SMESH_subMesh::MISSING_HYP: {
381     // notify if an algo missing hyp is attached to aSubMesh
382     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
383     ASSERT( algo );
384     bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
385     if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
386     {
387       TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
388       SMESH_Hypothesis::Hypothesis_Status status;
389       algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
390       if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
391         MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
392                  << "<" << algo->GetName() << "> has a bad parameter value");
393         errName = status;
394       } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
395         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
396                  << "<" << algo->GetName() << "> assigned to mismatching geometry");
397         errName = status;
398       } else {
399         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
400                  << "<" << algo->GetName() << "> misses some hypothesis");
401       }
402       if (IsGlobalHypothesis)
403         globalChecked[ algo->GetDim() ] = true;
404       theErrors.push_back( SMESH_Gen::TAlgoStateError() );
405       theErrors.back().Set( errName, algo, IsGlobalHypothesis );
406     }
407     ret = false;
408     break;
409   }
410   case SMESH_subMesh::HYP_OK:
411     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
412     ret = true;
413     break;
414   default: ASSERT(0);
415   }
416
417   // do not check under algo that hides sub-algos or
418   // re-start checking NO_ALGO state
419   ASSERT (algo);
420   bool isTopLocalAlgo =
421     ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
422   if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
423   {
424     bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
425     const map<int, SMESH_subMesh*>& subMeshes = aSubMesh->DependsOn();
426     map<int, SMESH_subMesh*>::const_iterator itsub;
427     for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
428     {
429       // sub-meshes should not be checked further more
430       int key = (*itsub).first;
431       SMESH_subMesh* sm = (*itsub).second;
432       if ( aCheckedMap.find( key ) == aCheckedMap.end() )
433         aCheckedMap[ key ] = sm;
434
435       if (isTopLocalAlgo)
436       {
437         //check algo on sub-meshes
438         int aTopAlgoDim2 = algo->GetDim();
439         if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
440                            globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
441         {
442           ret = false;
443           if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
444             checkNoAlgo2 = false;
445         }
446       }
447     }
448   }
449   return ret;
450 }
451
452 //=======================================================================
453 //function : CheckAlgoState
454 //purpose  : notify on bad state of attached algos, return false
455 //           if Compute() would fail because of some algo bad state
456 //=======================================================================
457
458 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
459 {
460   list< TAlgoStateError > errors;
461   return GetAlgoState( aMesh, aShape, errors );
462 }
463
464 //=======================================================================
465 //function : GetAlgoState
466 //purpose  : notify on bad state of attached algos, return false
467 //           if Compute() would fail because of some algo bad state
468 //           theErrors list contains problems description
469 //=======================================================================
470
471 bool SMESH_Gen::GetAlgoState(SMESH_Mesh&               theMesh,
472                              const TopoDS_Shape&       theShape,
473                              list< TAlgoStateError > & theErrors)
474 {
475   //MESSAGE("SMESH_Gen::CheckAlgoState");
476
477   bool ret = true;
478   bool hasAlgo = false;
479
480   SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
481   const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
482   TopoDS_Shape mainShape = meshDS->ShapeToMesh();
483
484   // -----------------
485   // get global algos
486   // -----------------
487
488   const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
489
490   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
491   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
492   for ( ; it != listHyp.end(); it++)
493   {
494     const SMESHDS_Hypothesis * aHyp = *it;
495     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
496       continue;
497
498     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
499     ASSERT ( algo );
500
501     int dim = algo->GetDim();
502     aGlobAlgoArr[ dim ] = algo;
503
504     hasAlgo = true;
505   }
506
507   // --------------------------------------------------------
508   // info on algos that will be ignored because of ones that
509   // don't NeedDescretBoundary() attached to super-shapes,
510   // check that a conform mesh will be produced
511   // --------------------------------------------------------
512
513
514   // find a global algo possibly hiding sub-algos
515   int dim;
516   const SMESH_Algo* aGlobIgnoAlgo = 0;
517   for (dim = 3; dim > 0; dim--)
518   {
519     if (aGlobAlgoArr[ dim ] &&
520         !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
521     {
522       aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
523       break;
524     }
525   }
526
527   const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
528   map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
529   map<int, SMESH_subMesh*> aCheckedMap;
530   bool checkConform = ( !theMesh.IsNotConformAllowed() );
531   int aKey = 1;
532   SMESH_subMesh* smToCheck = sm;
533
534   // loop on theShape and its sub-shapes
535   while ( smToCheck )
536   {
537     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
538       break;
539
540     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
541       if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
542                                      0, checkConform, aCheckedMap, theErrors))
543         ret = false;
544
545     if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
546       hasAlgo = true;
547
548     // next subMesh
549     if (revItSub != smMap.rend())
550     {
551       aKey = (*revItSub).first;
552       smToCheck = (*revItSub).second;
553       revItSub++;
554     }
555     else
556     {
557       smToCheck = 0;
558     }
559
560   }
561
562   // ----------------------------------------------------------------
563   // info on missing hypothesis and find out if all needed algos are
564   // well defined
565   // ----------------------------------------------------------------
566
567   //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
568
569   // find max dim of global algo
570   int aTopAlgoDim = 0;
571   for (dim = 3; dim > 0; dim--)
572   {
573     if (aGlobAlgoArr[ dim ])
574     {
575       aTopAlgoDim = dim;
576       break;
577     }
578   }
579   aCheckedMap.clear();
580   smToCheck = sm;
581   revItSub = smMap.rbegin();
582   bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
583   bool globalChecked[] = { false, false, false, false };
584
585   // loop on theShape and its sub-shapes
586   while ( smToCheck )
587   {
588     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
589       break;
590
591     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
592       if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
593                          globalChecked, checkNoAlgo, aCheckedMap, theErrors))
594       {
595         ret = false;
596         if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
597           checkNoAlgo = false;
598       }
599
600     // next subMesh
601     if (revItSub != smMap.rend())
602     {
603       aKey = (*revItSub).first;
604       smToCheck = (*revItSub).second;
605       revItSub++;
606     }
607     else
608       smToCheck = 0;
609   }
610
611   if ( !hasAlgo ) {
612     ret = false;
613     INFOS( "None algorithm attached" );
614     theErrors.push_back( TAlgoStateError() );
615     theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
616   }
617
618   return ret;
619 }
620
621 //=======================================================================
622 //function : IsGlobalHypothesis
623 //purpose  : check if theAlgo is attached to the main shape
624 //=======================================================================
625
626 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
627 {
628   SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
629   return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
630 }
631
632 //=============================================================================
633 /*!
634  *
635  */
636 //=============================================================================
637
638 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh &         aMesh,
639                                const TopoDS_Shape & aShape,
640                                TopoDS_Shape*        assignedTo)
641 {
642
643   SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
644   filter.And( filter.IsApplicableTo( aShape ));
645
646   return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
647 }
648
649 //=============================================================================
650 /*!
651  *
652  */
653 //=============================================================================
654
655 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
656 {
657         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
658
659         if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
660         {
661                 _mapStudyContext[studyId] = new StudyContextStruct;
662                 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
663         }
664         StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
665 //   ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
666         return myStudyContext;
667 }
668
669 //=============================================================================
670 /*!
671  *
672  */
673 //=============================================================================
674
675 void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
676 {
677 }
678
679 //=============================================================================
680 /*!
681  *
682  */
683 //=============================================================================
684
685 void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
686 {
687 }
688
689 //=============================================================================
690 /*!
691  *
692  */
693 //=============================================================================
694
695 void SMESH_Gen::Close(int studyId)
696 {
697 }
698
699 //=============================================================================
700 /*!
701  *
702  */
703 //=============================================================================
704
705 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
706 {
707   static vector<int> dim;
708   if ( dim.empty() )
709   {
710     dim.resize( TopAbs_SHAPE, -1 );
711     dim[ TopAbs_COMPOUND ]  = 3;
712     dim[ TopAbs_COMPSOLID ] = 3;
713     dim[ TopAbs_SOLID ]     = 3;
714     dim[ TopAbs_SHELL ]     = 3;
715     dim[ TopAbs_FACE  ]     = 2;
716     dim[ TopAbs_WIRE ]      = 1;
717     dim[ TopAbs_EDGE ]      = 1;
718     dim[ TopAbs_VERTEX ]    = 0;
719   }
720   return dim[ aShapeType ];
721 }
722
723 //=============================================================================
724 /*!
725  *
726  */
727 //=============================================================================
728
729 int SMESH_Gen::GetANewId()
730 {
731         //MESSAGE("SMESH_Gen::GetANewId");
732         return _hypId++;
733 }