1 // Copyright (C) 2007-2013 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 // File : StdMeshers_CartesianParameters3D_i.cxx
25 #include "StdMeshers_CartesianParameters3D_i.hxx"
27 #include "StdMeshers_CartesianParameters3D.hxx"
28 #include "SMESH_Gen_i.hxx"
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_PythonDump.hxx"
32 #include "Utils_CorbaException.hxx"
33 #include "utilities.h"
35 #define _vec2array( v, a,conversion ) \
37 a->length( v.size() ); \
38 for ( size_t i = 0; i < v.size(); ++i ) \
39 a[i] = conversion( v[i] ); \
41 #define _array2vec(a,v,conversion) \
43 v.resize( a.length() ); \
44 for ( size_t i = 0; i < v.size(); ++i ) \
45 v[i] = conversion ( a[i] ); \
49 const char* _string2chars(const std::string& s ) { return s.c_str(); }
52 //=============================================================================
54 * StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i
58 //=============================================================================
60 StdMeshers_CartesianParameters3D_i::
61 StdMeshers_CartesianParameters3D_i( PortableServer::POA_ptr thePOA,
63 ::SMESH_Gen* theGenImpl )
64 : SALOME::GenericObj_i( thePOA ),
65 SMESH_Hypothesis_i( thePOA )
67 MESSAGE( "StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i" );
68 myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
73 //=============================================================================
75 * StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i
79 //=============================================================================
81 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
83 MESSAGE( "StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i" );
86 //=============================================================================
90 //=============================================================================
92 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
94 throw (SALOME::SALOME_Exception)
96 std::vector<double> coordVec;//, yCoords, zCoords;
97 _array2vec( coords, coordVec, );
101 this->GetImpl()->SetGrid( coordVec, axis );
103 catch ( SALOME_Exception& S_ex ) {
104 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
107 // Update Python script
108 SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
111 //=============================================================================
115 //=============================================================================
117 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
118 throw (SALOME::SALOME_Exception)
120 std::vector<double> coordVec;
121 ASSERT( myBaseImpl );
123 this->GetImpl()->GetGrid(coordVec, axis);
125 catch ( SALOME_Exception& S_ex ) {
126 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
129 SMESH::double_array_var coords = new SMESH::double_array();
130 _vec2array( coordVec, coords, );
132 return coords._retn();
135 //=============================================================================
139 //=============================================================================
141 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
142 throw (SALOME::SALOME_Exception)
144 ASSERT( myBaseImpl );
146 this->GetImpl()->SetSizeThreshold(threshold);
148 catch ( SALOME_Exception& S_ex ) {
149 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
152 // Update Python script
153 SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << SMESH::TVar(threshold) << " )";
156 //=============================================================================
160 //=============================================================================
162 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
164 return this->GetImpl()->GetSizeThreshold();
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 //=======================================================================
176 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
177 const SMESH::double_array& internalPoints,
179 throw (SALOME::SALOME_Exception)
181 vector<string> funVec;
182 vector<double> pointVec;
183 _array2vec( spaceFunctions, funVec, (const char*) );
184 _array2vec( internalPoints, pointVec, );
186 ASSERT( myBaseImpl );
188 this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
190 catch ( SALOME_Exception& S_ex ) {
191 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
194 // Update Python script
195 SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
196 << spaceFunctions << ", "
197 << internalPoints << ", "
201 //=======================================================================
202 //function : GetGridSpacing
203 //=======================================================================
205 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
206 SMESH::double_array_out xInternalPoints,
208 throw (SALOME::SALOME_Exception)
210 ASSERT( myBaseImpl );
212 vector<string> funVec;
213 vector<double> pointVec;
214 this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
216 xSpaceFunctions = new SMESH::string_array();
217 xInternalPoints = new SMESH::double_array();
219 _vec2array( funVec, xSpaceFunctions, _string2chars );
220 _vec2array( pointVec, xInternalPoints, );
222 catch ( SALOME_Exception& S_ex ) {
223 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
227 //=======================================================================
228 //function : IsGridBySpacing
229 //purpose : Return true if the grid is defined by spacing functions and
230 // not by node coordinates
231 //=======================================================================
233 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
235 return this->GetImpl()->IsGridBySpacing(axis);
238 //=======================================================================
239 //function : ComputeCoordinates
240 //purpose : Computes node coordinates by spacing functions
241 //=======================================================================
244 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
246 const SMESH::string_array& spaceFuns,
247 const SMESH::double_array& points,
248 const char* axisName )
249 throw (SALOME::SALOME_Exception)
251 vector<string> xFuns;
252 vector<double> xPoints, coords;
253 _array2vec( spaceFuns, xFuns, (const char*) );
254 _array2vec( points, xPoints, );
257 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
259 catch ( SALOME_Exception& S_ex ) {
260 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
262 SMESH::double_array_var res = new SMESH::double_array;
263 _vec2array( coords, res, );
268 //=============================================================================
272 //=============================================================================
274 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
276 MESSAGE( "StdMeshers_CartesianParameters3D_i::GetImpl" );
277 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
280 //================================================================================
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
286 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
288 //================================================================================
290 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
292 return type == SMESH::DIM_3D;