1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : SMESH_Gen.cxx
24 // Author : Paul RASCLE, EDF
27 #include "SMESH_Gen.hxx"
28 #include "SMESH_subMesh.hxx"
29 #include "SMESH_HypoFilter.hxx"
30 #include "SMESHDS_Document.hxx"
31 #include "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
34 #include "utilities.h"
36 #include "Utils_ExceptHandlers.hxx"
39 #include <BRep_Tool.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 //=============================================================================
47 * default constructor:
49 //=============================================================================
51 SMESH_Gen::SMESH_Gen()
53 MESSAGE("SMESH_Gen::SMESH_Gen");
59 //=============================================================================
63 //=============================================================================
65 SMESH_Gen::~SMESH_Gen()
67 MESSAGE("SMESH_Gen::~SMESH_Gen");
70 //=============================================================================
74 //=============================================================================
76 /*SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
77 throw(SALOME_Exception)
80 MESSAGE("CreateHypothesis("<<anHyp<<","<<studyId<<")");
81 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
83 StudyContextStruct *myStudyContext = GetStudyContext(studyId);
85 // create a new hypothesis object, store its ref. in studyContext
87 SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId);
88 int hypId = myHypothesis->GetID();
89 myStudyContext->mapHypothesis[hypId] = myHypothesis;
93 // store hypothesis in SMESHDS document
95 myStudyContext->myDocument->AddHypothesis(myHypothesis);
99 //=============================================================================
103 //=============================================================================
105 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
106 throw(SALOME_Exception)
108 Unexpect aCatch(SalomeException);
109 MESSAGE("SMESH_Gen::CreateMesh");
111 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
112 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
114 // create a new SMESH_mesh object
115 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
119 aStudyContext->myDocument);
120 aStudyContext->mapMesh[_localId] = aMesh;
125 //=============================================================================
129 //=============================================================================
131 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
132 const TopoDS_Shape & aShape,
134 const ::MeshDimension aDim,
135 TSetOfInt* aShapesId)
137 MESSAGE("SMESH_Gen::Compute");
141 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
143 const bool includeSelf = true;
144 const bool complexShapeFirst = true;
146 SMESH_subMeshIteratorPtr smIt;
148 if ( anUpward ) // is called from below code here
150 // -----------------------------------------------
151 // mesh all the subshapes starting from vertices
152 // -----------------------------------------------
153 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
154 while ( smIt->more() )
156 SMESH_subMesh* smToCompute = smIt->next();
158 // do not mesh vertices of a pseudo shape
159 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
160 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
163 // check for preview dimension limitations
164 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
166 // clear compute state to not show previous compute errors
167 // if preview invoked less dimension less than previous
168 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
172 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
173 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
175 // we check all the submeshes here and detect if any of them failed to compute
176 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
178 else if ( aShapesId )
179 aShapesId->insert( smToCompute->GetId() );
185 // -----------------------------------------------------------------
186 // apply algos that DO NOT require descretized boundaries and DO NOT
187 // support submeshes, starting from the most complex shapes
188 // and collect submeshes with algos that DO support submeshes
189 // -----------------------------------------------------------------
190 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
191 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
192 while ( smIt->more() )
194 SMESH_subMesh* smToCompute = smIt->next();
195 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
198 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
199 const int aShapeDim = GetShapeDim( aSubShape );
200 if ( aShapeDim < 1 ) break;
202 // check for preview dimension limitations
203 if ( aShapesId && aShapeDim > (int)aDim )
206 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
207 if ( algo && !algo->NeedDescretBoundary() )
209 if ( algo->SupportSubmeshes() )
210 smWithAlgoSupportingSubmeshes.push_back( smToCompute );
213 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
215 aShapesId->insert( smToCompute->GetId() );
219 // ------------------------------------------------------------
220 // compute submeshes under shapes with algos that DO NOT require
221 // descretized boundaries and DO support submeshes
222 // ------------------------------------------------------------
223 list< SMESH_subMesh* >::reverse_iterator subIt, subEnd;
224 subIt = smWithAlgoSupportingSubmeshes.rbegin();
225 subEnd = smWithAlgoSupportingSubmeshes.rend();
226 // start from lower shapes
227 for ( ; subIt != subEnd; ++subIt )
231 // get a shape the algo is assigned to
232 TopoDS_Shape algoShape;
233 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
234 continue; // strange...
236 // look for more local algos
237 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
238 while ( smIt->more() )
240 SMESH_subMesh* smToCompute = smIt->next();
242 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
243 const int aShapeDim = GetShapeDim( aSubShape );
244 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
245 if ( aShapeDim < 1 ) continue;
247 // check for preview dimension limitations
248 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
251 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
253 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
254 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
256 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
257 SMESH_Hypothesis::Hypothesis_Status status;
258 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
259 // mesh a lower smToCompute starting from vertices
260 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
264 // ----------------------------------------------------------
265 // apply the algos that do not require descretized boundaries
266 // ----------------------------------------------------------
267 for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt )
268 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
270 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
271 // check for preview dimension limitations
272 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
275 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
277 aShapesId->insert( sm->GetId() );
280 // -----------------------------------------------
281 // mesh the rest subshapes starting from vertices
282 // -----------------------------------------------
283 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
286 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
291 //=============================================================================
295 //=============================================================================
297 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
298 const TopoDS_Shape & aShape,
299 MapShapeNbElems& aResMap,
301 TSetOfInt* aShapesId)
303 MESSAGE("SMESH_Gen::Evaluate");
307 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
309 const bool includeSelf = true;
310 const bool complexShapeFirst = true;
311 SMESH_subMeshIteratorPtr smIt;
313 if ( anUpward ) { // is called from below code here
314 // -----------------------------------------------
315 // mesh all the subshapes starting from vertices
316 // -----------------------------------------------
317 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
318 while ( smIt->more() ) {
319 SMESH_subMesh* smToCompute = smIt->next();
321 // do not mesh vertices of a pseudo shape
322 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
323 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
325 if ( !aMesh.HasShapeToMesh() ) {
326 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
327 aShType == TopAbs_SHELL )
331 smToCompute->Evaluate(aResMap);
333 aShapesId->insert( smToCompute->GetId() );
338 // -----------------------------------------------------------------
339 // apply algos that DO NOT require descretized boundaries and DO NOT
340 // support submeshes, starting from the most complex shapes
341 // and collect submeshes with algos that DO support submeshes
342 // -----------------------------------------------------------------
343 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
344 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
345 while ( smIt->more() ) {
346 SMESH_subMesh* smToCompute = smIt->next();
347 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
348 const int aShapeDim = GetShapeDim( aSubShape );
349 if ( aShapeDim < 1 ) break;
351 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
352 if ( algo && !algo->NeedDescretBoundary() ) {
353 if ( algo->SupportSubmeshes() ) {
354 smWithAlgoSupportingSubmeshes.push_back( smToCompute );
357 smToCompute->Evaluate(aResMap);
359 aShapesId->insert( smToCompute->GetId() );
363 // ------------------------------------------------------------
364 // compute submeshes under shapes with algos that DO NOT require
365 // descretized boundaries and DO support submeshes
366 // ------------------------------------------------------------
367 list< SMESH_subMesh* >::reverse_iterator subIt, subEnd;
368 subIt = smWithAlgoSupportingSubmeshes.rbegin();
369 subEnd = smWithAlgoSupportingSubmeshes.rend();
370 // start from lower shapes
371 for ( ; subIt != subEnd; ++subIt ) {
374 // get a shape the algo is assigned to
375 TopoDS_Shape algoShape;
376 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
377 continue; // strange...
379 // look for more local algos
380 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
381 while ( smIt->more() ) {
382 SMESH_subMesh* smToCompute = smIt->next();
384 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
385 const int aShapeDim = GetShapeDim( aSubShape );
386 if ( aShapeDim < 1 ) continue;
388 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
390 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
392 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
393 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
395 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
396 SMESH_Hypothesis::Hypothesis_Status status;
397 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
398 // mesh a lower smToCompute starting from vertices
399 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
403 // ----------------------------------------------------------
404 // apply the algos that do not require descretized boundaries
405 // ----------------------------------------------------------
406 for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt ) {
407 sm->Evaluate(aResMap);
409 aShapesId->insert( sm->GetId() );
412 // -----------------------------------------------
413 // mesh the rest subshapes starting from vertices
414 // -----------------------------------------------
415 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
418 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
423 //=======================================================================
424 //function : checkConformIgnoredAlgos
426 //=======================================================================
428 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
429 SMESH_subMesh* aSubMesh,
430 const SMESH_Algo* aGlobIgnoAlgo,
431 const SMESH_Algo* aLocIgnoAlgo,
433 map<int, SMESH_subMesh*>& aCheckedMap,
434 list< SMESH_Gen::TAlgoStateError > & theErrors)
437 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
443 const list<const SMESHDS_Hypothesis*>& listHyp =
444 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
445 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
446 for ( ; it != listHyp.end(); it++)
448 const SMESHDS_Hypothesis * aHyp = *it;
449 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
452 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
455 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
457 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
458 << aLocIgnoAlgo->GetName() << ">");
462 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
463 int dim = algo->GetDim();
464 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
466 if ( dim < aMaxGlobIgnoDim )
468 // algo is hidden by a global algo
469 INFOS( ( isGlobal ? "Global" : "Local" )
470 << " <" << algo->GetName() << "> is hidden by global <"
471 << aGlobIgnoAlgo->GetName() << ">");
473 else if ( !algo->NeedDescretBoundary() && !isGlobal)
475 // local algo is not hidden and hides algos on sub-shapes
476 if (checkConform && !aSubMesh->IsConform( algo ))
479 checkConform = false; // no more check conformity
480 INFOS( "ERROR: Local <" << algo->GetName() <<
481 "> would produce not conform mesh: "
482 "<Not Conform Mesh Allowed> hypotesis is missing");
483 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
484 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
487 // sub-algos will be hidden by a local <algo>
488 const map<int, SMESH_subMesh*>& smMap = aSubMesh->DependsOn();
489 map<int, SMESH_subMesh*>::const_reverse_iterator revItSub;
490 bool checkConform2 = false;
491 for ( revItSub = smMap.rbegin(); revItSub != smMap.rend(); revItSub++)
493 checkConformIgnoredAlgos (aMesh, (*revItSub).second, aGlobIgnoAlgo,
494 algo, checkConform2, aCheckedMap, theErrors);
495 int key = (*revItSub).first;
496 SMESH_subMesh* sm = (*revItSub).second;
497 if ( aCheckedMap.find( key ) == aCheckedMap.end() )
499 aCheckedMap[ key ] = sm;
509 //=======================================================================
510 //function : checkMissing
511 //purpose : notify on missing hypothesis
512 // Return false if algo or hipothesis is missing
513 //=======================================================================
515 static bool checkMissing(SMESH_Gen* aGen,
517 SMESH_subMesh* aSubMesh,
518 const int aTopAlgoDim,
520 const bool checkNoAlgo,
521 map<int, SMESH_subMesh*>& aCheckedMap,
522 list< SMESH_Gen::TAlgoStateError > & theErrors)
524 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
527 //MESSAGE("=====checkMissing");
530 SMESH_Algo* algo = 0;
532 switch (aSubMesh->GetAlgoState())
534 case SMESH_subMesh::NO_ALGO: {
537 // should there be any algo?
538 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
539 if (aTopAlgoDim > shapeDim)
541 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
543 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
544 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
549 case SMESH_subMesh::MISSING_HYP: {
550 // notify if an algo missing hyp is attached to aSubMesh
551 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
553 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
554 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
556 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
557 SMESH_Hypothesis::Hypothesis_Status status;
558 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
559 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
560 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
561 << "<" << algo->GetName() << "> has a bad parameter value");
563 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
564 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
565 << "<" << algo->GetName() << "> assigned to mismatching geometry");
568 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
569 << "<" << algo->GetName() << "> misses some hypothesis");
571 if (IsGlobalHypothesis)
572 globalChecked[ algo->GetDim() ] = true;
573 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
574 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
579 case SMESH_subMesh::HYP_OK:
580 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
586 // do not check under algo that hides sub-algos or
587 // re-start checking NO_ALGO state
589 bool isTopLocalAlgo =
590 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
591 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
593 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
594 const map<int, SMESH_subMesh*>& subMeshes = aSubMesh->DependsOn();
595 map<int, SMESH_subMesh*>::const_iterator itsub;
596 for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
598 // sub-meshes should not be checked further more
599 int key = (*itsub).first;
600 SMESH_subMesh* sm = (*itsub).second;
601 if ( aCheckedMap.find( key ) == aCheckedMap.end() )
602 aCheckedMap[ key ] = sm;
606 //check algo on sub-meshes
607 int aTopAlgoDim2 = algo->GetDim();
608 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
609 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
612 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
613 checkNoAlgo2 = false;
621 //=======================================================================
622 //function : CheckAlgoState
623 //purpose : notify on bad state of attached algos, return false
624 // if Compute() would fail because of some algo bad state
625 //=======================================================================
627 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
629 list< TAlgoStateError > errors;
630 return GetAlgoState( aMesh, aShape, errors );
633 //=======================================================================
634 //function : GetAlgoState
635 //purpose : notify on bad state of attached algos, return false
636 // if Compute() would fail because of some algo bad state
637 // theErrors list contains problems description
638 //=======================================================================
640 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
641 const TopoDS_Shape& theShape,
642 list< TAlgoStateError > & theErrors)
644 //MESSAGE("SMESH_Gen::CheckAlgoState");
647 bool hasAlgo = false;
649 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
650 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
651 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
657 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
659 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
660 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
661 for ( ; it != listHyp.end(); it++)
663 const SMESHDS_Hypothesis * aHyp = *it;
664 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
667 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
670 int dim = algo->GetDim();
671 aGlobAlgoArr[ dim ] = algo;
676 // --------------------------------------------------------
677 // info on algos that will be ignored because of ones that
678 // don't NeedDescretBoundary() attached to super-shapes,
679 // check that a conform mesh will be produced
680 // --------------------------------------------------------
683 // find a global algo possibly hiding sub-algos
685 const SMESH_Algo* aGlobIgnoAlgo = 0;
686 for (dim = 3; dim > 0; dim--)
688 if (aGlobAlgoArr[ dim ] &&
689 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
691 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
696 const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
697 map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
698 map<int, SMESH_subMesh*> aCheckedMap;
699 bool checkConform = ( !theMesh.IsNotConformAllowed() );
701 SMESH_subMesh* smToCheck = sm;
703 // loop on theShape and its sub-shapes
706 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
709 if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
710 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
711 0, checkConform, aCheckedMap, theErrors))
714 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
718 if (revItSub != smMap.rend())
720 aKey = (*revItSub).first;
721 smToCheck = (*revItSub).second;
731 // ----------------------------------------------------------------
732 // info on missing hypothesis and find out if all needed algos are
734 // ----------------------------------------------------------------
736 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
738 // find max dim of global algo
740 for (dim = 3; dim > 0; dim--)
742 if (aGlobAlgoArr[ dim ])
750 revItSub = smMap.rbegin();
751 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
752 bool globalChecked[] = { false, false, false, false };
754 // loop on theShape and its sub-shapes
757 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
760 if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
761 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
762 globalChecked, checkNoAlgo, aCheckedMap, theErrors))
765 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
770 if (revItSub != smMap.rend())
772 aKey = (*revItSub).first;
773 smToCheck = (*revItSub).second;
782 INFOS( "None algorithm attached" );
783 theErrors.push_back( TAlgoStateError() );
784 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
790 //=======================================================================
791 //function : IsGlobalHypothesis
792 //purpose : check if theAlgo is attached to the main shape
793 //=======================================================================
795 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
797 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
798 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
801 //=============================================================================
805 //=============================================================================
807 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
808 const TopoDS_Shape & aShape,
809 TopoDS_Shape* assignedTo)
812 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
813 filter.And( filter.IsApplicableTo( aShape ));
815 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
818 //=============================================================================
822 //=============================================================================
824 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
826 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
828 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
830 _mapStudyContext[studyId] = new StudyContextStruct;
831 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
833 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
834 // ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
835 return myStudyContext;
838 // //=============================================================================
842 // //=============================================================================
844 // void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
848 // //=============================================================================
852 // //=============================================================================
854 // void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
858 // //=============================================================================
862 // //=============================================================================
864 // void SMESH_Gen::Close(int studyId)
868 //=============================================================================
872 //=============================================================================
874 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
876 static vector<int> dim;
879 dim.resize( TopAbs_SHAPE, -1 );
880 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
881 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
882 dim[ TopAbs_SOLID ] = MeshDim_3D;
883 dim[ TopAbs_SHELL ] = MeshDim_3D;
884 dim[ TopAbs_FACE ] = MeshDim_2D;
885 dim[ TopAbs_WIRE ] = MeshDim_1D;
886 dim[ TopAbs_EDGE ] = MeshDim_1D;
887 dim[ TopAbs_VERTEX ] = MeshDim_0D;
889 return dim[ aShapeType ];
892 //=============================================================================
896 //=============================================================================
898 int SMESH_Gen::GetANewId()
900 //MESSAGE("SMESH_Gen::GetANewId");