1 // Copyright (C) 2007-2008 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
22 // NETGENPlugin : C++ implementation
23 // File : NETGENPlugin_Hypothesis.cxx
24 // Author : Michael Sazonov (OCN)
28 #include "NETGENPlugin_Hypothesis.hxx"
29 #include <utilities.h>
33 //=============================================================================
37 //=============================================================================
38 NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, int studyId,
40 : SMESH_Hypothesis(hypId, studyId, gen),
41 _maxSize (GetDefaultMaxSize()),
42 _growthRate (GetDefaultGrowthRate()),
43 _nbSegPerEdge (GetDefaultNbSegPerEdge()),
44 _nbSegPerRadius(GetDefaultNbSegPerRadius()),
45 _fineness (GetDefaultFineness()),
46 _secondOrder (GetDefaultSecondOrder()),
47 _optimize (GetDefaultOptimize())
49 _name = "NETGEN_Parameters";
53 //=============================================================================
57 //=============================================================================
58 void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
60 if (theSize != _maxSize)
63 NotifySubMeshesHypothesisModification();
67 //=============================================================================
71 //=============================================================================
72 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
74 if (theVal != _secondOrder)
76 _secondOrder = theVal;
77 NotifySubMeshesHypothesisModification();
81 //=============================================================================
85 //=============================================================================
86 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
88 if (theVal != _optimize)
91 NotifySubMeshesHypothesisModification();
95 //=============================================================================
99 //=============================================================================
100 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
102 if (theFineness != _fineness)
104 _fineness = theFineness;
105 // the predefined values are taken from NETGEN 4.5 sources
116 _nbSegPerRadius = 1.5;
137 NotifySubMeshesHypothesisModification();
141 //=============================================================================
145 //=============================================================================
146 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
148 if (theRate != _growthRate)
150 _growthRate = theRate;
151 _fineness = UserDefined;
152 NotifySubMeshesHypothesisModification();
156 //=============================================================================
160 //=============================================================================
161 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
163 if (theVal != _nbSegPerEdge)
165 _nbSegPerEdge = theVal;
166 _fineness = UserDefined;
167 NotifySubMeshesHypothesisModification();
171 //=============================================================================
175 //=============================================================================
176 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
178 if (theVal != _nbSegPerRadius)
180 _nbSegPerRadius = theVal;
181 _fineness = UserDefined;
182 NotifySubMeshesHypothesisModification();
186 //=============================================================================
190 //=============================================================================
191 ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
193 save << _maxSize << " " << _fineness;
195 if (_fineness == UserDefined)
196 save << " " << _growthRate << " " << _nbSegPerEdge << " " << _nbSegPerRadius;
198 save << " " << (int)_secondOrder << " " << (int)_optimize;
203 //=============================================================================
207 //=============================================================================
208 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
214 isOK = (load >> val);
218 load.clear(ios::badbit | load.rdstate());
222 SetFineness((Fineness) is);
224 load.clear(ios::badbit | load.rdstate());
226 if (_fineness == UserDefined)
228 isOK = (load >> val);
232 load.clear(ios::badbit | load.rdstate());
234 isOK = (load >> val);
238 load.clear(ios::badbit | load.rdstate());
240 isOK = (load >> val);
242 _nbSegPerRadius = val;
244 load.clear(ios::badbit | load.rdstate());
249 _secondOrder = (bool) is;
251 load.clear(ios::badbit | load.rdstate());
255 _optimize = (bool) is;
257 load.clear(ios::badbit | load.rdstate());
261 //=============================================================================
265 //=============================================================================
266 ostream & operator <<(ostream & save, NETGENPlugin_Hypothesis & hyp)
268 return hyp.SaveTo( save );
271 //=============================================================================
275 //=============================================================================
276 istream & operator >>(istream & load, NETGENPlugin_Hypothesis & hyp)
278 return hyp.LoadFrom( load );
282 //================================================================================
284 * \brief Does nothing
285 * \param theMesh - the built mesh
286 * \param theShape - the geometry of interest
287 * \retval bool - always false
289 //================================================================================
290 bool NETGENPlugin_Hypothesis::SetParametersByMesh(const SMESH_Mesh* theMesh,
291 const TopoDS_Shape& theShape)
296 //================================================================================
298 * \brief Initialize my parameter values by default parameters.
299 * \retval bool - true if parameter values have been successfully defined
301 //================================================================================
303 bool NETGENPlugin_Hypothesis::SetParametersByDefaults(const TDefaults& dflts,
304 const SMESH_Mesh* /*theMesh*/)
306 _nbSegPerEdge = dflts._nbSegments;
307 _maxSize = dflts._elemLength;
308 return _nbSegPerEdge && _maxSize > 0;
311 //=============================================================================
315 //=============================================================================
316 double NETGENPlugin_Hypothesis::GetDefaultMaxSize()
321 //=============================================================================
325 //=============================================================================
326 NETGENPlugin_Hypothesis::Fineness NETGENPlugin_Hypothesis::GetDefaultFineness()
331 //=============================================================================
335 //=============================================================================
336 double NETGENPlugin_Hypothesis::GetDefaultGrowthRate()
341 //=============================================================================
345 //=============================================================================
346 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerEdge()
351 //=============================================================================
355 //=============================================================================
356 double NETGENPlugin_Hypothesis::GetDefaultNbSegPerRadius()
361 //=============================================================================
365 //=============================================================================
366 bool NETGENPlugin_Hypothesis::GetDefaultSecondOrder()
371 //=============================================================================
375 //=============================================================================
376 bool NETGENPlugin_Hypothesis::GetDefaultOptimize()