Salome HOME
Copyright update 2021
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ViscousLayers_i.cxx
1 // Copyright (C) 2007-2021  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 classes
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                                                         ::SMESH_Gen*            theGenImpl )
52   : SALOME::GenericObj_i( thePOA ), 
53     SMESH_Hypothesis_i( thePOA )
54 {
55   myBaseImpl = new ::StdMeshers_ViscousLayers( theGenImpl->GetANewId(),
56                                                theGenImpl );
57 }
58
59 //=============================================================================
60 /*!
61  *  StdMeshers_ViscousLayers_i::~StdMeshers_ViscousLayers_i
62  *
63  *  Destructor
64  */
65 //=============================================================================
66
67 StdMeshers_ViscousLayers_i::~StdMeshers_ViscousLayers_i()
68 {
69 }
70
71 //================================================================================
72 /*!
73  * \brief 
74  */
75 //================================================================================
76
77 void StdMeshers_ViscousLayers_i::SetFaces(const ::SMESH::long_array& faceIDs,
78                                           CORBA::Boolean             toIgnore)
79 {
80   vector<int> ids( faceIDs.length() );
81   for ( unsigned i = 0; i < ids.size(); ++i )
82     if (( ids[i] = faceIDs[i] ) < 1 )
83       THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
84
85   GetImpl()->SetBndShapes( ids, toIgnore );
86
87   SMESH::TPythonDump() << _this() << ".SetFaces( " << faceIDs << ", " << toIgnore << " )";
88 }
89
90 //================================================================================
91 /*!
92  * \brief 
93  */
94 //================================================================================
95
96 SMESH::long_array* StdMeshers_ViscousLayers_i::GetFaces()
97 {
98   vector<int> idsVec = GetImpl()->GetBndShapes();
99   SMESH::long_array_var ids = new SMESH::long_array;
100   ids->length( idsVec.size() );
101   for ( unsigned i = 0; i < idsVec.size(); ++i )
102     ids[i] = idsVec[i];
103   return ids._retn();
104 }
105
106 //================================================================================
107 /*!
108  * \brief 
109  */
110 //================================================================================
111
112 SMESH::long_array* StdMeshers_ViscousLayers_i::GetIgnoreFaces()
113 {
114   if ( GetImpl()->IsToIgnoreShapes() )
115     return this->GetFaces();
116   return new SMESH::long_array;
117 }
118
119 //================================================================================
120 /*!
121  * \brief 
122  */
123 //================================================================================
124
125 CORBA::Boolean StdMeshers_ViscousLayers_i::GetIsToIgnoreFaces()
126 {
127   return GetImpl()->IsToIgnoreShapes();
128 }
129
130 //================================================================================
131 /*!
132  * \brief 
133  */
134 //================================================================================
135
136 void StdMeshers_ViscousLayers_i::SetIgnoreFaces(const ::SMESH::long_array& faceIDs)
137 {
138   vector<int> ids( faceIDs.length() );
139   for ( unsigned i = 0; i < ids.size(); ++i )
140     if (( ids[i] = faceIDs[i] ) < 1 )
141       THROW_SALOME_CORBA_EXCEPTION( "Invalid face id", SALOME::BAD_PARAM );
142   GetImpl()->SetBndShapes( ids, /*toIgnore=*/true );
143   SMESH::TPythonDump() << _this() << ".SetIgnoreFaces( " << faceIDs << " )";
144 }
145
146 //================================================================================
147 /*!
148  * \brief 
149  */
150 //================================================================================
151
152 void StdMeshers_ViscousLayers_i::SetTotalThickness(::CORBA::Double thickness)
153 {
154   if ( thickness < 1e-100 )
155     THROW_SALOME_CORBA_EXCEPTION( "Invalid thickness", SALOME::BAD_PARAM );
156   GetImpl()->SetTotalThickness(thickness);
157   SMESH::TPythonDump() << _this() << ".SetTotalThickness( " << SMESH::TVar(thickness) << " )";
158 }
159
160 //================================================================================
161 /*!
162  * \brief 
163  */
164 //================================================================================
165
166 ::CORBA::Double StdMeshers_ViscousLayers_i::GetTotalThickness()
167 {
168   return GetImpl()->GetTotalThickness();
169 }
170
171 //================================================================================
172 /*!
173  * \brief 
174  *  \param nb - 
175  */
176 //================================================================================
177
178 void StdMeshers_ViscousLayers_i::SetNumberLayers(::CORBA::Short nb)
179 {
180   if ( nb < 1 )
181     THROW_SALOME_CORBA_EXCEPTION( "Invalid number of layers", SALOME::BAD_PARAM );
182   GetImpl()->SetNumberLayers( nb );
183   SMESH::TPythonDump() << _this() << ".SetNumberLayers( " << SMESH::TVar(nb) << " )";
184 }
185
186 //================================================================================
187 /*!
188  * \brief 
189  */
190 //================================================================================
191
192 ::CORBA::Short StdMeshers_ViscousLayers_i::GetNumberLayers()
193 {
194   return CORBA::Short( GetImpl()->GetNumberLayers() );
195 }
196
197 //================================================================================
198 /*!
199  * \brief 
200  *  \param factor - 
201  */
202 //================================================================================
203
204 void StdMeshers_ViscousLayers_i::SetStretchFactor(::CORBA::Double factor)
205 {
206   if ( factor < 1 )
207     THROW_SALOME_CORBA_EXCEPTION( "Invalid stretch factor, it must be >= 1.0", SALOME::BAD_PARAM );
208   GetImpl()->SetStretchFactor(factor);
209   SMESH::TPythonDump() << _this() << ".SetStretchFactor( " << SMESH::TVar(factor) << " )";
210 }
211
212 //================================================================================
213 /*!
214  * \brief 
215  * 
216  */
217 //================================================================================
218
219 ::CORBA::Double StdMeshers_ViscousLayers_i::GetStretchFactor()
220 {
221   return GetImpl()->GetStretchFactor();
222 }
223
224 //================================================================================
225 /*!
226  * \brief Set Method of computing translation of a node
227  */
228 //================================================================================
229
230 void StdMeshers_ViscousLayers_i::SetMethod( ::StdMeshers::VLExtrusionMethod how )
231 {
232   GetImpl()->SetMethod( ::StdMeshers_ViscousLayers::ExtrusionMethod( how ));
233   const char* methNames[3] = { "SURF_OFFSET_SMOOTH",
234                                "FACE_OFFSET",
235                                "NODE_OFFSET" };
236   if ( how >= 0 && how < 3 )
237     SMESH::TPythonDump() << _this() << ".SetMethod( StdMeshers." << methNames[ how ]<< " )";
238 }
239
240 //================================================================================
241 /*!
242  * \brief Return Method of computing translation of a node
243  */
244 //================================================================================
245
246 ::StdMeshers::VLExtrusionMethod StdMeshers_ViscousLayers_i::GetMethod()
247 {
248   return (::StdMeshers::VLExtrusionMethod) GetImpl()->GetMethod();
249 }
250
251 //================================================================================
252 /*!
253  * \brief Set name of a group of layers elements
254  */
255 //================================================================================
256
257 void StdMeshers_ViscousLayers_i::SetGroupName(const char* name)
258 {
259   if ( GetImpl()->GetGroupName() != name )
260   {
261     GetImpl()->SetGroupName( name );
262     SMESH::TPythonDump() << _this() << ".SetGroupName( '" << name << "' )";
263   }
264 }
265
266 //================================================================================
267 /*!
268  * \brief Return name of a group of layers elements
269  */
270 //================================================================================
271
272 char* StdMeshers_ViscousLayers_i::GetGroupName()
273 {
274   return CORBA::string_dup( GetImpl()->GetGroupName().c_str() );
275 }
276
277 //=============================================================================
278 /*!
279  *  Get implementation
280  */
281 //=============================================================================
282
283 ::StdMeshers_ViscousLayers* StdMeshers_ViscousLayers_i::GetImpl()
284 {
285   return ( ::StdMeshers_ViscousLayers* )myBaseImpl;
286 }
287
288 //================================================================================
289 /*!
290  * \brief Verify whether hypothesis supports given entity type 
291   * \param type - dimension (see SMESH::Dimension enumeration)
292   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
293  * 
294  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
295  */
296 //================================================================================  
297 CORBA::Boolean StdMeshers_ViscousLayers_i::IsDimSupported( SMESH::Dimension type )
298 {
299   return type == SMESH::DIM_3D;
300 }
301
302 //================================================================================
303 /*!
304  * \brief Return method name corresponding to index of variable parameter
305  */
306 //================================================================================
307
308 std::string StdMeshers_ViscousLayers_i::getMethodOfParameter(const int paramIndex, int ) const
309 {
310   // order of methods was defined by StdMeshersGUI_StdHypothesisCreator::storeParams()
311   switch ( paramIndex )
312   {
313   case 0: return "SetTotalThickness";
314   case 1: return "SetNumberLayers";
315   case 2: return "SetStretchFactor";
316   }
317   return "";
318 }
319
320
321 //================================================================================
322 /*!
323  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
324  */
325 //================================================================================
326
327 bool
328 StdMeshers_ViscousLayers_i::getObjectsDependOn( std::vector< std::string > & /*entryArray*/,
329                                                 std::vector< int >         & subIDArray ) const
330 {
331   const ::StdMeshers_ViscousLayers* impl =
332     static_cast<const ::StdMeshers_ViscousLayers*>( myBaseImpl );
333
334   subIDArray = impl->GetBndShapes();
335
336   return true;
337 }
338
339 //================================================================================
340 /*!
341  * \brief Set new geometry instead of that returned by getObjectsDependOn()
342  */
343 //================================================================================
344
345 bool
346 StdMeshers_ViscousLayers_i::setObjectsDependOn( std::vector< std::string > & /*entryArray*/,
347                                                 std::vector< int >         & subIDArray )
348 {
349   std::vector< int > newIDs;
350   newIDs.reserve( subIDArray.size() );
351
352   for ( size_t i = 0; i < subIDArray.size(); ++i )
353     if ( subIDArray[ i ] > 0 )
354       newIDs.push_back( subIDArray[ i ]);
355
356   GetImpl()->SetBndShapes( newIDs, GetIsToIgnoreFaces() );
357
358   return true;
359 }