1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESH : implementaion of SMESH idl descriptions
21 // File : StdMeshers_MaxLength.cxx
24 #include "StdMeshers_MaxLength.hxx"
26 #include "SMESH_Mesh.hxx"
27 #include "SMESH_Algo.hxx"
29 #include "utilities.h"
31 #include <BRep_Tool.hxx>
32 #include <GCPnts_AbscissaPoint.hxx>
33 #include <GeomAdaptor_Curve.hxx>
34 #include <Geom_Curve.hxx>
36 #include <TopLoc_Location.hxx>
37 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <Precision.hxx>
44 //=============================================================================
48 //=============================================================================
50 StdMeshers_MaxLength::StdMeshers_MaxLength(int hypId, int studyId, SMESH_Gen * gen)
51 :SMESH_Hypothesis(hypId, studyId, gen)
55 _preestimation = false;
57 _param_algo_dim = 1; // is used by SMESH_Regular_1D
60 //=============================================================================
64 //=============================================================================
66 StdMeshers_MaxLength::~StdMeshers_MaxLength()
70 //=============================================================================
74 //=============================================================================
76 void StdMeshers_MaxLength::SetLength(double length) throw(SALOME_Exception)
79 throw SALOME_Exception(LOCALIZED("length must be positive"));
80 if ( _length != length ) {
82 NotifySubMeshesHypothesisModification();
86 //=============================================================================
90 //=============================================================================
92 double StdMeshers_MaxLength::GetLength() const
94 return ( _preestimation && _preestimated > 0. ) ? _preestimated : _length;
97 //================================================================================
99 * \brief Sets boolean parameter enabling/desabling usage of length computed
100 * basing on size of bounding box of shape to mesh
102 //================================================================================
104 void StdMeshers_MaxLength::SetUsePreestimatedLength(bool toUse)
106 if ( toUse != _preestimation )
108 _preestimation = toUse;
109 // this parameter is just to help the user
110 //NotifySubMeshesHypothesisModification();
114 //================================================================================
116 * \brief Store preestemated length
118 //================================================================================
120 void StdMeshers_MaxLength::SetPreestimatedLength(double length)
123 _preestimated = length;
126 //================================================================================
128 * \brief Returns value of boolean parameter enabling/desabling usage of length computed
129 * basing on size of bounding box of shape to mesh
131 //================================================================================
133 bool StdMeshers_MaxLength::GetUsePreestimatedLength() const
135 return _preestimation;
138 //=============================================================================
142 //=============================================================================
144 ostream & StdMeshers_MaxLength::SaveTo(ostream & save)
146 save << _length << " " << _preestimated << " " << _preestimation;
150 //=============================================================================
154 //=============================================================================
156 istream & StdMeshers_MaxLength::LoadFrom(istream & load)
165 load.clear(ios::badbit | load.rdstate());
171 load.clear(ios::badbit | load.rdstate());
174 isOK = (load >> pre);
176 _preestimation = pre;
178 load.clear(ios::badbit | load.rdstate());
183 //================================================================================
185 * \brief Initialize segment length by the mesh built on the geometry
186 * \param theMesh - the built mesh
187 * \param theShape - the geometry of interest
188 * \retval bool - true if parameter values have been successfully defined
190 //================================================================================
192 bool StdMeshers_MaxLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
193 const TopoDS_Shape& theShape)
195 if ( !theMesh || theShape.IsNull() )
200 Standard_Real UMin, UMax;
204 TopTools_IndexedMapOfShape edgeMap;
205 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
206 for ( int iE = 1; iE <= edgeMap.Extent(); ++iE )
208 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( iE ));
209 Handle(Geom_Curve) C = BRep_Tool::Curve( edge, L, UMin, UMax );
210 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax);
212 vector< double > params;
213 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
214 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
216 for ( int i = 1; i < params.size(); ++i )
217 _length += GCPnts_AbscissaPoint::Length( AdaptCurve, params[ i-1 ], params[ i ]);
218 nbEdges += params.size() - 1;
226 //================================================================================
228 * \brief Initialize my parameter values by default parameters.
229 * \retval bool - true if parameter values have been successfully defined
231 //================================================================================
233 bool StdMeshers_MaxLength::SetParametersByDefaults(const TDefaults& dflts,
234 const SMESH_Mesh* /*theMesh*/)
236 //_preestimation = ( dflts._elemLength > 0.);
237 if ( dflts._elemLength > 0. )
238 _preestimated = dflts._elemLength;
239 return ( _length = dflts._elemLength );