]> SALOME platform Git repositories - plugins/gmshplugin.git/blob - src/GMSHPlugin/GMSHPlugin_Hypothesis.cxx
Salome HOME
7e99d354d31a819a12a71c0409c1107801aec67a
[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
237   save << " " << "__COMPOUNDS_BEGIN__";
238   for (TCompound::const_iterator it = _compounds.begin();  it != _compounds.end(); ++it )
239     save << " " << *it << " ";
240   save << " " << "__COMPOUNDS_END__";
241
242   return save;
243 }
244
245 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
246 {
247   bool isOK = true;
248   int is;
249   double val;
250
251   isOK = static_cast<bool>(load >> is);
252   if (isOK)
253     _is2d = (bool)is;
254   else
255     load.clear(ios::badbit | load.rdstate());
256
257   isOK = static_cast<bool>(load >> is);
258   if (isOK)
259     _algo2d = (Algo2D)is;
260   else
261     load.clear(ios::badbit | load.rdstate());
262
263   if (!_is2d)
264   {
265     isOK = static_cast<bool>(load >> is);
266     if (isOK)
267       _algo3d = (Algo3D)is;
268     else
269       load.clear(ios::badbit | load.rdstate());
270   }
271
272   isOK = static_cast<bool>(load >> is);
273   if (isOK)
274     _recomb2DAlgo = (Recomb2DAlgo)is;
275   else
276     load.clear(ios::badbit | load.rdstate());
277
278   isOK = static_cast<bool>(load >> is);
279   if (isOK)
280     _recombineAll = (bool)is;
281   else
282     load.clear(ios::badbit | load.rdstate());
283
284   isOK = static_cast<bool>(load >> is);
285   if (isOK)
286     _subdivAlgo = (SubdivAlgo)is;
287   else
288     load.clear(ios::badbit | load.rdstate());
289
290   isOK = static_cast<bool>(load >> is);
291   if (isOK)
292     _remeshAlgo = (RemeshAlgo)is;
293   else
294     load.clear(ios::badbit | load.rdstate());
295
296   isOK = static_cast<bool>(load >> is);
297   if (isOK)
298     _remeshPara = (RemeshPara)is;
299   else
300     load.clear(ios::badbit | load.rdstate());
301
302   isOK = static_cast<bool>(load >> val);
303   if (isOK)
304     _smouthSteps = val;
305   else
306     load.clear(ios::badbit | load.rdstate());
307
308   isOK = static_cast<bool>(load >> val);
309   if (isOK)
310     _sizeFactor = val;
311   else
312     load.clear(ios::badbit | load.rdstate());
313
314 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
315   isOK = static_cast<bool>(load >> val);
316   if (isOK)
317     _meshCurvatureSize = val;
318   else
319     load.clear(ios::badbit | load.rdstate());
320 #endif
321
322   isOK = static_cast<bool>(load >> val);
323   if (isOK)
324     _maxSize = val;
325   else
326     load.clear(ios::badbit | load.rdstate());
327
328   isOK = static_cast<bool>(load >> val);
329   if (isOK)
330     _minSize = val;
331   else
332     load.clear(ios::badbit | load.rdstate());
333
334   isOK = static_cast<bool>(load >> is);
335   if (isOK)
336     _secondOrder = (bool)is;
337   else
338     load.clear(ios::badbit | load.rdstate());
339
340   isOK = static_cast<bool>(load >> is);
341   if (isOK)
342     _useIncomplElem = (bool)is;
343   else
344     load.clear(ios::badbit | load.rdstate());
345
346
347   std::string entry;
348   isOK = static_cast<bool>(load >> entry);
349   if (isOK && entry == "__COMPOUNDS_BEGIN__")
350   {
351     while (isOK && entry != "__COMPOUNDS_END__")
352     {
353       isOK = static_cast<bool>(load >> entry);
354       if (isOK && entry != "__COMPOUNDS_END__")
355         _compounds.insert(entry);
356     }
357   }
358   return load;
359 }
360
361 //================================================================================
362 /*!
363  * \brief Does nothing
364  * \param theMesh - the built mesh
365  * \param theShape - the geometry of interest
366  * \retval bool - always false
367  */
368 //================================================================================
369 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh*   /*theMesh*/,
370                                                   const TopoDS_Shape& /*theShape*/)
371 {
372   return false;
373 }
374
375 //================================================================================
376 /*!
377  * \brief Initialize my parameter values by default parameters.
378  *  \retval bool - true if parameter values have been successfully defined
379  */
380 //================================================================================
381
382 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults&  /*dflts*/,
383                                                     const SMESH_Mesh* /*theMesh*/)
384 {
385   //_nbSegPerEdge = dflts._nbSegments;
386   //_maxSize      = dflts._elemLength;
387
388   //if ( dflts._shape && !dflts._shape->IsNull() )
389   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
390   //else if ( theMesh && theMesh->HasShapeToMesh() )
391   //  _minSize    = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
392
393   //return _nbSegPerEdge && _maxSize > 0;
394   return false;
395 }