Salome HOME
597f7a5c93a0eb9430aee5ca1b030cd1508bc864
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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 {
80   ASSERT( myBaseImpl );
81   try
82   {
83     SMESH::double_array_var aRes = new SMESH::double_array();
84     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
85     aRes->length( res.size() );
86     for (size_t i = 0; i < res.size(); i++)
87       aRes[i] = res[i];
88     return aRes._retn();
89   }
90   catch( SALOME_Exception& S_ex )
91   {
92     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
93   }
94 }
95
96 SMESH::double_array*
97 StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
98                                                      CORBA::Long                nbSeg,
99                                                      CORBA::Long                conv )
100 {
101   ASSERT( myBaseImpl );
102
103   std::vector<double> tbl( func.length() );
104   for ( size_t i = 0; i < tbl.size(); i++ )
105     tbl[i] = func[i];
106
107   try
108   {
109     SMESH::double_array_var   aRes = new SMESH::double_array();
110     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
111     aRes->length( res.size() );
112     for (size_t i = 0; i < res.size(); i++)
113       aRes[i] = res[i];
114     return aRes._retn();
115   }
116   catch( SALOME_Exception& S_ex )
117   {
118     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
119   }
120 }
121
122 //=============================================================================
123 /*!
124  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
125  *
126  *  Set number of segments
127  */
128 //=============================================================================
129
130 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( SMESH::smIdType theSegmentsNumber )
131 {
132   ASSERT( myBaseImpl );
133   try {
134     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
135   }
136   catch (SALOME_Exception& S_ex) {
137     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
138                                   SALOME::BAD_PARAM );
139   }
140
141   // Update Python script
142   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
143 }
144
145 //=============================================================================
146 /*!
147  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
148  *
149  *  Get number of segments
150  */
151 //=============================================================================
152
153 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
154 {
155   ASSERT( myBaseImpl );
156   return this->GetImpl()->GetNumberOfSegments();
157 }
158
159 //=============================================================================
160 /*!
161  */
162 //=============================================================================
163
164 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
165 {
166   ASSERT( myBaseImpl );
167   try {
168     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
169
170     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
171
172     // Update Python script
173     if ( oldType != typ )
174       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
175   }
176   catch ( SALOME_Exception& S_ex ) {
177     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
178                                   SALOME::BAD_PARAM );
179   }
180 }
181
182 //=============================================================================
183 /*!
184  */
185 //=============================================================================
186
187 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
188 {
189   ASSERT( myBaseImpl );
190   return this->GetImpl()->GetDistrType();
191 }
192
193 //=============================================================================
194 /*!
195  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
196  *
197  *  Set scalar factor
198  */
199 //=============================================================================
200
201 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
202 {
203   ASSERT( myBaseImpl );
204   try {
205     this->GetImpl()->SetScaleFactor( theScaleFactor );
206     // Update Python script
207     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
208   }
209   catch ( SALOME_Exception& S_ex ) {
210     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
211                                   SALOME::BAD_PARAM );
212   }
213 }
214
215 //=============================================================================
216 /*!
217  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
218  *
219  *  Get scalar factor
220  */
221 //=============================================================================
222
223 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
224 {
225   ASSERT( myBaseImpl );
226   double scale;
227   try {
228     scale = this->GetImpl()->GetScaleFactor();
229   }
230   catch ( SALOME_Exception& S_ex ) {
231     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
232                                   SALOME::BAD_PARAM );
233   }
234   return scale;
235 }
236
237 //=============================================================================
238 /*!
239  *  StdMeshers_NumberOfSegments_i::SetBeta
240  *
241  *  Set beta coefficient for Beta Law distribution
242  */
243 //=============================================================================
244
245 void StdMeshers_NumberOfSegments_i::SetBeta(CORBA::Double beta)
246 {
247   ASSERT(myBaseImpl);
248   try {
249     this->GetImpl()->SetBeta(beta);
250     // Update Python script
251     SMESH::TPythonDump() << _this() << ".SetBeta( " << SMESH::TVar(beta) << " )";
252   }
253   catch (SALOME_Exception& S_ex) {
254     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
255   }
256 }
257
258 //=============================================================================
259 /*!
260  *  StdMeshers_NumberOfSegments_i::GetBeta
261  *
262  *  Get beta coefficient for Beta Law distribution
263  */
264 //=============================================================================
265
266 CORBA::Double StdMeshers_NumberOfSegments_i::GetBeta()
267 {
268   ASSERT(myBaseImpl);
269
270   double beta = 1.0;
271   try {
272     beta = this->GetImpl()->GetBeta();
273   }
274   catch (SALOME_Exception& S_ex) {
275     THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
276   }
277
278   return beta;
279 }
280
281 //=============================================================================
282 /*!
283  */
284 //=============================================================================
285
286 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
287 {
288   ASSERT( myBaseImpl );
289   std::vector<double> tbl( table.length() );
290   for ( CORBA::ULong i = 0; i < table.length(); i++)
291     tbl[i] = table[i];
292   try {
293     this->GetImpl()->SetTableFunction( tbl );
294     // Update Python script
295     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
296   }
297   catch ( SALOME_Exception& S_ex ) {
298     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
299                                   SALOME::BAD_PARAM );
300   }
301 }
302
303 //=============================================================================
304 /*!
305  */
306 //=============================================================================
307
308 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
309 {
310   ASSERT( myBaseImpl );
311   const std::vector<double>* tbl;
312   try {
313     tbl = &this->GetImpl()->GetTableFunction();
314   }
315   catch ( SALOME_Exception& S_ex ) {
316     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
317   }
318   SMESH::double_array_var aRes = new SMESH::double_array();
319   aRes->length(tbl->size());
320   for ( size_t i = 0; i < tbl->size(); i++ )
321     aRes[i] = (*tbl)[i];
322   return aRes._retn();
323 }
324
325 //=============================================================================
326 /*!
327  */
328 //=============================================================================
329
330 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
331 {
332   ASSERT( myBaseImpl );
333   try {
334     this->GetImpl()->SetExpressionFunction( expr );
335     // Update Python script
336     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
337   }
338   catch ( SALOME_Exception& S_ex ) {
339     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
340                                   SALOME::BAD_PARAM );
341   }
342 }
343
344 //=============================================================================
345 /*!
346  */
347 //=============================================================================
348
349 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
350 {
351   ASSERT( myBaseImpl );
352   const char* expr;
353   try {
354     expr = this->GetImpl()->GetExpressionFunction();
355   }
356   catch ( SALOME_Exception& S_ex ) {
357     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
358                                   SALOME::BAD_PARAM );
359   }
360   return CORBA::string_dup(expr);
361 }
362
363 //=============================================================================
364 /*!
365  */
366 //=============================================================================
367
368 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
369 {
370   ASSERT( myBaseImpl );
371   try {
372     this->GetImpl()->SetConversionMode( conv );
373     // Update Python script
374     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
375   }
376   catch ( SALOME_Exception& S_ex ) {
377     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
378                                   SALOME::BAD_PARAM );
379   }
380 }
381
382 //=============================================================================
383 /*!
384  */
385 //=============================================================================
386
387 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
388 {
389   ASSERT( myBaseImpl );
390   int conv;
391   try {
392     conv = this->GetImpl()->ConversionMode();
393   }
394   catch ( SALOME_Exception& S_ex ) {
395     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
396                                   SALOME::BAD_PARAM );
397   }
398   return conv;
399 }
400
401 //=============================================================================
402 /*!
403  *  StdMeshers_NumberOfSegments_i::GetImpl
404  *
405  *  Get implementation
406  */
407 //=============================================================================
408
409 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
410 {
411   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
412 }
413
414 //================================================================================
415 /*!
416  * \brief Verify whether hypothesis supports given entity type 
417   * \param type - dimension (see SMESH::Dimension enumeration)
418   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
419  * 
420  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
421  */
422 //================================================================================  
423 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
424 {
425   return type == SMESH::DIM_1D;
426 }
427
428 //================================================================================
429 /*!
430  * \brief Return method name corresponding to index of variable parameter
431  */
432 //================================================================================
433
434 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
435 {
436   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
437 }
438
439
440 //================================================================================
441 /*!
442  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
443  */
444 //================================================================================
445
446 bool
447 StdMeshers_NumberOfSegments_i::getObjectsDependOn( std::vector< std::string > & entryArray,
448                                                    std::vector< int >         & subIDArray ) const
449 {
450   return StdMeshers_Reversible1D_i::getObjectsDependOn( entryArray, subIDArray );
451 }
452
453 //================================================================================
454 /*!
455  * \brief Set new geometry instead of that returned by getObjectsDependOn()
456  */
457 //================================================================================
458
459 bool
460 StdMeshers_NumberOfSegments_i::setObjectsDependOn( std::vector< std::string > & entryArray,
461                                                    std::vector< int >         & subIDArray )
462 {
463   return StdMeshers_Reversible1D_i::setObjectsDependOn( entryArray, subIDArray );
464 }