Salome HOME
23586: [EDF] HYDRO: Copy mesh to new geometry
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_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 classes
24 //  File   : StdMeshers_NumberOfSegments_i.cxx
25 //           Moved here from SMESH_NumberOfSegments_i.cxx
26 //  Author : Paul RASCLE, EDF
27 //  Module : SMESH
28 //
29 #include "StdMeshers_NumberOfSegments_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
33
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
36
37 #include <TCollection_AsciiString.hxx>
38
39 //=============================================================================
40 /*!
41  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
42  *
43  *  Constructor
44  */
45 //=============================================================================
46
47 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
48                                                               ::SMESH_Gen*            theGenImpl )
49   : SALOME::GenericObj_i( thePOA ),
50     SMESH_Hypothesis_i( thePOA ),
51     StdMeshers_Reversible1D_i( this )
52 {
53   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
54                                                   theGenImpl );
55 }
56
57 //=============================================================================
58 /*!
59  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
60  *
61  *  Destructor
62  */
63 //=============================================================================
64
65 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
66 {
67 }
68
69 //=============================================================================
70 /*!
71  *  StdMeshers_NumberOfSegments_i::BuildDistribution
72  *
73  *  Builds point distribution according to passed function
74  */
75 //=============================================================================
76 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
77                                                                            CORBA::Long nbSeg, 
78                                                                            CORBA::Long conv )
79   throw ( SALOME::SALOME_Exception )
80 {
81   ASSERT( myBaseImpl );
82   try
83   {
84     SMESH::double_array_var aRes = new SMESH::double_array();
85     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
86     aRes->length( res.size() );
87     for (size_t i = 0; i < res.size(); i++)
88       aRes[i] = res[i];
89     return aRes._retn();
90   }
91   catch( SALOME_Exception& S_ex )
92   {
93     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
94   }
95 }
96
97 SMESH::double_array*
98 StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
99                                                      CORBA::Long                nbSeg,
100                                                      CORBA::Long                conv )
101   throw ( SALOME::SALOME_Exception )
102 {
103   ASSERT( myBaseImpl );
104
105   std::vector<double> tbl( func.length() );
106   for ( size_t i = 0; i < tbl.size(); i++ )
107     tbl[i] = func[i];
108
109   try
110   {
111     SMESH::double_array_var   aRes = new SMESH::double_array();
112     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
113     aRes->length( res.size() );
114     for (size_t i = 0; i < res.size(); i++)
115       aRes[i] = res[i];
116     return aRes._retn();
117   }
118   catch( SALOME_Exception& S_ex )
119   {
120     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
121   }
122 }
123
124 //=============================================================================
125 /*!
126  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
127  *
128  *  Set number of segments
129  */
130 //=============================================================================
131
132 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
133      throw ( SALOME::SALOME_Exception )
134 {
135   ASSERT( myBaseImpl );
136   try {
137     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
138   }
139   catch (SALOME_Exception& S_ex) {
140     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
141                                   SALOME::BAD_PARAM );
142   }
143
144   // Update Python script
145   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
146 }
147
148 //=============================================================================
149 /*!
150  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
151  *
152  *  Get number of segments
153  */
154 //=============================================================================
155
156 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
157 {
158   ASSERT( myBaseImpl );
159   return this->GetImpl()->GetNumberOfSegments();
160 }
161
162 //=============================================================================
163 /*!
164  */
165 //=============================================================================
166
167 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
168   throw ( SALOME::SALOME_Exception )
169 {
170   ASSERT( myBaseImpl );
171   try {
172     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
173
174     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
175
176     // Update Python script
177     if ( oldType != typ )
178       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
179   }
180   catch ( SALOME_Exception& S_ex ) {
181     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
182                                   SALOME::BAD_PARAM );
183   }
184 }
185
186 //=============================================================================
187 /*!
188  */
189 //=============================================================================
190
191 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
192 {
193   ASSERT( myBaseImpl );
194   return this->GetImpl()->GetDistrType();
195 }
196
197 //=============================================================================
198 /*!
199  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
200  *
201  *  Set scalar factor
202  */
203 //=============================================================================
204
205 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
206      throw ( SALOME::SALOME_Exception )
207 {
208   ASSERT( myBaseImpl );
209   try {
210     this->GetImpl()->SetScaleFactor( theScaleFactor );
211     // Update Python script
212     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
213   }
214   catch ( SALOME_Exception& S_ex ) {
215     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
216                                   SALOME::BAD_PARAM );
217   }
218 }
219
220 //=============================================================================
221 /*!
222  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
223  *
224  *  Get scalar factor
225  */
226 //=============================================================================
227
228 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
229   throw ( SALOME::SALOME_Exception )
230 {
231   ASSERT( myBaseImpl );
232   double scale;
233   try {
234     scale = this->GetImpl()->GetScaleFactor();
235   }
236   catch ( SALOME_Exception& S_ex ) {
237     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
238                                   SALOME::BAD_PARAM );
239   }
240   return scale;
241 }
242
243 //=============================================================================
244 /*!
245  */
246 //=============================================================================
247
248 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
249   throw ( SALOME::SALOME_Exception )
250 {
251   ASSERT( myBaseImpl );
252   std::vector<double> tbl( table.length() );
253   for ( CORBA::ULong i = 0; i < table.length(); i++)
254     tbl[i] = table[i];
255   try {
256     this->GetImpl()->SetTableFunction( tbl );
257     // Update Python script
258     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
259   }
260   catch ( SALOME_Exception& S_ex ) {
261     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
262                                   SALOME::BAD_PARAM );
263   }
264 }
265
266 //=============================================================================
267 /*!
268  */
269 //=============================================================================
270
271 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
272   throw ( SALOME::SALOME_Exception )
273 {
274   ASSERT( myBaseImpl );
275   const std::vector<double>* tbl;
276   try {
277     tbl = &this->GetImpl()->GetTableFunction();
278   }
279   catch ( SALOME_Exception& S_ex ) {
280     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
281   }
282   SMESH::double_array_var aRes = new SMESH::double_array();
283   aRes->length(tbl->size());
284   for ( size_t i = 0; i < tbl->size(); i++ )
285     aRes[i] = (*tbl)[i];
286   return aRes._retn();
287 }
288
289 //=============================================================================
290 /*!
291  */
292 //=============================================================================
293
294 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
295   throw ( SALOME::SALOME_Exception )
296 {
297   ASSERT( myBaseImpl );
298   try {
299     this->GetImpl()->SetExpressionFunction( expr );
300     // Update Python script
301     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
302   }
303   catch ( SALOME_Exception& S_ex ) {
304     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
305                                   SALOME::BAD_PARAM );
306   }
307 }
308
309 //=============================================================================
310 /*!
311  */
312 //=============================================================================
313
314 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
315   throw ( SALOME::SALOME_Exception )
316 {
317   ASSERT( myBaseImpl );
318   const char* expr;
319   try {
320     expr = this->GetImpl()->GetExpressionFunction();
321   }
322   catch ( SALOME_Exception& S_ex ) {
323     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
324                                   SALOME::BAD_PARAM );
325   }
326   return CORBA::string_dup(expr);
327 }
328
329 //=============================================================================
330 /*!
331  */
332 //=============================================================================
333
334 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
335   throw ( SALOME::SALOME_Exception )
336 {
337   ASSERT( myBaseImpl );
338   try {
339     this->GetImpl()->SetConversionMode( conv );
340     // Update Python script
341     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
342   }
343   catch ( SALOME_Exception& S_ex ) {
344     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
345                                   SALOME::BAD_PARAM );
346   }
347 }
348
349 //=============================================================================
350 /*!
351  */
352 //=============================================================================
353
354 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
355   throw ( SALOME::SALOME_Exception )
356 {
357   ASSERT( myBaseImpl );
358   int conv;
359   try {
360     conv = this->GetImpl()->ConversionMode();
361   }
362   catch ( SALOME_Exception& S_ex ) {
363     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
364                                   SALOME::BAD_PARAM );
365   }
366   return conv;
367 }
368
369 //=============================================================================
370 /*!
371  *  StdMeshers_NumberOfSegments_i::GetImpl
372  *
373  *  Get implementation
374  */
375 //=============================================================================
376
377 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
378 {
379   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
380 }
381
382 //================================================================================
383 /*!
384  * \brief Verify whether hypothesis supports given entity type 
385   * \param type - dimension (see SMESH::Dimension enumeration)
386   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
387  * 
388  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
389  */
390 //================================================================================  
391 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
392 {
393   return type == SMESH::DIM_1D;
394 }
395
396 //================================================================================
397 /*!
398  * \brief Return method name corresponding to index of variable parameter
399  */
400 //================================================================================
401
402 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
403 {
404   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
405 }
406
407
408 //================================================================================
409 /*!
410  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
411  */
412 //================================================================================
413
414 bool
415 StdMeshers_NumberOfSegments_i::getObjectsDependOn( std::vector< std::string > & entryArray,
416                                                    std::vector< int >         & subIDArray ) const
417 {
418   return StdMeshers_Reversible1D_i::getObjectsDependOn( entryArray, subIDArray );
419 }
420
421 //================================================================================
422 /*!
423  * \brief Set new geometry instead of that returned by getObjectsDependOn()
424  */
425 //================================================================================
426
427 bool
428 StdMeshers_NumberOfSegments_i::setObjectsDependOn( std::vector< std::string > & entryArray,
429                                                    std::vector< int >         & subIDArray )
430 {
431   return StdMeshers_Reversible1D_i::setObjectsDependOn( entryArray, subIDArray );
432 }