1 // Copyright (C) 2007-2010 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 SMESH : implementaion of SMESH idl descriptions
24 // File : StdMeshers_Arithmetic1D.cxx
25 // Author : Damien COQUERET, OCC
28 #include "StdMeshers_Arithmetic1D.hxx"
30 #include "SMESH_Algo.hxx"
31 #include "SMESH_Mesh.hxx"
33 #include <BRep_Tool.hxx>
34 #include <GCPnts_AbscissaPoint.hxx>
35 #include <GeomAdaptor_Curve.hxx>
36 #include <Geom_Curve.hxx>
38 #include <TopLoc_Location.hxx>
39 #include <TopTools_IndexedMapOfShape.hxx>
41 #include <TopoDS_Edge.hxx>
45 //=============================================================================
49 //=============================================================================
51 StdMeshers_Arithmetic1D::StdMeshers_Arithmetic1D(int hypId, int studyId, SMESH_Gen * gen)
52 :SMESH_Hypothesis(hypId, studyId, gen)
56 _name = "Arithmetic1D";
60 //=============================================================================
64 //=============================================================================
66 StdMeshers_Arithmetic1D::~StdMeshers_Arithmetic1D()
70 //=============================================================================
74 //=============================================================================
76 void StdMeshers_Arithmetic1D::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_Arithmetic1D::GetLength(bool isStartLength) const
99 return isStartLength ? _begLength : _endLength;
102 //=============================================================================
106 //=============================================================================
108 void StdMeshers_Arithmetic1D::SetReversedEdges( std::vector<int>& ids )
110 if ( ids != _edgeIDs ) {
113 NotifySubMeshesHypothesisModification();
117 //=============================================================================
121 //=============================================================================
123 ostream & StdMeshers_Arithmetic1D::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];
131 save << " " << _objEntry;
137 //=============================================================================
141 //=============================================================================
143 istream & StdMeshers_Arithmetic1D::LoadFrom(istream & load)
147 isOK = (load >> _begLength);
149 load.clear(ios::badbit | load.rdstate());
150 isOK = (load >> _endLength);
153 load.clear(ios::badbit | load.rdstate());
155 isOK = (load >> intVal);
156 if (isOK && intVal > 0) {
157 _edgeIDs.reserve( intVal );
158 for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
159 isOK = (load >> intVal);
160 if ( isOK ) _edgeIDs.push_back( intVal );
162 isOK = (load >> _objEntry);
168 //=============================================================================
172 //=============================================================================
174 ostream & operator <<(ostream & save, StdMeshers_Arithmetic1D & hyp)
176 return hyp.SaveTo( save );
179 //=============================================================================
183 //=============================================================================
185 istream & operator >>(istream & load, StdMeshers_Arithmetic1D & hyp)
187 return hyp.LoadFrom( load );
190 //================================================================================
192 * \brief Initialize start and end length by the mesh built on the geometry
193 * \param theMesh - the built mesh
194 * \param theShape - the geometry of interest
195 * \retval bool - true if parameter values have been successfully defined
197 //================================================================================
199 bool StdMeshers_Arithmetic1D::SetParametersByMesh(const SMESH_Mesh* theMesh,
200 const TopoDS_Shape& theShape)
202 if ( !theMesh || theShape.IsNull() )
205 _begLength = _endLength = 0.;
207 Standard_Real UMin, UMax;
211 TopTools_IndexedMapOfShape edgeMap;
212 TopExp::MapShapes( theShape, TopAbs_EDGE, edgeMap );
213 for ( int i = 1; i <= edgeMap.Extent(); ++i )
215 const TopoDS_Edge& edge = TopoDS::Edge( edgeMap( i ));
216 Handle(Geom_Curve) C = BRep_Tool::Curve(edge, L, UMin, UMax);
217 GeomAdaptor_Curve AdaptCurve(C);
219 vector< double > params;
220 SMESHDS_Mesh* aMeshDS = const_cast< SMESH_Mesh* >( theMesh )->GetMeshDS();
221 if ( SMESH_Algo::GetNodeParamOnEdge( aMeshDS, edge, params ))
224 _begLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[0], params[1]);
225 int nb = params.size();
226 _endLength += GCPnts_AbscissaPoint::Length( AdaptCurve, params[nb-2], params[nb-1]);
230 _begLength /= nbEdges;
231 _endLength /= nbEdges;
236 //================================================================================
238 * \brief Initialize my parameter values by default parameters.
239 * \retval bool - true if parameter values have been successfully defined
241 //================================================================================
243 bool StdMeshers_Arithmetic1D::SetParametersByDefaults(const TDefaults& dflts,
244 const SMESH_Mesh* /*mesh*/)
246 return ( _begLength = _endLength = dflts._elemLength );