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,
63 ::SMESH_Gen* theGenImpl )
64 : SALOME::GenericObj_i( thePOA ),
65 SMESH_Hypothesis_i( thePOA )
67 myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
72 //=============================================================================
74 * StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i
78 //=============================================================================
80 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
84 //=============================================================================
88 //=============================================================================
90 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
92 throw (SALOME::SALOME_Exception)
94 std::vector<double> coordVec;//, yCoords, zCoords;
95 _array2vec( coords, coordVec, );
99 this->GetImpl()->SetGrid( coordVec, axis );
101 catch ( SALOME_Exception& S_ex ) {
102 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
105 // Update Python script
106 SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
109 //=============================================================================
113 //=============================================================================
115 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
116 throw (SALOME::SALOME_Exception)
118 std::vector<double> coordVec;
119 ASSERT( myBaseImpl );
121 this->GetImpl()->GetGrid(coordVec, axis);
123 catch ( SALOME_Exception& S_ex ) {
124 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
127 SMESH::double_array_var coords = new SMESH::double_array();
128 _vec2array( coordVec, coords, );
130 return coords._retn();
133 //=============================================================================
137 //=============================================================================
139 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
140 throw (SALOME::SALOME_Exception)
142 ASSERT( myBaseImpl );
144 this->GetImpl()->SetSizeThreshold(threshold);
146 catch ( SALOME_Exception& S_ex ) {
147 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
150 // Update Python script
151 SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << SMESH::TVar(threshold) << " )";
154 //=============================================================================
158 //=============================================================================
160 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
162 return this->GetImpl()->GetSizeThreshold();
165 //=======================================================================
166 //function : SetGridSpacing
167 //\brief Set grid spacing along the three axes
168 // \param spaceFunctions - functions defining spacing values at given point on axis
169 // \param internalPoints - points dividing a grid into parts along each direction
170 // Parameter t of spaceFunction f(t) is a position [0,1] within bounding box of
171 // the shape to mesh or within an interval defined by internal points
172 //=======================================================================
174 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
175 const SMESH::double_array& internalPoints,
177 throw (SALOME::SALOME_Exception)
179 std::vector<std::string> funVec;
180 std::vector<double> pointVec;
181 _array2vec( spaceFunctions, funVec, (const char*) );
182 _array2vec( internalPoints, pointVec, );
184 ASSERT( myBaseImpl );
186 this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
188 catch ( SALOME_Exception& S_ex ) {
189 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
192 // Update Python script
193 SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
194 << spaceFunctions << ", "
195 << internalPoints << ", "
199 //=======================================================================
200 //function : GetGridSpacing
201 //=======================================================================
203 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
204 SMESH::double_array_out xInternalPoints,
206 throw (SALOME::SALOME_Exception)
208 ASSERT( myBaseImpl );
210 std::vector<std::string> funVec;
211 std::vector<double> pointVec;
212 this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
214 xSpaceFunctions = new SMESH::string_array();
215 xInternalPoints = new SMESH::double_array();
217 _vec2array( funVec, xSpaceFunctions, _string2chars );
218 _vec2array( pointVec, xInternalPoints, );
220 catch ( SALOME_Exception& S_ex ) {
221 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
225 //=======================================================================
226 //function : SetAxesDirs
227 //purpose : Set custom direction of axes
228 //=======================================================================
230 void StdMeshers_CartesianParameters3D_i::SetAxesDirs(const SMESH::DirStruct& xDir,
231 const SMESH::DirStruct& yDir,
232 const SMESH::DirStruct& zDir)
233 throw (SALOME::SALOME_Exception)
236 coords[0] = xDir.PS.x;
237 coords[1] = xDir.PS.y;
238 coords[2] = xDir.PS.z;
239 coords[3] = yDir.PS.x;
240 coords[4] = yDir.PS.y;
241 coords[5] = yDir.PS.z;
242 coords[6] = zDir.PS.x;
243 coords[7] = zDir.PS.y;
244 coords[8] = zDir.PS.z;
246 this->GetImpl()->SetAxisDirs(coords);
248 SMESH::TPythonDump() << _this() << ".SetAxesDirs( "
253 catch ( SALOME_Exception& S_ex ) {
254 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
258 //=======================================================================
259 //function : GetAxesDirs
260 //purpose : Returns direction of axes
261 //=======================================================================
263 void StdMeshers_CartesianParameters3D_i::GetAxesDirs(SMESH::DirStruct& xDir,
264 SMESH::DirStruct& yDir,
265 SMESH::DirStruct& zDir)
267 const double* coords = GetImpl()->GetAxisDirs();
268 xDir.PS.x = coords[0];
269 xDir.PS.y = coords[1];
270 xDir.PS.z = coords[2];
271 yDir.PS.x = coords[3];
272 yDir.PS.y = coords[4];
273 yDir.PS.z = coords[5];
274 zDir.PS.x = coords[6];
275 zDir.PS.y = coords[7];
276 zDir.PS.z = coords[8];
279 //=======================================================================
280 //function : SetFixedPoint
281 //purpose : * Set/unset a fixed point, at which a node will be created provided that grid
282 // * is defined by spacing in all directions
283 //=======================================================================
285 void StdMeshers_CartesianParameters3D_i::SetFixedPoint(const SMESH::PointStruct& ps,
286 CORBA::Boolean toUnset)
288 double p[3] = { ps.x, ps.y, ps.z };
289 GetImpl()->SetFixedPoint( p, toUnset );
291 SMESH::TPythonDump() << _this() << ".SetFixedPoint( " << ps << ", " << toUnset << " )";
294 //=======================================================================
295 //function : GetFixedPoint
296 //purpose : Returns a fixed point
297 //=======================================================================
299 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetFixedPoint(SMESH::PointStruct& ps)
302 if ( GetImpl()->GetFixedPoint( p ) )
318 //=======================================================================
319 //function : SetToAddEdges
320 //purpose : Enables implementation of geometrical edges into the mesh.
321 //=======================================================================
323 void StdMeshers_CartesianParameters3D_i::SetToAddEdges(CORBA::Boolean toAdd)
325 GetImpl()->SetToAddEdges( toAdd );
326 SMESH::TPythonDump() << _this() << ".SetToAddEdges( " << toAdd << " )";
329 //=======================================================================
330 //function : GetToAddEdges
331 //purpose : Returns true if implementation of geometrical edges into the
333 //=======================================================================
335 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToAddEdges()
337 return GetImpl()->GetToAddEdges();
340 //=======================================================================
341 //function : IsGridBySpacing
342 //purpose : Return true if the grid is defined by spacing functions and
343 // not by node coordinates
344 //=======================================================================
346 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
348 return this->GetImpl()->IsGridBySpacing(axis);
351 //=======================================================================
352 //function : ComputeOptimalAxesDirs
353 //purpose : Returns axes at which number of hexahedra is maximal
354 //=======================================================================
356 void StdMeshers_CartesianParameters3D_i::
357 ComputeOptimalAxesDirs(GEOM::GEOM_Object_ptr go,
358 CORBA::Boolean isOrthogonal,
359 SMESH::DirStruct& xDir,
360 SMESH::DirStruct& yDir,
361 SMESH::DirStruct& zDir)
362 throw (SALOME::SALOME_Exception)
364 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( go );
365 if ( shape.IsNull() )
366 THROW_SALOME_CORBA_EXCEPTION( "Null shape", SALOME::BAD_PARAM );
369 ::StdMeshers_CartesianParameters3D::ComputeOptimalAxesDirs( shape, isOrthogonal, c );
382 //=======================================================================
383 //function : ComputeCoordinates
384 //purpose : Computes node coordinates by spacing functions
385 //=======================================================================
388 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
390 const SMESH::string_array& spaceFuns,
391 const SMESH::double_array& points,
392 const char* axisName )
393 throw (SALOME::SALOME_Exception)
395 std::vector<std::string> xFuns;
396 std::vector<double> xPoints, coords;
397 _array2vec( spaceFuns, xFuns, (const char*) );
398 _array2vec( points, xPoints, );
401 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
403 catch ( SALOME_Exception& S_ex ) {
404 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
406 SMESH::double_array_var res = new SMESH::double_array;
407 _vec2array( coords, res, );
412 //=============================================================================
416 //=============================================================================
418 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
420 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
423 //================================================================================
425 * \brief Verify whether hypothesis supports given entity type
426 * \param type - dimension (see SMESH::Dimension enumeration)
427 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
429 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
431 //================================================================================
433 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
435 return type == SMESH::DIM_3D;