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