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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : StdMeshers_MaxLength.cxx
25 #include "StdMeshers_MaxLength.hxx"
27 #include "SMESH_Mesh.hxx"
28 #include "SMESH_Algo.hxx"
30 #include "utilities.h"
32 #include <BRep_Tool.hxx>
33 #include <GCPnts_AbscissaPoint.hxx>
34 #include <GeomAdaptor_Curve.hxx>
35 #include <Geom_Curve.hxx>
37 #include <TopLoc_Location.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <Precision.hxx>
45 //=============================================================================
49 //=============================================================================
51 StdMeshers_MaxLength::StdMeshers_MaxLength(int hypId, int studyId, SMESH_Gen * gen)
52 :SMESH_Hypothesis(hypId, studyId, gen)
56 _preestimation = false;
58 _param_algo_dim = 1; // is used by SMESH_Regular_1D
61 //=============================================================================
65 //=============================================================================
67 StdMeshers_MaxLength::~StdMeshers_MaxLength()
71 //=============================================================================
75 //=============================================================================
77 void StdMeshers_MaxLength::SetLength(double length) throw(SALOME_Exception)
80 throw SALOME_Exception(LOCALIZED("length must be positive"));
81 if ( _length != length ) {
83 NotifySubMeshesHypothesisModification();
87 //=============================================================================
91 //=============================================================================
93 double StdMeshers_MaxLength::GetLength() const
95 return ( _preestimation && _preestimated > 0. ) ? _preestimated : _length;
98 //================================================================================
100 * \brief Sets boolean parameter enabling/desabling usage of length computed
101 * basing on size of bounding box of shape to mesh
103 //================================================================================
105 void StdMeshers_MaxLength::SetUsePreestimatedLength(bool toUse)
107 if ( toUse != _preestimation )
109 _preestimation = toUse;
110 // this parameter is just to help the user
111 //NotifySubMeshesHypothesisModification();
115 //================================================================================
117 * \brief Store preestemated length
119 //================================================================================
121 void StdMeshers_MaxLength::SetPreestimatedLength(double length)
124 _preestimated = length;
127 //================================================================================
129 * \brief Returns value of boolean parameter enabling/desabling usage of length computed
130 * basing on size of bounding box of shape to mesh
132 //================================================================================
134 bool StdMeshers_MaxLength::GetUsePreestimatedLength() const
136 return _preestimation;
139 //=============================================================================
143 //=============================================================================
145 ostream & StdMeshers_MaxLength::SaveTo(ostream & save)
147 save << _length << " " << _preestimated << " " << _preestimation;
151 //=============================================================================
155 //=============================================================================
157 istream & StdMeshers_MaxLength::LoadFrom(istream & load)
166 load.clear(ios::badbit | load.rdstate());
172 load.clear(ios::badbit | load.rdstate());
175 isOK = (load >> pre);
177 _preestimation = pre;
179 load.clear(ios::badbit | load.rdstate());
184 //================================================================================
186 * \brief Initialize segment length by the mesh built on the geometry
187 * \param theMesh - the built mesh
188 * \param theShape - the geometry of interest
189 * \retval bool - true if parameter values have been successfully defined
191 //================================================================================
193 bool StdMeshers_MaxLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
194 const TopoDS_Shape& theShape)
196 if ( !theMesh || theShape.IsNull() )
201 Standard_Real UMin, UMax;
205 TopTools_IndexedMapOfShape edgeMap;
206 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
207 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
209 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE ));
210 Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax );
211 GeomAdaptor_Curve AdaptCurve(C);
213 vector< double > params;
214 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
215 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
217 for ( int i = 1; i < params.size(); ++i )
218 _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]);
219 nbEdges += params.size() - 1;
227 //================================================================================
229 * \brief Initialize my parameter values by default parameters.
230 * \retval bool - true if parameter values have been successfully defined
232 //================================================================================
234 bool StdMeshers_MaxLength::SetParametersByDefaults(const TDefaults& dflts,
235 const SMESH_Mesh* /*theMesh*/)
237 //_preestimation = ( dflts._elemLength > 0.);
238 if ( dflts._elemLength > 0. )
239 _preestimated = dflts._elemLength;
240 return ( _length = dflts._elemLength );