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 "SMESHDS_ListOfPtrHypothesis.hxx"
36 #include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
38 #include <GeomAdaptor_Curve.hxx>
39 #include <BRep_Tool.hxx>
40 #include <GCPnts_AbscissaPoint.hxx>
42 #include "utilities.h"
46 //=============================================================================
50 //=============================================================================
52 SMESH_Algo::SMESH_Algo(int hypId, int studyId, SMESH_Gen* gen)
53 : SMESH_Hypothesis(hypId, studyId, gen)
55 // _compatibleHypothesis.push_back("hypothese_bidon");
57 gen->_mapAlgo[hypId] = this;
60 //=============================================================================
64 //=============================================================================
66 SMESH_Algo::~SMESH_Algo()
70 //=============================================================================
74 //=============================================================================
76 const vector<string> & SMESH_Algo::GetCompatibleHypothesis()
78 return _compatibleHypothesis;
81 //=============================================================================
85 //=============================================================================
87 ostream & SMESH_Algo::SaveTo(ostream & save)
92 //=============================================================================
96 //=============================================================================
98 istream & SMESH_Algo::LoadFrom(istream & load)
100 return load >> (*this);
103 //=============================================================================
107 //=============================================================================
109 ostream& operator << (ostream & save, SMESH_Algo & hyp)
114 //=============================================================================
118 //=============================================================================
120 istream& operator >> (istream & load, SMESH_Algo & hyp)
125 //=============================================================================
129 //=============================================================================
131 bool SMESH_Algo::CheckHypothesis(SMESH_Mesh& aMesh,
132 const TopoDS_Shape& aShape)
134 MESSAGE("SMESH_Algo::CheckHypothesis");
135 ASSERT(0); // use method from derived classes
139 //=============================================================================
143 //=============================================================================
145 bool SMESH_Algo::Compute(SMESH_Mesh& aMesh,
146 const TopoDS_Shape& aShape)
148 MESSAGE("SMESH_Algo::Compute");
149 ASSERT(0); // use method from derived classes
153 //=============================================================================
155 * List the hypothesis used by the algorithm associated to the shape.
156 * Hypothesis associated to father shape -are- taken into account (see
157 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
158 * the algorithm. This method could be surcharged by specific algorithms, in
159 * case of several hypothesis simultaneously applicable.
161 //=============================================================================
163 const list<SMESHDS_Hypothesis*>&
164 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh& aMesh,
165 const TopoDS_Shape& aShape)
167 _usedHypList.clear();
168 _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
169 int nbHyp = _usedHypList.size();
172 TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
173 if (!mainShape.IsSame(aShape))
175 _usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy
176 nbHyp = _usedHypList.size();
179 if (nbHyp > 1) _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<SMESHDS_Hypothesis*>&
192 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh& aMesh,
193 const TopoDS_Shape& aShape)
195 const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
196 const SMESHDS_ListOfPtrHypothesis& listHyp = meshDS->GetHypothesis(aShape);
197 SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp);
202 _appliedHypList.clear();
205 SMESHDS_Hypothesis* anHyp = it.Value();
206 hypType = anHyp->GetType();
208 if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
210 hypName = anHyp->GetName();
211 vector<string>::iterator ith = find(_compatibleHypothesis.begin(),
212 _compatibleHypothesis.end(),
214 if (ith != _compatibleHypothesis.end()) // count only relevant
216 _appliedHypList.push_back(anHyp);
222 return _appliedHypList;
226 //=============================================================================
228 * Compute length of an edge
230 //=============================================================================
232 double SMESH_Algo::EdgeLength(const TopoDS_Edge& E)
234 double UMin = 0, UMax = 0;
236 if (BRep_Tool::Degenerated(E)) return 0;
237 Handle (Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
238 GeomAdaptor_Curve AdaptCurve(C);
239 GCPnts_AbscissaPoint gabs;
240 double length = gabs.Length(AdaptCurve, UMin, UMax);