Salome HOME
9a77eda52a4d82902f43f7ba491f1a295247bbf4
[plugins/gmshplugin.git] / src / GMSHPlugin / GMSHPlugin_Hypothesis.cxx
1 // Copyright (C) 2012-2015  ALNEOS
2 // Copyright (C) 2016-2023  EDF
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         (delaunay3),
36 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
37     _recomb2DAlgo   (simple),
38 #else
39     _recomb2DAlgo   (standard),
40 #endif
41     _recombineAll   (false),
42     _subdivAlgo     (none),
43     _remeshAlgo     (nosplit),
44     _remeshPara     (harmonic),
45     _smouthSteps    (1),
46     _sizeFactor     (1),
47 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
48     _meshCurvatureSize(0),
49 #endif
50     _minSize        (0),
51     _maxSize        (1e22),
52     _secondOrder    (false),
53     _useIncomplElem (true),
54     _verbLvl(status)
55 {
56   _name = "GMSH_Parameters";
57   _param_algo_dim = 3;
58 }
59
60 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
61 {
62   if (the2DAlgo != _algo2d)
63   {
64     _algo2d = the2DAlgo;
65     NotifySubMeshesHypothesisModification();
66   }
67 }
68
69 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
70 {
71   if (the3DAlgo != _algo3d)
72   {
73     _algo3d = the3DAlgo;
74     NotifySubMeshesHypothesisModification();
75   }
76 }
77
78 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
79 {
80   if (theRecomb2DAlgo != _recomb2DAlgo)
81   {
82     _recomb2DAlgo = theRecomb2DAlgo;
83     NotifySubMeshesHypothesisModification();
84   }
85 }
86
87 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
88 {
89   if (theRecombineAll != _recombineAll)
90   {
91     _recombineAll = theRecombineAll;
92     NotifySubMeshesHypothesisModification();
93   }
94 }
95
96 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
97 {
98   if (theSubdivAlgo != _subdivAlgo)
99   {
100     _subdivAlgo = theSubdivAlgo;
101     NotifySubMeshesHypothesisModification();
102   }
103 }
104
105 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
106 {
107   if (theRemeshAlgo != _remeshAlgo)
108   {
109     _remeshAlgo = theRemeshAlgo;
110     NotifySubMeshesHypothesisModification();
111   }
112 }
113
114 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
115 {
116   if (theRemeshPara != _remeshPara)
117   {
118     _remeshPara = theRemeshPara;
119     NotifySubMeshesHypothesisModification();
120   }
121 }
122
123 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
124 {
125   if (theSmouthSteps != _smouthSteps)
126   {
127     _smouthSteps = theSmouthSteps;
128     NotifySubMeshesHypothesisModification();
129   }
130 }
131
132 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
133 {
134   if (theSizeFactor != _sizeFactor)
135   {
136     _sizeFactor = theSizeFactor;
137     NotifySubMeshesHypothesisModification();
138   }
139 }
140
141 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
142 {
143   if (theUseIncomplElem != _useIncomplElem)
144   {
145     _useIncomplElem = theUseIncomplElem;
146     NotifySubMeshesHypothesisModification();
147   }
148 }
149
150 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
151 void GMSHPlugin_Hypothesis::SetMeshCurvatureSize(double theMeshCurvatureSize)
152 {
153   if (theMeshCurvatureSize != _meshCurvatureSize)
154   {
155     _meshCurvatureSize = theMeshCurvatureSize;
156     NotifySubMeshesHypothesisModification();
157   }
158 }
159 #endif
160
161 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
162 {
163   if (theSize != _maxSize)
164   {
165     _maxSize = theSize;
166     NotifySubMeshesHypothesisModification();
167   }
168 }
169
170 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
171 {
172   if (theSize != _minSize)
173   {
174     _minSize = theSize;
175     NotifySubMeshesHypothesisModification();
176   }
177 }
178
179 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
180 {
181   if (theVal != _secondOrder)
182   {
183     _secondOrder = theVal;
184     NotifySubMeshesHypothesisModification();
185   }
186 }
187
188 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
189 {
190   _is2d = theIs2d;
191 }
192
193 void GMSHPlugin_Hypothesis::SetVerbosityLevel(Verbosity theLevel)
194 {
195   _verbLvl = theLevel;
196 }
197
198
199 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
200 {
201   if (_compounds.find(entry) == _compounds.end())
202   {
203     _compounds.insert(entry);
204     NotifySubMeshesHypothesisModification();
205   }
206 }
207
208 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
209 {
210   if (_compounds.find(entry) != _compounds.end())
211   {
212     _compounds.erase(entry);
213     NotifySubMeshesHypothesisModification();
214   }
215 }
216
217 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
218 {
219   save << (int)_is2d << " " << _algo2d;
220   if (!_is2d)
221     save << " " << _algo3d;
222   save << " " << _recomb2DAlgo         <<
223           " " << (int)_recombineAll    <<
224           " " << _subdivAlgo           <<
225           " " << _remeshAlgo           <<
226           " " << _remeshPara           <<
227           " " << _smouthSteps          <<
228           " " << _sizeFactor           <<
229 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
230           " " << _meshCurvatureSize    <<
231 #endif
232           " " << _maxSize              <<
233           " " << _minSize              <<
234           " " << (int)_secondOrder     <<
235           " " << (int)_useIncomplElem  <<
236           " " << (int)_verbLvl         ;
237
238   save << " " << "__COMPOUNDS_BEGIN__";
239   for (TCompound::const_iterator it = _compounds.begin();  it != _compounds.end(); ++it )
240     save << " " << *it << " ";
241   save << " " << "__COMPOUNDS_END__";
242
243   return save;
244 }
245
246 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
247 {
248   bool isOK = true;
249   int is;
250   double val;
251
252   isOK = static_cast<bool>(load >> is);
253   if (isOK)
254     _is2d = (bool)is;
255   else
256     load.clear(ios::badbit | load.rdstate());
257
258   isOK = static_cast<bool>(load >> is);
259   if (isOK)
260     _algo2d = (Algo2D)is;
261   else
262     load.clear(ios::badbit | load.rdstate());
263
264   if (!_is2d)
265   {
266     isOK = static_cast<bool>(load >> is);
267     if (isOK)
268       _algo3d = (Algo3D)is;
269     else
270       load.clear(ios::badbit | load.rdstate());
271   }
272
273   isOK = static_cast<bool>(load >> is);
274   if (isOK)
275     _recomb2DAlgo = (Recomb2DAlgo)is;
276   else
277     load.clear(ios::badbit | load.rdstate());
278
279   isOK = static_cast<bool>(load >> is);
280   if (isOK)
281     _recombineAll = (bool)is;
282   else
283     load.clear(ios::badbit | load.rdstate());
284
285   isOK = static_cast<bool>(load >> is);
286   if (isOK)
287     _subdivAlgo = (SubdivAlgo)is;
288   else
289     load.clear(ios::badbit | load.rdstate());
290
291   isOK = static_cast<bool>(load >> is);
292   if (isOK)
293     _remeshAlgo = (RemeshAlgo)is;
294   else
295     load.clear(ios::badbit | load.rdstate());
296
297   isOK = static_cast<bool>(load >> is);
298   if (isOK)
299     _remeshPara = (RemeshPara)is;
300   else
301     load.clear(ios::badbit | load.rdstate());
302
303   isOK = static_cast<bool>(load >> val);
304   if (isOK)
305     _smouthSteps = val;
306   else
307     load.clear(ios::badbit | load.rdstate());
308
309   isOK = static_cast<bool>(load >> val);
310   if (isOK)
311     _sizeFactor = val;
312   else
313     load.clear(ios::badbit | load.rdstate());
314
315 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
316   isOK = static_cast<bool>(load >> val);
317   if (isOK)
318     _meshCurvatureSize = val;
319   else
320     load.clear(ios::badbit | load.rdstate());
321 #endif
322
323   isOK = static_cast<bool>(load >> val);
324   if (isOK)
325     _maxSize = val;
326   else
327     load.clear(ios::badbit | load.rdstate());
328
329   isOK = static_cast<bool>(load >> val);
330   if (isOK)
331     _minSize = val;
332   else
333     load.clear(ios::badbit | load.rdstate());
334
335   isOK = static_cast<bool>(load >> is);
336   if (isOK)
337     _secondOrder = (bool)is;
338   else
339     load.clear(ios::badbit | load.rdstate());
340
341   isOK = static_cast<bool>(load >> is);
342   if (isOK)
343     _useIncomplElem = (bool)is;
344   else
345     load.clear(ios::badbit | load.rdstate());
346
347   isOK = static_cast<bool>(load >> is);
348   if (isOK)
349     _verbLvl = (Verbosity)is;
350   else
351     load.clear(ios::badbit | load.rdstate());
352
353
354   std::string entry;
355   isOK = static_cast<bool>(load >> entry);
356   if (isOK && entry == "__COMPOUNDS_BEGIN__")
357   {
358     while (isOK && entry != "__COMPOUNDS_END__")
359     {
360       isOK = static_cast<bool>(load >> entry);
361       if (isOK && entry != "__COMPOUNDS_END__")
362         _compounds.insert(entry);
363     }
364   }
365   return load;
366 }
367
368 //================================================================================
369 /*!
370  * \brief Does nothing
371  * \param theMesh - the built mesh
372  * \param theShape - the geometry of interest
373  * \retval bool - always false
374  */
375 //================================================================================
376 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   /*theMesh*/,
377                                                   const TopoDS_Shape& /*theShape*/)
378 {
379   return false;
380 }
381
382 //================================================================================
383 /*!
384  * \brief Initialize my parameter values by default parameters.
385  *  \retval bool - true if parameter values have been successfully defined
386  */
387 //================================================================================
388
389 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
390                                                     const SMESH_Mesh* /*theMesh*/)
391 {
392   //_nbSegPerEdge = dflts._nbSegments;
393   //_maxSize      = dflts._elemLength;
394
395   //if ( dflts._shape && !dflts._shape->IsNull() )
396   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
397   //else if ( theMesh && theMesh->HasShapeToMesh() )
398   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
399
400   //return _nbSegPerEdge && _maxSize > 0;
401   return false;
402 }