1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_Algo.cxx
25 // Author : Paul RASCLE, EDF
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_HypoFilter.hxx"
35 #include <GeomAdaptor_Curve.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
39 #include "utilities.h"
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 //=============================================================================
49 //=============================================================================
51 SMESH_Algo::SMESH_Algo(int hypId, int studyId,
52 SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
54 // _compatibleHypothesis.push_back("hypothese_bidon");
56 gen->_mapAlgo[hypId] = this;
58 _onlyUnaryInput = _requireDescretBoundary = true;
61 //=============================================================================
65 //=============================================================================
67 SMESH_Algo::~SMESH_Algo()
71 //=============================================================================
75 //=============================================================================
77 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
79 return _compatibleHypothesis;
82 //=============================================================================
84 * List the hypothesis used by the algorithm associated to the shape.
85 * Hypothesis associated to father shape -are- taken into account (see
86 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
87 * the algorithm. This method could be surcharged by specific algorithms, in
88 * case of several hypothesis simultaneously applicable.
90 //=============================================================================
92 const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
93 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
96 if ( !_compatibleHypothesis.empty() )
98 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] ));
99 for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
100 filter.Or( filter.HasName( _compatibleHypothesis[ i ] ));
102 aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
103 if ( _usedHypList.size() > 1 )
104 _usedHypList.clear(); //only one compatible hypothesis allowed
109 //=============================================================================
111 * List the relevant hypothesis associated to the shape. Relevant hypothesis
112 * have a name (type) listed in the algorithm. Hypothesis associated to
113 * father shape -are not- taken into account (see GetUsedHypothesis)
115 //=============================================================================
117 const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
118 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
120 _appliedHypList.clear();
121 if ( !_compatibleHypothesis.empty() )
123 SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] ));
124 for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
125 filter.Or( filter.HasName( _compatibleHypothesis[ i ] ));
127 aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
129 return _appliedHypList;
132 //=============================================================================
134 * Compute length of an edge
136 //=============================================================================
138 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
140 double UMin = 0, UMax = 0;
142 if (BRep_Tool::Degenerated(E))
144 Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
145 GeomAdaptor_Curve AdaptCurve(C);
146 GCPnts_AbscissaPoint gabs;
147 double length = gabs.Length(AdaptCurve, UMin, UMax);