1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016 EDF R&D
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.
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.
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
18 // See http://www.alneos.com/ or email : contact@alneos.fr
20 #include "GMSHPlugin_Hypothesis.hxx"
22 #include "GMSHPlugin_Mesher.hxx"
23 #include "SMESH_Mesh.hxx"
25 #include <utilities.h>
30 GMSHPlugin_Hypothesis::GMSHPlugin_Hypothesis (int hypId, int studyId,
32 : SMESH_Hypothesis(hypId, studyId, gen),
35 _recomb2DAlgo (standard),
36 _recombineAll (false),
38 _remeshAlgo (nosplit),
39 _remeshPara (harmonic),
45 _useIncomplElem (true)
47 _name = "GMSH_Parameters";
51 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
53 if (the2DAlgo != _algo2d)
56 NotifySubMeshesHypothesisModification();
60 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
62 if (the3DAlgo != _algo3d)
65 NotifySubMeshesHypothesisModification();
69 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
71 if (theRecomb2DAlgo != _recomb2DAlgo)
73 _recomb2DAlgo = theRecomb2DAlgo;
74 NotifySubMeshesHypothesisModification();
78 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
80 if (theRecombineAll != _recombineAll)
82 _recombineAll = theRecombineAll;
83 NotifySubMeshesHypothesisModification();
87 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
89 if (theSubdivAlgo != _subdivAlgo)
91 _subdivAlgo = theSubdivAlgo;
92 NotifySubMeshesHypothesisModification();
96 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
98 if (theRemeshAlgo != _remeshAlgo)
100 _remeshAlgo = theRemeshAlgo;
101 NotifySubMeshesHypothesisModification();
105 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
107 if (theRemeshPara != _remeshPara)
109 _remeshPara = theRemeshPara;
110 NotifySubMeshesHypothesisModification();
114 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
116 if (theSmouthSteps != _smouthSteps)
118 _smouthSteps = theSmouthSteps;
119 NotifySubMeshesHypothesisModification();
123 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
125 if (theSizeFactor != _sizeFactor)
127 _sizeFactor = theSizeFactor;
128 NotifySubMeshesHypothesisModification();
132 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
134 if (theUseIncomplElem != _useIncomplElem)
136 _useIncomplElem = theUseIncomplElem;
137 NotifySubMeshesHypothesisModification();
141 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
143 if (theSize != _maxSize)
146 NotifySubMeshesHypothesisModification();
150 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
152 if (theSize != _minSize)
155 NotifySubMeshesHypothesisModification();
159 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
161 if (theVal != _secondOrder)
163 _secondOrder = theVal;
164 NotifySubMeshesHypothesisModification();
168 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
174 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
176 if (_compounds.find(entry) == _compounds.end())
178 _compounds.insert(entry);
179 NotifySubMeshesHypothesisModification();
183 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
185 if (_compounds.find(entry) != _compounds.end())
187 _compounds.erase(entry);
188 NotifySubMeshesHypothesisModification();
192 ostream & GMSHPlugin_Hypothesis::SaveTo(ostream & save)
194 save << (int)_is2d << " " << _algo2d;
196 save << " " << _algo3d;
197 save << " " << _recomb2DAlgo <<
198 " " << (int)_recombineAll <<
199 " " << _subdivAlgo <<
200 " " << _remeshAlgo <<
201 " " << _remeshPara <<
202 " " << _smouthSteps <<
203 " " << _sizeFactor <<
206 " " << (int)_secondOrder <<
207 " " << (int)_useIncomplElem ;
209 save << " " << "__COMPOUNDS_BEGIN__";
210 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
211 save << " " << *it << " ";
212 save << " " << "__COMPOUNDS_END__";
217 istream & GMSHPlugin_Hypothesis::LoadFrom(istream & load)
223 isOK = static_cast<bool>(load >> is);
227 load.clear(ios::badbit | load.rdstate());
229 isOK = static_cast<bool>(load >> is);
231 _algo2d = (Algo2D)is;
233 load.clear(ios::badbit | load.rdstate());
237 isOK = static_cast<bool>(load >> is);
239 _algo3d = (Algo3D)is;
241 load.clear(ios::badbit | load.rdstate());
244 isOK = static_cast<bool>(load >> is);
246 _recomb2DAlgo = (Recomb2DAlgo)is;
248 load.clear(ios::badbit | load.rdstate());
250 isOK = static_cast<bool>(load >> is);
252 _recombineAll = (bool)is;
254 load.clear(ios::badbit | load.rdstate());
256 isOK = static_cast<bool>(load >> is);
258 _subdivAlgo = (SubdivAlgo)is;
260 load.clear(ios::badbit | load.rdstate());
262 isOK = static_cast<bool>(load >> is);
264 _remeshAlgo = (RemeshAlgo)is;
266 load.clear(ios::badbit | load.rdstate());
268 isOK = static_cast<bool>(load >> is);
270 _remeshPara = (RemeshPara)is;
272 load.clear(ios::badbit | load.rdstate());
274 isOK = static_cast<bool>(load >> val);
278 load.clear(ios::badbit | load.rdstate());
280 isOK = static_cast<bool>(load >> val);
284 load.clear(ios::badbit | load.rdstate());
286 isOK = static_cast<bool>(load >> val);
290 load.clear(ios::badbit | load.rdstate());
292 isOK = static_cast<bool>(load >> val);
296 load.clear(ios::badbit | load.rdstate());
298 isOK = static_cast<bool>(load >> is);
300 _secondOrder = (bool)is;
302 load.clear(ios::badbit | load.rdstate());
304 isOK = static_cast<bool>(load >> is);
306 _useIncomplElem = (bool)is;
308 load.clear(ios::badbit | load.rdstate());
312 isOK = static_cast<bool>(load >> entry);
313 if (isOK && entry == "__COMPOUNDS_BEGIN__")
315 while (isOK && entry != "__COMPOUNDS_END__")
317 isOK = static_cast<bool>(load >> entry);
318 if (isOK && entry != "__COMPOUNDS_END__")
319 _compounds.insert(entry);
325 ostream & operator <<(ostream & save, GMSHPlugin_Hypothesis & hyp)
327 return hyp.SaveTo( save );
330 istream & operator >>(istream & load, GMSHPlugin_Hypothesis & hyp)
332 return hyp.LoadFrom( load );
336 //================================================================================
338 * \brief Does nothing
339 * \param theMesh - the built mesh
340 * \param theShape - the geometry of interest
341 * \retval bool - always false
343 //================================================================================
344 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
345 const TopoDS_Shape& theShape)
350 //================================================================================
352 * \brief Initialize my parameter values by default parameters.
353 * \retval bool - true if parameter values have been successfully defined
355 //================================================================================
357 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
358 const SMESH_Mesh* theMesh)
360 //_nbSegPerEdge = dflts._nbSegments;
361 //_maxSize = dflts._elemLength;
363 //if ( dflts._shape && !dflts._shape->IsNull() )
364 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
365 //else if ( theMesh && theMesh->HasShapeToMesh() )
366 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
368 //return _nbSegPerEdge && _maxSize > 0;