Salome HOME
Join modifications from branch BR_3_1_0deb
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 using namespace std;
31 #include "StdMeshers_NumberOfSegments_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_PythonDump.hxx"
35
36 #include "Utils_CorbaException.hxx"
37 #include "utilities.h"
38
39 #include <TCollection_AsciiString.hxx>
40
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, long nbSeg, long conv )
82 throw ( SALOME::SALOME_Exception )
83 {
84   MESSAGE( "StdMeshers_NumberOfSegments_i::BuildDistribution" );
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                                                                           long nbSeg, long conv )
103 throw ( SALOME::SALOME_Exception )
104 {
105   MESSAGE( "StdMeshers_NumberOfSegments_i::BuildDistribution" );
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   MESSAGE( "StdMeshers_NumberOfSegments_i::SetNumberOfSegments" );
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   MESSAGE( "StdMeshers_NumberOfSegments_i::GetNumberOfSegments" );
163   ASSERT( myBaseImpl );
164   return this->GetImpl()->GetNumberOfSegments();
165 }
166
167 //=============================================================================
168 /*!
169  */
170 //=============================================================================
171
172 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
173   throw ( SALOME::SALOME_Exception )
174 {
175   MESSAGE( "StdMeshers_NumberOfSegments_i::SetDistrType" );
176   ASSERT( myBaseImpl );
177   try {
178     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
179
180     // Update Python script
181     SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
182   }
183   catch ( SALOME_Exception& S_ex ) {
184     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
185                                   SALOME::BAD_PARAM );
186   }
187 }
188
189 //=============================================================================
190 /*!
191  */
192 //=============================================================================
193
194 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
195 {
196   MESSAGE( "StdMeshers_NumberOfSegments_i::GetDistrType" );
197   ASSERT( myBaseImpl );
198   return this->GetImpl()->GetDistrType();
199 }
200
201 //=============================================================================
202 /*!
203  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
204  *
205  *  Set scalar factor
206  */
207 //=============================================================================
208
209 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
210      throw ( SALOME::SALOME_Exception )
211 {
212   MESSAGE( "StdMeshers_NumberOfSegments_i::SetScaleFactor" );
213   ASSERT( myBaseImpl );
214   try {
215     this->GetImpl()->SetScaleFactor( theScaleFactor );
216     // Update Python script
217     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << theScaleFactor << " )";
218   }
219   catch ( SALOME_Exception& S_ex ) {
220     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
221                                   SALOME::BAD_PARAM );
222   }
223 }
224
225 //=============================================================================
226 /*!
227  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
228  *
229  *  Get scalar factor
230  */
231 //=============================================================================
232
233 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
234   throw ( SALOME::SALOME_Exception )
235 {
236   MESSAGE( "StdMeshers_NumberOfSegments_i::GetScaleFactor" );
237   ASSERT( myBaseImpl );
238   double scale;
239   try {
240     scale = this->GetImpl()->GetScaleFactor();
241   }
242   catch ( SALOME_Exception& S_ex ) {
243     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
244                                   SALOME::BAD_PARAM );
245   }
246   return scale;
247 }
248
249 //=============================================================================
250 /*!
251  */
252 //=============================================================================
253
254 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
255   throw ( SALOME::SALOME_Exception )
256 {
257   MESSAGE( "StdMeshers_NumberOfSegments_i::SetTableFunction" );
258   ASSERT( myBaseImpl );
259   std::vector<double> tbl( table.length() );
260   for (int i = 0; i < table.length(); i++)
261     tbl[i] = table[i];
262   try {
263     this->GetImpl()->SetTableFunction( tbl );
264     // Update Python script
265     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
266   }
267   catch ( SALOME_Exception& S_ex ) {
268     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
269                                   SALOME::BAD_PARAM );
270   }
271 }
272
273 //=============================================================================
274 /*!
275  */
276 //=============================================================================
277
278 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
279   throw ( SALOME::SALOME_Exception )
280 {
281   MESSAGE( "StdMeshers_NumberOfSegments_i::GetTableFunction" );
282   ASSERT( myBaseImpl );
283   const std::vector<double>* tbl;
284   try {
285     tbl = &this->GetImpl()->GetTableFunction();
286   }
287   catch ( SALOME_Exception& S_ex ) {
288     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
289                                   SALOME::BAD_PARAM );
290   }
291   SMESH::double_array_var aRes = new SMESH::double_array();
292   aRes->length(tbl->size());
293   for (int i = 0; i < tbl->size(); i++)
294     aRes[i] = (*tbl)[i];
295   return aRes._retn();
296 }
297
298 //=============================================================================
299 /*!
300  */
301 //=============================================================================
302
303 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
304   throw ( SALOME::SALOME_Exception )
305 {
306   MESSAGE( "StdMeshers_NumberOfSegments_i::SetExpressionFunction" );
307   ASSERT( myBaseImpl );
308   try {
309     this->GetImpl()->SetExpressionFunction( expr );
310     // Update Python script
311     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( " << expr << " )";
312   }
313   catch ( SALOME_Exception& S_ex ) {
314     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
315                                   SALOME::BAD_PARAM );
316   }
317 }
318
319 //=============================================================================
320 /*!
321  */
322 //=============================================================================
323
324 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
325   throw ( SALOME::SALOME_Exception )
326 {
327   MESSAGE( "StdMeshers_NumberOfSegments_i::GetExpressionFunction" );
328   ASSERT( myBaseImpl );
329   const char* expr;
330   try {
331     expr = this->GetImpl()->GetExpressionFunction();
332   }
333   catch ( SALOME_Exception& S_ex ) {
334     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
335                                   SALOME::BAD_PARAM );
336   }
337   return CORBA::string_dup(expr);
338 }
339
340 //=============================================================================
341 /*!
342  */
343 //=============================================================================
344
345 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
346   throw ( SALOME::SALOME_Exception )
347 {
348   MESSAGE( "StdMeshers_NumberOfSegments_i::SetConversionMode" );
349   ASSERT( myBaseImpl );
350   try {
351     this->GetImpl()->SetConversionMode( conv );
352     // Update Python script
353     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
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 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
367   throw ( SALOME::SALOME_Exception )
368 {
369   MESSAGE( "StdMeshers_NumberOfSegments_i::ConversionMode" );
370   ASSERT( myBaseImpl );
371   int conv;
372   try {
373     conv = this->GetImpl()->ConversionMode();
374   }
375   catch ( SALOME_Exception& S_ex ) {
376     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
377                                   SALOME::BAD_PARAM );
378   }
379   return conv;
380 }
381
382 //=============================================================================
383 /*!
384  *  StdMeshers_NumberOfSegments_i::GetImpl
385  *
386  *  Get implementation
387  */
388 //=============================================================================
389
390 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
391 {
392   MESSAGE( "StdMeshers_NumberOfSegments_i::GetImpl" );
393   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
394 }
395
396 //================================================================================
397 /*!
398  * \brief Verify whether hypothesis supports given entity type 
399   * \param type - dimension (see SMESH::Dimension enumeration)
400   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
401  * 
402  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
403  */
404 //================================================================================  
405 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
406 {
407   return type == SMESH::DIM_1D;
408 }
409