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