Salome HOME
Merge branch 'V9_9_BR'
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ViscousLayers2D_i.cxx
1 // Copyright (C) 2007-2022  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 //  File   : StdMeshers_ViscousLayers2D_i.cxx
24 //  Module : SMESH
25 //
26 #include "StdMeshers_ViscousLayers2D_i.hxx"
27
28 #include "SMESH_Gen.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_PythonDump.hxx"
31
32 #include "Utils_CorbaException.hxx"
33 #include "utilities.h"
34
35 #include <TCollection_AsciiString.hxx>
36
37 #include CORBA_SERVER_HEADER(SMESH_Group)
38
39 using namespace std;
40
41 //=============================================================================
42 /*!
43  *  StdMeshers_ViscousLayers2D_i::StdMeshers_ViscousLayers2D_i
44  *
45  *  Constructor
46  */
47 //=============================================================================
48
49 StdMeshers_ViscousLayers2D_i::StdMeshers_ViscousLayers2D_i( PortableServer::POA_ptr thePOA,
50                                                             ::SMESH_Gen*            theGenImpl )
51   : SALOME::GenericObj_i( thePOA ),
52     SMESH_Hypothesis_i( thePOA )
53 {
54   myBaseImpl = new ::StdMeshers_ViscousLayers2D( theGenImpl->GetANewId(),
55                                                  theGenImpl );
56 }
57
58 //=============================================================================
59 /*!
60  *  StdMeshers_ViscousLayers2D_i::~StdMeshers_ViscousLayers2D_i
61  *
62  *  Destructor
63  */
64 //=============================================================================
65
66 StdMeshers_ViscousLayers2D_i::~StdMeshers_ViscousLayers2D_i()
67 {
68 }
69
70 //================================================================================
71 /*!
72  * \brief 
73  */
74 //================================================================================
75
76 void StdMeshers_ViscousLayers2D_i::SetEdges(const ::SMESH::long_array& edgeIDs,
77                                             CORBA::Boolean             toIgnore)
78 {
79   vector<int> ids( edgeIDs.length() );
80   for ( unsigned i = 0; i < ids.size(); ++i )
81     if (( ids[i] = edgeIDs[i] ) < 1 )
82       THROW_SALOME_CORBA_EXCEPTION( "Invalid edge id", SALOME::BAD_PARAM );
83
84   GetImpl()->SetBndShapes( ids, toIgnore );
85
86   SMESH::TPythonDump() << _this() << ".SetEdges( " << edgeIDs << ", " << toIgnore << " )";
87 }
88
89 //================================================================================
90 /*!
91  * \brief 
92  */
93 //================================================================================
94
95 void StdMeshers_ViscousLayers2D_i::SetIgnoreEdges(const ::SMESH::long_array& edgeIDs)
96 {
97   SMESH::TPythonDump pyDump;
98   this->SetEdges( edgeIDs, true );
99   pyDump<< _this() << ".SetIgnoreEdges( " << edgeIDs << " )";
100 }
101
102 //================================================================================
103 /*!
104  * \brief 
105  */
106 //================================================================================
107
108 SMESH::long_array* StdMeshers_ViscousLayers2D_i::GetEdges()
109 {
110   vector<int> idsVec = GetImpl()->GetBndShapes();
111   SMESH::long_array_var ids = new SMESH::long_array;
112   ids->length( idsVec.size() );
113   for ( unsigned i = 0; i < idsVec.size(); ++i )
114     ids[i] = idsVec[i];
115   return ids._retn();
116 }
117
118 //================================================================================
119 /*!
120  * \brief 
121  */
122 //================================================================================
123
124 SMESH::long_array* StdMeshers_ViscousLayers2D_i::GetIgnoreEdges()
125 {
126   if ( GetImpl()->IsToIgnoreShapes() )
127     return this->GetEdges();
128   return new SMESH::long_array;
129 }
130
131 //================================================================================
132 /*!
133  * \brief 
134  */
135 //================================================================================
136
137 CORBA::Boolean StdMeshers_ViscousLayers2D_i::GetIsToIgnoreEdges()
138 {
139   return GetImpl()->IsToIgnoreShapes();
140 }
141
142 //================================================================================
143 /*!
144  * \brief 
145  */
146 //================================================================================
147
148 void StdMeshers_ViscousLayers2D_i::SetTotalThickness(::CORBA::Double thickness)
149 {
150   if ( thickness < 1e-100 )
151     THROW_SALOME_CORBA_EXCEPTION( "Invalid thickness", SALOME::BAD_PARAM );
152   GetImpl()->SetTotalThickness(thickness);
153   SMESH::TPythonDump() << _this() << ".SetTotalThickness( " << SMESH::TVar(thickness) << " )";
154 }
155
156 //================================================================================
157 /*!
158  * \brief 
159  */
160 //================================================================================
161
162 ::CORBA::Double StdMeshers_ViscousLayers2D_i::GetTotalThickness()
163 {
164   return GetImpl()->GetTotalThickness();
165 }
166
167 //================================================================================
168 /*!
169  * \brief 
170  *  \param nb - 
171  */
172 //================================================================================
173
174 void StdMeshers_ViscousLayers2D_i::SetNumberLayers(::CORBA::Short nb)
175 {
176   if ( nb < 1 )
177     THROW_SALOME_CORBA_EXCEPTION( "Invalid number of layers", SALOME::BAD_PARAM );
178   GetImpl()->SetNumberLayers( nb );
179   SMESH::TPythonDump() << _this() << ".SetNumberLayers( " << SMESH::TVar(nb) << " )";
180 }
181
182 //================================================================================
183 /*!
184  * \brief 
185  */
186 //================================================================================
187
188 ::CORBA::Short StdMeshers_ViscousLayers2D_i::GetNumberLayers()
189 {
190   return CORBA::Short( GetImpl()->GetNumberLayers() );
191 }
192
193 //================================================================================
194 /*!
195  * \brief 
196  *  \param factor - 
197  */
198 //================================================================================
199
200 void StdMeshers_ViscousLayers2D_i::SetStretchFactor(::CORBA::Double factor)
201 {
202   if ( factor < 1 )
203     THROW_SALOME_CORBA_EXCEPTION( "Invalid stretch factor, it must be >= 1.0", SALOME::BAD_PARAM );
204   GetImpl()->SetStretchFactor(factor);
205   SMESH::TPythonDump() << _this() << ".SetStretchFactor( " << SMESH::TVar(factor) << " )";
206 }
207
208 //================================================================================
209 /*!
210  * \brief 
211  * 
212  */
213 //================================================================================
214
215 ::CORBA::Double StdMeshers_ViscousLayers2D_i::GetStretchFactor()
216 {
217   return GetImpl()->GetStretchFactor();
218 }
219
220 //================================================================================
221 /*!
222  * \brief Set name of a group of layers elements
223  */
224 //================================================================================
225
226 void StdMeshers_ViscousLayers2D_i::SetGroupName(const char* name)
227 {
228   if ( GetImpl()->GetGroupName() != name )
229   {
230     GetImpl()->SetGroupName( name );
231     SMESH::TPythonDump() << _this() << ".SetGroupName( '" << name << "' )";
232   }
233 }
234
235 //================================================================================
236 /*!
237  * \brief Return name of a group of layers elements
238  */
239 //================================================================================
240
241 char* StdMeshers_ViscousLayers2D_i::GetGroupName()
242 {
243   return CORBA::string_dup( GetImpl()->GetGroupName().c_str() );
244 }
245
246
247 //=============================================================================
248 /*!
249  *  Get implementation
250  */
251 //=============================================================================
252
253 ::StdMeshers_ViscousLayers2D* StdMeshers_ViscousLayers2D_i::GetImpl()
254 {
255   return ( ::StdMeshers_ViscousLayers2D* )myBaseImpl;
256 }
257
258 //================================================================================
259 /*!
260  * \brief Verify whether hypothesis supports given entity type
261  *  \param type - dimension (see SMESH::Dimension enumeration)
262  *  \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
263  *
264  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
265  */
266 //================================================================================
267
268 CORBA::Boolean StdMeshers_ViscousLayers2D_i::IsDimSupported( SMESH::Dimension type )
269 {
270   return type == SMESH::DIM_2D;
271 }
272
273 //================================================================================
274 /*!
275  * \brief Sets sub-mesh event listeners to clear sub-meshes of edges
276  *        shrinked by viscous layers
277  */
278 //================================================================================
279
280 void StdMeshers_ViscousLayers2D_i::UpdateAsMeshesRestored()
281 {
282   GetImpl()->RestoreListeners();
283 }
284
285 //================================================================================
286 /*!
287  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
288  */
289 //================================================================================
290
291 bool
292 StdMeshers_ViscousLayers2D_i::getObjectsDependOn( std::vector< std::string > & /*entryArray*/,
293                                                   std::vector< int >         & subIDArray ) const
294 {
295   const ::StdMeshers_ViscousLayers2D* impl =
296     static_cast<const ::StdMeshers_ViscousLayers2D*>( myBaseImpl );
297
298   subIDArray = impl->GetBndShapes();
299
300   return true;
301 }
302
303 //================================================================================
304 /*!
305  * \brief Set new geometry instead of that returned by getObjectsDependOn()
306  */
307 //================================================================================
308
309 bool
310 StdMeshers_ViscousLayers2D_i::setObjectsDependOn( std::vector< std::string > & /*entryArray*/,
311                                                   std::vector< int >         & subIDArray )
312 {
313   std::vector< int > newIDs;
314   newIDs.reserve( subIDArray.size() );
315
316   for ( size_t i = 0; i < subIDArray.size(); ++i )
317     if ( subIDArray[ i ] > 0 )
318       newIDs.push_back( subIDArray[ i ]);
319
320   GetImpl()->SetBndShapes( newIDs, GetIsToIgnoreEdges() );
321
322   return true;
323 }