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