Salome HOME
Copyright update: 2016
[modules/smesh.git] / src / StdMeshers / StdMeshers_NumberOfLayers.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SMESH SMESH : idl implementation based on 'SMESH' unit's classes
24 //  File   : StdMeshers_NumberOfLayers.cxx
25 //  Author : Edward AGAPOV
26 //  Module : SMESH
27 //
28 #include "StdMeshers_NumberOfLayers.hxx"
29
30
31 #include "SMESH_Mesh.hxx"
32 #include "utilities.h"
33
34 using namespace std;
35
36
37 //=============================================================================
38 /*!
39  *  StdMeshers_NumberOfLayers::StdMeshers_NumberOfLayers
40  *
41  *  Constructor
42  */
43 //=============================================================================
44
45 StdMeshers_NumberOfLayers::StdMeshers_NumberOfLayers(int hypId, int studyId,
46                                                      SMESH_Gen * gen)
47   : SMESH_Hypothesis(hypId, studyId, gen)
48 {
49   _name = "NumberOfLayers"; // used by RadialPrism_3D
50   _param_algo_dim = 3; // 3D
51   _nbLayers = 1;
52 }
53
54 //=============================================================================
55 /*!
56  *  StdMeshers_NumberOfLayers::~StdMeshers_NumberOfLayers
57  *
58  *  Destructor
59  */
60 //=============================================================================
61
62 StdMeshers_NumberOfLayers::~StdMeshers_NumberOfLayers()
63 {
64   MESSAGE( "StdMeshers_NumberOfLayers::~StdMeshers_NumberOfLayers" );
65 }
66
67 //=============================================================================
68 /*!
69  *  StdMeshers_NumberOfLayers::SetNumberOfLayers
70  *
71  *  Sets <number of segments> parameter value
72  */
73 //=============================================================================
74
75 void StdMeshers_NumberOfLayers::SetNumberOfLayers(int numberOfLayers)
76   throw ( SALOME_Exception )
77 {
78   if ( _nbLayers != numberOfLayers ) {
79     if ( numberOfLayers <= 0 )
80       throw SALOME_Exception(LOCALIZED("numberOfLayers must be more than zero"));
81     _nbLayers = numberOfLayers;
82
83     NotifySubMeshesHypothesisModification();
84   }
85 }
86
87 //=============================================================================
88 /*!
89  *  StdMeshers_NumberOfLayers::GetNumberOfLayers
90  *
91  *  Returns <number of layers> parameter value
92  */
93 //=============================================================================
94
95 int StdMeshers_NumberOfLayers::GetNumberOfLayers() const
96 {
97   return _nbLayers;
98 }
99
100 //=============================================================================
101 /*!
102  *  
103  */
104 //=============================================================================
105
106 ostream & StdMeshers_NumberOfLayers::SaveTo(ostream & save)
107 {
108   save << _nbLayers;
109   return save;
110 }
111
112 //=============================================================================
113 /*!
114  *  
115  */
116 //=============================================================================
117
118 istream & StdMeshers_NumberOfLayers::LoadFrom(istream & load)
119 {
120   bool isOK = true;
121   isOK = static_cast<bool>(load >> _nbLayers);
122   if (!isOK)
123     load.clear(ios::badbit | load.rdstate());
124   return load;
125 }
126
127 //=============================================================================
128 /*!
129  *  
130  */
131 //=============================================================================
132
133 ostream & operator <<(ostream & save, StdMeshers_NumberOfLayers & hyp)
134 {
135   return hyp.SaveTo( save );
136 }
137
138 //=============================================================================
139 /*!
140  *  
141  */
142 //=============================================================================
143
144 istream & operator >>(istream & load, StdMeshers_NumberOfLayers & hyp)
145 {
146   return hyp.LoadFrom( load );
147 }
148
149 //================================================================================
150 /*!
151  * \brief Initialize start and end length by the mesh built on the geometry
152  * \param theMesh - the built mesh
153  * \param theShape - the geometry of interest
154  * \retval bool - true if parameter values have been successfully defined
155  */
156 //================================================================================
157
158 bool StdMeshers_NumberOfLayers::SetParametersByMesh(const SMESH_Mesh*   ,
159                                                     const TopoDS_Shape& )
160 {
161   return false;
162 }
163
164 //================================================================================
165 /*!
166  * \brief Initialize my parameter values by default parameters.
167  *  \retval bool - true if parameter values have been successfully defined
168  */
169 //================================================================================
170
171 bool StdMeshers_NumberOfLayers::SetParametersByDefaults(const TDefaults&  dflts,
172                                                         const SMESH_Mesh* theMesh)
173 {
174   if ( dflts._elemLength )
175     return theMesh ? (_nbLayers = int( theMesh->GetShapeDiagonalSize() / dflts._elemLength/ 2.)) : 0;
176   return false;
177 }
178