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