1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2024 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 <<
236 " " << (int)_verbLvl ;
238 save << " " << "__COMPOUNDS_BEGIN__";
239 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
240 save << " " << *it << " ";
241 save << " " << "__COMPOUNDS_END__";
246 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
252 isOK = static_cast<bool>(load >> is);
256 load.clear(ios::badbit | load.rdstate());
258 isOK = static_cast<bool>(load >> is);
260 _algo2d = (Algo2D)is;
262 load.clear(ios::badbit | load.rdstate());
266 isOK = static_cast<bool>(load >> is);
268 _algo3d = (Algo3D)is;
270 load.clear(ios::badbit | load.rdstate());
273 isOK = static_cast<bool>(load >> is);
275 _recomb2DAlgo = (Recomb2DAlgo)is;
277 load.clear(ios::badbit | load.rdstate());
279 isOK = static_cast<bool>(load >> is);
281 _recombineAll = (bool)is;
283 load.clear(ios::badbit | load.rdstate());
285 isOK = static_cast<bool>(load >> is);
287 _subdivAlgo = (SubdivAlgo)is;
289 load.clear(ios::badbit | load.rdstate());
291 isOK = static_cast<bool>(load >> is);
293 _remeshAlgo = (RemeshAlgo)is;
295 load.clear(ios::badbit | load.rdstate());
297 isOK = static_cast<bool>(load >> is);
299 _remeshPara = (RemeshPara)is;
301 load.clear(ios::badbit | load.rdstate());
303 isOK = static_cast<bool>(load >> val);
307 load.clear(ios::badbit | load.rdstate());
309 isOK = static_cast<bool>(load >> val);
313 load.clear(ios::badbit | load.rdstate());
315 #if GMSH_MAJOR_VERSION >=4 && GMSH_MINOR_VERSION >=10
316 isOK = static_cast<bool>(load >> val);
318 _meshCurvatureSize = val;
320 load.clear(ios::badbit | load.rdstate());
323 isOK = static_cast<bool>(load >> val);
327 load.clear(ios::badbit | load.rdstate());
329 isOK = static_cast<bool>(load >> val);
333 load.clear(ios::badbit | load.rdstate());
335 isOK = static_cast<bool>(load >> is);
337 _secondOrder = (bool)is;
339 load.clear(ios::badbit | load.rdstate());
341 isOK = static_cast<bool>(load >> is);
343 _useIncomplElem = (bool)is;
345 load.clear(ios::badbit | load.rdstate());
347 isOK = static_cast<bool>(load >> is);
349 _verbLvl = (Verbosity)is;
351 load.clear(ios::badbit | load.rdstate());
355 isOK = static_cast<bool>(load >> entry);
356 if (isOK && entry == "__COMPOUNDS_BEGIN__")
358 while (isOK && entry != "__COMPOUNDS_END__")
360 isOK = static_cast<bool>(load >> entry);
361 if (isOK && entry != "__COMPOUNDS_END__")
362 _compounds.insert(entry);
368 //================================================================================
370 * \brief Does nothing
371 * \param theMesh - the built mesh
372 * \param theShape - the geometry of interest
373 * \retval bool - always false
375 //================================================================================
376 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
377 const TopoDS_Shape& /*theShape*/)
382 //================================================================================
384 * \brief Initialize my parameter values by default parameters.
385 * \retval bool - true if parameter values have been successfully defined
387 //================================================================================
389 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
390 const SMESH_Mesh* /*theMesh*/)
392 //_nbSegPerEdge = dflts._nbSegments;
393 //_maxSize = dflts._elemLength;
395 //if ( dflts._shape && !dflts._shape->IsNull() )
396 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
397 //else if ( theMesh && theMesh->HasShapeToMesh() )
398 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
400 //return _nbSegPerEdge && _maxSize > 0;