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