1 // Copyright (C) 2007-2011 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"
41 #include <TopoDS_Iterator.hxx>
47 //=============================================================================
51 //=============================================================================
53 SMESH_Gen::SMESH_Gen()
55 MESSAGE("SMESH_Gen::SMESH_Gen");
58 _segmentation = _nbSegments = 10;
59 SMDS_Mesh::_meshList.clear();
60 MESSAGE(SMDS_Mesh::_meshList.size());
61 _counters = new counters(100);
62 #ifdef WITH_SMESH_CANCEL_COMPUTE
63 _compute_canceled = false;
68 //=============================================================================
72 //=============================================================================
74 SMESH_Gen::~SMESH_Gen()
76 MESSAGE("SMESH_Gen::~SMESH_Gen");
79 //=============================================================================
81 * Creates a mesh in a study.
82 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
84 //=============================================================================
86 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
87 throw(SALOME_Exception)
89 Unexpect aCatch(SalomeException);
90 MESSAGE("SMESH_Gen::CreateMesh");
92 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
93 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
95 // create a new SMESH_mesh object
96 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
100 aStudyContext->myDocument);
101 aStudyContext->mapMesh[_localId] = aMesh;
106 //=============================================================================
110 //=============================================================================
112 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
113 const TopoDS_Shape & aShape,
115 const ::MeshDimension aDim,
116 TSetOfInt* aShapesId)
118 MESSAGE("SMESH_Gen::Compute");
123 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
125 const bool includeSelf = true;
126 const bool complexShapeFirst = true;
128 SMESH_subMeshIteratorPtr smIt;
130 if ( anUpward ) // is called from below code here
132 // -----------------------------------------------
133 // mesh all the subshapes starting from vertices
134 // -----------------------------------------------
135 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
136 while ( smIt->more() )
138 SMESH_subMesh* smToCompute = smIt->next();
140 // do not mesh vertices of a pseudo shape
141 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
142 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
145 // check for preview dimension limitations
146 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
148 // clear compute state to not show previous compute errors
149 // if preview invoked less dimension less than previous
150 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
154 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
156 #ifdef WITH_SMESH_CANCEL_COMPUTE
157 if (_compute_canceled)
159 _sm_current = smToCompute;
161 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
162 #ifdef WITH_SMESH_CANCEL_COMPUTE
167 // we check all the submeshes here and detect if any of them failed to compute
168 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
170 else if ( aShapesId )
171 aShapesId->insert( smToCompute->GetId() );
173 //aMesh.GetMeshDS()->Modified();
178 // -----------------------------------------------------------------
179 // apply algos that DO NOT require descretized boundaries and DO NOT
180 // support submeshes, starting from the most complex shapes
181 // and collect submeshes with algos that DO support submeshes
182 // -----------------------------------------------------------------
183 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
185 // map to sort sm with same dim algos according to dim of
186 // the shape the algo assigned to (issue 0021217)
187 multimap< int, SMESH_subMesh* > shDim2sm;
188 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
189 TopoDS_Shape algoShape;
190 int prevShapeDim = -1;
192 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
193 while ( smIt->more() )
195 SMESH_subMesh* smToCompute = smIt->next();
196 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
199 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
200 int aShapeDim = GetShapeDim( aSubShape );
201 if ( aShapeDim < 1 ) break;
203 // check for preview dimension limitations
204 if ( aShapesId && aShapeDim > (int)aDim )
207 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
208 if ( algo && !algo->NeedDescretBoundary() )
210 if ( algo->SupportSubmeshes() )
212 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
213 if ( prevShapeDim != aShapeDim )
215 prevShapeDim = aShapeDim;
216 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
217 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
220 // add smToCompute to shDim2sm map
221 aShapeDim = GetShapeDim( algoShape );
222 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
224 TopoDS_Iterator it( algoShape );
225 aShapeDim += GetShapeDim( it.Value() );
227 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
231 #ifdef WITH_SMESH_CANCEL_COMPUTE
232 if (_compute_canceled)
234 _sm_current = smToCompute;
236 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
237 #ifdef WITH_SMESH_CANCEL_COMPUTE
241 aShapesId->insert( smToCompute->GetId() );
245 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
246 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
247 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
249 // ------------------------------------------------------------
250 // sort list of submeshes according to mesh order
251 // ------------------------------------------------------------
252 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
254 // ------------------------------------------------------------
255 // compute submeshes under shapes with algos that DO NOT require
256 // descretized boundaries and DO support submeshes
257 // ------------------------------------------------------------
258 list< SMESH_subMesh* >::iterator subIt, subEnd;
259 subIt = smWithAlgoSupportingSubmeshes.begin();
260 subEnd = smWithAlgoSupportingSubmeshes.end();
261 // start from lower shapes
262 for ( ; subIt != subEnd; ++subIt )
266 // get a shape the algo is assigned to
267 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
268 continue; // strange...
270 // look for more local algos
271 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
272 while ( smIt->more() )
274 SMESH_subMesh* smToCompute = smIt->next();
276 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
277 const int aShapeDim = GetShapeDim( aSubShape );
278 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
279 if ( aShapeDim < 1 ) continue;
281 // check for preview dimension limitations
282 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
285 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
287 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
288 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
290 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
291 SMESH_Hypothesis::Hypothesis_Status status;
292 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
293 // mesh a lower smToCompute starting from vertices
294 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
298 // ----------------------------------------------------------
299 // apply the algos that do not require descretized boundaries
300 // ----------------------------------------------------------
301 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
304 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
306 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
307 // check for preview dimension limitations
308 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
311 #ifdef WITH_SMESH_CANCEL_COMPUTE
312 if (_compute_canceled)
316 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
317 #ifdef WITH_SMESH_CANCEL_COMPUTE
321 aShapesId->insert( sm->GetId() );
324 // -----------------------------------------------
325 // mesh the rest subshapes starting from vertices
326 // -----------------------------------------------
327 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
330 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
333 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
334 myMesh->adjustStructure();
335 MESSAGE("*** compactMesh after compute");
336 myMesh->compactMesh();
337 //myMesh->adjustStructure();
338 list<int> listind = myMesh->SubMeshIndices();
339 list<int>::iterator it = listind.begin();
341 for(; it != listind.end(); ++it)
343 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
344 total += subMesh->getSize();
346 MESSAGE("total elements and nodes in submesh sets:" << total);
347 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
348 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
349 //myMesh->dumpGrid();
350 //aMesh.GetMeshDS()->Modified();
355 #ifdef WITH_SMESH_CANCEL_COMPUTE
356 //=============================================================================
358 * Prepare Compute a mesh
360 //=============================================================================
361 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
362 const TopoDS_Shape & aShape)
364 _compute_canceled = false;
367 //=============================================================================
369 * Cancel Compute a mesh
371 //=============================================================================
372 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
373 const TopoDS_Shape & aShape)
375 _compute_canceled = true;
378 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
383 //=============================================================================
387 //=============================================================================
389 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
390 const TopoDS_Shape & aShape,
391 MapShapeNbElems& aResMap,
393 TSetOfInt* aShapesId)
395 MESSAGE("SMESH_Gen::Evaluate");
399 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
401 const bool includeSelf = true;
402 const bool complexShapeFirst = true;
403 SMESH_subMeshIteratorPtr smIt;
405 if ( anUpward ) { // is called from below code here
406 // -----------------------------------------------
407 // mesh all the subshapes starting from vertices
408 // -----------------------------------------------
409 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
410 while ( smIt->more() ) {
411 SMESH_subMesh* smToCompute = smIt->next();
413 // do not mesh vertices of a pseudo shape
414 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
415 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
417 if ( !aMesh.HasShapeToMesh() ) {
418 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
419 aShType == TopAbs_SHELL )
423 smToCompute->Evaluate(aResMap);
425 aShapesId->insert( smToCompute->GetId() );
430 // -----------------------------------------------------------------
431 // apply algos that DO NOT require descretized boundaries and DO NOT
432 // support submeshes, starting from the most complex shapes
433 // and collect submeshes with algos that DO support submeshes
434 // -----------------------------------------------------------------
435 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
436 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
437 while ( smIt->more() ) {
438 SMESH_subMesh* smToCompute = smIt->next();
439 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
440 const int aShapeDim = GetShapeDim( aSubShape );
441 if ( aShapeDim < 1 ) break;
443 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
444 if ( algo && !algo->NeedDescretBoundary() ) {
445 if ( algo->SupportSubmeshes() ) {
446 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
449 smToCompute->Evaluate(aResMap);
451 aShapesId->insert( smToCompute->GetId() );
456 // ------------------------------------------------------------
457 // sort list of meshes according to mesh order
458 // ------------------------------------------------------------
459 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
461 // ------------------------------------------------------------
462 // compute submeshes under shapes with algos that DO NOT require
463 // descretized boundaries and DO support submeshes
464 // ------------------------------------------------------------
465 list< SMESH_subMesh* >::iterator subIt, subEnd;
466 subIt = smWithAlgoSupportingSubmeshes.begin();
467 subEnd = smWithAlgoSupportingSubmeshes.end();
468 // start from lower shapes
469 for ( ; subIt != subEnd; ++subIt ) {
472 // get a shape the algo is assigned to
473 TopoDS_Shape algoShape;
474 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
475 continue; // strange...
477 // look for more local algos
478 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
479 while ( smIt->more() ) {
480 SMESH_subMesh* smToCompute = smIt->next();
482 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
483 const int aShapeDim = GetShapeDim( aSubShape );
484 if ( aShapeDim < 1 ) continue;
486 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
488 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
490 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
491 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
493 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
494 SMESH_Hypothesis::Hypothesis_Status status;
495 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
496 // mesh a lower smToCompute starting from vertices
497 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
501 // ----------------------------------------------------------
502 // apply the algos that do not require descretized boundaries
503 // ----------------------------------------------------------
504 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
507 sm->Evaluate(aResMap);
509 aShapesId->insert( sm->GetId() );
512 // -----------------------------------------------
513 // mesh the rest subshapes starting from vertices
514 // -----------------------------------------------
515 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
518 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
523 //=======================================================================
524 //function : checkConformIgnoredAlgos
526 //=======================================================================
528 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
529 SMESH_subMesh* aSubMesh,
530 const SMESH_Algo* aGlobIgnoAlgo,
531 const SMESH_Algo* aLocIgnoAlgo,
533 set<SMESH_subMesh*>& aCheckedMap,
534 list< SMESH_Gen::TAlgoStateError > & theErrors)
537 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
543 const list<const SMESHDS_Hypothesis*>& listHyp =
544 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
545 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
546 for ( ; it != listHyp.end(); it++)
548 const SMESHDS_Hypothesis * aHyp = *it;
549 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
552 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
555 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
557 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
558 << aLocIgnoAlgo->GetName() << ">");
562 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
563 int dim = algo->GetDim();
564 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
566 if ( dim < aMaxGlobIgnoDim )
568 // algo is hidden by a global algo
569 INFOS( ( isGlobal ? "Global" : "Local" )
570 << " <" << algo->GetName() << "> is hidden by global <"
571 << aGlobIgnoAlgo->GetName() << ">");
573 else if ( !algo->NeedDescretBoundary() && !isGlobal)
575 // local algo is not hidden and hides algos on sub-shapes
576 if (checkConform && !aSubMesh->IsConform( algo ))
579 checkConform = false; // no more check conformity
580 INFOS( "ERROR: Local <" << algo->GetName() <<
581 "> would produce not conform mesh: "
582 "<Not Conform Mesh Allowed> hypotesis is missing");
583 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
584 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
587 // sub-algos will be hidden by a local <algo>
588 SMESH_subMeshIteratorPtr revItSub =
589 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
590 bool checkConform2 = false;
591 while ( revItSub->more() )
593 SMESH_subMesh* sm = revItSub->next();
594 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
595 algo, checkConform2, aCheckedMap, theErrors);
596 aCheckedMap.insert( sm );
605 //=======================================================================
606 //function : checkMissing
607 //purpose : notify on missing hypothesis
608 // Return false if algo or hipothesis is missing
609 //=======================================================================
611 static bool checkMissing(SMESH_Gen* aGen,
613 SMESH_subMesh* aSubMesh,
614 const int aTopAlgoDim,
616 const bool checkNoAlgo,
617 set<SMESH_subMesh*>& aCheckedMap,
618 list< SMESH_Gen::TAlgoStateError > & theErrors)
620 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
623 //MESSAGE("=====checkMissing");
626 SMESH_Algo* algo = 0;
628 switch (aSubMesh->GetAlgoState())
630 case SMESH_subMesh::NO_ALGO: {
633 // should there be any algo?
634 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
635 if (aTopAlgoDim > shapeDim)
637 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
639 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
640 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
645 case SMESH_subMesh::MISSING_HYP: {
646 // notify if an algo missing hyp is attached to aSubMesh
647 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
649 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
650 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
652 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
653 SMESH_Hypothesis::Hypothesis_Status status;
654 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
655 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
656 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
657 << "<" << algo->GetName() << "> has a bad parameter value");
659 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
660 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
661 << "<" << algo->GetName() << "> assigned to mismatching geometry");
664 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
665 << "<" << algo->GetName() << "> misses some hypothesis");
667 if (IsGlobalHypothesis)
668 globalChecked[ algo->GetDim() ] = true;
669 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
670 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
675 case SMESH_subMesh::HYP_OK:
676 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
682 // do not check under algo that hides sub-algos or
683 // re-start checking NO_ALGO state
685 bool isTopLocalAlgo =
686 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
687 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
689 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
690 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
691 /*complexShapeFirst=*/false);
692 while ( itsub->more() )
694 // sub-meshes should not be checked further more
695 SMESH_subMesh* sm = itsub->next();
696 aCheckedMap.insert( sm );
700 //check algo on sub-meshes
701 int aTopAlgoDim2 = algo->GetDim();
702 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
703 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
706 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
707 checkNoAlgo2 = false;
715 //=======================================================================
716 //function : CheckAlgoState
717 //purpose : notify on bad state of attached algos, return false
718 // if Compute() would fail because of some algo bad state
719 //=======================================================================
721 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
723 list< TAlgoStateError > errors;
724 return GetAlgoState( aMesh, aShape, errors );
727 //=======================================================================
728 //function : GetAlgoState
729 //purpose : notify on bad state of attached algos, return false
730 // if Compute() would fail because of some algo bad state
731 // theErrors list contains problems description
732 //=======================================================================
734 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
735 const TopoDS_Shape& theShape,
736 list< TAlgoStateError > & theErrors)
738 //MESSAGE("SMESH_Gen::CheckAlgoState");
741 bool hasAlgo = false;
743 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
744 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
745 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
751 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
753 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
754 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
755 for ( ; it != listHyp.end(); it++)
757 const SMESHDS_Hypothesis * aHyp = *it;
758 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
761 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
764 int dim = algo->GetDim();
765 aGlobAlgoArr[ dim ] = algo;
770 // --------------------------------------------------------
771 // info on algos that will be ignored because of ones that
772 // don't NeedDescretBoundary() attached to super-shapes,
773 // check that a conform mesh will be produced
774 // --------------------------------------------------------
777 // find a global algo possibly hiding sub-algos
779 const SMESH_Algo* aGlobIgnoAlgo = 0;
780 for (dim = 3; dim > 0; dim--)
782 if (aGlobAlgoArr[ dim ] &&
783 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
785 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
790 set<SMESH_subMesh*> aCheckedSubs;
791 bool checkConform = ( !theMesh.IsNotConformAllowed() );
793 // loop on theShape and its sub-shapes
794 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
795 /*complexShapeFirst=*/true);
796 while ( revItSub->more() )
798 SMESH_subMesh* smToCheck = revItSub->next();
799 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
802 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
803 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
804 0, checkConform, aCheckedSubs, theErrors))
807 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
811 // ----------------------------------------------------------------
812 // info on missing hypothesis and find out if all needed algos are
814 // ----------------------------------------------------------------
816 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
818 // find max dim of global algo
820 for (dim = 3; dim > 0; dim--)
822 if (aGlobAlgoArr[ dim ])
828 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
829 bool globalChecked[] = { false, false, false, false };
831 // loop on theShape and its sub-shapes
832 aCheckedSubs.clear();
833 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
834 while ( revItSub->more() )
836 SMESH_subMesh* smToCheck = revItSub->next();
837 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
840 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
841 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
842 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
845 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
852 INFOS( "None algorithm attached" );
853 theErrors.push_back( TAlgoStateError() );
854 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
860 //=======================================================================
861 //function : IsGlobalHypothesis
862 //purpose : check if theAlgo is attached to the main shape
863 //=======================================================================
865 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
867 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
868 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
871 //=============================================================================
873 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
875 //=============================================================================
877 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
878 const TopoDS_Shape & aShape,
879 TopoDS_Shape* assignedTo)
881 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
882 filter.And( filter.IsApplicableTo( aShape ));
884 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
887 //=============================================================================
889 * Returns StudyContextStruct for a study
891 //=============================================================================
893 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
895 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
897 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
899 _mapStudyContext[studyId] = new StudyContextStruct;
900 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
902 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
903 return myStudyContext;
906 //================================================================================
908 * \brief Return shape dimension by TopAbs_ShapeEnum
910 //================================================================================
912 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
914 static vector<int> dim;
917 dim.resize( TopAbs_SHAPE, -1 );
918 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
919 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
920 dim[ TopAbs_SOLID ] = MeshDim_3D;
921 dim[ TopAbs_SHELL ] = MeshDim_3D;
922 dim[ TopAbs_FACE ] = MeshDim_2D;
923 dim[ TopAbs_WIRE ] = MeshDim_1D;
924 dim[ TopAbs_EDGE ] = MeshDim_1D;
925 dim[ TopAbs_VERTEX ] = MeshDim_0D;
927 return dim[ aShapeType ];
930 //=============================================================================
932 * Genarate a new id unique withing this Gen
934 //=============================================================================
936 int SMESH_Gen::GetANewId()