Salome HOME
Integration some new classes for working of core mesher
[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 #include "SMESH_HypoFilter.hxx"
34
35 #include <GeomAdaptor_Curve.hxx>
36 #include <BRep_Tool.hxx>
37 #include <GCPnts_AbscissaPoint.hxx>
38
39 #include "utilities.h"
40
41 #include <algorithm>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44
45 //=============================================================================
46 /*!
47  *  
48  */
49 //=============================================================================
50
51 SMESH_Algo::SMESH_Algo(int hypId, int studyId,
52         SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
53 {
54 //   _compatibleHypothesis.push_back("hypothese_bidon");
55         _type = ALGO;
56         gen->_mapAlgo[hypId] = this;
57
58         _onlyUnaryInput = _requireDescretBoundary = true;
59 }
60
61 //=============================================================================
62 /*!
63  *  
64  */
65 //=============================================================================
66
67 SMESH_Algo::~SMESH_Algo()
68 {
69 }
70
71 //=============================================================================
72 /*!
73  *  
74  */
75 //=============================================================================
76
77 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
78 {
79         return _compatibleHypothesis;
80 }
81
82 //=============================================================================
83 /*!
84  *  List the hypothesis used by the algorithm associated to the shape.
85  *  Hypothesis associated to father shape -are- taken into account (see
86  *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
87  *  the algorithm. This method could be surcharged by specific algorithms, in 
88  *  case of several hypothesis simultaneously applicable.
89  */
90 //=============================================================================
91
92 const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
93         SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
94 {
95   _usedHypList.clear();
96   if ( !_compatibleHypothesis.empty() )
97   {
98     SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] ));
99     for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
100       filter.Or( filter.HasName( _compatibleHypothesis[ i ] ));
101
102     aMesh.GetHypotheses( aShape, filter, _usedHypList, true );
103     if ( _usedHypList.size() > 1 )
104       _usedHypList.clear();     //only one compatible hypothesis allowed
105   }
106   return _usedHypList;
107 }
108
109 //=============================================================================
110 /*!
111  *  List the relevant hypothesis associated to the shape. Relevant hypothesis
112  *  have a name (type) listed in the algorithm. Hypothesis associated to
113  *  father shape -are not- taken into account (see GetUsedHypothesis)
114  */
115 //=============================================================================
116
117 const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
118         SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
119 {
120   _appliedHypList.clear();
121   if ( !_compatibleHypothesis.empty() )
122   {
123     SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( _compatibleHypothesis[0] ));
124     for ( int i = 1; i < _compatibleHypothesis.size(); ++i )
125       filter.Or( filter.HasName( _compatibleHypothesis[ i ] ));
126     
127     aMesh.GetHypotheses( aShape, filter, _appliedHypList, false );
128   }
129   return _appliedHypList;
130 }
131
132 //=============================================================================
133 /*!
134  *  Compute length of an edge
135  */
136 //=============================================================================
137
138 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
139 {
140         double UMin = 0, UMax = 0;
141         TopLoc_Location L;
142         if (BRep_Tool::Degenerated(E))
143                 return 0;
144         Handle(Geom_Curve) C = BRep_Tool::Curve(E, L, UMin, UMax);
145         GeomAdaptor_Curve AdaptCurve(C);
146         GCPnts_AbscissaPoint gabs;
147         double length = gabs.Length(AdaptCurve, UMin, UMax);
148         return length;
149 }