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