1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2022 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, 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),
50 _useIncomplElem (true)
52 _name = "GMSH_Parameters";
56 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
58 if (the2DAlgo != _algo2d)
61 NotifySubMeshesHypothesisModification();
65 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
67 if (the3DAlgo != _algo3d)
70 NotifySubMeshesHypothesisModification();
74 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
76 if (theRecomb2DAlgo != _recomb2DAlgo)
78 _recomb2DAlgo = theRecomb2DAlgo;
79 NotifySubMeshesHypothesisModification();
83 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
85 if (theRecombineAll != _recombineAll)
87 _recombineAll = theRecombineAll;
88 NotifySubMeshesHypothesisModification();
92 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
94 if (theSubdivAlgo != _subdivAlgo)
96 _subdivAlgo = theSubdivAlgo;
97 NotifySubMeshesHypothesisModification();
101 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
103 if (theRemeshAlgo != _remeshAlgo)
105 _remeshAlgo = theRemeshAlgo;
106 NotifySubMeshesHypothesisModification();
110 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
112 if (theRemeshPara != _remeshPara)
114 _remeshPara = theRemeshPara;
115 NotifySubMeshesHypothesisModification();
119 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
121 if (theSmouthSteps != _smouthSteps)
123 _smouthSteps = theSmouthSteps;
124 NotifySubMeshesHypothesisModification();
128 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
130 if (theSizeFactor != _sizeFactor)
132 _sizeFactor = theSizeFactor;
133 NotifySubMeshesHypothesisModification();
137 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
139 if (theUseIncomplElem != _useIncomplElem)
141 _useIncomplElem = theUseIncomplElem;
142 NotifySubMeshesHypothesisModification();
146 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
148 if (theSize != _maxSize)
151 NotifySubMeshesHypothesisModification();
155 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
157 if (theSize != _minSize)
160 NotifySubMeshesHypothesisModification();
164 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
166 if (theVal != _secondOrder)
168 _secondOrder = theVal;
169 NotifySubMeshesHypothesisModification();
173 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
179 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
181 if (_compounds.find(entry) == _compounds.end())
183 _compounds.insert(entry);
184 NotifySubMeshesHypothesisModification();
188 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
190 if (_compounds.find(entry) != _compounds.end())
192 _compounds.erase(entry);
193 NotifySubMeshesHypothesisModification();
197 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
199 save << (int)_is2d << " " << _algo2d;
201 save << " " << _algo3d;
202 save << " " << _recomb2DAlgo <<
203 " " << (int)_recombineAll <<
204 " " << _subdivAlgo <<
205 " " << _remeshAlgo <<
206 " " << _remeshPara <<
207 " " << _smouthSteps <<
208 " " << _sizeFactor <<
211 " " << (int)_secondOrder <<
212 " " << (int)_useIncomplElem ;
214 save << " " << "__COMPOUNDS_BEGIN__";
215 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
216 save << " " << *it << " ";
217 save << " " << "__COMPOUNDS_END__";
222 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
228 isOK = static_cast<bool>(load >> is);
232 load.clear(ios::badbit | load.rdstate());
234 isOK = static_cast<bool>(load >> is);
236 _algo2d = (Algo2D)is;
238 load.clear(ios::badbit | load.rdstate());
242 isOK = static_cast<bool>(load >> is);
244 _algo3d = (Algo3D)is;
246 load.clear(ios::badbit | load.rdstate());
249 isOK = static_cast<bool>(load >> is);
251 _recomb2DAlgo = (Recomb2DAlgo)is;
253 load.clear(ios::badbit | load.rdstate());
255 isOK = static_cast<bool>(load >> is);
257 _recombineAll = (bool)is;
259 load.clear(ios::badbit | load.rdstate());
261 isOK = static_cast<bool>(load >> is);
263 _subdivAlgo = (SubdivAlgo)is;
265 load.clear(ios::badbit | load.rdstate());
267 isOK = static_cast<bool>(load >> is);
269 _remeshAlgo = (RemeshAlgo)is;
271 load.clear(ios::badbit | load.rdstate());
273 isOK = static_cast<bool>(load >> is);
275 _remeshPara = (RemeshPara)is;
277 load.clear(ios::badbit | load.rdstate());
279 isOK = static_cast<bool>(load >> val);
283 load.clear(ios::badbit | load.rdstate());
285 isOK = static_cast<bool>(load >> val);
289 load.clear(ios::badbit | load.rdstate());
291 isOK = static_cast<bool>(load >> val);
295 load.clear(ios::badbit | load.rdstate());
297 isOK = static_cast<bool>(load >> val);
301 load.clear(ios::badbit | load.rdstate());
303 isOK = static_cast<bool>(load >> is);
305 _secondOrder = (bool)is;
307 load.clear(ios::badbit | load.rdstate());
309 isOK = static_cast<bool>(load >> is);
311 _useIncomplElem = (bool)is;
313 load.clear(ios::badbit | load.rdstate());
317 isOK = static_cast<bool>(load >> entry);
318 if (isOK && entry == "__COMPOUNDS_BEGIN__")
320 while (isOK && entry != "__COMPOUNDS_END__")
322 isOK = static_cast<bool>(load >> entry);
323 if (isOK && entry != "__COMPOUNDS_END__")
324 _compounds.insert(entry);
330 //================================================================================
332 * \brief Does nothing
333 * \param theMesh - the built mesh
334 * \param theShape - the geometry of interest
335 * \retval bool - always false
337 //================================================================================
338 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
339 const TopoDS_Shape& /*theShape*/)
344 //================================================================================
346 * \brief Initialize my parameter values by default parameters.
347 * \retval bool - true if parameter values have been successfully defined
349 //================================================================================
351 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
352 const SMESH_Mesh* /*theMesh*/)
354 //_nbSegPerEdge = dflts._nbSegments;
355 //_maxSize = dflts._elemLength;
357 //if ( dflts._shape && !dflts._shape->IsNull() )
358 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
359 //else if ( theMesh && theMesh->HasShapeToMesh() )
360 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
362 //return _nbSegPerEdge && _maxSize > 0;