2 //=============================================================================
3 // File : SMESH_Algo.cxx
4 // Created : sam mai 18 09:20:53 CEST 2002
5 // Author : Paul RASCLE, EDF
7 // Copyright : EDF 2002
9 //=============================================================================
12 #include "SMESH_Algo.hxx"
13 #include "SMESH_Gen.hxx"
14 #include "SMESH_Mesh.hxx"
16 #include "SMESHDS_ListOfPtrHypothesis.hxx"
17 #include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
19 #include <GeomAdaptor_Curve.hxx>
20 #include <BRep_Tool.hxx>
21 #include <GCPnts_AbscissaPoint.hxx>
23 #include "utilities.h"
27 //=============================================================================
31 //=============================================================================
33 SMESH_Algo::SMESH_Algo(int hypId, int studyId, SMESH_Gen* gen)
34 : SMESH_Hypothesis(hypId, studyId, gen)
36 // _compatibleHypothesis.push_back("hypothese_bidon");
38 gen->_mapAlgo[hypId] = this;
41 //=============================================================================
45 //=============================================================================
47 SMESH_Algo::~SMESH_Algo()
51 //=============================================================================
55 //=============================================================================
57 const vector<string> & SMESH_Algo::GetCompatibleHypothesis()
59 return _compatibleHypothesis;
62 //=============================================================================
66 //=============================================================================
68 ostream & SMESH_Algo::SaveTo(ostream & save)
73 //=============================================================================
77 //=============================================================================
79 istream & SMESH_Algo::LoadFrom(istream & load)
81 return load >> (*this);
84 //=============================================================================
88 //=============================================================================
90 ostream& operator << (ostream & save, SMESH_Algo & hyp)
95 //=============================================================================
99 //=============================================================================
101 istream& operator >> (istream & load, SMESH_Algo & hyp)
106 //=============================================================================
110 //=============================================================================
112 bool SMESH_Algo::CheckHypothesis(SMESH_Mesh& aMesh,
113 const TopoDS_Shape& aShape)
115 MESSAGE("SMESH_Algo::CheckHypothesis");
116 ASSERT(0); // use method from derived classes
120 //=============================================================================
124 //=============================================================================
126 bool SMESH_Algo::Compute(SMESH_Mesh& aMesh,
127 const TopoDS_Shape& aShape)
129 MESSAGE("SMESH_Algo::Compute");
130 ASSERT(0); // use method from derived classes
134 //=============================================================================
136 * List the hypothesis used by the algorithm associated to the shape.
137 * Hypothesis associated to father shape -are- taken into account (see
138 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
139 * the algorithm. This method could be surcharged by specific algorithms, in
140 * case of several hypothesis simultaneously applicable.
142 //=============================================================================
144 const list<SMESHDS_Hypothesis*>&
145 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh& aMesh,
146 const TopoDS_Shape& aShape)
148 _usedHypList.clear();
149 _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
150 int nbHyp = _usedHypList.size();
153 TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
154 if (!mainShape.IsSame(aShape))
156 _usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy
157 nbHyp = _usedHypList.size();
160 if (nbHyp > 1) _usedHypList.clear(); //only one compatible hypothesis allowed
164 //=============================================================================
166 * List the relevant hypothesis associated to the shape. Relevant hypothesis
167 * have a name (type) listed in the algorithm. Hypothesis associated to
168 * father shape -are not- taken into account (see GetUsedHypothesis)
170 //=============================================================================
172 const list<SMESHDS_Hypothesis*>&
173 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh& aMesh,
174 const TopoDS_Shape& aShape)
176 const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
177 const SMESHDS_ListOfPtrHypothesis& listHyp = meshDS->GetHypothesis(aShape);
178 SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp);
183 _appliedHypList.clear();
186 SMESHDS_Hypothesis* anHyp = it.Value();
187 hypType = anHyp->GetType();
189 if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
191 hypName = anHyp->GetName();
192 vector<string>::iterator ith = find(_compatibleHypothesis.begin(),
193 _compatibleHypothesis.end(),
195 if (ith != _compatibleHypothesis.end()) // count only relevant
197 _appliedHypList.push_back(anHyp);
203 return _appliedHypList;
207 //=============================================================================
209 * Compute length of an edge
211 //=============================================================================
213 double SMESH_Algo::EdgeLength(const TopoDS_Edge& E)
215 double UMin = 0, UMax = 0;
217 if (BRep_Tool::Degenerated(E)) return 0;
218 Handle (Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
219 GeomAdaptor_Curve AdaptCurve(C);
220 GCPnts_AbscissaPoint gabs;
221 double length = gabs.Length(AdaptCurve, UMin, UMax);