1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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()),
56 _surfaceCurvature(GetDefaultSurfaceCurvature()),
57 _fuseEdges (GetDefaultFuseEdges())
59 _name = "NETGEN_Parameters";
64 //=============================================================================
68 //=============================================================================
69 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
71 if (theSize != _maxSize)
74 NotifySubMeshesHypothesisModification();
78 //=============================================================================
82 //=============================================================================
83 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
85 if (theSize != _minSize)
88 NotifySubMeshesHypothesisModification();
92 //=============================================================================
96 //=============================================================================
97 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
99 if (theVal != _secondOrder)
101 _secondOrder = theVal;
102 NotifySubMeshesHypothesisModification();
106 //=============================================================================
110 //=============================================================================
111 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
113 if (theVal != _optimize)
116 NotifySubMeshesHypothesisModification();
120 //=============================================================================
124 //=============================================================================
125 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
127 if (theFineness != _fineness)
129 _fineness = theFineness;
130 // the predefined values are taken from NETGEN 4.5 sources
141 _nbSegPerRadius = 1.5;
162 NotifySubMeshesHypothesisModification();
166 //=============================================================================
170 //=============================================================================
171 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
173 if (theRate != _growthRate)
175 _growthRate = theRate;
176 _fineness = UserDefined;
177 NotifySubMeshesHypothesisModification();
181 //=============================================================================
185 //=============================================================================
186 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
188 if (theVal != _nbSegPerEdge)
190 _nbSegPerEdge = theVal;
191 _fineness = UserDefined;
192 NotifySubMeshesHypothesisModification();
196 //=============================================================================
200 //=============================================================================
201 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
203 if (theVal != _nbSegPerRadius)
205 _nbSegPerRadius = theVal;
206 _fineness = UserDefined;
207 NotifySubMeshesHypothesisModification();
211 //=============================================================================
215 //=============================================================================
216 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
218 if(_localSize[entry] != localSize)
220 _localSize[entry] = localSize;
221 NotifySubMeshesHypothesisModification();
225 //=============================================================================
229 //=============================================================================
230 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
232 TLocalSize::iterator it = _localSize.find( entry );
233 if ( it != _localSize.end() )
239 //=============================================================================
243 //=============================================================================
244 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
246 _localSize.erase(entry);
247 NotifySubMeshesHypothesisModification();
250 //=============================================================================
254 //=============================================================================
255 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
257 if (theVal != _quadAllowed)
259 _quadAllowed = theVal;
260 NotifySubMeshesHypothesisModification();
264 //=============================================================================
268 //=============================================================================
269 bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
274 //=============================================================================
278 //=============================================================================
279 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
281 if (theVal != _surfaceCurvature)
283 _surfaceCurvature = theVal;
284 NotifySubMeshesHypothesisModification();
288 //=============================================================================
292 //=============================================================================
293 bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
298 //=============================================================================
302 //=============================================================================
303 void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
305 if (theVal != _fuseEdges)
308 NotifySubMeshesHypothesisModification();
312 //=============================================================================
316 //=============================================================================
317 bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
319 return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
322 //=============================================================================
326 //=============================================================================
327 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
329 save << _maxSize << " " << _fineness;
331 if (_fineness == UserDefined)
332 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
334 save << " " << (int)_secondOrder << " " << (int)_optimize;
336 TLocalSize::iterator it_sm = _localSize.begin();
337 if (it_sm != _localSize.end()) {
338 save << " " << "__LOCALSIZE_BEGIN__";
339 for ( ; it_sm != _localSize.end(); ++it_sm ) {
340 save << " " << it_sm->first
341 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
343 save << " " << "__LOCALSIZE_END__";
345 save << " " << _minSize;
346 save << " " << _quadAllowed;
347 save << " " << _surfaceCurvature;
348 save << " " << _fuseEdges;
353 //=============================================================================
357 //=============================================================================
358 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
364 isOK = (load >> val);
368 load.clear(ios::badbit | load.rdstate());
372 SetFineness((Fineness) is);
374 load.clear(ios::badbit | load.rdstate());
376 if (_fineness == UserDefined)
378 isOK = (load >> val);
382 load.clear(ios::badbit | load.rdstate());
384 isOK = (load >> val);
388 load.clear(ios::badbit | load.rdstate());
390 isOK = (load >> val);
392 _nbSegPerRadius = val;
394 load.clear(ios::badbit | load.rdstate());
399 _secondOrder = (bool) is;
401 load.clear(ios::badbit | load.rdstate());
405 _optimize = (bool) is;
407 load.clear(ios::badbit | load.rdstate());
409 std::string option_or_sm;
410 bool hasLocalSize = false;
412 isOK = (load >> option_or_sm);
414 if (option_or_sm == "__LOCALSIZE_BEGIN__")
417 std::string smEntry, smValue;
418 while (isOK && hasLocalSize) {
419 isOK = (load >> smEntry);
421 if (smEntry == "__LOCALSIZE_END__")
423 isOK = (load >> smValue);
426 std::istringstream tmp(smValue);
429 _localSize[ smEntry ] = val;
433 if ( !hasLocalSize && !option_or_sm.empty() )
434 _minSize = atof( option_or_sm.c_str() );
436 isOK = ( load >> _quadAllowed );
438 _quadAllowed = GetDefaultQuadAllowed();
440 isOK = ( load >> _surfaceCurvature );
442 _surfaceCurvature = GetDefaultSurfaceCurvature();
444 isOK = ( load >> _fuseEdges );
446 _fuseEdges = GetDefaultFuseEdges();
451 //=============================================================================
455 //=============================================================================
456 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
458 return hyp.SaveTo( save );
461 //=============================================================================
465 //=============================================================================
466 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
468 return hyp.LoadFrom( load );
472 //================================================================================
474 * \brief Does nothing
475 * \param theMesh - the built mesh
476 * \param theShape - the geometry of interest
477 * \retval bool - always false
479 //================================================================================
480 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
481 const TopoDS_Shape& theShape)
486 //================================================================================
488 * \brief Initialize my parameter values by default parameters.
489 * \retval bool - true if parameter values have been successfully defined
491 //================================================================================
493 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
494 const SMESH_Mesh* theMesh)
496 _nbSegPerEdge = dflts._nbSegments;
497 _maxSize = dflts._elemLength;
499 if ( dflts._shape && !dflts._shape->IsNull() )
500 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
501 else if ( theMesh && theMesh->HasShapeToMesh() )
502 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
504 return _nbSegPerEdge && _maxSize > 0;
507 //=============================================================================
511 //=============================================================================
512 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
517 //=============================================================================
521 //=============================================================================
522 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
527 //=============================================================================
531 //=============================================================================
532 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
537 //=============================================================================
541 //=============================================================================
542 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
547 //=============================================================================
551 //=============================================================================
552 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
557 //=============================================================================
561 //=============================================================================
562 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
567 //=============================================================================
571 //=============================================================================
572 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()