Salome HOME
correct previous integration (Porting to Python 2.6)
[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.reserve( intVal );
158     for (int i = 0; i < _params.capacity() && isOK; i++) {
159       isOK = (load >> dblVal);
160       if ( isOK ) _params.push_back( dblVal );
161     }
162   }
163
164   isOK = (load >> intVal);
165   if (isOK && intVal > 0) {
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.reserve( intVal );
176     for (int i = 0; i < _edgeIDs.capacity() && isOK; i++) {
177       isOK = (load >> intVal);
178       if ( isOK ) _edgeIDs.push_back( intVal );
179     }
180   }
181
182   isOK = (load >> _objEntry);
183
184   return load;
185 }
186
187 //=============================================================================
188 /*!
189  *  
190  */
191 //=============================================================================
192
193 ostream & operator <<(ostream & save, StdMeshers_FixedPoints1D & hyp)
194 {
195   return hyp.SaveTo( save );
196 }
197
198 //=============================================================================
199 /*!
200  *  
201  */
202 //=============================================================================
203
204 istream & operator >>(istream & load, StdMeshers_FixedPoints1D & hyp)
205 {
206   return hyp.LoadFrom( load );
207 }
208
209 //================================================================================
210 /*!
211  * \brief Initialize start and end length by the mesh built on the geometry
212  * \param theMesh - the built mesh
213  * \param theShape - the geometry of interest
214  * \retval bool - true if parameter values have been successfully defined
215  */
216 //================================================================================
217
218 bool StdMeshers_FixedPoints1D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
219                                                    const TopoDS_Shape& theShape)
220 {
221   if ( !theMesh || theShape.IsNull() )
222     return false;
223
224   _nbsegs.reserve( 1 );
225   _nbsegs.push_back( 1 );
226   return true;
227 }
228
229 //================================================================================
230 /*!
231  * \brief Initialize my parameter values by default parameters.
232  *  \retval bool - true if parameter values have been successfully defined
233  */
234 //================================================================================
235
236 bool StdMeshers_FixedPoints1D::SetParametersByDefaults(const TDefaults&  dflts,
237                                                        const SMESH_Mesh* /*mesh*/)
238 {
239   _nbsegs.reserve( 1 );
240   _nbsegs.push_back( 1 );
241   return true;
242 }
243