Back to index

salome-smesh  6.5.0
StdMeshers_ProjectionSource2D_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_ProjectionSource2D_i.cxx
00025 //  Author : Edward AGAPOV
00026 //  Module : SMESH
00027 //
00028 #include "StdMeshers_ProjectionSource2D_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_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_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_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i" );
00056   myBaseImpl = new ::StdMeshers_ProjectionSource2D( theGenImpl->GetANewId(),
00057                                                     theStudyId,
00058                                                     theGenImpl );
00059 }
00060 
00061 //=============================================================================
00067 //=============================================================================
00068 
00069 StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i()
00070 {
00071   MESSAGE( "StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i" );
00072 }
00073 
00074 //=============================================================================
00078 //=============================================================================
00079 
00080 void StdMeshers_ProjectionSource2D_i::SetSourceFace(GEOM::GEOM_Object_ptr face)
00081   throw ( SALOME::SALOME_Exception )
00082 {
00083   ASSERT( myBaseImpl );
00084   try {
00085     this->GetImpl()->SetSourceFace( StdMeshers_ObjRefUlils::GeomObjectToShape( face ));
00086     CORBA::String_var entry = face->GetStudyEntry();
00087     myShapeEntries[ SRC_FACE ] = 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() << ".SetSourceFace( " << face << " )";
00094 }
00095 
00096 //=============================================================================
00100 //=============================================================================
00101 
00102 void StdMeshers_ProjectionSource2D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
00103   throw ( SALOME::SALOME_Exception )
00104 {
00105   ASSERT( myBaseImpl );
00106 
00107   ::SMESH_Mesh* mesh = 0;
00108 
00109   if ( !CORBA::is_nil( theMesh ))
00110   {
00111     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
00112     if ( !mesh_i )
00113       THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
00114     mesh = &mesh_i->GetImpl();
00115   }
00116 
00117   try {
00118     this->GetImpl()->SetSourceMesh ( mesh );
00119   }
00120   catch ( SALOME_Exception& S_ex ) {
00121     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00122   }
00123 
00124   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
00125 
00126   // Update Python script
00127   SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
00128 }
00129 
00130 //=============================================================================
00134 //=============================================================================
00135 
00136 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource2D_i::GetSourceMesh()
00137 {
00138   SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
00139   return mesh._retn();
00140 }
00141 
00142 //=============================================================================
00148 //=============================================================================
00149 
00150 void StdMeshers_ProjectionSource2D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
00151                                                            GEOM::GEOM_Object_ptr sourceVertex2,
00152                                                            GEOM::GEOM_Object_ptr targetVertex1,
00153                                                            GEOM::GEOM_Object_ptr targetVertex2)
00154   throw ( SALOME::SALOME_Exception )
00155 {
00156   ASSERT( myBaseImpl );
00157   try {
00158     TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
00159     TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
00160     TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
00161     TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
00162     this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
00163 
00164     myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
00165     myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
00166     myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
00167     myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
00168   }
00169   catch ( SALOME_Exception& S_ex ) {
00170     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
00171   }
00172   // Update Python script
00173   SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
00174                        << sourceVertex1 << ", "
00175                        << sourceVertex2 << ", "
00176                        << targetVertex1 << ", "
00177                        << targetVertex2 << " )";
00178 }
00179 
00180 //=============================================================================
00184 //=============================================================================
00185 
00186 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceFace()
00187 {
00188   ASSERT( myBaseImpl );
00189   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00190     ( myShapeEntries[ SRC_FACE ],
00191       this->GetImpl()->GetSourceFace() );
00192 }
00193 
00194 //=============================================================================
00199 //=============================================================================
00200 
00201 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceVertex(CORBA::Long i)
00202 {
00203   ASSERT( myBaseImpl );
00204   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00205     ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
00206       this->GetImpl()->GetSourceVertex((int) i ));
00207 }
00208 
00209 //=============================================================================
00214 //=============================================================================
00215 
00216 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetTargetVertex(CORBA::Long i)
00217 {
00218   ASSERT( myBaseImpl );
00219   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
00220     ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
00221       this->GetImpl()->GetTargetVertex( (int)i ));
00222 }
00223 
00224 //=============================================================================
00230 //=============================================================================
00231 
00232 ::StdMeshers_ProjectionSource2D* StdMeshers_ProjectionSource2D_i::GetImpl()
00233 {
00234   return ( ::StdMeshers_ProjectionSource2D* )myBaseImpl;
00235 }
00236 
00237 //================================================================================
00245 //================================================================================  
00246 CORBA::Boolean StdMeshers_ProjectionSource2D_i::IsDimSupported( SMESH::Dimension type )
00247 {
00248   return type == SMESH::DIM_2D;
00249 }
00250 
00251 //================================================================================
00256 //================================================================================
00257 
00258 char* StdMeshers_ProjectionSource2D_i::SaveTo()
00259 {
00260   ASSERT( myBaseImpl );
00261   std::ostringstream os;
00262 
00263   for ( int i = 0; i < NB_SHAPES; ++i )
00264     StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
00265   StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
00266 
00267   myBaseImpl->SaveTo( os );
00268 
00269   return CORBA::string_dup( os.str().c_str() );
00270 }
00271 
00272 //================================================================================
00277 //================================================================================
00278 
00279 void StdMeshers_ProjectionSource2D_i::LoadFrom( const char* theStream )
00280 {
00281   ASSERT( myBaseImpl );
00282   std::istringstream is( theStream );
00283 
00284   TopoDS_Shape shapes[ NB_SHAPES ];
00285   for ( int i = 0; i < NB_SHAPES; ++i )
00286     shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
00287   SMESH::SMESH_Mesh_var mesh = 
00288     StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
00289 
00290   ::SMESH_Mesh* meshImpl = 0;
00291 
00292   if ( !CORBA::is_nil( mesh ))
00293   {
00294     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
00295     if ( mesh_i )
00296       meshImpl = &mesh_i->GetImpl();
00297   }
00298 
00299   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
00300 
00301   GetImpl()->SetSourceMesh       ( meshImpl );
00302   GetImpl()->SetSourceFace       ( shapes[ SRC_FACE ] );
00303   GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
00304                                    shapes[ SRC_VERTEX2 ],
00305                                    shapes[ TGT_VERTEX1 ],
00306                                    shapes[ TGT_VERTEX2 ]);
00307   myBaseImpl->LoadFrom( is );
00308 
00309   std::istringstream str( theStream );
00310   for ( int i = 0; i < NB_SHAPES; ++i )
00311     str >> myShapeEntries[ i ];
00312 }
00313