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