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 : SetAxesDirs
229 //purpose : Set custom direction of axes
230 //=======================================================================
232 void StdMeshers_CartesianParameters3D_i::SetAxesDirs(const SMESH::DirStruct& xDir,
233 const SMESH::DirStruct& yDir,
234 const SMESH::DirStruct& zDir)
235 throw (SALOME::SALOME_Exception)
238 coords[0] = xDir.PS.x;
239 coords[1] = xDir.PS.y;
240 coords[2] = xDir.PS.z;
241 coords[3] = yDir.PS.x;
242 coords[4] = yDir.PS.y;
243 coords[5] = yDir.PS.z;
244 coords[6] = zDir.PS.x;
245 coords[7] = zDir.PS.y;
246 coords[8] = zDir.PS.z;
248 this->GetImpl()->SetAxisDirs(coords);
250 SMESH::TPythonDump() << _this() << ".SetAxesDirs( "
255 catch ( SALOME_Exception& S_ex ) {
256 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
260 //=======================================================================
261 //function : GetAxesDirs
262 //purpose : Returns direction of axes
263 //=======================================================================
265 void StdMeshers_CartesianParameters3D_i::GetAxesDirs(SMESH::DirStruct& xDir,
266 SMESH::DirStruct& yDir,
267 SMESH::DirStruct& zDir)
269 const double* coords = GetImpl()->GetAxisDirs();
270 xDir.PS.x = coords[0];
271 xDir.PS.y = coords[1];
272 xDir.PS.z = coords[2];
273 yDir.PS.x = coords[3];
274 yDir.PS.y = coords[4];
275 yDir.PS.z = coords[5];
276 zDir.PS.x = coords[6];
277 zDir.PS.y = coords[7];
278 zDir.PS.z = coords[8];
281 //=======================================================================
282 //function : SetFixedPoint
283 //purpose : * Set/unset a fixed point, at which a node will be created provided that grid
284 // * is defined by spacing in all directions
285 //=======================================================================
287 void StdMeshers_CartesianParameters3D_i::SetFixedPoint(const SMESH::PointStruct& ps,
288 CORBA::Boolean toUnset)
290 double p[3] = { ps.x, ps.y, ps.z };
291 GetImpl()->SetFixedPoint( p, toUnset );
293 SMESH::TPythonDump() << _this() << ".SetFixedPoint( " << ps << ", " << toUnset << " )";
296 //=======================================================================
297 //function : GetFixedPoint
298 //purpose : Returns a fixed point
299 //=======================================================================
301 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetFixedPoint(SMESH::PointStruct& ps)
304 if ( GetImpl()->GetFixedPoint( p ) )
320 //=======================================================================
321 //function : SetToAddEdges
322 //purpose : Enables implementation of geometrical edges into the mesh.
323 //=======================================================================
325 void StdMeshers_CartesianParameters3D_i::SetToAddEdges(CORBA::Boolean toAdd)
327 GetImpl()->SetToAddEdges( toAdd );
328 SMESH::TPythonDump() << _this() << ".SetToAddEdges( " << toAdd << " )";
331 //=======================================================================
332 //function : GetToAddEdges
333 //purpose : Returns true if implementation of geometrical edges into the
335 //=======================================================================
337 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToAddEdges()
339 return GetImpl()->GetToAddEdges();
342 //=======================================================================
343 //function : IsGridBySpacing
344 //purpose : Return true if the grid is defined by spacing functions and
345 // not by node coordinates
346 //=======================================================================
348 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
350 return this->GetImpl()->IsGridBySpacing(axis);
353 //=======================================================================
354 //function : ComputeOptimalAxesDirs
355 //purpose : Returns axes at which number of hexahedra is maximal
356 //=======================================================================
358 void StdMeshers_CartesianParameters3D_i::
359 ComputeOptimalAxesDirs(GEOM::GEOM_Object_ptr go,
360 CORBA::Boolean isOrthogonal,
361 SMESH::DirStruct& xDir,
362 SMESH::DirStruct& yDir,
363 SMESH::DirStruct& zDir)
364 throw (SALOME::SALOME_Exception)
366 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( go );
367 if ( shape.IsNull() )
368 THROW_SALOME_CORBA_EXCEPTION( "Null shape", SALOME::BAD_PARAM );
371 ::StdMeshers_CartesianParameters3D::ComputeOptimalAxesDirs( shape, isOrthogonal, c );
384 //=======================================================================
385 //function : ComputeCoordinates
386 //purpose : Computes node coordinates by spacing functions
387 //=======================================================================
390 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
392 const SMESH::string_array& spaceFuns,
393 const SMESH::double_array& points,
394 const char* axisName )
395 throw (SALOME::SALOME_Exception)
397 vector<string> xFuns;
398 vector<double> xPoints, coords;
399 _array2vec( spaceFuns, xFuns, (const char*) );
400 _array2vec( points, xPoints, );
403 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
405 catch ( SALOME_Exception& S_ex ) {
406 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
408 SMESH::double_array_var res = new SMESH::double_array;
409 _vec2array( coords, res, );
414 //=============================================================================
418 //=============================================================================
420 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
422 MESSAGE( "StdMeshers_CartesianParameters3D_i::GetImpl" );
423 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
426 //================================================================================
428 * \brief Verify whether hypothesis supports given entity type
429 * \param type - dimension (see SMESH::Dimension enumeration)
430 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
432 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
434 //================================================================================
436 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
438 return type == SMESH::DIM_3D;