1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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
29 #include "StdMeshers_NumberOfSegments_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
37 #include <TCollection_AsciiString.hxx>
40 //=============================================================================
42 * StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
46 //=============================================================================
48 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
50 ::SMESH_Gen* theGenImpl )
51 : SALOME::GenericObj_i( thePOA ),
52 SMESH_Hypothesis_i( thePOA )
54 myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
59 //=============================================================================
61 * StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
65 //=============================================================================
67 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
71 //=============================================================================
73 * StdMeshers_NumberOfSegments_i::BuildDistribution
75 * Builds point distribution according to passed function
77 //=============================================================================
78 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func,
81 throw ( SALOME::SALOME_Exception )
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++)
93 catch( SALOME_Exception& S_ex )
95 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
100 StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
103 throw ( SALOME::SALOME_Exception )
105 ASSERT( myBaseImpl );
107 std::vector<double> tbl( func.length() );
108 for ( size_t i = 0; i < tbl.size(); i++ )
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++)
120 catch( SALOME_Exception& S_ex )
122 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
126 //=============================================================================
128 * StdMeshers_NumberOfSegments_i::SetNumberOfSegments
130 * Set number of segments
132 //=============================================================================
134 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
135 throw ( SALOME::SALOME_Exception )
137 ASSERT( myBaseImpl );
139 this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
141 catch (SALOME_Exception& S_ex) {
142 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
146 // Update Python script
147 SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
150 //=============================================================================
152 * StdMeshers_NumberOfSegments_i::GetNumberOfSegments
154 * Get number of segments
156 //=============================================================================
158 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
160 ASSERT( myBaseImpl );
161 return this->GetImpl()->GetNumberOfSegments();
164 //=============================================================================
166 * StdMeshers_NumberOfSegments_i::SetReversedEdges
168 * Set edges to reverse
170 //=============================================================================
172 void StdMeshers_NumberOfSegments_i::SetReversedEdges( const SMESH::long_array& theIds )
174 ASSERT( myBaseImpl );
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 ];
181 this->GetImpl()->SetReversedEdges( ids );
183 catch ( SALOME_Exception& S_ex ) {
184 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
188 // Update Python script
189 SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
192 //=============================================================================
194 * StdMeshers_NumberOfSegments_i::SetObjectEntry
196 * Set the Entry for the Main Object
198 //=============================================================================
200 void StdMeshers_NumberOfSegments_i::SetObjectEntry( const char* theEntry )
202 ASSERT( myBaseImpl );
203 string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
205 this->GetImpl()->SetObjectEntry( entry.c_str() );
207 catch ( SALOME_Exception& S_ex ) {
208 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
211 // Update Python script
212 SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
215 //=============================================================================
217 * StdMeshers_NumberOfSegments_i::GetObjectEntry
219 * Set the Entry for the Main Object
221 //=============================================================================
223 char* StdMeshers_NumberOfSegments_i::GetObjectEntry()
225 ASSERT( myBaseImpl );
229 entry = this->GetImpl()->GetObjectEntry();
231 catch ( SALOME_Exception& S_ex ) {
232 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
235 return CORBA::string_dup( entry );
238 //=============================================================================
240 * StdMeshers_NumberOfSegments_i::GetReversedEdges
244 //=============================================================================
246 SMESH::long_array* StdMeshers_NumberOfSegments_i::GetReversedEdges()
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 ];
255 return anArray._retn();
258 //=============================================================================
261 //=============================================================================
263 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
264 throw ( SALOME::SALOME_Exception )
266 ASSERT( myBaseImpl );
268 CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
270 this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
272 // Update Python script
273 if ( oldType != typ )
274 SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
276 catch ( SALOME_Exception& S_ex ) {
277 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
282 //=============================================================================
285 //=============================================================================
287 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
289 ASSERT( myBaseImpl );
290 return this->GetImpl()->GetDistrType();
293 //=============================================================================
295 * StdMeshers_NumberOfSegments_i::SetScaleFactor
299 //=============================================================================
301 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
302 throw ( SALOME::SALOME_Exception )
304 ASSERT( myBaseImpl );
306 this->GetImpl()->SetScaleFactor( theScaleFactor );
307 // Update Python script
308 SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
310 catch ( SALOME_Exception& S_ex ) {
311 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
316 //=============================================================================
318 * StdMeshers_NumberOfSegments_i::GetScaleFactor
322 //=============================================================================
324 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
325 throw ( SALOME::SALOME_Exception )
327 ASSERT( myBaseImpl );
330 scale = this->GetImpl()->GetScaleFactor();
332 catch ( SALOME_Exception& S_ex ) {
333 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
339 //=============================================================================
342 //=============================================================================
344 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
345 throw ( SALOME::SALOME_Exception )
347 ASSERT( myBaseImpl );
348 std::vector<double> tbl( table.length() );
349 for ( CORBA::ULong i = 0; i < table.length(); i++)
352 this->GetImpl()->SetTableFunction( tbl );
353 // Update Python script
354 SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
356 catch ( SALOME_Exception& S_ex ) {
357 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
362 //=============================================================================
365 //=============================================================================
367 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
368 throw ( SALOME::SALOME_Exception )
370 ASSERT( myBaseImpl );
371 const std::vector<double>* tbl;
373 tbl = &this->GetImpl()->GetTableFunction();
375 catch ( SALOME_Exception& S_ex ) {
376 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
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++ )
385 //=============================================================================
388 //=============================================================================
390 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
391 throw ( SALOME::SALOME_Exception )
393 ASSERT( myBaseImpl );
395 this->GetImpl()->SetExpressionFunction( expr );
396 // Update Python script
397 SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
399 catch ( SALOME_Exception& S_ex ) {
400 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
405 //=============================================================================
408 //=============================================================================
410 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
411 throw ( SALOME::SALOME_Exception )
413 ASSERT( myBaseImpl );
416 expr = this->GetImpl()->GetExpressionFunction();
418 catch ( SALOME_Exception& S_ex ) {
419 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
422 return CORBA::string_dup(expr);
425 //=============================================================================
428 //=============================================================================
430 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
431 throw ( SALOME::SALOME_Exception )
433 ASSERT( myBaseImpl );
435 this->GetImpl()->SetConversionMode( conv );
436 // Update Python script
437 SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
439 catch ( SALOME_Exception& S_ex ) {
440 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
445 //=============================================================================
448 //=============================================================================
450 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
451 throw ( SALOME::SALOME_Exception )
453 ASSERT( myBaseImpl );
456 conv = this->GetImpl()->ConversionMode();
458 catch ( SALOME_Exception& S_ex ) {
459 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
465 //=============================================================================
467 * StdMeshers_NumberOfSegments_i::GetImpl
471 //=============================================================================
473 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
475 return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
478 //================================================================================
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
484 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
486 //================================================================================
487 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
489 return type == SMESH::DIM_1D;
492 //================================================================================
494 * \brief Return method name corresponding to index of variable parameter
496 //================================================================================
498 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
500 return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";