Salome HOME
Merge from V6_main 01/04/2013
[modules/smesh.git] / src / StdMeshers / StdMeshers_FixedPoints1D.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESH : implementaion of SMESH idl descriptions
21 //  File   : StdMeshers_FixedPoints1D.cxx
22 //  Author : Damien COQUERET, OCC
23 //  Module : SMESH
24 //
25 #include "StdMeshers_FixedPoints1D.hxx"
26
27 #include "SMESH_Algo.hxx"
28 #include "SMESH_Mesh.hxx"
29
30 //#include <BRep_Tool.hxx>
31 //#include <GCPnts_AbscissaPoint.hxx>
32 //#include <GeomAdaptor_Curve.hxx>
33 //#include <Geom_Curve.hxx>
34 //#include <TopExp.hxx>
35 //#include <TopLoc_Location.hxx>
36 //#include <TopTools_IndexedMapOfShape.hxx>
37 //#include <TopoDS.hxx>
38 //#include <TopoDS_Edge.hxx>
39
40 using namespace std;
41
42 //=============================================================================
43 /*!
44  *  
45  */
46 //=============================================================================
47
48 StdMeshers_FixedPoints1D::StdMeshers_FixedPoints1D(int hypId, int studyId,
49                                                    SMESH_Gen * gen)
50   :SMESH_Hypothesis(hypId, studyId, gen)
51 {
52   _name = "FixedPoints1D";
53   _param_algo_dim = 1; 
54   _nbsegs.reserve( 1 );
55   _nbsegs.push_back( 1 );
56 }
57
58 //=============================================================================
59 /*!
60  *  
61  */
62 //=============================================================================
63
64 StdMeshers_FixedPoints1D::~StdMeshers_FixedPoints1D()
65 {
66 }
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73
74 void StdMeshers_FixedPoints1D::SetPoints(std::vector<double>& listParams)
75                               throw(SALOME_Exception)
76 {
77   _params = listParams;
78   NotifySubMeshesHypothesisModification();
79 }
80
81 //=============================================================================
82 /*!
83  *  
84  */
85 //=============================================================================
86
87 void StdMeshers_FixedPoints1D::SetNbSegments(std::vector<int>& listNbSeg) 
88                               throw(SALOME_Exception)
89 {
90   _nbsegs = listNbSeg;
91   NotifySubMeshesHypothesisModification();
92 }
93
94 //=============================================================================
95 /*!
96  *  
97  */
98 //=============================================================================
99
100 void StdMeshers_FixedPoints1D::SetReversedEdges( std::vector<int>& ids )
101 {
102   if ( ids != _edgeIDs ) {
103     _edgeIDs = ids;
104
105     NotifySubMeshesHypothesisModification();
106   }
107 }
108
109 //=============================================================================
110 /*!
111  *  
112  */
113 //=============================================================================
114
115 ostream & StdMeshers_FixedPoints1D::SaveTo(ostream & save)
116 {
117   int listSize = _params.size();
118   save << listSize;
119   if ( listSize > 0 ) {
120     for ( int i = 0; i < listSize; i++) save << " " << _params[i];
121   }
122
123   listSize = _nbsegs.size();
124   save << " " << listSize;
125   if ( listSize > 0 ) {
126     for ( int i = 0; i < listSize; i++) save << " " << _nbsegs[i];
127   }
128
129   listSize = _edgeIDs.size();
130   save << " " << listSize;
131   if ( listSize > 0 ) {
132     for ( int i = 0; i < listSize; i++)
133       save << " " << _edgeIDs[i];
134   }
135
136   save << " " << _objEntry;
137
138   return save;
139 }
140
141 //=============================================================================
142 /*!
143  *  
144  */
145 //=============================================================================
146
147 istream & StdMeshers_FixedPoints1D::LoadFrom(istream & load)
148 {
149   bool isOK = true;
150   int intVal;
151   double dblVal;
152
153   isOK = (load >> intVal);
154   if (isOK && intVal > 0) {
155     _params.clear();
156     _params.reserve( intVal );
157     for (int i = 0; i < _params.capacity() && isOK; i++) {
158       isOK = (load >> dblVal);
159       if ( isOK ) _params.push_back( dblVal );
160     }
161   }
162
163   isOK = (load >> intVal);
164   if (isOK && intVal > 0) {
165     _nbsegs.clear();
166     _nbsegs.reserve( intVal );
167     for (int i = 0; i < _nbsegs.capacity() && isOK; i++) {
168       isOK = (load >> intVal);
169       if ( isOK ) _nbsegs.push_back( intVal );
170     }
171   }
172
173   isOK = (load >> intVal);
174   if (isOK && intVal > 0) {
175     _edgeIDs.clear();
176     _edgeIDs.reserve( intVal );
177     for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
178       isOK = (load >> intVal);
179       if ( isOK ) _edgeIDs.push_back( intVal );
180     }
181   }
182
183   isOK = (load >> _objEntry);
184
185   return load;
186 }
187
188 //=============================================================================
189 /*!
190  *  
191  */
192 //=============================================================================
193
194 ostream & operator <<(ostream & save, StdMeshers_FixedPoints1D & hyp)
195 {
196   return hyp.SaveTo( save );
197 }
198
199 //=============================================================================
200 /*!
201  *  
202  */
203 //=============================================================================
204
205 istream & operator >>(istream & load, StdMeshers_FixedPoints1D & hyp)
206 {
207   return hyp.LoadFrom( load );
208 }
209
210 //================================================================================
211 /*!
212  * \brief Initialize start and end length by the mesh built on the geometry
213  * \param theMesh - the built mesh
214  * \param theShape - the geometry of interest
215  * \retval bool - true if parameter values have been successfully defined
216  */
217 //================================================================================
218
219 bool StdMeshers_FixedPoints1D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
220                                                    const TopoDS_Shape& theShape)
221 {
222   if ( !theMesh || theShape.IsNull() )
223     return false;
224
225   _nbsegs.reserve( 1 );
226   _nbsegs.push_back( 1 );
227   return true;
228 }
229
230 //================================================================================
231 /*!
232  * \brief Initialize my parameter values by default parameters.
233  *  \retval bool - true if parameter values have been successfully defined
234  */
235 //================================================================================
236
237 bool StdMeshers_FixedPoints1D::SetParametersByDefaults(const TDefaults&  dflts,
238                                                        const SMESH_Mesh* /*mesh*/)
239 {
240   _nbsegs.reserve( 1 );
241   _nbsegs.push_back( 1 );
242   return true;
243 }
244