Salome HOME
#16522 [CEA 7599] Viscous layers hypothesis: extract layers as a group
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ViscousLayers2D_i.cxx
1 // Copyright (C) 2007-2019  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   throw ( SALOME::SALOME_Exception )
79 {
80   vector<int> ids( edgeIDs.length() );
81   for ( unsigned i = 0; i < ids.size(); ++i )
82     if (( ids[i] = edgeIDs[i] ) < 1 )
83       THROW_SALOME_CORBA_EXCEPTION( "Invalid edge id", SALOME::BAD_PARAM );
84
85   GetImpl()->SetBndShapes( ids, toIgnore );
86
87   SMESH::TPythonDump() << _this() << ".SetEdges( " << edgeIDs << ", " << toIgnore << " )";
88 }
89
90 //================================================================================
91 /*!
92  * \brief 
93  */
94 //================================================================================
95
96 void StdMeshers_ViscousLayers2D_i::SetIgnoreEdges(const ::SMESH::long_array& edgeIDs)
97   throw ( SALOME::SALOME_Exception )
98 {
99   SMESH::TPythonDump pyDump;
100   this->SetEdges( edgeIDs, true );
101   pyDump<< _this() << ".SetIgnoreEdges( " << edgeIDs << " )";
102 }
103
104 //================================================================================
105 /*!
106  * \brief 
107  */
108 //================================================================================
109
110 SMESH::long_array* StdMeshers_ViscousLayers2D_i::GetEdges()
111 {
112   vector<int> idsVec = GetImpl()->GetBndShapes();
113   SMESH::long_array_var ids = new SMESH::long_array;
114   ids->length( idsVec.size() );
115   for ( unsigned i = 0; i < idsVec.size(); ++i )
116     ids[i] = idsVec[i];
117   return ids._retn();
118 }
119
120 //================================================================================
121 /*!
122  * \brief 
123  */
124 //================================================================================
125
126 SMESH::long_array* StdMeshers_ViscousLayers2D_i::GetIgnoreEdges()
127 {
128   if ( GetImpl()->IsToIgnoreShapes() )
129     return this->GetEdges();
130   return new SMESH::long_array;
131 }
132
133 //================================================================================
134 /*!
135  * \brief 
136  */
137 //================================================================================
138
139 CORBA::Boolean StdMeshers_ViscousLayers2D_i::GetIsToIgnoreEdges()
140 {
141   return GetImpl()->IsToIgnoreShapes();
142 }
143
144 //================================================================================
145 /*!
146  * \brief 
147  */
148 //================================================================================
149
150 void StdMeshers_ViscousLayers2D_i::SetTotalThickness(::CORBA::Double thickness)
151 throw ( SALOME::SALOME_Exception )
152 {
153   if ( thickness < 1e-100 )
154     THROW_SALOME_CORBA_EXCEPTION( "Invalid thickness", SALOME::BAD_PARAM );
155   GetImpl()->SetTotalThickness(thickness);
156   SMESH::TPythonDump() << _this() << ".SetTotalThickness( " << SMESH::TVar(thickness) << " )";
157 }
158
159 //================================================================================
160 /*!
161  * \brief 
162  */
163 //================================================================================
164
165 ::CORBA::Double StdMeshers_ViscousLayers2D_i::GetTotalThickness()
166 {
167   return GetImpl()->GetTotalThickness();
168 }
169
170 //================================================================================
171 /*!
172  * \brief 
173  *  \param nb - 
174  */
175 //================================================================================
176
177 void StdMeshers_ViscousLayers2D_i::SetNumberLayers(::CORBA::Short nb)
178 throw ( SALOME::SALOME_Exception )
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_ViscousLayers2D_i::GetNumberLayers()
193 {
194   return CORBA::Short( GetImpl()->GetNumberLayers() );
195 }
196
197 //================================================================================
198 /*!
199  * \brief 
200  *  \param factor - 
201  */
202 //================================================================================
203
204 void StdMeshers_ViscousLayers2D_i::SetStretchFactor(::CORBA::Double factor)
205 throw ( SALOME::SALOME_Exception )
206 {
207   if ( factor < 1 )
208     THROW_SALOME_CORBA_EXCEPTION( "Invalid stretch factor, it must be >= 1.0", SALOME::BAD_PARAM );
209   GetImpl()->SetStretchFactor(factor);
210   SMESH::TPythonDump() << _this() << ".SetStretchFactor( " << SMESH::TVar(factor) << " )";
211 }
212
213 //================================================================================
214 /*!
215  * \brief 
216  * 
217  */
218 //================================================================================
219
220 ::CORBA::Double StdMeshers_ViscousLayers2D_i::GetStretchFactor()
221 {
222   return GetImpl()->GetStretchFactor();
223 }
224
225 //================================================================================
226 /*!
227  * \brief Set name of a group of layers elements
228  */
229 //================================================================================
230
231 void StdMeshers_ViscousLayers2D_i::SetGroupName(const char* name)
232 {
233   if ( GetImpl()->GetGroupName() != name )
234   {
235     GetImpl()->SetGroupName( name );
236     SMESH::TPythonDump() << _this() << ".SetGroupName( '" << name << "' )";
237   }
238 }
239
240 //================================================================================
241 /*!
242  * \brief Return name of a group of layers elements
243  */
244 //================================================================================
245
246 char* StdMeshers_ViscousLayers2D_i::GetGroupName()
247 {
248   return CORBA::string_dup( GetImpl()->GetGroupName().c_str() );
249 }
250
251
252 //=============================================================================
253 /*!
254  *  Get implementation
255  */
256 //=============================================================================
257
258 ::StdMeshers_ViscousLayers2D* StdMeshers_ViscousLayers2D_i::GetImpl()
259 {
260   return ( ::StdMeshers_ViscousLayers2D* )myBaseImpl;
261 }
262
263 //================================================================================
264 /*!
265  * \brief Verify whether hypothesis supports given entity type
266  *  \param type - dimension (see SMESH::Dimension enumeration)
267  *  \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
268  *
269  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
270  */
271 //================================================================================
272
273 CORBA::Boolean StdMeshers_ViscousLayers2D_i::IsDimSupported( SMESH::Dimension type )
274 {
275   return type == SMESH::DIM_2D;
276 }
277
278 //================================================================================
279 /*!
280  * \brief Sets sub-mesh event listeners to clear sub-meshes of edges
281  *        shrinked by viscous layers
282  */
283 //================================================================================
284
285 void StdMeshers_ViscousLayers2D_i::UpdateAsMeshesRestored()
286 {
287   GetImpl()->RestoreListeners();
288 }
289
290 //================================================================================
291 /*!
292  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
293  */
294 //================================================================================
295
296 bool
297 StdMeshers_ViscousLayers2D_i::getObjectsDependOn( std::vector< std::string > & entryArray,
298                                                   std::vector< int >         & subIDArray ) const
299 {
300   const ::StdMeshers_ViscousLayers2D* impl =
301     static_cast<const ::StdMeshers_ViscousLayers2D*>( myBaseImpl );
302
303   subIDArray = impl->GetBndShapes();
304
305   return true;
306 }
307
308 //================================================================================
309 /*!
310  * \brief Set new geometry instead of that returned by getObjectsDependOn()
311  */
312 //================================================================================
313
314 bool
315 StdMeshers_ViscousLayers2D_i::setObjectsDependOn( std::vector< std::string > & entryArray,
316                                                   std::vector< int >         & subIDArray )
317 {
318   std::vector< int > newIDs;
319   newIDs.reserve( subIDArray.size() );
320
321   for ( size_t i = 0; i < subIDArray.size(); ++i )
322     if ( subIDArray[ i ] > 0 )
323       newIDs.push_back( subIDArray[ i ]);
324
325   GetImpl()->SetBndShapes( newIDs, GetIsToIgnoreEdges() );
326
327   return true;
328 }