1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 // File : StdMeshers_CartesianParameters3D_i.cxx
26 #include "StdMeshers_CartesianParameters3D_i.hxx"
28 #include "StdMeshers_CartesianParameters3D.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_Gen.hxx"
31 #include "SMESH_PythonDump.hxx"
33 #include "Utils_CorbaException.hxx"
34 #include "utilities.h"
36 #define _vec2array( v, a,conversion ) \
38 a->length( v.size() ); \
39 for ( size_t i = 0; i < v.size(); ++i ) \
40 a[i] = conversion( v[i] ); \
42 #define _array2vec(a,v,conversion) \
44 v.resize( a.length() ); \
45 for ( size_t i = 0; i < v.size(); ++i ) \
46 v[i] = conversion ( a[i] ); \
50 const char* _string2chars(const std::string& s ) { return s.c_str(); }
53 //=============================================================================
55 * StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i
59 //=============================================================================
61 StdMeshers_CartesianParameters3D_i::
62 StdMeshers_CartesianParameters3D_i( PortableServer::POA_ptr thePOA,
64 ::SMESH_Gen* theGenImpl )
65 : SALOME::GenericObj_i( thePOA ),
66 SMESH_Hypothesis_i( thePOA )
68 MESSAGE( "StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i" );
69 myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
74 //=============================================================================
76 * StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i
80 //=============================================================================
82 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
84 MESSAGE( "StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i" );
87 //=============================================================================
91 //=============================================================================
93 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
95 throw (SALOME::SALOME_Exception)
97 std::vector<double> coordVec;//, yCoords, zCoords;
98 _array2vec( coords, coordVec, );
100 ASSERT( myBaseImpl );
102 this->GetImpl()->SetGrid( coordVec, axis );
104 catch ( SALOME_Exception& S_ex ) {
105 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
108 // Update Python script
109 SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
112 //=============================================================================
116 //=============================================================================
118 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
119 throw (SALOME::SALOME_Exception)
121 std::vector<double> coordVec;
122 ASSERT( myBaseImpl );
124 this->GetImpl()->GetGrid(coordVec, axis);
126 catch ( SALOME_Exception& S_ex ) {
127 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
130 SMESH::double_array_var coords = new SMESH::double_array();
131 _vec2array( coordVec, coords, );
133 return coords._retn();
136 //=============================================================================
140 //=============================================================================
142 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
143 throw (SALOME::SALOME_Exception)
145 ASSERT( myBaseImpl );
147 this->GetImpl()->SetSizeThreshold(threshold);
149 catch ( SALOME_Exception& S_ex ) {
150 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
153 // Update Python script
154 SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << threshold << " )";
157 //=============================================================================
161 //=============================================================================
163 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
165 return this->GetImpl()->GetSizeThreshold();
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 //=======================================================================
177 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
178 const SMESH::double_array& internalPoints,
180 throw (SALOME::SALOME_Exception)
182 vector<string> funVec;
183 vector<double> pointVec;
184 _array2vec( spaceFunctions, funVec, (const char*) );
185 _array2vec( internalPoints, pointVec, );
187 ASSERT( myBaseImpl );
189 this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
191 catch ( SALOME_Exception& S_ex ) {
192 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
195 // Update Python script
196 SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
197 << spaceFunctions << ", "
198 << internalPoints << ", "
202 //=======================================================================
203 //function : GetGridSpacing
204 //=======================================================================
206 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
207 SMESH::double_array_out xInternalPoints,
209 throw (SALOME::SALOME_Exception)
211 ASSERT( myBaseImpl );
213 vector<string> funVec;
214 vector<double> pointVec;
215 this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
217 xSpaceFunctions = new SMESH::string_array();
218 xInternalPoints = new SMESH::double_array();
220 _vec2array( funVec, xSpaceFunctions, _string2chars );
221 _vec2array( pointVec, xInternalPoints, );
223 catch ( SALOME_Exception& S_ex ) {
224 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
228 //=======================================================================
229 //function : IsGridBySpacing
230 //purpose : Return true if the grid is defined by spacing functions and
231 // not by node coordinates
232 //=======================================================================
234 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
236 return this->GetImpl()->IsGridBySpacing(axis);
239 //=======================================================================
240 //function : ComputeCoordinates
241 //purpose : Computes node coordinates by spacing functions
242 //=======================================================================
245 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
247 const SMESH::string_array& spaceFuns,
248 const SMESH::double_array& points,
249 const char* axisName )
250 throw (SALOME::SALOME_Exception)
252 vector<string> xFuns;
253 vector<double> xPoints, coords;
254 _array2vec( spaceFuns, xFuns, (const char*) );
255 _array2vec( points, xPoints, );
258 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
260 catch ( SALOME_Exception& S_ex ) {
261 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
263 SMESH::double_array_var res = new SMESH::double_array;
264 _vec2array( coords, res, );
269 //=============================================================================
273 //=============================================================================
275 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
277 MESSAGE( "StdMeshers_CartesianParameters3D_i::GetImpl" );
278 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
281 //================================================================================
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
287 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
289 //================================================================================
291 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
293 return type == SMESH::DIM_3D;