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