Salome HOME
23514: EDF 16031 - SMESH freezes
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 //  File   : StdMeshers_NumberOfSegments_i.cxx
25 //           Moved here from SMESH_NumberOfSegments_i.cxx
26 //  Author : Paul RASCLE, EDF
27 //  Module : SMESH
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   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
55                                              theStudyId,
56                                              theGenImpl );
57 }
58
59 //=============================================================================
60 /*!
61  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
62  *
63  *  Destructor
64  */
65 //=============================================================================
66
67 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
68 {
69 }
70
71 //=============================================================================
72 /*!
73  *  StdMeshers_NumberOfSegments_i::BuildDistribution
74  *
75  *  Builds point distribution according to passed function
76  */
77 //=============================================================================
78 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
79                                                                            CORBA::Long nbSeg, 
80                                                                            CORBA::Long conv )
81   throw ( SALOME::SALOME_Exception )
82 {
83   ASSERT( myBaseImpl );
84   try
85   {
86     SMESH::double_array_var aRes = new SMESH::double_array();
87     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
88     aRes->length( res.size() );
89     for (size_t i = 0; i < res.size(); i++)
90       aRes[i] = res[i];
91     return aRes._retn();
92   }
93   catch( SALOME_Exception& S_ex )
94   {
95     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
96   }
97 }
98
99 SMESH::double_array*
100 StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
101                                                      CORBA::Long                nbSeg,
102                                                      CORBA::Long                conv )
103   throw ( SALOME::SALOME_Exception )
104 {
105   ASSERT( myBaseImpl );
106
107   std::vector<double> tbl( func.length() );
108   for ( size_t i = 0; i < tbl.size(); i++ )
109     tbl[i] = func[i];
110
111   try
112   {
113     SMESH::double_array_var   aRes = new SMESH::double_array();
114     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
115     aRes->length( res.size() );
116     for (size_t i = 0; i < res.size(); i++)
117       aRes[i] = res[i];
118     return aRes._retn();
119   }
120   catch( SALOME_Exception& S_ex )
121   {
122     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
123   }
124 }
125
126 //=============================================================================
127 /*!
128  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
129  *
130  *  Set number of segments
131  */
132 //=============================================================================
133
134 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
135      throw ( SALOME::SALOME_Exception )
136 {
137   ASSERT( myBaseImpl );
138   try {
139     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
140   }
141   catch (SALOME_Exception& S_ex) {
142     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
143                                   SALOME::BAD_PARAM );
144   }
145
146   // Update Python script
147   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
148 }
149
150 //=============================================================================
151 /*!
152  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
153  *
154  *  Get number of segments
155  */
156 //=============================================================================
157
158 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
159 {
160   ASSERT( myBaseImpl );
161   return this->GetImpl()->GetNumberOfSegments();
162 }
163
164 //=============================================================================
165 /*!
166  *  StdMeshers_NumberOfSegments_i::SetReversedEdges
167  *
168  *  Set edges to reverse
169  */
170 //=============================================================================
171
172 void StdMeshers_NumberOfSegments_i::SetReversedEdges( const SMESH::long_array& theIds )
173 {
174   ASSERT( myBaseImpl );
175   try {
176     std::vector<int> ids( theIds.length() );
177     CORBA::Long iEnd = theIds.length();
178     for ( CORBA::Long i = 0; i < iEnd; i++ )
179       ids[ i ] = theIds[ i ];
180
181     this->GetImpl()->SetReversedEdges( ids );
182   }
183   catch ( SALOME_Exception& S_ex ) {
184     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
185                                   SALOME::BAD_PARAM );
186   }
187
188   // Update Python script
189   SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
190 }
191
192 //=============================================================================
193 /*!
194  *  StdMeshers_NumberOfSegments_i::SetObjectEntry
195  *
196  *  Set the Entry for the Main Object
197  */
198 //=============================================================================
199
200 void StdMeshers_NumberOfSegments_i::SetObjectEntry( const char* theEntry )
201 {
202   ASSERT( myBaseImpl );
203   string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
204   try {
205     this->GetImpl()->SetObjectEntry( entry.c_str() );
206   }
207   catch ( SALOME_Exception& S_ex ) {
208     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
209                                   SALOME::BAD_PARAM );
210   }
211   // Update Python script
212   SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
213 }
214
215 //=============================================================================
216 /*!
217  *  StdMeshers_NumberOfSegments_i::GetObjectEntry
218  *
219  *  Set the Entry for the Main Object
220  */
221 //=============================================================================
222
223 char* StdMeshers_NumberOfSegments_i::GetObjectEntry()
224 {
225   ASSERT( myBaseImpl );
226
227   const char* entry;
228   try {
229     entry = this->GetImpl()->GetObjectEntry();
230   }
231   catch ( SALOME_Exception& S_ex ) {
232     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
233                                   SALOME::BAD_PARAM );
234   }
235   return CORBA::string_dup( entry );
236 }
237
238 //=============================================================================
239 /*!
240  *  StdMeshers_NumberOfSegments_i::GetReversedEdges
241  *
242  *  Get reversed edges
243  */
244 //=============================================================================
245
246 SMESH::long_array* StdMeshers_NumberOfSegments_i::GetReversedEdges()
247 {
248   ASSERT( myBaseImpl );
249   SMESH::long_array_var anArray = new SMESH::long_array;
250   std::vector<int> ids = this->GetImpl()->GetReversedEdges();
251   anArray->length( ids.size() );
252   for ( size_t i = 0; i < ids.size(); i++)
253     anArray [ i ] = ids [ i ];
254
255   return anArray._retn();
256 }
257
258 //=============================================================================
259 /*!
260  */
261 //=============================================================================
262
263 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
264   throw ( SALOME::SALOME_Exception )
265 {
266   ASSERT( myBaseImpl );
267   try {
268     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
269
270     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
271
272     // Update Python script
273     if ( oldType != typ )
274       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
275   }
276   catch ( SALOME_Exception& S_ex ) {
277     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
278                                   SALOME::BAD_PARAM );
279   }
280 }
281
282 //=============================================================================
283 /*!
284  */
285 //=============================================================================
286
287 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
288 {
289   ASSERT( myBaseImpl );
290   return this->GetImpl()->GetDistrType();
291 }
292
293 //=============================================================================
294 /*!
295  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
296  *
297  *  Set scalar factor
298  */
299 //=============================================================================
300
301 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
302      throw ( SALOME::SALOME_Exception )
303 {
304   ASSERT( myBaseImpl );
305   try {
306     this->GetImpl()->SetScaleFactor( theScaleFactor );
307     // Update Python script
308     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
309   }
310   catch ( SALOME_Exception& S_ex ) {
311     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
312                                   SALOME::BAD_PARAM );
313   }
314 }
315
316 //=============================================================================
317 /*!
318  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
319  *
320  *  Get scalar factor
321  */
322 //=============================================================================
323
324 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
325   throw ( SALOME::SALOME_Exception )
326 {
327   ASSERT( myBaseImpl );
328   double scale;
329   try {
330     scale = this->GetImpl()->GetScaleFactor();
331   }
332   catch ( SALOME_Exception& S_ex ) {
333     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
334                                   SALOME::BAD_PARAM );
335   }
336   return scale;
337 }
338
339 //=============================================================================
340 /*!
341  */
342 //=============================================================================
343
344 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
345   throw ( SALOME::SALOME_Exception )
346 {
347   ASSERT( myBaseImpl );
348   std::vector<double> tbl( table.length() );
349   for ( CORBA::ULong i = 0; i < table.length(); i++)
350     tbl[i] = table[i];
351   try {
352     this->GetImpl()->SetTableFunction( tbl );
353     // Update Python script
354     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
355   }
356   catch ( SALOME_Exception& S_ex ) {
357     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
358                                   SALOME::BAD_PARAM );
359   }
360 }
361
362 //=============================================================================
363 /*!
364  */
365 //=============================================================================
366
367 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
368   throw ( SALOME::SALOME_Exception )
369 {
370   ASSERT( myBaseImpl );
371   const std::vector<double>* tbl;
372   try {
373     tbl = &this->GetImpl()->GetTableFunction();
374   }
375   catch ( SALOME_Exception& S_ex ) {
376     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
377   }
378   SMESH::double_array_var aRes = new SMESH::double_array();
379   aRes->length(tbl->size());
380   for ( size_t i = 0; i < tbl->size(); i++ )
381     aRes[i] = (*tbl)[i];
382   return aRes._retn();
383 }
384
385 //=============================================================================
386 /*!
387  */
388 //=============================================================================
389
390 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
391   throw ( SALOME::SALOME_Exception )
392 {
393   ASSERT( myBaseImpl );
394   try {
395     this->GetImpl()->SetExpressionFunction( expr );
396     // Update Python script
397     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
398   }
399   catch ( SALOME_Exception& S_ex ) {
400     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
401                                   SALOME::BAD_PARAM );
402   }
403 }
404
405 //=============================================================================
406 /*!
407  */
408 //=============================================================================
409
410 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
411   throw ( SALOME::SALOME_Exception )
412 {
413   ASSERT( myBaseImpl );
414   const char* expr;
415   try {
416     expr = this->GetImpl()->GetExpressionFunction();
417   }
418   catch ( SALOME_Exception& S_ex ) {
419     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
420                                   SALOME::BAD_PARAM );
421   }
422   return CORBA::string_dup(expr);
423 }
424
425 //=============================================================================
426 /*!
427  */
428 //=============================================================================
429
430 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
431   throw ( SALOME::SALOME_Exception )
432 {
433   ASSERT( myBaseImpl );
434   try {
435     this->GetImpl()->SetConversionMode( conv );
436     // Update Python script
437     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
438   }
439   catch ( SALOME_Exception& S_ex ) {
440     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
441                                   SALOME::BAD_PARAM );
442   }
443 }
444
445 //=============================================================================
446 /*!
447  */
448 //=============================================================================
449
450 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
451   throw ( SALOME::SALOME_Exception )
452 {
453   ASSERT( myBaseImpl );
454   int conv;
455   try {
456     conv = this->GetImpl()->ConversionMode();
457   }
458   catch ( SALOME_Exception& S_ex ) {
459     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
460                                   SALOME::BAD_PARAM );
461   }
462   return conv;
463 }
464
465 //=============================================================================
466 /*!
467  *  StdMeshers_NumberOfSegments_i::GetImpl
468  *
469  *  Get implementation
470  */
471 //=============================================================================
472
473 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
474 {
475   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
476 }
477
478 //================================================================================
479 /*!
480  * \brief Verify whether hypothesis supports given entity type 
481   * \param type - dimension (see SMESH::Dimension enumeration)
482   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
483  * 
484  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
485  */
486 //================================================================================  
487 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
488 {
489   return type == SMESH::DIM_1D;
490 }
491
492 //================================================================================
493 /*!
494  * \brief Return method name corresponding to index of variable parameter
495  */
496 //================================================================================
497
498 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
499 {
500   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
501 }