1 // Copyright (C) 2007-2011 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"
30 #include <utilities.h>
34 //=============================================================================
38 //=============================================================================
39 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
41 : SMESH_Hypothesis(hypId, studyId, gen),
42 _maxSize (GetDefaultMaxSize()),
43 _growthRate (GetDefaultGrowthRate()),
44 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
45 _nbSegPerRadius(GetDefaultNbSegPerRadius()),
46 _fineness (GetDefaultFineness()),
47 _secondOrder (GetDefaultSecondOrder()),
48 _optimize (GetDefaultOptimize()),
49 _localSize (GetDefaultLocalSize())
51 _name = "NETGEN_Parameters";
56 //=============================================================================
60 //=============================================================================
61 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
63 if (theSize != _maxSize)
66 NotifySubMeshesHypothesisModification();
70 //=============================================================================
74 //=============================================================================
75 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
77 if (theVal != _secondOrder)
79 _secondOrder = theVal;
80 NotifySubMeshesHypothesisModification();
84 //=============================================================================
88 //=============================================================================
89 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
91 if (theVal != _optimize)
94 NotifySubMeshesHypothesisModification();
98 //=============================================================================
102 //=============================================================================
103 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
105 if (theFineness != _fineness)
107 _fineness = theFineness;
108 // the predefined values are taken from NETGEN 4.5 sources
119 _nbSegPerRadius = 1.5;
140 NotifySubMeshesHypothesisModification();
144 //=============================================================================
148 //=============================================================================
149 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
151 if (theRate != _growthRate)
153 _growthRate = theRate;
154 _fineness = UserDefined;
155 NotifySubMeshesHypothesisModification();
159 //=============================================================================
163 //=============================================================================
164 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
166 if (theVal != _nbSegPerEdge)
168 _nbSegPerEdge = theVal;
169 _fineness = UserDefined;
170 NotifySubMeshesHypothesisModification();
174 //=============================================================================
178 //=============================================================================
179 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
181 if (theVal != _nbSegPerRadius)
183 _nbSegPerRadius = theVal;
184 _fineness = UserDefined;
185 NotifySubMeshesHypothesisModification();
189 //=============================================================================
193 //=============================================================================
194 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
196 if(_localSize[entry] != localSize)
198 _localSize[entry] = localSize;
199 NotifySubMeshesHypothesisModification();
203 //=============================================================================
207 //=============================================================================
208 double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
210 TLocalSize::iterator it = _localSize.find( entry );
211 if ( it != _localSize.end() )
217 //=============================================================================
221 //=============================================================================
222 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
224 _localSize.erase(entry);
225 NotifySubMeshesHypothesisModification();
228 //=============================================================================
232 //=============================================================================
233 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
235 save << _maxSize << " " << _fineness;
237 if (_fineness == UserDefined)
238 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
240 save << " " << (int)_secondOrder << " " << (int)_optimize;
242 TLocalSize::iterator it_sm = _localSize.begin();
243 if (it_sm != _localSize.end()) {
244 save << " " << "__LOCALSIZE_BEGIN__";
245 for ( ; it_sm != _localSize.end(); ++it_sm ) {
246 save << " " << it_sm->first
247 << " " << it_sm->second << "%#"; // "%#" is a mark of value end
249 save << " " << "__LOCALSIZE_END__";
255 //=============================================================================
259 //=============================================================================
260 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
266 isOK = (load >> val);
270 load.clear(ios::badbit | load.rdstate());
274 SetFineness((Fineness) is);
276 load.clear(ios::badbit | load.rdstate());
278 if (_fineness == UserDefined)
280 isOK = (load >> val);
284 load.clear(ios::badbit | load.rdstate());
286 isOK = (load >> val);
290 load.clear(ios::badbit | load.rdstate());
292 isOK = (load >> val);
294 _nbSegPerRadius = val;
296 load.clear(ios::badbit | load.rdstate());
301 _secondOrder = (bool) is;
303 load.clear(ios::badbit | load.rdstate());
307 _optimize = (bool) is;
309 load.clear(ios::badbit | load.rdstate());
311 std::string option_or_sm;
312 bool hasLocalSize = false;
314 isOK = (load >> option_or_sm);
316 if (option_or_sm == "__LOCALSIZE_BEGIN__")
319 std::string smEntry, smValue;
320 while (isOK && hasLocalSize) {
321 isOK = (load >> smEntry);
323 if (smEntry == "__LOCALSIZE_END__")
325 isOK = (load >> smValue);
328 std::istringstream tmp(smValue);
331 _localSize[ smEntry ] = val;
338 //=============================================================================
342 //=============================================================================
343 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
345 return hyp.SaveTo( save );
348 //=============================================================================
352 //=============================================================================
353 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
355 return hyp.LoadFrom( load );
359 //================================================================================
361 * \brief Does nothing
362 * \param theMesh - the built mesh
363 * \param theShape - the geometry of interest
364 * \retval bool - always false
366 //================================================================================
367 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
368 const TopoDS_Shape& theShape)
373 //================================================================================
375 * \brief Initialize my parameter values by default parameters.
376 * \retval bool - true if parameter values have been successfully defined
378 //================================================================================
380 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
381 const SMESH_Mesh* /*theMesh*/)
383 _nbSegPerEdge = dflts._nbSegments;
384 _maxSize = dflts._elemLength;
385 return _nbSegPerEdge && _maxSize > 0;
388 //=============================================================================
392 //=============================================================================
393 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
398 //=============================================================================
402 //=============================================================================
403 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
408 //=============================================================================
412 //=============================================================================
413 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
418 //=============================================================================
422 //=============================================================================
423 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
428 //=============================================================================
432 //=============================================================================
433 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
438 //=============================================================================
442 //=============================================================================
443 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
448 //=============================================================================
452 //=============================================================================
453 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()