1 // Copyright (C) 2007-2012 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
23 // SMESH StdMeshers_StartEndLength : implementaion of SMESH idl descriptions
24 // File : StdMeshers_StartEndLength.cxx
27 #include "StdMeshers_StartEndLength.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_StartEndLength::StdMeshers_StartEndLength(int hypId,
53 :SMESH_Hypothesis(hypId, studyId, gen)
57 _name = "StartEndLength";
58 _param_algo_dim = 1; // is used by SMESH_Regular_1D
61 //=============================================================================
65 //=============================================================================
67 StdMeshers_StartEndLength::~StdMeshers_StartEndLength()
71 //=============================================================================
75 //=============================================================================
77 void StdMeshers_StartEndLength::SetLength(double length, bool isStartLength)
78 throw(SALOME_Exception)
80 if ( (isStartLength ? _begLength : _endLength) != length ) {
82 throw SALOME_Exception(LOCALIZED("length must be positive"));
88 NotifySubMeshesHypothesisModification();
92 //=============================================================================
96 //=============================================================================
98 double StdMeshers_StartEndLength::GetLength(bool isStartLength) const
100 return isStartLength ? _begLength : _endLength;
103 //=============================================================================
107 //=============================================================================
109 void StdMeshers_StartEndLength::SetReversedEdges( std::vector<int>& ids )
111 if ( ids != _edgeIDs ) {
114 NotifySubMeshesHypothesisModification();
118 //=============================================================================
122 //=============================================================================
124 ostream & StdMeshers_StartEndLength::SaveTo(ostream & save)
126 int listSize = _edgeIDs.size();
127 save << _begLength << " " << _endLength << " " << listSize;
129 if ( listSize > 0 ) {
130 for ( int i = 0; i < listSize; i++) {
131 save << " " << _edgeIDs[i];
133 save << " " << _objEntry;
139 //=============================================================================
143 //=============================================================================
145 istream & StdMeshers_StartEndLength::LoadFrom(istream & load)
149 isOK = (load >> _begLength);
151 load.clear(ios::badbit | load.rdstate());
152 isOK = (load >> _endLength);
155 load.clear(ios::badbit | load.rdstate());
157 isOK = (load >> intVal);
158 if (isOK && intVal > 0) {
159 _edgeIDs.reserve( intVal );
160 for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
161 isOK = (load >> intVal);
162 if ( isOK ) _edgeIDs.push_back( intVal );
164 isOK = (load >> _objEntry);
170 //=============================================================================
174 //=============================================================================
176 ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp)
178 return hyp.SaveTo( save );
181 //=============================================================================
185 //=============================================================================
187 istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp)
189 return hyp.LoadFrom( load );
192 //================================================================================
194 * \brief Initialize start and end length by the mesh built on the geometry
195 * \param theMesh - the built mesh
196 * \param theShape - the geometry of interest
197 * \retval bool - true if parameter values have been successfully defined
199 //================================================================================
201 bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
202 const TopoDS_Shape& theShape)
204 if ( !theMesh || theShape.IsNull() )
207 _begLength = _endLength = 0.;
209 Standard_Real UMin, UMax;
213 TopTools_IndexedMapOfShape edgeMap;
214 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
215 for ( int i = 1; i <= edgeMap.Extent(); ++i )
217 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
218 Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax);
219 GeomAdaptor_Curve AdaptCurve(C, UMin, UMax);
221 vector< double > params;
222 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
223 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
226 _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]);
227 int nb = params.size();
228 _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]);
232 _begLength /= nbEdges;
233 _endLength /= nbEdges;
238 //================================================================================
240 * \brief Initialize my parameter values by default parameters.
241 * \retval bool - true if parameter values have been successfully defined
243 //================================================================================
245 bool StdMeshers_StartEndLength::SetParametersByDefaults(const TDefaults& dflts,
246 const SMESH_Mesh* /*theMesh*/)
248 return (_begLength = _endLength = dflts._elemLength );