Salome HOME
Merge branch V7_3_1_BR
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 // Copyright (C) 2007-2014  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                                                     int                     theStudyId,
50                                                     ::SMESH_Gen*            theGenImpl )
51      : SALOME::GenericObj_i( thePOA ), 
52        SMESH_Hypothesis_i( thePOA )
53 {
54   MESSAGE( "StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i" );
55   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
56                                              theStudyId,
57                                              theGenImpl );
58 }
59
60 //=============================================================================
61 /*!
62  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
63  *
64  *  Destructor
65  */
66 //=============================================================================
67
68 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
69 {
70   MESSAGE( "StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i" );
71 }
72
73 //=============================================================================
74 /*!
75  *  StdMeshers_NumberOfSegments_i::BuildDistribution
76  *
77  *  Builds point distribution according to passed function
78  */
79 //=============================================================================
80 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
81                                                                            CORBA::Long nbSeg, 
82                                                                            CORBA::Long conv )
83   throw ( SALOME::SALOME_Exception )
84 {
85   ASSERT( myBaseImpl );
86   try
87   {
88     SMESH::double_array_var aRes = new SMESH::double_array();
89     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
90     aRes->length( res.size() );
91     for (int i = 0; i < res.size(); i++)
92       aRes[i] = res[i];
93     return aRes._retn();
94   }
95   catch( SALOME_Exception& S_ex )
96   {
97     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
98   }
99 }
100
101 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
102                                                                           CORBA::Long nbSeg, 
103                                                                           CORBA::Long conv )
104   throw ( SALOME::SALOME_Exception )
105 {
106   ASSERT( myBaseImpl );
107
108   std::vector<double> tbl( func.length() );
109   for (int i = 0; i < func.length(); i++)
110     tbl[i] = func[i];
111
112   try
113   {
114     SMESH::double_array_var aRes = new SMESH::double_array();
115     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
116     aRes->length( res.size() );
117     for (int i = 0; i < res.size(); i++)
118       aRes[i] = res[i];
119     return aRes._retn();
120   }
121   catch( SALOME_Exception& S_ex )
122   {
123     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
124   }
125 }
126
127 //=============================================================================
128 /*!
129  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
130  *
131  *  Set number of segments
132  */
133 //=============================================================================
134
135 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
136      throw ( SALOME::SALOME_Exception )
137 {
138   ASSERT( myBaseImpl );
139   try {
140     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
141   }
142   catch (SALOME_Exception& S_ex) {
143     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
144                                   SALOME::BAD_PARAM );
145   }
146
147   // Update Python script
148   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
149 }
150
151 //=============================================================================
152 /*!
153  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
154  *
155  *  Get number of segments
156  */
157 //=============================================================================
158
159 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
160 {
161   ASSERT( myBaseImpl );
162   return this->GetImpl()->GetNumberOfSegments();
163 }
164
165 //=============================================================================
166 /*!
167  *  StdMeshers_NumberOfSegments_i::SetReversedEdges
168  *
169  *  Set edges to reverse
170  */
171 //=============================================================================
172
173 void StdMeshers_NumberOfSegments_i::SetReversedEdges( const SMESH::long_array& theIds )
174 {
175   ASSERT( myBaseImpl );
176   try {
177     std::vector<int> ids( theIds.length() );
178     CORBA::Long iEnd = theIds.length();
179     for ( CORBA::Long i = 0; i < iEnd; i++ )
180       ids[ i ] = theIds[ i ];
181
182     this->GetImpl()->SetReversedEdges( ids );
183   }
184   catch ( SALOME_Exception& S_ex ) {
185     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
186                                   SALOME::BAD_PARAM );
187   }
188
189   // Update Python script
190   SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
191 }
192
193 //=============================================================================
194 /*!
195  *  StdMeshers_NumberOfSegments_i::SetObjectEntry
196  *
197  *  Set the Entry for the Main Object
198  */
199 //=============================================================================
200
201 void StdMeshers_NumberOfSegments_i::SetObjectEntry( const char* theEntry )
202 {
203   ASSERT( myBaseImpl );
204   string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
205   try {
206     this->GetImpl()->SetObjectEntry( entry.c_str() );
207   }
208   catch ( SALOME_Exception& S_ex ) {
209     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
210                                   SALOME::BAD_PARAM );
211   }
212   // Update Python script
213   SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
214 }
215
216 //=============================================================================
217 /*!
218  *  StdMeshers_NumberOfSegments_i::GetObjectEntry
219  *
220  *  Set the Entry for the Main Object
221  */
222 //=============================================================================
223
224 char* StdMeshers_NumberOfSegments_i::GetObjectEntry()
225 {
226   ASSERT( myBaseImpl );
227
228   const char* entry;
229   try {
230     entry = this->GetImpl()->GetObjectEntry();
231   }
232   catch ( SALOME_Exception& S_ex ) {
233     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
234                                   SALOME::BAD_PARAM );
235   }
236   return CORBA::string_dup( entry );
237 }
238
239 //=============================================================================
240 /*!
241  *  StdMeshers_NumberOfSegments_i::GetReversedEdges
242  *
243  *  Get reversed edges
244  */
245 //=============================================================================
246
247 SMESH::long_array* StdMeshers_NumberOfSegments_i::GetReversedEdges()
248 {
249   MESSAGE( "StdMeshers_NumberOfSegments_i::GetReversedEdges" );
250   ASSERT( myBaseImpl );
251   SMESH::long_array_var anArray = new SMESH::long_array;
252   std::vector<int> ids = this->GetImpl()->GetReversedEdges();
253   anArray->length( ids.size() );
254   for ( CORBA::Long i = 0; i < ids.size(); i++)
255     anArray [ i ] = ids [ i ];
256
257   return anArray._retn();
258 }
259
260 //=============================================================================
261 /*!
262  */
263 //=============================================================================
264
265 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
266   throw ( SALOME::SALOME_Exception )
267 {
268   ASSERT( myBaseImpl );
269   try {
270     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
271
272     // Update Python script
273     SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
274   }
275   catch ( SALOME_Exception& S_ex ) {
276     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
277                                   SALOME::BAD_PARAM );
278   }
279 }
280
281 //=============================================================================
282 /*!
283  */
284 //=============================================================================
285
286 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
287 {
288   ASSERT( myBaseImpl );
289   return this->GetImpl()->GetDistrType();
290 }
291
292 //=============================================================================
293 /*!
294  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
295  *
296  *  Set scalar factor
297  */
298 //=============================================================================
299
300 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
301      throw ( SALOME::SALOME_Exception )
302 {
303   ASSERT( myBaseImpl );
304   try {
305     this->GetImpl()->SetScaleFactor( theScaleFactor );
306     // Update Python script
307     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
308   }
309   catch ( SALOME_Exception& S_ex ) {
310     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
311                                   SALOME::BAD_PARAM );
312   }
313 }
314
315 //=============================================================================
316 /*!
317  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
318  *
319  *  Get scalar factor
320  */
321 //=============================================================================
322
323 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
324   throw ( SALOME::SALOME_Exception )
325 {
326   ASSERT( myBaseImpl );
327   double scale;
328   try {
329     scale = this->GetImpl()->GetScaleFactor();
330   }
331   catch ( SALOME_Exception& S_ex ) {
332     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
333                                   SALOME::BAD_PARAM );
334   }
335   return scale;
336 }
337
338 //=============================================================================
339 /*!
340  */
341 //=============================================================================
342
343 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
344   throw ( SALOME::SALOME_Exception )
345 {
346   ASSERT( myBaseImpl );
347   std::vector<double> tbl( table.length() );
348   for (int i = 0; i < table.length(); i++)
349     tbl[i] = table[i];
350   try {
351     this->GetImpl()->SetTableFunction( tbl );
352     // Update Python script
353     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
354   }
355   catch ( SALOME_Exception& S_ex ) {
356     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
357                                   SALOME::BAD_PARAM );
358   }
359 }
360
361 //=============================================================================
362 /*!
363  */
364 //=============================================================================
365
366 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
367   throw ( SALOME::SALOME_Exception )
368 {
369   ASSERT( myBaseImpl );
370   const std::vector<double>* tbl;
371   try {
372     tbl = &this->GetImpl()->GetTableFunction();
373   }
374   catch ( SALOME_Exception& S_ex ) {
375     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
376                                   SALOME::BAD_PARAM );
377   }
378   SMESH::double_array_var aRes = new SMESH::double_array();
379   aRes->length(tbl->size());
380   for (int i = 0; i < tbl->size(); i++)
381     aRes[i] = (*tbl)[i];
382   return aRes._retn();
383 }
384
385 //=============================================================================
386 /*!
387  */
388 //=============================================================================
389
390 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
391   throw ( SALOME::SALOME_Exception )
392 {
393   ASSERT( myBaseImpl );
394   try {
395     this->GetImpl()->SetExpressionFunction( expr );
396     // Update Python script
397     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
398   }
399   catch ( SALOME_Exception& S_ex ) {
400     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
401                                   SALOME::BAD_PARAM );
402   }
403 }
404
405 //=============================================================================
406 /*!
407  */
408 //=============================================================================
409
410 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
411   throw ( SALOME::SALOME_Exception )
412 {
413   ASSERT( myBaseImpl );
414   const char* expr;
415   try {
416     expr = this->GetImpl()->GetExpressionFunction();
417   }
418   catch ( SALOME_Exception& S_ex ) {
419     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
420                                   SALOME::BAD_PARAM );
421   }
422   return CORBA::string_dup(expr);
423 }
424
425 //=============================================================================
426 /*!
427  */
428 //=============================================================================
429
430 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
431   throw ( SALOME::SALOME_Exception )
432 {
433   ASSERT( myBaseImpl );
434   try {
435     this->GetImpl()->SetConversionMode( conv );
436     // Update Python script
437     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
438   }
439   catch ( SALOME_Exception& S_ex ) {
440     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
441                                   SALOME::BAD_PARAM );
442   }
443 }
444
445 //=============================================================================
446 /*!
447  */
448 //=============================================================================
449
450 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
451   throw ( SALOME::SALOME_Exception )
452 {
453   ASSERT( myBaseImpl );
454   int conv;
455   try {
456     conv = this->GetImpl()->ConversionMode();
457   }
458   catch ( SALOME_Exception& S_ex ) {
459     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
460                                   SALOME::BAD_PARAM );
461   }
462   return conv;
463 }
464
465 //=============================================================================
466 /*!
467  *  StdMeshers_NumberOfSegments_i::GetImpl
468  *
469  *  Get implementation
470  */
471 //=============================================================================
472
473 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
474 {
475   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
476 }
477
478 //================================================================================
479 /*!
480  * \brief Verify whether hypothesis supports given entity type 
481   * \param type - dimension (see SMESH::Dimension enumeration)
482   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
483  * 
484  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
485  */
486 //================================================================================  
487 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
488 {
489   return type == SMESH::DIM_1D;
490 }
491
492 //================================================================================
493 /*!
494  * \brief Return method name corresponding to index of variable parameter
495  */
496 //================================================================================
497
498 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
499 {
500   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
501 }