Salome HOME
23586: [EDF] HYDRO: Copy mesh to new geometry
[modules/smesh.git] / src / StdMeshers / StdMeshers_FixedPoints1D.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 : implementation 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 using namespace std;
31
32 //=============================================================================
33 /*!
34  *  
35  */
36 //=============================================================================
37
38 StdMeshers_FixedPoints1D::StdMeshers_FixedPoints1D(int hypId, int studyId,
39                                                    SMESH_Gen * gen)
40   :StdMeshers_Reversible1D(hypId, studyId, gen)
41 {
42   _name = "FixedPoints1D";
43   _param_algo_dim = 1;
44   _nbsegs.reserve( 1 );
45   _nbsegs.push_back( 1 );
46 }
47
48 //=============================================================================
49 /*!
50  *
51  */
52 //=============================================================================
53
54 StdMeshers_FixedPoints1D::~StdMeshers_FixedPoints1D()
55 {
56 }
57
58 //=============================================================================
59 /*!
60  *  
61  */
62 //=============================================================================
63
64 void StdMeshers_FixedPoints1D::SetPoints(std::vector<double>& listParams)
65   throw(SALOME_Exception)
66 {
67   _params = listParams;
68   NotifySubMeshesHypothesisModification();
69 }
70
71 //=============================================================================
72 /*!
73  *  
74  */
75 //=============================================================================
76
77 void StdMeshers_FixedPoints1D::SetNbSegments(std::vector<int>& listNbSeg) 
78   throw(SALOME_Exception)
79 {
80   _nbsegs = listNbSeg;
81   NotifySubMeshesHypothesisModification();
82 }
83
84 ostream & StdMeshers_FixedPoints1D::SaveTo(ostream & save)
85 {
86   int listSize = _params.size();
87   save << listSize;
88   if ( listSize > 0 ) {
89     for ( int i = 0; i < listSize; i++) save << " " << _params[i];
90   }
91
92   listSize = _nbsegs.size();
93   save << " " << listSize;
94   if ( listSize > 0 ) {
95     for ( int i = 0; i < listSize; i++) save << " " << _nbsegs[i];
96   }
97
98   listSize = _edgeIDs.size();
99   save << " " << listSize;
100   if ( listSize > 0 ) {
101     for ( int i = 0; i < listSize; i++)
102       save << " " << _edgeIDs[i];
103   }
104
105   save << " " << _objEntry;
106
107   return save;
108 }
109
110 //=============================================================================
111 /*!
112  *
113  */
114 //=============================================================================
115
116 istream & StdMeshers_FixedPoints1D::LoadFrom(istream & load)
117 {
118   bool isOK = true;
119   int intVal;
120   double dblVal;
121
122   isOK = static_cast<bool>(load >> intVal);
123   if (isOK && intVal > 0) {
124     _params.clear();
125     _params.reserve( intVal );
126     for ( size_t i = 0; i < _params.capacity() && isOK; i++) {
127       isOK = static_cast<bool>(load >> dblVal);
128       if ( isOK ) _params.push_back( dblVal );
129     }
130   }
131
132   isOK = static_cast<bool>(load >> intVal);
133   if (isOK && intVal > 0) {
134     _nbsegs.clear();
135     _nbsegs.reserve( intVal );
136     for ( size_t i = 0; i < _nbsegs.capacity() && isOK; i++) {
137       isOK = static_cast<bool>(load >> intVal);
138       if ( isOK ) _nbsegs.push_back( intVal );
139     }
140   }
141
142   isOK = static_cast<bool>(load >> intVal);
143   if (isOK && intVal > 0) {
144     _edgeIDs.clear();
145     _edgeIDs.reserve( intVal );
146     for ( size_t i = 0; i < _edgeIDs.capacity() && isOK; i++) {
147       isOK = static_cast<bool>(load >> intVal);
148       if ( isOK ) _edgeIDs.push_back( intVal );
149     }
150   }
151
152   isOK = static_cast<bool>(load >> _objEntry);
153
154   return load;
155 }
156
157 //================================================================================
158 /*!
159  * \brief Initialize start and end length by the mesh built on the geometry
160  * \param theMesh - the built mesh
161  * \param theShape - the geometry of interest
162  * \retval bool - true if parameter values have been successfully defined
163  */
164 //================================================================================
165
166 bool StdMeshers_FixedPoints1D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
167                                                    const TopoDS_Shape& theShape)
168 {
169   if ( !theMesh || theShape.IsNull() )
170     return false;
171
172   _nbsegs.reserve( 1 );
173   _nbsegs.push_back( 1 );
174   return true;
175 }
176
177 //================================================================================
178 /*!
179  * \brief Initialize my parameter values by default parameters.
180  *  \retval bool - true if parameter values have been successfully defined
181  */
182 //================================================================================
183
184 bool StdMeshers_FixedPoints1D::SetParametersByDefaults(const TDefaults&  dflts,
185                                                        const SMESH_Mesh* /*mesh*/)
186 {
187   _nbsegs.reserve( 1 );
188   _nbsegs.push_back( 1 );
189   return true;
190 }
191