1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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>
56 //#include <vtkDebugLeaks.h>
59 //=============================================================================
63 //=============================================================================
65 SMESH_Gen::SMESH_Gen()
67 MESSAGE("SMESH_Gen::SMESH_Gen");
70 _segmentation = _nbSegments = 10;
71 SMDS_Mesh::_meshList.clear();
72 MESSAGE(SMDS_Mesh::_meshList.size());
73 //_counters = new counters(100);
74 _compute_canceled = false;
76 //vtkDebugLeaks::SetExitError(0);
79 //=============================================================================
83 //=============================================================================
85 SMESH_Gen::~SMESH_Gen()
87 MESSAGE("SMESH_Gen::~SMESH_Gen");
88 std::map < int, StudyContextStruct * >::iterator i_sc = _mapStudyContext.begin();
89 for ( ; i_sc != _mapStudyContext.end(); ++i_sc )
91 delete i_sc->second->myDocument;
96 //=============================================================================
98 * Creates a mesh in a study.
99 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
101 //=============================================================================
103 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
104 throw(SALOME_Exception)
106 Unexpect aCatch(SalomeException);
107 MESSAGE("SMESH_Gen::CreateMesh");
109 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
110 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
112 // create a new SMESH_mesh object
113 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
117 aStudyContext->myDocument);
118 aStudyContext->mapMesh[_localId-1] = aMesh;
123 //=============================================================================
127 //=============================================================================
129 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
130 const TopoDS_Shape & aShape,
131 const bool aShapeOnly /*=false*/,
132 const bool anUpward /*=false*/,
133 const ::MeshDimension aDim /*=::MeshDim_3D*/,
134 TSetOfInt* aShapesId /*=0*/)
136 MESSAGE("SMESH_Gen::Compute");
141 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
143 const bool includeSelf = true;
144 const bool complexShapeFirst = true;
145 const int globalAlgoDim = 100;
147 SMESH_subMeshIteratorPtr smIt;
149 // Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
150 // that must be computed by Projection 1D-2D when Projection asks to compute
152 SMESH_subMesh::compute_event computeEvent =
153 aShapeOnly ? SMESH_subMesh::COMPUTE_SUBMESH : SMESH_subMesh::COMPUTE;
155 if ( anUpward ) // is called from the below code in this method
157 // ===============================================
158 // Mesh all the sub-shapes starting from vertices
159 // ===============================================
161 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
162 while ( smIt->more() )
164 SMESH_subMesh* smToCompute = smIt->next();
166 // do not mesh vertices of a pseudo shape
167 const TopoDS_Shape& shape = smToCompute->GetSubShape();
168 const TopAbs_ShapeEnum shapeType = shape.ShapeType();
169 if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
172 // check for preview dimension limitations
173 if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
175 // clear compute state not to show previous compute errors
176 // if preview invoked less dimension less than previous
177 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
181 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
183 if (_compute_canceled)
185 _sm_current = smToCompute;
186 smToCompute->ComputeStateEngine( computeEvent );
190 // we check all the sub-meshes here and detect if any of them failed to compute
191 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
192 ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
194 else if ( aShapesId )
195 aShapesId->insert( smToCompute->GetId() );
197 //aMesh.GetMeshDS()->Modified();
202 // ================================================================
203 // Apply algos that do NOT require discreteized boundaries
204 // ("all-dimensional") and do NOT support sub-meshes, starting from
205 // the most complex shapes and collect sub-meshes with algos that
206 // DO support sub-meshes
207 // ================================================================
209 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
211 // map to sort sm with same dim algos according to dim of
212 // the shape the algo assigned to (issue 0021217).
213 // Other issues influenced the algo applying order:
214 // 21406, 21556, 21893, 20206
215 multimap< int, SMESH_subMesh* > shDim2sm;
216 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
217 TopoDS_Shape algoShape;
218 int prevShapeDim = -1, aShapeDim;
220 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
221 while ( smIt->more() )
223 SMESH_subMesh* smToCompute = smIt->next();
224 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
227 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
228 aShapeDim = GetShapeDim( aSubShape );
229 if ( aShapeDim < 1 ) break;
231 // check for preview dimension limitations
232 if ( aShapesId && aShapeDim > (int)aDim )
235 SMESH_Algo* algo = GetAlgo( smToCompute, &algoShape );
236 if ( algo && !algo->NeedDiscreteBoundary() )
238 if ( algo->SupportSubmeshes() )
240 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
241 // so that more local algos to go first
242 if ( prevShapeDim != aShapeDim )
244 prevShapeDim = aShapeDim;
245 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
246 if ( shDim2smIt->first == globalAlgoDim )
247 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_back( shDim2smIt->second );
249 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_front( shDim2smIt->second );
252 // add smToCompute to shDim2sm map
253 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
255 aShapeDim = globalAlgoDim; // to compute last
259 aShapeDim = GetShapeDim( algoShape );
260 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
262 TopoDS_Iterator it( algoShape );
263 aShapeDim += GetShapeDim( it.Value() );
266 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
268 else // Compute w/o support of sub-meshes
270 if (_compute_canceled)
272 _sm_current = smToCompute;
273 smToCompute->ComputeStateEngine( computeEvent );
276 aShapesId->insert( smToCompute->GetId() );
280 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
281 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
282 if ( shDim2smIt->first == globalAlgoDim )
283 smWithAlgoSupportingSubmeshes[3].push_back( shDim2smIt->second );
285 smWithAlgoSupportingSubmeshes[0].push_front( shDim2smIt->second );
287 // ======================================================
288 // Apply all-dimensional algorithms supporing sub-meshes
289 // ======================================================
291 std::vector< SMESH_subMesh* > smVec;
292 for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim )
294 // ------------------------------------------------
295 // sort list of sub-meshes according to mesh order
296 // ------------------------------------------------
297 smVec.assign( smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(),
298 smWithAlgoSupportingSubmeshes[ aShapeDim ].end() );
299 aMesh.SortByMeshOrder( smVec );
301 // ------------------------------------------------------------
302 // compute sub-meshes with local uni-dimensional algos under
303 // sub-meshes with all-dimensional algos
304 // ------------------------------------------------------------
305 // start from lower shapes
306 for ( size_t i = 0; i < smVec.size(); ++i )
310 // get a shape the algo is assigned to
311 if ( !GetAlgo( sm, & algoShape ))
312 continue; // strange...
314 // look for more local algos
315 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
316 while ( smIt->more() )
318 SMESH_subMesh* smToCompute = smIt->next();
320 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
321 const int aShapeDim = GetShapeDim( aSubShape );
322 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
323 if ( aShapeDim < 1 ) continue;
325 // check for preview dimension limitations
326 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
329 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
331 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
332 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
334 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true))
336 if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
337 SMESH_Hypothesis::Hypothesis_Status status;
338 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
339 // mesh a lower smToCompute starting from vertices
340 Compute( aMesh, aSubShape, aShapeOnly, /*anUpward=*/true, aDim, aShapesId );
344 // --------------------------------
345 // apply the all-dimensional algos
346 // --------------------------------
347 for ( size_t i = 0; i < smVec.size(); ++i )
350 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
352 const TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
353 // check for preview dimension limitations
354 if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
357 if (_compute_canceled)
360 sm->ComputeStateEngine( computeEvent );
363 aShapesId->insert( sm->GetId() );
366 } // loop on shape dimensions
368 // -----------------------------------------------
369 // mesh the rest sub-shapes starting from vertices
370 // -----------------------------------------------
371 ret = Compute( aMesh, aShape, aShapeOnly, /*anUpward=*/true, aDim, aShapesId );
374 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
377 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
378 MESSAGE("*** compactMesh after compute");
379 myMesh->compactMesh();
381 // fix quadratic mesh by bending iternal links near concave boundary
382 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
383 !aShapesId && // not preview
384 ret ) // everything is OK
386 SMESH_MesherHelper aHelper( aMesh );
387 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
389 aHelper.FixQuadraticElements( sm->GetComputeError() );
395 //=============================================================================
397 * Prepare Compute a mesh
399 //=============================================================================
400 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
401 const TopoDS_Shape & aShape)
403 _compute_canceled = false;
406 //=============================================================================
408 * Cancel Compute a mesh
410 //=============================================================================
411 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
412 const TopoDS_Shape & aShape)
414 _compute_canceled = true;
417 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
421 //=============================================================================
425 //=============================================================================
427 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
428 const TopoDS_Shape & aShape,
429 MapShapeNbElems& aResMap,
431 TSetOfInt* aShapesId)
433 MESSAGE("SMESH_Gen::Evaluate");
437 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
439 const bool includeSelf = true;
440 const bool complexShapeFirst = true;
441 SMESH_subMeshIteratorPtr smIt;
443 if ( anUpward ) { // is called from below code here
444 // -----------------------------------------------
445 // mesh all the sub-shapes starting from vertices
446 // -----------------------------------------------
447 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
448 while ( smIt->more() ) {
449 SMESH_subMesh* smToCompute = smIt->next();
451 // do not mesh vertices of a pseudo shape
452 const TopAbs_ShapeEnum shapeType = smToCompute->GetSubShape().ShapeType();
453 //if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
455 if ( !aMesh.HasShapeToMesh() ) {
456 if( shapeType == TopAbs_VERTEX || shapeType == TopAbs_WIRE ||
457 shapeType == TopAbs_SHELL )
461 smToCompute->Evaluate(aResMap);
463 aShapesId->insert( smToCompute->GetId() );
468 // -----------------------------------------------------------------
469 // apply algos that DO NOT require Discreteized boundaries and DO NOT
470 // support sub-meshes, starting from the most complex shapes
471 // and collect sub-meshes with algos that DO support sub-meshes
472 // -----------------------------------------------------------------
473 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
474 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
475 while ( smIt->more() ) {
476 SMESH_subMesh* smToCompute = smIt->next();
477 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
478 const int aShapeDim = GetShapeDim( aSubShape );
479 if ( aShapeDim < 1 ) break;
481 SMESH_Algo* algo = GetAlgo( smToCompute );
482 if ( algo && !algo->NeedDiscreteBoundary() ) {
483 if ( algo->SupportSubmeshes() ) {
484 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
487 smToCompute->Evaluate(aResMap);
489 aShapesId->insert( smToCompute->GetId() );
494 // ------------------------------------------------------------
495 // sort list of meshes according to mesh order
496 // ------------------------------------------------------------
497 std::vector< SMESH_subMesh* > smVec( smWithAlgoSupportingSubmeshes.begin(),
498 smWithAlgoSupportingSubmeshes.end() );
499 aMesh.SortByMeshOrder( smVec );
501 // ------------------------------------------------------------
502 // compute sub-meshes under shapes with algos that DO NOT require
503 // Discreteized boundaries and DO support sub-meshes
504 // ------------------------------------------------------------
505 // start from lower shapes
506 for ( size_t i = 0; i < smVec.size(); ++i )
510 // get a shape the algo is assigned to
511 TopoDS_Shape algoShape;
512 if ( !GetAlgo( sm, & algoShape ))
513 continue; // strange...
515 // look for more local algos
516 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
517 while ( smIt->more() ) {
518 SMESH_subMesh* smToCompute = smIt->next();
520 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
521 const int aShapeDim = GetShapeDim( aSubShape );
522 if ( aShapeDim < 1 ) continue;
524 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
526 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
527 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
529 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true ))
531 if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
532 SMESH_Hypothesis::Hypothesis_Status status;
533 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
534 // mesh a lower smToCompute starting from vertices
535 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
539 // ----------------------------------------------------------
540 // apply the algos that do not require Discreteized boundaries
541 // ----------------------------------------------------------
542 for ( size_t i = 0; i < smVec.size(); ++i )
545 sm->Evaluate(aResMap);
547 aShapesId->insert( sm->GetId() );
550 // -----------------------------------------------
551 // mesh the rest sub-shapes starting from vertices
552 // -----------------------------------------------
553 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
556 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
561 //=======================================================================
562 //function : checkConformIgnoredAlgos
564 //=======================================================================
566 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
567 SMESH_subMesh* aSubMesh,
568 const SMESH_Algo* aGlobIgnoAlgo,
569 const SMESH_Algo* aLocIgnoAlgo,
571 set<SMESH_subMesh*>& aCheckedMap,
572 list< SMESH_Gen::TAlgoStateError > & theErrors)
575 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
581 const list<const SMESHDS_Hypothesis*>& listHyp =
582 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
583 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
584 for ( ; it != listHyp.end(); it++)
586 const SMESHDS_Hypothesis * aHyp = *it;
587 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
590 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
593 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
595 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
596 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, false );
597 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
598 << aLocIgnoAlgo->GetName() << ">");
602 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
603 int dim = algo->GetDim();
604 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
605 bool isNeededDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->NeedLowerHyps( dim ) : false );
607 if (( dim < aMaxGlobIgnoDim && !isNeededDim ) &&
608 ( isGlobal || !aGlobIgnoAlgo->SupportSubmeshes() ))
610 // algo is hidden by a global algo
611 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
612 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, true );
613 INFOS( ( isGlobal ? "Global" : "Local" )
614 << " <" << algo->GetName() << "> is hidden by global <"
615 << aGlobIgnoAlgo->GetName() << ">");
617 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
619 // local algo is not hidden and hides algos on sub-shapes
620 if (checkConform && !aSubMesh->IsConform( algo ))
623 checkConform = false; // no more check conformity
624 INFOS( "ERROR: Local <" << algo->GetName() <<
625 "> would produce not conform mesh: "
626 "<Not Conform Mesh Allowed> hypotesis is missing");
627 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
628 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
631 // sub-algos will be hidden by a local <algo> if <algo> does not support sub-meshes
632 if ( algo->SupportSubmeshes() )
634 SMESH_subMeshIteratorPtr revItSub =
635 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
636 bool checkConform2 = false;
637 while ( revItSub->more() )
639 SMESH_subMesh* sm = revItSub->next();
640 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
641 algo, checkConform2, aCheckedMap, theErrors);
642 aCheckedMap.insert( sm );
651 //=======================================================================
652 //function : checkMissing
653 //purpose : notify on missing hypothesis
654 // Return false if algo or hipothesis is missing
655 //=======================================================================
657 static bool checkMissing(SMESH_Gen* aGen,
659 SMESH_subMesh* aSubMesh,
660 const int aTopAlgoDim,
662 const bool checkNoAlgo,
663 set<SMESH_subMesh*>& aCheckedMap,
664 list< SMESH_Gen::TAlgoStateError > & theErrors)
666 switch ( aSubMesh->GetSubShape().ShapeType() )
670 case TopAbs_SOLID: break; // check this sub-mesh, it can be meshed
672 return true; // not meshable sub-mesh
674 if ( aCheckedMap.count( aSubMesh ))
677 //MESSAGE("=====checkMissing");
680 SMESH_Algo* algo = 0;
682 switch (aSubMesh->GetAlgoState())
684 case SMESH_subMesh::NO_ALGO: {
687 // should there be any algo?
688 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
689 if (aTopAlgoDim > shapeDim)
691 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
693 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
694 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
699 case SMESH_subMesh::MISSING_HYP: {
700 // notify if an algo missing hyp is attached to aSubMesh
701 algo = aSubMesh->GetAlgo();
703 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
704 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
706 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
707 SMESH_Hypothesis::Hypothesis_Status status;
708 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
709 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
710 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
711 << "<" << algo->GetName() << "> has a bad parameter value");
713 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
714 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
715 << "<" << algo->GetName() << "> assigned to mismatching geometry");
718 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
719 << "<" << algo->GetName() << "> misses some hypothesis");
721 if (IsGlobalHypothesis)
722 globalChecked[ algo->GetDim() ] = true;
723 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
724 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
729 case SMESH_subMesh::HYP_OK:
730 algo = aSubMesh->GetAlgo();
732 if (!algo->NeedDiscreteBoundary())
734 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
735 /*complexShapeFirst=*/false);
736 while ( itsub->more() )
737 aCheckedMap.insert( itsub->next() );
743 // do not check under algo that hides sub-algos or
744 // re-start checking NO_ALGO state
746 bool isTopLocalAlgo =
747 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
748 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
750 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
751 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
752 /*complexShapeFirst=*/true);
753 while ( itsub->more() )
755 // sub-meshes should not be checked further more
756 SMESH_subMesh* sm = itsub->next();
760 //check algo on sub-meshes
761 int aTopAlgoDim2 = algo->GetDim();
762 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
763 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
766 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
767 checkNoAlgo2 = false;
770 aCheckedMap.insert( sm );
776 //=======================================================================
777 //function : CheckAlgoState
778 //purpose : notify on bad state of attached algos, return false
779 // if Compute() would fail because of some algo bad state
780 //=======================================================================
782 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
784 list< TAlgoStateError > errors;
785 return GetAlgoState( aMesh, aShape, errors );
788 //=======================================================================
789 //function : GetAlgoState
790 //purpose : notify on bad state of attached algos, return false
791 // if Compute() would fail because of some algo bad state
792 // theErrors list contains problems description
793 //=======================================================================
795 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
796 const TopoDS_Shape& theShape,
797 list< TAlgoStateError > & theErrors)
799 //MESSAGE("SMESH_Gen::CheckAlgoState");
802 bool hasAlgo = false;
804 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
805 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
806 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
812 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
814 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
815 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
816 for ( ; it != listHyp.end(); it++)
818 const SMESHDS_Hypothesis * aHyp = *it;
819 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
822 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
825 int dim = algo->GetDim();
826 aGlobAlgoArr[ dim ] = algo;
831 // --------------------------------------------------------
832 // info on algos that will be ignored because of ones that
833 // don't NeedDiscreteBoundary() attached to super-shapes,
834 // check that a conform mesh will be produced
835 // --------------------------------------------------------
838 // find a global algo possibly hiding sub-algos
840 const SMESH_Algo* aGlobIgnoAlgo = 0;
841 for (dim = 3; dim > 0; dim--)
843 if (aGlobAlgoArr[ dim ] &&
844 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary() /*&&
845 !aGlobAlgoArr[ dim ]->SupportSubmeshes()*/ )
847 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
852 set<SMESH_subMesh*> aCheckedSubs;
853 bool checkConform = ( !theMesh.IsNotConformAllowed() );
855 // loop on theShape and its sub-shapes
856 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
857 /*complexShapeFirst=*/true);
858 while ( revItSub->more() )
860 SMESH_subMesh* smToCheck = revItSub->next();
861 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
864 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
865 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
866 0, checkConform, aCheckedSubs, theErrors))
869 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
873 // ----------------------------------------------------------------
874 // info on missing hypothesis and find out if all needed algos are
876 // ----------------------------------------------------------------
878 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
880 // find max dim of global algo
882 for (dim = 3; dim > 0; dim--)
884 if (aGlobAlgoArr[ dim ])
890 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
891 bool globalChecked[] = { false, false, false, false };
893 // loop on theShape and its sub-shapes
894 aCheckedSubs.clear();
895 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
896 while ( revItSub->more() )
898 SMESH_subMesh* smToCheck = revItSub->next();
899 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
902 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
903 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
906 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
913 theErrors.push_back( TAlgoStateError() );
914 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
920 //=======================================================================
921 //function : IsGlobalHypothesis
922 //purpose : check if theAlgo is attached to the main shape
923 //=======================================================================
925 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
927 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
928 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
931 //================================================================================
933 * \brief Return paths to xml files of plugins
935 //================================================================================
937 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
939 // Get paths to xml files of plugins
940 vector< string > xmlPaths;
942 if ( const char* meshersList = getenv("SMESH_MeshersList") )
944 string meshers = meshersList, plugin;
945 string::size_type from = 0, pos;
946 while ( from < meshers.size() )
948 // cut off plugin name
949 pos = meshers.find( ':', from );
950 if ( pos != string::npos )
951 plugin = meshers.substr( from, pos-from );
953 plugin = meshers.substr( from ), pos = meshers.size();
956 // get PLUGIN_ROOT_DIR path
957 string rootDirVar, pluginSubDir = plugin;
958 if ( plugin == "StdMeshers" )
959 rootDirVar = "SMESH", pluginSubDir = "smesh";
961 for ( pos = 0; pos < plugin.size(); ++pos )
962 rootDirVar += toupper( plugin[pos] );
963 rootDirVar += "_ROOT_DIR";
965 const char* rootDir = getenv( rootDirVar.c_str() );
966 if ( !rootDir || strlen(rootDir) == 0 )
968 rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
969 rootDir = getenv( rootDirVar.c_str() );
970 if ( !rootDir || strlen(rootDir) == 0 ) continue;
973 // get a separator from rootDir
974 for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
975 if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
981 if (sep.empty() ) sep = "\\";
983 if (sep.empty() ) sep = "/";
986 // get a path to resource file
987 string xmlPath = rootDir;
988 if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
990 xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
991 for ( pos = 0; pos < pluginSubDir.size(); ++pos )
992 xmlPath += tolower( pluginSubDir[pos] );
993 xmlPath += sep + plugin + ".xml";
996 fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
998 fileOK = (access(xmlPath.c_str(), F_OK) == 0);
1001 xmlPaths.push_back( xmlPath );
1008 //=============================================================================
1010 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
1012 //=============================================================================
1014 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
1015 const TopoDS_Shape & aShape,
1016 TopoDS_Shape* assignedTo)
1018 return GetAlgo( aMesh.GetSubMesh( aShape ), assignedTo );
1021 //=============================================================================
1023 * Finds algo to mesh a sub-mesh. Optionally returns a shape the found algo is bound to
1025 //=============================================================================
1027 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_subMesh * aSubMesh,
1028 TopoDS_Shape* assignedTo)
1030 if ( !aSubMesh ) return 0;
1032 const TopoDS_Shape & aShape = aSubMesh->GetSubShape();
1033 SMESH_Mesh& aMesh = *aSubMesh->GetFather();
1035 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
1036 filter.And( filter.IsApplicableTo( aShape ));
1038 typedef SMESH_Algo::Features AlgoData;
1040 TopoDS_Shape assignedToShape;
1042 (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape );
1045 aShape.ShapeType() == TopAbs_FACE &&
1046 !aShape.IsSame( assignedToShape ) &&
1047 SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
1049 // Issue 0021559. If there is another 2D algo with different types of output
1050 // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
1051 // have different types of input elements, we choose a most appropriate 2D algo.
1053 // try to find a concurrent 2D algo
1054 filter.AndNot( filter.Is( algo ));
1055 TopoDS_Shape assignedToShape2;
1057 (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape2 );
1058 if ( algo2 && // algo found
1059 !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) && // algo is local
1060 ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
1061 SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
1062 aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ), // no forced order
1063 aMesh.GetSubMesh( assignedToShape )))
1065 // get algos on the adjacent SOLIDs
1066 filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
1067 vector< SMESH_Algo* > algos3D;
1068 PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
1070 while ( const TopoDS_Shape* solid = solidIt->next() )
1071 if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
1073 algos3D.push_back( algo3D );
1074 filter.AndNot( filter.HasName( algo3D->GetName() ));
1076 // check compatibility of algos
1077 if ( algos3D.size() > 1 )
1079 const AlgoData& algoData = algo->SMESH_Algo::GetFeatures();
1080 const AlgoData& algoData2 = algo2->SMESH_Algo::GetFeatures();
1081 const AlgoData& algoData3d0 = algos3D[0]->SMESH_Algo::GetFeatures();
1082 const AlgoData& algoData3d1 = algos3D[1]->SMESH_Algo::GetFeatures();
1083 if (( algoData2.IsCompatible( algoData3d0 ) &&
1084 algoData2.IsCompatible( algoData3d1 ))
1086 !(algoData.IsCompatible( algoData3d0 ) &&
1087 algoData.IsCompatible( algoData3d1 )))
1093 if ( assignedTo && algo )
1094 * assignedTo = assignedToShape;
1099 //=============================================================================
1101 * Returns StudyContextStruct for a study
1103 //=============================================================================
1105 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
1107 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
1109 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
1111 _mapStudyContext[studyId] = new StudyContextStruct;
1112 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
1114 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
1115 return myStudyContext;
1118 //================================================================================
1120 * \brief Return shape dimension by TopAbs_ShapeEnum
1122 //================================================================================
1124 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1126 static vector<int> dim;
1129 dim.resize( TopAbs_SHAPE, -1 );
1130 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
1131 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1132 dim[ TopAbs_SOLID ] = MeshDim_3D;
1133 dim[ TopAbs_SHELL ] = MeshDim_2D;
1134 dim[ TopAbs_FACE ] = MeshDim_2D;
1135 dim[ TopAbs_WIRE ] = MeshDim_1D;
1136 dim[ TopAbs_EDGE ] = MeshDim_1D;
1137 dim[ TopAbs_VERTEX ] = MeshDim_0D;
1139 return dim[ aShapeType ];
1142 //=============================================================================
1144 * Genarate a new id unique withing this Gen
1146 //=============================================================================
1148 int SMESH_Gen::GetANewId()