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
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_Mesh.hxx"
34 #include <GeomAdaptor_Curve.hxx>
35 #include <BRep_Tool.hxx>
36 #include <GCPnts_AbscissaPoint.hxx>
38 #include "utilities.h"
41 #include <TopTools_ListOfShape.hxx>
42 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 //=============================================================================
48 //=============================================================================
50 SMESH_Algo::SMESH_Algo(int hypId, int studyId,
51 SMESH_Gen * gen):SMESH_Hypothesis(hypId, studyId, gen)
53 // _compatibleHypothesis.push_back("hypothese_bidon");
55 gen->_mapAlgo[hypId] = this;
57 _onlyUnaryInput = _requireDescretBoundary = true;
60 //=============================================================================
64 //=============================================================================
66 SMESH_Algo::~SMESH_Algo()
70 //=============================================================================
74 //=============================================================================
76 const vector < string > &SMESH_Algo::GetCompatibleHypothesis()
78 return _compatibleHypothesis;
81 //=============================================================================
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.
89 //=============================================================================
91 const list <const SMESHDS_Hypothesis *> & SMESH_Algo::GetUsedHypothesis(
92 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
95 _usedHypList = GetAppliedHypothesis(aMesh, aShape); // copy
96 int nbHyp = _usedHypList.size();
99 TopTools_ListIteratorOfListOfShape ancIt( aMesh.GetAncestors( aShape ));
100 for (; ancIt.More(); ancIt.Next())
102 const TopoDS_Shape& ancestor = ancIt.Value();
103 _usedHypList = GetAppliedHypothesis(aMesh, ancestor); // copy
104 nbHyp = _usedHypList.size();
108 // TopoDS_Shape mainShape = aMesh.GetMeshDS()->ShapeToMesh();
109 // if (!mainShape.IsSame(aShape))
111 // _usedHypList = GetAppliedHypothesis(aMesh, mainShape); // copy
112 // nbHyp = _usedHypList.size();
116 _usedHypList.clear(); //only one compatible hypothesis allowed
120 //=============================================================================
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)
126 //=============================================================================
128 const list<const SMESHDS_Hypothesis *> & SMESH_Algo::GetAppliedHypothesis(
129 SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
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();
138 _appliedHypList.clear();
139 while (it!=listHyp.end())
141 const SMESHDS_Hypothesis *anHyp = *it;
142 hypType = anHyp->GetType();
144 if (hypType == SMESHDS_Hypothesis::PARAM_ALGO)
146 hypName = anHyp->GetName();
147 vector < string >::iterator ith =
148 find(_compatibleHypothesis.begin(), _compatibleHypothesis.end(),
150 if (ith != _compatibleHypothesis.end()) // count only relevant
152 _appliedHypList.push_back(anHyp);
158 return _appliedHypList;
161 //=============================================================================
163 * Compute length of an edge
165 //=============================================================================
167 double SMESH_Algo::EdgeLength(const TopoDS_Edge & E)
169 double UMin = 0, UMax = 0;
171 if (BRep_Tool::Degenerated(E))
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);