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 StdMeshers_StartEndLength : implementaion of SMESH idl descriptions
23 // File : StdMeshers_StartEndLength.cxx
26 #include "StdMeshers_StartEndLength.hxx"
28 #include "SMESH_Algo.hxx"
29 #include "SMESH_Mesh.hxx"
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>
43 //=============================================================================
47 //=============================================================================
49 StdMeshers_StartEndLength::StdMeshers_StartEndLength(int hypId,
52 :SMESH_Hypothesis(hypId, studyId, gen)
56 _name = "StartEndLength";
57 _param_algo_dim = 1; // is used by SMESH_Regular_1D
60 //=============================================================================
64 //=============================================================================
66 StdMeshers_StartEndLength::~StdMeshers_StartEndLength()
70 //=============================================================================
74 //=============================================================================
76 void StdMeshers_StartEndLength::SetLength(double length, bool isStartLength)
77 throw(SALOME_Exception)
79 if ( (isStartLength ? _begLength : _endLength) != length ) {
81 throw SALOME_Exception(LOCALIZED("length must be positive"));
87 NotifySubMeshesHypothesisModification();
91 //=============================================================================
95 //=============================================================================
97 double StdMeshers_StartEndLength::GetLength(bool isStartLength) const
99 return isStartLength ? _begLength : _endLength;
102 //=============================================================================
106 //=============================================================================
108 ostream & StdMeshers_StartEndLength::SaveTo(ostream & save)
110 save << _begLength << " " <<_endLength;
114 //=============================================================================
118 //=============================================================================
120 istream & StdMeshers_StartEndLength::LoadFrom(istream & load)
123 isOK = (load >> _begLength);
125 load.clear(ios::badbit | load.rdstate());
126 isOK = (load >> _endLength);
128 load.clear(ios::badbit | load.rdstate());
132 //=============================================================================
136 //=============================================================================
138 ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp)
140 return hyp.SaveTo( save );
143 //=============================================================================
147 //=============================================================================
149 istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp)
151 return hyp.LoadFrom( load );
154 //================================================================================
156 * \brief Initialize start and end length by the mesh built on the geometry
157 * \param theMesh - the built mesh
158 * \param theShape - the geometry of interest
159 * \retval bool - true if parameter values have been successfully defined
161 //================================================================================
163 bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
164 const TopoDS_Shape& theShape)
166 if ( !theMesh || theShape.IsNull() )
169 _begLength = _endLength = 0.;
171 Standard_Real UMin, UMax;
175 TopTools_IndexedMapOfShape edgeMap;
176 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
177 for ( int i = 1; i <= edgeMap.Extent(); ++i )
179 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
180 Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax);
181 GeomAdaptor_Curve AdaptCurve(C);
183 vector< double > params;
184 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
185 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
188 _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]);
189 int nb = params.size();
190 _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]);
194 _begLength /= nbEdges;
195 _endLength /= nbEdges;
200 //================================================================================
202 * \brief Initialize my parameter values by linear size of mesh element.
203 * \retval bool - true if parameter values have been successfully defined
205 //================================================================================
207 bool StdMeshers_StartEndLength::SetParametersByElementSize(double elemLenght,
208 const SMESH_Mesh* /*theMesh*/)
210 return bool(_begLength = _endLength = elemLenght );