1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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
23 // SMESH SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Geometric1D.cxx
27 #include "StdMeshers_Geometric1D.hxx"
29 #include "SMESH_Mesh.hxx"
31 #include <BRepAdaptor_Curve.hxx>
32 #include <GCPnts_AbscissaPoint.hxx>
33 #include <SMESH_Algo.hxx>
35 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TopoDS_Edge.hxx>
39 //=============================================================================
43 //=============================================================================
45 StdMeshers_Geometric1D::StdMeshers_Geometric1D(int hypId, int studyId, SMESH_Gen * gen)
46 :StdMeshers_Reversible1D(hypId, studyId, gen)
50 _name = "GeometricProgression";
53 //=============================================================================
55 * Sets length of the first segment
57 //=============================================================================
59 void StdMeshers_Geometric1D::SetStartLength(double length)
60 throw(SALOME_Exception)
62 if ( _begLength != length )
65 throw SALOME_Exception(LOCALIZED("length must be positive"));
67 NotifySubMeshesHypothesisModification();
71 //=============================================================================
73 * Sets value of Common Ratio
75 //=============================================================================
77 void StdMeshers_Geometric1D::SetCommonRatio(double factor)
78 throw(SALOME_Exception)
80 if ( _ratio != factor )
83 throw SALOME_Exception(LOCALIZED("Zero factor is not allowed"));
85 NotifySubMeshesHypothesisModification();
89 //=============================================================================
91 * Returns length of the first segment
93 //=============================================================================
95 double StdMeshers_Geometric1D::GetStartLength() const
100 //=============================================================================
102 * Returns value of Common Ratio
104 //=============================================================================
106 double StdMeshers_Geometric1D::GetCommonRatio() const
111 //=============================================================================
115 //=============================================================================
117 ostream & StdMeshers_Geometric1D::SaveTo(ostream & save)
119 save << _begLength << " " << _ratio << " ";
121 StdMeshers_Reversible1D::SaveTo( save );
126 //=============================================================================
130 //=============================================================================
132 istream & StdMeshers_Geometric1D::LoadFrom(istream & load)
135 isOK = static_cast<bool>(load >> _begLength);
136 isOK = static_cast<bool>(load >> _ratio);
139 StdMeshers_Reversible1D::LoadFrom( load );
144 //================================================================================
146 * \brief Initialize start and end length by the mesh built on the geometry
147 * \param theMesh - the built mesh
148 * \param theShape - the geometry of interest
149 * \retval bool - true if parameter values have been successfully defined
151 //================================================================================
153 bool StdMeshers_Geometric1D::SetParametersByMesh(const SMESH_Mesh* theMesh,
154 const TopoDS_Shape& theShape)
156 if ( !theMesh || theShape.IsNull() )
159 _begLength = _ratio = 0.;
162 TopTools_IndexedMapOfShape edgeMap;
163 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
164 for ( int i = 1; i <= edgeMap.Extent(); ++i )
166 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
167 BRepAdaptor_Curve C( edge );
169 std::vector< double > params;
170 if ( SMESH_Algo::GetNodeParamOnEdge( theMesh->GetMeshDS(), edge, params ))
173 double l1 = GCPnts_AbscissaPoint::Length( C, params[0], params[1] );
175 if ( params.size() > 2 && l1 > 1e-100 )
176 _ratio += GCPnts_AbscissaPoint::Length( C, params[1], params[2]) / l1;
182 _begLength /= nbEdges;
192 //================================================================================
194 * \brief Initialize my parameter values by default parameters.
195 * \retval bool - true if parameter values have been successfully defined
197 //================================================================================
199 bool StdMeshers_Geometric1D::SetParametersByDefaults(const TDefaults& dflts,
200 const SMESH_Mesh* /*mesh*/)
202 return ( _begLength = dflts._elemLength );