1 // Copyright (C) 2007-2024 CEA, EDF, 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,
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)
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)
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,
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,
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)
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 const double* oldCoords = GetImpl()->GetAxisDirs();
246 for ( int i = 0; i < 9 && isSame; ++i )
247 isSame = ( oldCoords[i] == coords[i] );
252 this->GetImpl()->SetAxisDirs(coords);
254 SMESH::TPythonDump() << _this() << ".SetAxesDirs( "
259 catch ( SALOME_Exception& S_ex ) {
260 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
264 //=======================================================================
265 //function : GetAxesDirs
266 //purpose : Returns direction of axes
267 //=======================================================================
269 void StdMeshers_CartesianParameters3D_i::GetAxesDirs(SMESH::DirStruct& xDir,
270 SMESH::DirStruct& yDir,
271 SMESH::DirStruct& zDir)
273 const double* coords = GetImpl()->GetAxisDirs();
274 xDir.PS.x = coords[0];
275 xDir.PS.y = coords[1];
276 xDir.PS.z = coords[2];
277 yDir.PS.x = coords[3];
278 yDir.PS.y = coords[4];
279 yDir.PS.z = coords[5];
280 zDir.PS.x = coords[6];
281 zDir.PS.y = coords[7];
282 zDir.PS.z = coords[8];
285 //=======================================================================
286 //function : SetFixedPoint
287 //purpose : * Set/unset a fixed point, at which a node will be created provided that grid
288 // * is defined by spacing in all directions
289 //=======================================================================
291 void StdMeshers_CartesianParameters3D_i::SetFixedPoint(const SMESH::PointStruct& ps,
292 CORBA::Boolean toUnset)
294 SMESH::PointStruct oldPS;
295 GetFixedPoint( oldPS );
296 if ( oldPS.x == ps.x && oldPS.y == ps.y && oldPS.z == ps.z )
299 double p[3] = { ps.x, ps.y, ps.z };
300 GetImpl()->SetFixedPoint( p, toUnset );
302 SMESH::TPythonDump() << _this() << ".SetFixedPoint( " << ps << ", " << toUnset << " )";
305 //=======================================================================
306 //function : GetFixedPoint
307 //purpose : Returns a fixed point
308 //=======================================================================
310 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetFixedPoint(SMESH::PointStruct& ps)
313 if ( GetImpl()->GetFixedPoint( p ) )
329 //=======================================================================
330 //function : SetToAddEdges
331 //purpose : Enables implementation of geometrical edges into the mesh.
332 //=======================================================================
334 void StdMeshers_CartesianParameters3D_i::SetToAddEdges(CORBA::Boolean toAdd)
336 GetImpl()->SetToAddEdges( toAdd );
337 SMESH::TPythonDump() << _this() << ".SetToAddEdges( " << toAdd << " )";
340 //=======================================================================
341 //function : GetToAddEdges
342 //purpose : Returns true if implementation of geometrical edges into the
344 //=======================================================================
346 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToAddEdges()
348 return GetImpl()->GetToAddEdges();
351 //=======================================================================
352 //function : SetToConsiderInternalFaces
353 //purpose : Enables treatment of geom faces, either shared by solids or internal.
354 //=======================================================================
356 void StdMeshers_CartesianParameters3D_i::SetToConsiderInternalFaces(CORBA::Boolean toTreat)
358 if ( GetToConsiderInternalFaces() == toTreat )
360 GetImpl()->SetToConsiderInternalFaces( toTreat );
361 SMESH::TPythonDump() << _this() << ".SetToConsiderInternalFaces( " << toTreat << " )";
364 //=======================================================================
365 //function : GetToConsiderInternalFaces
366 //purpose : Return true if treatment of internal geom faces is enabled
367 //=======================================================================
369 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToConsiderInternalFaces()
371 return GetImpl()->GetToConsiderInternalFaces();
374 //=======================================================================
375 //function : SetToUseThresholdForInternalFaces
376 //purpose : Enables applying size threshold to grid cells cut by internal geom faces.
377 //=======================================================================
379 void StdMeshers_CartesianParameters3D_i::SetToUseThresholdForInternalFaces(CORBA::Boolean toUse)
381 if ( GetToUseThresholdForInternalFaces() == toUse )
383 GetImpl()->SetToUseThresholdForInternalFaces( toUse );
384 SMESH::TPythonDump() << _this() << ".SetToUseThresholdForInternalFaces( " << toUse << " )";
387 //=======================================================================
388 //function : GetToUseThresholdForInternalFaces
389 //purpose : Return true if applying size threshold to grid cells cut by
390 // internal geom faces is enabled
391 //=======================================================================
393 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToUseThresholdForInternalFaces()
395 return GetImpl()->GetToUseThresholdForInternalFaces();
398 //=======================================================================
399 //function : SetToCreateFaces
400 //purpose : Enables creation of mesh faces.
401 //=======================================================================
403 void StdMeshers_CartesianParameters3D_i::SetToCreateFaces(CORBA::Boolean toCreate)
405 if ( GetToCreateFaces() == toCreate )
407 GetImpl()->SetToCreateFaces( toCreate );
408 SMESH::TPythonDump() << _this() << ".SetToCreateFaces( " << toCreate << " )";
411 //=======================================================================
412 //function : GetToCreateFaces
413 //purpose : Check if creation of mesh faces enabled
414 //=======================================================================
416 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToCreateFaces()
418 return GetImpl()->GetToCreateFaces();
422 //=======================================================================
423 //function : SetToUseQuanta
424 //purpose : Enables use of quanta value.
425 //=======================================================================
427 void StdMeshers_CartesianParameters3D_i::SetToUseQuanta(CORBA::Boolean toUseQuanta)
429 if ( GetToUseQuanta() == toUseQuanta )
431 GetImpl()->SetToUseQuanta( toUseQuanta );
432 SMESH::TPythonDump() << _this() << ".SetToUseQuanta( " << toUseQuanta << " )";
435 //=======================================================================
436 //function : GetToUseQuanta
437 //purpose : Check the value of toUseQuanta option
438 //=======================================================================
440 CORBA::Boolean StdMeshers_CartesianParameters3D_i::GetToUseQuanta()
442 return GetImpl()->GetToUseQuanta();
445 //=============================================================================
449 //=============================================================================
451 void StdMeshers_CartesianParameters3D_i::SetQuanta(CORBA::Double quanta)
454 ASSERT( myBaseImpl );
456 this->GetImpl()->SetQuanta(quanta);
458 catch ( SALOME_Exception& S_ex ) {
459 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
462 if ( GetToUseQuanta() )
463 // Update Python script
464 SMESH::TPythonDump() << _this() << ".SetQuanta( " << SMESH::TVar(quanta) << " )";
467 //=============================================================================
471 //=============================================================================
473 CORBA::Double StdMeshers_CartesianParameters3D_i::GetQuanta()
475 return this->GetImpl()->GetQuanta();
478 //=======================================================================
479 //function : IsGridBySpacing
480 //purpose : Return true if the grid is defined by spacing functions and
481 // not by node coordinates
482 //=======================================================================
484 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
486 return this->GetImpl()->IsGridBySpacing(axis);
489 //=======================================================================
490 //function : ComputeOptimalAxesDirs
491 //purpose : Returns axes at which number of hexahedra is maximal
492 //=======================================================================
494 void StdMeshers_CartesianParameters3D_i::
495 ComputeOptimalAxesDirs(GEOM::GEOM_Object_ptr go,
496 CORBA::Boolean isOrthogonal,
497 SMESH::DirStruct& xDir,
498 SMESH::DirStruct& yDir,
499 SMESH::DirStruct& zDir)
502 TopoDS_Shape shape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( go );
503 if ( shape.IsNull() )
504 THROW_SALOME_CORBA_EXCEPTION( "Null shape", SALOME::BAD_PARAM );
507 ::StdMeshers_CartesianParameters3D::ComputeOptimalAxesDirs( shape, isOrthogonal, c );
520 //=======================================================================
521 //function : ComputeCoordinates
522 //purpose : Computes node coordinates by spacing functions
523 //=======================================================================
526 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double x0,
528 const SMESH::string_array& spaceFuns,
529 const SMESH::double_array& points,
530 const char* axisName )
533 std::vector<std::string> xFuns;
534 std::vector<double> xPoints, coords;
535 _array2vec( spaceFuns, xFuns, (const char*) );
536 _array2vec( points, xPoints, );
539 this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
541 catch ( SALOME_Exception& S_ex ) {
542 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
544 SMESH::double_array_var res = new SMESH::double_array;
545 _vec2array( coords, res, );
550 //=============================================================================
554 //=============================================================================
556 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
558 return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
561 //================================================================================
563 * \brief Verify whether hypothesis supports given entity type
564 * \param type - dimension (see SMESH::Dimension enumeration)
565 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
567 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
569 //================================================================================
571 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
573 return type == SMESH::DIM_3D;