1 // Copyright (C) 2007-2012 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-1] = 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;
131 const int globalAlgoDim = 100;
133 SMESH_subMeshIteratorPtr smIt;
135 if ( anUpward ) // is called from below code here
137 // -----------------------------------------------
138 // mesh all the sub-shapes starting from vertices
139 // -----------------------------------------------
140 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
141 while ( smIt->more() )
143 SMESH_subMesh* smToCompute = smIt->next();
145 // do not mesh vertices of a pseudo shape
146 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
147 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
150 // check for preview dimension limitations
151 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
153 // clear compute state to not show previous compute errors
154 // if preview invoked less dimension less than previous
155 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
159 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
161 #ifdef WITH_SMESH_CANCEL_COMPUTE
162 if (_compute_canceled)
164 _sm_current = smToCompute;
166 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
167 #ifdef WITH_SMESH_CANCEL_COMPUTE
172 // we check all the submeshes here and detect if any of them failed to compute
173 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
175 else if ( aShapesId )
176 aShapesId->insert( smToCompute->GetId() );
178 //aMesh.GetMeshDS()->Modified();
183 // -----------------------------------------------------------------
184 // apply algos that DO NOT require Discreteized boundaries and DO NOT
185 // support submeshes, starting from the most complex shapes
186 // and collect submeshes with algos that DO support submeshes
187 // -----------------------------------------------------------------
188 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
190 // map to sort sm with same dim algos according to dim of
191 // the shape the algo assigned to (issue 0021217)
192 multimap< int, SMESH_subMesh* > shDim2sm;
193 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
194 TopoDS_Shape algoShape;
195 int prevShapeDim = -1;
197 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
198 while ( smIt->more() )
200 SMESH_subMesh* smToCompute = smIt->next();
201 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
204 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
205 int aShapeDim = GetShapeDim( aSubShape );
206 if ( aShapeDim < 1 ) break;
208 // check for preview dimension limitations
209 if ( aShapesId && aShapeDim > (int)aDim )
212 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
213 if ( algo && !algo->NeedDiscreteBoundary() )
215 if ( algo->SupportSubmeshes() )
217 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
218 // so that more local algos to go first
219 if ( prevShapeDim != aShapeDim )
221 prevShapeDim = aShapeDim;
222 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
223 if ( shDim2smIt->first == globalAlgoDim )
224 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
226 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
229 // add smToCompute to shDim2sm map
230 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
232 aShapeDim = globalAlgoDim; // to compute last
236 aShapeDim = GetShapeDim( algoShape );
237 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
239 TopoDS_Iterator it( algoShape );
240 aShapeDim += GetShapeDim( it.Value() );
243 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
247 #ifdef WITH_SMESH_CANCEL_COMPUTE
248 if (_compute_canceled)
250 _sm_current = smToCompute;
252 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
253 #ifdef WITH_SMESH_CANCEL_COMPUTE
257 aShapesId->insert( smToCompute->GetId() );
261 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
262 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
263 if ( shDim2smIt->first == globalAlgoDim )
264 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
266 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
268 // ------------------------------------------------------------
269 // sort list of submeshes according to mesh order
270 // ------------------------------------------------------------
271 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
273 // ------------------------------------------------------------
274 // compute submeshes under shapes with algos that DO NOT require
275 // Discreteized boundaries and DO support submeshes
276 // ------------------------------------------------------------
277 list< SMESH_subMesh* >::iterator subIt, subEnd;
278 subIt = smWithAlgoSupportingSubmeshes.begin();
279 subEnd = smWithAlgoSupportingSubmeshes.end();
280 // start from lower shapes
281 for ( ; subIt != subEnd; ++subIt )
285 // get a shape the algo is assigned to
286 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
287 continue; // strange...
289 // look for more local algos
290 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
291 while ( smIt->more() )
293 SMESH_subMesh* smToCompute = smIt->next();
295 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
296 const int aShapeDim = GetShapeDim( aSubShape );
297 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
298 if ( aShapeDim < 1 ) continue;
300 // check for preview dimension limitations
301 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
304 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
306 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
307 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
309 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
310 SMESH_Hypothesis::Hypothesis_Status status;
311 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
312 // mesh a lower smToCompute starting from vertices
313 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
317 // ----------------------------------------------------------
318 // apply the algos that do not require Discreteized boundaries
319 // ----------------------------------------------------------
320 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
323 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
325 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
326 // check for preview dimension limitations
327 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
330 #ifdef WITH_SMESH_CANCEL_COMPUTE
331 if (_compute_canceled)
335 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
336 #ifdef WITH_SMESH_CANCEL_COMPUTE
340 aShapesId->insert( sm->GetId() );
343 // -----------------------------------------------
344 // mesh the rest sub-shapes starting from vertices
345 // -----------------------------------------------
346 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
349 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
352 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
353 myMesh->adjustStructure();
354 MESSAGE("*** compactMesh after compute");
355 myMesh->compactMesh();
356 //myMesh->adjustStructure();
357 list<int> listind = myMesh->SubMeshIndices();
358 list<int>::iterator it = listind.begin();
360 for(; it != listind.end(); ++it)
362 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
363 total += subMesh->getSize();
365 MESSAGE("total elements and nodes in submesh sets:" << total);
366 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
367 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
368 //myMesh->dumpGrid();
369 //aMesh.GetMeshDS()->Modified();
371 // fix quadratic mesh by bending iternal links near concave boundary
372 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
373 !aShapesId ) // not preview
375 SMESH_MesherHelper aHelper( aMesh );
376 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
377 aHelper.FixQuadraticElements();
383 #ifdef WITH_SMESH_CANCEL_COMPUTE
384 //=============================================================================
386 * Prepare Compute a mesh
388 //=============================================================================
389 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
390 const TopoDS_Shape & aShape)
392 _compute_canceled = false;
395 //=============================================================================
397 * Cancel Compute a mesh
399 //=============================================================================
400 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
401 const TopoDS_Shape & aShape)
403 _compute_canceled = true;
406 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
411 //=============================================================================
415 //=============================================================================
417 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
418 const TopoDS_Shape & aShape,
419 MapShapeNbElems& aResMap,
421 TSetOfInt* aShapesId)
423 MESSAGE("SMESH_Gen::Evaluate");
427 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
429 const bool includeSelf = true;
430 const bool complexShapeFirst = true;
431 SMESH_subMeshIteratorPtr smIt;
433 if ( anUpward ) { // is called from below code here
434 // -----------------------------------------------
435 // mesh all the sub-shapes starting from vertices
436 // -----------------------------------------------
437 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
438 while ( smIt->more() ) {
439 SMESH_subMesh* smToCompute = smIt->next();
441 // do not mesh vertices of a pseudo shape
442 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
443 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
445 if ( !aMesh.HasShapeToMesh() ) {
446 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
447 aShType == TopAbs_SHELL )
451 smToCompute->Evaluate(aResMap);
453 aShapesId->insert( smToCompute->GetId() );
458 // -----------------------------------------------------------------
459 // apply algos that DO NOT require Discreteized boundaries and DO NOT
460 // support submeshes, starting from the most complex shapes
461 // and collect submeshes with algos that DO support submeshes
462 // -----------------------------------------------------------------
463 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
464 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
465 while ( smIt->more() ) {
466 SMESH_subMesh* smToCompute = smIt->next();
467 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
468 const int aShapeDim = GetShapeDim( aSubShape );
469 if ( aShapeDim < 1 ) break;
471 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
472 if ( algo && !algo->NeedDiscreteBoundary() ) {
473 if ( algo->SupportSubmeshes() ) {
474 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
477 smToCompute->Evaluate(aResMap);
479 aShapesId->insert( smToCompute->GetId() );
484 // ------------------------------------------------------------
485 // sort list of meshes according to mesh order
486 // ------------------------------------------------------------
487 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
489 // ------------------------------------------------------------
490 // compute submeshes under shapes with algos that DO NOT require
491 // Discreteized boundaries and DO support submeshes
492 // ------------------------------------------------------------
493 list< SMESH_subMesh* >::iterator subIt, subEnd;
494 subIt = smWithAlgoSupportingSubmeshes.begin();
495 subEnd = smWithAlgoSupportingSubmeshes.end();
496 // start from lower shapes
497 for ( ; subIt != subEnd; ++subIt ) {
500 // get a shape the algo is assigned to
501 TopoDS_Shape algoShape;
502 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
503 continue; // strange...
505 // look for more local algos
506 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
507 while ( smIt->more() ) {
508 SMESH_subMesh* smToCompute = smIt->next();
510 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
511 const int aShapeDim = GetShapeDim( aSubShape );
512 if ( aShapeDim < 1 ) continue;
514 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
516 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
518 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
519 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
521 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
522 SMESH_Hypothesis::Hypothesis_Status status;
523 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
524 // mesh a lower smToCompute starting from vertices
525 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
529 // ----------------------------------------------------------
530 // apply the algos that do not require Discreteized boundaries
531 // ----------------------------------------------------------
532 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
535 sm->Evaluate(aResMap);
537 aShapesId->insert( sm->GetId() );
540 // -----------------------------------------------
541 // mesh the rest sub-shapes starting from vertices
542 // -----------------------------------------------
543 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
546 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
551 //=======================================================================
552 //function : checkConformIgnoredAlgos
554 //=======================================================================
556 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
557 SMESH_subMesh* aSubMesh,
558 const SMESH_Algo* aGlobIgnoAlgo,
559 const SMESH_Algo* aLocIgnoAlgo,
561 set<SMESH_subMesh*>& aCheckedMap,
562 list< SMESH_Gen::TAlgoStateError > & theErrors)
565 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
571 const list<const SMESHDS_Hypothesis*>& listHyp =
572 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
573 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
574 for ( ; it != listHyp.end(); it++)
576 const SMESHDS_Hypothesis * aHyp = *it;
577 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
580 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
583 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
585 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
586 << aLocIgnoAlgo->GetName() << ">");
590 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
591 int dim = algo->GetDim();
592 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
594 if ( dim < aMaxGlobIgnoDim )
596 // algo is hidden by a global algo
597 INFOS( ( isGlobal ? "Global" : "Local" )
598 << " <" << algo->GetName() << "> is hidden by global <"
599 << aGlobIgnoAlgo->GetName() << ">");
601 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
603 // local algo is not hidden and hides algos on sub-shapes
604 if (checkConform && !aSubMesh->IsConform( algo ))
607 checkConform = false; // no more check conformity
608 INFOS( "ERROR: Local <" << algo->GetName() <<
609 "> would produce not conform mesh: "
610 "<Not Conform Mesh Allowed> hypotesis is missing");
611 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
612 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
615 // sub-algos will be hidden by a local <algo>
616 SMESH_subMeshIteratorPtr revItSub =
617 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
618 bool checkConform2 = false;
619 while ( revItSub->more() )
621 SMESH_subMesh* sm = revItSub->next();
622 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
623 algo, checkConform2, aCheckedMap, theErrors);
624 aCheckedMap.insert( sm );
633 //=======================================================================
634 //function : checkMissing
635 //purpose : notify on missing hypothesis
636 // Return false if algo or hipothesis is missing
637 //=======================================================================
639 static bool checkMissing(SMESH_Gen* aGen,
641 SMESH_subMesh* aSubMesh,
642 const int aTopAlgoDim,
644 const bool checkNoAlgo,
645 set<SMESH_subMesh*>& aCheckedMap,
646 list< SMESH_Gen::TAlgoStateError > & theErrors)
648 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
651 //MESSAGE("=====checkMissing");
654 SMESH_Algo* algo = 0;
656 switch (aSubMesh->GetAlgoState())
658 case SMESH_subMesh::NO_ALGO: {
661 // should there be any algo?
662 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
663 if (aTopAlgoDim > shapeDim)
665 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
667 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
668 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
673 case SMESH_subMesh::MISSING_HYP: {
674 // notify if an algo missing hyp is attached to aSubMesh
675 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
677 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
678 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
680 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
681 SMESH_Hypothesis::Hypothesis_Status status;
682 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
683 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
684 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
685 << "<" << algo->GetName() << "> has a bad parameter value");
687 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
688 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
689 << "<" << algo->GetName() << "> assigned to mismatching geometry");
692 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
693 << "<" << algo->GetName() << "> misses some hypothesis");
695 if (IsGlobalHypothesis)
696 globalChecked[ algo->GetDim() ] = true;
697 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
698 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
703 case SMESH_subMesh::HYP_OK:
704 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
710 // do not check under algo that hides sub-algos or
711 // re-start checking NO_ALGO state
713 bool isTopLocalAlgo =
714 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
715 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
717 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
718 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
719 /*complexShapeFirst=*/false);
720 while ( itsub->more() )
722 // sub-meshes should not be checked further more
723 SMESH_subMesh* sm = itsub->next();
724 aCheckedMap.insert( sm );
728 //check algo on sub-meshes
729 int aTopAlgoDim2 = algo->GetDim();
730 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
731 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
734 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
735 checkNoAlgo2 = false;
743 //=======================================================================
744 //function : CheckAlgoState
745 //purpose : notify on bad state of attached algos, return false
746 // if Compute() would fail because of some algo bad state
747 //=======================================================================
749 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
751 list< TAlgoStateError > errors;
752 return GetAlgoState( aMesh, aShape, errors );
755 //=======================================================================
756 //function : GetAlgoState
757 //purpose : notify on bad state of attached algos, return false
758 // if Compute() would fail because of some algo bad state
759 // theErrors list contains problems description
760 //=======================================================================
762 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
763 const TopoDS_Shape& theShape,
764 list< TAlgoStateError > & theErrors)
766 //MESSAGE("SMESH_Gen::CheckAlgoState");
769 bool hasAlgo = false;
771 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
772 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
773 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
779 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
781 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
782 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
783 for ( ; it != listHyp.end(); it++)
785 const SMESHDS_Hypothesis * aHyp = *it;
786 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
789 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
792 int dim = algo->GetDim();
793 aGlobAlgoArr[ dim ] = algo;
798 // --------------------------------------------------------
799 // info on algos that will be ignored because of ones that
800 // don't NeedDiscreteBoundary() attached to super-shapes,
801 // check that a conform mesh will be produced
802 // --------------------------------------------------------
805 // find a global algo possibly hiding sub-algos
807 const SMESH_Algo* aGlobIgnoAlgo = 0;
808 for (dim = 3; dim > 0; dim--)
810 if (aGlobAlgoArr[ dim ] &&
811 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary())
813 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
818 set<SMESH_subMesh*> aCheckedSubs;
819 bool checkConform = ( !theMesh.IsNotConformAllowed() );
821 // loop on theShape and its sub-shapes
822 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
823 /*complexShapeFirst=*/true);
824 while ( revItSub->more() )
826 SMESH_subMesh* smToCheck = revItSub->next();
827 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
830 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
831 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
832 0, checkConform, aCheckedSubs, theErrors))
835 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
839 // ----------------------------------------------------------------
840 // info on missing hypothesis and find out if all needed algos are
842 // ----------------------------------------------------------------
844 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
846 // find max dim of global algo
848 for (dim = 3; dim > 0; dim--)
850 if (aGlobAlgoArr[ dim ])
856 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
857 bool globalChecked[] = { false, false, false, false };
859 // loop on theShape and its sub-shapes
860 aCheckedSubs.clear();
861 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
862 while ( revItSub->more() )
864 SMESH_subMesh* smToCheck = revItSub->next();
865 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
868 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
869 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
870 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
873 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
880 INFOS( "None algorithm attached" );
881 theErrors.push_back( TAlgoStateError() );
882 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
888 //=======================================================================
889 //function : IsGlobalHypothesis
890 //purpose : check if theAlgo is attached to the main shape
891 //=======================================================================
893 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
895 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
896 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
899 //=============================================================================
901 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
903 //=============================================================================
905 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
906 const TopoDS_Shape & aShape,
907 TopoDS_Shape* assignedTo)
909 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
910 filter.And( filter.IsApplicableTo( aShape ));
912 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
915 //=============================================================================
917 * Returns StudyContextStruct for a study
919 //=============================================================================
921 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
923 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
925 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
927 _mapStudyContext[studyId] = new StudyContextStruct;
928 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
930 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
931 return myStudyContext;
934 //================================================================================
936 * \brief Return shape dimension by TopAbs_ShapeEnum
938 //================================================================================
940 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
942 static vector<int> dim;
945 dim.resize( TopAbs_SHAPE, -1 );
946 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
947 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
948 dim[ TopAbs_SOLID ] = MeshDim_3D;
949 dim[ TopAbs_SHELL ] = MeshDim_2D;
950 dim[ TopAbs_FACE ] = MeshDim_2D;
951 dim[ TopAbs_WIRE ] = MeshDim_1D;
952 dim[ TopAbs_EDGE ] = MeshDim_1D;
953 dim[ TopAbs_VERTEX ] = MeshDim_0D;
955 return dim[ aShapeType ];
958 //=============================================================================
960 * Genarate a new id unique withing this Gen
962 //=============================================================================
964 int SMESH_Gen::GetANewId()