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;
187 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
188 while ( smIt->more() )
190 SMESH_subMesh* smToCompute = smIt->next();
191 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
194 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
195 const int aShapeDim = GetShapeDim( aSubShape );
196 if ( aShapeDim < 1 ) break;
198 // check for preview dimension limitations
199 if ( aShapesId && aShapeDim > (int)aDim )
202 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
203 if ( algo && !algo->NeedDescretBoundary() )
205 if ( algo->SupportSubmeshes() )
206 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
209 #ifdef WITH_SMESH_CANCEL_COMPUTE
210 if (_compute_canceled)
212 _sm_current = smToCompute;
214 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
215 #ifdef WITH_SMESH_CANCEL_COMPUTE
219 aShapesId->insert( smToCompute->GetId() );
224 // ------------------------------------------------------------
225 // sort list of submeshes according to mesh order
226 // ------------------------------------------------------------
227 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
229 // ------------------------------------------------------------
230 // compute submeshes under shapes with algos that DO NOT require
231 // descretized boundaries and DO support submeshes
232 // ------------------------------------------------------------
233 list< SMESH_subMesh* >::iterator subIt, subEnd;
234 subIt = smWithAlgoSupportingSubmeshes.begin();
235 subEnd = smWithAlgoSupportingSubmeshes.end();
236 // start from lower shapes
237 for ( ; subIt != subEnd; ++subIt )
241 // get a shape the algo is assigned to
242 TopoDS_Shape algoShape;
243 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
244 continue; // strange...
246 // look for more local algos
247 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
248 while ( smIt->more() )
250 SMESH_subMesh* smToCompute = smIt->next();
252 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
253 const int aShapeDim = GetShapeDim( aSubShape );
254 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
255 if ( aShapeDim < 1 ) continue;
257 // check for preview dimension limitations
258 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
261 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
263 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
264 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
266 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
267 SMESH_Hypothesis::Hypothesis_Status status;
268 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
269 // mesh a lower smToCompute starting from vertices
270 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
274 // ----------------------------------------------------------
275 // apply the algos that do not require descretized boundaries
276 // ----------------------------------------------------------
277 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
280 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
282 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
283 // check for preview dimension limitations
284 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
287 #ifdef WITH_SMESH_CANCEL_COMPUTE
288 if (_compute_canceled)
292 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
293 #ifdef WITH_SMESH_CANCEL_COMPUTE
297 aShapesId->insert( sm->GetId() );
300 // -----------------------------------------------
301 // mesh the rest subshapes starting from vertices
302 // -----------------------------------------------
303 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
306 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
309 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
310 myMesh->adjustStructure();
311 MESSAGE("*** compactMesh after compute");
312 myMesh->compactMesh();
313 //myMesh->adjustStructure();
314 list<int> listind = myMesh->SubMeshIndices();
315 list<int>::iterator it = listind.begin();
317 for(; it != listind.end(); ++it)
319 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
320 total += subMesh->getSize();
322 MESSAGE("total elements and nodes in submesh sets:" << total);
323 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
324 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
325 //myMesh->dumpGrid();
326 //aMesh.GetMeshDS()->Modified();
331 #ifdef WITH_SMESH_CANCEL_COMPUTE
332 //=============================================================================
334 * Prepare Compute a mesh
336 //=============================================================================
337 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
338 const TopoDS_Shape & aShape)
340 _compute_canceled = false;
343 //=============================================================================
345 * Cancel Compute a mesh
347 //=============================================================================
348 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
349 const TopoDS_Shape & aShape)
351 _compute_canceled = true;
354 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
359 //=============================================================================
363 //=============================================================================
365 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
366 const TopoDS_Shape & aShape,
367 MapShapeNbElems& aResMap,
369 TSetOfInt* aShapesId)
371 MESSAGE("SMESH_Gen::Evaluate");
375 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
377 const bool includeSelf = true;
378 const bool complexShapeFirst = true;
379 SMESH_subMeshIteratorPtr smIt;
381 if ( anUpward ) { // is called from below code here
382 // -----------------------------------------------
383 // mesh all the subshapes starting from vertices
384 // -----------------------------------------------
385 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
386 while ( smIt->more() ) {
387 SMESH_subMesh* smToCompute = smIt->next();
389 // do not mesh vertices of a pseudo shape
390 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
391 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
393 if ( !aMesh.HasShapeToMesh() ) {
394 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
395 aShType == TopAbs_SHELL )
399 smToCompute->Evaluate(aResMap);
401 aShapesId->insert( smToCompute->GetId() );
406 // -----------------------------------------------------------------
407 // apply algos that DO NOT require descretized boundaries and DO NOT
408 // support submeshes, starting from the most complex shapes
409 // and collect submeshes with algos that DO support submeshes
410 // -----------------------------------------------------------------
411 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
412 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
413 while ( smIt->more() ) {
414 SMESH_subMesh* smToCompute = smIt->next();
415 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
416 const int aShapeDim = GetShapeDim( aSubShape );
417 if ( aShapeDim < 1 ) break;
419 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
420 if ( algo && !algo->NeedDescretBoundary() ) {
421 if ( algo->SupportSubmeshes() ) {
422 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
425 smToCompute->Evaluate(aResMap);
427 aShapesId->insert( smToCompute->GetId() );
432 // ------------------------------------------------------------
433 // sort list of meshes according to mesh order
434 // ------------------------------------------------------------
435 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
437 // ------------------------------------------------------------
438 // compute submeshes under shapes with algos that DO NOT require
439 // descretized boundaries and DO support submeshes
440 // ------------------------------------------------------------
441 list< SMESH_subMesh* >::iterator subIt, subEnd;
442 subIt = smWithAlgoSupportingSubmeshes.begin();
443 subEnd = smWithAlgoSupportingSubmeshes.end();
444 // start from lower shapes
445 for ( ; subIt != subEnd; ++subIt ) {
448 // get a shape the algo is assigned to
449 TopoDS_Shape algoShape;
450 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
451 continue; // strange...
453 // look for more local algos
454 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
455 while ( smIt->more() ) {
456 SMESH_subMesh* smToCompute = smIt->next();
458 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
459 const int aShapeDim = GetShapeDim( aSubShape );
460 if ( aShapeDim < 1 ) continue;
462 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
464 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
466 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
467 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
469 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
470 SMESH_Hypothesis::Hypothesis_Status status;
471 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
472 // mesh a lower smToCompute starting from vertices
473 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
477 // ----------------------------------------------------------
478 // apply the algos that do not require descretized boundaries
479 // ----------------------------------------------------------
480 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
483 sm->Evaluate(aResMap);
485 aShapesId->insert( sm->GetId() );
488 // -----------------------------------------------
489 // mesh the rest subshapes starting from vertices
490 // -----------------------------------------------
491 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
494 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
499 //=======================================================================
500 //function : checkConformIgnoredAlgos
502 //=======================================================================
504 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
505 SMESH_subMesh* aSubMesh,
506 const SMESH_Algo* aGlobIgnoAlgo,
507 const SMESH_Algo* aLocIgnoAlgo,
509 set<SMESH_subMesh*>& aCheckedMap,
510 list< SMESH_Gen::TAlgoStateError > & theErrors)
513 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
519 const list<const SMESHDS_Hypothesis*>& listHyp =
520 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
521 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
522 for ( ; it != listHyp.end(); it++)
524 const SMESHDS_Hypothesis * aHyp = *it;
525 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
528 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
531 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
533 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
534 << aLocIgnoAlgo->GetName() << ">");
538 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
539 int dim = algo->GetDim();
540 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
542 if ( dim < aMaxGlobIgnoDim )
544 // algo is hidden by a global algo
545 INFOS( ( isGlobal ? "Global" : "Local" )
546 << " <" << algo->GetName() << "> is hidden by global <"
547 << aGlobIgnoAlgo->GetName() << ">");
549 else if ( !algo->NeedDescretBoundary() && !isGlobal)
551 // local algo is not hidden and hides algos on sub-shapes
552 if (checkConform && !aSubMesh->IsConform( algo ))
555 checkConform = false; // no more check conformity
556 INFOS( "ERROR: Local <" << algo->GetName() <<
557 "> would produce not conform mesh: "
558 "<Not Conform Mesh Allowed> hypotesis is missing");
559 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
560 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
563 // sub-algos will be hidden by a local <algo>
564 SMESH_subMeshIteratorPtr revItSub =
565 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
566 bool checkConform2 = false;
567 while ( revItSub->more() )
569 SMESH_subMesh* sm = revItSub->next();
570 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
571 algo, checkConform2, aCheckedMap, theErrors);
572 aCheckedMap.insert( sm );
581 //=======================================================================
582 //function : checkMissing
583 //purpose : notify on missing hypothesis
584 // Return false if algo or hipothesis is missing
585 //=======================================================================
587 static bool checkMissing(SMESH_Gen* aGen,
589 SMESH_subMesh* aSubMesh,
590 const int aTopAlgoDim,
592 const bool checkNoAlgo,
593 set<SMESH_subMesh*>& aCheckedMap,
594 list< SMESH_Gen::TAlgoStateError > & theErrors)
596 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
599 //MESSAGE("=====checkMissing");
602 SMESH_Algo* algo = 0;
604 switch (aSubMesh->GetAlgoState())
606 case SMESH_subMesh::NO_ALGO: {
609 // should there be any algo?
610 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
611 if (aTopAlgoDim > shapeDim)
613 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
615 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
616 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
621 case SMESH_subMesh::MISSING_HYP: {
622 // notify if an algo missing hyp is attached to aSubMesh
623 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
625 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
626 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
628 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
629 SMESH_Hypothesis::Hypothesis_Status status;
630 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
631 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
632 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
633 << "<" << algo->GetName() << "> has a bad parameter value");
635 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
636 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
637 << "<" << algo->GetName() << "> assigned to mismatching geometry");
640 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
641 << "<" << algo->GetName() << "> misses some hypothesis");
643 if (IsGlobalHypothesis)
644 globalChecked[ algo->GetDim() ] = true;
645 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
646 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
651 case SMESH_subMesh::HYP_OK:
652 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
658 // do not check under algo that hides sub-algos or
659 // re-start checking NO_ALGO state
661 bool isTopLocalAlgo =
662 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
663 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
665 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
666 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
667 /*complexShapeFirst=*/false);
668 while ( itsub->more() )
670 // sub-meshes should not be checked further more
671 SMESH_subMesh* sm = itsub->next();
672 aCheckedMap.insert( sm );
676 //check algo on sub-meshes
677 int aTopAlgoDim2 = algo->GetDim();
678 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
679 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
682 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
683 checkNoAlgo2 = false;
691 //=======================================================================
692 //function : CheckAlgoState
693 //purpose : notify on bad state of attached algos, return false
694 // if Compute() would fail because of some algo bad state
695 //=======================================================================
697 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
699 list< TAlgoStateError > errors;
700 return GetAlgoState( aMesh, aShape, errors );
703 //=======================================================================
704 //function : GetAlgoState
705 //purpose : notify on bad state of attached algos, return false
706 // if Compute() would fail because of some algo bad state
707 // theErrors list contains problems description
708 //=======================================================================
710 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
711 const TopoDS_Shape& theShape,
712 list< TAlgoStateError > & theErrors)
714 //MESSAGE("SMESH_Gen::CheckAlgoState");
717 bool hasAlgo = false;
719 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
720 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
721 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
727 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
729 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
730 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
731 for ( ; it != listHyp.end(); it++)
733 const SMESHDS_Hypothesis * aHyp = *it;
734 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
737 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
740 int dim = algo->GetDim();
741 aGlobAlgoArr[ dim ] = algo;
746 // --------------------------------------------------------
747 // info on algos that will be ignored because of ones that
748 // don't NeedDescretBoundary() attached to super-shapes,
749 // check that a conform mesh will be produced
750 // --------------------------------------------------------
753 // find a global algo possibly hiding sub-algos
755 const SMESH_Algo* aGlobIgnoAlgo = 0;
756 for (dim = 3; dim > 0; dim--)
758 if (aGlobAlgoArr[ dim ] &&
759 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
761 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
766 set<SMESH_subMesh*> aCheckedSubs;
767 bool checkConform = ( !theMesh.IsNotConformAllowed() );
769 // loop on theShape and its sub-shapes
770 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
771 /*complexShapeFirst=*/true);
772 while ( revItSub->more() )
774 SMESH_subMesh* smToCheck = revItSub->next();
775 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
778 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
779 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
780 0, checkConform, aCheckedSubs, theErrors))
783 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
787 // ----------------------------------------------------------------
788 // info on missing hypothesis and find out if all needed algos are
790 // ----------------------------------------------------------------
792 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
794 // find max dim of global algo
796 for (dim = 3; dim > 0; dim--)
798 if (aGlobAlgoArr[ dim ])
804 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
805 bool globalChecked[] = { false, false, false, false };
807 // loop on theShape and its sub-shapes
808 aCheckedSubs.clear();
809 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
810 while ( revItSub->more() )
812 SMESH_subMesh* smToCheck = revItSub->next();
813 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
816 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
817 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
818 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
821 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
828 INFOS( "None algorithm attached" );
829 theErrors.push_back( TAlgoStateError() );
830 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
836 //=======================================================================
837 //function : IsGlobalHypothesis
838 //purpose : check if theAlgo is attached to the main shape
839 //=======================================================================
841 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
843 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
844 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
847 //=============================================================================
849 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
851 //=============================================================================
853 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
854 const TopoDS_Shape & aShape,
855 TopoDS_Shape* assignedTo)
857 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
858 filter.And( filter.IsApplicableTo( aShape ));
860 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
863 //=============================================================================
865 * Returns StudyContextStruct for a study
867 //=============================================================================
869 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
871 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
873 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
875 _mapStudyContext[studyId] = new StudyContextStruct;
876 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
878 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
879 return myStudyContext;
882 //================================================================================
884 * \brief Return shape dimension by TopAbs_ShapeEnum
886 //================================================================================
888 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
890 static vector<int> dim;
893 dim.resize( TopAbs_SHAPE, -1 );
894 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
895 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
896 dim[ TopAbs_SOLID ] = MeshDim_3D;
897 dim[ TopAbs_SHELL ] = MeshDim_3D;
898 dim[ TopAbs_FACE ] = MeshDim_2D;
899 dim[ TopAbs_WIRE ] = MeshDim_1D;
900 dim[ TopAbs_EDGE ] = MeshDim_1D;
901 dim[ TopAbs_VERTEX ] = MeshDim_0D;
903 return dim[ aShapeType ];
906 //=============================================================================
908 * Genarate a new id unique withing this Gen
910 //=============================================================================
912 int SMESH_Gen::GetANewId()