Salome HOME
#18963 Minimize compiler warnings
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_Hypothesis.cxx
1 // Copyright (C) 2012-2015  ALNEOS
2 // Copyright (C) 2016-2020  EDF R&D
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.alneos.com/ or email : contact@alneos.fr
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //
21 #include "GMSHPlugin_Hypothesis.hxx"
22
23 #include "GMSHPlugin_Mesher.hxx"
24 #include "SMESH_Mesh.hxx"
25
26 #include <utilities.h>
27
28 using namespace std;
29
30
31 GMSHPlugin_Hypothesis::GMSHPlugin_Hypothesis (int hypId,
32                                                   SMESH_Gen * gen)
33   : SMESH_Hypothesis(hypId, gen),
34     _algo2d         (automatic),
35     _algo3d         (frontal3),
36     _recomb2DAlgo   (standard),
37     _recombineAll   (false),
38     _subdivAlgo     (none),
39     _remeshAlgo     (nosplit),
40     _remeshPara     (harmonic),
41     _smouthSteps    (1),
42     _sizeFactor     (1),
43     _minSize        (0),
44     _maxSize        (1e22),
45     _secondOrder    (false),
46     _useIncomplElem (true)
47 {
48   _name = "GMSH_Parameters";
49   _param_algo_dim = 3;
50 }
51
52 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
53 {
54   if (the2DAlgo != _algo2d)
55   {
56     _algo2d = the2DAlgo;
57     NotifySubMeshesHypothesisModification();
58   }
59 }
60
61 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
62 {
63   if (the3DAlgo != _algo3d)
64   {
65     _algo3d = the3DAlgo;
66     NotifySubMeshesHypothesisModification();
67   }
68 }
69
70 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
71 {
72   if (theRecomb2DAlgo != _recomb2DAlgo)
73   {
74     _recomb2DAlgo = theRecomb2DAlgo;
75     NotifySubMeshesHypothesisModification();
76   }
77 }
78
79 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
80 {
81   if (theRecombineAll != _recombineAll)
82   {
83     _recombineAll = theRecombineAll;
84     NotifySubMeshesHypothesisModification();
85   }
86 }
87
88 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
89 {
90   if (theSubdivAlgo != _subdivAlgo)
91   {
92     _subdivAlgo = theSubdivAlgo;
93     NotifySubMeshesHypothesisModification();
94   }
95 }
96
97 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
98 {
99   if (theRemeshAlgo != _remeshAlgo)
100   {
101     _remeshAlgo = theRemeshAlgo;
102     NotifySubMeshesHypothesisModification();
103   }
104 }
105
106 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
107 {
108   if (theRemeshPara != _remeshPara)
109   {
110     _remeshPara = theRemeshPara;
111     NotifySubMeshesHypothesisModification();
112   }
113 }
114
115 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
116 {
117   if (theSmouthSteps != _smouthSteps)
118   {
119     _smouthSteps = theSmouthSteps;
120     NotifySubMeshesHypothesisModification();
121   }
122 }
123
124 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
125 {
126   if (theSizeFactor != _sizeFactor)
127   {
128     _sizeFactor = theSizeFactor;
129     NotifySubMeshesHypothesisModification();
130   }
131 }
132
133 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
134 {
135   if (theUseIncomplElem != _useIncomplElem)
136   {
137     _useIncomplElem = theUseIncomplElem;
138     NotifySubMeshesHypothesisModification();
139   }
140 }
141
142 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
143 {
144   if (theSize != _maxSize)
145   {
146     _maxSize = theSize;
147     NotifySubMeshesHypothesisModification();
148   }
149 }
150
151 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
152 {
153   if (theSize != _minSize)
154   {
155     _minSize = theSize;
156     NotifySubMeshesHypothesisModification();
157   }
158 }
159
160 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
161 {
162   if (theVal != _secondOrder)
163   {
164     _secondOrder = theVal;
165     NotifySubMeshesHypothesisModification();
166   }
167 }
168
169 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
170 {
171   _is2d = theIs2d;
172 }
173
174
175 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
176 {
177   if (_compounds.find(entry) == _compounds.end())
178   {
179     _compounds.insert(entry);
180     NotifySubMeshesHypothesisModification();
181   }
182 }
183
184 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
185 {
186   if (_compounds.find(entry) != _compounds.end())
187   {
188     _compounds.erase(entry);
189     NotifySubMeshesHypothesisModification();
190   }
191 }
192
193 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
194 {
195   save << (int)_is2d << " " << _algo2d;
196   if (!_is2d)
197     save << " " << _algo3d;
198   save << " " << _recomb2DAlgo         <<
199           " " << (int)_recombineAll    <<
200           " " << _subdivAlgo           <<
201           " " << _remeshAlgo           <<
202           " " << _remeshPara           <<
203           " " << _smouthSteps          <<
204           " " << _sizeFactor           <<
205           " " << _maxSize              <<
206           " " << _minSize              <<
207           " " << (int)_secondOrder     <<
208           " " << (int)_useIncomplElem  ;
209   
210   save << " " << "__COMPOUNDS_BEGIN__";
211   for (TCompound::const_iterator it = _compounds.begin();  it != _compounds.end(); ++it )
212     save << " " << *it << " ";
213   save << " " << "__COMPOUNDS_END__";
214   
215   return save;
216 }
217
218 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
219 {
220   bool isOK = true;
221   int is;
222   double val;
223
224   isOK = static_cast<bool>(load >> is);
225   if (isOK)
226     _is2d = (bool)is;
227   else
228     load.clear(ios::badbit | load.rdstate());
229   
230   isOK = static_cast<bool>(load >> is);
231   if (isOK)
232     _algo2d = (Algo2D)is;
233   else
234     load.clear(ios::badbit | load.rdstate());
235   
236   if (!_is2d)
237   {
238     isOK = static_cast<bool>(load >> is);
239     if (isOK)
240       _algo3d = (Algo3D)is;
241     else
242       load.clear(ios::badbit | load.rdstate());
243   }
244   
245   isOK = static_cast<bool>(load >> is);
246   if (isOK)
247     _recomb2DAlgo = (Recomb2DAlgo)is;
248   else
249     load.clear(ios::badbit | load.rdstate());
250   
251   isOK = static_cast<bool>(load >> is);
252   if (isOK)
253     _recombineAll = (bool)is;
254   else
255     load.clear(ios::badbit | load.rdstate());
256   
257   isOK = static_cast<bool>(load >> is);
258   if (isOK)
259     _subdivAlgo = (SubdivAlgo)is;
260   else
261     load.clear(ios::badbit | load.rdstate());
262   
263   isOK = static_cast<bool>(load >> is);
264   if (isOK)
265     _remeshAlgo = (RemeshAlgo)is;
266   else
267     load.clear(ios::badbit | load.rdstate());
268   
269   isOK = static_cast<bool>(load >> is);
270   if (isOK)
271     _remeshPara = (RemeshPara)is;
272   else
273     load.clear(ios::badbit | load.rdstate());
274   
275   isOK = static_cast<bool>(load >> val);
276   if (isOK)
277     _smouthSteps = val;
278   else
279     load.clear(ios::badbit | load.rdstate());
280   
281   isOK = static_cast<bool>(load >> val);
282   if (isOK)
283     _sizeFactor = val;
284   else
285     load.clear(ios::badbit | load.rdstate());
286   
287   isOK = static_cast<bool>(load >> val);
288   if (isOK)
289     _maxSize = val;
290   else
291     load.clear(ios::badbit | load.rdstate());
292   
293   isOK = static_cast<bool>(load >> val);
294   if (isOK)
295     _minSize = val;
296   else
297     load.clear(ios::badbit | load.rdstate());
298   
299   isOK = static_cast<bool>(load >> is);
300   if (isOK)
301     _secondOrder = (bool)is;
302   else
303     load.clear(ios::badbit | load.rdstate());
304   
305   isOK = static_cast<bool>(load >> is);
306   if (isOK)
307     _useIncomplElem = (bool)is;
308   else
309     load.clear(ios::badbit | load.rdstate());
310   
311   
312   std::string entry;
313   isOK = static_cast<bool>(load >> entry);
314   if (isOK && entry == "__COMPOUNDS_BEGIN__")
315   {
316     while (isOK && entry != "__COMPOUNDS_END__")
317     {
318       isOK = static_cast<bool>(load >> entry);
319       if (isOK && entry != "__COMPOUNDS_END__")
320         _compounds.insert(entry);
321     }
322   }
323   return load;
324 }
325
326 //================================================================================
327 /*!
328  * \brief Does nothing
329  * \param theMesh - the built mesh
330  * \param theShape - the geometry of interest
331  * \retval bool - always false
332  */
333 //================================================================================
334 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   /*theMesh*/,
335                                                   const TopoDS_Shape& /*theShape*/)
336 {
337   return false;
338 }
339
340 //================================================================================
341 /*!
342  * \brief Initialize my parameter values by default parameters.
343  *  \retval bool - true if parameter values have been successfully defined
344  */
345 //================================================================================
346
347 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
348                                                     const SMESH_Mesh* /*theMesh*/)
349 {
350   //_nbSegPerEdge = dflts._nbSegments;
351   //_maxSize      = dflts._elemLength;
352
353   //if ( dflts._shape && !dflts._shape->IsNull() )
354   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
355   //else if ( theMesh && theMesh->HasShapeToMesh() )
356   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
357
358   //return _nbSegPerEdge && _maxSize > 0;
359   return false;
360 }