1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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,
62 ::SMESH_Gen* theGenImpl )
63 : SALOME::GenericObj_i( thePOA ),
64 SMESH_Hypothesis_i( thePOA )
66 myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
70 //=============================================================================
72 * StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i
76 //=============================================================================
78 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
82 //=============================================================================
86 //=============================================================================
88 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
90 throw (SALOME::SALOME_Exception)
92 std::vector<double> coordVec;//, yCoords, zCoords;
93 _array2vec( coords, coordVec, );
97 this->GetImpl()->SetGrid( coordVec, axis );
99 catch ( SALOME_Exception& S_ex ) {
100 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
103 // Update Python script
104 SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
107 //=============================================================================
111 //=============================================================================
113 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
114 throw (SALOME::SALOME_Exception)
116 std::vector<double> coordVec;
117 ASSERT( myBaseImpl );
119 this->GetImpl()->GetGrid(coordVec, axis);
121 catch ( SALOME_Exception& S_ex ) {
122 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
125 SMESH::double_array_var coords = new SMESH::double_array();
126 _vec2array( coordVec, coords, );
128 return coords._retn();
131 //=============================================================================
135 //=============================================================================
137 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
138 throw (SALOME::SALOME_Exception)
140 ASSERT( myBaseImpl );
142 this->GetImpl()->SetSizeThreshold(threshold);
144 catch ( SALOME_Exception& S_ex ) {
145 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
148 // Update Python script
149 SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << SMESH::TVar(threshold) << " )";
152 //=============================================================================
156 //=============================================================================
158 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
160 return this->GetImpl()->GetSizeThreshold();
163 //=======================================================================
164 //function : SetGridSpacing
165 //\brief Set grid spacing along the three axes
166 // \param spaceFunctions - functions defining spacing values at given point on axis
167 // \param internalPoints - points dividing a grid into parts along each direction
168 // Parameter t of spaceFunction f(t) is a position [0,1] within bounding box of
169 // the shape to mesh or within an interval defined by internal points
170 //=======================================================================
172 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
173 const SMESH::double_array& internalPoints,
175 throw (SALOME::SALOME_Exception)
177 std::vector<std::string> funVec;
178 std::vector<double> pointVec;
179 _array2vec( spaceFunctions, funVec, (const char*) );
180 _array2vec( internalPoints, pointVec, );
182 ASSERT( myBaseImpl );
184 this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
186 catch ( SALOME_Exception& S_ex ) {
187 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
190 // Update Python script
191 SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
192 << spaceFunctions << ", "
193 << internalPoints << ", "
197 //=======================================================================
198 //function : GetGridSpacing
199 //=======================================================================
201 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
202 SMESH::double_array_out xInternalPoints,
204 throw (SALOME::SALOME_Exception)
206 ASSERT( myBaseImpl );
208 std::vector<std::string> funVec;
209 std::vector<double> pointVec;
210 this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
212 xSpaceFunctions = new SMESH::string_array();
213 xInternalPoints = new SMESH::double_array();
215 _vec2array( funVec, xSpaceFunctions, _string2chars );
216 _vec2array( pointVec, xInternalPoints, );
218 catch ( SALOME_Exception& S_ex ) {
219 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
223 //=======================================================================
224 //function : SetAxesDirs
225 //purpose : Set custom direction of axes
226 //=======================================================================
228 void StdMeshers_CartesianParameters3D_i::SetAxesDirs(const SMESH::DirStruct& xDir,
229 const SMESH::DirStruct& yDir,
230 const SMESH::DirStruct& zDir)
231 throw (SALOME::SALOME_Exception)
234 coords[0] = xDir.PS.x;
235 coords[1] = xDir.PS.y;
236 coords[2] = xDir.PS.z;
237 coords[3] = yDir.PS.x;
238 coords[4] = yDir.PS.y;
239 coords[5] = yDir.PS.z;
240 coords[6] = zDir.PS.x;
241 coords[7] = zDir.PS.y;
242 coords[8] = zDir.PS.z;
244 this->GetImpl()->SetAxisDirs(coords);
246 SMESH::TPythonDump() << _this() << ".SetAxesDirs( "
251 catch ( SALOME_Exception& S_ex ) {
252 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
256 //=======================================================================
257 //function : GetAxesDirs
258 //purpose : Returns direction of axes
259 //=======================================================================
261 void StdMeshers_CartesianParameters3D_i::GetAxesDirs(SMESH::DirStruct& xDir,
262 SMESH::DirStruct& yDir,
263 SMESH::DirStruct& zDir)
265 const double* coords = GetImpl()->GetAxisDirs();
266 xDir.PS.x = coords[0];
267 xDir.PS.y = coords[1];
268 xDir.PS.z = coords[2];
269 yDir.PS.x = coords[3];
270 yDir.PS.y = coords[4];
271 yDir.PS.z = coords[5];
272 zDir.PS.x = coords[6];
273 zDir.PS.y = coords[7];
274 zDir.PS.z = coords[8];
277 //=======================================================================
278 //function : SetFixedPoint
279 //purpose : * Set/unset a fixed point, at which a node will be created provided that grid
280 // * is defined by spacing in all directions
281 //=======================================================================
283 void StdMeshers_CartesianParameters3D_i::SetFixedPoint(const SMESH::PointStruct& ps,
284 CORBA::Boolean toUnset)
286 double p[3] = { ps.x, ps.y, ps.z };
287 GetImpl()->SetFixedPoint( p, toUnset );
289 SMESH::TPythonDump() << _this() << ".SetFixedPoint( " << ps << ", " << toUnset << " )";
292 //=======================================================================
293 //function : GetFixedPoint
294 //purpose : Returns a fixed point
295 //=======================================================================
297 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetFixedPoint(SMESH::PointStruct& ps)
300 if ( GetImpl()->GetFixedPoint( p ) )
316 //=======================================================================
317 //function : SetToAddEdges
318 //purpose : Enables implementation of geometrical edges into the mesh.
319 //=======================================================================
321 void StdMeshers_CartesianParameters3D_i::SetToAddEdges(CORBA::Boolean toAdd)
323 GetImpl()->SetToAddEdges( toAdd );
324 SMESH::TPythonDump() << _this() << ".SetToAddEdges( " << toAdd << " )";
327 //=======================================================================
328 //function : GetToAddEdges
329 //purpose : Returns true if implementation of geometrical edges into the
331 //=======================================================================
333 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToAddEdges()
335 return GetImpl()->GetToAddEdges();
338 //=======================================================================
339 //function : IsGridBySpacing
340 //purpose : Return true if the grid is defined by spacing functions and
341 // not by node coordinates
342 //=======================================================================
344 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
346 return this->GetImpl()->IsGridBySpacing(axis);
349 //=======================================================================
350 //function : ComputeOptimalAxesDirs
351 //purpose : Returns axes at which number of hexahedra is maximal
352 //=======================================================================
354 void StdMeshers_CartesianParameters3D_i::
355 ComputeOptimalAxesDirs(GEOM::GEOM_Object_ptr go,
356 CORBA::Boolean isOrthogonal,
357 SMESH::DirStruct& xDir,
358 SMESH::DirStruct& yDir,
359 SMESH::DirStruct& zDir)
360 throw (SALOME::SALOME_Exception)
362 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( go );
363 if ( shape.IsNull() )
364 THROW_SALOME_CORBA_EXCEPTION( "Null shape", SALOME::BAD_PARAM );
367 ::StdMeshers_CartesianParameters3D::ComputeOptimalAxesDirs( shape, isOrthogonal, c );
380 //=======================================================================
381 //function : ComputeCoordinates
382 //purpose : Computes node coordinates by spacing functions
383 //=======================================================================
386 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
388 const SMESH::string_array& spaceFuns,
389 const SMESH::double_array& points,
390 const char* axisName )
391 throw (SALOME::SALOME_Exception)
393 std::vector<std::string> xFuns;
394 std::vector<double> xPoints, coords;
395 _array2vec( spaceFuns, xFuns, (const char*) );
396 _array2vec( points, xPoints, );
399 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
401 catch ( SALOME_Exception& S_ex ) {
402 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
404 SMESH::double_array_var res = new SMESH::double_array;
405 _vec2array( coords, res, );
410 //=============================================================================
414 //=============================================================================
416 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
418 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
421 //================================================================================
423 * \brief Verify whether hypothesis supports given entity type
424 * \param type - dimension (see SMESH::Dimension enumeration)
425 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
427 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
429 //================================================================================
431 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
433 return type == SMESH::DIM_3D;