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