1 // Copyright (C) 2007-2023 CEA, EDF, 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 : implementation of SMESH idl descriptions
24 // File : SMESH_Gen.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_Gen.hxx"
32 #include "SMESH_DriverMesh.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_Mesh.hxx"
39 #include "SMESH_SequentialMesh.hxx"
40 #include "SMESH_ParallelMesh.hxx"
41 #include "SMESH_MesherHelper.hxx"
42 #include "SMESH_subMesh.hxx"
44 #include <utilities.h>
45 #include <Utils_ExceptHandlers.hxx>
47 #include <TopExp_Explorer.hxx>
49 #include <TopoDS_Iterator.hxx>
61 #include <Basics_Utils.hxx>
64 #include <boost/asio.hpp>
69 #include <boost/filesystem.hpp>
70 namespace fs = boost::filesystem;
73 // Environment variable separator
82 // a structure used to nullify SMESH_Gen field of SMESH_Hypothesis,
83 // which is needed for SMESH_Hypothesis not deleted before ~SMESH_Gen()
84 struct _Hyp : public SMESH_Hypothesis
92 //================================================================================
94 * \brief Fill a map of shapes with all sub-shape of a sub-mesh
96 //================================================================================
98 TopTools_IndexedMapOfShape * fillAllowed( SMESH_subMesh* sm,
100 TopTools_IndexedMapOfShape * allowedSub )
102 if ( !toFill || !allowedSub )
106 if ( allowedSub->IsEmpty() )
108 allowedSub->ReSize( sm->DependsOn().size() + 1 );
109 allowedSub->Add( sm->GetSubShape() );
110 for ( const auto & key_sm : sm->DependsOn() )
111 allowedSub->Add( key_sm.second->GetSubShape() );
117 //=============================================================================
121 //=============================================================================
123 SMESH_Gen::SMESH_Gen()
125 _studyContext = new StudyContextStruct;
126 _studyContext->myDocument = new SMESHDS_Document();
129 _segmentation = _nbSegments = 10;
130 _compute_canceled = false;
133 //=============================================================================
137 //=============================================================================
139 SMESH_Gen::~SMESH_Gen()
141 std::map < int, SMESH_Hypothesis * >::iterator i_hyp = _studyContext->mapHypothesis.begin();
142 for ( ; i_hyp != _studyContext->mapHypothesis.end(); ++i_hyp )
144 if ( _Hyp* h = static_cast< _Hyp*>( i_hyp->second ))
147 delete _studyContext->myDocument;
148 delete _studyContext;
151 //=============================================================================
153 * Creates a mesh in a study.
154 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
156 //=============================================================================
158 SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
160 Unexpect aCatch(SalomeException);
162 // create a new SMESH_mesh object
163 SMESH_Mesh *aMesh = new SMESH_SequentialMesh(
167 _studyContext->myDocument);
168 _studyContext->mapMesh[_localId-1] = aMesh;
173 //=============================================================================
175 * Creates a parallel mesh in a study.
176 * if (theIsEmbeddedMode) { mesh modification commands are not logged }
178 //=============================================================================
180 SMESH_ParallelMesh* SMESH_Gen::CreateParallelMesh(bool theIsEmbeddedMode)
182 Unexpect aCatch(SalomeException);
184 // create a new SMESH_mesh object
185 SMESH_ParallelMesh *aMesh = new SMESH_ParallelMesh(
189 _studyContext->myDocument);
190 _studyContext->mapMesh[_localId-1] = aMesh;
195 //=============================================================================
197 * Algo to run the computation of all the submeshes of a mesh in sequentila
199 //=============================================================================
201 bool SMESH_Gen::sequentialComputeSubMeshes(
203 const TopoDS_Shape & aShape,
204 const ::MeshDimension aDim,
205 TSetOfInt* aShapesId /*=0*/,
206 TopTools_IndexedMapOfShape* allowedSubShapes,
207 SMESH_subMesh::compute_event &computeEvent,
208 const bool includeSelf,
209 const bool complexShapeFirst,
210 const bool aShapeOnly)
212 MESSAGE("Sequential Compute of submeshes");
216 SMESH_subMeshIteratorPtr smIt;
217 SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
219 smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
220 while ( smIt->more() )
222 SMESH_subMesh* smToCompute = smIt->next();
224 // do not mesh vertices of a pseudo shape
225 const TopoDS_Shape& shape = smToCompute->GetSubShape();
226 const TopAbs_ShapeEnum shapeType = shape.ShapeType();
227 if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
230 // check for preview dimension limitations
231 if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
233 // clear compute state not to show previous compute errors
234 // if preview invoked less dimension less than previous
235 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
239 if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
241 if (_compute_canceled)
243 smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
244 setCurrentSubMesh( smToCompute );
245 smToCompute->ComputeStateEngine( computeEvent );
246 setCurrentSubMesh( nullptr );
247 smToCompute->SetAllowedSubShapes( nullptr );
250 // we check all the sub-meshes here and detect if any of them failed to compute
251 if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
252 ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
254 else if ( aShapesId )
255 aShapesId->insert( smToCompute->GetId() );
257 //aMesh.GetMeshDS()->Modified();
262 //=============================================================================
264 * compute of a submesh
265 * This function is passed to the thread pool
267 //=============================================================================
268 const std::function<void(SMESH_subMesh*,
269 SMESH_subMesh::compute_event,
272 TopTools_IndexedMapOfShape *,
274 compute_function([] (SMESH_subMesh* sm,
275 SMESH_subMesh::compute_event event,
276 SMESH_subMesh *shapeSM,
278 TopTools_IndexedMapOfShape *allowedSubShapes,
279 TSetOfInt* aShapesId) -> void
281 if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
283 sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
284 //setCurrentSubMesh( sm );
285 sm->ComputeStateEngine(event);
286 //setCurrentSubMesh( nullptr );
287 sm->SetAllowedSubShapes( nullptr );
291 aShapesId->insert( sm->GetId() );
296 //=============================================================================
298 * Copy a file on remote resource
300 //=============================================================================
302 void SMESH_Gen::send_mesh(SMESH_Mesh& aMesh, std::string file_name)
305 SMESH_ParallelMesh& aParMesh = dynamic_cast<SMESH_ParallelMesh&>(aMesh);
306 // Calling run_mesher
307 // Path to mesher script
308 fs::path send_files = fs::path(std::getenv("SMESH_ROOT_DIR"))/
311 fs::path("send_files.py");
313 std::string s_program="python3";
314 std::list<std::string> params;
315 params.push_back(send_files.string());
316 params.push_back(file_name);
317 params.push_back("--resource="+aParMesh.GetResource());
320 fs::path log_file=aParMesh.GetTmpFolder() / fs::path("copy.log");
321 QString out_file = log_file.string().c_str();
323 // Building arguments for QProcess
324 QString program = QString::fromStdString(s_program);
325 QStringList arguments;
326 for(auto arg : params){
327 arguments << arg.c_str();
330 std::string cmd = "";
332 for(auto arg: params){
335 MESSAGE("Send files command: ");
339 myProcess.setProcessChannelMode(QProcess::MergedChannels);
340 myProcess.setStandardOutputFile(out_file);
342 myProcess.start(program, arguments);
343 // Waiting for process to finish (argument -1 make it wait until the end of
344 // the process otherwise it just waits 30 seconds)
345 bool finished = myProcess.waitForFinished(-1);
346 int ret = myProcess.exitCode();
348 if(ret != 0 || !finished){
350 std::string msg = "Issue with send_files: \n";
351 msg += "See log for more details: " + log_file.string() + "\n";
353 throw SALOME_Exception(msg);
358 //=============================================================================
360 * Algo to run the computation of all the submeshes of a mesh in parallel
362 //=============================================================================
364 bool SMESH_Gen::parallelComputeSubMeshes(
366 const TopoDS_Shape & aShape,
367 const ::MeshDimension aDim,
368 TSetOfInt* aShapesId /*=0*/,
369 TopTools_IndexedMapOfShape* allowedSubShapes,
370 SMESH_subMesh::compute_event &computeEvent,
371 const bool includeSelf,
372 const bool complexShapeFirst,
373 const bool aShapeOnly)
376 throw SALOME_Exception("ParallelMesh is not working on Windows");
381 SMESH_subMeshIteratorPtr smIt;
382 SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
383 SMESH_ParallelMesh &aParMesh = dynamic_cast<SMESH_ParallelMesh&>(aMesh);
385 TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
386 MESSAGE("Parallel Compute of submeshes");
389 smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
390 while ( smIt->more() )
392 SMESH_subMesh* smToCompute = smIt->next();
394 // do not mesh vertices of a pseudo shape
395 const TopoDS_Shape& shape = smToCompute->GetSubShape();
396 const TopAbs_ShapeEnum shapeType = shape.ShapeType();
397 // Not doing in parallel 1D and 2D meshes
398 if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
401 if (shapeType != previousShapeType) {
402 // Waiting for all threads for the previous type to end
405 std::string file_name;
406 switch(previousShapeType){
408 file_name = "Mesh2D.med";
411 // file_name = "Mesh1D.med";
413 //case TopAbs_VERTEX:
414 // file_name = "Mesh0D.med";
423 fs::path mesh_file = fs::path(aParMesh.GetTmpFolder()) / fs::path(file_name);
424 SMESH_DriverMesh::exportMesh(mesh_file.string(), aMesh, "MESH");
425 if (aParMesh.GetParallelismMethod() == ParallelismMethod::MultiNode) {
426 this->send_mesh(aMesh, mesh_file.string());
429 //Resetting threaded pool info
430 previousShapeType = shapeType;
433 // check for preview dimension limitations
434 if ( aShapesId && SMESH_Gen::GetShapeDim( shapeType ) > (int)aDim )
436 // clear compute state not to show previous compute errors
437 // if preview invoked less dimension less than previous
438 smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
441 // Parallelism is only for 3D parts
442 if(shapeType!=TopAbs_SOLID){
443 compute_function(smToCompute, computeEvent,
444 shapeSM, aShapeOnly, allowedSubShapes,
447 boost::asio::post(*(aParMesh.GetPool()), std::bind(compute_function, smToCompute, computeEvent,
448 shapeSM, aShapeOnly, allowedSubShapes,
453 // Waiting for the thread for Solids to finish
456 aMesh.GetMeshDS()->Modified();
458 // Cleanup done here as in Python the destructor is not called
465 //=============================================================================
469 //=============================================================================
471 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
472 const TopoDS_Shape & aShape,
473 const int aFlags /*= COMPACT_MESH*/,
474 const ::MeshDimension aDim /*=::MeshDim_3D*/,
475 TSetOfInt* aShapesId /*=0*/,
476 TopTools_IndexedMapOfShape* anAllowedSubShapes/*=0*/)
480 const bool aShapeOnly = aFlags & SHAPE_ONLY;
481 const bool anUpward = aFlags & UPWARD;
482 const bool aCompactMesh = aFlags & COMPACT_MESH;
486 SMESH_subMesh *sm, *shapeSM = aMesh.GetSubMesh(aShape);
488 const bool includeSelf = true;
489 const bool complexShapeFirst = true;
490 const int globalAlgoDim = 100;
492 SMESH_subMeshIteratorPtr smIt;
494 // Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
495 // that must be computed by Projection 1D-2D while the Projection asks to compute
497 SMESH_subMesh::compute_event computeEvent =
498 aShapeOnly ? SMESH_subMesh::COMPUTE_SUBMESH : SMESH_subMesh::COMPUTE;
499 if ( !aMesh.HasShapeToMesh() )
500 computeEvent = SMESH_subMesh::COMPUTE_NOGEOM; // if several algos and no geometry
502 TopTools_IndexedMapOfShape *allowedSubShapes = anAllowedSubShapes, allowedSub;
503 if ( aShapeOnly && !allowedSubShapes )
504 allowedSubShapes = &allowedSub;
506 if ( anUpward ) // is called from the below code in this method
508 // ===============================================
509 // Mesh all the sub-shapes starting from vertices
510 // ===============================================
511 ret = aMesh.ComputeSubMeshes(
514 aShapesId, allowedSubShapes,
524 // ================================================================
525 // Apply algos that do NOT require discretized boundaries
526 // ("all-dimensional") and do NOT support sub-meshes, starting from
527 // the most complex shapes and collect sub-meshes with algos that
528 // DO support sub-meshes
529 // ================================================================
530 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
532 // map to sort sm with same dim algos according to dim of
533 // the shape the algo assigned to (issue 0021217).
534 // Other issues influenced the algo applying order:
535 // 21406, 21556, 21893, 20206
536 multimap< int, SMESH_subMesh* > shDim2sm;
537 multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
538 TopoDS_Shape algoShape;
539 int prevShapeDim = -1, aShapeDim;
541 smIt = shapeSM->getDependsOnIterator(includeSelf, complexShapeFirst);
542 while ( smIt->more() )
544 SMESH_subMesh* smToCompute = smIt->next();
545 if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
548 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
549 aShapeDim = GetShapeDim( aSubShape );
550 if ( aShapeDim < 1 ) break;
552 // check for preview dimension limitations
553 if ( aShapesId && aShapeDim > (int)aDim )
556 SMESH_Algo* algo = GetAlgo( smToCompute, &algoShape );
557 if ( algo && !algo->NeedDiscreteBoundary() )
559 if ( algo->SupportSubmeshes() )
561 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
562 // so that more local algos to go first
563 if ( prevShapeDim != aShapeDim )
565 prevShapeDim = aShapeDim;
566 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
567 if ( shDim2smIt->first == globalAlgoDim )
568 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_back( shDim2smIt->second );
570 smWithAlgoSupportingSubmeshes[ aShapeDim ].push_front( shDim2smIt->second );
573 // add smToCompute to shDim2sm map
574 if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
576 aShapeDim = globalAlgoDim; // to compute last
580 aShapeDim = GetShapeDim( algoShape );
581 if ( algoShape.ShapeType() == TopAbs_COMPOUND )
583 TopoDS_Iterator it( algoShape );
584 aShapeDim += GetShapeDim( it.Value() );
587 shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
589 else // Compute w/o support of sub-meshes
591 if (_compute_canceled)
593 smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
594 setCurrentSubMesh( smToCompute );
595 smToCompute->ComputeStateEngine( computeEvent );
596 setCurrentSubMesh( nullptr );
597 smToCompute->SetAllowedSubShapes( nullptr );
599 aShapesId->insert( smToCompute->GetId() );
603 // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
604 for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
605 if ( shDim2smIt->first == globalAlgoDim )
606 smWithAlgoSupportingSubmeshes[3].push_back( shDim2smIt->second );
608 smWithAlgoSupportingSubmeshes[0].push_front( shDim2smIt->second );
610 // ======================================================
611 // Apply all-dimensional algorithms supporing sub-meshes
612 // ======================================================
614 std::vector< SMESH_subMesh* > smVec;
615 for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim )
616 smVec.insert( smVec.end(),
617 smWithAlgoSupportingSubmeshes[aShapeDim].begin(),
618 smWithAlgoSupportingSubmeshes[aShapeDim].end() );
620 // gather sub-shapes with local uni-dimensional algos (bos #29143)
621 // ----------------------------------------------------------------
622 TopTools_MapOfShape uniDimAlgoShapes;
623 if ( !smVec.empty() )
625 ShapeToHypothesis::Iterator s2hyps( aMesh.GetMeshDS()->GetHypotheses() );
626 for ( ; s2hyps.More(); s2hyps.Next() )
628 const TopoDS_Shape& s = s2hyps.Key();
629 if ( s.IsSame( aMesh.GetShapeToMesh() ))
631 for ( auto & hyp : s2hyps.Value() )
633 if ( const SMESH_Algo* algo = dynamic_cast< const SMESH_Algo*>( hyp ))
634 if ( algo->NeedDiscreteBoundary() )
636 TopAbs_ShapeEnum sType;
637 switch ( algo->GetDim() ) {
638 case 3: sType = TopAbs_SOLID; break;
639 case 2: sType = TopAbs_FACE; break;
640 default: sType = TopAbs_EDGE; break;
642 for ( TopExp_Explorer ex( s2hyps.Key(), sType ); ex.More(); ex.Next() )
643 uniDimAlgoShapes.Add( ex.Current() );
650 // ------------------------------------------------
651 // sort list of sub-meshes according to mesh order
652 // ------------------------------------------------
653 aMesh.SortByMeshOrder( smVec );
655 // ------------------------------------------------------------
656 // compute sub-meshes with local uni-dimensional algos under
657 // sub-meshes with all-dimensional algos
658 // ------------------------------------------------------------
659 // start from lower shapes
660 for ( size_t i = 0; i < smVec.size(); ++i )
663 if ( sm->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE)
666 const TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
668 if ( !uniDimAlgoShapes.IsEmpty() )
670 // get a shape the algo is assigned to
671 if ( !GetAlgo( sm, & algoShape ))
672 continue; // strange...
674 // look for more local algos
675 if ( SMESH_subMesh* algoSM = aMesh.GetSubMesh( algoShape ))
676 smIt = algoSM->getDependsOnIterator(!includeSelf, !complexShapeFirst);
678 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
680 while ( smIt->more() )
682 SMESH_subMesh* smToCompute = smIt->next();
684 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
685 const int aShapeDim = GetShapeDim( aSubShape );
686 if ( aShapeDim < 1 || aSubShape.ShapeType() <= shapeType )
688 if ( !uniDimAlgoShapes.Contains( aSubShape ))
689 continue; // [bos #29143] aMesh.GetHypothesis() is too long
691 // check for preview dimension limitations
692 if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
695 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
697 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
698 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
700 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true))
702 if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
703 TopTools_IndexedMapOfShape* localAllowed = allowedSubShapes;
704 if ( localAllowed && localAllowed->IsEmpty() )
705 localAllowed = 0; // prevent fillAllowed() with aSubShape
707 SMESH_Hypothesis::Hypothesis_Status status;
708 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
709 // mesh a lower smToCompute starting from vertices
710 Compute( aMesh, aSubShape, aFlags | SHAPE_ONLY_UPWARD, aDim, aShapesId, localAllowed );
714 // --------------------------------
715 // apply the all-dimensional algo
716 // --------------------------------
718 if (_compute_canceled)
720 // check for preview dimension limitations
721 if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
723 sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
725 setCurrentSubMesh( sm );
726 sm->ComputeStateEngine( computeEvent );
728 setCurrentSubMesh( NULL );
729 sm->SetAllowedSubShapes( nullptr );
731 aShapesId->insert( sm->GetId() );
736 // -----------------------------------------------
737 // mesh the rest sub-shapes starting from vertices
738 // -----------------------------------------------
739 ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes );
745 // fix quadratic mesh by bending iternal links near concave boundary
746 if ( aCompactMesh && // a final compute
747 aShape.IsSame( aMesh.GetShapeToMesh() ) &&
748 !aShapesId && // not preview
749 ret ) // everything is OK
751 SMESH_MesherHelper aHelper( aMesh );
752 if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
754 aHelper.FixQuadraticElements( shapeSM->GetComputeError() );
760 aMesh.GetMeshDS()->Modified();
761 aMesh.GetMeshDS()->CompactMesh();
766 //=============================================================================
768 * Prepare Compute a mesh
770 //=============================================================================
771 void SMESH_Gen::PrepareCompute(SMESH_Mesh & /*aMesh*/,
772 const TopoDS_Shape & /*aShape*/)
774 _compute_canceled = false;
775 resetCurrentSubMesh();
778 //=============================================================================
780 * Cancel Compute a mesh
782 //=============================================================================
783 void SMESH_Gen::CancelCompute(SMESH_Mesh & /*aMesh*/,
784 const TopoDS_Shape & /*aShape*/)
786 _compute_canceled = true;
787 if ( const SMESH_subMesh* sm = GetCurrentSubMesh() )
789 const_cast< SMESH_subMesh* >( sm )->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
791 resetCurrentSubMesh();
794 //================================================================================
796 * \brief Returns a sub-mesh being currently computed
798 //================================================================================
800 const SMESH_subMesh* SMESH_Gen::GetCurrentSubMesh() const
802 return _sm_current.empty() ? 0 : _sm_current.back();
805 //================================================================================
807 * \brief Sets a sub-mesh being currently computed.
809 * An algorithm can call Compute() for a sub-shape, hence we keep a stack of sub-meshes
811 //================================================================================
813 void SMESH_Gen::setCurrentSubMesh(SMESH_subMesh* sm)
816 _sm_current.push_back( sm );
818 else if ( !_sm_current.empty() )
819 _sm_current.pop_back();
822 void SMESH_Gen::resetCurrentSubMesh()
827 //=============================================================================
831 //=============================================================================
833 bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
834 const TopoDS_Shape & aShape,
835 MapShapeNbElems& aResMap,
837 TSetOfInt* aShapesId)
841 SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
843 const bool includeSelf = true;
844 const bool complexShapeFirst = true;
845 SMESH_subMeshIteratorPtr smIt;
847 if ( anUpward ) { // is called from below code here
848 // -----------------------------------------------
849 // mesh all the sub-shapes starting from vertices
850 // -----------------------------------------------
851 smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
852 while ( smIt->more() ) {
853 SMESH_subMesh* smToCompute = smIt->next();
855 // do not mesh vertices of a pseudo shape
856 const TopAbs_ShapeEnum shapeType = smToCompute->GetSubShape().ShapeType();
857 //if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
859 if ( !aMesh.HasShapeToMesh() ) {
860 if( shapeType == TopAbs_VERTEX || shapeType == TopAbs_WIRE ||
861 shapeType == TopAbs_SHELL )
865 smToCompute->Evaluate(aResMap);
867 aShapesId->insert( smToCompute->GetId() );
872 // -----------------------------------------------------------------
873 // apply algos that DO NOT require Discreteized boundaries and DO NOT
874 // support sub-meshes, starting from the most complex shapes
875 // and collect sub-meshes with algos that DO support sub-meshes
876 // -----------------------------------------------------------------
877 list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
878 smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
879 while ( smIt->more() ) {
880 SMESH_subMesh* smToCompute = smIt->next();
881 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
882 const int aShapeDim = GetShapeDim( aSubShape );
883 if ( aShapeDim < 1 ) break;
885 SMESH_Algo* algo = GetAlgo( smToCompute );
886 if ( algo && !algo->NeedDiscreteBoundary() ) {
887 if ( algo->SupportSubmeshes() ) {
888 smWithAlgoSupportingSubmeshes.push_front( smToCompute );
891 smToCompute->Evaluate(aResMap);
893 aShapesId->insert( smToCompute->GetId() );
898 // ------------------------------------------------------------
899 // sort list of meshes according to mesh order
900 // ------------------------------------------------------------
901 std::vector< SMESH_subMesh* > smVec( smWithAlgoSupportingSubmeshes.begin(),
902 smWithAlgoSupportingSubmeshes.end() );
903 aMesh.SortByMeshOrder( smVec );
905 // ------------------------------------------------------------
906 // compute sub-meshes under shapes with algos that DO NOT require
907 // Discreteized boundaries and DO support sub-meshes
908 // ------------------------------------------------------------
909 // start from lower shapes
910 for ( size_t i = 0; i < smVec.size(); ++i )
914 // get a shape the algo is assigned to
915 TopoDS_Shape algoShape;
916 if ( !GetAlgo( sm, & algoShape ))
917 continue; // strange...
919 // look for more local algos
920 smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
921 while ( smIt->more() ) {
922 SMESH_subMesh* smToCompute = smIt->next();
924 const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
925 const int aShapeDim = GetShapeDim( aSubShape );
926 if ( aShapeDim < 1 ) continue;
928 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
930 .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
931 .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
933 if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( smToCompute, filter, true ))
935 if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
936 SMESH_Hypothesis::Hypothesis_Status status;
937 if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
938 // mesh a lower smToCompute starting from vertices
939 Evaluate( aMesh, aSubShape, aResMap, /*anUpward=*/true, aShapesId );
943 // ----------------------------------------------------------
944 // apply the algos that do not require Discreteized boundaries
945 // ----------------------------------------------------------
946 for ( size_t i = 0; i < smVec.size(); ++i )
949 sm->Evaluate(aResMap);
951 aShapesId->insert( sm->GetId() );
954 // -----------------------------------------------
955 // mesh the rest sub-shapes starting from vertices
956 // -----------------------------------------------
957 ret = Evaluate( aMesh, aShape, aResMap, /*anUpward=*/true, aShapesId );
964 //=======================================================================
965 //function : checkConformIgnoredAlgos
967 //=======================================================================
969 static bool checkConformIgnoredAlgos(SMESH_Mesh& aMesh,
970 SMESH_subMesh* aSubMesh,
971 const SMESH_Algo* aGlobIgnoAlgo,
972 const SMESH_Algo* aLocIgnoAlgo,
974 set<SMESH_subMesh*>& aCheckedMap,
975 list< SMESH_Gen::TAlgoStateError > & theErrors)
978 if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
984 const list<const SMESHDS_Hypothesis*>& listHyp =
985 aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
986 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
987 for ( ; it != listHyp.end(); it++)
989 const SMESHDS_Hypothesis * aHyp = *it;
990 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
993 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
996 if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
998 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
999 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, false );
1000 INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
1001 << aLocIgnoAlgo->GetName() << ">");
1005 bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
1006 int dim = algo->GetDim();
1007 int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
1008 bool isNeededDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->NeedLowerHyps( dim ) : false );
1010 if (( dim < aMaxGlobIgnoDim && !isNeededDim ) &&
1011 ( isGlobal || !aGlobIgnoAlgo->SupportSubmeshes() ))
1013 // algo is hidden by a global algo
1014 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
1015 theErrors.back().Set( SMESH_Hypothesis::HYP_HIDDEN_ALGO, algo, true );
1016 INFOS( ( isGlobal ? "Global" : "Local" )
1017 << " <" << algo->GetName() << "> is hidden by global <"
1018 << aGlobIgnoAlgo->GetName() << ">");
1020 else if ( !algo->NeedDiscreteBoundary() && !isGlobal)
1022 // local algo is not hidden and hides algos on sub-shapes
1023 if (checkConform && !aSubMesh->IsConform( algo ))
1026 checkConform = false; // no more check conformity
1027 INFOS( "ERROR: Local <" << algo->GetName() <<
1028 "> would produce not conform mesh: "
1029 "<Not Conform Mesh Allowed> hypothesis is missing");
1030 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
1031 theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
1034 // sub-algos will be hidden by a local <algo> if <algo> does not support sub-meshes
1035 if ( algo->SupportSubmeshes() )
1037 SMESH_subMeshIteratorPtr revItSub =
1038 aSubMesh->getDependsOnIterator( /*includeSelf=*/false, /*complexShapeFirst=*/true);
1039 bool checkConform2 = false;
1040 while ( revItSub->more() )
1042 SMESH_subMesh* sm = revItSub->next();
1043 checkConformIgnoredAlgos (aMesh, sm, aGlobIgnoAlgo,
1044 algo, checkConform2, aCheckedMap, theErrors);
1045 aCheckedMap.insert( sm );
1054 //=======================================================================
1055 //function : checkMissing
1056 //purpose : notify on missing hypothesis
1057 // Return false if algo or hipothesis is missing
1058 //=======================================================================
1060 static bool checkMissing(SMESH_Gen* aGen,
1062 SMESH_subMesh* aSubMesh,
1063 const int aTopAlgoDim,
1064 bool* globalChecked,
1065 const bool checkNoAlgo,
1066 set<SMESH_subMesh*>& aCheckedMap,
1067 list< SMESH_Gen::TAlgoStateError > & theErrors)
1069 switch ( aSubMesh->GetSubShape().ShapeType() )
1073 case TopAbs_SOLID: break; // check this sub-mesh, it can be meshed
1075 return true; // not meshable sub-mesh
1077 if ( aCheckedMap.count( aSubMesh ))
1081 SMESH_Algo* algo = 0;
1083 switch (aSubMesh->GetAlgoState())
1085 case SMESH_subMesh::NO_ALGO: {
1088 // should there be any algo?
1089 int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
1090 if (aTopAlgoDim > shapeDim)
1092 MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
1094 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
1095 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
1100 case SMESH_subMesh::MISSING_HYP: {
1101 // notify if an algo missing hyp is attached to aSubMesh
1102 algo = aSubMesh->GetAlgo();
1104 bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
1105 if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
1107 TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
1108 SMESH_Hypothesis::Hypothesis_Status status;
1109 algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
1110 if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
1111 MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
1112 << "<" << algo->GetName() << "> has a bad parameter value");
1114 } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
1115 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
1116 << "<" << algo->GetName() << "> assigned to mismatching geometry");
1119 MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
1120 << "<" << algo->GetName() << "> misses some hypothesis");
1122 if (IsGlobalHypothesis)
1123 globalChecked[ algo->GetDim() ] = true;
1124 theErrors.push_back( SMESH_Gen::TAlgoStateError() );
1125 theErrors.back().Set( errName, algo, IsGlobalHypothesis );
1130 case SMESH_subMesh::HYP_OK:
1131 algo = aSubMesh->GetAlgo();
1133 if (!algo->NeedDiscreteBoundary())
1135 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
1136 /*complexShapeFirst=*/false);
1137 while ( itsub->more() )
1138 aCheckedMap.insert( itsub->next() );
1144 // do not check under algo that hides sub-algos or
1145 // re-start checking NO_ALGO state
1147 bool isTopLocalAlgo =
1148 ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
1149 if (!algo->NeedDiscreteBoundary() || isTopLocalAlgo)
1151 bool checkNoAlgo2 = ( algo->NeedDiscreteBoundary() );
1152 SMESH_subMeshIteratorPtr itsub = aSubMesh->getDependsOnIterator( /*includeSelf=*/false,
1153 /*complexShapeFirst=*/true);
1154 while ( itsub->more() )
1156 // sub-meshes should not be checked further more
1157 SMESH_subMesh* sm = itsub->next();
1161 //check algo on sub-meshes
1162 int aTopAlgoDim2 = algo->GetDim();
1163 if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
1164 globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
1167 if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
1168 checkNoAlgo2 = false;
1171 aCheckedMap.insert( sm );
1177 //=======================================================================
1178 //function : CheckAlgoState
1179 //purpose : notify on bad state of attached algos, return false
1180 // if Compute() would fail because of some algo bad state
1181 //=======================================================================
1183 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
1185 list< TAlgoStateError > errors;
1186 return GetAlgoState( aMesh, aShape, errors );
1189 //=======================================================================
1190 //function : GetAlgoState
1191 //purpose : notify on bad state of attached algos, return false
1192 // if Compute() would fail because of some algo bad state
1193 // theErrors list contains problems description
1194 //=======================================================================
1196 bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
1197 const TopoDS_Shape& theShape,
1198 list< TAlgoStateError > & theErrors)
1201 bool hasAlgo = false;
1203 SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
1204 const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
1205 TopoDS_Shape mainShape = meshDS->ShapeToMesh();
1207 // -----------------
1209 // -----------------
1211 const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
1213 const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
1214 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
1215 for ( ; it != listHyp.end(); it++)
1217 const SMESHDS_Hypothesis * aHyp = *it;
1218 if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
1221 const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
1224 int dim = algo->GetDim();
1225 aGlobAlgoArr[ dim ] = algo;
1230 // --------------------------------------------------------
1231 // info on algos that will be ignored because of ones that
1232 // don't NeedDiscreteBoundary() attached to super-shapes,
1233 // check that a conform mesh will be produced
1234 // --------------------------------------------------------
1237 // find a global algo possibly hiding sub-algos
1239 const SMESH_Algo* aGlobIgnoAlgo = 0;
1240 for (dim = 3; dim > 0; dim--)
1242 if (aGlobAlgoArr[ dim ] &&
1243 !aGlobAlgoArr[ dim ]->NeedDiscreteBoundary() /*&&
1244 !aGlobAlgoArr[ dim ]->SupportSubmeshes()*/ )
1246 aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
1251 set<SMESH_subMesh*> aCheckedSubs;
1252 bool checkConform = ( !theMesh.IsNotConformAllowed() );
1254 // loop on theShape and its sub-shapes
1255 SMESH_subMeshIteratorPtr revItSub = sm->getDependsOnIterator( /*includeSelf=*/true,
1256 /*complexShapeFirst=*/true);
1257 while ( revItSub->more() )
1259 SMESH_subMesh* smToCheck = revItSub->next();
1260 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
1263 if ( aCheckedSubs.insert( smToCheck ).second ) // not yet checked
1264 if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
1265 0, checkConform, aCheckedSubs, theErrors))
1268 if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
1272 // ----------------------------------------------------------------
1273 // info on missing hypothesis and find out if all needed algos are
1275 // ----------------------------------------------------------------
1277 // find max dim of global algo
1278 int aTopAlgoDim = 0;
1279 for (dim = 3; dim > 0; dim--)
1281 if (aGlobAlgoArr[ dim ])
1287 bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
1288 bool globalChecked[] = { false, false, false, false };
1290 // loop on theShape and its sub-shapes
1291 aCheckedSubs.clear();
1292 revItSub = sm->getDependsOnIterator( /*includeSelf=*/true, /*complexShapeFirst=*/true);
1293 while ( revItSub->more() )
1295 SMESH_subMesh* smToCheck = revItSub->next();
1296 if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
1299 if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
1300 globalChecked, checkNoAlgo, aCheckedSubs, theErrors))
1303 if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
1304 checkNoAlgo = false;
1310 theErrors.push_back( TAlgoStateError() );
1311 theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, theMesh.HasShapeToMesh() ? 1 : 3, true );
1317 //=======================================================================
1318 //function : IsGlobalHypothesis
1319 //purpose : check if theAlgo is attached to the main shape
1320 //=======================================================================
1322 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
1324 SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
1325 return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
1328 //================================================================================
1330 * \brief Return paths to xml files of plugins
1332 //================================================================================
1334 std::vector< std::string > SMESH_Gen::GetPluginXMLPaths()
1336 // Get paths to xml files of plugins
1337 vector< string > xmlPaths;
1339 if ( const char* meshersList = getenv("SMESH_MeshersList") )
1341 string meshers = meshersList, plugin;
1342 string::size_type from = 0, pos;
1343 while ( from < meshers.size() )
1345 // cut off plugin name
1346 pos = meshers.find( env_sep, from );
1347 if ( pos != string::npos )
1348 plugin = meshers.substr( from, pos-from );
1350 plugin = meshers.substr( from ), pos = meshers.size();
1353 // get PLUGIN_ROOT_DIR path
1354 string rootDirVar, pluginSubDir = plugin;
1355 if ( plugin == "StdMeshers" )
1356 rootDirVar = "SMESH", pluginSubDir = "smesh";
1358 for ( pos = 0; pos < plugin.size(); ++pos )
1359 rootDirVar += toupper( plugin[pos] );
1360 rootDirVar += "_ROOT_DIR";
1362 const char* rootDir = getenv( rootDirVar.c_str() );
1363 if ( !rootDir || strlen(rootDir) == 0 )
1365 rootDirVar = plugin + "_ROOT_DIR"; // HexoticPLUGIN_ROOT_DIR
1366 rootDir = getenv( rootDirVar.c_str() );
1367 if ( !rootDir || strlen(rootDir) == 0 ) continue;
1370 // get a separator from rootDir
1371 for ( int i = strlen( rootDir )-1; i >= 0 && sep.empty(); --i )
1372 if ( rootDir[i] == '/' || rootDir[i] == '\\' )
1378 if (sep.empty() ) sep = "\\";
1380 if (sep.empty() ) sep = "/";
1383 // get a path to resource file
1384 string xmlPath = rootDir;
1385 if ( xmlPath[ xmlPath.size()-1 ] != sep[0] )
1387 xmlPath += "share" + sep + "salome" + sep + "resources" + sep;
1388 for ( pos = 0; pos < pluginSubDir.size(); ++pos )
1389 xmlPath += tolower( pluginSubDir[pos] );
1390 xmlPath += sep + plugin + ".xml";
1394 const wchar_t* path = Kernel_Utils::decode_s(xmlPath);
1395 SMESHUtils::ArrayDeleter<const wchar_t> deleter( path );
1397 const char* path = xmlPath.c_str();
1399 fileOK = (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES);
1402 fileOK = (access(xmlPath.c_str(), F_OK) == 0);
1405 xmlPaths.push_back( xmlPath );
1412 //=============================================================================
1414 * Finds algo to mesh a shape. Optionally returns a shape the found algo is bound to
1416 //=============================================================================
1418 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh,
1419 const TopoDS_Shape & aShape,
1420 TopoDS_Shape* assignedTo)
1422 return GetAlgo( aMesh.GetSubMesh( aShape ), assignedTo );
1425 //=============================================================================
1427 * Finds algo to mesh a sub-mesh. Optionally returns a shape the found algo is bound to
1429 //=============================================================================
1431 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_subMesh * aSubMesh,
1432 TopoDS_Shape* assignedTo)
1434 if ( !aSubMesh ) return 0;
1436 const TopoDS_Shape & aShape = aSubMesh->GetSubShape();
1437 SMESH_Mesh& aMesh = *aSubMesh->GetFather();
1439 SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
1440 if ( aMesh.HasShapeToMesh() )
1441 filter.And( filter.IsApplicableTo( aShape ));
1443 typedef SMESH_Algo::Features AlgoData;
1445 TopoDS_Shape assignedToShape;
1447 (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape );
1450 aShape.ShapeType() == TopAbs_FACE &&
1451 !aShape.IsSame( assignedToShape ) &&
1452 SMESH_MesherHelper::NbAncestors( aShape, aMesh, TopAbs_SOLID ) > 1 )
1454 // Issue 0021559. If there is another 2D algo with different types of output
1455 // elements that can be used to mesh aShape, and 3D algos on adjacent SOLIDs
1456 // have different types of input elements, we choose a most appropriate 2D algo.
1458 // try to find a concurrent 2D algo
1459 filter.AndNot( filter.Is( algo ));
1460 TopoDS_Shape assignedToShape2;
1462 (SMESH_Algo*) aMesh.GetHypothesis( aSubMesh, filter, true, &assignedToShape2 );
1463 if ( algo2 && // algo found
1464 !assignedToShape2.IsSame( aMesh.GetShapeToMesh() ) && // algo is local
1465 ( SMESH_MesherHelper::GetGroupType( assignedToShape2 ) == // algo of the same level
1466 SMESH_MesherHelper::GetGroupType( assignedToShape )) &&
1467 aMesh.IsOrderOK( aMesh.GetSubMesh( assignedToShape2 ), // no forced order
1468 aMesh.GetSubMesh( assignedToShape )))
1470 // get algos on the adjacent SOLIDs
1471 filter.Init( filter.IsAlgo() ).And( filter.HasDim( 3 ));
1472 vector< SMESH_Algo* > algos3D;
1473 PShapeIteratorPtr solidIt = SMESH_MesherHelper::GetAncestors( aShape, aMesh,
1475 while ( const TopoDS_Shape* solid = solidIt->next() )
1476 if ( SMESH_Algo* algo3D = (SMESH_Algo*) aMesh.GetHypothesis( *solid, filter, true ))
1478 algos3D.push_back( algo3D );
1479 filter.AndNot( filter.HasName( algo3D->GetName() ));
1481 // check compatibility of algos
1482 if ( algos3D.size() > 1 )
1484 const AlgoData& algoData = algo->SMESH_Algo::GetFeatures();
1485 const AlgoData& algoData2 = algo2->SMESH_Algo::GetFeatures();
1486 const AlgoData& algoData3d0 = algos3D[0]->SMESH_Algo::GetFeatures();
1487 const AlgoData& algoData3d1 = algos3D[1]->SMESH_Algo::GetFeatures();
1488 if (( algoData2.IsCompatible( algoData3d0 ) &&
1489 algoData2.IsCompatible( algoData3d1 ))
1491 !(algoData.IsCompatible( algoData3d0 ) &&
1492 algoData.IsCompatible( algoData3d1 )))
1498 if ( assignedTo && algo )
1499 * assignedTo = assignedToShape;
1504 //=============================================================================
1506 * Returns StudyContextStruct for a study
1508 //=============================================================================
1510 StudyContextStruct *SMESH_Gen::GetStudyContext()
1512 return _studyContext;
1515 //================================================================================
1517 * \brief Return shape dimension by TopAbs_ShapeEnum
1519 //================================================================================
1521 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
1523 static vector<int> dim;
1526 dim.resize( TopAbs_SHAPE, -1 );
1527 dim[ TopAbs_COMPOUND ] = MeshDim_3D;
1528 dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
1529 dim[ TopAbs_SOLID ] = MeshDim_3D;
1530 dim[ TopAbs_SHELL ] = MeshDim_2D;
1531 dim[ TopAbs_FACE ] = MeshDim_2D;
1532 dim[ TopAbs_WIRE ] = MeshDim_1D;
1533 dim[ TopAbs_EDGE ] = MeshDim_1D;
1534 dim[ TopAbs_VERTEX ] = MeshDim_0D;
1536 return dim[ aShapeType ];
1539 //================================================================================
1541 * \brief Return shape dimension by exploding compounds
1543 //================================================================================
1545 int SMESH_Gen::GetFlatShapeDim(const TopoDS_Shape &aShape)
1548 if ( aShape.ShapeType() == TopAbs_COMPOUND ||
1549 aShape.ShapeType() == TopAbs_COMPSOLID )
1551 TopoDS_Iterator it( aShape );
1552 aShapeDim = GetFlatShapeDim( it.Value() );
1555 aShapeDim = GetShapeDim( aShape );
1559 //=============================================================================
1561 * Generate a new id unique within this Gen
1563 //=============================================================================
1565 int SMESH_Gen::GetANewId()