Back to index

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