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_Algo.cxx
25 // Author : Paul RASCLE, EDF
28 #include "SMESH_Algo.hxx"
30 #include "SMDS_EdgePosition.hxx"
31 #include "SMDS_FacePosition.hxx"
32 #include "SMDS_MeshElement.hxx"
33 #include "SMDS_MeshNode.hxx"
34 #include "SMDS_VolumeTool.hxx"
35 #include "SMESHDS_Mesh.hxx"
36 #include "SMESHDS_SubMesh.hxx"
37 #include "SMESH_Comment.hxx"
38 #include "SMESH_Gen.hxx"
39 #include "SMESH_HypoFilter.hxx"
40 #include "SMESH_Mesh.hxx"
41 #include "SMESH_TypeDefs.hxx"
42 #include "SMESH_subMesh.hxx"
44 #include <Basics_OCCTVersion.hxx>
46 #include <BRepAdaptor_Curve.hxx>
47 #include <BRepLProp.hxx>
48 #include <BRep_Tool.hxx>
49 #include <GCPnts_AbscissaPoint.hxx>
50 #include <GeomAdaptor_Curve.hxx>
51 #include <Geom_Surface.hxx>
53 #include <TopExp_Explorer.hxx>
54 #include <TopLoc_Location.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56 #include <TopTools_ListOfShape.hxx>
58 #include <TopoDS_Edge.hxx>
59 #include <TopoDS_Face.hxx>
60 #include <TopoDS_Vertex.hxx>
61 #include <TopoDS_Wire.hxx>
63 #include <gp_Pnt2d.hxx>
66 #include <Standard_ErrorHandler.hxx>
67 #include <Standard_Failure.hxx>
69 #include "utilities.h"
76 //=============================================================================
80 //=============================================================================
82 SMESH_Algo::SMESH_Algo (int hypId, int studyId, SMESH_Gen * gen)
83 : SMESH_Hypothesis(hypId, studyId, gen)
85 gen->_mapAlgo[hypId] = this;
87 _onlyUnaryInput = _requireDiscreteBoundary = _requireShape = true;
88 _quadraticMesh = _supportSubmeshes = false;
92 //=============================================================================
96 //=============================================================================
98 SMESH_Algo::~SMESH_Algo()
102 //=============================================================================
106 //=============================================================================
108 SMESH_0D_Algo::SMESH_0D_Algo(int hypId, int studyId, SMESH_Gen* gen)
109 : SMESH_Algo(hypId, studyId, gen)
111 _shapeType = (1 << TopAbs_VERTEX);
113 gen->_map0D_Algo[hypId] = this;
115 SMESH_1D_Algo::SMESH_1D_Algo(int hypId, int studyId, SMESH_Gen* gen)
116 : SMESH_Algo(hypId, studyId, gen)
118 _shapeType = (1 << TopAbs_EDGE);
120 gen->_map1D_Algo[hypId] = this;
122 SMESH_2D_Algo::SMESH_2D_Algo(int hypId, int studyId, SMESH_Gen* gen)
123 : SMESH_Algo(hypId, studyId, gen)
125 _shapeType = (1 << TopAbs_FACE);
127 gen->_map2D_Algo[hypId] = this;
129 SMESH_3D_Algo::SMESH_3D_Algo(int hypId, int studyId, SMESH_Gen* gen)
130 : SMESH_Algo(hypId, studyId, gen)
132 _shapeType = (1 << TopAbs_SOLID);
134 gen->_map3D_Algo[hypId] = this;
137 //=============================================================================
139 * Usually an algoritm has nothing to save
141 //=============================================================================
143 ostream & SMESH_Algo::SaveTo(ostream & save) { return save; }
144 istream & SMESH_Algo::LoadFrom(istream & load) { return load; }
146 //=============================================================================
150 //=============================================================================
152 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
154 return _compatibleHypothesis;
157 //=============================================================================
159 * List the hypothesis used by the algorithm associated to the shape.
160 * Hypothesis associated to father shape -are- taken into account (see
161 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
162 * the algorithm. This method could be surcharged by specific algorithms, in
163 * case of several hypothesis simultaneously applicable.
165 //=============================================================================
167 const list <const SMESHDS_Hypothesis *> &
168 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh & aMesh,
169 const TopoDS_Shape & aShape,
170 const bool ignoreAuxiliary)
172 _usedHypList.clear();
173 SMESH_HypoFilter filter;
174 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
176 aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
177 if ( ignoreAuxiliary && _usedHypList.size() > 1 )
178 _usedHypList.clear(); //only one compatible hypothesis allowed
183 //=============================================================================
185 * List the relevant hypothesis associated to the shape. Relevant hypothesis
186 * have a name (type) listed in the algorithm. Hypothesis associated to
187 * father shape -are not- taken into account (see GetUsedHypothesis)
189 //=============================================================================
191 const list<const SMESHDS_Hypothesis *> &
192 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh & aMesh,
193 const TopoDS_Shape & aShape,
194 const bool ignoreAuxiliary)
196 _appliedHypList.clear();
197 SMESH_HypoFilter filter;
198 if ( InitCompatibleHypoFilter( filter, ignoreAuxiliary ))
199 aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
201 return _appliedHypList;
204 //=============================================================================
206 * Compute length of an edge
208 //=============================================================================
210 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
212 double UMin = 0, UMax = 0;
213 if (BRep_Tool::Degenerated(E))
216 Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
217 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax); //range is important for periodic curves
218 double length = GCPnts_AbscissaPoint::Length(AdaptCurve, UMin, UMax);
222 //================================================================================
224 * \brief Calculate normal of a mesh face
226 //================================================================================
228 bool SMESH_Algo::FaceNormal(const SMDS_MeshElement* F, gp_XYZ& normal, bool normalized)
230 if ( !F || F->GetType() != SMDSAbs_Face )
233 normal.SetCoord(0,0,0);
234 int nbNodes = F->IsQuadratic() ? F->NbNodes()/2 : F->NbNodes();
235 for ( int i = 0; i < nbNodes-2; ++i )
238 for ( int n = 0; n < 3; ++n )
240 const SMDS_MeshNode* node = F->GetNode( i + n );
241 p[n].SetCoord( node->X(), node->Y(), node->Z() );
243 normal += ( p[2] - p[1] ) ^ ( p[0] - p[1] );
245 double size2 = normal.SquareModulus();
246 bool ok = ( size2 > numeric_limits<double>::min() * numeric_limits<double>::min());
247 if ( normalized && ok )
248 normal /= sqrt( size2 );
253 //================================================================================
255 * \brief Find out elements orientation on a geometrical face
256 * \param theFace - The face correctly oriented in the shape being meshed
257 * \param theMeshDS - The mesh data structure
258 * \retval bool - true if the face normal and the normal of first element
259 * in the correspoding submesh point in different directions
261 //================================================================================
263 bool SMESH_Algo::IsReversedSubMesh (const TopoDS_Face& theFace,
264 SMESHDS_Mesh* theMeshDS)
266 if ( theFace.IsNull() || !theMeshDS )
269 // find out orientation of a meshed face
270 int faceID = theMeshDS->ShapeToIndex( theFace );
271 TopoDS_Shape aMeshedFace = theMeshDS->IndexToShape( faceID );
272 bool isReversed = ( theFace.Orientation() != aMeshedFace.Orientation() );
274 const SMESHDS_SubMesh * aSubMeshDSFace = theMeshDS->MeshElements( faceID );
275 if ( !aSubMeshDSFace )
278 // find element with node located on face and get its normal
279 const SMDS_FacePosition* facePos = 0;
283 bool normalOK = false;
284 SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
285 while ( iteratorElem->more() ) // loop on elements on theFace
287 const SMDS_MeshElement* elem = iteratorElem->next();
288 if ( elem && elem->NbNodes() > 2 ) {
289 SMDS_ElemIteratorPtr nodesIt = elem->nodesIterator();
290 const SMDS_FacePosition* fPos = 0;
292 while ( nodesIt->more() ) { // loop on nodes
293 const SMDS_MeshNode* node
294 = static_cast<const SMDS_MeshNode *>(nodesIt->next());
296 nPnt[ i++ ].SetCoord( node->X(), node->Y(), node->Z() );
298 const SMDS_PositionPtr& pos = node->GetPosition();
299 if ( !pos ) continue;
300 if ( pos->GetTypeOfPosition() == SMDS_TOP_FACE ) {
301 fPos = dynamic_cast< const SMDS_FacePosition* >( pos );
303 else if ( pos->GetTypeOfPosition() == SMDS_TOP_VERTEX ) {
304 vID = node->getshapeId();
307 if ( fPos || ( !normalOK && vID )) {
309 gp_Vec v01( nPnt[0], nPnt[1] ), v02( nPnt[0], nPnt[2] );
310 if ( v01.SquareMagnitude() > RealSmall() &&
311 v02.SquareMagnitude() > RealSmall() )
314 normalOK = ( Ne.SquareMagnitude() > RealSmall() );
316 // we need position on theFace or at least on vertex
319 if ((facePos = fPos))
328 // node position on face
331 u = facePos->GetUParameter();
332 v = facePos->GetVParameter();
334 else if ( vertexID ) {
335 TopoDS_Shape V = theMeshDS->IndexToShape( vertexID );
336 if ( V.IsNull() || V.ShapeType() != TopAbs_VERTEX )
338 gp_Pnt2d uv = BRep_Tool::Parameters( TopoDS::Vertex( V ), theFace );
347 // face normal at node position
349 Handle(Geom_Surface) surf = BRep_Tool::Surface( theFace, loc );
350 // if ( surf.IsNull() || surf->Continuity() < GeomAbs_C1 )
351 // some surfaces not detected as GeomAbs_C1 are nevertheless correct for meshing
352 if ( surf.IsNull() || surf->Continuity() < GeomAbs_C0 )
355 MESSAGE("surf->Continuity() < GeomAbs_C1 " << (surf->Continuity() < GeomAbs_C1));
359 surf->D1( u, v, nPnt[0], d1u, d1v );
360 gp_Vec Nf = (d1u ^ d1v).Transformed( loc );
362 if ( theFace.Orientation() == TopAbs_REVERSED )
368 //================================================================================
370 * \brief Just return false as the algorithm does not hold parameters values
372 //================================================================================
374 bool SMESH_Algo::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
375 const TopoDS_Shape& /*theShape*/)
379 bool SMESH_Algo::SetParametersByDefaults(const TDefaults& , const SMESH_Mesh*)
383 //================================================================================
385 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
386 * \param theMesh - The mesh containing nodes
387 * \param theEdge - The geometrical edge of interest
388 * \param theParams - The resulting vector of sorted node parameters
389 * \retval bool - false if not all parameters are OK
391 //================================================================================
393 bool SMESH_Algo::GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
394 const TopoDS_Edge& theEdge,
395 vector< double > & theParams)
399 if ( !theMesh || theEdge.IsNull() )
402 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
403 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
404 return false; // edge is not meshed
406 //int nbEdgeNodes = 0;
407 set < double > paramSet;
410 // loop on nodes of an edge: sort them by param on edge
411 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
412 while ( nIt->more() )
414 const SMDS_MeshNode* node = nIt->next();
415 const SMDS_PositionPtr& pos = node->GetPosition();
416 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
418 const SMDS_EdgePosition* epos =
419 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
420 if ( !paramSet.insert( epos->GetUParameter() ).second )
421 return false; // equal parameters
424 // add vertex nodes params
426 TopExp::Vertices( theEdge, V1, V2);
427 if ( VertexNode( V1, theMesh ) &&
428 !paramSet.insert( BRep_Tool::Parameter(V1,theEdge) ).second )
429 return false; // there are equal parameters
430 if ( VertexNode( V2, theMesh ) &&
431 !paramSet.insert( BRep_Tool::Parameter(V2,theEdge) ).second )
432 return false; // there are equal parameters
435 theParams.resize( paramSet.size() );
436 set < double >::iterator par = paramSet.begin();
437 vector< double >::iterator vecPar = theParams.begin();
438 for ( ; par != paramSet.end(); ++par, ++vecPar )
441 return theParams.size() > 1;
444 //================================================================================
446 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
447 * \param theMesh - The mesh containing nodes
448 * \param theEdge - The geometrical edge of interest
449 * \param theParams - The resulting vector of sorted node parameters
450 * \retval bool - false if not all parameters are OK
452 //================================================================================
454 bool SMESH_Algo::GetSortedNodesOnEdge(const SMESHDS_Mesh* theMesh,
455 const TopoDS_Edge& theEdge,
456 const bool ignoreMediumNodes,
457 map< double, const SMDS_MeshNode* > & theNodes)
461 if ( !theMesh || theEdge.IsNull() )
464 SMESHDS_SubMesh * eSubMesh = theMesh->MeshElements( theEdge );
465 if ( !eSubMesh || !eSubMesh->GetElements()->more() )
466 return false; // edge is not meshed
469 set < double > paramSet;
472 // loop on nodes of an edge: sort them by param on edge
473 SMDS_NodeIteratorPtr nIt = eSubMesh->GetNodes();
474 while ( nIt->more() )
476 const SMDS_MeshNode* node = nIt->next();
477 if ( ignoreMediumNodes ) {
478 SMDS_ElemIteratorPtr elemIt = node->GetInverseElementIterator();
479 if ( elemIt->more() && elemIt->next()->IsMediumNode( node ))
482 const SMDS_PositionPtr& pos = node->GetPosition();
483 if ( pos->GetTypeOfPosition() != SMDS_TOP_EDGE )
485 const SMDS_EdgePosition* epos =
486 static_cast<const SMDS_EdgePosition*>(node->GetPosition());
487 theNodes.insert( theNodes.end(), make_pair( epos->GetUParameter(), node ));
488 //MESSAGE("U " << epos->GetUParameter() << " ID " << node->GetID());
493 TopoDS_Vertex v1, v2;
494 TopExp::Vertices(theEdge, v1, v2);
495 const SMDS_MeshNode* n1 = VertexNode( v1, (SMESHDS_Mesh*) theMesh );
496 const SMDS_MeshNode* n2 = VertexNode( v2, (SMESHDS_Mesh*) theMesh );
497 //MESSAGE("Vertices ID " << n1->GetID() << " " << n2->GetID());
499 BRep_Tool::Range(theEdge, f, l);
500 if ( v1.Orientation() != TopAbs_FORWARD )
502 if ( n1 && ++nbNodes )
503 theNodes.insert( make_pair( f, n1 ));
504 if ( n2 && ++nbNodes )
505 theNodes.insert( make_pair( l, n2 ));
507 return theNodes.size() == nbNodes;
510 //================================================================================
512 * \brief Make filter recognize only compatible hypotheses
513 * \param theFilter - the filter to initialize
514 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
516 //================================================================================
518 bool SMESH_Algo::InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
519 const bool ignoreAuxiliary) const
521 if ( !_compatibleHypothesis.empty() )
523 theFilter.Init( theFilter.HasName( _compatibleHypothesis[0] ));
524 for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
525 theFilter.Or( theFilter.HasName( _compatibleHypothesis[ i ] ));
527 if ( ignoreAuxiliary )
528 theFilter.AndNot( theFilter.IsAuxiliary() );
535 //================================================================================
537 * \brief Return continuity of two edges
538 * \param E1 - the 1st edge
539 * \param E2 - the 2nd edge
540 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
542 //================================================================================
544 GeomAbs_Shape SMESH_Algo::Continuity(TopoDS_Edge E1,
547 //E1.Orientation(TopAbs_FORWARD), E2.Orientation(TopAbs_FORWARD); // avoid pb with internal edges
548 if (E1.Orientation() > TopAbs_REVERSED) // INTERNAL
549 E1.Orientation( TopAbs_FORWARD );
550 if (E2.Orientation() > TopAbs_REVERSED) // INTERNAL
551 E2.Orientation( TopAbs_FORWARD );
553 TopoDS_Vertex V, VV1[2], VV2[2];
554 TopExp::Vertices( E1, VV1[0], VV1[1], true );
555 TopExp::Vertices( E2, VV2[0], VV2[1], true );
556 if ( VV1[1].IsSame( VV2[0] )) { V = VV1[1]; }
557 else if ( VV1[0].IsSame( VV2[1] )) { V = VV1[0]; }
558 else if ( VV1[1].IsSame( VV2[1] )) { V = VV1[1]; E1.Reverse(); }
559 else if ( VV1[0].IsSame( VV2[0] )) { V = VV1[0]; E1.Reverse(); }
560 else { return GeomAbs_C0; }
562 Standard_Real u1 = BRep_Tool::Parameter( V, E1 );
563 Standard_Real u2 = BRep_Tool::Parameter( V, E2 );
564 BRepAdaptor_Curve C1( E1 ), C2( E2 );
565 Standard_Real tol = BRep_Tool::Tolerance( V );
566 Standard_Real angTol = 2e-3;
568 #if OCC_VERSION_LARGE > 0x06010000
571 return BRepLProp::Continuity(C1, C2, u1, u2, tol, angTol);
573 catch (Standard_Failure) {
578 //================================================================================
580 * \brief Return the node built on a vertex
581 * \param V - the vertex
582 * \param meshDS - mesh
583 * \retval const SMDS_MeshNode* - found node or NULL
585 //================================================================================
587 const SMDS_MeshNode* SMESH_Algo::VertexNode(const TopoDS_Vertex& V,
588 const SMESHDS_Mesh* meshDS)
590 if ( SMESHDS_SubMesh* sm = meshDS->MeshElements(V) ) {
591 SMDS_NodeIteratorPtr nIt= sm->GetNodes();
598 //=======================================================================
599 //function : GetCommonNodes
600 //purpose : Return nodes common to two elements
601 //=======================================================================
603 vector< const SMDS_MeshNode*> SMESH_Algo::GetCommonNodes(const SMDS_MeshElement* e1,
604 const SMDS_MeshElement* e2)
606 vector< const SMDS_MeshNode*> common;
607 for ( int i = 0 ; i < e1->NbNodes(); ++i )
608 if ( e2->GetNodeIndex( e1->GetNode( i )) >= 0 )
609 common.push_back( e1->GetNode( i ));
613 //=======================================================================
614 //function : GetMeshError
615 //purpose : Finds topological errors of a sub-mesh
616 //WARNING : 1D check is NOT implemented so far
617 //=======================================================================
619 SMESH_Algo::EMeshError SMESH_Algo::GetMeshError(SMESH_subMesh* subMesh)
621 EMeshError err = MEr_OK;
623 SMESHDS_SubMesh* smDS = subMesh->GetSubMeshDS();
627 switch ( subMesh->GetSubShape().ShapeType() )
629 case TopAbs_FACE: { // ====================== 2D =====================
631 SMDS_ElemIteratorPtr fIt = smDS->GetElements();
635 // We check that olny links on EDGEs encouter once, the rest links, twice
636 set< SMESH_TLink > links;
637 while ( fIt->more() )
639 const SMDS_MeshElement* f = fIt->next();
640 int nbNodes = f->NbCornerNodes(); // ignore medium nodes
641 for ( int i = 0; i < nbNodes; ++i )
643 const SMDS_MeshNode* n1 = f->GetNode( i );
644 const SMDS_MeshNode* n2 = f->GetNode(( i+1 ) % nbNodes);
645 std::pair< set< SMESH_TLink >::iterator, bool > it_added =
646 links.insert( SMESH_TLink( n1, n2 ));
647 if ( !it_added.second )
648 // As we do NOT(!) check if mesh is manifold, we believe that a link can
649 // encounter once or twice only (not three times), we erase a link as soon
650 // as it encounters twice to speed up search in the <links> map.
651 links.erase( it_added.first );
654 // the links remaining in the <links> should all be on EDGE
655 set< SMESH_TLink >::iterator linkIt = links.begin();
656 for ( ; linkIt != links.end(); ++linkIt )
658 const SMESH_TLink& link = *linkIt;
659 if ( link.node1()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE ||
660 link.node2()->GetPosition()->GetTypeOfPosition() > SMDS_TOP_EDGE )
663 // TODO: to check orientation
666 case TopAbs_SOLID: { // ====================== 3D =====================
668 SMDS_ElemIteratorPtr vIt = smDS->GetElements();
672 SMDS_VolumeTool vTool;
673 while ( !vIt->more() )
675 if (!vTool.Set( vIt->next() ))
678 for ( int iF = 0; iF < vTool.NbFaces(); ++iF )
679 if ( vTool.IsFreeFace( iF ))
681 int nbN = vTool.NbFaceNodes( iF );
682 const SMDS_MeshNode** nodes = vTool.GetFaceNodes( iF );
683 for ( int i = 0; i < nbN; ++i )
684 if ( nodes[i]->GetPosition()->GetTypeOfPosition() > SMDS_TOP_FACE )
695 //================================================================================
697 * \brief Sets event listener to submeshes if necessary
698 * \param subMesh - submesh where algo is set
700 * After being set, event listener is notified on each event of a submesh.
701 * By default non listener is set
703 //================================================================================
705 void SMESH_Algo::SetEventListener(SMESH_subMesh* /*subMesh*/)
709 //================================================================================
711 * \brief Allow algo to do something after persistent restoration
712 * \param subMesh - restored submesh
714 * This method is called only if a submesh has HYP_OK algo_state.
716 //================================================================================
718 void SMESH_Algo::SubmeshRestored(SMESH_subMesh* /*subMesh*/)
722 //================================================================================
724 * \brief Computes mesh without geometry
725 * \param aMesh - the mesh
726 * \param aHelper - helper that must be used for adding elements to \aaMesh
727 * \retval bool - is a success
729 //================================================================================
731 bool SMESH_Algo::Compute(SMESH_Mesh & /*aMesh*/, SMESH_MesherHelper* /*aHelper*/)
733 return error( COMPERR_BAD_INPUT_MESH, "Mesh built on shape expected");
736 //=======================================================================
737 //function : CancelCompute
738 //purpose : Sets _computeCanceled to true. It's usage depends on
739 // * implementation of a particular mesher.
740 //=======================================================================
742 void SMESH_Algo::CancelCompute()
744 _computeCanceled = true;
745 _error = COMPERR_CANCELED;
748 //================================================================================
750 * \brief store error and comment and then return ( error == COMPERR_OK )
752 //================================================================================
754 bool SMESH_Algo::error(int error, const SMESH_Comment& comment)
758 return ( error == COMPERR_OK );
761 //================================================================================
763 * \brief store error and return ( error == COMPERR_OK )
765 //================================================================================
767 bool SMESH_Algo::error(SMESH_ComputeErrorPtr error)
770 _error = error->myName;
771 _comment = error->myComment;
772 _badInputElements = error->myBadElements;
773 return error->IsOK();
778 //================================================================================
780 * \brief return compute error
782 //================================================================================
784 SMESH_ComputeErrorPtr SMESH_Algo::GetComputeError() const
786 SMESH_ComputeErrorPtr err = SMESH_ComputeError::New( _error, _comment, this );
787 // hope this method is called by only SMESH_subMesh after this->Compute()
788 err->myBadElements.splice( err->myBadElements.end(),
789 (list<const SMDS_MeshElement*>&) _badInputElements );
793 //================================================================================
795 * \brief initialize compute error
797 //================================================================================
799 void SMESH_Algo::InitComputeError()
803 list<const SMDS_MeshElement*>::iterator elem = _badInputElements.begin();
804 for ( ; elem != _badInputElements.end(); ++elem )
805 if ( (*elem)->GetID() < 1 )
807 _badInputElements.clear();
809 _computeCanceled = false;
812 //================================================================================
814 * \brief store a bad input element preventing computation,
815 * which may be a temporary one i.e. not residing the mesh,
816 * then it will be deleted by InitComputeError()
818 //================================================================================
820 void SMESH_Algo::addBadInputElement(const SMDS_MeshElement* elem)
823 _badInputElements.push_back( elem );
826 //=============================================================================
830 //=============================================================================
832 int SMESH_Algo::NumberOfWires(const TopoDS_Shape& S)
835 for (TopExp_Explorer exp(S,TopAbs_WIRE); exp.More(); exp.Next())
840 //=============================================================================
844 //=============================================================================
846 int SMESH_Algo::NumberOfPoints(SMESH_Mesh& aMesh, const TopoDS_Wire& W)
849 for (TopExp_Explorer exp(W,TopAbs_EDGE); exp.More(); exp.Next()) {
850 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
851 int nb = aMesh.GetSubMesh(E)->GetSubMeshDS()->NbNodes();
854 nbPoints += nb + 1; // internal points plus 1 vertex of 2 (last point ?)