Salome HOME
PAL10953. Add Fineness parameter to Automatic Length hypothesis
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
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 using namespace std;
31 #include "StdMeshers_NumberOfSegments_i.hxx"
32 #include "SMESH_Gen_i.hxx"
33 #include "SMESH_Gen.hxx"
34 #include "SMESH_PythonDump.hxx"
35
36 #include "Utils_CorbaException.hxx"
37 #include "utilities.h"
38
39 #include <TCollection_AsciiString.hxx>
40
41 //=============================================================================
42 /*!
43  *  StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i
44  *
45  *  Constructor
46  */
47 //=============================================================================
48
49 StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i( PortableServer::POA_ptr thePOA,
50                                                     int                     theStudyId,
51                                                     ::SMESH_Gen*            theGenImpl )
52      : SALOME::GenericObj_i( thePOA ), 
53        SMESH_Hypothesis_i( thePOA )
54 {
55   MESSAGE( "StdMeshers_NumberOfSegments_i::StdMeshers_NumberOfSegments_i" );
56   myBaseImpl = new ::StdMeshers_NumberOfSegments( theGenImpl->GetANewId(),
57                                              theStudyId,
58                                              theGenImpl );
59 }
60
61 //=============================================================================
62 /*!
63  *  StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i
64  *
65  *  Destructor
66  */
67 //=============================================================================
68
69 StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i()
70 {
71   MESSAGE( "StdMeshers_NumberOfSegments_i::~StdMeshers_NumberOfSegments_i" );
72 }
73
74 //=============================================================================
75 /*!
76  *  StdMeshers_NumberOfSegments_i::SetNumberOfSegments
77  *
78  *  Set number of segments
79  */
80 //=============================================================================
81
82 void StdMeshers_NumberOfSegments_i::SetNumberOfSegments( CORBA::Long theSegmentsNumber )
83      throw ( SALOME::SALOME_Exception )
84 {
85   MESSAGE( "StdMeshers_NumberOfSegments_i::SetNumberOfSegments" );
86   ASSERT( myBaseImpl );
87   try {
88     this->GetImpl()->SetNumberOfSegments( theSegmentsNumber );
89   }
90   catch (SALOME_Exception& S_ex) {
91     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
92                                   SALOME::BAD_PARAM );
93   }
94
95   // Update Python script
96   SMESH::TPythonDump() << _this() << ".SetNumberOfSegments( " << theSegmentsNumber << " )";
97 }
98
99 //=============================================================================
100 /*!
101  *  StdMeshers_NumberOfSegments_i::GetNumberOfSegments
102  *
103  *  Get number of segments
104  */
105 //=============================================================================
106
107 CORBA::Long StdMeshers_NumberOfSegments_i::GetNumberOfSegments()
108 {
109   MESSAGE( "StdMeshers_NumberOfSegments_i::GetNumberOfSegments" );
110   ASSERT( myBaseImpl );
111   return this->GetImpl()->GetNumberOfSegments();
112 }
113
114 //=============================================================================
115 /*!
116  */
117 //=============================================================================
118
119 void StdMeshers_NumberOfSegments_i::SetDistrType(CORBA::Long typ)
120   throw ( SALOME::SALOME_Exception )
121 {
122   MESSAGE( "StdMeshers_NumberOfSegments_i::SetDistrType" );
123   ASSERT( myBaseImpl );
124   try {
125     this->GetImpl()->SetDistrType( (::StdMeshers_NumberOfSegments::DistrType) typ );
126
127     // Update Python script
128     SMESH::TPythonDump() << _this() << ".SetDistrType( " << typ << " )";
129   }
130   catch ( SALOME_Exception& S_ex ) {
131     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
132                                   SALOME::BAD_PARAM );
133   }
134 }
135
136 //=============================================================================
137 /*!
138  */
139 //=============================================================================
140
141 CORBA::Long StdMeshers_NumberOfSegments_i::GetDistrType()
142 {
143   MESSAGE( "StdMeshers_NumberOfSegments_i::GetDistrType" );
144   ASSERT( myBaseImpl );
145   return this->GetImpl()->GetDistrType();
146 }
147
148 //=============================================================================
149 /*!
150  *  StdMeshers_NumberOfSegments_i::SetScaleFactor
151  *
152  *  Set scalar factor
153  */
154 //=============================================================================
155
156 void StdMeshers_NumberOfSegments_i::SetScaleFactor( CORBA::Double theScaleFactor )
157      throw ( SALOME::SALOME_Exception )
158 {
159   MESSAGE( "StdMeshers_NumberOfSegments_i::SetScaleFactor" );
160   ASSERT( myBaseImpl );
161   try {
162     this->GetImpl()->SetScaleFactor( theScaleFactor );
163     // Update Python script
164     SMESH::TPythonDump() << _this() << ".SetScaleFactor( " << theScaleFactor << " )";
165   }
166   catch ( SALOME_Exception& S_ex ) {
167     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
168                                   SALOME::BAD_PARAM );
169   }
170 }
171
172 //=============================================================================
173 /*!
174  *  StdMeshers_NumberOfSegments_i::GetScaleFactor
175  *
176  *  Get scalar factor
177  */
178 //=============================================================================
179
180 CORBA::Double StdMeshers_NumberOfSegments_i::GetScaleFactor()
181   throw ( SALOME::SALOME_Exception )
182 {
183   MESSAGE( "StdMeshers_NumberOfSegments_i::GetScaleFactor" );
184   ASSERT( myBaseImpl );
185   double scale;
186   try {
187     scale = this->GetImpl()->GetScaleFactor();
188   }
189   catch ( SALOME_Exception& S_ex ) {
190     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
191                                   SALOME::BAD_PARAM );
192   }
193   return scale;
194 }
195
196 //=============================================================================
197 /*!
198  */
199 //=============================================================================
200
201 void StdMeshers_NumberOfSegments_i::SetTableFunction(const SMESH::double_array& table)
202   throw ( SALOME::SALOME_Exception )
203 {
204   MESSAGE( "StdMeshers_NumberOfSegments_i::SetTableFunction" );
205   ASSERT( myBaseImpl );
206   std::vector<double> tbl( table.length() );
207   for (int i = 0; i < table.length(); i++)
208     tbl[i] = table[i];
209   try {
210     this->GetImpl()->SetTableFunction( tbl );
211     // Update Python script
212     SMESH::TPythonDump() << _this() << ".SetTableFunction( " << table << " )";
213   }
214   catch ( SALOME_Exception& S_ex ) {
215     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
216                                   SALOME::BAD_PARAM );
217   }
218 }
219
220 //=============================================================================
221 /*!
222  */
223 //=============================================================================
224
225 SMESH::double_array* StdMeshers_NumberOfSegments_i::GetTableFunction()
226   throw ( SALOME::SALOME_Exception )
227 {
228   MESSAGE( "StdMeshers_NumberOfSegments_i::GetTableFunction" );
229   ASSERT( myBaseImpl );
230   const std::vector<double>* tbl;
231   try {
232     tbl = &this->GetImpl()->GetTableFunction();
233   }
234   catch ( SALOME_Exception& S_ex ) {
235     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
236                                   SALOME::BAD_PARAM );
237   }
238   SMESH::double_array_var aRes = new SMESH::double_array();
239   aRes->length(tbl->size());
240   for (int i = 0; i < tbl->size(); i++)
241     aRes[i] = (*tbl)[i];
242   return aRes._retn();
243 }
244
245 //=============================================================================
246 /*!
247  */
248 //=============================================================================
249
250 void StdMeshers_NumberOfSegments_i::SetExpressionFunction(const char* expr)
251   throw ( SALOME::SALOME_Exception )
252 {
253   MESSAGE( "StdMeshers_NumberOfSegments_i::SetExpressionFunction" );
254   ASSERT( myBaseImpl );
255   try {
256     this->GetImpl()->SetExpressionFunction( expr );
257     // Update Python script
258     SMESH::TPythonDump() << _this() << ".SetExpressionFunction( " << expr << " )";
259   }
260   catch ( SALOME_Exception& S_ex ) {
261     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
262                                   SALOME::BAD_PARAM );
263   }
264 }
265
266 //=============================================================================
267 /*!
268  */
269 //=============================================================================
270
271 char* StdMeshers_NumberOfSegments_i::GetExpressionFunction()
272   throw ( SALOME::SALOME_Exception )
273 {
274   MESSAGE( "StdMeshers_NumberOfSegments_i::GetExpressionFunction" );
275   ASSERT( myBaseImpl );
276   const char* expr;
277   try {
278     expr = this->GetImpl()->GetExpressionFunction();
279   }
280   catch ( SALOME_Exception& S_ex ) {
281     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
282                                   SALOME::BAD_PARAM );
283   }
284   return CORBA::string_dup(expr);
285 }
286
287 //=============================================================================
288 /*!
289  */
290 //=============================================================================
291
292 void StdMeshers_NumberOfSegments_i::SetExponentMode(CORBA::Boolean isExp)
293   throw ( SALOME::SALOME_Exception )
294 {
295   MESSAGE( "StdMeshers_NumberOfSegments_i::SetExponentMode" );
296   ASSERT( myBaseImpl );
297   try {
298     this->GetImpl()->SetExponentMode( isExp );
299     // Update Python script
300     SMESH::TPythonDump() << _this() << ".SetExponentMode( " << isExp << " )";
301   }
302   catch ( SALOME_Exception& S_ex ) {
303     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
304                                   SALOME::BAD_PARAM );
305   }
306 }
307
308 //=============================================================================
309 /*!
310  */
311 //=============================================================================
312
313 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsExponentMode()
314   throw ( SALOME::SALOME_Exception )
315 {
316   MESSAGE( "StdMeshers_NumberOfSegments_i::IsExponentMode" );
317   ASSERT( myBaseImpl );
318   bool isExp;
319   try {
320     isExp = this->GetImpl()->IsExponentMode();
321   }
322   catch ( SALOME_Exception& S_ex ) {
323     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
324                                   SALOME::BAD_PARAM );
325   }
326   return isExp;
327 }
328
329 //=============================================================================
330 /*!
331  *  StdMeshers_NumberOfSegments_i::GetImpl
332  *
333  *  Get implementation
334  */
335 //=============================================================================
336
337 ::StdMeshers_NumberOfSegments* StdMeshers_NumberOfSegments_i::GetImpl()
338 {
339   MESSAGE( "StdMeshers_NumberOfSegments_i::GetImpl" );
340   return ( ::StdMeshers_NumberOfSegments* )myBaseImpl;
341 }
342
343 //================================================================================
344 /*!
345  * \brief Verify whether hypothesis supports given entity type 
346   * \param type - dimension (see SMESH::Dimension enumeration)
347   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
348  * 
349  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
350  */
351 //================================================================================  
352 CORBA::Boolean StdMeshers_NumberOfSegments_i::IsDimSupported( SMESH::Dimension type )
353 {
354   return type == SMESH::DIM_1D;
355 }
356