]> SALOME platform Git repositories - modules/smesh.git/blob - src/StdMeshers_I/StdMeshers_NumberOfSegments_i.cxx
Salome HOME
82d7f9d95c34fbfe9d2d3d38310f1bae26c0d6e3
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_NumberOfSegments_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : StdMeshers_NumberOfSegments_i.cxx
25 //           Moved here from SMESH_NumberOfSegments_i.cxx
26 //  Author : Paul RASCLE, EDF
27 //  Module : SMESH
28 //  $Header$
29
30 #include "StdMeshers_NumberOfSegments_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Gen.hxx"
33 #include "SMESH_PythonDump.hxx"
34
35 #include "Utils_CorbaException.hxx"
36 #include "utilities.h"
37
38 #include <TCollection_AsciiString.hxx>
39
40 using namespace std;
41
42 //=============================================================================
43 /*!
44  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
45  *
46  *  Constructor
47  */
48 //=============================================================================
49
50 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
51                                                     int                     theStudyId,
52                                                     ::SMESH_Gen*            theGenImpl )
53      : SALOME::GenericObj_i( thePOA ), 
54        SMESH_Hypothesis_i( thePOA )
55 {
56   MESSAGE( "StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i" );
57   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
58                                              theStudyId,
59                                              theGenImpl );
60 }
61
62 //=============================================================================
63 /*!
64  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
65  *
66  *  Destructor
67  */
68 //=============================================================================
69
70 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
71 {
72   MESSAGE( "StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i" );
73 }
74
75 //=============================================================================
76 /*!
77  *  StdMeshers_NumberOfSegments_i::BuildDistribution
78  *
79  *  Builds point distribution according to passed function
80  */
81 //=============================================================================
82 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionExpr( const char* func, 
83                                                                            CORBA::Long nbSeg, 
84                                                                            CORBA::Long conv )
85   throw ( SALOME::SALOME_Exception )
86 {
87   ASSERT( myBaseImpl );
88   try
89   {
90     SMESH::double_array_var aRes = new SMESH::double_array();
91     const std::vector<double>& res = this->GetImpl()->BuildDistributionExpr( func, nbSeg, conv );
92     aRes->length( res.size() );
93     for (int i = 0; i < res.size(); i++)
94       aRes[i] = res[i];
95     return aRes._retn();
96   }
97   catch( SALOME_Exception& S_ex )
98   {
99     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
100   }
101 }
102
103 SMESH::double_array* StdMeshers_NumberOfSegments_i::BuildDistributionTab( const SMESH::double_array& func,
104                                                                           CORBA::Long nbSeg, 
105                                                                           CORBA::Long conv )
106   throw ( SALOME::SALOME_Exception )
107 {
108   ASSERT( myBaseImpl );
109
110   std::vector<double> tbl( func.length() );
111   for (int i = 0; i < func.length(); i++)
112     tbl[i] = func[i];
113
114   try
115   {
116     SMESH::double_array_var aRes = new SMESH::double_array();
117     const std::vector<double>& res = this->GetImpl()->BuildDistributionTab( tbl, nbSeg, conv );
118     aRes->length( res.size() );
119     for (int i = 0; i < res.size(); i++)
120       aRes[i] = res[i];
121     return aRes._retn();
122   }
123   catch( SALOME_Exception& S_ex )
124   {
125     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
126   }
127 }
128
129 //=============================================================================
130 /*!
131  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
132  *
133  *  Set number of segments
134  */
135 //=============================================================================
136
137 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
138      throw ( SALOME::SALOME_Exception )
139 {
140   ASSERT( myBaseImpl );
141   try {
142     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
143   }
144   catch (SALOME_Exception& S_ex) {
145     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
146                                   SALOME::BAD_PARAM );
147   }
148
149   // Update Python script
150   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << theSegmentsNumber << " )";
151 }
152
153 //=============================================================================
154 /*!
155  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
156  *
157  *  Get number of segments
158  */
159 //=============================================================================
160
161 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
162 {
163   ASSERT( myBaseImpl );
164   return this->GetImpl()->GetNumberOfSegments();
165 }
166
167 //=============================================================================
168 /*!
169  */
170 //=============================================================================
171
172 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
173   throw ( SALOME::SALOME_Exception )
174 {
175   ASSERT( myBaseImpl );
176   try {
177     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
178
179     // Update Python script
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( " << 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 (int 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(),
283                                   SALOME::BAD_PARAM );
284   }
285   SMESH::double_array_var aRes = new SMESH::double_array();
286   aRes->length(tbl->size());
287   for (int i = 0; i < tbl->size(); i++)
288     aRes[i] = (*tbl)[i];
289   return aRes._retn();
290 }
291
292 //=============================================================================
293 /*!
294  */
295 //=============================================================================
296
297 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
298   throw ( SALOME::SALOME_Exception )
299 {
300   ASSERT( myBaseImpl );
301   try {
302     this->GetImpl()->SetExpressionFunction( expr );
303     // Update Python script
304     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( '" << expr << "' )";
305   }
306   catch ( SALOME_Exception& S_ex ) {
307     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
308                                   SALOME::BAD_PARAM );
309   }
310 }
311
312 //=============================================================================
313 /*!
314  */
315 //=============================================================================
316
317 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
318   throw ( SALOME::SALOME_Exception )
319 {
320   ASSERT( myBaseImpl );
321   const char* expr;
322   try {
323     expr = this->GetImpl()->GetExpressionFunction();
324   }
325   catch ( SALOME_Exception& S_ex ) {
326     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
327                                   SALOME::BAD_PARAM );
328   }
329   return CORBA::string_dup(expr);
330 }
331
332 //=============================================================================
333 /*!
334  */
335 //=============================================================================
336
337 void StdMeshers_NumberOfSegments_i::SetConversionMode(CORBA::Long conv )
338   throw ( SALOME::SALOME_Exception )
339 {
340   ASSERT( myBaseImpl );
341   try {
342     this->GetImpl()->SetConversionMode( conv );
343     // Update Python script
344     SMESH::TPythonDump() << _this() << ".SetConversionMode( " << conv << " )";
345   }
346   catch ( SALOME_Exception& S_ex ) {
347     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
348                                   SALOME::BAD_PARAM );
349   }
350 }
351
352 //=============================================================================
353 /*!
354  */
355 //=============================================================================
356
357 CORBA::Long StdMeshers_NumberOfSegments_i::ConversionMode()
358   throw ( SALOME::SALOME_Exception )
359 {
360   ASSERT( myBaseImpl );
361   int conv;
362   try {
363     conv = this->GetImpl()->ConversionMode();
364   }
365   catch ( SALOME_Exception& S_ex ) {
366     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
367                                   SALOME::BAD_PARAM );
368   }
369   return conv;
370 }
371
372 //=============================================================================
373 /*!
374  *  StdMeshers_NumberOfSegments_i::GetImpl
375  *
376  *  Get implementation
377  */
378 //=============================================================================
379
380 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
381 {
382   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
383 }
384
385 //================================================================================
386 /*!
387  * \brief Verify whether hypothesis supports given entity type 
388   * \param type - dimension (see SMESH::Dimension enumeration)
389   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
390  * 
391  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
392  */
393 //================================================================================  
394 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
395 {
396   return type == SMESH::DIM_1D;
397 }
398