Salome HOME
23586: [EDF] HYDRO: Copy mesh to new geometry
[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     StdMeshers_Reversible1D_i( this )
52 {
53   myBaseImpl = new ::StdMeshers_FixedPoints1D(theGenImpl->GetANewId(),
54                                               theStudyId,
55                                               theGenImpl);
56 }
57
58 //=============================================================================
59 /*!
60  *  StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i
61  *
62  *  Destructor
63  */
64 //=============================================================================
65
66 StdMeshers_FixedPoints1D_i::~StdMeshers_FixedPoints1D_i()
67 {
68 }
69
70 //=============================================================================
71 /*!
72  *  StdMeshers_FixedPoints1D_i::SetNbSegments
73  */
74 //=============================================================================
75
76 void StdMeshers_FixedPoints1D_i::SetNbSegments(const SMESH::long_array& listNbSeg) 
77      throw ( SALOME::SALOME_Exception )
78 {
79   ASSERT( myBaseImpl );
80   try {
81     std::vector<int> nbsegs( listNbSeg.length() );
82     CORBA::Long iEnd = listNbSeg.length();
83     for ( CORBA::Long i = 0; i < iEnd; i++ )
84       nbsegs[ i ] = listNbSeg[ i ];
85     this->GetImpl()->SetNbSegments( nbsegs );
86   }
87   catch ( SALOME_Exception& S_ex ) {
88     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
89                                   SALOME::BAD_PARAM );
90   }
91
92   // Update Python script
93   SMESH::TPythonDump() << _this() << ".SetNbSegments( " << listNbSeg << " )";
94 }
95
96 //=============================================================================
97 /*!
98  *  StdMeshers_FixedPoints1D_i::SetPoints
99  */
100 //=============================================================================
101
102 void StdMeshers_FixedPoints1D_i::SetPoints(const SMESH::double_array& listParams) 
103      throw ( SALOME::SALOME_Exception )
104 {
105   ASSERT( myBaseImpl );
106   try {
107     std::vector<double> params( listParams.length() );
108     CORBA::Long iEnd = listParams.length();
109     for ( CORBA::Long i = 0; i < iEnd; i++ )
110       params[ i ] = listParams[ i ];
111     this->GetImpl()->SetPoints( params );
112   }
113   catch ( SALOME_Exception& S_ex ) {
114     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(),
115                                   SALOME::BAD_PARAM );
116   }
117
118   // Update Python script
119   SMESH::TPythonDump() << _this() << ".SetPoints( " << listParams << " )";
120 }
121
122 //=============================================================================
123 /*!
124  *  StdMeshers_FixedPoints1D_i::GetPoints
125  *
126  *  Get list of point's parameters
127  */
128 //=============================================================================
129
130 SMESH::double_array* StdMeshers_FixedPoints1D_i::GetPoints()
131 {
132   ASSERT( myBaseImpl );
133   SMESH::double_array_var anArray = new SMESH::double_array;
134   std::vector<double> params = this->GetImpl()->GetPoints();
135   anArray->length( params.size() );
136   for ( CORBA::ULong i = 0; i < params.size(); i++)
137     anArray [ i ] = params [ i ];
138
139   return anArray._retn();
140 }
141
142 //=============================================================================
143 /*!
144  *  StdMeshers_FixedPoints1D_i::GetNbSegments
145  *
146  *  Get list of point's parameters
147  */
148 //=============================================================================
149
150 SMESH::long_array* StdMeshers_FixedPoints1D_i::GetNbSegments()
151 {
152   ASSERT( myBaseImpl );
153   SMESH::long_array_var anArray = new SMESH::long_array;
154   std::vector<int> nbsegs = this->GetImpl()->GetNbSegments();
155   anArray->length( nbsegs.size() );
156   for ( CORBA::ULong i = 0; i < nbsegs.size(); i++)
157     anArray [ i ] = nbsegs [ i ];
158
159   return anArray._retn();
160 }
161
162 //=============================================================================
163 /*!
164  *  StdMeshers_FixedPoints1D_i::GetImpl
165  *
166  *  Get implementation
167  */
168 //=============================================================================
169
170 ::StdMeshers_FixedPoints1D* StdMeshers_FixedPoints1D_i::GetImpl()
171 {
172   return ( ::StdMeshers_FixedPoints1D* )myBaseImpl;
173 }
174
175 //================================================================================
176 /*!
177  * \brief Verify whether hypothesis supports given entity type 
178   * \param type - dimension (see SMESH::Dimension enumeration)
179   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
180  * 
181  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
182  */
183 //================================================================================
184 CORBA::Boolean StdMeshers_FixedPoints1D_i::IsDimSupported( SMESH::Dimension type )
185 {
186   return type == SMESH::DIM_1D;
187 }
188
189 //================================================================================
190 /*!
191  * \brief Return geometry this hypothesis depends on. Return false if there is no geometry parameter
192  */
193 //================================================================================
194
195 bool
196 StdMeshers_FixedPoints1D_i::getObjectsDependOn( std::vector< std::string > & entryArray,
197                                                 std::vector< int >         & subIDArray ) const
198 {
199   return StdMeshers_Reversible1D_i::getObjectsDependOn( entryArray, subIDArray );
200 }
201
202 //================================================================================
203 /*!
204  * \brief Set new geometry instead of that returned by getObjectsDependOn()
205  */
206 //================================================================================
207
208 bool
209 StdMeshers_FixedPoints1D_i::setObjectsDependOn( std::vector< std::string > & entryArray,
210                                                 std::vector< int >         & subIDArray )
211 {
212   return StdMeshers_Reversible1D_i::setObjectsDependOn( entryArray, subIDArray );
213 }