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