1 // Copyright (C) 2007-2010 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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : SMESH_Gen.cxx
25 // Author : Paul RASCLE, EDF
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 #include "SMDS_Mesh.hxx"
36 #include "utilities.h"
38 #include "Utils_ExceptHandlers.hxx"
41 #include <BRep_Tool.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
49 //=============================================================================
53 //=============================================================================
55 SMESH_Gen::SMESH_Gen()
57 MESSAGE("SMESH_Gen::SMESH_Gen");
61 SMDS_Mesh::_meshList.clear();
62 MESSAGE(SMDS_Mesh::_meshList.size());
65 //=============================================================================
69 //=============================================================================
71 SMESH_Gen::~SMESH_Gen()
73 MESSAGE("SMESH_Gen::~SMESH_Gen");
76 //=============================================================================
78 * Creates a mesh in a study.
79 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
81 //=============================================================================
83 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
84 throw(SALOME_Exception)
86 Unexpect aCatch(SalomeException);
87 MESSAGE("SMESH_Gen::CreateMesh");
89 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
90 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
92 // create a new SMESH_mesh object
93 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
97 aStudyContext->myDocument);
98 aStudyContext->mapMesh[_localId] = aMesh;
103 //=============================================================================
107 //=============================================================================
109 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
110 const TopoDS_Shape & aShape,
112 const ::MeshDimension aDim,
113 TSetOfInt* aShapesId)
115 MESSAGE("SMESH_Gen::Compute");
120 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
122 const bool includeSelf = true;
123 const bool complexShapeFirst = true;
125 SMESH_subMeshIteratorPtr smIt;
127 if ( anUpward ) // is called from below code here
129 // -----------------------------------------------
130 // mesh all the subshapes starting from vertices
131 // -----------------------------------------------
132 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
133 while ( smIt->more() )
135 SMESH_subMesh* smToCompute = smIt->next();
137 // do not mesh vertices of a pseudo shape
138 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
139 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
142 // check for preview dimension limitations
143 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
145 // clear compute state to not show previous compute errors
146 // if preview invoked less dimension less than previous
147 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
151 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
152 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
154 // we check all the submeshes here and detect if any of them failed to compute
155 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
157 else if ( aShapesId )
158 aShapesId->insert( smToCompute->GetId() );
164 // -----------------------------------------------------------------
165 // apply algos that DO NOT require descretized boundaries and DO NOT
166 // support submeshes, starting from the most complex shapes
167 // and collect submeshes with algos that DO support submeshes
168 // -----------------------------------------------------------------
169 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
170 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
171 while ( smIt->more() )
173 SMESH_subMesh* smToCompute = smIt->next();
174 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
177 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
178 const int aShapeDim = GetShapeDim( aSubShape );
179 if ( aShapeDim < 1 ) break;
181 // check for preview dimension limitations
182 if ( aShapesId && aShapeDim > (int)aDim )
185 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
186 if ( algo && !algo->NeedDescretBoundary() )
188 if ( algo->SupportSubmeshes() )
189 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
192 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
194 aShapesId->insert( smToCompute->GetId() );
199 // ------------------------------------------------------------
200 // sort list of meshes according to mesh order
201 // ------------------------------------------------------------
202 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
204 // ------------------------------------------------------------
205 // compute submeshes under shapes with algos that DO NOT require
206 // descretized boundaries and DO support submeshes
207 // ------------------------------------------------------------
208 list< SMESH_subMesh* >::iterator subIt, subEnd;
209 subIt = smWithAlgoSupportingSubmeshes.begin();
210 subEnd = smWithAlgoSupportingSubmeshes.end();
211 // start from lower shapes
212 for ( ; subIt != subEnd; ++subIt )
216 // get a shape the algo is assigned to
217 TopoDS_Shape algoShape;
218 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
219 continue; // strange...
221 // look for more local algos
222 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
223 while ( smIt->more() )
225 SMESH_subMesh* smToCompute = smIt->next();
227 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
228 const int aShapeDim = GetShapeDim( aSubShape );
229 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
230 if ( aShapeDim < 1 ) continue;
232 // check for preview dimension limitations
233 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
236 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
238 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
239 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
241 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
242 SMESH_Hypothesis::Hypothesis_Status status;
243 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
244 // mesh a lower smToCompute starting from vertices
245 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
249 // ----------------------------------------------------------
250 // apply the algos that do not require descretized boundaries
251 // ----------------------------------------------------------
252 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
255 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
257 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
258 // check for preview dimension limitations
259 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
262 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
264 aShapesId->insert( sm->GetId() );
267 // -----------------------------------------------
268 // mesh the rest subshapes starting from vertices
269 // -----------------------------------------------
270 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
273 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
276 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
277 myMesh->adjustStructure();
278 myMesh->compactMesh();
279 //myMesh->adjustStructure();
280 list<int> listind = myMesh->SubMeshIndices();
281 list<int>::iterator it = listind.begin();
283 for(; it != listind.end(); ++it)
285 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
286 total += subMesh->getSize();
288 MESSAGE("total elements and nodes in submesh sets:" << total);
289 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
290 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
291 //myMesh->dumpGrid();
296 //=============================================================================
300 //=============================================================================
302 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
303 const TopoDS_Shape & aShape,
304 MapShapeNbElems& aResMap,
306 TSetOfInt* aShapesId)
308 MESSAGE("SMESH_Gen::Evaluate");
312 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
314 const bool includeSelf = true;
315 const bool complexShapeFirst = true;
316 SMESH_subMeshIteratorPtr smIt;
318 if ( anUpward ) { // is called from below code here
319 // -----------------------------------------------
320 // mesh all the subshapes starting from vertices
321 // -----------------------------------------------
322 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
323 while ( smIt->more() ) {
324 SMESH_subMesh* smToCompute = smIt->next();
326 // do not mesh vertices of a pseudo shape
327 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
328 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
330 if ( !aMesh.HasShapeToMesh() ) {
331 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
332 aShType == TopAbs_SHELL )
336 smToCompute->Evaluate(aResMap);
338 aShapesId->insert( smToCompute->GetId() );
343 // -----------------------------------------------------------------
344 // apply algos that DO NOT require descretized boundaries and DO NOT
345 // support submeshes, starting from the most complex shapes
346 // and collect submeshes with algos that DO support submeshes
347 // -----------------------------------------------------------------
348 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
349 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
350 while ( smIt->more() ) {
351 SMESH_subMesh* smToCompute = smIt->next();
352 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
353 const int aShapeDim = GetShapeDim( aSubShape );
354 if ( aShapeDim < 1 ) break;
356 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
357 if ( algo && !algo->NeedDescretBoundary() ) {
358 if ( algo->SupportSubmeshes() ) {
359 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
362 smToCompute->Evaluate(aResMap);
364 aShapesId->insert( smToCompute->GetId() );
369 // ------------------------------------------------------------
370 // sort list of meshes according to mesh order
371 // ------------------------------------------------------------
372 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
374 // ------------------------------------------------------------
375 // compute submeshes under shapes with algos that DO NOT require
376 // descretized boundaries and DO support submeshes
377 // ------------------------------------------------------------
378 list< SMESH_subMesh* >::iterator subIt, subEnd;
379 subIt = smWithAlgoSupportingSubmeshes.begin();
380 subEnd = smWithAlgoSupportingSubmeshes.end();
381 // start from lower shapes
382 for ( ; subIt != subEnd; ++subIt ) {
385 // get a shape the algo is assigned to
386 TopoDS_Shape algoShape;
387 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
388 continue; // strange...
390 // look for more local algos
391 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
392 while ( smIt->more() ) {
393 SMESH_subMesh* smToCompute = smIt->next();
395 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
396 const int aShapeDim = GetShapeDim( aSubShape );
397 if ( aShapeDim < 1 ) continue;
399 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
401 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
403 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
404 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
406 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
407 SMESH_Hypothesis::Hypothesis_Status status;
408 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
409 // mesh a lower smToCompute starting from vertices
410 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
414 // ----------------------------------------------------------
415 // apply the algos that do not require descretized boundaries
416 // ----------------------------------------------------------
417 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
420 sm->Evaluate(aResMap);
422 aShapesId->insert( sm->GetId() );
425 // -----------------------------------------------
426 // mesh the rest subshapes starting from vertices
427 // -----------------------------------------------
428 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
431 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
436 //=======================================================================
437 //function : checkConformIgnoredAlgos
439 //=======================================================================
441 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
442 SMESH_subMesh* aSubMesh,
443 const SMESH_Algo* aGlobIgnoAlgo,
444 const SMESH_Algo* aLocIgnoAlgo,
446 set<SMESH_subMesh*>& aCheckedMap,
447 list< SMESH_Gen::TAlgoStateError > & theErrors)
450 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
456 const list<const SMESHDS_Hypothesis*>& listHyp =
457 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
458 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
459 for ( ; it != listHyp.end(); it++)
461 const SMESHDS_Hypothesis * aHyp = *it;
462 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
465 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
468 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
470 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
471 << aLocIgnoAlgo->GetName() << ">");
475 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
476 int dim = algo->GetDim();
477 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
479 if ( dim < aMaxGlobIgnoDim )
481 // algo is hidden by a global algo
482 INFOS( ( isGlobal ? "Global" : "Local" )
483 << " <" << algo->GetName() << "> is hidden by global <"
484 << aGlobIgnoAlgo->GetName() << ">");
486 else if ( !algo->NeedDescretBoundary() && !isGlobal)
488 // local algo is not hidden and hides algos on sub-shapes
489 if (checkConform && !aSubMesh->IsConform( algo ))
492 checkConform = false; // no more check conformity
493 INFOS( "ERROR: Local <" << algo->GetName() <<
494 "> would produce not conform mesh: "
495 "<Not Conform Mesh Allowed> hypotesis is missing");
496 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
497 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
500 // sub-algos will be hidden by a local <algo>
501 SMESH_subMeshIteratorPtr revItSub =
502 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
503 bool checkConform2 = false;
504 while ( revItSub->more() )
506 SMESH_subMesh* sm = revItSub->next();
507 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
508 algo, checkConform2, aCheckedMap, theErrors);
509 aCheckedMap.insert( sm );
518 //=======================================================================
519 //function : checkMissing
520 //purpose : notify on missing hypothesis
521 // Return false if algo or hipothesis is missing
522 //=======================================================================
524 static bool checkMissing(SMESH_Gen* aGen,
526 SMESH_subMesh* aSubMesh,
527 const int aTopAlgoDim,
529 const bool checkNoAlgo,
530 set<SMESH_subMesh*>& aCheckedMap,
531 list< SMESH_Gen::TAlgoStateError > & theErrors)
533 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
536 //MESSAGE("=====checkMissing");
539 SMESH_Algo* algo = 0;
541 switch (aSubMesh->GetAlgoState())
543 case SMESH_subMesh::NO_ALGO: {
546 // should there be any algo?
547 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
548 if (aTopAlgoDim > shapeDim)
550 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
552 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
553 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
558 case SMESH_subMesh::MISSING_HYP: {
559 // notify if an algo missing hyp is attached to aSubMesh
560 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
562 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
563 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
565 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
566 SMESH_Hypothesis::Hypothesis_Status status;
567 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
568 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
569 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
570 << "<" << algo->GetName() << "> has a bad parameter value");
572 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
573 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
574 << "<" << algo->GetName() << "> assigned to mismatching geometry");
577 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
578 << "<" << algo->GetName() << "> misses some hypothesis");
580 if (IsGlobalHypothesis)
581 globalChecked[ algo->GetDim() ] = true;
582 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
583 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
588 case SMESH_subMesh::HYP_OK:
589 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
595 // do not check under algo that hides sub-algos or
596 // re-start checking NO_ALGO state
598 bool isTopLocalAlgo =
599 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
600 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
602 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
603 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
604 /*complexShapeFirst=*/false);
605 while ( itsub->more() )
607 // sub-meshes should not be checked further more
608 SMESH_subMesh* sm = itsub->next();
609 aCheckedMap.insert( sm );
613 //check algo on sub-meshes
614 int aTopAlgoDim2 = algo->GetDim();
615 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
616 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
619 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
620 checkNoAlgo2 = false;
628 //=======================================================================
629 //function : CheckAlgoState
630 //purpose : notify on bad state of attached algos, return false
631 // if Compute() would fail because of some algo bad state
632 //=======================================================================
634 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
636 list< TAlgoStateError > errors;
637 return GetAlgoState( aMesh, aShape, errors );
640 //=======================================================================
641 //function : GetAlgoState
642 //purpose : notify on bad state of attached algos, return false
643 // if Compute() would fail because of some algo bad state
644 // theErrors list contains problems description
645 //=======================================================================
647 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
648 const TopoDS_Shape& theShape,
649 list< TAlgoStateError > & theErrors)
651 //MESSAGE("SMESH_Gen::CheckAlgoState");
654 bool hasAlgo = false;
656 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
657 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
658 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
664 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
666 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
667 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
668 for ( ; it != listHyp.end(); it++)
670 const SMESHDS_Hypothesis * aHyp = *it;
671 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
674 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
677 int dim = algo->GetDim();
678 aGlobAlgoArr[ dim ] = algo;
683 // --------------------------------------------------------
684 // info on algos that will be ignored because of ones that
685 // don't NeedDescretBoundary() attached to super-shapes,
686 // check that a conform mesh will be produced
687 // --------------------------------------------------------
690 // find a global algo possibly hiding sub-algos
692 const SMESH_Algo* aGlobIgnoAlgo = 0;
693 for (dim = 3; dim > 0; dim--)
695 if (aGlobAlgoArr[ dim ] &&
696 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
698 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
703 set<SMESH_subMesh*> aCheckedSubs;
704 bool checkConform = ( !theMesh.IsNotConformAllowed() );
706 // loop on theShape and its sub-shapes
707 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
708 /*complexShapeFirst=*/true);
709 while ( revItSub->more() )
711 SMESH_subMesh* smToCheck = revItSub->next();
712 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
715 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
716 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
717 0, checkConform, aCheckedSubs, theErrors))
720 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
724 // ----------------------------------------------------------------
725 // info on missing hypothesis and find out if all needed algos are
727 // ----------------------------------------------------------------
729 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
731 // find max dim of global algo
733 for (dim = 3; dim > 0; dim--)
735 if (aGlobAlgoArr[ dim ])
741 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
742 bool globalChecked[] = { false, false, false, false };
744 // loop on theShape and its sub-shapes
745 aCheckedSubs.clear();
746 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
747 while ( revItSub->more() )
749 SMESH_subMesh* smToCheck = revItSub->next();
750 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
753 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
754 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
755 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
758 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
765 INFOS( "None algorithm attached" );
766 theErrors.push_back( TAlgoStateError() );
767 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
773 //=======================================================================
774 //function : IsGlobalHypothesis
775 //purpose : check if theAlgo is attached to the main shape
776 //=======================================================================
778 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
780 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
781 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
784 //=============================================================================
786 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
788 //=============================================================================
790 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
791 const TopoDS_Shape & aShape,
792 TopoDS_Shape* assignedTo)
794 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
795 filter.And( filter.IsApplicableTo( aShape ));
797 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
800 //=============================================================================
802 * Returns StudyContextStruct for a study
804 //=============================================================================
806 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
808 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
810 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
812 _mapStudyContext[studyId] = new StudyContextStruct;
813 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
815 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
816 return myStudyContext;
819 //================================================================================
821 * \brief Return shape dimension by TopAbs_ShapeEnum
823 //================================================================================
825 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
827 static vector<int> dim;
830 dim.resize( TopAbs_SHAPE, -1 );
831 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
832 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
833 dim[ TopAbs_SOLID ] = MeshDim_3D;
834 dim[ TopAbs_SHELL ] = MeshDim_3D;
835 dim[ TopAbs_FACE ] = MeshDim_2D;
836 dim[ TopAbs_WIRE ] = MeshDim_1D;
837 dim[ TopAbs_EDGE ] = MeshDim_1D;
838 dim[ TopAbs_VERTEX ] = MeshDim_0D;
840 return dim[ aShapeType ];
843 //=============================================================================
845 * Genarate a new id unique withing this Gen
847 //=============================================================================
849 int SMESH_Gen::GetANewId()