Salome HOME
23514: EDF 16031 - SMESH freezes
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_FixedPoints1D_i.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
21 //  File   : StdMeshers_FixedPoints1D_i.cxx
22 //  Author : Damien COQUERET, OCC
23 //  Module : SMESH
24 //  $Header$
25 //
26 #include "StdMeshers_FixedPoints1D_i.hxx"
27 #include "SMESH_Gen_i.hxx"
28 #include "SMESH_Gen.hxx"
29 #include "SMESH_PythonDump.hxx"
30
31 #include "Utils_CorbaException.hxx"
32 #include "utilities.h"
33
34 #include <TCollection_AsciiString.hxx>
35
36 using namespace std;
37
38 //=============================================================================
39 /*!
40  *  StdMeshers_FixedPoints1D_i::StdMeshers_FixedPoints1D_i
41  *
42  *  Constructor
43  */
44 //=============================================================================
45
46 StdMeshers_FixedPoints1D_i::StdMeshers_FixedPoints1D_i( PortableServer::POA_ptr thePOA,
47                                                         int                     theStudyId,
48                                                         ::SMESH_Gen*            theGenImpl )
49      : SALOME::GenericObj_i( thePOA ), 
50        SMESH_Hypothesis_i( thePOA )
51 {
52   myBaseImpl = new ::StdMeshers_FixedPoints1D(theGenImpl->GetANewId(),
53                                               theStudyId,
54                                               theGenImpl);
55 }
56
57 //=============================================================================
58 /*!
59  *  StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i
60  *
61  *  Destructor
62  */
63 //=============================================================================
64
65 StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i()
66 {
67 }
68
69 //=============================================================================
70 /*!
71  *  StdMeshers_FixedPoints1D_i::SetNbSegments
72  */
73 //=============================================================================
74
75 void StdMeshers_FixedPoints1D_i::SetNbSegments(const SMESH::long_array& listNbSeg) 
76      throw ( SALOME::SALOME_Exception )
77 {
78   ASSERT( myBaseImpl );
79   try {
80     std::vector<int> nbsegs( listNbSeg.length() );
81     CORBA::Long iEnd = listNbSeg.length();
82     for ( CORBA::Long i = 0; i < iEnd; i++ )
83       nbsegs[ i ] = listNbSeg[ i ];
84     this->GetImpl()->SetNbSegments( nbsegs );
85   }
86   catch ( SALOME_Exception& S_ex ) {
87     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
88                                   SALOME::BAD_PARAM );
89   }
90
91   // Update Python script
92   SMESH::TPythonDump() << _this() << ".SetNbSegments( " << listNbSeg << " )";
93 }
94
95 //=============================================================================
96 /*!
97  *  StdMeshers_FixedPoints1D_i::SetPoints
98  */
99 //=============================================================================
100
101 void StdMeshers_FixedPoints1D_i::SetPoints(const SMESH::double_array& listParams) 
102      throw ( SALOME::SALOME_Exception )
103 {
104   ASSERT( myBaseImpl );
105   try {
106     std::vector<double> params( listParams.length() );
107     CORBA::Long iEnd = listParams.length();
108     for ( CORBA::Long i = 0; i < iEnd; i++ )
109       params[ i ] = listParams[ i ];
110     this->GetImpl()->SetPoints( params );
111   }
112   catch ( SALOME_Exception& S_ex ) {
113     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
114                                   SALOME::BAD_PARAM );
115   }
116
117   // Update Python script
118   SMESH::TPythonDump() << _this() << ".SetPoints( " << listParams << " )";
119 }
120
121 //=============================================================================
122 /*!
123  *  StdMeshers_FixedPoints1D_i::GetPoints
124  *
125  *  Get list of point's parameters
126  */
127 //=============================================================================
128
129 SMESH::double_array* StdMeshers_FixedPoints1D_i::GetPoints()
130 {
131   ASSERT( myBaseImpl );
132   SMESH::double_array_var anArray = new SMESH::double_array;
133   std::vector<double> params = this->GetImpl()->GetPoints();
134   anArray->length( params.size() );
135   for ( CORBA::ULong i = 0; i < params.size(); i++)
136     anArray [ i ] = params [ i ];
137
138   return anArray._retn();
139 }
140
141 //=============================================================================
142 /*!
143  *  StdMeshers_FixedPoints1D_i::GetNbSegments
144  *
145  *  Get list of point's parameters
146  */
147 //=============================================================================
148
149 SMESH::long_array* StdMeshers_FixedPoints1D_i::GetNbSegments()
150 {
151   ASSERT( myBaseImpl );
152   SMESH::long_array_var anArray = new SMESH::long_array;
153   std::vector<int> nbsegs = this->GetImpl()->GetNbSegments();
154   anArray->length( nbsegs.size() );
155   for ( CORBA::ULong i = 0; i < nbsegs.size(); i++)
156     anArray [ i ] = nbsegs [ i ];
157
158   return anArray._retn();
159 }
160
161 //=============================================================================
162 /*!
163  *  StdMeshers_FixedPoints1D_i::SetReversedEdges
164  *
165  *  Set edges to reverse
166  */
167 //=============================================================================
168
169 void StdMeshers_FixedPoints1D_i::SetReversedEdges( const SMESH::long_array& theIds )
170 {
171   ASSERT( myBaseImpl );
172   try {
173     std::vector<int> ids( theIds.length() );
174     CORBA::Long iEnd = theIds.length();
175     for ( CORBA::Long i = 0; i < iEnd; i++ )
176       ids[ i ] = theIds[ i ];
177
178     this->GetImpl()->SetReversedEdges( ids );
179   }
180   catch ( SALOME_Exception& S_ex ) {
181     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
182                                   SALOME::BAD_PARAM );
183   }
184
185   // Update Python script
186   SMESH::TPythonDump() << _this() << ".SetReversedEdges( " << theIds << " )";
187 }
188
189 //=============================================================================
190 /*!
191  *  StdMeshers_FixedPoints1D_i::SetObjectEntry
192  *
193  *  Set the Entry for the Main Object
194  */
195 //=============================================================================
196
197 void StdMeshers_FixedPoints1D_i::SetObjectEntry( const char* theEntry )
198 {
199   ASSERT( myBaseImpl );
200   string entry(theEntry); // actually needed as theEntry is spoiled by moment of dumping
201   try {
202     this->GetImpl()->SetObjectEntry( entry.c_str() );
203     // Update Python script
204     SMESH::TPythonDump() << _this() << ".SetObjectEntry( \"" << entry.c_str() << "\" )";
205   }
206   catch ( SALOME_Exception& S_ex ) {
207     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),SALOME::BAD_PARAM );
208   }
209 }
210
211 //=============================================================================
212 /*!
213  *  StdMeshers_FixedPoints1D_i::GetObjectEntry
214  *
215  *  Set the Entry for the Main Object
216  */
217 //=============================================================================
218
219 char* StdMeshers_FixedPoints1D_i::GetObjectEntry()
220 {
221   ASSERT( myBaseImpl );
222   const char* entry;
223   try {
224     entry = this->GetImpl()->GetObjectEntry();
225   }
226   catch ( SALOME_Exception& S_ex ) {
227     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
228                                   SALOME::BAD_PARAM );
229   }
230   return CORBA::string_dup( entry );
231 }
232
233 //=============================================================================
234 /*!
235  *  StdMeshers_FixedPoints1D_i::GetReversedEdges
236  *
237  *  Get reversed edges
238  */
239 //=============================================================================
240
241 SMESH::long_array* StdMeshers_FixedPoints1D_i::GetReversedEdges()
242 {
243   ASSERT( myBaseImpl );
244   SMESH::long_array_var anArray = new SMESH::long_array;
245   std::vector<int> ids = this->GetImpl()->GetReversedEdges();
246   anArray->length( ids.size() );
247   for ( CORBA::ULong i = 0; i < ids.size(); i++)
248     anArray [ i ] = ids [ i ];
249
250   return anArray._retn();
251 }
252
253 //=============================================================================
254 /*!
255  *  StdMeshers_FixedPoints1D_i::GetImpl
256  *
257  *  Get implementation
258  */
259 //=============================================================================
260
261 ::StdMeshers_FixedPoints1D* StdMeshers_FixedPoints1D_i::GetImpl()
262 {
263   return ( ::StdMeshers_FixedPoints1D* )myBaseImpl;
264 }
265
266 //================================================================================
267 /*!
268  * \brief Verify whether hypothesis supports given entity type 
269   * \param type - dimension (see SMESH::Dimension enumeration)
270   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
271  * 
272  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
273  */
274 //================================================================================  
275 CORBA::Boolean StdMeshers_FixedPoints1D_i::IsDimSupported( SMESH::Dimension type )
276 {
277   return type == SMESH::DIM_1D;
278 }
279