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