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>
55 //=============================================================================
59 //=============================================================================
61 SMESH_Gen::SMESH_Gen()
63 MESSAGE("SMESH_Gen::SMESH_Gen");
66 _segmentation = _nbSegments = 10;
67 SMDS_Mesh::_meshList.clear();
68 MESSAGE(SMDS_Mesh::_meshList.size());
69 _counters = new counters(100);
70 #ifdef WITH_SMESH_CANCEL_COMPUTE
71 _compute_canceled = false;
76 //=============================================================================
80 //=============================================================================
82 SMESH_Gen::~SMESH_Gen()
84 MESSAGE("SMESH_Gen::~SMESH_Gen");
87 //=============================================================================
89 * Creates a mesh in a study.
90 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
92 //=============================================================================
94 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
95 throw(SALOME_Exception)
97 Unexpect aCatch(SalomeException);
98 MESSAGE("SMESH_Gen::CreateMesh");
100 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
101 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
103 // create a new SMESH_mesh object
104 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
108 aStudyContext->myDocument);
109 aStudyContext->mapMesh[_localId-1] = aMesh;
114 //=============================================================================
118 //=============================================================================
120 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
121 const TopoDS_Shape & aShape,
123 const ::MeshDimension aDim,
124 TSetOfInt* aShapesId)
126 MESSAGE("SMESH_Gen::Compute");
131 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
133 const bool includeSelf = true;
134 const bool complexShapeFirst = true;
135 const int globalAlgoDim = 100;
137 SMESH_subMeshIteratorPtr smIt;
139 if ( anUpward ) // is called from below code here
141 // -----------------------------------------------
142 // mesh all the sub-shapes starting from vertices
143 // -----------------------------------------------
144 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
145 while ( smIt->more() )
147 SMESH_subMesh* smToCompute = smIt->next();
149 // do not mesh vertices of a pseudo shape
150 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
151 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
154 // check for preview dimension limitations
155 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
157 // clear compute state to not show previous compute errors
158 // if preview invoked less dimension less than previous
159 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
163 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
165 #ifdef WITH_SMESH_CANCEL_COMPUTE
166 if (_compute_canceled)
168 _sm_current = smToCompute;
170 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
171 #ifdef WITH_SMESH_CANCEL_COMPUTE
176 // we check all the submeshes here and detect if any of them failed to compute
177 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
179 else if ( aShapesId )
180 aShapesId->insert( smToCompute->GetId() );
182 //aMesh.GetMeshDS()->Modified();
187 // -----------------------------------------------------------------
188 // apply algos that DO NOT require Discreteized boundaries and DO NOT
189 // support submeshes, starting from the most complex shapes
190 // and collect submeshes with algos that DO support submeshes
191 // -----------------------------------------------------------------
192 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
194 // map to sort sm with same dim algos according to dim of
195 // the shape the algo assigned to (issue 0021217)
196 multimap< int, SMESH_subMesh* > shDim2sm;
197 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
198 TopoDS_Shape algoShape;
199 int prevShapeDim = -1;
201 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
202 while ( smIt->more() )
204 SMESH_subMesh* smToCompute = smIt->next();
205 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
208 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
209 int aShapeDim = GetShapeDim( aSubShape );
210 if ( aShapeDim < 1 ) break;
212 // check for preview dimension limitations
213 if ( aShapesId && aShapeDim > (int)aDim )
216 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
217 if ( algo && !algo->NeedDiscreteBoundary() )
219 if ( algo->SupportSubmeshes() )
221 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
222 // so that more local algos to go first
223 if ( prevShapeDim != aShapeDim )
225 prevShapeDim = aShapeDim;
226 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
227 if ( shDim2smIt->first == globalAlgoDim )
228 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
230 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
233 // add smToCompute to shDim2sm map
234 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
236 aShapeDim = globalAlgoDim; // to compute last
240 aShapeDim = GetShapeDim( algoShape );
241 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
243 TopoDS_Iterator it( algoShape );
244 aShapeDim += GetShapeDim( it.Value() );
247 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
251 #ifdef WITH_SMESH_CANCEL_COMPUTE
252 if (_compute_canceled)
254 _sm_current = smToCompute;
256 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
257 #ifdef WITH_SMESH_CANCEL_COMPUTE
261 aShapesId->insert( smToCompute->GetId() );
265 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
266 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
267 if ( shDim2smIt->first == globalAlgoDim )
268 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
270 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
272 // ------------------------------------------------------------
273 // sort list of submeshes according to mesh order
274 // ------------------------------------------------------------
275 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
277 // ------------------------------------------------------------
278 // compute submeshes under shapes with algos that DO NOT require
279 // Discreteized boundaries and DO support submeshes
280 // ------------------------------------------------------------
281 list< SMESH_subMesh* >::iterator subIt, subEnd;
282 subIt = smWithAlgoSupportingSubmeshes.begin();
283 subEnd = smWithAlgoSupportingSubmeshes.end();
284 // start from lower shapes
285 for ( ; subIt != subEnd; ++subIt )
289 // get a shape the algo is assigned to
290 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
291 continue; // strange...
293 // look for more local algos
294 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
295 while ( smIt->more() )
297 SMESH_subMesh* smToCompute = smIt->next();
299 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
300 const int aShapeDim = GetShapeDim( aSubShape );
301 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
302 if ( aShapeDim < 1 ) continue;
304 // check for preview dimension limitations
305 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
308 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
310 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
311 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
313 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
314 SMESH_Hypothesis::Hypothesis_Status status;
315 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
316 // mesh a lower smToCompute starting from vertices
317 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
321 // ----------------------------------------------------------
322 // apply the algos that do not require Discreteized boundaries
323 // ----------------------------------------------------------
324 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
327 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
329 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
330 // check for preview dimension limitations
331 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
334 #ifdef WITH_SMESH_CANCEL_COMPUTE
335 if (_compute_canceled)
339 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
340 #ifdef WITH_SMESH_CANCEL_COMPUTE
344 aShapesId->insert( sm->GetId() );
347 // -----------------------------------------------
348 // mesh the rest sub-shapes starting from vertices
349 // -----------------------------------------------
350 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
353 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
356 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
357 myMesh->adjustStructure();
358 MESSAGE("*** compactMesh after compute");
359 myMesh->compactMesh();
360 //myMesh->adjustStructure();
361 list<int> listind = myMesh->SubMeshIndices();
362 list<int>::iterator it = listind.begin();
364 for(; it != listind.end(); ++it)
366 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
367 total += subMesh->getSize();
369 MESSAGE("total elements and nodes in submesh sets:" << total);
370 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
371 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
372 //myMesh->dumpGrid();
373 //aMesh.GetMeshDS()->Modified();
375 // fix quadratic mesh by bending iternal links near concave boundary
376 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
377 !aShapesId ) // not preview
379 SMESH_MesherHelper aHelper( aMesh );
380 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
381 aHelper.FixQuadraticElements();
387 #ifdef WITH_SMESH_CANCEL_COMPUTE
388 //=============================================================================
390 * Prepare Compute a mesh
392 //=============================================================================
393 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
394 const TopoDS_Shape & aShape)
396 _compute_canceled = false;
399 //=============================================================================
401 * Cancel Compute a mesh
403 //=============================================================================
404 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
405 const TopoDS_Shape & aShape)
407 _compute_canceled = true;
410 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
415 //=============================================================================
419 //=============================================================================
421 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
422 const TopoDS_Shape & aShape,
423 MapShapeNbElems& aResMap,
425 TSetOfInt* aShapesId)
427 MESSAGE("SMESH_Gen::Evaluate");
431 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
433 const bool includeSelf = true;
434 const bool complexShapeFirst = true;
435 SMESH_subMeshIteratorPtr smIt;
437 if ( anUpward ) { // is called from below code here
438 // -----------------------------------------------
439 // mesh all the sub-shapes starting from vertices
440 // -----------------------------------------------
441 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
442 while ( smIt->more() ) {
443 SMESH_subMesh* smToCompute = smIt->next();
445 // do not mesh vertices of a pseudo shape
446 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
447 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
449 if ( !aMesh.HasShapeToMesh() ) {
450 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
451 aShType == TopAbs_SHELL )
455 smToCompute->Evaluate(aResMap);
457 aShapesId->insert( smToCompute->GetId() );
462 // -----------------------------------------------------------------
463 // apply algos that DO NOT require Discreteized boundaries and DO NOT
464 // support submeshes, starting from the most complex shapes
465 // and collect submeshes with algos that DO support submeshes
466 // -----------------------------------------------------------------
467 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
468 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
469 while ( smIt->more() ) {
470 SMESH_subMesh* smToCompute = smIt->next();
471 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
472 const int aShapeDim = GetShapeDim( aSubShape );
473 if ( aShapeDim < 1 ) break;
475 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
476 if ( algo && !algo->NeedDiscreteBoundary() ) {
477 if ( algo->SupportSubmeshes() ) {
478 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
481 smToCompute->Evaluate(aResMap);
483 aShapesId->insert( smToCompute->GetId() );
488 // ------------------------------------------------------------
489 // sort list of meshes according to mesh order
490 // ------------------------------------------------------------
491 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
493 // ------------------------------------------------------------
494 // compute submeshes under shapes with algos that DO NOT require
495 // Discreteized boundaries and DO support submeshes
496 // ------------------------------------------------------------
497 list< SMESH_subMesh* >::iterator subIt, subEnd;
498 subIt = smWithAlgoSupportingSubmeshes.begin();
499 subEnd = smWithAlgoSupportingSubmeshes.end();
500 // start from lower shapes
501 for ( ; subIt != subEnd; ++subIt ) {
504 // get a shape the algo is assigned to
505 TopoDS_Shape algoShape;
506 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
507 continue; // strange...
509 // look for more local algos
510 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
511 while ( smIt->more() ) {
512 SMESH_subMesh* smToCompute = smIt->next();
514 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
515 const int aShapeDim = GetShapeDim( aSubShape );
516 if ( aShapeDim < 1 ) continue;
518 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
520 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
522 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
523 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
525 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
526 SMESH_Hypothesis::Hypothesis_Status status;
527 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
528 // mesh a lower smToCompute starting from vertices
529 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
533 // ----------------------------------------------------------
534 // apply the algos that do not require Discreteized boundaries
535 // ----------------------------------------------------------
536 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
539 sm->Evaluate(aResMap);
541 aShapesId->insert( sm->GetId() );
544 // -----------------------------------------------
545 // mesh the rest sub-shapes starting from vertices
546 // -----------------------------------------------
547 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
550 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
555 //=======================================================================
556 //function : checkConformIgnoredAlgos
558 //=======================================================================
560 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
561 SMESH_subMesh* aSubMesh,
562 const SMESH_Algo* aGlobIgnoAlgo,
563 const SMESH_Algo* aLocIgnoAlgo,
565 set<SMESH_subMesh*>& aCheckedMap,
566 list< SMESH_Gen::TAlgoStateError > & theErrors)
569 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
575 const list<const SMESHDS_Hypothesis*>& listHyp =
576 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
577 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
578 for ( ; it != listHyp.end(); it++)
580 const SMESHDS_Hypothesis * aHyp = *it;
581 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
584 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
587 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
589 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
590 << aLocIgnoAlgo->GetName() << ">");
594 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
595 int dim = algo->GetDim();
596 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
598 if ( dim < aMaxGlobIgnoDim )
600 // algo is hidden by a global algo
601 INFOS( ( isGlobal ? "Global" : "Local" )
602 << " <" << algo->GetName() << "> is hidden by global <"
603 << aGlobIgnoAlgo->GetName() << ">");
605 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
607 // local algo is not hidden and hides algos on sub-shapes
608 if (checkConform && !aSubMesh->IsConform( algo ))
611 checkConform = false; // no more check conformity
612 INFOS( "ERROR: Local <" << algo->GetName() <<
613 "> would produce not conform mesh: "
614 "<Not Conform Mesh Allowed> hypotesis is missing");
615 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
616 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
619 // sub-algos will be hidden by a local <algo>
620 SMESH_subMeshIteratorPtr revItSub =
621 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
622 bool checkConform2 = false;
623 while ( revItSub->more() )
625 SMESH_subMesh* sm = revItSub->next();
626 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
627 algo, checkConform2, aCheckedMap, theErrors);
628 aCheckedMap.insert( sm );
637 //=======================================================================
638 //function : checkMissing
639 //purpose : notify on missing hypothesis
640 // Return false if algo or hipothesis is missing
641 //=======================================================================
643 static bool checkMissing(SMESH_Gen* aGen,
645 SMESH_subMesh* aSubMesh,
646 const int aTopAlgoDim,
648 const bool checkNoAlgo,
649 set<SMESH_subMesh*>& aCheckedMap,
650 list< SMESH_Gen::TAlgoStateError > & theErrors)
652 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
655 //MESSAGE("=====checkMissing");
658 SMESH_Algo* algo = 0;
660 switch (aSubMesh->GetAlgoState())
662 case SMESH_subMesh::NO_ALGO: {
665 // should there be any algo?
666 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
667 if (aTopAlgoDim > shapeDim)
669 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
671 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
672 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
677 case SMESH_subMesh::MISSING_HYP: {
678 // notify if an algo missing hyp is attached to aSubMesh
679 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
681 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
682 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
684 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
685 SMESH_Hypothesis::Hypothesis_Status status;
686 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
687 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
688 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
689 << "<" << algo->GetName() << "> has a bad parameter value");
691 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
692 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
693 << "<" << algo->GetName() << "> assigned to mismatching geometry");
696 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
697 << "<" << algo->GetName() << "> misses some hypothesis");
699 if (IsGlobalHypothesis)
700 globalChecked[ algo->GetDim() ] = true;
701 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
702 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
707 case SMESH_subMesh::HYP_OK:
708 algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
714 // do not check under algo that hides sub-algos or
715 // re-start checking NO_ALGO state
717 bool isTopLocalAlgo =
718 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
719 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
721 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
722 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
723 /*complexShapeFirst=*/false);
724 while ( itsub->more() )
726 // sub-meshes should not be checked further more
727 SMESH_subMesh* sm = itsub->next();
728 aCheckedMap.insert( sm );
732 //check algo on sub-meshes
733 int aTopAlgoDim2 = algo->GetDim();
734 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
735 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
738 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
739 checkNoAlgo2 = false;
747 //=======================================================================
748 //function : CheckAlgoState
749 //purpose : notify on bad state of attached algos, return false
750 // if Compute() would fail because of some algo bad state
751 //=======================================================================
753 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
755 list< TAlgoStateError > errors;
756 return GetAlgoState( aMesh, aShape, errors );
759 //=======================================================================
760 //function : GetAlgoState
761 //purpose : notify on bad state of attached algos, return false
762 // if Compute() would fail because of some algo bad state
763 // theErrors list contains problems description
764 //=======================================================================
766 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
767 const TopoDS_Shape& theShape,
768 list< TAlgoStateError > & theErrors)
770 //MESSAGE("SMESH_Gen::CheckAlgoState");
773 bool hasAlgo = false;
775 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
776 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
777 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
783 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
785 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
786 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
787 for ( ; it != listHyp.end(); it++)
789 const SMESHDS_Hypothesis * aHyp = *it;
790 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
793 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
796 int dim = algo->GetDim();
797 aGlobAlgoArr[ dim ] = algo;
802 // --------------------------------------------------------
803 // info on algos that will be ignored because of ones that
804 // don't NeedDiscreteBoundary() attached to super-shapes,
805 // check that a conform mesh will be produced
806 // --------------------------------------------------------
809 // find a global algo possibly hiding sub-algos
811 const SMESH_Algo* aGlobIgnoAlgo = 0;
812 for (dim = 3; dim > 0; dim--)
814 if (aGlobAlgoArr[ dim ] &&
815 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary())
817 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
822 set<SMESH_subMesh*> aCheckedSubs;
823 bool checkConform = ( !theMesh.IsNotConformAllowed() );
825 // loop on theShape and its sub-shapes
826 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
827 /*complexShapeFirst=*/true);
828 while ( revItSub->more() )
830 SMESH_subMesh* smToCheck = revItSub->next();
831 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
834 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
835 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
836 0, checkConform, aCheckedSubs, theErrors))
839 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
843 // ----------------------------------------------------------------
844 // info on missing hypothesis and find out if all needed algos are
846 // ----------------------------------------------------------------
848 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
850 // find max dim of global algo
852 for (dim = 3; dim > 0; dim--)
854 if (aGlobAlgoArr[ dim ])
860 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
861 bool globalChecked[] = { false, false, false, false };
863 // loop on theShape and its sub-shapes
864 aCheckedSubs.clear();
865 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
866 while ( revItSub->more() )
868 SMESH_subMesh* smToCheck = revItSub->next();
869 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
872 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
873 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
874 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
877 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
884 //INFOS( "None algorithm attached" );
885 theErrors.push_back( TAlgoStateError() );
886 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
892 //=======================================================================
893 //function : IsGlobalHypothesis
894 //purpose : check if theAlgo is attached to the main shape
895 //=======================================================================
897 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
899 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
900 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
903 //================================================================================
905 * \brief Return paths to xml files of plugins
907 //================================================================================
909 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
911 // Get paths to xml files of plugins
912 vector< string > xmlPaths;
914 if ( const char* meshersList = getenv("SMESH_MeshersList") )
916 string meshers = meshersList, plugin;
917 string::size_type from = 0, pos;
918 while ( from < meshers.size() )
920 // cut off plugin name
921 pos = meshers.find( ':', from );
922 if ( pos != string::npos )
923 plugin = meshers.substr( from, pos-from );
925 plugin = meshers.substr( from ), pos = meshers.size();
928 // get PLUGIN_ROOT_DIR path
929 string rootDirVar, pluginSubDir = plugin;
930 if ( plugin == "StdMeshers" )
931 rootDirVar = "SMESH", pluginSubDir = "smesh";
933 for ( pos = 0; pos < plugin.size(); ++pos )
934 rootDirVar += toupper( plugin[pos] );
935 rootDirVar += "_ROOT_DIR";
937 const char* rootDir = getenv( rootDirVar.c_str() );
938 if ( !rootDir || strlen(rootDir) == 0 )
940 rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
941 rootDir = getenv( rootDirVar.c_str() );
942 if ( !rootDir || strlen(rootDir) == 0 ) continue;
945 // get a separator from rootDir
946 for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
947 if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
953 if (sep.empty() ) sep = "\\";
955 if (sep.empty() ) sep = "/";
958 // get a path to resource file
959 string xmlPath = rootDir;
960 if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
962 xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
963 for ( pos = 0; pos < pluginSubDir.size(); ++pos )
964 xmlPath += tolower( pluginSubDir[pos] );
965 xmlPath += sep + plugin + ".xml";
968 fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
970 fileOK = (access(xmlPath.c_str(), F_OK) == 0);
973 xmlPaths.push_back( xmlPath );
980 //=============================================================================
982 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
984 //=============================================================================
986 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
987 const TopoDS_Shape & aShape,
988 TopoDS_Shape* assignedTo)
990 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
991 filter.And( filter.IsApplicableTo( aShape ));
993 return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
996 //=============================================================================
998 * Returns StudyContextStruct for a study
1000 //=============================================================================
1002 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
1004 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
1006 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
1008 _mapStudyContext[studyId] = new StudyContextStruct;
1009 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
1011 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
1012 return myStudyContext;
1015 //================================================================================
1017 * \brief Return shape dimension by TopAbs_ShapeEnum
1019 //================================================================================
1021 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1023 static vector<int> dim;
1026 dim.resize( TopAbs_SHAPE, -1 );
1027 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
1028 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1029 dim[ TopAbs_SOLID ] = MeshDim_3D;
1030 dim[ TopAbs_SHELL ] = MeshDim_2D;
1031 dim[ TopAbs_FACE ] = MeshDim_2D;
1032 dim[ TopAbs_WIRE ] = MeshDim_1D;
1033 dim[ TopAbs_EDGE ] = MeshDim_1D;
1034 dim[ TopAbs_VERTEX ] = MeshDim_0D;
1036 return dim[ aShapeType ];
1039 //=============================================================================
1041 * Genarate a new id unique withing this Gen
1043 //=============================================================================
1045 int SMESH_Gen::GetANewId()