Salome HOME
Update of CheckDone
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 // Copyright (C) 2007-2021  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 classes
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 //=============================================================================
40 /*!
41  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
42  *
43  *  Constructor
44  */
45 //=============================================================================
46
47 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
48                                                               ::SMESH_Gen*            theGenImpl )
49   : SALOME::GenericObj_i( thePOA ),
50     SMESH_Hypothesis_i( thePOA ),
51     StdMeshers_Reversible1D_i( this )
52 {
53   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
54                                                   theGenImpl );
55 }
56
57 //=============================================================================
58 /*!
59  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
60  *
61  *  Destructor
62  */
63 //=============================================================================
64
65 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
66 {
67 }
68
69 //=============================================================================
70 /*!
71  *  StdMeshers_NumberOfSegments_i::BuildDistribution
72  *
73  *  Builds point distribution according to passed function
74  */
75 //=============================================================================
76 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
77                                                                            CORBA::Long nbSeg, 
78                                                                            CORBA::Long conv )
79 {
80   ASSERT( myBaseImpl );
81   try
82   {
83     SMESH::double_array_var aRes = new SMESH::double_array();
84     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
85     aRes->length( res.size() );
86     for (size_t i = 0; i < res.size(); i++)
87       aRes[i] = res[i];
88     return aRes._retn();
89   }
90   catch( SALOME_Exception& S_ex )
91   {
92     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
93   }
94 }
95
96 SMESH::double_array*
97 StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
98                                                      CORBA::Long                nbSeg,
99                                                      CORBA::Long                conv )
100 {
101   ASSERT( myBaseImpl );
102
103   std::vector<double> tbl( func.length() );
104   for ( size_t i = 0; i < tbl.size(); i++ )
105     tbl[i] = func[i];
106
107   try
108   {
109     SMESH::double_array_var   aRes = new SMESH::double_array();
110     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
111     aRes->length( res.size() );
112     for (size_t i = 0; i < res.size(); i++)
113       aRes[i] = res[i];
114     return aRes._retn();
115   }
116   catch( SALOME_Exception& S_ex )
117   {
118     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
119   }
120 }
121
122 //=============================================================================
123 /*!
124  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
125  *
126  *  Set number of segments
127  */
128 //=============================================================================
129
130 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( SMESH::smIdType theSegmentsNumber )
131 {
132   ASSERT( myBaseImpl );
133   try {
134     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
135   }
136   catch (SALOME_Exception& S_ex) {
137     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
138                                   SALOME::BAD_PARAM );
139   }
140
141   // Update Python script
142   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << SMESH::TVar(theSegmentsNumber) << " )";
143 }
144
145 //=============================================================================
146 /*!
147  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
148  *
149  *  Get number of segments
150  */
151 //=============================================================================
152
153 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
154 {
155   ASSERT( myBaseImpl );
156   return this->GetImpl()->GetNumberOfSegments();
157 }
158
159 //=============================================================================
160 /*!
161  */
162 //=============================================================================
163
164 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
165 {
166   ASSERT( myBaseImpl );
167   try {
168     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
169
170     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
171
172     // Update Python script
173     if ( oldType != typ )
174       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
175   }
176   catch ( SALOME_Exception& S_ex ) {
177     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
178                                   SALOME::BAD_PARAM );
179   }
180 }
181
182 //=============================================================================
183 /*!
184  */
185 //=============================================================================
186
187 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
188 {
189   ASSERT( myBaseImpl );
190   return this->GetImpl()->GetDistrType();
191 }
192
193 //=============================================================================
194 /*!
195  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
196  *
197  *  Set scalar factor
198  */
199 //=============================================================================
200
201 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
202 {
203   ASSERT( myBaseImpl );
204   try {
205     this->GetImpl()->SetScaleFactor( theScaleFactor );
206     // Update Python script
207     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
208   }
209   catch ( SALOME_Exception& S_ex ) {
210     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
211                                   SALOME::BAD_PARAM );
212   }
213 }
214
215 //=============================================================================
216 /*!
217  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
218  *
219  *  Get scalar factor
220  */
221 //=============================================================================
222
223 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
224 {
225   ASSERT( myBaseImpl );
226   double scale;
227   try {
228     scale = this->GetImpl()->GetScaleFactor();
229   }
230   catch ( SALOME_Exception& S_ex ) {
231     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
232                                   SALOME::BAD_PARAM );
233   }
234   return scale;
235 }
236
237 //=============================================================================
238 /*!
239  */
240 //=============================================================================
241
242 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
243 {
244   ASSERT( myBaseImpl );
245   std::vector<double> tbl( table.length() );
246   for ( CORBA::ULong i = 0; i < table.length(); i++)
247     tbl[i] = table[i];
248   try {
249     this->GetImpl()->SetTableFunction( tbl );
250     // Update Python script
251     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
252   }
253   catch ( SALOME_Exception& S_ex ) {
254     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
255                                   SALOME::BAD_PARAM );
256   }
257 }
258
259 //=============================================================================
260 /*!
261  */
262 //=============================================================================
263
264 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
265 {
266   ASSERT( myBaseImpl );
267   const std::vector<double>* tbl;
268   try {
269     tbl = &this->GetImpl()->GetTableFunction();
270   }
271   catch ( SALOME_Exception& S_ex ) {
272     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
273   }
274   SMESH::double_array_var aRes = new SMESH::double_array();
275   aRes->length(tbl->size());
276   for ( size_t i = 0; i < tbl->size(); i++ )
277     aRes[i] = (*tbl)[i];
278   return aRes._retn();
279 }
280
281 //=============================================================================
282 /*!
283  */
284 //=============================================================================
285
286 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
287 {
288   ASSERT( myBaseImpl );
289   try {
290     this->GetImpl()->SetExpressionFunction( expr );
291     // Update Python script
292     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
293   }
294   catch ( SALOME_Exception& S_ex ) {
295     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
296                                   SALOME::BAD_PARAM );
297   }
298 }
299
300 //=============================================================================
301 /*!
302  */
303 //=============================================================================
304
305 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
306 {
307   ASSERT( myBaseImpl );
308   const char* expr;
309   try {
310     expr = this->GetImpl()->GetExpressionFunction();
311   }
312   catch ( SALOME_Exception& S_ex ) {
313     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
314                                   SALOME::BAD_PARAM );
315   }
316   return CORBA::string_dup(expr);
317 }
318
319 //=============================================================================
320 /*!
321  */
322 //=============================================================================
323
324 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
325 {
326   ASSERT( myBaseImpl );
327   try {
328     this->GetImpl()->SetConversionMode( conv );
329     // Update Python script
330     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
331   }
332   catch ( SALOME_Exception& S_ex ) {
333     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
334                                   SALOME::BAD_PARAM );
335   }
336 }
337
338 //=============================================================================
339 /*!
340  */
341 //=============================================================================
342
343 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
344 {
345   ASSERT( myBaseImpl );
346   int conv;
347   try {
348     conv = this->GetImpl()->ConversionMode();
349   }
350   catch ( SALOME_Exception& S_ex ) {
351     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
352                                   SALOME::BAD_PARAM );
353   }
354   return conv;
355 }
356
357 //=============================================================================
358 /*!
359  *  StdMeshers_NumberOfSegments_i::GetImpl
360  *
361  *  Get implementation
362  */
363 //=============================================================================
364
365 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
366 {
367   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
368 }
369
370 //================================================================================
371 /*!
372  * \brief Verify whether hypothesis supports given entity type 
373   * \param type - dimension (see SMESH::Dimension enumeration)
374   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
375  * 
376  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
377  */
378 //================================================================================  
379 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
380 {
381   return type == SMESH::DIM_1D;
382 }
383
384 //================================================================================
385 /*!
386  * \brief Return method name corresponding to index of variable parameter
387  */
388 //================================================================================
389
390 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
391 {
392   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
393 }
394
395
396 //================================================================================
397 /*!
398  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
399  */
400 //================================================================================
401
402 bool
403 StdMeshers_NumberOfSegments_i::getObjectsDependOn( std::vector< std::string > & entryArray,
404                                                    std::vector< int >         & subIDArray ) const
405 {
406   return StdMeshers_Reversible1D_i::getObjectsDependOn( entryArray, subIDArray );
407 }
408
409 //================================================================================
410 /*!
411  * \brief Set new geometry instead of that returned by getObjectsDependOn()
412  */
413 //================================================================================
414
415 bool
416 StdMeshers_NumberOfSegments_i::setObjectsDependOn( std::vector< std::string > & entryArray,
417                                                    std::vector< int >         & subIDArray )
418 {
419   return StdMeshers_Reversible1D_i::setObjectsDependOn( entryArray, subIDArray );
420 }