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>
46 #include <LDOMParser.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 #ifdef WITH_SMESH_CANCEL_COMPUTE
75 _compute_canceled = false;
78 //vtkDebugLeaks::SetExitError(0);
81 //=============================================================================
85 //=============================================================================
87 SMESH_Gen::~SMESH_Gen()
89 MESSAGE("SMESH_Gen::~SMESH_Gen");
90 std::map < int, StudyContextStruct * >::iterator i_sc = _mapStudyContext.begin();
91 for ( ; i_sc != _mapStudyContext.end(); ++i_sc )
93 delete i_sc->second->myDocument;
98 //=============================================================================
100 * Creates a mesh in a study.
101 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
103 //=============================================================================
105 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
106 throw(SALOME_Exception)
108 Unexpect aCatch(SalomeException);
109 MESSAGE("SMESH_Gen::CreateMesh");
111 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
112 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
114 // create a new SMESH_mesh object
115 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
119 aStudyContext->myDocument);
120 aStudyContext->mapMesh[_localId-1] = aMesh;
125 //=============================================================================
129 //=============================================================================
131 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
132 const TopoDS_Shape & aShape,
134 const ::MeshDimension aDim,
135 TSetOfInt* aShapesId)
137 MESSAGE("SMESH_Gen::Compute");
142 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
144 const bool includeSelf = true;
145 const bool complexShapeFirst = true;
146 const int globalAlgoDim = 100;
148 SMESH_subMeshIteratorPtr smIt;
150 if ( anUpward ) // is called from below code here
152 // -----------------------------------------------
153 // mesh all the sub-shapes starting from vertices
154 // -----------------------------------------------
155 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
156 while ( smIt->more() )
158 SMESH_subMesh* smToCompute = smIt->next();
160 // do not mesh vertices of a pseudo shape
161 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
162 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
165 // check for preview dimension limitations
166 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
168 // clear compute state not to show previous compute errors
169 // if preview invoked less dimension less than previous
170 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
174 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
176 #ifdef WITH_SMESH_CANCEL_COMPUTE
177 if (_compute_canceled)
179 _sm_current = smToCompute;
181 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
182 #ifdef WITH_SMESH_CANCEL_COMPUTE
187 // we check all the submeshes here and detect if any of them failed to compute
188 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
190 else if ( aShapesId )
191 aShapesId->insert( smToCompute->GetId() );
193 //aMesh.GetMeshDS()->Modified();
198 // -----------------------------------------------------------------
199 // apply algos that DO NOT require Discreteized boundaries and DO NOT
200 // support submeshes, starting from the most complex shapes
201 // and collect submeshes with algos that DO support submeshes
202 // -----------------------------------------------------------------
203 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
205 // map to sort sm with same dim algos according to dim of
206 // the shape the algo assigned to (issue 0021217)
207 multimap< int, SMESH_subMesh* > shDim2sm;
208 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
209 TopoDS_Shape algoShape;
210 int prevShapeDim = -1;
212 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
213 while ( smIt->more() )
215 SMESH_subMesh* smToCompute = smIt->next();
216 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
219 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
220 int aShapeDim = GetShapeDim( aSubShape );
221 if ( aShapeDim < 1 ) break;
223 // check for preview dimension limitations
224 if ( aShapesId && aShapeDim > (int)aDim )
227 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
228 if ( algo && !algo->NeedDiscreteBoundary() )
230 if ( algo->SupportSubmeshes() )
232 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
233 // so that more local algos to go first
234 if ( prevShapeDim != aShapeDim )
236 prevShapeDim = aShapeDim;
237 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
238 if ( shDim2smIt->first == globalAlgoDim )
239 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
241 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
244 // add smToCompute to shDim2sm map
245 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
247 aShapeDim = globalAlgoDim; // to compute last
251 aShapeDim = GetShapeDim( algoShape );
252 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
254 TopoDS_Iterator it( algoShape );
255 aShapeDim += GetShapeDim( it.Value() );
258 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
262 #ifdef WITH_SMESH_CANCEL_COMPUTE
263 if (_compute_canceled)
265 _sm_current = smToCompute;
267 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
268 #ifdef WITH_SMESH_CANCEL_COMPUTE
272 aShapesId->insert( smToCompute->GetId() );
276 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
277 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
278 if ( shDim2smIt->first == globalAlgoDim )
279 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
281 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
283 // ------------------------------------------------------------
284 // sort list of submeshes according to mesh order
285 // ------------------------------------------------------------
286 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
288 // ------------------------------------------------------------
289 // compute submeshes under shapes with algos that DO NOT require
290 // Discreteized boundaries and DO support submeshes
291 // ------------------------------------------------------------
292 list< SMESH_subMesh* >::iterator subIt, subEnd;
293 subIt = smWithAlgoSupportingSubmeshes.begin();
294 subEnd = smWithAlgoSupportingSubmeshes.end();
295 // start from lower shapes
296 for ( ; subIt != subEnd; ++subIt )
300 // get a shape the algo is assigned to
301 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
302 continue; // strange...
304 // look for more local algos
305 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
306 while ( smIt->more() )
308 SMESH_subMesh* smToCompute = smIt->next();
310 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
311 const int aShapeDim = GetShapeDim( aSubShape );
312 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
313 if ( aShapeDim < 1 ) continue;
315 // check for preview dimension limitations
316 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
319 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
321 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
322 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
324 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
325 if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
326 SMESH_Hypothesis::Hypothesis_Status status;
327 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
328 // mesh a lower smToCompute starting from vertices
329 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
333 // ----------------------------------------------------------
334 // apply the algos that do not require Discreteized boundaries
335 // ----------------------------------------------------------
336 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
339 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
341 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
342 // check for preview dimension limitations
343 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
346 #ifdef WITH_SMESH_CANCEL_COMPUTE
347 if (_compute_canceled)
351 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
352 #ifdef WITH_SMESH_CANCEL_COMPUTE
356 aShapesId->insert( sm->GetId() );
359 // -----------------------------------------------
360 // mesh the rest sub-shapes starting from vertices
361 // -----------------------------------------------
362 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
365 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
368 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
369 MESSAGE("*** compactMesh after compute");
370 myMesh->compactMesh();
372 // fix quadratic mesh by bending iternal links near concave boundary
373 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
374 !aShapesId && // not preview
375 ret ) // everything is OK
377 SMESH_MesherHelper aHelper( aMesh );
378 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
380 aHelper.FixQuadraticElements( sm->GetComputeError() );
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 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
590 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, false );
591 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
592 << aLocIgnoAlgo->GetName() << ">");
596 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
597 int dim = algo->GetDim();
598 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
599 bool isNeededDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->NeedLowerHyps( dim ) : false );
601 if (( dim < aMaxGlobIgnoDim && !isNeededDim ) &&
602 ( isGlobal || !aGlobIgnoAlgo->SupportSubmeshes() ))
604 // algo is hidden by a global algo
605 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
606 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, true );
607 INFOS( ( isGlobal ? "Global" : "Local" )
608 << " <" << algo->GetName() << "> is hidden by global <"
609 << aGlobIgnoAlgo->GetName() << ">");
611 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
613 // local algo is not hidden and hides algos on sub-shapes
614 if (checkConform && !aSubMesh->IsConform( algo ))
617 checkConform = false; // no more check conformity
618 INFOS( "ERROR: Local <" << algo->GetName() <<
619 "> would produce not conform mesh: "
620 "<Not Conform Mesh Allowed> hypotesis is missing");
621 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
622 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
625 // sub-algos will be hidden by a local <algo>
626 SMESH_subMeshIteratorPtr revItSub =
627 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
628 bool checkConform2 = false;
629 while ( revItSub->more() )
631 SMESH_subMesh* sm = revItSub->next();
632 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
633 algo, checkConform2, aCheckedMap, theErrors);
634 aCheckedMap.insert( sm );
643 //=======================================================================
644 //function : checkMissing
645 //purpose : notify on missing hypothesis
646 // Return false if algo or hipothesis is missing
647 //=======================================================================
649 static bool checkMissing(SMESH_Gen* aGen,
651 SMESH_subMesh* aSubMesh,
652 const int aTopAlgoDim,
654 const bool checkNoAlgo,
655 set<SMESH_subMesh*>& aCheckedMap,
656 list< SMESH_Gen::TAlgoStateError > & theErrors)
658 switch ( aSubMesh->GetSubShape().ShapeType() )
662 case TopAbs_SOLID: break; // check this submesh, it can be meshed
664 return true; // not meshable submesh
666 if ( aCheckedMap.count( aSubMesh ))
669 //MESSAGE("=====checkMissing");
672 SMESH_Algo* algo = 0;
674 switch (aSubMesh->GetAlgoState())
676 case SMESH_subMesh::NO_ALGO: {
679 // should there be any algo?
680 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
681 if (aTopAlgoDim > shapeDim)
683 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
685 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
686 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
691 case SMESH_subMesh::MISSING_HYP: {
692 // notify if an algo missing hyp is attached to aSubMesh
693 algo = aSubMesh->GetAlgo();
695 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
696 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
698 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
699 SMESH_Hypothesis::Hypothesis_Status status;
700 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
701 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
702 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
703 << "<" << algo->GetName() << "> has a bad parameter value");
705 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
706 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
707 << "<" << algo->GetName() << "> assigned to mismatching geometry");
710 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
711 << "<" << algo->GetName() << "> misses some hypothesis");
713 if (IsGlobalHypothesis)
714 globalChecked[ algo->GetDim() ] = true;
715 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
716 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
721 case SMESH_subMesh::HYP_OK:
722 algo = aSubMesh->GetAlgo();
724 if (!algo->NeedDiscreteBoundary())
726 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
727 /*complexShapeFirst=*/false);
728 while ( itsub->more() )
729 aCheckedMap.insert( itsub->next() );
735 // do not check under algo that hides sub-algos or
736 // re-start checking NO_ALGO state
738 bool isTopLocalAlgo =
739 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
740 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
742 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
743 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
744 /*complexShapeFirst=*/true);
745 while ( itsub->more() )
747 // sub-meshes should not be checked further more
748 SMESH_subMesh* sm = itsub->next();
752 //check algo on sub-meshes
753 int aTopAlgoDim2 = algo->GetDim();
754 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
755 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
758 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
759 checkNoAlgo2 = false;
762 aCheckedMap.insert( sm );
768 //=======================================================================
769 //function : CheckAlgoState
770 //purpose : notify on bad state of attached algos, return false
771 // if Compute() would fail because of some algo bad state
772 //=======================================================================
774 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
776 list< TAlgoStateError > errors;
777 return GetAlgoState( aMesh, aShape, errors );
780 //=======================================================================
781 //function : GetAlgoState
782 //purpose : notify on bad state of attached algos, return false
783 // if Compute() would fail because of some algo bad state
784 // theErrors list contains problems description
785 //=======================================================================
787 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
788 const TopoDS_Shape& theShape,
789 list< TAlgoStateError > & theErrors)
791 //MESSAGE("SMESH_Gen::CheckAlgoState");
794 bool hasAlgo = false;
796 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
797 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
798 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
804 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
806 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
807 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
808 for ( ; it != listHyp.end(); it++)
810 const SMESHDS_Hypothesis * aHyp = *it;
811 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
814 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
817 int dim = algo->GetDim();
818 aGlobAlgoArr[ dim ] = algo;
823 // --------------------------------------------------------
824 // info on algos that will be ignored because of ones that
825 // don't NeedDiscreteBoundary() attached to super-shapes,
826 // check that a conform mesh will be produced
827 // --------------------------------------------------------
830 // find a global algo possibly hiding sub-algos
832 const SMESH_Algo* aGlobIgnoAlgo = 0;
833 for (dim = 3; dim > 0; dim--)
835 if (aGlobAlgoArr[ dim ] &&
836 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary() /*&&
837 !aGlobAlgoArr[ dim ]->SupportSubmeshes()*/ )
839 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
844 set<SMESH_subMesh*> aCheckedSubs;
845 bool checkConform = ( !theMesh.IsNotConformAllowed() );
847 // loop on theShape and its sub-shapes
848 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
849 /*complexShapeFirst=*/true);
850 while ( revItSub->more() )
852 SMESH_subMesh* smToCheck = revItSub->next();
853 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
856 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
857 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
858 0, checkConform, aCheckedSubs, theErrors))
861 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
865 // ----------------------------------------------------------------
866 // info on missing hypothesis and find out if all needed algos are
868 // ----------------------------------------------------------------
870 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
872 // find max dim of global algo
874 for (dim = 3; dim > 0; dim--)
876 if (aGlobAlgoArr[ dim ])
882 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
883 bool globalChecked[] = { false, false, false, false };
885 // loop on theShape and its sub-shapes
886 aCheckedSubs.clear();
887 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
888 while ( revItSub->more() )
890 SMESH_subMesh* smToCheck = revItSub->next();
891 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
894 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
895 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
898 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
905 INFOS( "None algorithm attached" );
906 theErrors.push_back( TAlgoStateError() );
907 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
913 //=======================================================================
914 //function : IsGlobalHypothesis
915 //purpose : check if theAlgo is attached to the main shape
916 //=======================================================================
918 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
920 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
921 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
924 //================================================================================
926 * \brief Return paths to xml files of plugins
928 //================================================================================
930 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
932 // Get paths to xml files of plugins
933 vector< string > xmlPaths;
935 if ( const char* meshersList = getenv("SMESH_MeshersList") )
937 string meshers = meshersList, plugin;
938 string::size_type from = 0, pos;
939 while ( from < meshers.size() )
941 // cut off plugin name
942 pos = meshers.find( ':', from );
943 if ( pos != string::npos )
944 plugin = meshers.substr( from, pos-from );
946 plugin = meshers.substr( from ), pos = meshers.size();
949 // get PLUGIN_ROOT_DIR path
950 string rootDirVar, pluginSubDir = plugin;
951 if ( plugin == "StdMeshers" )
952 rootDirVar = "SMESH", pluginSubDir = "smesh";
954 for ( pos = 0; pos < plugin.size(); ++pos )
955 rootDirVar += toupper( plugin[pos] );
956 rootDirVar += "_ROOT_DIR";
958 const char* rootDir = getenv( rootDirVar.c_str() );
959 if ( !rootDir || strlen(rootDir) == 0 )
961 rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
962 rootDir = getenv( rootDirVar.c_str() );
963 if ( !rootDir || strlen(rootDir) == 0 ) continue;
966 // get a separator from rootDir
967 for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
968 if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
974 if (sep.empty() ) sep = "\\";
976 if (sep.empty() ) sep = "/";
979 // get a path to resource file
980 string xmlPath = rootDir;
981 if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
983 xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
984 for ( pos = 0; pos < pluginSubDir.size(); ++pos )
985 xmlPath += tolower( pluginSubDir[pos] );
986 xmlPath += sep + plugin + ".xml";
989 fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
991 fileOK = (access(xmlPath.c_str(), F_OK) == 0);
994 xmlPaths.push_back( xmlPath );
1001 //=======================================================================
1002 namespace // Access to type of input and output of an algorithm
1003 //=======================================================================
1008 set<SMDSAbs_GeometryType> _inElemTypes; // acceptable types of input mesh element
1009 set<SMDSAbs_GeometryType> _outElemTypes; // produced types of mesh elements
1011 bool IsCompatible( const AlgoData& algo2 ) const
1013 if ( _dim > algo2._dim ) return algo2.IsCompatible( *this );
1014 // algo2 is of highter dimension
1015 if ( _outElemTypes.empty() || algo2._inElemTypes.empty() )
1017 bool compatible = true;
1018 set<SMDSAbs_GeometryType>::const_iterator myOutType = _outElemTypes.begin();
1019 for ( ; myOutType != _outElemTypes.end() && compatible; ++myOutType )
1020 compatible = algo2._inElemTypes.count( *myOutType );
1025 //================================================================================
1027 * \brief Return AlgoData of the algorithm
1029 //================================================================================
1031 const AlgoData& getAlgoData( const SMESH_Algo* algo )
1033 static map< string, AlgoData > theDataByName;
1034 if ( theDataByName.empty() )
1036 // Read Plugin.xml files
1037 vector< string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
1038 LDOMParser xmlParser;
1039 for ( size_t iXML = 0; iXML < xmlPaths.size(); ++iXML )
1041 bool error = xmlParser.parse( xmlPaths[iXML].c_str() );
1044 TCollection_AsciiString data;
1045 INFOS( xmlParser.GetError(data) );
1048 // <algorithm type="Regular_1D"
1051 // output="QUAD,TRIA">
1053 LDOM_Document xmlDoc = xmlParser.getDocument();
1054 LDOM_NodeList algoNodeList = xmlDoc.getElementsByTagName( "algorithm" );
1055 for ( int i = 0; i < algoNodeList.getLength(); ++i )
1057 LDOM_Node algoNode = algoNodeList.item( i );
1058 LDOM_Element& algoElem = (LDOM_Element&) algoNode;
1059 TCollection_AsciiString algoType = algoElem.getAttribute("type");
1060 TCollection_AsciiString input = algoElem.getAttribute("input");
1061 TCollection_AsciiString output = algoElem.getAttribute("output");
1062 TCollection_AsciiString dim = algoElem.getAttribute("dim");
1063 if ( algoType.IsEmpty() ) continue;
1064 AlgoData & data = theDataByName[ algoType.ToCString() ];
1065 data._dim = dim.IntegerValue();
1066 for ( int isInput = 0; isInput < 2; ++isInput )
1068 TCollection_AsciiString& typeStr = isInput ? input : output;
1069 set<SMDSAbs_GeometryType>& typeSet = isInput ? data._inElemTypes : data._outElemTypes;
1071 while ( beg <= typeStr.Length() )
1073 while ( beg < typeStr.Length() && !isalpha( typeStr.Value( beg ) ))
1076 while ( end < typeStr.Length() && isalpha( typeStr.Value( end + 1 ) ))
1080 TCollection_AsciiString typeName = typeStr.SubString( beg, end );
1081 if ( typeName == "EDGE" ) typeSet.insert( SMDSGeom_EDGE );
1082 else if ( typeName == "TRIA" ) typeSet.insert( SMDSGeom_TRIANGLE );
1083 else if ( typeName == "QUAD" ) typeSet.insert( SMDSGeom_QUADRANGLE );
1091 return theDataByName[ algo->GetName() ];
1095 //=============================================================================
1097 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
1099 //=============================================================================
1101 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
1102 const TopoDS_Shape & aShape,
1103 TopoDS_Shape* assignedTo)
1105 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
1106 filter.And( filter.IsApplicableTo( aShape ));
1108 TopoDS_Shape assignedToShape;
1110 (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape );
1113 aShape.ShapeType() == TopAbs_FACE &&
1114 !aShape.IsSame( assignedToShape ) &&
1115 SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
1117 // Issue 0021559. If there is another 2D algo with different types of output
1118 // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
1119 // have different types of input elements, we choose a most appropriate 2D algo.
1121 // try to find a concurrent 2D algo
1122 filter.AndNot( filter.Is( algo ));
1123 TopoDS_Shape assignedToShape2;
1125 (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape2 );
1126 if ( algo2 && // algo found
1127 !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) && // algo is local
1128 ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
1129 SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
1130 aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ), // no forced order
1131 aMesh.GetSubMesh( assignedToShape )))
1133 // get algos on the adjacent SOLIDs
1134 filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
1135 vector< SMESH_Algo* > algos3D;
1136 PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
1138 while ( const TopoDS_Shape* solid = solidIt->next() )
1139 if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
1141 algos3D.push_back( algo3D );
1142 filter.AndNot( filter.HasName( algo3D->GetName() ));
1144 // check compatibility of algos
1145 if ( algos3D.size() > 1 )
1147 const AlgoData& algoData = getAlgoData( algo );
1148 const AlgoData& algoData2 = getAlgoData( algo2 );
1149 const AlgoData& algoData3d0 = getAlgoData( algos3D[0] );
1150 const AlgoData& algoData3d1 = getAlgoData( algos3D[1] );
1151 if (( algoData2.IsCompatible( algoData3d0 ) &&
1152 algoData2.IsCompatible( algoData3d1 ))
1154 !(algoData.IsCompatible( algoData3d0 ) &&
1155 algoData.IsCompatible( algoData3d1 )))
1161 if ( assignedTo && algo )
1162 * assignedTo = assignedToShape;
1167 //=============================================================================
1169 * Returns StudyContextStruct for a study
1171 //=============================================================================
1173 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
1175 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
1177 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
1179 _mapStudyContext[studyId] = new StudyContextStruct;
1180 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
1182 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
1183 return myStudyContext;
1186 //================================================================================
1188 * \brief Return shape dimension by TopAbs_ShapeEnum
1190 //================================================================================
1192 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1194 static vector<int> dim;
1197 dim.resize( TopAbs_SHAPE, -1 );
1198 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
1199 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1200 dim[ TopAbs_SOLID ] = MeshDim_3D;
1201 dim[ TopAbs_SHELL ] = MeshDim_2D;
1202 dim[ TopAbs_FACE ] = MeshDim_2D;
1203 dim[ TopAbs_WIRE ] = MeshDim_1D;
1204 dim[ TopAbs_EDGE ] = MeshDim_1D;
1205 dim[ TopAbs_VERTEX ] = MeshDim_0D;
1207 return dim[ aShapeType ];
1210 //=============================================================================
1212 * Genarate a new id unique withing this Gen
1214 //=============================================================================
1216 int SMESH_Gen::GetANewId()