1 // Copyright (C) 2007-2016 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::SetMeshSizeFile(const std::string& fileName)
257 if ( fileName != _meshSizeFile )
259 _meshSizeFile = fileName;
260 NotifySubMeshesHypothesisModification();
264 //=============================================================================
268 //=============================================================================
269 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
271 if (theVal != _quadAllowed)
273 _quadAllowed = theVal;
274 NotifySubMeshesHypothesisModification();
278 //=============================================================================
282 //=============================================================================
283 bool NETGENPlugin_Hypothesis::GetDefaultQuadAllowed()
288 //=============================================================================
292 //=============================================================================
293 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
295 if (theVal != _surfaceCurvature)
297 _surfaceCurvature = theVal;
298 NotifySubMeshesHypothesisModification();
302 //=============================================================================
306 //=============================================================================
307 bool NETGENPlugin_Hypothesis::GetDefaultSurfaceCurvature()
312 //=============================================================================
316 //=============================================================================
317 void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
319 if (theVal != _fuseEdges)
322 NotifySubMeshesHypothesisModification();
326 //=============================================================================
330 //=============================================================================
331 bool NETGENPlugin_Hypothesis::GetDefaultFuseEdges()
333 return true; // false; -- for SALOME_TESTS/Grids/smesh/3D_mesh_NETGEN_05/F6
336 //=============================================================================
340 //=============================================================================
341 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
343 save << _maxSize << " " << _fineness;
345 if (_fineness == UserDefined)
346 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
348 save << " " << (int)_secondOrder << " " << (int)_optimize;
350 TLocalSize::iterator it_sm = _localSize.begin();
351 if (it_sm != _localSize.end()) {
352 save << " " << "__LOCALSIZE_BEGIN__";
353 for ( ; it_sm != _localSize.end(); ++it_sm ) {
354 save << " " << it_sm->first
355 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
357 save << " " << "__LOCALSIZE_END__";
359 save << " " << _minSize;
360 save << " " << _quadAllowed;
361 save << " " << _surfaceCurvature;
362 save << " " << _fuseEdges;
364 save << " " << _meshSizeFile.size() << " " << _meshSizeFile;
369 //=============================================================================
373 //=============================================================================
374 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
380 isOK = static_cast<bool>(load >> val);
384 load.clear(ios::badbit | load.rdstate());
386 isOK = static_cast<bool>(load >> is);
388 SetFineness((Fineness) is);
390 load.clear(ios::badbit | load.rdstate());
392 if (_fineness == UserDefined)
394 isOK = static_cast<bool>(load >> val);
398 load.clear(ios::badbit | load.rdstate());
400 isOK = static_cast<bool>(load >> val);
404 load.clear(ios::badbit | load.rdstate());
406 isOK = static_cast<bool>(load >> val);
408 _nbSegPerRadius = val;
410 load.clear(ios::badbit | load.rdstate());
413 isOK = static_cast<bool>(load >> is);
415 _secondOrder = (bool) is;
417 load.clear(ios::badbit | load.rdstate());
419 isOK = static_cast<bool>(load >> is);
421 _optimize = (bool) is;
423 load.clear(ios::badbit | load.rdstate());
425 std::string option_or_sm;
426 bool hasLocalSize = false;
428 isOK = static_cast<bool>(load >> option_or_sm);
430 if (option_or_sm == "__LOCALSIZE_BEGIN__")
433 std::string smEntry, smValue;
434 while (isOK && hasLocalSize) {
435 isOK = static_cast<bool>(load >> smEntry);
437 if (smEntry == "__LOCALSIZE_END__")
439 isOK = static_cast<bool>(load >> smValue);
442 std::istringstream tmp(smValue);
445 _localSize[ smEntry ] = val;
449 if ( !hasLocalSize && !option_or_sm.empty() )
450 _minSize = atof( option_or_sm.c_str() );
454 isOK = static_cast<bool>( load >> is );
456 _quadAllowed = (bool) is;
458 _quadAllowed = GetDefaultQuadAllowed();
460 isOK = static_cast<bool>( load >> is );
462 _surfaceCurvature = (bool) is;
464 _surfaceCurvature = GetDefaultSurfaceCurvature();
466 isOK = static_cast<bool>( load >> is );
468 _fuseEdges = (bool) is;
470 _fuseEdges = GetDefaultFuseEdges();
472 isOK = static_cast<bool>( load >> is >> std::ws ); // size of meshSizeFile
473 if ( isOK && is > 0 )
475 _meshSizeFile.resize( is );
476 load.get( &_meshSizeFile[0], is+1 );
482 //=============================================================================
486 //=============================================================================
487 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
489 return hyp.SaveTo( save );
492 //=============================================================================
496 //=============================================================================
497 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
499 return hyp.LoadFrom( load );
503 //================================================================================
505 * \brief Does nothing
506 * \param theMesh - the built mesh
507 * \param theShape - the geometry of interest
508 * \retval bool - always false
510 //================================================================================
511 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
512 const TopoDS_Shape& theShape)
517 //================================================================================
519 * \brief Initialize my parameter values by default parameters.
520 * \retval bool - true if parameter values have been successfully defined
522 //================================================================================
524 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
525 const SMESH_Mesh* theMesh)
527 _nbSegPerEdge = dflts._nbSegments;
528 _maxSize = dflts._elemLength;
530 if ( dflts._shape && !dflts._shape->IsNull() )
531 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( *dflts._shape, _maxSize );
532 else if ( theMesh && theMesh->HasShapeToMesh() )
533 _minSize = NETGENPlugin_Mesher::GetDefaultMinSize( theMesh->GetShapeToMesh(), _maxSize );
535 return _nbSegPerEdge && _maxSize > 0;
538 //=============================================================================
542 //=============================================================================
543 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
548 //=============================================================================
552 //=============================================================================
553 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
558 //=============================================================================
562 //=============================================================================
563 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
568 //=============================================================================
572 //=============================================================================
573 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
578 //=============================================================================
582 //=============================================================================
583 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
588 //=============================================================================
592 //=============================================================================
593 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
598 //=============================================================================
602 //=============================================================================
603 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()