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>
52 //=============================================================================
56 //=============================================================================
58 SMESH_Gen::SMESH_Gen()
60 MESSAGE("SMESH_Gen::SMESH_Gen");
63 _segmentation = _nbSegments = 10;
64 SMDS_Mesh::_meshList.clear();
65 MESSAGE(SMDS_Mesh::_meshList.size());
66 _counters = new counters(100);
67 #ifdef WITH_SMESH_CANCEL_COMPUTE
68 _compute_canceled = false;
73 //=============================================================================
77 //=============================================================================
79 SMESH_Gen::~SMESH_Gen()
81 MESSAGE("SMESH_Gen::~SMESH_Gen");
84 //=============================================================================
86 * Creates a mesh in a study.
87 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
89 //=============================================================================
91 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
92 throw(SALOME_Exception)
94 Unexpect aCatch(SalomeException);
95 MESSAGE("SMESH_Gen::CreateMesh");
97 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
98 StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
100 // create a new SMESH_mesh object
101 SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
105 aStudyContext->myDocument);
106 aStudyContext->mapMesh[_localId-1] = aMesh;
111 //=============================================================================
115 //=============================================================================
117 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
118 const TopoDS_Shape & aShape,
120 const ::MeshDimension aDim,
121 TSetOfInt* aShapesId)
123 MESSAGE("SMESH_Gen::Compute");
128 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
130 const bool includeSelf = true;
131 const bool complexShapeFirst = true;
132 const int globalAlgoDim = 100;
134 SMESH_subMeshIteratorPtr smIt;
136 if ( anUpward ) // is called from below code here
138 // -----------------------------------------------
139 // mesh all the sub-shapes starting from vertices
140 // -----------------------------------------------
141 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
142 while ( smIt->more() )
144 SMESH_subMesh* smToCompute = smIt->next();
146 // do not mesh vertices of a pseudo shape
147 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
148 if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
151 // check for preview dimension limitations
152 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
154 // clear compute state to not show previous compute errors
155 // if preview invoked less dimension less than previous
156 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
160 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
162 #ifdef WITH_SMESH_CANCEL_COMPUTE
163 if (_compute_canceled)
165 _sm_current = smToCompute;
167 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
168 #ifdef WITH_SMESH_CANCEL_COMPUTE
173 // we check all the submeshes here and detect if any of them failed to compute
174 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
176 else if ( aShapesId )
177 aShapesId->insert( smToCompute->GetId() );
179 //aMesh.GetMeshDS()->Modified();
184 // -----------------------------------------------------------------
185 // apply algos that DO NOT require Discreteized boundaries and DO NOT
186 // support submeshes, starting from the most complex shapes
187 // and collect submeshes with algos that DO support submeshes
188 // -----------------------------------------------------------------
189 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
191 // map to sort sm with same dim algos according to dim of
192 // the shape the algo assigned to (issue 0021217)
193 multimap< int, SMESH_subMesh* > shDim2sm;
194 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
195 TopoDS_Shape algoShape;
196 int prevShapeDim = -1;
198 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
199 while ( smIt->more() )
201 SMESH_subMesh* smToCompute = smIt->next();
202 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
205 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
206 int aShapeDim = GetShapeDim( aSubShape );
207 if ( aShapeDim < 1 ) break;
209 // check for preview dimension limitations
210 if ( aShapesId && aShapeDim > (int)aDim )
213 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape, &algoShape );
214 if ( algo && !algo->NeedDiscreteBoundary() )
216 if ( algo->SupportSubmeshes() )
218 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
219 // so that more local algos to go first
220 if ( prevShapeDim != aShapeDim )
222 prevShapeDim = aShapeDim;
223 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
224 if ( shDim2smIt->first == globalAlgoDim )
225 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
227 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
230 // add smToCompute to shDim2sm map
231 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
233 aShapeDim = globalAlgoDim; // to compute last
237 aShapeDim = GetShapeDim( algoShape );
238 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
240 TopoDS_Iterator it( algoShape );
241 aShapeDim += GetShapeDim( it.Value() );
244 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
248 #ifdef WITH_SMESH_CANCEL_COMPUTE
249 if (_compute_canceled)
251 _sm_current = smToCompute;
253 smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
254 #ifdef WITH_SMESH_CANCEL_COMPUTE
258 aShapesId->insert( smToCompute->GetId() );
262 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
263 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
264 if ( shDim2smIt->first == globalAlgoDim )
265 smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
267 smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
269 // ------------------------------------------------------------
270 // sort list of submeshes according to mesh order
271 // ------------------------------------------------------------
272 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
274 // ------------------------------------------------------------
275 // compute submeshes under shapes with algos that DO NOT require
276 // Discreteized boundaries and DO support submeshes
277 // ------------------------------------------------------------
278 list< SMESH_subMesh* >::iterator subIt, subEnd;
279 subIt = smWithAlgoSupportingSubmeshes.begin();
280 subEnd = smWithAlgoSupportingSubmeshes.end();
281 // start from lower shapes
282 for ( ; subIt != subEnd; ++subIt )
286 // get a shape the algo is assigned to
287 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
288 continue; // strange...
290 // look for more local algos
291 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
292 while ( smIt->more() )
294 SMESH_subMesh* smToCompute = smIt->next();
296 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
297 const int aShapeDim = GetShapeDim( aSubShape );
298 //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
299 if ( aShapeDim < 1 ) continue;
301 // check for preview dimension limitations
302 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
305 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
307 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
308 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
310 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
311 SMESH_Hypothesis::Hypothesis_Status status;
312 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
313 // mesh a lower smToCompute starting from vertices
314 Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
318 // ----------------------------------------------------------
319 // apply the algos that do not require Discreteized boundaries
320 // ----------------------------------------------------------
321 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
324 if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
326 const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
327 // check for preview dimension limitations
328 if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
331 #ifdef WITH_SMESH_CANCEL_COMPUTE
332 if (_compute_canceled)
336 sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
337 #ifdef WITH_SMESH_CANCEL_COMPUTE
341 aShapesId->insert( sm->GetId() );
344 // -----------------------------------------------
345 // mesh the rest sub-shapes starting from vertices
346 // -----------------------------------------------
347 ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
350 MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
353 SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
354 myMesh->adjustStructure();
355 MESSAGE("*** compactMesh after compute");
356 myMesh->compactMesh();
357 //myMesh->adjustStructure();
358 list<int> listind = myMesh->SubMeshIndices();
359 list<int>::iterator it = listind.begin();
361 for(; it != listind.end(); ++it)
363 ::SMESHDS_SubMesh *subMesh = myMesh->MeshElements(*it);
364 total += subMesh->getSize();
366 MESSAGE("total elements and nodes in submesh sets:" << total);
367 MESSAGE("Number of node objects " << SMDS_MeshNode::nbNodes);
368 MESSAGE("Number of cell objects " << SMDS_MeshCell::nbCells);
369 //myMesh->dumpGrid();
370 //aMesh.GetMeshDS()->Modified();
372 // fix quadratic mesh by bending iternal links near concave boundary
373 if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
374 !aShapesId ) // not preview
376 SMESH_MesherHelper aHelper( aMesh );
377 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
379 aHelper.FixQuadraticElements( sm->GetComputeError() );
386 #ifdef WITH_SMESH_CANCEL_COMPUTE
387 //=============================================================================
389 * Prepare Compute a mesh
391 //=============================================================================
392 void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
393 const TopoDS_Shape & aShape)
395 _compute_canceled = false;
398 //=============================================================================
400 * Cancel Compute a mesh
402 //=============================================================================
403 void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
404 const TopoDS_Shape & aShape)
406 _compute_canceled = true;
409 _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
414 //=============================================================================
418 //=============================================================================
420 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
421 const TopoDS_Shape & aShape,
422 MapShapeNbElems& aResMap,
424 TSetOfInt* aShapesId)
426 MESSAGE("SMESH_Gen::Evaluate");
430 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
432 const bool includeSelf = true;
433 const bool complexShapeFirst = true;
434 SMESH_subMeshIteratorPtr smIt;
436 if ( anUpward ) { // is called from below code here
437 // -----------------------------------------------
438 // mesh all the sub-shapes starting from vertices
439 // -----------------------------------------------
440 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
441 while ( smIt->more() ) {
442 SMESH_subMesh* smToCompute = smIt->next();
444 // do not mesh vertices of a pseudo shape
445 const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
446 //if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
448 if ( !aMesh.HasShapeToMesh() ) {
449 if( aShType == TopAbs_VERTEX || aShType == TopAbs_WIRE ||
450 aShType == TopAbs_SHELL )
454 smToCompute->Evaluate(aResMap);
456 aShapesId->insert( smToCompute->GetId() );
461 // -----------------------------------------------------------------
462 // apply algos that DO NOT require Discreteized boundaries and DO NOT
463 // support submeshes, starting from the most complex shapes
464 // and collect submeshes with algos that DO support submeshes
465 // -----------------------------------------------------------------
466 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
467 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
468 while ( smIt->more() ) {
469 SMESH_subMesh* smToCompute = smIt->next();
470 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
471 const int aShapeDim = GetShapeDim( aSubShape );
472 if ( aShapeDim < 1 ) break;
474 SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
475 if ( algo && !algo->NeedDiscreteBoundary() ) {
476 if ( algo->SupportSubmeshes() ) {
477 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
480 smToCompute->Evaluate(aResMap);
482 aShapesId->insert( smToCompute->GetId() );
487 // ------------------------------------------------------------
488 // sort list of meshes according to mesh order
489 // ------------------------------------------------------------
490 aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
492 // ------------------------------------------------------------
493 // compute submeshes under shapes with algos that DO NOT require
494 // Discreteized boundaries and DO support submeshes
495 // ------------------------------------------------------------
496 list< SMESH_subMesh* >::iterator subIt, subEnd;
497 subIt = smWithAlgoSupportingSubmeshes.begin();
498 subEnd = smWithAlgoSupportingSubmeshes.end();
499 // start from lower shapes
500 for ( ; subIt != subEnd; ++subIt ) {
503 // get a shape the algo is assigned to
504 TopoDS_Shape algoShape;
505 if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
506 continue; // strange...
508 // look for more local algos
509 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
510 while ( smIt->more() ) {
511 SMESH_subMesh* smToCompute = smIt->next();
513 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
514 const int aShapeDim = GetShapeDim( aSubShape );
515 if ( aShapeDim < 1 ) continue;
517 //const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
519 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
521 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
522 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
524 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
525 SMESH_Hypothesis::Hypothesis_Status status;
526 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
527 // mesh a lower smToCompute starting from vertices
528 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
532 // ----------------------------------------------------------
533 // apply the algos that do not require Discreteized boundaries
534 // ----------------------------------------------------------
535 for ( subIt = smWithAlgoSupportingSubmeshes.begin(); subIt != subEnd; ++subIt )
538 sm->Evaluate(aResMap);
540 aShapesId->insert( sm->GetId() );
543 // -----------------------------------------------
544 // mesh the rest sub-shapes starting from vertices
545 // -----------------------------------------------
546 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
549 MESSAGE( "VSR - SMESH_Gen::Evaluate() finished, OK = " << ret);
554 //=======================================================================
555 //function : checkConformIgnoredAlgos
557 //=======================================================================
559 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
560 SMESH_subMesh* aSubMesh,
561 const SMESH_Algo* aGlobIgnoAlgo,
562 const SMESH_Algo* aLocIgnoAlgo,
564 set<SMESH_subMesh*>& aCheckedMap,
565 list< SMESH_Gen::TAlgoStateError > & theErrors)
568 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
574 const list<const SMESHDS_Hypothesis*>& listHyp =
575 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
576 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
577 for ( ; it != listHyp.end(); it++)
579 const SMESHDS_Hypothesis * aHyp = *it;
580 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
583 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
586 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
588 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
589 << aLocIgnoAlgo->GetName() << ">");
593 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
594 int dim = algo->GetDim();
595 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
597 if ( dim < aMaxGlobIgnoDim )
599 // algo is hidden by a global algo
600 INFOS( ( isGlobal ? "Global" : "Local" )
601 << " <" << algo->GetName() << "> is hidden by global <"
602 << aGlobIgnoAlgo->GetName() << ">");
604 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
606 // local algo is not hidden and hides algos on sub-shapes
607 if (checkConform && !aSubMesh->IsConform( algo ))
610 checkConform = false; // no more check conformity
611 INFOS( "ERROR: Local <" << algo->GetName() <<
612 "> would produce not conform mesh: "
613 "<Not Conform Mesh Allowed> hypotesis is missing");
614 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
615 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
618 // sub-algos will be hidden by a local <algo>
619 SMESH_subMeshIteratorPtr revItSub =
620 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
621 bool checkConform2 = false;
622 while ( revItSub->more() )
624 SMESH_subMesh* sm = revItSub->next();
625 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
626 algo, checkConform2, aCheckedMap, theErrors);
627 aCheckedMap.insert( sm );
636 //=======================================================================
637 //function : checkMissing
638 //purpose : notify on missing hypothesis
639 // Return false if algo or hipothesis is missing
640 //=======================================================================
642 static bool checkMissing(SMESH_Gen* aGen,
644 SMESH_subMesh* aSubMesh,
645 const int aTopAlgoDim,
647 const bool checkNoAlgo,
648 set<SMESH_subMesh*>& aCheckedMap,
649 list< SMESH_Gen::TAlgoStateError > & theErrors)
651 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX ||
652 aCheckedMap.count( aSubMesh ))
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 = aSubMesh->GetAlgo();
710 if (!algo->NeedDiscreteBoundary())
712 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
713 /*complexShapeFirst=*/false);
714 while ( itsub->more() )
715 aCheckedMap.insert( itsub->next() );
721 // do not check under algo that hides sub-algos or
722 // re-start checking NO_ALGO state
724 bool isTopLocalAlgo =
725 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
726 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
728 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
729 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
730 /*complexShapeFirst=*/false);
731 while ( itsub->more() )
733 // sub-meshes should not be checked further more
734 SMESH_subMesh* sm = itsub->next();
738 //check algo on sub-meshes
739 int aTopAlgoDim2 = algo->GetDim();
740 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
741 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
744 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
745 checkNoAlgo2 = false;
748 aCheckedMap.insert( sm );
754 //=======================================================================
755 //function : CheckAlgoState
756 //purpose : notify on bad state of attached algos, return false
757 // if Compute() would fail because of some algo bad state
758 //=======================================================================
760 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
762 list< TAlgoStateError > errors;
763 return GetAlgoState( aMesh, aShape, errors );
766 //=======================================================================
767 //function : GetAlgoState
768 //purpose : notify on bad state of attached algos, return false
769 // if Compute() would fail because of some algo bad state
770 // theErrors list contains problems description
771 //=======================================================================
773 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
774 const TopoDS_Shape& theShape,
775 list< TAlgoStateError > & theErrors)
777 //MESSAGE("SMESH_Gen::CheckAlgoState");
780 bool hasAlgo = false;
782 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
783 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
784 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
790 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
792 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
793 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
794 for ( ; it != listHyp.end(); it++)
796 const SMESHDS_Hypothesis * aHyp = *it;
797 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
800 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
803 int dim = algo->GetDim();
804 aGlobAlgoArr[ dim ] = algo;
809 // --------------------------------------------------------
810 // info on algos that will be ignored because of ones that
811 // don't NeedDiscreteBoundary() attached to super-shapes,
812 // check that a conform mesh will be produced
813 // --------------------------------------------------------
816 // find a global algo possibly hiding sub-algos
818 const SMESH_Algo* aGlobIgnoAlgo = 0;
819 for (dim = 3; dim > 0; dim--)
821 if (aGlobAlgoArr[ dim ] &&
822 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary())
824 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
829 set<SMESH_subMesh*> aCheckedSubs;
830 bool checkConform = ( !theMesh.IsNotConformAllowed() );
832 // loop on theShape and its sub-shapes
833 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
834 /*complexShapeFirst=*/true);
835 while ( revItSub->more() )
837 SMESH_subMesh* smToCheck = revItSub->next();
838 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
841 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
842 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
843 0, checkConform, aCheckedSubs, theErrors))
846 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
850 // ----------------------------------------------------------------
851 // info on missing hypothesis and find out if all needed algos are
853 // ----------------------------------------------------------------
855 //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
857 // find max dim of global algo
859 for (dim = 3; dim > 0; dim--)
861 if (aGlobAlgoArr[ dim ])
867 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
868 bool globalChecked[] = { false, false, false, false };
870 // loop on theShape and its sub-shapes
871 aCheckedSubs.clear();
872 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
873 while ( revItSub->more() )
875 SMESH_subMesh* smToCheck = revItSub->next();
876 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
879 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
880 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
881 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
884 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
891 INFOS( "None algorithm attached" );
892 theErrors.push_back( TAlgoStateError() );
893 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
899 //=======================================================================
900 //function : IsGlobalHypothesis
901 //purpose : check if theAlgo is attached to the main shape
902 //=======================================================================
904 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
906 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
907 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
910 //================================================================================
912 * \brief Return paths to xml files of plugins
914 //================================================================================
916 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
918 // Get paths to xml files of plugins
919 vector< string > xmlPaths;
921 if ( const char* meshersList = getenv("SMESH_MeshersList") )
923 string meshers = meshersList, plugin;
924 string::size_type from = 0, pos;
925 while ( from < meshers.size() )
927 // cut off plugin name
928 pos = meshers.find( ':', from );
929 if ( pos != string::npos )
930 plugin = meshers.substr( from, pos-from );
932 plugin = meshers.substr( from ), pos = meshers.size();
935 // get PLUGIN_ROOT_DIR path
936 string rootDirVar, pluginSubDir = plugin;
937 if ( plugin == "StdMeshers" )
938 rootDirVar = "SMESH", pluginSubDir = "smesh";
940 for ( pos = 0; pos < plugin.size(); ++pos )
941 rootDirVar += toupper( plugin[pos] );
942 rootDirVar += "_ROOT_DIR";
944 const char* rootDir = getenv( rootDirVar.c_str() );
945 if ( !rootDir || strlen(rootDir) == 0 )
947 rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
948 rootDir = getenv( rootDirVar.c_str() );
949 if ( !rootDir || strlen(rootDir) == 0 ) continue;
952 // get a separator from rootDir
953 for ( pos = strlen( rootDir )-1; pos >= 0 && sep.empty(); --pos )
954 if ( rootDir[pos] == '/' || rootDir[pos] == '\\' )
960 if (sep.empty() ) sep = "\\";
962 if (sep.empty() ) sep = "/";
965 // get a path to resource file
966 string xmlPath = rootDir;
967 if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
969 xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
970 for ( pos = 0; pos < pluginSubDir.size(); ++pos )
971 xmlPath += tolower( pluginSubDir[pos] );
972 xmlPath += sep + plugin + ".xml";
975 fileOK = (GetFileAttributes(xmlPath.c_str()) != INVALID_FILE_ATTRIBUTES);
977 fileOK = (access(xmlPath.c_str(), F_OK) == 0);
980 xmlPaths.push_back( xmlPath );
987 //=======================================================================
988 namespace // Access to type of input and output of an algorithm
989 //=======================================================================
994 set<SMDSAbs_GeometryType> _inElemTypes; // acceptable types of input mesh element
995 set<SMDSAbs_GeometryType> _outElemTypes; // produced types of mesh elements
997 bool IsCompatible( const AlgoData& algo2 ) const
999 if ( _dim > algo2._dim ) return algo2.IsCompatible( *this );
1000 // algo2 is of highter dimension
1001 if ( _outElemTypes.empty() || algo2._inElemTypes.empty() )
1003 bool compatible = true;
1004 set<SMDSAbs_GeometryType>::const_iterator myOutType = _outElemTypes.begin();
1005 for ( ; myOutType != _outElemTypes.end() && compatible; ++myOutType )
1006 compatible = algo2._inElemTypes.count( *myOutType );
1011 //================================================================================
1013 * \brief Return AlgoData of the algorithm
1015 //================================================================================
1017 const AlgoData& getAlgoData( const SMESH_Algo* algo )
1019 static map< string, AlgoData > theDataByName;
1020 if ( theDataByName.empty() )
1022 // Read Plugin.xml files
1023 vector< string > xmlPaths = SMESH_Gen::GetPluginXMLPaths();
1024 LDOMParser xmlParser;
1025 for ( size_t iXML = 0; iXML < xmlPaths.size(); ++iXML )
1027 bool error = xmlParser.parse( xmlPaths[iXML].c_str() );
1030 TCollection_AsciiString data;
1031 INFOS( xmlParser.GetError(data) );
1034 // <algorithm type="Regular_1D"
1037 // output="QUAD,TRIA">
1039 LDOM_Document xmlDoc = xmlParser.getDocument();
1040 LDOM_NodeList algoNodeList = xmlDoc.getElementsByTagName( "algorithm" );
1041 for ( int i = 0; i < algoNodeList.getLength(); ++i )
1043 LDOM_Node algoNode = algoNodeList.item( i );
1044 LDOM_Element& algoElem = (LDOM_Element&) algoNode;
1045 TCollection_AsciiString algoType = algoElem.getAttribute("type");
1046 TCollection_AsciiString input = algoElem.getAttribute("input");
1047 TCollection_AsciiString output = algoElem.getAttribute("output");
1048 TCollection_AsciiString dim = algoElem.getAttribute("dim");
1049 if ( algoType.IsEmpty() ) continue;
1050 AlgoData & data = theDataByName[ algoType.ToCString() ];
1051 data._dim = dim.IntegerValue();
1052 for ( int isInput = 0; isInput < 2; ++isInput )
1054 TCollection_AsciiString& typeStr = isInput ? input : output;
1055 set<SMDSAbs_GeometryType>& typeSet = isInput ? data._inElemTypes : data._outElemTypes;
1057 while ( beg <= typeStr.Length() )
1059 while ( beg < typeStr.Length() && !isalpha( typeStr.Value( beg ) ))
1062 while ( end < typeStr.Length() && isalpha( typeStr.Value( end + 1 ) ))
1066 TCollection_AsciiString typeName = typeStr.SubString( beg, end );
1067 if ( typeName == "EDGE" ) typeSet.insert( SMDSGeom_EDGE );
1068 else if ( typeName == "TRIA" ) typeSet.insert( SMDSGeom_TRIANGLE );
1069 else if ( typeName == "QUAD" ) typeSet.insert( SMDSGeom_QUADRANGLE );
1077 return theDataByName[ algo->GetName() ];
1081 //=============================================================================
1083 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
1085 //=============================================================================
1087 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
1088 const TopoDS_Shape & aShape,
1089 TopoDS_Shape* assignedTo)
1091 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
1092 filter.And( filter.IsApplicableTo( aShape ));
1094 TopoDS_Shape assignedToShape;
1096 (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape );
1099 aShape.ShapeType() == TopAbs_FACE &&
1100 !aShape.IsSame( assignedToShape ) &&
1101 SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
1103 // Issue 0021559. If there is another 2D algo with different types of output
1104 // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
1105 // have different types of input elements, we choose a most appropriate 2D algo.
1107 // try to find a concurrent 2D algo
1108 filter.AndNot( filter.Is( algo ));
1109 TopoDS_Shape assignedToShape2;
1111 (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, &assignedToShape2 );
1112 if ( algo2 && // algo found
1113 !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) && // algo is local
1114 ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
1115 SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
1116 aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ), // no forced order
1117 aMesh.GetSubMesh( assignedToShape )))
1119 // get algos on the adjacent SOLIDs
1120 filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
1121 vector< SMESH_Algo* > algos3D;
1122 PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
1124 while ( const TopoDS_Shape* solid = solidIt->next() )
1125 if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
1127 algos3D.push_back( algo3D );
1128 filter.AndNot( filter.HasName( algo3D->GetName() ));
1130 // check compatibility of algos
1131 if ( algos3D.size() > 1 )
1133 const AlgoData& algoData = getAlgoData( algo );
1134 const AlgoData& algoData2 = getAlgoData( algo2 );
1135 const AlgoData& algoData3d0 = getAlgoData( algos3D[0] );
1136 const AlgoData& algoData3d1 = getAlgoData( algos3D[1] );
1137 if (( algoData2.IsCompatible( algoData3d0 ) &&
1138 algoData2.IsCompatible( algoData3d1 ))
1140 !(algoData.IsCompatible( algoData3d0 ) &&
1141 algoData.IsCompatible( algoData3d1 )))
1147 if ( assignedTo && algo )
1148 * assignedTo = assignedToShape;
1153 //=============================================================================
1155 * Returns StudyContextStruct for a study
1157 //=============================================================================
1159 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
1161 // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
1163 if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
1165 _mapStudyContext[studyId] = new StudyContextStruct;
1166 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
1168 StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
1169 return myStudyContext;
1172 //================================================================================
1174 * \brief Return shape dimension by TopAbs_ShapeEnum
1176 //================================================================================
1178 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1180 static vector<int> dim;
1183 dim.resize( TopAbs_SHAPE, -1 );
1184 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
1185 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1186 dim[ TopAbs_SOLID ] = MeshDim_3D;
1187 dim[ TopAbs_SHELL ] = MeshDim_2D;
1188 dim[ TopAbs_FACE ] = MeshDim_2D;
1189 dim[ TopAbs_WIRE ] = MeshDim_1D;
1190 dim[ TopAbs_EDGE ] = MeshDim_1D;
1191 dim[ TopAbs_VERTEX ] = MeshDim_0D;
1193 return dim[ aShapeType ];
1196 //=============================================================================
1198 * Genarate a new id unique withing this Gen
1200 //=============================================================================
1202 int SMESH_Gen::GetANewId()