Salome HOME
23586: [EDF] HYDRO: Copy mesh to new geometry
[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 //=============================================================================
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                                                     int                     theStudyId,
49                                                     ::SMESH_Gen*            theGenImpl )
50      : SALOME::GenericObj_i( thePOA ), 
51        SMESH_Hypothesis_i( thePOA ),
52        StdMeshers_Reversible1D_i( this )
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  */
167 //=============================================================================
168
169 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
170   throw ( SALOME::SALOME_Exception )
171 {
172   ASSERT( myBaseImpl );
173   try {
174     CORBA::Long oldType = (CORBA::Long) this->GetImpl()->GetDistrType();
175
176     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
177
178     // Update Python script
179     if ( oldType != typ )
180       SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
181   }
182   catch ( SALOME_Exception& S_ex ) {
183     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
184                                   SALOME::BAD_PARAM );
185   }
186 }
187
188 //=============================================================================
189 /*!
190  */
191 //=============================================================================
192
193 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
194 {
195   ASSERT( myBaseImpl );
196   return this->GetImpl()->GetDistrType();
197 }
198
199 //=============================================================================
200 /*!
201  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
202  *
203  *  Set scalar factor
204  */
205 //=============================================================================
206
207 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
208      throw ( SALOME::SALOME_Exception )
209 {
210   ASSERT( myBaseImpl );
211   try {
212     this->GetImpl()->SetScaleFactor( theScaleFactor );
213     // Update Python script
214     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << SMESH::TVar(theScaleFactor) << " )";
215   }
216   catch ( SALOME_Exception& S_ex ) {
217     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
218                                   SALOME::BAD_PARAM );
219   }
220 }
221
222 //=============================================================================
223 /*!
224  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
225  *
226  *  Get scalar factor
227  */
228 //=============================================================================
229
230 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
231   throw ( SALOME::SALOME_Exception )
232 {
233   ASSERT( myBaseImpl );
234   double scale;
235   try {
236     scale = this->GetImpl()->GetScaleFactor();
237   }
238   catch ( SALOME_Exception& S_ex ) {
239     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
240                                   SALOME::BAD_PARAM );
241   }
242   return scale;
243 }
244
245 //=============================================================================
246 /*!
247  */
248 //=============================================================================
249
250 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
251   throw ( SALOME::SALOME_Exception )
252 {
253   ASSERT( myBaseImpl );
254   std::vector<double> tbl( table.length() );
255   for ( CORBA::ULong i = 0; i < table.length(); i++)
256     tbl[i] = table[i];
257   try {
258     this->GetImpl()->SetTableFunction( tbl );
259     // Update Python script
260     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
261   }
262   catch ( SALOME_Exception& S_ex ) {
263     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
264                                   SALOME::BAD_PARAM );
265   }
266 }
267
268 //=============================================================================
269 /*!
270  */
271 //=============================================================================
272
273 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
274   throw ( SALOME::SALOME_Exception )
275 {
276   ASSERT( myBaseImpl );
277   const std::vector<double>* tbl;
278   try {
279     tbl = &this->GetImpl()->GetTableFunction();
280   }
281   catch ( SALOME_Exception& S_ex ) {
282     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
283   }
284   SMESH::double_array_var aRes = new SMESH::double_array();
285   aRes->length(tbl->size());
286   for ( size_t i = 0; i < tbl->size(); i++ )
287     aRes[i] = (*tbl)[i];
288   return aRes._retn();
289 }
290
291 //=============================================================================
292 /*!
293  */
294 //=============================================================================
295
296 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
297   throw ( SALOME::SALOME_Exception )
298 {
299   ASSERT( myBaseImpl );
300   try {
301     this->GetImpl()->SetExpressionFunction( expr );
302     // Update Python script
303     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
304   }
305   catch ( SALOME_Exception& S_ex ) {
306     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
307                                   SALOME::BAD_PARAM );
308   }
309 }
310
311 //=============================================================================
312 /*!
313  */
314 //=============================================================================
315
316 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
317   throw ( SALOME::SALOME_Exception )
318 {
319   ASSERT( myBaseImpl );
320   const char* expr;
321   try {
322     expr = this->GetImpl()->GetExpressionFunction();
323   }
324   catch ( SALOME_Exception& S_ex ) {
325     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
326                                   SALOME::BAD_PARAM );
327   }
328   return CORBA::string_dup(expr);
329 }
330
331 //=============================================================================
332 /*!
333  */
334 //=============================================================================
335
336 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
337   throw ( SALOME::SALOME_Exception )
338 {
339   ASSERT( myBaseImpl );
340   try {
341     this->GetImpl()->SetConversionMode( conv );
342     // Update Python script
343     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
344   }
345   catch ( SALOME_Exception& S_ex ) {
346     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
347                                   SALOME::BAD_PARAM );
348   }
349 }
350
351 //=============================================================================
352 /*!
353  */
354 //=============================================================================
355
356 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
357   throw ( SALOME::SALOME_Exception )
358 {
359   ASSERT( myBaseImpl );
360   int conv;
361   try {
362     conv = this->GetImpl()->ConversionMode();
363   }
364   catch ( SALOME_Exception& S_ex ) {
365     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
366                                   SALOME::BAD_PARAM );
367   }
368   return conv;
369 }
370
371 //=============================================================================
372 /*!
373  *  StdMeshers_NumberOfSegments_i::GetImpl
374  *
375  *  Get implementation
376  */
377 //=============================================================================
378
379 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
380 {
381   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
382 }
383
384 //================================================================================
385 /*!
386  * \brief Verify whether hypothesis supports given entity type 
387   * \param type - dimension (see SMESH::Dimension enumeration)
388   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
389  * 
390  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
391  */
392 //================================================================================  
393 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
394 {
395   return type == SMESH::DIM_1D;
396 }
397
398 //================================================================================
399 /*!
400  * \brief Return method name corresponding to index of variable parameter
401  */
402 //================================================================================
403
404 std::string StdMeshers_NumberOfSegments_i::getMethodOfParameter(const int paramIndex, int ) const
405 {
406   return paramIndex == 0 ? "SetNumberOfSegments" : "SetScaleFactor";
407 }
408
409
410 //================================================================================
411 /*!
412  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
413  */
414 //================================================================================
415
416 bool
417 StdMeshers_NumberOfSegments_i::getObjectsDependOn( std::vector< std::string > & entryArray,
418                                                    std::vector< int >         & subIDArray ) const
419 {
420   return StdMeshers_Reversible1D_i::getObjectsDependOn( entryArray, subIDArray );
421 }
422
423 //================================================================================
424 /*!
425  * \brief Set new geometry instead of that returned by getObjectsDependOn()
426  */
427 //================================================================================
428
429 bool
430 StdMeshers_NumberOfSegments_i::setObjectsDependOn( std::vector< std::string > & entryArray,
431                                                    std::vector< int >         & subIDArray )
432 {
433   return StdMeshers_Reversible1D_i::setObjectsDependOn( entryArray, subIDArray );
434 }