Salome HOME
fix Save() and Load()
[modules/smesh.git] / src / StdMeshers / StdMeshers_FixedPoints1D.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESH : implementaion of SMESH idl descriptions
23 //  File   : StdMeshers_FixedPoints1D.cxx
24 //  Author : Damien COQUERET, OCC
25 //  Module : SMESH
26 //
27 #include "StdMeshers_FixedPoints1D.hxx"
28
29 #include "SMESH_Algo.hxx"
30 #include "SMESH_Mesh.hxx"
31
32 //#include <BRep_Tool.hxx>
33 //#include <GCPnts_AbscissaPoint.hxx>
34 //#include <GeomAdaptor_Curve.hxx>
35 //#include <Geom_Curve.hxx>
36 //#include <TopExp.hxx>
37 //#include <TopLoc_Location.hxx>
38 //#include <TopTools_IndexedMapOfShape.hxx>
39 //#include <TopoDS.hxx>
40 //#include <TopoDS_Edge.hxx>
41
42 using namespace std;
43
44 //=============================================================================
45 /*!
46  *  
47  */
48 //=============================================================================
49
50 StdMeshers_FixedPoints1D::StdMeshers_FixedPoints1D(int hypId, int studyId,
51                                                    SMESH_Gen * gen)
52   :SMESH_Hypothesis(hypId, studyId, gen)
53 {
54   _name = "FixedPoints1D";
55   _param_algo_dim = 1; 
56   _nbsegs.reserve( 1 );
57   _nbsegs.push_back( 1 );
58 }
59
60 //=============================================================================
61 /*!
62  *  
63  */
64 //=============================================================================
65
66 StdMeshers_FixedPoints1D::~StdMeshers_FixedPoints1D()
67 {
68 }
69
70 //=============================================================================
71 /*!
72  *  
73  */
74 //=============================================================================
75
76 void StdMeshers_FixedPoints1D::SetPoints(std::vector<double>& listParams)
77                               throw(SALOME_Exception)
78 {
79   _params = listParams;
80   NotifySubMeshesHypothesisModification();
81 }
82
83 //=============================================================================
84 /*!
85  *  
86  */
87 //=============================================================================
88
89 void StdMeshers_FixedPoints1D::SetNbSegments(std::vector<int>& listNbSeg) 
90                               throw(SALOME_Exception)
91 {
92   _nbsegs = listNbSeg;
93   NotifySubMeshesHypothesisModification();
94 }
95
96 //=============================================================================
97 /*!
98  *  
99  */
100 //=============================================================================
101
102 void StdMeshers_FixedPoints1D::SetReversedEdges( std::vector<int>& ids )
103 {
104   if ( ids != _edgeIDs ) {
105     _edgeIDs = ids;
106
107     NotifySubMeshesHypothesisModification();
108   }
109 }
110
111 //=============================================================================
112 /*!
113  *  
114  */
115 //=============================================================================
116
117 ostream & StdMeshers_FixedPoints1D::SaveTo(ostream & save)
118 {
119   int listSize = _params.size();
120   save << listSize;
121   if ( listSize > 0 ) {
122     for ( int i = 0; i < listSize; i++) save << " " << _params[i];
123   }
124
125   listSize = _nbsegs.size();
126   save << " " << listSize;
127   if ( listSize > 0 ) {
128     for ( int i = 0; i < listSize; i++) save << " " << _nbsegs[i];
129   }
130
131   listSize = _edgeIDs.size();
132   save << " " << listSize;
133   if ( listSize > 0 ) {
134     for ( int i = 0; i < listSize; i++)
135       save << " " << _edgeIDs[i];
136   }
137
138   save << " " << _objEntry;
139
140   return save;
141 }
142
143 //=============================================================================
144 /*!
145  *  
146  */
147 //=============================================================================
148
149 istream & StdMeshers_FixedPoints1D::LoadFrom(istream & load)
150 {
151   bool isOK = true;
152   int intVal;
153   double dblVal;
154
155   isOK = (load >> intVal);
156   if (isOK && intVal > 0) {
157     _params.clear();
158     _params.reserve( intVal );
159     for (int i = 0; i < _params.capacity() && isOK; i++) {
160       isOK = (load >> dblVal);
161       if ( isOK ) _params.push_back( dblVal );
162     }
163   }
164
165   isOK = (load >> intVal);
166   if (isOK && intVal > 0) {
167     _nbsegs.clear();
168     _nbsegs.reserve( intVal );
169     for (int i = 0; i < _nbsegs.capacity() && isOK; i++) {
170       isOK = (load >> intVal);
171       if ( isOK ) _nbsegs.push_back( intVal );
172     }
173   }
174
175   isOK = (load >> intVal);
176   if (isOK && intVal > 0) {
177     _edgeIDs.clear();
178     _edgeIDs.reserve( intVal );
179     for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
180       isOK = (load >> intVal);
181       if ( isOK ) _edgeIDs.push_back( intVal );
182     }
183   }
184
185   isOK = (load >> _objEntry);
186
187   return load;
188 }
189
190 //=============================================================================
191 /*!
192  *  
193  */
194 //=============================================================================
195
196 ostream & operator <<(ostream & save, StdMeshers_FixedPoints1D & hyp)
197 {
198   return hyp.SaveTo( save );
199 }
200
201 //=============================================================================
202 /*!
203  *  
204  */
205 //=============================================================================
206
207 istream & operator >>(istream & load, StdMeshers_FixedPoints1D & hyp)
208 {
209   return hyp.LoadFrom( load );
210 }
211
212 //================================================================================
213 /*!
214  * \brief Initialize start and end length by the mesh built on the geometry
215  * \param theMesh - the built mesh
216  * \param theShape - the geometry of interest
217  * \retval bool - true if parameter values have been successfully defined
218  */
219 //================================================================================
220
221 bool StdMeshers_FixedPoints1D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
222                                                    const TopoDS_Shape& theShape)
223 {
224   if ( !theMesh || theShape.IsNull() )
225     return false;
226
227   _nbsegs.reserve( 1 );
228   _nbsegs.push_back( 1 );
229   return true;
230 }
231
232 //================================================================================
233 /*!
234  * \brief Initialize my parameter values by default parameters.
235  *  \retval bool - true if parameter values have been successfully defined
236  */
237 //================================================================================
238
239 bool StdMeshers_FixedPoints1D::SetParametersByDefaults(const TDefaults&  dflts,
240                                                        const SMESH_Mesh* /*mesh*/)
241 {
242   _nbsegs.reserve( 1 );
243   _nbsegs.push_back( 1 );
244   return true;
245 }
246