Salome HOME
Merge branch 'master' into pre/penta18
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ViscousLayers_i.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_I : idl implementation based on 'SMESH' unit's calsses
24 //  File   : StdMeshers_ViscousLayers_i.cxx
25 //  Module : SMESH
26 //
27 #include "StdMeshers_ViscousLayers_i.hxx"
28
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_PythonDump.hxx"
32
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
35
36 #include <TCollection_AsciiString.hxx>
37
38 #include CORBA_SERVER_HEADER(SMESH_Group)
39
40 using namespace std;
41
42 //=============================================================================
43 /*!
44  *  StdMeshers_ViscousLayers_i::StdMeshers_ViscousLayers_i
45  *
46  *  Constructor
47  */
48 //=============================================================================
49
50 StdMeshers_ViscousLayers_i::StdMeshers_ViscousLayers_i( PortableServer::POA_ptr thePOA,
51                                                         int                     theStudyId,
52                                                         ::SMESH_Gen*            theGenImpl )
53   : SALOME::GenericObj_i( thePOA ), 
54     SMESH_Hypothesis_i( thePOA )
55 {
56   myBaseImpl = new ::StdMeshers_ViscousLayers( theGenImpl->GetANewId(),
57                                                theStudyId,
58                                                theGenImpl );
59 }
60
61 //=============================================================================
62 /*!
63  *  StdMeshers_ViscousLayers_i::~StdMeshers_ViscousLayers_i
64  *
65  *  Destructor
66  */
67 //=============================================================================
68
69 StdMeshers_ViscousLayers_i::~StdMeshers_ViscousLayers_i()
70 {
71 }
72
73 //================================================================================
74 /*!
75  * \brief 
76  */
77 //================================================================================
78
79 void StdMeshers_ViscousLayers_i::SetFaces(const ::SMESH::long_array& faceIDs,
80                                           CORBA::Boolean             toIgnore)
81   throw ( SALOME::SALOME_Exception )
82 {
83   vector<int> ids( faceIDs.length() );
84   for ( unsigned i = 0; i < ids.size(); ++i )
85     if (( ids[i] = faceIDs[i] ) < 1 )
86       THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
87
88   GetImpl()->SetBndShapes( ids, toIgnore );
89
90   SMESH::TPythonDump() << _this() << ".SetFaces( " << faceIDs << ", " << toIgnore << " )";
91 }
92
93 //================================================================================
94 /*!
95  * \brief 
96  */
97 //================================================================================
98
99 SMESH::long_array* StdMeshers_ViscousLayers_i::GetFaces()
100 {
101   vector<int> idsVec = GetImpl()->GetBndShapes();
102   SMESH::long_array_var ids = new SMESH::long_array;
103   ids->length( idsVec.size() );
104   for ( unsigned i = 0; i < idsVec.size(); ++i )
105     ids[i] = idsVec[i];
106   return ids._retn();
107 }
108
109 //================================================================================
110 /*!
111  * \brief 
112  */
113 //================================================================================
114
115 SMESH::long_array* StdMeshers_ViscousLayers_i::GetIgnoreFaces()
116 {
117   if ( GetImpl()->IsToIgnoreShapes() )
118     return this->GetFaces();
119   return new SMESH::long_array;
120 }
121
122 //================================================================================
123 /*!
124  * \brief 
125  */
126 //================================================================================
127
128 CORBA::Boolean StdMeshers_ViscousLayers_i::GetIsToIgnoreFaces()
129 {
130   return GetImpl()->IsToIgnoreShapes();
131 }
132
133 //================================================================================
134 /*!
135  * \brief 
136  */
137 //================================================================================
138
139 void StdMeshers_ViscousLayers_i::SetIgnoreFaces(const ::SMESH::long_array& faceIDs)
140 throw ( SALOME::SALOME_Exception )
141 {
142   vector<int> ids( faceIDs.length() );
143   for ( unsigned i = 0; i < ids.size(); ++i )
144     if (( ids[i] = faceIDs[i] ) < 1 )
145       THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
146   GetImpl()->SetBndShapes( ids, /*toIgnore=*/true );
147   SMESH::TPythonDump() << _this() << ".SetIgnoreFaces( " << faceIDs << " )";
148 }
149
150 //================================================================================
151 /*!
152  * \brief 
153  */
154 //================================================================================
155
156 void StdMeshers_ViscousLayers_i::SetTotalThickness(::CORBA::Double thickness)
157 throw ( SALOME::SALOME_Exception )
158 {
159   if ( thickness < 1e-100 )
160     THROW_SALOME_CORBA_EXCEPTION( "Invalid thickness", SALOME::BAD_PARAM );
161   GetImpl()->SetTotalThickness(thickness);
162   SMESH::TPythonDump() << _this() << ".SetTotalThickness( " << SMESH::TVar(thickness) << " )";
163 }
164
165 //================================================================================
166 /*!
167  * \brief 
168  */
169 //================================================================================
170
171 ::CORBA::Double StdMeshers_ViscousLayers_i::GetTotalThickness()
172 {
173   return GetImpl()->GetTotalThickness();
174 }
175
176 //================================================================================
177 /*!
178  * \brief 
179  *  \param nb - 
180  */
181 //================================================================================
182
183 void StdMeshers_ViscousLayers_i::SetNumberLayers(::CORBA::Short nb)
184 throw ( SALOME::SALOME_Exception )
185 {
186   if ( nb < 1 )
187     THROW_SALOME_CORBA_EXCEPTION( "Invalid number of layers", SALOME::BAD_PARAM );
188   GetImpl()->SetNumberLayers( nb );
189   SMESH::TPythonDump() << _this() << ".SetNumberLayers( " << SMESH::TVar(nb) << " )";
190 }
191
192 //================================================================================
193 /*!
194  * \brief 
195  */
196 //================================================================================
197
198 ::CORBA::Short StdMeshers_ViscousLayers_i::GetNumberLayers()
199 {
200   return CORBA::Short( GetImpl()->GetNumberLayers() );
201 }
202
203 //================================================================================
204 /*!
205  * \brief 
206  *  \param factor - 
207  */
208 //================================================================================
209
210 void StdMeshers_ViscousLayers_i::SetStretchFactor(::CORBA::Double factor)
211 throw ( SALOME::SALOME_Exception )
212 {
213   if ( factor < 1 )
214     THROW_SALOME_CORBA_EXCEPTION( "Invalid stretch factor, it must be >= 1.0", SALOME::BAD_PARAM );
215   GetImpl()->SetStretchFactor(factor);
216   SMESH::TPythonDump() << _this() << ".SetStretchFactor( " << SMESH::TVar(factor) << " )";
217 }
218
219 //================================================================================
220 /*!
221  * \brief 
222  * 
223  */
224 //================================================================================
225
226 ::CORBA::Double StdMeshers_ViscousLayers_i::GetStretchFactor()
227 {
228   return GetImpl()->GetStretchFactor();
229 }
230
231 //================================================================================
232 /*!
233  * \brief Set Method of computing translation of a node
234  */
235 //================================================================================
236
237 void StdMeshers_ViscousLayers_i::SetMethod( ::StdMeshers::VLExtrusionMethod how )
238 {
239   GetImpl()->SetMethod( ::StdMeshers_ViscousLayers::ExtrusionMethod( how ));
240   const char* methNames[3] = { "SURF_OFFSET_SMOOTH",
241                                "FACE_OFFSET",
242                                "NODE_OFFSET" };
243   if ( how >= 0 && how < 3 )
244     SMESH::TPythonDump() << _this() << ".SetMethod( StdMeshers." << methNames[ how ]<< " )";
245 }
246
247 //================================================================================
248 /*!
249  * \brief Return Method of computing translation of a node
250  */
251 //================================================================================
252
253 ::StdMeshers::VLExtrusionMethod StdMeshers_ViscousLayers_i::GetMethod()
254 {
255   return (::StdMeshers::VLExtrusionMethod) GetImpl()->GetMethod();
256 }
257
258 //=============================================================================
259 /*!
260  *  Get implementation
261  */
262 //=============================================================================
263
264 ::StdMeshers_ViscousLayers* StdMeshers_ViscousLayers_i::GetImpl()
265 {
266   return ( ::StdMeshers_ViscousLayers* )myBaseImpl;
267 }
268
269 //================================================================================
270 /*!
271  * \brief Verify whether hypothesis supports given entity type 
272   * \param type - dimension (see SMESH::Dimension enumeration)
273   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
274  * 
275  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
276  */
277 //================================================================================  
278 CORBA::Boolean StdMeshers_ViscousLayers_i::IsDimSupported( SMESH::Dimension type )
279 {
280   return type == SMESH::DIM_3D;
281 }
282
283 //================================================================================
284 /*!
285  * \brief Return method name corresponding to index of variable parameter
286  */
287 //================================================================================
288
289 std::string StdMeshers_ViscousLayers_i::getMethodOfParameter(const int paramIndex, int ) const
290 {
291   // order of methods was defined by StdMeshersGUI_StdHypothesisCreator::storeParams()
292   switch ( paramIndex )
293   {
294   case 0: return "SetTotalThickness";
295   case 1: return "SetNumberLayers";
296   case 2: return "SetStretchFactor";
297   }
298   return "";
299 }