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