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
31 #include "SMESH_Gen.hxx"
33 #include "SMDS_Mesh.hxx"
34 #include "SMDS_MeshElement.hxx"
35 #include "SMDS_MeshNode.hxx"
36 #include "SMESHDS_Document.hxx"
37 #include "SMESH_HypoFilter.hxx"
38 #include "SMESH_MesherHelper.hxx"
39 #include "SMESH_subMesh.hxx"
41 #include "utilities.h"
43 #include "Utils_ExceptHandlers.hxx"
45 #include <TopoDS_Iterator.hxx>
51 //=============================================================================
55 //=============================================================================
57 SMESH_Gen::SMESH_Gen()
59 MESSAGE("SMESH_Gen::SMESH_Gen");
62 _segmentation = _nbSegments = 10;
63 SMDS_Mesh::_meshList.clear();
64 MESSAGE(SMDS_Mesh::_meshList.size());
65 _counters = new counters(100);
66 #ifdef WITH_SMESH_CANCEL_COMPUTE
67 _compute_canceled = false;
72 //=============================================================================
76 //=============================================================================
78 SMESH_Gen::~SMESH_Gen()
80 MESSAGE("SMESH_Gen::~SMESH_Gen");
83 //=============================================================================
85 * Creates a mesh in a study.
86 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
88 //=============================================================================
90 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
91 throw(SALOME_Exception)
93 Unexpect aCatch(SalomeException);
94 MESSAGE("SMESH_Gen::CreateMesh");
96 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
97 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
99 // create a new SMESH_mesh object
100 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
104 aStudyContext->myDocument);
105 aStudyContext->mapMesh[_localId] = aMesh;
110 //=============================================================================
114 //=============================================================================
116 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
117 const TopoDS_Shape & aShape,
119 const ::MeshDimension aDim,
120 TSetOfInt* aShapesId)
122 MESSAGE("SMESH_Gen::Compute");
127 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
129 const bool includeSelf = true;
130 const bool complexShapeFirst = true;
132 SMESH_subMeshIteratorPtr smIt;
134 if ( anUpward ) // is called from below code here
136 // -----------------------------------------------
137 // mesh all the subshapes starting from vertices
138 // -----------------------------------------------
139 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
140 while ( smIt->more() )
142 SMESH_subMesh* smToCompute = smIt->next();
144 // do not mesh vertices of a pseudo shape
145 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
146 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
149 // check for preview dimension limitations
150 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
152 // clear compute state to not show previous compute errors
153 // if preview invoked less dimension less than previous
154 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
158 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
160 #ifdef WITH_SMESH_CANCEL_COMPUTE
161 if (_compute_canceled)
163 _sm_current = smToCompute;
165 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
166 #ifdef WITH_SMESH_CANCEL_COMPUTE
171 // we check all the submeshes here and detect if any of them failed to compute
172 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
174 else if ( aShapesId )
175 aShapesId->insert( smToCompute->GetId() );
177 //aMesh.GetMeshDS()->Modified();
182 // -----------------------------------------------------------------
183 // apply algos that DO NOT require descretized boundaries and DO NOT
184 // support submeshes, starting from the most complex shapes
185 // and collect submeshes with algos that DO support submeshes
186 // -----------------------------------------------------------------
187 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
189 // map to sort sm with same dim algos according to dim of
190 // the shape the algo assigned to (issue 0021217)
191 multimap< int, SMESH_subMesh* > shDim2sm;
192 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
193 TopoDS_Shape algoShape;
194 int prevShapeDim = -1;
196 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
197 while ( smIt->more() )
199 SMESH_subMesh* smToCompute = smIt->next();
200 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
203 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
204 int aShapeDim = GetShapeDim( aSubShape );
205 if ( aShapeDim < 1 ) break;
207 // check for preview dimension limitations
208 if ( aShapesId && aShapeDim > (int)aDim )
211 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
212 if ( algo && !algo->NeedDescretBoundary() )
214 if ( algo->SupportSubmeshes() )
216 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
217 if ( prevShapeDim != aShapeDim )
219 prevShapeDim = aShapeDim;
220 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
221 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
224 // add smToCompute to shDim2sm map
225 aShapeDim = GetShapeDim( algoShape );
226 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
228 TopoDS_Iterator it( algoShape );
229 aShapeDim += GetShapeDim( it.Value() );
231 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
235 #ifdef WITH_SMESH_CANCEL_COMPUTE
236 if (_compute_canceled)
238 _sm_current = smToCompute;
240 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
241 #ifdef WITH_SMESH_CANCEL_COMPUTE
245 aShapesId->insert( smToCompute->GetId() );
249 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
250 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
251 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
253 // ------------------------------------------------------------
254 // sort list of submeshes according to mesh order
255 // ------------------------------------------------------------
256 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
258 // ------------------------------------------------------------
259 // compute submeshes under shapes with algos that DO NOT require
260 // descretized boundaries and DO support submeshes
261 // ------------------------------------------------------------
262 list< SMESH_subMesh* >::iterator subIt, subEnd;
263 subIt = smWithAlgoSupportingSubmeshes.begin();
264 subEnd = smWithAlgoSupportingSubmeshes.end();
265 // start from lower shapes
266 for ( ; subIt != subEnd; ++subIt )
270 // get a shape the algo is assigned to
271 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
272 continue; // strange...
274 // look for more local algos
275 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
276 while ( smIt->more() )
278 SMESH_subMesh* smToCompute = smIt->next();
280 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
281 const int aShapeDim = GetShapeDim( aSubShape );
282 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
283 if ( aShapeDim < 1 ) continue;
285 // check for preview dimension limitations
286 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
289 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
291 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
292 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
294 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
295 SMESH_Hypothesis::Hypothesis_Status status;
296 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
297 // mesh a lower smToCompute starting from vertices
298 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
302 // ----------------------------------------------------------
303 // apply the algos that do not require descretized boundaries
304 // ----------------------------------------------------------
305 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
308 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
310 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
311 // check for preview dimension limitations
312 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
315 #ifdef WITH_SMESH_CANCEL_COMPUTE
316 if (_compute_canceled)
320 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
321 #ifdef WITH_SMESH_CANCEL_COMPUTE
325 aShapesId->insert( sm->GetId() );
328 // -----------------------------------------------
329 // mesh the rest subshapes starting from vertices
330 // -----------------------------------------------
331 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
334 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
337 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
338 myMesh->adjustStructure();
339 MESSAGE("*** compactMesh after compute");
340 myMesh->compactMesh();
341 //myMesh->adjustStructure();
342 list<int> listind = myMesh->SubMeshIndices();
343 list<int>::iterator it = listind.begin();
345 for(; it != listind.end(); ++it)
347 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
348 total += subMesh->getSize();
350 MESSAGE("total elements and nodes in submesh sets:" << total);
351 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
352 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
353 //myMesh->dumpGrid();
354 //aMesh.GetMeshDS()->Modified();
356 // fix quadratic mesh by bending iternal links near concave boundary
357 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
358 !aShapesId ) // not preview
360 SMESH_MesherHelper aHelper( aMesh );
361 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
362 aHelper.FixQuadraticElements();
368 #ifdef WITH_SMESH_CANCEL_COMPUTE
369 //=============================================================================
371 * Prepare Compute a mesh
373 //=============================================================================
374 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
375 const TopoDS_Shape & aShape)
377 _compute_canceled = false;
380 //=============================================================================
382 * Cancel Compute a mesh
384 //=============================================================================
385 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
386 const TopoDS_Shape & aShape)
388 _compute_canceled = true;
391 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
396 //=============================================================================
400 //=============================================================================
402 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
403 const TopoDS_Shape & aShape,
404 MapShapeNbElems& aResMap,
406 TSetOfInt* aShapesId)
408 MESSAGE("SMESH_Gen::Evaluate");
412 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
414 const bool includeSelf = true;
415 const bool complexShapeFirst = true;
416 SMESH_subMeshIteratorPtr smIt;
418 if ( anUpward ) { // is called from below code here
419 // -----------------------------------------------
420 // mesh all the subshapes starting from vertices
421 // -----------------------------------------------
422 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
423 while ( smIt->more() ) {
424 SMESH_subMesh* smToCompute = smIt->next();
426 // do not mesh vertices of a pseudo shape
427 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
428 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
430 if ( !aMesh.HasShapeToMesh() ) {
431 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
432 aShType == TopAbs_SHELL )
436 smToCompute->Evaluate(aResMap);
438 aShapesId->insert( smToCompute->GetId() );
443 // -----------------------------------------------------------------
444 // apply algos that DO NOT require descretized boundaries and DO NOT
445 // support submeshes, starting from the most complex shapes
446 // and collect submeshes with algos that DO support submeshes
447 // -----------------------------------------------------------------
448 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
449 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
450 while ( smIt->more() ) {
451 SMESH_subMesh* smToCompute = smIt->next();
452 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
453 const int aShapeDim = GetShapeDim( aSubShape );
454 if ( aShapeDim < 1 ) break;
456 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
457 if ( algo && !algo->NeedDescretBoundary() ) {
458 if ( algo->SupportSubmeshes() ) {
459 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
462 smToCompute->Evaluate(aResMap);
464 aShapesId->insert( smToCompute->GetId() );
469 // ------------------------------------------------------------
470 // sort list of meshes according to mesh order
471 // ------------------------------------------------------------
472 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
474 // ------------------------------------------------------------
475 // compute submeshes under shapes with algos that DO NOT require
476 // descretized boundaries and DO support submeshes
477 // ------------------------------------------------------------
478 list< SMESH_subMesh* >::iterator subIt, subEnd;
479 subIt = smWithAlgoSupportingSubmeshes.begin();
480 subEnd = smWithAlgoSupportingSubmeshes.end();
481 // start from lower shapes
482 for ( ; subIt != subEnd; ++subIt ) {
485 // get a shape the algo is assigned to
486 TopoDS_Shape algoShape;
487 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
488 continue; // strange...
490 // look for more local algos
491 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
492 while ( smIt->more() ) {
493 SMESH_subMesh* smToCompute = smIt->next();
495 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
496 const int aShapeDim = GetShapeDim( aSubShape );
497 if ( aShapeDim < 1 ) continue;
499 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
501 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
503 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
504 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
506 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
507 SMESH_Hypothesis::Hypothesis_Status status;
508 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
509 // mesh a lower smToCompute starting from vertices
510 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
514 // ----------------------------------------------------------
515 // apply the algos that do not require descretized boundaries
516 // ----------------------------------------------------------
517 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
520 sm->Evaluate(aResMap);
522 aShapesId->insert( sm->GetId() );
525 // -----------------------------------------------
526 // mesh the rest subshapes starting from vertices
527 // -----------------------------------------------
528 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
531 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
536 //=======================================================================
537 //function : checkConformIgnoredAlgos
539 //=======================================================================
541 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
542 SMESH_subMesh* aSubMesh,
543 const SMESH_Algo* aGlobIgnoAlgo,
544 const SMESH_Algo* aLocIgnoAlgo,
546 set<SMESH_subMesh*>& aCheckedMap,
547 list< SMESH_Gen::TAlgoStateError > & theErrors)
550 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
556 const list<const SMESHDS_Hypothesis*>& listHyp =
557 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
558 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
559 for ( ; it != listHyp.end(); it++)
561 const SMESHDS_Hypothesis * aHyp = *it;
562 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
565 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
568 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
570 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
571 << aLocIgnoAlgo->GetName() << ">");
575 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
576 int dim = algo->GetDim();
577 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
579 if ( dim < aMaxGlobIgnoDim )
581 // algo is hidden by a global algo
582 INFOS( ( isGlobal ? "Global" : "Local" )
583 << " <" << algo->GetName() << "> is hidden by global <"
584 << aGlobIgnoAlgo->GetName() << ">");
586 else if ( !algo->NeedDescretBoundary() && !isGlobal)
588 // local algo is not hidden and hides algos on sub-shapes
589 if (checkConform && !aSubMesh->IsConform( algo ))
592 checkConform = false; // no more check conformity
593 INFOS( "ERROR: Local <" << algo->GetName() <<
594 "> would produce not conform mesh: "
595 "<Not Conform Mesh Allowed> hypotesis is missing");
596 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
597 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
600 // sub-algos will be hidden by a local <algo>
601 SMESH_subMeshIteratorPtr revItSub =
602 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
603 bool checkConform2 = false;
604 while ( revItSub->more() )
606 SMESH_subMesh* sm = revItSub->next();
607 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
608 algo, checkConform2, aCheckedMap, theErrors);
609 aCheckedMap.insert( sm );
618 //=======================================================================
619 //function : checkMissing
620 //purpose : notify on missing hypothesis
621 // Return false if algo or hipothesis is missing
622 //=======================================================================
624 static bool checkMissing(SMESH_Gen* aGen,
626 SMESH_subMesh* aSubMesh,
627 const int aTopAlgoDim,
629 const bool checkNoAlgo,
630 set<SMESH_subMesh*>& aCheckedMap,
631 list< SMESH_Gen::TAlgoStateError > & theErrors)
633 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
636 //MESSAGE("=====checkMissing");
639 SMESH_Algo* algo = 0;
641 switch (aSubMesh->GetAlgoState())
643 case SMESH_subMesh::NO_ALGO: {
646 // should there be any algo?
647 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
648 if (aTopAlgoDim > shapeDim)
650 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
652 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
653 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
658 case SMESH_subMesh::MISSING_HYP: {
659 // notify if an algo missing hyp is attached to aSubMesh
660 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
662 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
663 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
665 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
666 SMESH_Hypothesis::Hypothesis_Status status;
667 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
668 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
669 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
670 << "<" << algo->GetName() << "> has a bad parameter value");
672 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
673 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
674 << "<" << algo->GetName() << "> assigned to mismatching geometry");
677 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
678 << "<" << algo->GetName() << "> misses some hypothesis");
680 if (IsGlobalHypothesis)
681 globalChecked[ algo->GetDim() ] = true;
682 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
683 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
688 case SMESH_subMesh::HYP_OK:
689 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
695 // do not check under algo that hides sub-algos or
696 // re-start checking NO_ALGO state
698 bool isTopLocalAlgo =
699 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
700 if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
702 bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
703 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
704 /*complexShapeFirst=*/false);
705 while ( itsub->more() )
707 // sub-meshes should not be checked further more
708 SMESH_subMesh* sm = itsub->next();
709 aCheckedMap.insert( sm );
713 //check algo on sub-meshes
714 int aTopAlgoDim2 = algo->GetDim();
715 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
716 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
719 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
720 checkNoAlgo2 = false;
728 //=======================================================================
729 //function : CheckAlgoState
730 //purpose : notify on bad state of attached algos, return false
731 // if Compute() would fail because of some algo bad state
732 //=======================================================================
734 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
736 list< TAlgoStateError > errors;
737 return GetAlgoState( aMesh, aShape, errors );
740 //=======================================================================
741 //function : GetAlgoState
742 //purpose : notify on bad state of attached algos, return false
743 // if Compute() would fail because of some algo bad state
744 // theErrors list contains problems description
745 //=======================================================================
747 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
748 const TopoDS_Shape& theShape,
749 list< TAlgoStateError > & theErrors)
751 //MESSAGE("SMESH_Gen::CheckAlgoState");
754 bool hasAlgo = false;
756 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
757 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
758 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
764 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
766 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
767 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
768 for ( ; it != listHyp.end(); it++)
770 const SMESHDS_Hypothesis * aHyp = *it;
771 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
774 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
777 int dim = algo->GetDim();
778 aGlobAlgoArr[ dim ] = algo;
783 // --------------------------------------------------------
784 // info on algos that will be ignored because of ones that
785 // don't NeedDescretBoundary() attached to super-shapes,
786 // check that a conform mesh will be produced
787 // --------------------------------------------------------
790 // find a global algo possibly hiding sub-algos
792 const SMESH_Algo* aGlobIgnoAlgo = 0;
793 for (dim = 3; dim > 0; dim--)
795 if (aGlobAlgoArr[ dim ] &&
796 !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
798 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
803 set<SMESH_subMesh*> aCheckedSubs;
804 bool checkConform = ( !theMesh.IsNotConformAllowed() );
806 // loop on theShape and its sub-shapes
807 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
808 /*complexShapeFirst=*/true);
809 while ( revItSub->more() )
811 SMESH_subMesh* smToCheck = revItSub->next();
812 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
815 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
816 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
817 0, checkConform, aCheckedSubs, theErrors))
820 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
824 // ----------------------------------------------------------------
825 // info on missing hypothesis and find out if all needed algos are
827 // ----------------------------------------------------------------
829 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
831 // find max dim of global algo
833 for (dim = 3; dim > 0; dim--)
835 if (aGlobAlgoArr[ dim ])
841 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
842 bool globalChecked[] = { false, false, false, false };
844 // loop on theShape and its sub-shapes
845 aCheckedSubs.clear();
846 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
847 while ( revItSub->more() )
849 SMESH_subMesh* smToCheck = revItSub->next();
850 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
853 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
854 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
855 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
858 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
865 INFOS( "None algorithm attached" );
866 theErrors.push_back( TAlgoStateError() );
867 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
873 //=======================================================================
874 //function : IsGlobalHypothesis
875 //purpose : check if theAlgo is attached to the main shape
876 //=======================================================================
878 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
880 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
881 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
884 //=============================================================================
886 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
888 //=============================================================================
890 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
891 const TopoDS_Shape & aShape,
892 TopoDS_Shape* assignedTo)
894 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
895 filter.And( filter.IsApplicableTo( aShape ));
897 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
900 //=============================================================================
902 * Returns StudyContextStruct for a study
904 //=============================================================================
906 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
908 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
910 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
912 _mapStudyContext[studyId] = new StudyContextStruct;
913 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
915 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
916 return myStudyContext;
919 //================================================================================
921 * \brief Return shape dimension by TopAbs_ShapeEnum
923 //================================================================================
925 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
927 static vector<int> dim;
930 dim.resize( TopAbs_SHAPE, -1 );
931 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
932 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
933 dim[ TopAbs_SOLID ] = MeshDim_3D;
934 dim[ TopAbs_SHELL ] = MeshDim_3D;
935 dim[ TopAbs_FACE ] = MeshDim_2D;
936 dim[ TopAbs_WIRE ] = MeshDim_1D;
937 dim[ TopAbs_EDGE ] = MeshDim_1D;
938 dim[ TopAbs_VERTEX ] = MeshDim_0D;
940 return dim[ aShapeType ];
943 //=============================================================================
945 * Genarate a new id unique withing this Gen
947 //=============================================================================
949 int SMESH_Gen::GetANewId()