Salome HOME
23514: EDF 16031 - SMESH freezes
[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 : 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 using namespace std;
31
32 //=============================================================================
33 /*!
34  *  
35  */
36 //=============================================================================
37
38 StdMeshers_FixedPoints1D::StdMeshers_FixedPoints1D(int hypId, int studyId,
39                                                    SMESH_Gen * gen)
40   :SMESH_Hypothesis(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 //=============================================================================
85 /*!
86  *  
87  */
88 //=============================================================================
89
90 void StdMeshers_FixedPoints1D::SetReversedEdges( std::vector<int>& ids )
91 {
92   if ( ids != _edgeIDs ) {
93     _edgeIDs = ids;
94
95     NotifySubMeshesHypothesisModification();
96   }
97 }
98
99 //=============================================================================
100 /*!
101  *  
102  */
103 //=============================================================================
104
105 ostream & StdMeshers_FixedPoints1D::SaveTo(ostream & save)
106 {
107   int listSize = _params.size();
108   save << listSize;
109   if ( listSize > 0 ) {
110     for ( int i = 0; i < listSize; i++) save << " " << _params[i];
111   }
112
113   listSize = _nbsegs.size();
114   save << " " << listSize;
115   if ( listSize > 0 ) {
116     for ( int i = 0; i < listSize; i++) save << " " << _nbsegs[i];
117   }
118
119   listSize = _edgeIDs.size();
120   save << " " << listSize;
121   if ( listSize > 0 ) {
122     for ( int i = 0; i < listSize; i++)
123       save << " " << _edgeIDs[i];
124   }
125
126   save << " " << _objEntry;
127
128   return save;
129 }
130
131 //=============================================================================
132 /*!
133  *
134  */
135 //=============================================================================
136
137 istream & StdMeshers_FixedPoints1D::LoadFrom(istream & load)
138 {
139   bool isOK = true;
140   int intVal;
141   double dblVal;
142
143   isOK = static_cast<bool>(load >> intVal);
144   if (isOK && intVal > 0) {
145     _params.clear();
146     _params.reserve( intVal );
147     for ( size_t i = 0; i < _params.capacity() && isOK; i++) {
148       isOK = static_cast<bool>(load >> dblVal);
149       if ( isOK ) _params.push_back( dblVal );
150     }
151   }
152
153   isOK = static_cast<bool>(load >> intVal);
154   if (isOK && intVal > 0) {
155     _nbsegs.clear();
156     _nbsegs.reserve( intVal );
157     for ( size_t i = 0; i < _nbsegs.capacity() && isOK; i++) {
158       isOK = static_cast<bool>(load >> intVal);
159       if ( isOK ) _nbsegs.push_back( intVal );
160     }
161   }
162
163   isOK = static_cast<bool>(load >> intVal);
164   if (isOK && intVal > 0) {
165     _edgeIDs.clear();
166     _edgeIDs.reserve( intVal );
167     for ( size_t i = 0; i < _edgeIDs.capacity() && isOK; i++) {
168       isOK = static_cast<bool>(load >> intVal);
169       if ( isOK ) _edgeIDs.push_back( intVal );
170     }
171   }
172
173   isOK = static_cast<bool>(load >> _objEntry);
174
175   return load;
176 }
177
178 //================================================================================
179 /*!
180  * \brief Initialize start and end length by the mesh built on the geometry
181  * \param theMesh - the built mesh
182  * \param theShape - the geometry of interest
183  * \retval bool - true if parameter values have been successfully defined
184  */
185 //================================================================================
186
187 bool StdMeshers_FixedPoints1D::SetParametersByMesh(const SMESH_Mesh*   theMesh,
188                                                    const TopoDS_Shape& theShape)
189 {
190   if ( !theMesh || theShape.IsNull() )
191     return false;
192
193   _nbsegs.reserve( 1 );
194   _nbsegs.push_back( 1 );
195   return true;
196 }
197
198 //================================================================================
199 /*!
200  * \brief Initialize my parameter values by default parameters.
201  *  \retval bool - true if parameter values have been successfully defined
202  */
203 //================================================================================
204
205 bool StdMeshers_FixedPoints1D::SetParametersByDefaults(const TDefaults&  dflts,
206                                                        const SMESH_Mesh* /*mesh*/)
207 {
208   _nbsegs.reserve( 1 );
209   _nbsegs.push_back( 1 );
210   return true;
211 }
212