Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/smesh.git] / src / SMESH / SMESH_Algo.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_Algo.cxx
4 // Created   : sam mai 18 09:20:53 CEST 2002
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2002
8 // $Header$
9 //=============================================================================
10 using namespace std;
11
12 #include "SMESH_Algo.hxx"
13 #include "SMESH_Gen.hxx"
14 #include "SMESH_Mesh.hxx"
15
16 #include "SMESHDS_ListOfPtrHypothesis.hxx"
17 #include "SMESHDS_ListIteratorOfListOfPtrHypothesis.hxx"
18
19 #include <GeomAdaptor_Curve.hxx>
20 #include <BRep_Tool.hxx>
21 #include <GCPnts_AbscissaPoint.hxx>
22
23 #include "utilities.h"
24
25 #include <algorithm>
26
27 //=============================================================================
28 /*!
29  *  
30  */
31 //=============================================================================
32
33 SMESH_Algo::SMESH_Algo(int hypId, int studyId, SMESH_Gen* gen)
34   : SMESH_Hypothesis(hypId, studyId, gen)
35 {
36 //   _compatibleHypothesis.push_back("hypothese_bidon");
37   _type = ALGO;
38   gen->_mapAlgo[hypId] = this;
39 }
40
41 //=============================================================================
42 /*!
43  *  
44  */
45 //=============================================================================
46
47 SMESH_Algo::~SMESH_Algo()
48 {
49 }
50
51 //=============================================================================
52 /*!
53  *  
54  */
55 //=============================================================================
56
57 const vector<string> &  SMESH_Algo::GetCompatibleHypothesis()
58 {
59   return _compatibleHypothesis;
60 }
61
62 //=============================================================================
63 /*!
64  *  
65  */
66 //=============================================================================
67
68 ostream & SMESH_Algo::SaveTo(ostream & save)
69 {
70   return save << this;
71 }
72
73 //=============================================================================
74 /*!
75  *  
76  */
77 //=============================================================================
78
79 istream & SMESH_Algo::LoadFrom(istream & load)
80 {
81   return load >> (*this);
82 }
83
84 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 ostream& operator << (ostream & save, SMESH_Algo & hyp)
91 {
92   return save;
93 }
94
95 //=============================================================================
96 /*!
97  *  
98  */
99 //=============================================================================
100
101 istream& operator >> (istream & load, SMESH_Algo & hyp)
102 {
103   return load;
104 }
105
106 //=============================================================================
107 /*!
108  *  
109  */
110 //=============================================================================
111
112 bool SMESH_Algo::CheckHypothesis(SMESH_Mesh& aMesh,
113                                  const TopoDS_Shape& aShape)
114 {
115   MESSAGE("SMESH_Algo::CheckHypothesis");
116   ASSERT(0); // use method from derived classes
117   return false;
118 }
119
120 //=============================================================================
121 /*!
122  *  
123  */
124 //=============================================================================
125
126 bool SMESH_Algo::Compute(SMESH_Mesh& aMesh,
127                          const TopoDS_Shape& aShape)
128 {
129   MESSAGE("SMESH_Algo::Compute");
130   ASSERT(0); // use method from derived classes
131   return false;
132 }
133
134 //=============================================================================
135 /*!
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.
141  */
142 //=============================================================================
143
144 const list<SMESHDS_Hypothesis*>&
145 SMESH_Algo::GetUsedHypothesis(SMESH_Mesh& aMesh,
146                               const TopoDS_Shape& aShape)
147 {
148   _usedHypList.clear();
149   _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
150   int nbHyp = _usedHypList.size();
151   if (nbHyp == 0)
152     {
153       TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
154       if (!mainShape.IsSame(aShape))
155         {
156           _usedHypList  = GetAppliedHypothesis(aMesh, mainShape); // copy
157           nbHyp = _usedHypList.size();
158         }
159     }
160   if (nbHyp > 1) _usedHypList.clear(); //only one compatible hypothesis allowed
161   return _usedHypList;
162 }
163
164 //=============================================================================
165 /*!
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)
169  */
170 //=============================================================================
171
172 const list<SMESHDS_Hypothesis*>&
173 SMESH_Algo::GetAppliedHypothesis(SMESH_Mesh& aMesh,
174                                  const TopoDS_Shape& aShape)
175 {
176   const Handle(SMESHDS_Mesh)& meshDS = aMesh.GetMeshDS();
177   const SMESHDS_ListOfPtrHypothesis& listHyp = meshDS->GetHypothesis(aShape);
178   SMESHDS_ListIteratorOfListOfPtrHypothesis it(listHyp);
179
180   int hypType;
181   string hypName;
182
183   _appliedHypList.clear();
184   while (it.More())
185     {
186       SMESHDS_Hypothesis* anHyp = it.Value();
187       hypType = anHyp->GetType();
188       //SCRUTE(hypType);
189       if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
190         {
191           hypName = anHyp->GetName();
192           vector<string>::iterator ith = find(_compatibleHypothesis.begin(),
193                                               _compatibleHypothesis.end(),
194                                               hypName);
195           if (ith != _compatibleHypothesis.end()) // count only relevant 
196             {
197               _appliedHypList.push_back(anHyp);
198               //SCRUTE(hypName);
199             }
200         }
201       it.Next();
202     }
203   return _appliedHypList;
204 }
205
206
207 //=============================================================================
208 /*!
209  *  Compute length of an edge
210  */
211 //=============================================================================
212
213 double SMESH_Algo::EdgeLength(const TopoDS_Edge& E)
214 {
215   double UMin = 0, UMax = 0;
216   TopLoc_Location L;
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);
222   return length;
223 }
224