Salome HOME
Merge multi-study removal branch.
[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 calsses
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 using namespace std;
40 //=============================================================================
41 /*!
42  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
43  *
44  *  Constructor
45  */
46 //=============================================================================
47
48 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
49                                                               ::SMESH_Gen*            theGenImpl )
50      : SALOME::GenericObj_i( thePOA ), 
51        SMESH_Hypothesis_i( thePOA )
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  *  StdMeshers_NumberOfSegments_i::SetReversedEdges
165  *
166  *  Set edges to reverse
167  */
168 //=============================================================================
169
170 void StdMeshers_NumberOfSegments_i::SetReversedEdges( const SMESH::long_array& theIds )
171 {
172   ASSERT( myBaseImpl );
173   try {
174     std::vector<int> ids( theIds.length() );
175     CORBA::Long iEnd = theIds.length();
176     for ( CORBA::Long i = 0; i < iEnd; i++ )
177       ids[ i ] = theIds[ i ];
178
179     this->GetImpl()->SetReversedEdges( ids );
180   }
181   catch ( SALOME_Exception& S_ex ) {
182     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
183                                   SALOME::BAD_PARAM );
184   }
185
186   // Update Python script
187   SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
188 }
189
190 //=============================================================================
191 /*!
192  *  StdMeshers_NumberOfSegments_i::SetObjectEntry
193  *
194  *  Set the Entry for the Main Object
195  */
196 //=============================================================================
197
198 void StdMeshers_NumberOfSegments_i::SetObjectEntry( const char* theEntry )
199 {
200   ASSERT( myBaseImpl );
201   string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
202   try {
203     this->GetImpl()->SetObjectEntry( entry.c_str() );
204   }
205   catch ( SALOME_Exception& S_ex ) {
206     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
207                                   SALOME::BAD_PARAM );
208   }
209   // Update Python script
210   SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
211 }
212
213 //=============================================================================
214 /*!
215  *  StdMeshers_NumberOfSegments_i::GetObjectEntry
216  *
217  *  Set the Entry for the Main Object
218  */
219 //=============================================================================
220
221 char* StdMeshers_NumberOfSegments_i::GetObjectEntry()
222 {
223   ASSERT( myBaseImpl );
224
225   const char* entry;
226   try {
227     entry = this->GetImpl()->GetObjectEntry();
228   }
229   catch ( SALOME_Exception& S_ex ) {
230     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
231                                   SALOME::BAD_PARAM );
232   }
233   return CORBA::string_dup( entry );
234 }
235
236 //=============================================================================
237 /*!
238  *  StdMeshers_NumberOfSegments_i::GetReversedEdges
239  *
240  *  Get reversed edges
241  */
242 //=============================================================================
243
244 SMESH::long_array* StdMeshers_NumberOfSegments_i::GetReversedEdges()
245 {
246   ASSERT( myBaseImpl );
247   SMESH::long_array_var anArray = new SMESH::long_array;
248   std::vector<int> ids = this->GetImpl()->GetReversedEdges();
249   anArray->length( ids.size() );
250   for ( size_t i = 0; i < ids.size(); i++)
251     anArray [ i ] = ids [ i ];
252
253   return anArray._retn();
254 }
255
256 //=============================================================================
257 /*!
258  */
259 //=============================================================================
260
261 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
262   throw ( SALOME::SALOME_Exception )
263 {
264   ASSERT( myBaseImpl );
265   try {
266     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
267
268     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
269
270     // Update Python script
271     if ( oldType != typ )
272       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
273   }
274   catch ( SALOME_Exception& S_ex ) {
275     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
276                                   SALOME::BAD_PARAM );
277   }
278 }
279
280 //=============================================================================
281 /*!
282  */
283 //=============================================================================
284
285 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
286 {
287   ASSERT( myBaseImpl );
288   return this->GetImpl()->GetDistrType();
289 }
290
291 //=============================================================================
292 /*!
293  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
294  *
295  *  Set scalar factor
296  */
297 //=============================================================================
298
299 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
300      throw ( SALOME::SALOME_Exception )
301 {
302   ASSERT( myBaseImpl );
303   try {
304     this->GetImpl()->SetScaleFactor( theScaleFactor );
305     // Update Python script
306     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
307   }
308   catch ( SALOME_Exception& S_ex ) {
309     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
310                                   SALOME::BAD_PARAM );
311   }
312 }
313
314 //=============================================================================
315 /*!
316  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
317  *
318  *  Get scalar factor
319  */
320 //=============================================================================
321
322 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
323   throw ( SALOME::SALOME_Exception )
324 {
325   ASSERT( myBaseImpl );
326   double scale;
327   try {
328     scale = this->GetImpl()->GetScaleFactor();
329   }
330   catch ( SALOME_Exception& S_ex ) {
331     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
332                                   SALOME::BAD_PARAM );
333   }
334   return scale;
335 }
336
337 //=============================================================================
338 /*!
339  */
340 //=============================================================================
341
342 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
343   throw ( SALOME::SALOME_Exception )
344 {
345   ASSERT( myBaseImpl );
346   std::vector<double> tbl( table.length() );
347   for ( CORBA::ULong i = 0; i < table.length(); i++)
348     tbl[i] = table[i];
349   try {
350     this->GetImpl()->SetTableFunction( tbl );
351     // Update Python script
352     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
353   }
354   catch ( SALOME_Exception& S_ex ) {
355     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
356                                   SALOME::BAD_PARAM );
357   }
358 }
359
360 //=============================================================================
361 /*!
362  */
363 //=============================================================================
364
365 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
366   throw ( SALOME::SALOME_Exception )
367 {
368   ASSERT( myBaseImpl );
369   const std::vector<double>* tbl;
370   try {
371     tbl = &this->GetImpl()->GetTableFunction();
372   }
373   catch ( SALOME_Exception& S_ex ) {
374     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
375   }
376   SMESH::double_array_var aRes = new SMESH::double_array();
377   aRes->length(tbl->size());
378   for ( size_t i = 0; i < tbl->size(); i++ )
379     aRes[i] = (*tbl)[i];
380   return aRes._retn();
381 }
382
383 //=============================================================================
384 /*!
385  */
386 //=============================================================================
387
388 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
389   throw ( SALOME::SALOME_Exception )
390 {
391   ASSERT( myBaseImpl );
392   try {
393     this->GetImpl()->SetExpressionFunction( expr );
394     // Update Python script
395     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
396   }
397   catch ( SALOME_Exception& S_ex ) {
398     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
399                                   SALOME::BAD_PARAM );
400   }
401 }
402
403 //=============================================================================
404 /*!
405  */
406 //=============================================================================
407
408 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
409   throw ( SALOME::SALOME_Exception )
410 {
411   ASSERT( myBaseImpl );
412   const char* expr;
413   try {
414     expr = this->GetImpl()->GetExpressionFunction();
415   }
416   catch ( SALOME_Exception& S_ex ) {
417     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
418                                   SALOME::BAD_PARAM );
419   }
420   return CORBA::string_dup(expr);
421 }
422
423 //=============================================================================
424 /*!
425  */
426 //=============================================================================
427
428 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
429   throw ( SALOME::SALOME_Exception )
430 {
431   ASSERT( myBaseImpl );
432   try {
433     this->GetImpl()->SetConversionMode( conv );
434     // Update Python script
435     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
436   }
437   catch ( SALOME_Exception& S_ex ) {
438     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
439                                   SALOME::BAD_PARAM );
440   }
441 }
442
443 //=============================================================================
444 /*!
445  */
446 //=============================================================================
447
448 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
449   throw ( SALOME::SALOME_Exception )
450 {
451   ASSERT( myBaseImpl );
452   int conv;
453   try {
454     conv = this->GetImpl()->ConversionMode();
455   }
456   catch ( SALOME_Exception& S_ex ) {
457     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
458                                   SALOME::BAD_PARAM );
459   }
460   return conv;
461 }
462
463 //=============================================================================
464 /*!
465  *  StdMeshers_NumberOfSegments_i::GetImpl
466  *
467  *  Get implementation
468  */
469 //=============================================================================
470
471 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
472 {
473   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
474 }
475
476 //================================================================================
477 /*!
478  * \brief Verify whether hypothesis supports given entity type 
479   * \param type - dimension (see SMESH::Dimension enumeration)
480   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
481  * 
482  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
483  */
484 //================================================================================  
485 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
486 {
487   return type == SMESH::DIM_1D;
488 }
489
490 //================================================================================
491 /*!
492  * \brief Return method name corresponding to index of variable parameter
493  */
494 //================================================================================
495
496 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
497 {
498   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
499 }