Salome HOME
Update copyright information
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 //  File   : StdMeshers_NumberOfSegments_i.cxx
24 //           Moved here from SMESH_NumberOfSegments_i.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28 //
29 #include "StdMeshers_NumberOfSegments_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
33
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
36
37 #include <TCollection_AsciiString.hxx>
38
39 using namespace std;
40 //=============================================================================
41 /*!
42  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
43  *
44  *  Constructor
45  */
46 //=============================================================================
47
48 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
49                                                     int                     theStudyId,
50                                                     ::SMESH_Gen*            theGenImpl )
51      : SALOME::GenericObj_i( thePOA ), 
52        SMESH_Hypothesis_i( thePOA )
53 {
54   MESSAGE( "StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i" );
55   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
56                                              theStudyId,
57                                              theGenImpl );
58 }
59
60 //=============================================================================
61 /*!
62  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
63  *
64  *  Destructor
65  */
66 //=============================================================================
67
68 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
69 {
70   MESSAGE( "StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i" );
71 }
72
73 //=============================================================================
74 /*!
75  *  StdMeshers_NumberOfSegments_i::BuildDistribution
76  *
77  *  Builds point distribution according to passed function
78  */
79 //=============================================================================
80 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
81                                                                            CORBA::Long nbSeg, 
82                                                                            CORBA::Long conv )
83   throw ( SALOME::SALOME_Exception )
84 {
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                                                                           CORBA::Long nbSeg, 
103                                                                           CORBA::Long conv )
104   throw ( SALOME::SALOME_Exception )
105 {
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   ASSERT( myBaseImpl );
139   try {
140     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
141   }
142   catch (SALOME_Exception& S_ex) {
143     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
144                                   SALOME::BAD_PARAM );
145   }
146
147   // Update Python script
148   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << theSegmentsNumber << " )";
149 }
150
151 //=============================================================================
152 /*!
153  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
154  *
155  *  Get number of segments
156  */
157 //=============================================================================
158
159 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
160 {
161   ASSERT( myBaseImpl );
162   return this->GetImpl()->GetNumberOfSegments();
163 }
164
165 //=============================================================================
166 /*!
167  */
168 //=============================================================================
169
170 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
171   throw ( SALOME::SALOME_Exception )
172 {
173   ASSERT( myBaseImpl );
174   try {
175     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
176
177     // Update Python script
178     SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
179   }
180   catch ( SALOME_Exception& S_ex ) {
181     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
182                                   SALOME::BAD_PARAM );
183   }
184 }
185
186 //=============================================================================
187 /*!
188  */
189 //=============================================================================
190
191 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
192 {
193   ASSERT( myBaseImpl );
194   return this->GetImpl()->GetDistrType();
195 }
196
197 //=============================================================================
198 /*!
199  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
200  *
201  *  Set scalar factor
202  */
203 //=============================================================================
204
205 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
206      throw ( SALOME::SALOME_Exception )
207 {
208   ASSERT( myBaseImpl );
209   try {
210     this->GetImpl()->SetScaleFactor( theScaleFactor );
211     // Update Python script
212     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << theScaleFactor << " )";
213   }
214   catch ( SALOME_Exception& S_ex ) {
215     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
216                                   SALOME::BAD_PARAM );
217   }
218 }
219
220 //=============================================================================
221 /*!
222  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
223  *
224  *  Get scalar factor
225  */
226 //=============================================================================
227
228 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
229   throw ( SALOME::SALOME_Exception )
230 {
231   ASSERT( myBaseImpl );
232   double scale;
233   try {
234     scale = this->GetImpl()->GetScaleFactor();
235   }
236   catch ( SALOME_Exception& S_ex ) {
237     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
238                                   SALOME::BAD_PARAM );
239   }
240   return scale;
241 }
242
243 //=============================================================================
244 /*!
245  */
246 //=============================================================================
247
248 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
249   throw ( SALOME::SALOME_Exception )
250 {
251   ASSERT( myBaseImpl );
252   std::vector<double> tbl( table.length() );
253   for (int i = 0; i < table.length(); i++)
254     tbl[i] = table[i];
255   try {
256     this->GetImpl()->SetTableFunction( tbl );
257     // Update Python script
258     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
259   }
260   catch ( SALOME_Exception& S_ex ) {
261     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
262                                   SALOME::BAD_PARAM );
263   }
264 }
265
266 //=============================================================================
267 /*!
268  */
269 //=============================================================================
270
271 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
272   throw ( SALOME::SALOME_Exception )
273 {
274   ASSERT( myBaseImpl );
275   const std::vector<double>* tbl;
276   try {
277     tbl = &this->GetImpl()->GetTableFunction();
278   }
279   catch ( SALOME_Exception& S_ex ) {
280     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
281                                   SALOME::BAD_PARAM );
282   }
283   SMESH::double_array_var aRes = new SMESH::double_array();
284   aRes->length(tbl->size());
285   for (int i = 0; i < tbl->size(); i++)
286     aRes[i] = (*tbl)[i];
287   return aRes._retn();
288 }
289
290 //=============================================================================
291 /*!
292  */
293 //=============================================================================
294
295 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
296   throw ( SALOME::SALOME_Exception )
297 {
298   ASSERT( myBaseImpl );
299   try {
300     this->GetImpl()->SetExpressionFunction( expr );
301     // Update Python script
302     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
303   }
304   catch ( SALOME_Exception& S_ex ) {
305     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
306                                   SALOME::BAD_PARAM );
307   }
308 }
309
310 //=============================================================================
311 /*!
312  */
313 //=============================================================================
314
315 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
316   throw ( SALOME::SALOME_Exception )
317 {
318   ASSERT( myBaseImpl );
319   const char* expr;
320   try {
321     expr = this->GetImpl()->GetExpressionFunction();
322   }
323   catch ( SALOME_Exception& S_ex ) {
324     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
325                                   SALOME::BAD_PARAM );
326   }
327   return CORBA::string_dup(expr);
328 }
329
330 //=============================================================================
331 /*!
332  */
333 //=============================================================================
334
335 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
336   throw ( SALOME::SALOME_Exception )
337 {
338   ASSERT( myBaseImpl );
339   try {
340     this->GetImpl()->SetConversionMode( conv );
341     // Update Python script
342     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
343   }
344   catch ( SALOME_Exception& S_ex ) {
345     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
346                                   SALOME::BAD_PARAM );
347   }
348 }
349
350 //=============================================================================
351 /*!
352  */
353 //=============================================================================
354
355 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
356   throw ( SALOME::SALOME_Exception )
357 {
358   ASSERT( myBaseImpl );
359   int conv;
360   try {
361     conv = this->GetImpl()->ConversionMode();
362   }
363   catch ( SALOME_Exception& S_ex ) {
364     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
365                                   SALOME::BAD_PARAM );
366   }
367   return conv;
368 }
369
370 //=============================================================================
371 /*!
372  *  StdMeshers_NumberOfSegments_i::GetImpl
373  *
374  *  Get implementation
375  */
376 //=============================================================================
377
378 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
379 {
380   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
381 }
382
383 //================================================================================
384 /*!
385  * \brief Verify whether hypothesis supports given entity type 
386   * \param type - dimension (see SMESH::Dimension enumeration)
387   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
388  * 
389  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
390  */
391 //================================================================================  
392 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
393 {
394   return type == SMESH::DIM_1D;
395 }
396