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
31 #include "SMESH_Algo.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_Mesh.hxx"
35 #include <GeomAdaptor_Curve.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
39 #include "utilities.h"
43 //=============================================================================
47 //=============================================================================
49 SMESH_Algo::SMESH_Algo(int hypId, int studyId,
50 SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
52 // _compatibleHypothesis.push_back("hypothese_bidon");
54 gen->_mapAlgo[hypId] = this;
57 //=============================================================================
61 //=============================================================================
63 SMESH_Algo::~SMESH_Algo()
67 //=============================================================================
71 //=============================================================================
73 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
75 return _compatibleHypothesis;
78 //=============================================================================
82 //=============================================================================
84 ostream & SMESH_Algo::SaveTo(ostream & save)
89 //=============================================================================
93 //=============================================================================
95 istream & SMESH_Algo::LoadFrom(istream & load)
97 return load >> (*this);
100 //=============================================================================
104 //=============================================================================
106 ostream & operator <<(ostream & save, SMESH_Algo & hyp)
111 //=============================================================================
115 //=============================================================================
117 istream & operator >>(istream & load, SMESH_Algo & hyp)
122 //=============================================================================
126 //=============================================================================
128 bool SMESH_Algo::CheckHypothesis(SMESH_Mesh & aMesh,
129 const TopoDS_Shape & aShape)
131 MESSAGE("SMESH_Algo::CheckHypothesis");
132 ASSERT(0); // use method from derived classes
136 //=============================================================================
140 //=============================================================================
142 bool SMESH_Algo::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
144 MESSAGE("SMESH_Algo::Compute");
145 ASSERT(0); // use method from derived classes
149 //=============================================================================
151 * List the hypothesis used by the algorithm associated to the shape.
152 * Hypothesis associated to father shape -are- taken into account (see
153 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
154 * the algorithm. This method could be surcharged by specific algorithms, in
155 * case of several hypothesis simultaneously applicable.
157 //=============================================================================
159 const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
160 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
162 _usedHypList.clear();
163 _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
164 int nbHyp = _usedHypList.size();
167 TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
168 if (!mainShape.IsSame(aShape))
170 _usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy
171 nbHyp = _usedHypList.size();
175 _usedHypList.clear(); //only one compatible hypothesis allowed
179 //=============================================================================
181 * List the relevant hypothesis associated to the shape. Relevant hypothesis
182 * have a name (type) listed in the algorithm. Hypothesis associated to
183 * father shape -are not- taken into account (see GetUsedHypothesis)
185 //=============================================================================
187 const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
188 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
190 const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
191 const list<const SMESHDS_Hypothesis*> & listHyp = meshDS->GetHypothesis(aShape);
192 list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
197 _appliedHypList.clear();
198 while (it!=listHyp.end())
200 const SMESHDS_Hypothesis *anHyp = *it;
201 hypType = anHyp->GetType();
203 if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
205 hypName = anHyp->GetName();
206 vector < string >::iterator ith =
207 find(_compatibleHypothesis.begin(), _compatibleHypothesis.end(),
209 if (ith != _compatibleHypothesis.end()) // count only relevant
211 _appliedHypList.push_back(anHyp);
217 return _appliedHypList;
220 //=============================================================================
222 * Compute length of an edge
224 //=============================================================================
226 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
228 double UMin = 0, UMax = 0;
230 if (BRep_Tool::Degenerated(E))
232 Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
233 GeomAdaptor_Curve AdaptCurve(C);
234 GCPnts_AbscissaPoint gabs;
235 double length = gabs.Length(AdaptCurve, UMin, UMax);