Back to index

salome-smesh  6.5.0
StdMeshers_CartesianParameters3D_i.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  File   : StdMeshers_CartesianParameters3D_i.cxx
00023 //  Module : SMESH
00024 //
00025 #include "StdMeshers_CartesianParameters3D_i.hxx"
00026 
00027 #include "StdMeshers_CartesianParameters3D.hxx"
00028 #include "SMESH_Gen_i.hxx"
00029 #include "SMESH_Gen.hxx"
00030 #include "SMESH_PythonDump.hxx"
00031 
00032 #include "Utils_CorbaException.hxx"
00033 #include "utilities.h"
00034 
00035 #define _vec2array( v, a,conversion )           \
00036   {                                             \
00037     a->length( v.size() );                      \
00038     for ( size_t i = 0; i < v.size(); ++i )     \
00039       a[i] = conversion( v[i] );                \
00040   }
00041 #define _array2vec(a,v,conversion)              \
00042   {                                             \
00043     v.resize( a.length() );                     \
00044     for ( size_t i = 0; i < v.size(); ++i )     \
00045       v[i] = conversion ( a[i] );               \
00046   }
00047 namespace
00048 {
00049   const char* _string2chars(const std::string& s ) { return s.c_str(); }
00050 }
00051 
00052 //=============================================================================
00058 //=============================================================================
00059 
00060 StdMeshers_CartesianParameters3D_i::
00061 StdMeshers_CartesianParameters3D_i( PortableServer::POA_ptr thePOA,
00062                                     int                     theStudyId,
00063                                     ::SMESH_Gen*            theGenImpl )
00064   : SALOME::GenericObj_i( thePOA ), 
00065     SMESH_Hypothesis_i( thePOA )
00066 {
00067   MESSAGE( "StdMeshers_CartesianParameters3D_i::StdMeshers_CartesianParameters3D_i" );
00068   myBaseImpl = new ::StdMeshers_CartesianParameters3D( theGenImpl->GetANewId(),
00069                                                        theStudyId,
00070                                                        theGenImpl );
00071 }
00072 
00073 //=============================================================================
00079 //=============================================================================
00080 
00081 StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i()
00082 {
00083   MESSAGE( "StdMeshers_CartesianParameters3D_i::~StdMeshers_CartesianParameters3D_i" );
00084 }
00085 
00086 //=============================================================================
00090 //=============================================================================
00091 
00092 void StdMeshers_CartesianParameters3D_i::SetGrid(const SMESH::double_array& coords,
00093                                                  CORBA::Short               axis)
00094   throw (SALOME::SALOME_Exception)
00095 {
00096   std::vector<double> coordVec;//, yCoords, zCoords;
00097   _array2vec( coords, coordVec, );
00098 
00099   ASSERT( myBaseImpl );
00100   try {
00101     this->GetImpl()->SetGrid( coordVec, axis );
00102   }
00103   catch ( SALOME_Exception& S_ex ) {
00104     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00105   }
00106 
00107   // Update Python script
00108   SMESH::TPythonDump() << _this() << ".SetGrid( " << coords << ", " << axis << " )";
00109 }
00110 
00111 //=============================================================================
00115 //=============================================================================
00116 
00117 SMESH::double_array* StdMeshers_CartesianParameters3D_i::GetGrid(CORBA::Short axis)
00118   throw (SALOME::SALOME_Exception)
00119 {
00120   std::vector<double> coordVec;
00121   ASSERT( myBaseImpl );
00122   try {
00123     this->GetImpl()->GetGrid(coordVec, axis);
00124   }
00125   catch ( SALOME_Exception& S_ex ) {
00126     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00127   }
00128 
00129   SMESH::double_array_var coords = new SMESH::double_array();
00130   _vec2array( coordVec, coords, );
00131 
00132   return coords._retn();
00133 }
00134 
00135 //=============================================================================
00139 //=============================================================================
00140 
00141 void StdMeshers_CartesianParameters3D_i::SetSizeThreshold(CORBA::Double threshold)
00142   throw (SALOME::SALOME_Exception)
00143 {
00144   ASSERT( myBaseImpl );
00145   try {
00146     this->GetImpl()->SetSizeThreshold(threshold);
00147   }
00148   catch ( SALOME_Exception& S_ex ) {
00149     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00150   }
00151 
00152   // Update Python script
00153   SMESH::TPythonDump() << _this() << ".SetSizeThreshold( " << SMESH::TVar(threshold) << " )";
00154 }
00155 
00156 //=============================================================================
00160 //=============================================================================
00161 
00162 CORBA::Double StdMeshers_CartesianParameters3D_i::GetSizeThreshold()
00163 {
00164   return this->GetImpl()->GetSizeThreshold();
00165 }
00166 
00167 //=======================================================================
00168 //function : SetGridSpacing
00169 //\brief Set grid spacing along the three axes
00170 // \param spaceFunctions - functions defining spacing values at given point on axis
00171 // \param internalPoints - points dividing a grid into parts along each direction
00172 // Parameter t of spaceFunction f(t) is a position [0,1] withing bounding box of
00173 // the shape to mesh or withing an interval defined by internal points
00174 //=======================================================================
00175 
00176 void StdMeshers_CartesianParameters3D_i::SetGridSpacing(const SMESH::string_array& spaceFunctions,
00177                                                         const SMESH::double_array& internalPoints,
00178                                                         CORBA::Short               axis)
00179   throw (SALOME::SALOME_Exception)
00180 {
00181   vector<string> funVec;
00182   vector<double> pointVec;
00183   _array2vec( spaceFunctions, funVec, (const char*) );
00184   _array2vec( internalPoints, pointVec, );
00185 
00186   ASSERT( myBaseImpl );
00187   try {
00188     this->GetImpl()->SetGridSpacing( funVec, pointVec, axis );
00189   }
00190   catch ( SALOME_Exception& S_ex ) {
00191     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00192   }
00193 
00194   // Update Python script
00195   SMESH::TPythonDump() << _this() << ".SetGridSpacing( "
00196                        << spaceFunctions << ", "
00197                        << internalPoints << ", "
00198                        << axis << " )";
00199 }
00200 
00201 //=======================================================================
00202 //function : GetGridSpacing
00203 //=======================================================================
00204 
00205 void StdMeshers_CartesianParameters3D_i::GetGridSpacing(SMESH::string_array_out xSpaceFunctions,
00206                                                         SMESH::double_array_out xInternalPoints,
00207                                                         CORBA::Short            axis)
00208   throw (SALOME::SALOME_Exception)
00209 {
00210   ASSERT( myBaseImpl );
00211   try {
00212     vector<string> funVec;
00213     vector<double> pointVec;
00214     this->GetImpl()->GetGridSpacing( funVec, pointVec, axis );
00215 
00216     xSpaceFunctions = new SMESH::string_array();
00217     xInternalPoints = new SMESH::double_array();
00218 
00219     _vec2array( funVec, xSpaceFunctions, _string2chars );
00220     _vec2array( pointVec, xInternalPoints, );
00221   }
00222   catch ( SALOME_Exception& S_ex ) {
00223     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00224   }
00225 }
00226 
00227 //=======================================================================
00228 //function : IsGridBySpacing
00229 //purpose  : Return true if the grid is defined by spacing functions and 
00230 //           not by node coordinates
00231 //=======================================================================
00232 
00233 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsGridBySpacing(CORBA::Short axis)
00234 {
00235   return this->GetImpl()->IsGridBySpacing(axis);
00236 }
00237 
00238 //=======================================================================
00239 //function : ComputeCoordinates
00240 //purpose  : Computes node coordinates by spacing functions
00241 //=======================================================================
00242 
00243 SMESH::double_array*
00244 StdMeshers_CartesianParameters3D_i::ComputeCoordinates(CORBA::Double              x0,
00245                                                        CORBA::Double              x1,
00246                                                        const SMESH::string_array& spaceFuns,
00247                                                        const SMESH::double_array& points,
00248                                                        const char*                axisName )
00249     throw (SALOME::SALOME_Exception)
00250 {
00251   vector<string> xFuns;
00252   vector<double> xPoints, coords;
00253   _array2vec( spaceFuns, xFuns, (const char*) );
00254   _array2vec( points, xPoints, );
00255   
00256   try {
00257     this->GetImpl()->ComputeCoordinates( x0, x1, xFuns, xPoints, coords, axisName );
00258   }
00259   catch ( SALOME_Exception& S_ex ) {
00260     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00261   }
00262   SMESH::double_array_var res = new SMESH::double_array;
00263   _vec2array( coords, res,  );
00264 
00265   return res._retn();
00266 }
00267 
00268 //=============================================================================
00272 //=============================================================================
00273 
00274 ::StdMeshers_CartesianParameters3D* StdMeshers_CartesianParameters3D_i::GetImpl()
00275 {
00276   MESSAGE( "StdMeshers_CartesianParameters3D_i::GetImpl" );
00277   return ( ::StdMeshers_CartesianParameters3D* )myBaseImpl;
00278 }
00279 
00280 //================================================================================
00288 //================================================================================  
00289 
00290 CORBA::Boolean StdMeshers_CartesianParameters3D_i::IsDimSupported( SMESH::Dimension type )
00291 {
00292   return type == SMESH::DIM_3D;
00293 }