1 // Copyright (C) 2012-2015 ALNEOS
2 // Copyright (C) 2016-2021 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 _recomb2DAlgo (standard),
37 _recombineAll (false),
39 _remeshAlgo (nosplit),
40 _remeshPara (harmonic),
46 _useIncomplElem (true)
48 _name = "GMSH_Parameters";
52 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
54 if (the2DAlgo != _algo2d)
57 NotifySubMeshesHypothesisModification();
61 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
63 if (the3DAlgo != _algo3d)
66 NotifySubMeshesHypothesisModification();
70 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
72 if (theRecomb2DAlgo != _recomb2DAlgo)
74 _recomb2DAlgo = theRecomb2DAlgo;
75 NotifySubMeshesHypothesisModification();
79 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
81 if (theRecombineAll != _recombineAll)
83 _recombineAll = theRecombineAll;
84 NotifySubMeshesHypothesisModification();
88 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
90 if (theSubdivAlgo != _subdivAlgo)
92 _subdivAlgo = theSubdivAlgo;
93 NotifySubMeshesHypothesisModification();
97 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
99 if (theRemeshAlgo != _remeshAlgo)
101 _remeshAlgo = theRemeshAlgo;
102 NotifySubMeshesHypothesisModification();
106 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
108 if (theRemeshPara != _remeshPara)
110 _remeshPara = theRemeshPara;
111 NotifySubMeshesHypothesisModification();
115 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
117 if (theSmouthSteps != _smouthSteps)
119 _smouthSteps = theSmouthSteps;
120 NotifySubMeshesHypothesisModification();
124 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
126 if (theSizeFactor != _sizeFactor)
128 _sizeFactor = theSizeFactor;
129 NotifySubMeshesHypothesisModification();
133 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
135 if (theUseIncomplElem != _useIncomplElem)
137 _useIncomplElem = theUseIncomplElem;
138 NotifySubMeshesHypothesisModification();
142 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
144 if (theSize != _maxSize)
147 NotifySubMeshesHypothesisModification();
151 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
153 if (theSize != _minSize)
156 NotifySubMeshesHypothesisModification();
160 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
162 if (theVal != _secondOrder)
164 _secondOrder = theVal;
165 NotifySubMeshesHypothesisModification();
169 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
175 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
177 if (_compounds.find(entry) == _compounds.end())
179 _compounds.insert(entry);
180 NotifySubMeshesHypothesisModification();
184 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
186 if (_compounds.find(entry) != _compounds.end())
188 _compounds.erase(entry);
189 NotifySubMeshesHypothesisModification();
193 std::ostream & GMSHPlugin_Hypothesis::SaveTo(std::ostream & save)
195 save << (int)_is2d << " " << _algo2d;
197 save << " " << _algo3d;
198 save << " " << _recomb2DAlgo <<
199 " " << (int)_recombineAll <<
200 " " << _subdivAlgo <<
201 " " << _remeshAlgo <<
202 " " << _remeshPara <<
203 " " << _smouthSteps <<
204 " " << _sizeFactor <<
207 " " << (int)_secondOrder <<
208 " " << (int)_useIncomplElem ;
210 save << " " << "__COMPOUNDS_BEGIN__";
211 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
212 save << " " << *it << " ";
213 save << " " << "__COMPOUNDS_END__";
218 std::istream & GMSHPlugin_Hypothesis::LoadFrom(std::istream & load)
224 isOK = static_cast<bool>(load >> is);
228 load.clear(ios::badbit | load.rdstate());
230 isOK = static_cast<bool>(load >> is);
232 _algo2d = (Algo2D)is;
234 load.clear(ios::badbit | load.rdstate());
238 isOK = static_cast<bool>(load >> is);
240 _algo3d = (Algo3D)is;
242 load.clear(ios::badbit | load.rdstate());
245 isOK = static_cast<bool>(load >> is);
247 _recomb2DAlgo = (Recomb2DAlgo)is;
249 load.clear(ios::badbit | load.rdstate());
251 isOK = static_cast<bool>(load >> is);
253 _recombineAll = (bool)is;
255 load.clear(ios::badbit | load.rdstate());
257 isOK = static_cast<bool>(load >> is);
259 _subdivAlgo = (SubdivAlgo)is;
261 load.clear(ios::badbit | load.rdstate());
263 isOK = static_cast<bool>(load >> is);
265 _remeshAlgo = (RemeshAlgo)is;
267 load.clear(ios::badbit | load.rdstate());
269 isOK = static_cast<bool>(load >> is);
271 _remeshPara = (RemeshPara)is;
273 load.clear(ios::badbit | load.rdstate());
275 isOK = static_cast<bool>(load >> val);
279 load.clear(ios::badbit | load.rdstate());
281 isOK = static_cast<bool>(load >> val);
285 load.clear(ios::badbit | load.rdstate());
287 isOK = static_cast<bool>(load >> val);
291 load.clear(ios::badbit | load.rdstate());
293 isOK = static_cast<bool>(load >> val);
297 load.clear(ios::badbit | load.rdstate());
299 isOK = static_cast<bool>(load >> is);
301 _secondOrder = (bool)is;
303 load.clear(ios::badbit | load.rdstate());
305 isOK = static_cast<bool>(load >> is);
307 _useIncomplElem = (bool)is;
309 load.clear(ios::badbit | load.rdstate());
313 isOK = static_cast<bool>(load >> entry);
314 if (isOK && entry == "__COMPOUNDS_BEGIN__")
316 while (isOK && entry != "__COMPOUNDS_END__")
318 isOK = static_cast<bool>(load >> entry);
319 if (isOK && entry != "__COMPOUNDS_END__")
320 _compounds.insert(entry);
326 //================================================================================
328 * \brief Does nothing
329 * \param theMesh - the built mesh
330 * \param theShape - the geometry of interest
331 * \retval bool - always false
333 //================================================================================
334 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* /*theMesh*/,
335 const TopoDS_Shape& /*theShape*/)
340 //================================================================================
342 * \brief Initialize my parameter values by default parameters.
343 * \retval bool - true if parameter values have been successfully defined
345 //================================================================================
347 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& /*dflts*/,
348 const SMESH_Mesh* /*theMesh*/)
350 //_nbSegPerEdge = dflts._nbSegments;
351 //_maxSize = dflts._elemLength;
353 //if ( dflts._shape && !dflts._shape->IsNull() )
354 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
355 //else if ( theMesh && theMesh->HasShapeToMesh() )
356 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
358 //return _nbSegPerEdge && _maxSize > 0;