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 void StdMeshers_StartEndLength::SetReversedEdges( std::vector<int>& ids )
110 if ( ids != _edgeIDs ) {
113 NotifySubMeshesHypothesisModification();
117 //=============================================================================
121 //=============================================================================
123 ostream & StdMeshers_StartEndLength::SaveTo(ostream & save)
125 int listSize = _edgeIDs.size();
126 save << _begLength << " " << _endLength << " " << listSize;
128 if ( listSize > 0 ) {
129 for ( int i = 0; i < listSize; i++) {
130 save << " " << _edgeIDs[i];
132 save << " " << _objEntry;
138 //=============================================================================
142 //=============================================================================
144 istream & StdMeshers_StartEndLength::LoadFrom(istream & load)
148 isOK = (load >> _begLength);
150 load.clear(ios::badbit | load.rdstate());
151 isOK = (load >> _endLength);
154 load.clear(ios::badbit | load.rdstate());
156 isOK = (load >> intVal);
157 if (isOK && intVal > 0) {
158 _edgeIDs.reserve( intVal );
159 for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
160 isOK = (load >> intVal);
161 if ( isOK ) _edgeIDs.push_back( intVal );
163 isOK = (load >> _objEntry);
169 //=============================================================================
173 //=============================================================================
175 ostream & operator <<(ostream & save, StdMeshers_StartEndLength & hyp)
177 return hyp.SaveTo( save );
180 //=============================================================================
184 //=============================================================================
186 istream & operator >>(istream & load, StdMeshers_StartEndLength & hyp)
188 return hyp.LoadFrom( load );
191 //================================================================================
193 * \brief Initialize start and end length by the mesh built on the geometry
194 * \param theMesh - the built mesh
195 * \param theShape - the geometry of interest
196 * \retval bool - true if parameter values have been successfully defined
198 //================================================================================
200 bool StdMeshers_StartEndLength::SetParametersByMesh(const SMESH_Mesh* theMesh,
201 const TopoDS_Shape& theShape)
203 if ( !theMesh || theShape.IsNull() )
206 _begLength = _endLength = 0.;
208 Standard_Real UMin, UMax;
212 TopTools_IndexedMapOfShape edgeMap;
213 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
214 for ( int i = 1; i <= edgeMap.Extent(); ++i )
216 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
217 Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax);
218 GeomAdaptor_Curve AdaptCurve(C);
220 vector< double > params;
221 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
222 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
225 _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]);
226 int nb = params.size();
227 _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]);
231 _begLength /= nbEdges;
232 _endLength /= nbEdges;
237 //================================================================================
239 * \brief Initialize my parameter values by default parameters.
240 * \retval bool - true if parameter values have been successfully defined
242 //================================================================================
244 bool StdMeshers_StartEndLength::SetParametersByDefaults(const TDefaults& dflts,
245 const SMESH_Mesh* /*theMesh*/)
247 return (_begLength = _endLength = dflts._elemLength );