Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/smesh.git] / src / SMESH / SMESH_Algo.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_Algo.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 using namespace std;
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Mesh.hxx"
33
34 #include <GeomAdaptor_Curve.hxx>
35 #include <BRep_Tool.hxx>
36 #include <GCPnts_AbscissaPoint.hxx>
37
38 #include "utilities.h"
39
40 #include <algorithm>
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
43
44 //=============================================================================
45 /*!
46  *  
47  */
48 //=============================================================================
49
50 SMESH_Algo::SMESH_Algo(int hypId, int studyId,
51         SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
52 {
53 //   _compatibleHypothesis.push_back("hypothese_bidon");
54         _type = ALGO;
55         gen->_mapAlgo[hypId] = this;
56
57         _onlyUnaryInput = _requireDescretBoundary = true;
58 }
59
60 //=============================================================================
61 /*!
62  *  
63  */
64 //=============================================================================
65
66 SMESH_Algo::~SMESH_Algo()
67 {
68 }
69
70 //=============================================================================
71 /*!
72  *  
73  */
74 //=============================================================================
75
76 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
77 {
78         return _compatibleHypothesis;
79 }
80
81 //=============================================================================
82 /*!
83  *  List the hypothesis used by the algorithm associated to the shape.
84  *  Hypothesis associated to father shape -are- taken into account (see
85  *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
86  *  the algorithm. This method could be surcharged by specific algorithms, in 
87  *  case of several hypothesis simultaneously applicable.
88  */
89 //=============================================================================
90
91 const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
92         SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
93 {
94         _usedHypList.clear();
95         _usedHypList = GetAppliedHypothesis(aMesh, aShape);     // copy
96         int nbHyp = _usedHypList.size();
97         if (nbHyp == 0)
98         {
99           TopTools_ListIteratorOfListOfShape ancIt( aMesh.GetAncestors( aShape ));
100           for (; ancIt.More(); ancIt.Next())
101           {
102             const TopoDS_Shape& ancestor = ancIt.Value();
103             _usedHypList = GetAppliedHypothesis(aMesh, ancestor);       // copy
104             nbHyp = _usedHypList.size();
105             if (nbHyp == 1)
106               break;
107           }
108 //              TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
109 //              if (!mainShape.IsSame(aShape))
110 //              {
111 //                      _usedHypList = GetAppliedHypothesis(aMesh, mainShape);  // copy
112 //                      nbHyp = _usedHypList.size();
113 //              }
114         }
115         if (nbHyp > 1)
116                 _usedHypList.clear();   //only one compatible hypothesis allowed
117         return _usedHypList;
118 }
119
120 //=============================================================================
121 /*!
122  *  List the relevant hypothesis associated to the shape. Relevant hypothesis
123  *  have a name (type) listed in the algorithm. Hypothesis associated to
124  *  father shape -are not- taken into account (see GetUsedHypothesis)
125  */
126 //=============================================================================
127
128 const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
129         SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
130 {
131         const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
132         const list<const SMESHDS_Hypothesis*> & listHyp = meshDS->GetHypothesis(aShape);
133         list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
134
135         int hypType;
136         string hypName;
137
138         _appliedHypList.clear();
139         while (it!=listHyp.end())
140         {
141                 const SMESHDS_Hypothesis *anHyp = *it;
142                 hypType = anHyp->GetType();
143                 //SCRUTE(hypType);
144                 if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
145                 {
146                         hypName = anHyp->GetName();
147                         vector < string >::iterator ith =
148                                 find(_compatibleHypothesis.begin(), _compatibleHypothesis.end(),
149                                 hypName);
150                         if (ith != _compatibleHypothesis.end()) // count only relevant 
151                         {
152                                 _appliedHypList.push_back(anHyp);
153                                 //SCRUTE(hypName);
154                         }
155                 }
156                 it++;
157         }
158         return _appliedHypList;
159 }
160
161 //=============================================================================
162 /*!
163  *  Compute length of an edge
164  */
165 //=============================================================================
166
167 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
168 {
169         double UMin = 0, UMax = 0;
170         TopLoc_Location L;
171         if (BRep_Tool::Degenerated(E))
172                 return 0;
173         Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
174         GeomAdaptor_Curve AdaptCurve(C);
175         GCPnts_AbscissaPoint gabs;
176         double length = gabs.Length(AdaptCurve, UMin, UMax);
177         return length;
178 }