Back to index

salome-smesh  6.5.0
StdMeshers_ProjectionSource1D_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 
00023 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
00024 //  File   : StdMeshers_ProjectionSource1D_i.cxx
00025 //  Author : Edward AGAPOV
00026 //  Module : SMESH
00027 //
00028 #include "StdMeshers_ProjectionSource1D_i.hxx"
00029 
00030 #include "SMESH_Gen_i.hxx"
00031 #include "SMESH_Gen.hxx"
00032 #include "SMESH_PythonDump.hxx"
00033 
00034 #include "Utils_CorbaException.hxx"
00035 #include "utilities.h"
00036 
00037 #include "StdMeshers_ObjRefUlils.hxx"
00038 
00039 using namespace std;
00040 
00041 //=============================================================================
00047 //=============================================================================
00048 
00049 StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
00050 ( PortableServer::POA_ptr thePOA,
00051   int                     theStudyId,
00052   ::SMESH_Gen*            theGenImpl ) : SALOME::GenericObj_i( thePOA ), 
00053                                          SMESH_Hypothesis_i( thePOA )
00054 {
00055   MESSAGE( "StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i" );
00056   myBaseImpl = new ::StdMeshers_ProjectionSource1D( theGenImpl->GetANewId(),
00057                                                     theStudyId,
00058                                                     theGenImpl );
00059 }
00060 
00061 //=============================================================================
00067 //=============================================================================
00068 
00069 StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i()
00070 {
00071   MESSAGE( "StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i" );
00072 }
00073 
00074 //=============================================================================
00078 //=============================================================================
00079 
00080 void StdMeshers_ProjectionSource1D_i::SetSourceEdge(GEOM::GEOM_Object_ptr edge)
00081   throw ( SALOME::SALOME_Exception )
00082 {
00083   ASSERT( myBaseImpl );
00084   try {
00085     this->GetImpl()->SetSourceEdge( StdMeshers_ObjRefUlils::GeomObjectToShape( edge ));
00086     CORBA::String_var entry = edge->GetStudyEntry();
00087     myShapeEntries[ SRC_EDGE ] = entry.in();
00088   }
00089   catch ( SALOME_Exception& S_ex ) {
00090     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00091   }
00092   // Update Python script
00093   SMESH::TPythonDump() << _this() << ".SetSourceEdge( " << edge << " )";
00094 }
00095 
00096 //=============================================================================
00101 //=============================================================================
00102 
00103 void StdMeshers_ProjectionSource1D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex,
00104                                                            GEOM::GEOM_Object_ptr targetVertex)
00105   throw ( SALOME::SALOME_Exception )
00106 {
00107   ASSERT( myBaseImpl );
00108   try {
00109     TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex );
00110     TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex );
00111     this->GetImpl()->SetVertexAssociation( v1, v2 );
00112 
00113     myShapeEntries[ SRC_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex );
00114     myShapeEntries[ TGT_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex );
00115   }
00116   catch ( SALOME_Exception& S_ex ) {
00117     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00118   }
00119   // Update Python script
00120   SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
00121                        << sourceVertex << ", " << targetVertex << " )";
00122 }
00123 
00124 //=============================================================================
00128 //=============================================================================
00129 
00130 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
00131   throw ( SALOME::SALOME_Exception )
00132 {
00133   ASSERT( myBaseImpl );
00134 
00135   ::SMESH_Mesh* mesh = 0;
00136 
00137   if ( !CORBA::is_nil( theMesh ))
00138   {
00139     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
00140     if ( !mesh_i )
00141       THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
00142     mesh = &mesh_i->GetImpl();
00143   }
00144 
00145   try {
00146     this->GetImpl()->SetSourceMesh ( mesh );
00147   }
00148   catch ( SALOME_Exception& S_ex ) {
00149     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00150   }
00151 
00152   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
00153 
00154   // Update Python script
00155   SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
00156 }
00157 
00158 //=============================================================================
00162 //=============================================================================
00163 
00164 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
00165 {
00166   SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
00167   return mesh._retn();
00168 }
00169 
00170 //=============================================================================
00174 //=============================================================================
00175 
00176 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
00177 {
00178   ASSERT( myBaseImpl );
00179   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00180     ( myShapeEntries[ SRC_EDGE ],
00181       this->GetImpl()->GetSourceEdge() );
00182 }
00183 
00184 //=============================================================================
00189 //=============================================================================
00190 
00191 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
00192 {
00193   ASSERT( myBaseImpl );
00194   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00195     ( myShapeEntries[ SRC_VERTEX ],
00196       this->GetImpl()->GetSourceVertex() );
00197 }
00198 
00199 //=============================================================================
00204 //=============================================================================
00205 
00206 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
00207 {
00208   ASSERT( myBaseImpl );
00209   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00210     ( myShapeEntries[ TGT_VERTEX ],
00211       this->GetImpl()->GetTargetVertex() );
00212 }
00213 
00214 //=============================================================================
00220 //=============================================================================
00221 
00222 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
00223 {
00224   return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
00225 }
00226 
00227 //================================================================================
00235 //================================================================================  
00236 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
00237 {
00238   return type == SMESH::DIM_1D;
00239 }
00240 
00241 //================================================================================
00246 //================================================================================
00247 
00248 char* StdMeshers_ProjectionSource1D_i::SaveTo()
00249 {
00250   ASSERT( myBaseImpl );
00251   std::ostringstream os;
00252 
00253   for ( int i = 0; i < NB_SHAPES; ++i )
00254     StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
00255   StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
00256 
00257   myBaseImpl->SaveTo( os );
00258 
00259   return CORBA::string_dup( os.str().c_str() );
00260 }
00261 
00262 //================================================================================
00267 //================================================================================
00268 
00269 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
00270 {
00271   ASSERT( myBaseImpl );
00272   std::istringstream is( theStream );
00273 
00274   TopoDS_Shape shapes[ NB_SHAPES ];
00275   for ( int i = 0; i < NB_SHAPES; ++i )
00276     shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
00277   SMESH::SMESH_Mesh_var mesh = 
00278     StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
00279 
00280   ::SMESH_Mesh* meshImpl = 0;
00281 
00282   if ( !CORBA::is_nil( mesh ))
00283   {
00284     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
00285     if ( mesh_i )
00286       meshImpl = &mesh_i->GetImpl();
00287   }
00288 
00289   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
00290   GetImpl()->SetSourceMesh       ( meshImpl );
00291   GetImpl()->SetSourceEdge       ( shapes[ SRC_EDGE ] );
00292   GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
00293                                    shapes[ TGT_VERTEX ]);
00294 
00295   myBaseImpl->LoadFrom( is );
00296 
00297   std::istringstream str( theStream );
00298   for ( int i = 0; i < NB_SHAPES; ++i )
00299     str >> myShapeEntries[ i ];
00300 }
00301