Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_FixedPoints1D_i.cxx
1 //  Copyright (C) 2007-2008  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.
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 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 //  File   : StdMeshers_FixedPoints1D_i.cxx
24 //  Author : Damien COQUERET, OCC
25 //  Module : SMESH
26 //  $Header$
27 //
28 #include "StdMeshers_FixedPoints1D_i.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_PythonDump.hxx"
32
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
35
36 #include <TCollection_AsciiString.hxx>
37
38 using namespace std;
39
40 //=============================================================================
41 /*!
42  *  StdMeshers_FixedPoints1D_i::StdMeshers_FixedPoints1D_i
43  *
44  *  Constructor
45  */
46 //=============================================================================
47
48 StdMeshers_FixedPoints1D_i::StdMeshers_FixedPoints1D_i( PortableServer::POA_ptr thePOA,
49                                                         int                     theStudyId,
50                                                         ::SMESH_Gen*            theGenImpl )
51      : SALOME::GenericObj_i( thePOA ), 
52        SMESH_Hypothesis_i( thePOA )
53 {
54   MESSAGE( "StdMeshers_FixedPoints1D_i::StdMeshers_FixedPoints1D_i" );
55   myBaseImpl = new ::StdMeshers_FixedPoints1D(theGenImpl->GetANewId(),
56                                               theStudyId,
57                                               theGenImpl);
58 }
59
60 //=============================================================================
61 /*!
62  *  StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i
63  *
64  *  Destructor
65  */
66 //=============================================================================
67
68 StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i()
69 {
70   MESSAGE( "StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i" );
71 }
72
73 //=============================================================================
74 /*!
75  *  StdMeshers_FixedPoints1D_i::SetNbSegments
76  */
77 //=============================================================================
78
79 void StdMeshers_FixedPoints1D_i::SetNbSegments(const SMESH::long_array& listNbSeg) 
80      throw ( SALOME::SALOME_Exception )
81 {
82   MESSAGE( "StdMeshers_FixedPoints1D_i::SetNbSegments" );
83   ASSERT( myBaseImpl );
84   try {
85     std::vector<int> nbsegs( listNbSeg.length() );
86     CORBA::Long iEnd = listNbSeg.length();
87     for ( CORBA::Long i = 0; i < iEnd; i++ )
88       nbsegs[ i ] = listNbSeg[ i ];
89     this->GetImpl()->SetNbSegments( nbsegs );
90   }
91   catch ( SALOME_Exception& S_ex ) {
92     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
93                                   SALOME::BAD_PARAM );
94   }
95
96   // Update Python script
97   SMESH::TPythonDump() << _this() << ".SetNbSegments( " << listNbSeg << " )";
98 }
99
100 //=============================================================================
101 /*!
102  *  StdMeshers_FixedPoints1D_i::SetPoints
103  */
104 //=============================================================================
105
106 void StdMeshers_FixedPoints1D_i::SetPoints(const SMESH::double_array& listParams) 
107      throw ( SALOME::SALOME_Exception )
108 {
109   MESSAGE( "StdMeshers_FixedPoints1D_i::SetPoints" );
110   ASSERT( myBaseImpl );
111   try {
112     std::vector<double> params( listParams.length() );
113     CORBA::Long iEnd = listParams.length();
114     for ( CORBA::Long i = 0; i < iEnd; i++ )
115       params[ i ] = listParams[ i ];
116     this->GetImpl()->SetPoints( params );
117   }
118   catch ( SALOME_Exception& S_ex ) {
119     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
120                                   SALOME::BAD_PARAM );
121   }
122
123   // Update Python script
124   SMESH::TPythonDump() << _this() << ".SetPoints( " << listParams << " )";
125 }
126
127 //=============================================================================
128 /*!
129  *  StdMeshers_FixedPoints1D_i::GetPoints
130  *
131  *  Get list of point's parameters
132  */
133 //=============================================================================
134
135 SMESH::double_array* StdMeshers_FixedPoints1D_i::GetPoints()
136 {
137   MESSAGE( "StdMeshers_FixedPoints1D_i::GetPoints" );
138   ASSERT( myBaseImpl );
139   SMESH::double_array_var anArray = new SMESH::double_array;
140   std::vector<double> params = this->GetImpl()->GetPoints();
141   anArray->length( params.size() );
142   for ( CORBA::Long i = 0; i < params.size(); i++)
143     anArray [ i ] = params [ i ];
144
145   return anArray._retn();
146 }
147
148 //=============================================================================
149 /*!
150  *  StdMeshers_FixedPoints1D_i::GetNbSegments
151  *
152  *  Get list of point's parameters
153  */
154 //=============================================================================
155
156 SMESH::long_array* StdMeshers_FixedPoints1D_i::GetNbSegments()
157 {
158   MESSAGE( "StdMeshers_FixedPoints1D_i::GetNbSegments" );
159   ASSERT( myBaseImpl );
160   SMESH::long_array_var anArray = new SMESH::long_array;
161   std::vector<int> nbsegs = this->GetImpl()->GetNbSegments();
162   anArray->length( nbsegs.size() );
163   for ( CORBA::Long i = 0; i < nbsegs.size(); i++)
164     anArray [ i ] = nbsegs [ i ];
165
166   return anArray._retn();
167 }
168
169 //=============================================================================
170 /*!
171  *  StdMeshers_FixedPoints1D_i::SetReversedEdges
172  *
173  *  Set edges to reverse
174  */
175 //=============================================================================
176
177 void StdMeshers_FixedPoints1D_i::SetReversedEdges( const SMESH::long_array& theIds )
178 {
179   ASSERT( myBaseImpl );
180   try {
181     std::vector<int> ids( theIds.length() );
182     CORBA::Long iEnd = theIds.length();
183     for ( CORBA::Long i = 0; i < iEnd; i++ )
184       ids[ i ] = theIds[ i ];
185
186     this->GetImpl()->SetReversedEdges( ids );
187   }
188   catch ( SALOME_Exception& S_ex ) {
189     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
190                                   SALOME::BAD_PARAM );
191   }
192
193   // Update Python script
194   SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
195 }
196
197 //=============================================================================
198 /*!
199  *  StdMeshers_FixedPoints1D_i::SetObjectEntry
200  *
201  *  Set the Entry for the Main Object
202  */
203 //=============================================================================
204
205 void StdMeshers_FixedPoints1D_i::SetObjectEntry( const char* theEntry )
206 {
207   ASSERT( myBaseImpl );
208   string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
209   try {
210     this->GetImpl()->SetObjectEntry( entry.c_str() );
211     // Update Python script
212     SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
213   }
214   catch ( SALOME_Exception& S_ex ) {
215     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),SALOME::BAD_PARAM );
216   }
217 }
218
219 //=============================================================================
220 /*!
221  *  StdMeshers_FixedPoints1D_i::GetObjectEntry
222  *
223  *  Set the Entry for the Main Object
224  */
225 //=============================================================================
226
227 char* StdMeshers_FixedPoints1D_i::GetObjectEntry()
228 {
229   MESSAGE( "StdMeshers_FixedPoints1D_i::SetObjectEntry" );
230   ASSERT( myBaseImpl );
231   const char* entry;
232   try {
233     entry = this->GetImpl()->GetObjectEntry();
234   }
235   catch ( SALOME_Exception& S_ex ) {
236     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
237                                   SALOME::BAD_PARAM );
238   }
239   return CORBA::string_dup( entry );
240 }
241
242 //=============================================================================
243 /*!
244  *  StdMeshers_FixedPoints1D_i::GetReversedEdges
245  *
246  *  Get reversed edges
247  */
248 //=============================================================================
249
250 SMESH::long_array* StdMeshers_FixedPoints1D_i::GetReversedEdges()
251 {
252   MESSAGE( "StdMeshers_FixedPoints1D_i::GetReversedEdges" );
253   ASSERT( myBaseImpl );
254   SMESH::long_array_var anArray = new SMESH::long_array;
255   std::vector<int> ids = this->GetImpl()->GetReversedEdges();
256   anArray->length( ids.size() );
257   for ( CORBA::Long i = 0; i < ids.size(); i++)
258     anArray [ i ] = ids [ i ];
259
260   return anArray._retn();
261 }
262
263 //=============================================================================
264 /*!
265  *  StdMeshers_FixedPoints1D_i::GetImpl
266  *
267  *  Get implementation
268  */
269 //=============================================================================
270
271 ::StdMeshers_FixedPoints1D* StdMeshers_FixedPoints1D_i::GetImpl()
272 {
273   MESSAGE( "StdMeshers_FixedPoints1D_i::GetImpl" );
274   return ( ::StdMeshers_FixedPoints1D* )myBaseImpl;
275 }
276
277 //================================================================================
278 /*!
279  * \brief Verify whether hypothesis supports given entity type 
280   * \param type - dimension (see SMESH::Dimension enumeration)
281   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
282  * 
283  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
284  */
285 //================================================================================  
286 CORBA::Boolean StdMeshers_FixedPoints1D_i::IsDimSupported( SMESH::Dimension type )
287 {
288   return type == SMESH::DIM_1D;
289 }
290