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),
56 _name = "GMSH_Parameters";
60 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
62 if (the2DAlgo != _algo2d)
65 NotifySubMeshesHypothesisModification();
69 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
71 if (the3DAlgo != _algo3d)
74 NotifySubMeshesHypothesisModification();
78 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
80 if (theRecomb2DAlgo != _recomb2DAlgo)
82 _recomb2DAlgo = theRecomb2DAlgo;
83 NotifySubMeshesHypothesisModification();
87 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
89 if (theRecombineAll != _recombineAll)
91 _recombineAll = theRecombineAll;
92 NotifySubMeshesHypothesisModification();
96 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
98 if (theSubdivAlgo != _subdivAlgo)
100 _subdivAlgo = theSubdivAlgo;
101 NotifySubMeshesHypothesisModification();
105 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
107 if (theRemeshAlgo != _remeshAlgo)
109 _remeshAlgo = theRemeshAlgo;
110 NotifySubMeshesHypothesisModification();
114 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
116 if (theRemeshPara != _remeshPara)
118 _remeshPara = theRemeshPara;
119 NotifySubMeshesHypothesisModification();
123 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
125 if (theSmouthSteps != _smouthSteps)
127 _smouthSteps = theSmouthSteps;
128 NotifySubMeshesHypothesisModification();
132 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
134 if (theSizeFactor != _sizeFactor)
136 _sizeFactor = theSizeFactor;
137 NotifySubMeshesHypothesisModification();
141 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
143 if (theUseIncomplElem != _useIncomplElem)
145 _useIncomplElem = theUseIncomplElem;
146 NotifySubMeshesHypothesisModification();
150 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
151 void GMSHPlugin_Hypothesis::SetMeshCurvatureSize(double theMeshCurvatureSize)
153 if (theMeshCurvatureSize != _meshCurvatureSize)
155 _meshCurvatureSize = theMeshCurvatureSize;
156 NotifySubMeshesHypothesisModification();
161 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
163 if (theSize != _maxSize)
166 NotifySubMeshesHypothesisModification();
170 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
172 if (theSize != _minSize)
175 NotifySubMeshesHypothesisModification();
179 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
181 if (theVal != _secondOrder)
183 _secondOrder = theVal;
184 NotifySubMeshesHypothesisModification();
188 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
193 void GMSHPlugin_Hypothesis::SetVerbosityLevel(Verbosity theLevel)
199 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
201 if (_compounds.find(entry) == _compounds.end())
203 _compounds.insert(entry);
204 NotifySubMeshesHypothesisModification();
208 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
210 if (_compounds.find(entry) != _compounds.end())
212 _compounds.erase(entry);
213 NotifySubMeshesHypothesisModification();
217 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
219 save << (int)_is2d << " " << _algo2d;
221 save << " " << _algo3d;
222 save << " " << _recomb2DAlgo <<
223 " " << (int)_recombineAll <<
224 " " << _subdivAlgo <<
225 " " << _remeshAlgo <<
226 " " << _remeshPara <<
227 " " << _smouthSteps <<
228 " " << _sizeFactor <<
229 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
230 " " << _meshCurvatureSize <<
234 " " << (int)_secondOrder <<
235 " " << (int)_useIncomplElem ;
237 save << " " << "__COMPOUNDS_BEGIN__";
238 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
239 save << " " << *it << " ";
240 save << " " << "__COMPOUNDS_END__";
245 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
251 isOK = static_cast<bool>(load >> is);
255 load.clear(ios::badbit | load.rdstate());
257 isOK = static_cast<bool>(load >> is);
259 _algo2d = (Algo2D)is;
261 load.clear(ios::badbit | load.rdstate());
265 isOK = static_cast<bool>(load >> is);
267 _algo3d = (Algo3D)is;
269 load.clear(ios::badbit | load.rdstate());
272 isOK = static_cast<bool>(load >> is);
274 _recomb2DAlgo = (Recomb2DAlgo)is;
276 load.clear(ios::badbit | load.rdstate());
278 isOK = static_cast<bool>(load >> is);
280 _recombineAll = (bool)is;
282 load.clear(ios::badbit | load.rdstate());
284 isOK = static_cast<bool>(load >> is);
286 _subdivAlgo = (SubdivAlgo)is;
288 load.clear(ios::badbit | load.rdstate());
290 isOK = static_cast<bool>(load >> is);
292 _remeshAlgo = (RemeshAlgo)is;
294 load.clear(ios::badbit | load.rdstate());
296 isOK = static_cast<bool>(load >> is);
298 _remeshPara = (RemeshPara)is;
300 load.clear(ios::badbit | load.rdstate());
302 isOK = static_cast<bool>(load >> val);
306 load.clear(ios::badbit | load.rdstate());
308 isOK = static_cast<bool>(load >> val);
312 load.clear(ios::badbit | load.rdstate());
314 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
315 isOK = static_cast<bool>(load >> val);
317 _meshCurvatureSize = val;
319 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 >> val);
332 load.clear(ios::badbit | load.rdstate());
334 isOK = static_cast<bool>(load >> is);
336 _secondOrder = (bool)is;
338 load.clear(ios::badbit | load.rdstate());
340 isOK = static_cast<bool>(load >> is);
342 _useIncomplElem = (bool)is;
344 load.clear(ios::badbit | load.rdstate());
348 isOK = static_cast<bool>(load >> entry);
349 if (isOK && entry == "__COMPOUNDS_BEGIN__")
351 while (isOK && entry != "__COMPOUNDS_END__")
353 isOK = static_cast<bool>(load >> entry);
354 if (isOK && entry != "__COMPOUNDS_END__")
355 _compounds.insert(entry);
361 //================================================================================
363 * \brief Does nothing
364 * \param theMesh - the built mesh
365 * \param theShape - the geometry of interest
366 * \retval bool - always false
368 //================================================================================
369 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
370 const TopoDS_Shape& /*theShape*/)
375 //================================================================================
377 * \brief Initialize my parameter values by default parameters.
378 * \retval bool - true if parameter values have been successfully defined
380 //================================================================================
382 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
383 const SMESH_Mesh* /*theMesh*/)
385 //_nbSegPerEdge = dflts._nbSegments;
386 //_maxSize = dflts._elemLength;
388 //if ( dflts._shape && !dflts._shape->IsNull() )
389 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
390 //else if ( theMesh && theMesh->HasShapeToMesh() )
391 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
393 //return _nbSegPerEdge && _maxSize > 0;