1 // Copyright (C) 2012-2013 ALNEOS
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.alneos.com/ or email : contact@alneos.fr
19 #include "GMSHPlugin_Hypothesis.hxx"
21 #include "GMSHPlugin_Mesher.hxx"
22 #include "SMESH_Mesh.hxx"
24 #include <utilities.h>
29 GMSHPlugin_Hypothesis::GMSHPlugin_Hypothesis (int hypId, int studyId,
31 : SMESH_Hypothesis(hypId, studyId, gen),
34 _recomb2DAlgo (standard),
35 _recombineAll (false),
37 _remeshAlgo (nosplit),
38 _remeshPara (harmonic),
44 _useIncomplElem (true)
46 _name = "GMSH_Parameters";
50 void GMSHPlugin_Hypothesis::Set2DAlgo(Algo2D the2DAlgo)
52 if (the2DAlgo != _algo2d)
55 NotifySubMeshesHypothesisModification();
59 void GMSHPlugin_Hypothesis::Set3DAlgo(Algo3D the3DAlgo)
61 if (the3DAlgo != _algo3d)
64 NotifySubMeshesHypothesisModification();
68 void GMSHPlugin_Hypothesis::SetRecomb2DAlgo(Recomb2DAlgo theRecomb2DAlgo)
70 if (theRecomb2DAlgo != _recomb2DAlgo)
72 _recomb2DAlgo = theRecomb2DAlgo;
73 NotifySubMeshesHypothesisModification();
77 void GMSHPlugin_Hypothesis::SetRecombineAll(bool theRecombineAll)
79 if (theRecombineAll != _recombineAll)
81 _recombineAll = theRecombineAll;
82 NotifySubMeshesHypothesisModification();
86 void GMSHPlugin_Hypothesis::SetSubdivAlgo(SubdivAlgo theSubdivAlgo)
88 if (theSubdivAlgo != _subdivAlgo)
90 _subdivAlgo = theSubdivAlgo;
91 NotifySubMeshesHypothesisModification();
95 void GMSHPlugin_Hypothesis::SetRemeshAlgo(RemeshAlgo theRemeshAlgo)
97 if (theRemeshAlgo != _remeshAlgo)
99 _remeshAlgo = theRemeshAlgo;
100 NotifySubMeshesHypothesisModification();
104 void GMSHPlugin_Hypothesis::SetRemeshPara(RemeshPara theRemeshPara)
106 if (theRemeshPara != _remeshPara)
108 _remeshPara = theRemeshPara;
109 NotifySubMeshesHypothesisModification();
113 void GMSHPlugin_Hypothesis::SetSmouthSteps(double theSmouthSteps)
115 if (theSmouthSteps != _smouthSteps)
117 _smouthSteps = theSmouthSteps;
118 NotifySubMeshesHypothesisModification();
122 void GMSHPlugin_Hypothesis::SetSizeFactor(double theSizeFactor)
124 if (theSizeFactor != _sizeFactor)
126 _sizeFactor = theSizeFactor;
127 NotifySubMeshesHypothesisModification();
131 void GMSHPlugin_Hypothesis::SetUseIncomplElem(bool theUseIncomplElem)
133 if (theUseIncomplElem != _useIncomplElem)
135 _useIncomplElem = theUseIncomplElem;
136 NotifySubMeshesHypothesisModification();
140 void GMSHPlugin_Hypothesis::SetMaxSize(double theSize)
142 if (theSize != _maxSize)
145 NotifySubMeshesHypothesisModification();
149 void GMSHPlugin_Hypothesis::SetMinSize(double theSize)
151 if (theSize != _minSize)
154 NotifySubMeshesHypothesisModification();
158 void GMSHPlugin_Hypothesis::SetSecondOrder(bool theVal)
160 if (theVal != _secondOrder)
162 _secondOrder = theVal;
163 NotifySubMeshesHypothesisModification();
167 void GMSHPlugin_Hypothesis::SetIs2d(bool theIs2d)
173 void GMSHPlugin_Hypothesis::SetCompoundOnEntry(const std::string& entry)
175 if (_compounds.find(entry) == _compounds.end())
177 _compounds.insert(entry);
178 NotifySubMeshesHypothesisModification();
182 void GMSHPlugin_Hypothesis::UnsetCompoundOnEntry(const std::string& entry)
184 if (_compounds.find(entry) != _compounds.end())
186 _compounds.erase(entry);
187 NotifySubMeshesHypothesisModification();
191 ostream & GMSHPlugin_Hypothesis::SaveTo(ostream & save)
193 save << (int)_is2d << " " << _algo2d;
195 save << " " << _algo3d;
196 save << " " << _recomb2DAlgo <<
197 " " << (int)_recombineAll <<
198 " " << _subdivAlgo <<
199 " " << _remeshAlgo <<
200 " " << _remeshPara <<
201 " " << _smouthSteps <<
202 " " << _sizeFactor <<
205 " " << (int)_secondOrder <<
206 " " << (int)_useIncomplElem ;
208 save << " " << "__COMPOUNDS_BEGIN__";
209 for (TCompound::const_iterator it = _compounds.begin(); it != _compounds.end(); ++it )
210 save << " " << *it << " ";
211 save << " " << "__COMPOUNDS_END__";
216 istream & GMSHPlugin_Hypothesis::LoadFrom(istream & load)
226 load.clear(ios::badbit | load.rdstate());
230 _algo2d = (Algo2D)is;
232 load.clear(ios::badbit | load.rdstate());
238 _algo3d = (Algo3D)is;
240 load.clear(ios::badbit | load.rdstate());
245 _recomb2DAlgo = (Recomb2DAlgo)is;
247 load.clear(ios::badbit | load.rdstate());
251 _recombineAll = (bool)is;
253 load.clear(ios::badbit | load.rdstate());
257 _subdivAlgo = (SubdivAlgo)is;
259 load.clear(ios::badbit | load.rdstate());
263 _remeshAlgo = (RemeshAlgo)is;
265 load.clear(ios::badbit | load.rdstate());
269 _remeshPara = (RemeshPara)is;
271 load.clear(ios::badbit | load.rdstate());
273 isOK = (load >> val);
277 load.clear(ios::badbit | load.rdstate());
279 isOK = (load >> val);
283 load.clear(ios::badbit | load.rdstate());
285 isOK = (load >> val);
289 load.clear(ios::badbit | load.rdstate());
291 isOK = (load >> val);
295 load.clear(ios::badbit | load.rdstate());
299 _secondOrder = (bool)is;
301 load.clear(ios::badbit | load.rdstate());
305 _useIncomplElem = (bool)is;
307 load.clear(ios::badbit | load.rdstate());
311 isOK = (load >> entry);
312 if (isOK && entry == "__COMPOUNDS_BEGIN__")
314 while (isOK && entry != "__COMPOUNDS_END__")
316 isOK = (load >> entry);
317 if (isOK && entry != "__COMPOUNDS_END__")
318 _compounds.insert(entry);
324 ostream & operator <<(ostream & save, GMSHPlugin_Hypothesis & hyp)
326 return hyp.SaveTo( save );
329 istream & operator >>(istream & load, GMSHPlugin_Hypothesis & hyp)
331 return hyp.LoadFrom( load );
335 //================================================================================
337 * \brief Does nothing
338 * \param theMesh - the built mesh
339 * \param theShape - the geometry of interest
340 * \retval bool - always false
342 //================================================================================
343 bool GMSHPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
344 const TopoDS_Shape& theShape)
349 //================================================================================
351 * \brief Initialize my parameter values by default parameters.
352 * \retval bool - true if parameter values have been successfully defined
354 //================================================================================
356 bool GMSHPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
357 const SMESH_Mesh* theMesh)
359 //_nbSegPerEdge = dflts._nbSegments;
360 //_maxSize = dflts._elemLength;
362 //if ( dflts._shape && !dflts._shape->IsNull() )
363 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
364 //else if ( theMesh && theMesh->HasShapeToMesh() )
365 // _minSize = GMSHPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
367 //return _nbSegPerEdge && _maxSize > 0;