1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2023 EDF
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.
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
19 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "GMSHPlugin_Hypothesis.hxx"
23 #include "GMSHPlugin_Mesher.hxx"
24 #include "SMESH_Mesh.hxx"
26 #include <utilities.h>
31 GMSHPlugin_Hypothesis::GMSHPlugin_Hypothesis (int hypId,
33 : SMESH_Hypothesis(hypId, gen),
36 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=8
37 _recomb2DAlgo (simple),
39 _recomb2DAlgo (standard),
41 _recombineAll (false),
43 _remeshAlgo (nosplit),
44 _remeshPara (harmonic),
47 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
48 _meshCurvatureSize(0),
53 _useIncomplElem (true)
55 _name = "GMSH_Parameters";
59 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
61 if (the2DAlgo != _algo2d)
64 NotifySubMeshesHypothesisModification();
68 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
70 if (the3DAlgo != _algo3d)
73 NotifySubMeshesHypothesisModification();
77 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
79 if (theRecomb2DAlgo != _recomb2DAlgo)
81 _recomb2DAlgo = theRecomb2DAlgo;
82 NotifySubMeshesHypothesisModification();
86 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
88 if (theRecombineAll != _recombineAll)
90 _recombineAll = theRecombineAll;
91 NotifySubMeshesHypothesisModification();
95 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
97 if (theSubdivAlgo != _subdivAlgo)
99 _subdivAlgo = theSubdivAlgo;
100 NotifySubMeshesHypothesisModification();
104 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
106 if (theRemeshAlgo != _remeshAlgo)
108 _remeshAlgo = theRemeshAlgo;
109 NotifySubMeshesHypothesisModification();
113 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
115 if (theRemeshPara != _remeshPara)
117 _remeshPara = theRemeshPara;
118 NotifySubMeshesHypothesisModification();
122 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
124 if (theSmouthSteps != _smouthSteps)
126 _smouthSteps = theSmouthSteps;
127 NotifySubMeshesHypothesisModification();
131 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
133 if (theSizeFactor != _sizeFactor)
135 _sizeFactor = theSizeFactor;
136 NotifySubMeshesHypothesisModification();
140 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
142 if (theUseIncomplElem != _useIncomplElem)
144 _useIncomplElem = theUseIncomplElem;
145 NotifySubMeshesHypothesisModification();
149 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
150 void GMSHPlugin_Hypothesis::SetMeshCurvatureSize(double theMeshCurvatureSize)
152 if (theMeshCurvatureSize != _meshCurvatureSize)
154 _meshCurvatureSize = theMeshCurvatureSize;
155 NotifySubMeshesHypothesisModification();
160 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
162 if (theSize != _maxSize)
165 NotifySubMeshesHypothesisModification();
169 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
171 if (theSize != _minSize)
174 NotifySubMeshesHypothesisModification();
178 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
180 if (theVal != _secondOrder)
182 _secondOrder = theVal;
183 NotifySubMeshesHypothesisModification();
187 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
193 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
195 if (_compounds.find(entry) == _compounds.end())
197 _compounds.insert(entry);
198 NotifySubMeshesHypothesisModification();
202 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
204 if (_compounds.find(entry) != _compounds.end())
206 _compounds.erase(entry);
207 NotifySubMeshesHypothesisModification();
211 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
213 save << (int)_is2d << " " << _algo2d;
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 <<
228 " " << (int)_secondOrder <<
229 " " << (int)_useIncomplElem ;
231 save << " " << "__COMPOUNDS_BEGIN__";
232 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
233 save << " " << *it << " ";
234 save << " " << "__COMPOUNDS_END__";
239 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
245 isOK = static_cast<bool>(load >> is);
249 load.clear(ios::badbit | load.rdstate());
251 isOK = static_cast<bool>(load >> is);
253 _algo2d = (Algo2D)is;
255 load.clear(ios::badbit | load.rdstate());
259 isOK = static_cast<bool>(load >> is);
261 _algo3d = (Algo3D)is;
263 load.clear(ios::badbit | load.rdstate());
266 isOK = static_cast<bool>(load >> is);
268 _recomb2DAlgo = (Recomb2DAlgo)is;
270 load.clear(ios::badbit | load.rdstate());
272 isOK = static_cast<bool>(load >> is);
274 _recombineAll = (bool)is;
276 load.clear(ios::badbit | load.rdstate());
278 isOK = static_cast<bool>(load >> is);
280 _subdivAlgo = (SubdivAlgo)is;
282 load.clear(ios::badbit | load.rdstate());
284 isOK = static_cast<bool>(load >> is);
286 _remeshAlgo = (RemeshAlgo)is;
288 load.clear(ios::badbit | load.rdstate());
290 isOK = static_cast<bool>(load >> is);
292 _remeshPara = (RemeshPara)is;
294 load.clear(ios::badbit | load.rdstate());
296 isOK = static_cast<bool>(load >> val);
300 load.clear(ios::badbit | load.rdstate());
302 isOK = static_cast<bool>(load >> val);
306 load.clear(ios::badbit | load.rdstate());
308 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
309 isOK = static_cast<bool>(load >> val);
311 _meshCurvatureSize = val;
313 load.clear(ios::badbit | load.rdstate());
316 isOK = static_cast<bool>(load >> val);
320 load.clear(ios::badbit | load.rdstate());
322 isOK = static_cast<bool>(load >> val);
326 load.clear(ios::badbit | load.rdstate());
328 isOK = static_cast<bool>(load >> is);
330 _secondOrder = (bool)is;
332 load.clear(ios::badbit | load.rdstate());
334 isOK = static_cast<bool>(load >> is);
336 _useIncomplElem = (bool)is;
338 load.clear(ios::badbit | load.rdstate());
342 isOK = static_cast<bool>(load >> entry);
343 if (isOK && entry == "__COMPOUNDS_BEGIN__")
345 while (isOK && entry != "__COMPOUNDS_END__")
347 isOK = static_cast<bool>(load >> entry);
348 if (isOK && entry != "__COMPOUNDS_END__")
349 _compounds.insert(entry);
355 //================================================================================
357 * \brief Does nothing
358 * \param theMesh - the built mesh
359 * \param theShape - the geometry of interest
360 * \retval bool - always false
362 //================================================================================
363 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
364 const TopoDS_Shape& /*theShape*/)
369 //================================================================================
371 * \brief Initialize my parameter values by default parameters.
372 * \retval bool - true if parameter values have been successfully defined
374 //================================================================================
376 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
377 const SMESH_Mesh* /*theMesh*/)
379 //_nbSegPerEdge = dflts._nbSegments;
380 //_maxSize = dflts._elemLength;
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 );
387 //return _nbSegPerEdge && _maxSize > 0;