1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // NETGENPlugin : C++ implementation
24 // File : NETGENPlugin_Hypothesis.cxx
25 // Author : Michael Sazonov (OCN)
29 #include "NETGENPlugin_Hypothesis.hxx"
31 #include "NETGENPlugin_Mesher.hxx"
32 #include "SMESH_Mesh.hxx"
34 #include <utilities.h>
38 //=============================================================================
42 //=============================================================================
43 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
45 : SMESH_Hypothesis(hypId, studyId, gen),
46 _maxSize (GetDefaultMaxSize()),
48 _growthRate (GetDefaultGrowthRate()),
49 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
50 _nbSegPerRadius(GetDefaultNbSegPerRadius()),
51 _fineness (GetDefaultFineness()),
52 _secondOrder (GetDefaultSecondOrder()),
53 _optimize (GetDefaultOptimize()),
54 _localSize (GetDefaultLocalSize()),
55 _quadAllowed (GetDefaultQuadAllowed())
57 _name = "NETGEN_Parameters";
62 //=============================================================================
66 //=============================================================================
67 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
69 if (theSize != _maxSize)
72 NotifySubMeshesHypothesisModification();
76 //=============================================================================
80 //=============================================================================
81 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
83 if (theSize != _minSize)
86 NotifySubMeshesHypothesisModification();
90 //=============================================================================
94 //=============================================================================
95 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
97 if (theVal != _secondOrder)
99 _secondOrder = theVal;
100 NotifySubMeshesHypothesisModification();
104 //=============================================================================
108 //=============================================================================
109 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
111 if (theVal != _optimize)
114 NotifySubMeshesHypothesisModification();
118 //=============================================================================
122 //=============================================================================
123 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
125 if (theFineness != _fineness)
127 _fineness = theFineness;
128 // the predefined values are taken from NETGEN 4.5 sources
139 _nbSegPerRadius = 1.5;
160 NotifySubMeshesHypothesisModification();
164 //=============================================================================
168 //=============================================================================
169 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
171 if (theRate != _growthRate)
173 _growthRate = theRate;
174 _fineness = UserDefined;
175 NotifySubMeshesHypothesisModification();
179 //=============================================================================
183 //=============================================================================
184 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
186 if (theVal != _nbSegPerEdge)
188 _nbSegPerEdge = theVal;
189 _fineness = UserDefined;
190 NotifySubMeshesHypothesisModification();
194 //=============================================================================
198 //=============================================================================
199 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
201 if (theVal != _nbSegPerRadius)
203 _nbSegPerRadius = theVal;
204 _fineness = UserDefined;
205 NotifySubMeshesHypothesisModification();
209 //=============================================================================
213 //=============================================================================
214 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
216 if(_localSize[entry] != localSize)
218 _localSize[entry] = localSize;
219 NotifySubMeshesHypothesisModification();
223 //=============================================================================
227 //=============================================================================
228 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
230 TLocalSize::iterator it = _localSize.find( entry );
231 if ( it != _localSize.end() )
237 //=============================================================================
241 //=============================================================================
242 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
244 _localSize.erase(entry);
245 NotifySubMeshesHypothesisModification();
248 //=============================================================================
252 //=============================================================================
253 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
255 if (theVal != _quadAllowed)
257 _quadAllowed = theVal;
258 NotifySubMeshesHypothesisModification();
262 //=============================================================================
266 //=============================================================================
267 bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
272 //=============================================================================
276 //=============================================================================
277 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
279 save << _maxSize << " " << _fineness;
281 if (_fineness == UserDefined)
282 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
284 save << " " << (int)_secondOrder << " " << (int)_optimize;
286 TLocalSize::iterator it_sm = _localSize.begin();
287 if (it_sm != _localSize.end()) {
288 save << " " << "__LOCALSIZE_BEGIN__";
289 for ( ; it_sm != _localSize.end(); ++it_sm ) {
290 save << " " << it_sm->first
291 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
293 save << " " << "__LOCALSIZE_END__";
295 save << " " << _minSize;
296 save << " " << _quadAllowed;
301 //=============================================================================
305 //=============================================================================
306 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
312 isOK = (load >> val);
316 load.clear(ios::badbit | load.rdstate());
320 SetFineness((Fineness) is);
322 load.clear(ios::badbit | load.rdstate());
324 if (_fineness == UserDefined)
326 isOK = (load >> val);
330 load.clear(ios::badbit | load.rdstate());
332 isOK = (load >> val);
336 load.clear(ios::badbit | load.rdstate());
338 isOK = (load >> val);
340 _nbSegPerRadius = val;
342 load.clear(ios::badbit | load.rdstate());
347 _secondOrder = (bool) is;
349 load.clear(ios::badbit | load.rdstate());
353 _optimize = (bool) is;
355 load.clear(ios::badbit | load.rdstate());
357 std::string option_or_sm;
358 bool hasLocalSize = false;
360 isOK = (load >> option_or_sm);
362 if (option_or_sm == "__LOCALSIZE_BEGIN__")
365 std::string smEntry, smValue;
366 while (isOK && hasLocalSize) {
367 isOK = (load >> smEntry);
369 if (smEntry == "__LOCALSIZE_END__")
371 isOK = (load >> smValue);
374 std::istringstream tmp(smValue);
377 _localSize[ smEntry ] = val;
381 if ( !hasLocalSize && !option_or_sm.empty() )
382 _minSize = atof( option_or_sm.c_str() );
384 isOK = ( load >> _quadAllowed );
386 _quadAllowed = GetDefaultQuadAllowed();
391 //=============================================================================
395 //=============================================================================
396 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
398 return hyp.SaveTo( save );
401 //=============================================================================
405 //=============================================================================
406 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
408 return hyp.LoadFrom( load );
412 //================================================================================
414 * \brief Does nothing
415 * \param theMesh - the built mesh
416 * \param theShape - the geometry of interest
417 * \retval bool - always false
419 //================================================================================
420 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
421 const TopoDS_Shape& theShape)
426 //================================================================================
428 * \brief Initialize my parameter values by default parameters.
429 * \retval bool - true if parameter values have been successfully defined
431 //================================================================================
433 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
434 const SMESH_Mesh* theMesh)
436 _nbSegPerEdge = dflts._nbSegments;
437 _maxSize = dflts._elemLength;
439 if ( dflts._shape && !dflts._shape->IsNull() )
440 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
441 else if ( theMesh && theMesh->HasShapeToMesh() )
442 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
444 return _nbSegPerEdge && _maxSize > 0;
447 //=============================================================================
451 //=============================================================================
452 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
457 //=============================================================================
461 //=============================================================================
462 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
467 //=============================================================================
471 //=============================================================================
472 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
477 //=============================================================================
481 //=============================================================================
482 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
487 //=============================================================================
491 //=============================================================================
492 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
497 //=============================================================================
501 //=============================================================================
502 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
507 //=============================================================================
511 //=============================================================================
512 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()