1 // Copyright (C) 2007-2008 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.
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 // SMESH SMESH : implementaion of SMESH idl descriptions
23 // File : StdMeshers_Arithmetic1D.cxx
24 // Author : Damien COQUERET, OCC
27 #include "StdMeshers_Arithmetic1D.hxx"
29 #include "SMESH_Algo.hxx"
30 #include "SMESH_Mesh.hxx"
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>
44 //=============================================================================
48 //=============================================================================
50 StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, SMESH_Gen * gen)
51 :SMESH_Hypothesis(hypId, studyId, gen)
55 _name = "Arithmetic1D";
59 //=============================================================================
63 //=============================================================================
65 StdMeshers_Arithmetic1D::~StdMeshers_Arithmetic1D()
69 //=============================================================================
73 //=============================================================================
75 void StdMeshers_Arithmetic1D::SetLength(double length, bool isStartLength)
76 throw(SALOME_Exception)
78 if ( (isStartLength ? _begLength : _endLength) != length ) {
80 throw SALOME_Exception(LOCALIZED("length must be positive"));
86 NotifySubMeshesHypothesisModification();
90 //=============================================================================
94 //=============================================================================
96 double StdMeshers_Arithmetic1D::GetLength(bool isStartLength) const
98 return isStartLength ? _begLength : _endLength;
101 //=============================================================================
105 //=============================================================================
107 ostream & StdMeshers_Arithmetic1D::SaveTo(ostream & save)
109 save << _begLength << " " << _endLength;
113 //=============================================================================
117 //=============================================================================
119 istream & StdMeshers_Arithmetic1D::LoadFrom(istream & load)
122 isOK = (load >> _begLength);
124 load.clear(ios::badbit | load.rdstate());
125 isOK = (load >> _endLength);
127 load.clear(ios::badbit | load.rdstate());
131 //=============================================================================
135 //=============================================================================
137 ostream & operator <<(ostream & save, StdMeshers_Arithmetic1D & hyp)
139 return hyp.SaveTo( save );
142 //=============================================================================
146 //=============================================================================
148 istream & operator >>(istream & load, StdMeshers_Arithmetic1D & hyp)
150 return hyp.LoadFrom( load );
153 //================================================================================
155 * \brief Initialize start and end length by the mesh built on the geometry
156 * \param theMesh - the built mesh
157 * \param theShape - the geometry of interest
158 * \retval bool - true if parameter values have been successfully defined
160 //================================================================================
162 bool StdMeshers_Arithmetic1D::SetParametersByMesh(const SMESH_Mesh* theMesh,
163 const TopoDS_Shape& theShape)
165 if ( !theMesh || theShape.IsNull() )
168 _begLength = _endLength = 0.;
170 Standard_Real UMin, UMax;
174 TopTools_IndexedMapOfShape edgeMap;
175 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
176 for ( int i = 1; i <= edgeMap.Extent(); ++i )
178 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
179 Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax);
180 GeomAdaptor_Curve AdaptCurve(C);
182 vector< double > params;
183 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
184 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
187 _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]);
188 int nb = params.size();
189 _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]);
193 _begLength /= nbEdges;
194 _endLength /= nbEdges;
199 //================================================================================
201 * \brief Initialize my parameter values by default parameters.
202 * \retval bool - true if parameter values have been successfully defined
204 //================================================================================
206 bool StdMeshers_Arithmetic1D::SetParametersByDefaults(const TDefaults& dflts,
207 const SMESH_Mesh* /*mesh*/)
209 return bool( _begLength = _endLength = dflts._elemLength );