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