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
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 #include "SMDS_Mesh.hxx"
37 #include "utilities.h"
39 #include "Utils_ExceptHandlers.hxx"
42 #include <BRep_Tool.hxx>
43 #include <TopTools_ListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 //=============================================================================
54 //=============================================================================
56 SMESH_Gen::SMESH_Gen()
58 MESSAGE("SMESH_Gen::SMESH_Gen");
61 _segmentation = _nbSegments = 10;
62 SMDS_Mesh::_meshList.clear();
63 MESSAGE(SMDS_Mesh::_meshList.size());
64 _counters = new counters(100);
65 #ifdef WITH_SMESH_CANCEL_COMPUTE
66 _compute_canceled = false;
71 //=============================================================================
75 //=============================================================================
77 SMESH_Gen::~SMESH_Gen()
79 MESSAGE("SMESH_Gen::~SMESH_Gen");
82 //=============================================================================
84 * Creates a mesh in a study.
85 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
87 //=============================================================================
89 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
90 throw(SALOME_Exception)
92 Unexpect aCatch(SalomeException);
93 MESSAGE("SMESH_Gen::CreateMesh");
95 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
96 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
98 // create a new SMESH_mesh object
99 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
103 aStudyContext->myDocument);
104 aStudyContext->mapMesh[_localId] = aMesh;
109 //=============================================================================
113 //=============================================================================
115 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
116 const TopoDS_Shape & aShape,
118 const ::MeshDimension aDim,
119 TSetOfInt* aShapesId)
121 MESSAGE("SMESH_Gen::Compute");
126 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
128 const bool includeSelf = true;
129 const bool complexShapeFirst = true;
131 SMESH_subMeshIteratorPtr smIt;
133 if ( anUpward ) // is called from below code here
135 // -----------------------------------------------
136 // mesh all the subshapes starting from vertices
137 // -----------------------------------------------
138 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
139 while ( smIt->more() )
141 SMESH_subMesh* smToCompute = smIt->next();
143 // do not mesh vertices of a pseudo shape
144 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
145 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
148 // check for preview dimension limitations
149 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
151 // clear compute state to not show previous compute errors
152 // if preview invoked less dimension less than previous
153 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
157 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
159 #ifdef WITH_SMESH_CANCEL_COMPUTE
160 if (_compute_canceled)
162 _sm_current = smToCompute;
164 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
165 #ifdef WITH_SMESH_CANCEL_COMPUTE
170 // we check all the submeshes here and detect if any of them failed to compute
171 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
173 else if ( aShapesId )
174 aShapesId->insert( smToCompute->GetId() );
176 //aMesh.GetMeshDS()->Modified();
181 // -----------------------------------------------------------------
182 // apply algos that DO NOT require descretized boundaries and DO NOT
183 // support submeshes, starting from the most complex shapes
184 // and collect submeshes with algos that DO support submeshes
185 // -----------------------------------------------------------------
186 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
188 // map to sort sm with same dim algos according to dim of
189 // the shape the algo assigned to (issue 0021217)
190 multimap< int, SMESH_subMesh* > shDim2sm;
191 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
192 TopoDS_Shape algoShape;
193 int prevShapeDim = -1;
195 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
196 while ( smIt->more() )
198 SMESH_subMesh* smToCompute = smIt->next();
199 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
202 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
203 int aShapeDim = GetShapeDim( aSubShape );
204 if ( aShapeDim < 1 ) break;
206 // check for preview dimension limitations
207 if ( aShapesId && aShapeDim > (int)aDim )
210 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
211 if ( algo && !algo->NeedDescretBoundary() )
213 if ( algo->SupportSubmeshes() )
215 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
216 if ( prevShapeDim != aShapeDim )
218 prevShapeDim = aShapeDim;
219 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
220 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
223 // add smToCompute to shDim2sm map
224 aShapeDim = GetShapeDim( algoShape );
225 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
229 #ifdef WITH_SMESH_CANCEL_COMPUTE
230 if (_compute_canceled)
232 _sm_current = smToCompute;
234 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
235 #ifdef WITH_SMESH_CANCEL_COMPUTE
239 aShapesId->insert( smToCompute->GetId() );
243 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
244 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
245 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
247 // ------------------------------------------------------------
248 // sort list of submeshes according to mesh order
249 // ------------------------------------------------------------
250 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
252 // ------------------------------------------------------------
253 // compute submeshes under shapes with algos that DO NOT require
254 // descretized boundaries and DO support submeshes
255 // ------------------------------------------------------------
256 list< SMESH_subMesh* >::iterator subIt, subEnd;
257 subIt = smWithAlgoSupportingSubmeshes.begin();
258 subEnd = smWithAlgoSupportingSubmeshes.end();
259 // start from lower shapes
260 for ( ; subIt != subEnd; ++subIt )
264 // get a shape the algo is assigned to
265 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
266 continue; // strange...
268 // look for more local algos
269 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
270 while ( smIt->more() )
272 SMESH_subMesh* smToCompute = smIt->next();
274 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
275 const int aShapeDim = GetShapeDim( aSubShape );
276 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
277 if ( aShapeDim < 1 ) continue;
279 // check for preview dimension limitations
280 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
283 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
285 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
286 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
288 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
289 SMESH_Hypothesis::Hypothesis_Status status;
290 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
291 // mesh a lower smToCompute starting from vertices
292 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
296 // ----------------------------------------------------------
297 // apply the algos that do not require descretized boundaries
298 // ----------------------------------------------------------
299 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
302 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
304 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
305 // check for preview dimension limitations
306 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
309 #ifdef WITH_SMESH_CANCEL_COMPUTE
310 if (_compute_canceled)
314 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
315 #ifdef WITH_SMESH_CANCEL_COMPUTE
319 aShapesId->insert( sm->GetId() );
322 // -----------------------------------------------
323 // mesh the rest subshapes starting from vertices
324 // -----------------------------------------------
325 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
328 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
331 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
332 myMesh->adjustStructure();
333 MESSAGE("*** compactMesh after compute");
334 myMesh->compactMesh();
335 //myMesh->adjustStructure();
336 list<int> listind = myMesh->SubMeshIndices();
337 list<int>::iterator it = listind.begin();
339 for(; it != listind.end(); ++it)
341 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
342 total += subMesh->getSize();
344 MESSAGE("total elements and nodes in submesh sets:" << total);
345 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
346 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
347 //myMesh->dumpGrid();
348 //aMesh.GetMeshDS()->Modified();
353 #ifdef WITH_SMESH_CANCEL_COMPUTE
354 //=============================================================================
356 * Prepare Compute a mesh
358 //=============================================================================
359 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
360 const TopoDS_Shape & aShape)
362 _compute_canceled = false;
365 //=============================================================================
367 * Cancel Compute a mesh
369 //=============================================================================
370 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
371 const TopoDS_Shape & aShape)
373 _compute_canceled = true;
376 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
381 //=============================================================================
385 //=============================================================================
387 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
388 const TopoDS_Shape & aShape,
389 MapShapeNbElems& aResMap,
391 TSetOfInt* aShapesId)
393 MESSAGE("SMESH_Gen::Evaluate");
397 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
399 const bool includeSelf = true;
400 const bool complexShapeFirst = true;
401 SMESH_subMeshIteratorPtr smIt;
403 if ( anUpward ) { // is called from below code here
404 // -----------------------------------------------
405 // mesh all the subshapes starting from vertices
406 // -----------------------------------------------
407 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
408 while ( smIt->more() ) {
409 SMESH_subMesh* smToCompute = smIt->next();
411 // do not mesh vertices of a pseudo shape
412 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
413 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
415 if ( !aMesh.HasShapeToMesh() ) {
416 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
417 aShType == TopAbs_SHELL )
421 smToCompute->Evaluate(aResMap);
423 aShapesId->insert( smToCompute->GetId() );
428 // -----------------------------------------------------------------
429 // apply algos that DO NOT require descretized boundaries and DO NOT
430 // support submeshes, starting from the most complex shapes
431 // and collect submeshes with algos that DO support submeshes
432 // -----------------------------------------------------------------
433 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
434 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
435 while ( smIt->more() ) {
436 SMESH_subMesh* smToCompute = smIt->next();
437 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
438 const int aShapeDim = GetShapeDim( aSubShape );
439 if ( aShapeDim < 1 ) break;
441 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
442 if ( algo && !algo->NeedDescretBoundary() ) {
443 if ( algo->SupportSubmeshes() ) {
444 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
447 smToCompute->Evaluate(aResMap);
449 aShapesId->insert( smToCompute->GetId() );
454 // ------------------------------------------------------------
455 // sort list of meshes according to mesh order
456 // ------------------------------------------------------------
457 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
459 // ------------------------------------------------------------
460 // compute submeshes under shapes with algos that DO NOT require
461 // descretized boundaries and DO support submeshes
462 // ------------------------------------------------------------
463 list< SMESH_subMesh* >::iterator subIt, subEnd;
464 subIt = smWithAlgoSupportingSubmeshes.begin();
465 subEnd = smWithAlgoSupportingSubmeshes.end();
466 // start from lower shapes
467 for ( ; subIt != subEnd; ++subIt ) {
470 // get a shape the algo is assigned to
471 TopoDS_Shape algoShape;
472 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
473 continue; // strange...
475 // look for more local algos
476 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
477 while ( smIt->more() ) {
478 SMESH_subMesh* smToCompute = smIt->next();
480 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
481 const int aShapeDim = GetShapeDim( aSubShape );
482 if ( aShapeDim < 1 ) continue;
484 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
486 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
488 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
489 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
491 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
492 SMESH_Hypothesis::Hypothesis_Status status;
493 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
494 // mesh a lower smToCompute starting from vertices
495 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
499 // ----------------------------------------------------------
500 // apply the algos that do not require descretized boundaries
501 // ----------------------------------------------------------
502 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
505 sm->Evaluate(aResMap);
507 aShapesId->insert( sm->GetId() );
510 // -----------------------------------------------
511 // mesh the rest subshapes starting from vertices
512 // -----------------------------------------------
513 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
516 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
521 //=======================================================================
522 //function : checkConformIgnoredAlgos
524 //=======================================================================
526 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
527 SMESH_subMesh* aSubMesh,
528 const SMESH_Algo* aGlobIgnoAlgo,
529 const SMESH_Algo* aLocIgnoAlgo,
531 set<SMESH_subMesh*>& aCheckedMap,
532 list< SMESH_Gen::TAlgoStateError > & theErrors)
535 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
541 const list<const SMESHDS_Hypothesis*>& listHyp =
542 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
543 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
544 for ( ; it != listHyp.end(); it++)
546 const SMESHDS_Hypothesis * aHyp = *it;
547 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
550 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
553 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
555 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
556 << aLocIgnoAlgo->GetName() << ">");
560 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
561 int dim = algo->GetDim();
562 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
564 if ( dim < aMaxGlobIgnoDim )
566 // algo is hidden by a global algo
567 INFOS( ( isGlobal ? "Global" : "Local" )
568 << " <" << algo->GetName() << "> is hidden by global <"
569 << aGlobIgnoAlgo->GetName() << ">");
571 else if ( !algo->NeedDescretBoundary() && !isGlobal)
573 // local algo is not hidden and hides algos on sub-shapes
574 if (checkConform && !aSubMesh->IsConform( algo ))
577 checkConform = false; // no more check conformity
578 INFOS( "ERROR: Local <" << algo->GetName() <<
579 "> would produce not conform mesh: "
580 "<Not Conform Mesh Allowed> hypotesis is missing");
581 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
582 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
585 // sub-algos will be hidden by a local <algo>
586 SMESH_subMeshIteratorPtr revItSub =
587 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
588 bool checkConform2 = false;
589 while ( revItSub->more() )
591 SMESH_subMesh* sm = revItSub->next();
592 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
593 algo, checkConform2, aCheckedMap, theErrors);
594 aCheckedMap.insert( sm );
603 //=======================================================================
604 //function : checkMissing
605 //purpose : notify on missing hypothesis
606 // Return false if algo or hipothesis is missing
607 //=======================================================================
609 static bool checkMissing(SMESH_Gen* aGen,
611 SMESH_subMesh* aSubMesh,
612 const int aTopAlgoDim,
614 const bool checkNoAlgo,
615 set<SMESH_subMesh*>& aCheckedMap,
616 list< SMESH_Gen::TAlgoStateError > & theErrors)
618 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
621 //MESSAGE("=====checkMissing");
624 SMESH_Algo* algo = 0;
626 switch (aSubMesh->GetAlgoState())
628 case SMESH_subMesh::NO_ALGO: {
631 // should there be any algo?
632 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
633 if (aTopAlgoDim > shapeDim)
635 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
637 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
638 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
643 case SMESH_subMesh::MISSING_HYP: {
644 // notify if an algo missing hyp is attached to aSubMesh
645 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
647 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
648 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
650 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
651 SMESH_Hypothesis::Hypothesis_Status status;
652 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
653 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
654 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
655 << "<" << algo->GetName() << "> has a bad parameter value");
657 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
658 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
659 << "<" << algo->GetName() << "> assigned to mismatching geometry");
662 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
663 << "<" << algo->GetName() << "> misses some hypothesis");
665 if (IsGlobalHypothesis)
666 globalChecked[ algo->GetDim() ] = true;
667 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
668 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
673 case SMESH_subMesh::HYP_OK:
674 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
680 // do not check under algo that hides sub-algos or
681 // re-start checking NO_ALGO state
683 bool isTopLocalAlgo =
684 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
685 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
687 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
688 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
689 /*complexShapeFirst=*/false);
690 while ( itsub->more() )
692 // sub-meshes should not be checked further more
693 SMESH_subMesh* sm = itsub->next();
694 aCheckedMap.insert( sm );
698 //check algo on sub-meshes
699 int aTopAlgoDim2 = algo->GetDim();
700 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
701 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
704 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
705 checkNoAlgo2 = false;
713 //=======================================================================
714 //function : CheckAlgoState
715 //purpose : notify on bad state of attached algos, return false
716 // if Compute() would fail because of some algo bad state
717 //=======================================================================
719 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
721 list< TAlgoStateError > errors;
722 return GetAlgoState( aMesh, aShape, errors );
725 //=======================================================================
726 //function : GetAlgoState
727 //purpose : notify on bad state of attached algos, return false
728 // if Compute() would fail because of some algo bad state
729 // theErrors list contains problems description
730 //=======================================================================
732 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
733 const TopoDS_Shape& theShape,
734 list< TAlgoStateError > & theErrors)
736 //MESSAGE("SMESH_Gen::CheckAlgoState");
739 bool hasAlgo = false;
741 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
742 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
743 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
749 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
751 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
752 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
753 for ( ; it != listHyp.end(); it++)
755 const SMESHDS_Hypothesis * aHyp = *it;
756 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
759 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
762 int dim = algo->GetDim();
763 aGlobAlgoArr[ dim ] = algo;
768 // --------------------------------------------------------
769 // info on algos that will be ignored because of ones that
770 // don't NeedDescretBoundary() attached to super-shapes,
771 // check that a conform mesh will be produced
772 // --------------------------------------------------------
775 // find a global algo possibly hiding sub-algos
777 const SMESH_Algo* aGlobIgnoAlgo = 0;
778 for (dim = 3; dim > 0; dim--)
780 if (aGlobAlgoArr[ dim ] &&
781 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
783 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
788 set<SMESH_subMesh*> aCheckedSubs;
789 bool checkConform = ( !theMesh.IsNotConformAllowed() );
791 // loop on theShape and its sub-shapes
792 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
793 /*complexShapeFirst=*/true);
794 while ( revItSub->more() )
796 SMESH_subMesh* smToCheck = revItSub->next();
797 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
800 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
801 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
802 0, checkConform, aCheckedSubs, theErrors))
805 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
809 // ----------------------------------------------------------------
810 // info on missing hypothesis and find out if all needed algos are
812 // ----------------------------------------------------------------
814 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
816 // find max dim of global algo
818 for (dim = 3; dim > 0; dim--)
820 if (aGlobAlgoArr[ dim ])
826 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
827 bool globalChecked[] = { false, false, false, false };
829 // loop on theShape and its sub-shapes
830 aCheckedSubs.clear();
831 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
832 while ( revItSub->more() )
834 SMESH_subMesh* smToCheck = revItSub->next();
835 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
838 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
839 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
840 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
843 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
850 INFOS( "None algorithm attached" );
851 theErrors.push_back( TAlgoStateError() );
852 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
858 //=======================================================================
859 //function : IsGlobalHypothesis
860 //purpose : check if theAlgo is attached to the main shape
861 //=======================================================================
863 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
865 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
866 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
869 //=============================================================================
871 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
873 //=============================================================================
875 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
876 const TopoDS_Shape & aShape,
877 TopoDS_Shape* assignedTo)
879 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
880 filter.And( filter.IsApplicableTo( aShape ));
882 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
885 //=============================================================================
887 * Returns StudyContextStruct for a study
889 //=============================================================================
891 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
893 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
895 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
897 _mapStudyContext[studyId] = new StudyContextStruct;
898 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
900 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
901 return myStudyContext;
904 //================================================================================
906 * \brief Return shape dimension by TopAbs_ShapeEnum
908 //================================================================================
910 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
912 static vector<int> dim;
915 dim.resize( TopAbs_SHAPE, -1 );
916 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
917 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
918 dim[ TopAbs_SOLID ] = MeshDim_3D;
919 dim[ TopAbs_SHELL ] = MeshDim_3D;
920 dim[ TopAbs_FACE ] = MeshDim_2D;
921 dim[ TopAbs_WIRE ] = MeshDim_1D;
922 dim[ TopAbs_EDGE ] = MeshDim_1D;
923 dim[ TopAbs_VERTEX ] = MeshDim_0D;
925 return dim[ aShapeType ];
928 //=============================================================================
930 * Genarate a new id unique withing this Gen
932 //=============================================================================
934 int SMESH_Gen::GetANewId()