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