Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_CartesianParameters3D_i.cxx
1 // Copyright (C) 2007-2012  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 //  File   : StdMeshers_CartesianParameters3D_i.cxx
23 //  Module : SMESH
24 //
25 #include "StdMeshers_CartesianParameters3D_i.hxx"
26
27 #include "StdMeshers_CartesianParameters3D.hxx"
28 #include "SMESH_Gen_i.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_PythonDump.hxx"
31
32 #include "Utils_CorbaException.hxx"
33 #include "utilities.h"
34
35 #define _vec2array( v, a,conversion )           \
36   {                                             \
37     a->length( v.size() );                      \
38     for ( size_t i = 0; i < v.size(); ++i )     \
39       a[i] = conversion( v[i] );                \
40   }
41 #define _array2vec(a,v,conversion)              \
42   {                                             \
43     v.resize( a.length() );                     \
44     for ( size_t i = 0; i < v.size(); ++i )     \
45       v[i] = conversion ( a[i] );               \
46   }
47 namespace
48 {
49   const char* _string2chars(const std::string& s ) { return s.c_str(); }
50 }
51
52 //=============================================================================
53 /*!
54  *  StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i
55  *
56  *  Constructor
57  */
58 //=============================================================================
59
60 StdMeshers_CartesianParameters3D_i::
61 StdMeshers_CartesianParameters3D_i( PortableServer::POA_ptr thePOA,
62                                     int                     theStudyId,
63                                     ::SMESH_Gen*            theGenImpl )
64   : SALOME::GenericObj_i( thePOA ), 
65     SMESH_Hypothesis_i( thePOA )
66 {
67   MESSAGE( "StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i" );
68   myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
69                                                        theStudyId,
70                                                        theGenImpl );
71 }
72
73 //=============================================================================
74 /*!
75  *  StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i
76  *
77  *  Destructor
78  */
79 //=============================================================================
80
81 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
82 {
83   MESSAGE( "StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i" );
84 }
85
86 //=============================================================================
87 /*!
88  * SetGrid
89  */
90 //=============================================================================
91
92 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
93                                                  CORBA::Short               axis)
94   throw (SALOME::SALOME_Exception)
95 {
96   std::vector<double> coordVec;//, yCoords, zCoords;
97   _array2vec( coords, coordVec, );
98
99   ASSERT( myBaseImpl );
100   try {
101     this->GetImpl()->SetGrid( coordVec, axis );
102   }
103   catch ( SALOME_Exception& S_ex ) {
104     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
105   }
106
107   // Update Python script
108   SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
109 }
110
111 //=============================================================================
112 /*!
113  *  GetGrid
114  */
115 //=============================================================================
116
117 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
118   throw (SALOME::SALOME_Exception)
119 {
120   std::vector<double> coordVec;
121   ASSERT( myBaseImpl );
122   try {
123     this->GetImpl()->GetGrid(coordVec, axis);
124   }
125   catch ( SALOME_Exception& S_ex ) {
126     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
127   }
128
129   SMESH::double_array_var coords = new SMESH::double_array();
130   _vec2array( coordVec, coords, );
131
132   return coords._retn();
133 }
134
135 //=============================================================================
136 /*!
137  *  SetSizeThreshold
138  */
139 //=============================================================================
140
141 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
142   throw (SALOME::SALOME_Exception)
143 {
144   ASSERT( myBaseImpl );
145   try {
146     this->GetImpl()->SetSizeThreshold(threshold);
147   }
148   catch ( SALOME_Exception& S_ex ) {
149     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
150   }
151
152   // Update Python script
153   SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << SMESH::TVar(threshold) << " )";
154 }
155
156 //=============================================================================
157 /*!
158  *  GetSizeThreshold
159  */
160 //=============================================================================
161
162 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
163 {
164   return this->GetImpl()->GetSizeThreshold();
165 }
166
167 //=======================================================================
168 //function : SetGridSpacing
169 //\brief Set grid spacing along the three axes
170 // \param spaceFunctions - functions defining spacing values at given point on axis
171 // \param internalPoints - points dividing a grid into parts along each direction
172 // Parameter t of spaceFunction f(t) is a position [0,1] withing bounding box of
173 // the shape to mesh or withing an interval defined by internal points
174 //=======================================================================
175
176 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
177                                                         const SMESH::double_array& internalPoints,
178                                                         CORBA::Short               axis)
179   throw (SALOME::SALOME_Exception)
180 {
181   vector<string> funVec;
182   vector<double> pointVec;
183   _array2vec( spaceFunctions, funVec, (const char*) );
184   _array2vec( internalPoints, pointVec, );
185
186   ASSERT( myBaseImpl );
187   try {
188     this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
189   }
190   catch ( SALOME_Exception& S_ex ) {
191     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
192   }
193
194   // Update Python script
195   SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
196                        << spaceFunctions << ", "
197                        << internalPoints << ", "
198                        << axis << " )";
199 }
200
201 //=======================================================================
202 //function : GetGridSpacing
203 //=======================================================================
204
205 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
206                                                         SMESH::double_array_out xInternalPoints,
207                                                         CORBA::Short            axis)
208   throw (SALOME::SALOME_Exception)
209 {
210   ASSERT( myBaseImpl );
211   try {
212     vector<string> funVec;
213     vector<double> pointVec;
214     this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
215
216     xSpaceFunctions = new SMESH::string_array();
217     xInternalPoints = new SMESH::double_array();
218
219     _vec2array( funVec, xSpaceFunctions, _string2chars );
220     _vec2array( pointVec, xInternalPoints, );
221   }
222   catch ( SALOME_Exception& S_ex ) {
223     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
224   }
225 }
226
227 //=======================================================================
228 //function : IsGridBySpacing
229 //purpose  : Return true if the grid is defined by spacing functions and 
230 //           not by node coordinates
231 //=======================================================================
232
233 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
234 {
235   return this->GetImpl()->IsGridBySpacing(axis);
236 }
237
238 //=======================================================================
239 //function : ComputeCoordinates
240 //purpose  : Computes node coordinates by spacing functions
241 //=======================================================================
242
243 SMESH::double_array*
244 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double              x0,
245                                                        CORBA::Double              x1,
246                                                        const SMESH::string_array& spaceFuns,
247                                                        const SMESH::double_array& points,
248                                                        const char*                axisName )
249     throw (SALOME::SALOME_Exception)
250 {
251   vector<string> xFuns;
252   vector<double> xPoints, coords;
253   _array2vec( spaceFuns, xFuns, (const char*) );
254   _array2vec( points, xPoints, );
255   
256   try {
257     this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
258   }
259   catch ( SALOME_Exception& S_ex ) {
260     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
261   }
262   SMESH::double_array_var res = new SMESH::double_array;
263   _vec2array( coords, res,  );
264
265   return res._retn();
266 }
267
268 //=============================================================================
269 /*!
270  *  Get implementation
271  */
272 //=============================================================================
273
274 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
275 {
276   MESSAGE( "StdMeshers_CartesianParameters3D_i::GetImpl" );
277   return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
278 }
279
280 //================================================================================
281 /*!
282  * \brief Verify whether hypothesis supports given entity type 
283   * \param type - dimension (see SMESH::Dimension enumeration)
284   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
285  * 
286  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
287  */
288 //================================================================================  
289
290 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
291 {
292   return type == SMESH::DIM_3D;
293 }