1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, 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.
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 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
23 // File : StdMeshers_ProjectionSource1D_i.cxx
24 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource1D_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
37 #include "StdMeshers_ObjRefUlils.hxx"
41 //=============================================================================
43 * StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
50 ( PortableServer::POA_ptr thePOA,
52 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
53 SMESH_Hypothesis_i( thePOA )
55 MESSAGE( "StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i" );
56 myBaseImpl = new ::StdMeshers_ProjectionSource1D( theGenImpl->GetANewId(),
61 //=============================================================================
63 * StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i
67 //=============================================================================
69 StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i()
71 MESSAGE( "StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i" );
74 //=============================================================================
76 * Sets source <edge> or a group containing edges to take a mesh pattern from
78 //=============================================================================
80 void StdMeshers_ProjectionSource1D_i::SetSourceEdge(GEOM::GEOM_Object_ptr edge)
81 throw ( SALOME::SALOME_Exception )
85 this->GetImpl()->SetSourceEdge( StdMeshers_ObjRefUlils::GeomObjectToShape( edge ));
87 catch ( SALOME_Exception& S_ex ) {
88 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
90 // Update Python script
91 SMESH::TPythonDump() << _this() << ".SetSourceEdge( " << edge << " )";
94 //=============================================================================
96 * Sets vertex association between the source edge and the target one.
97 * This parameter is optional
99 //=============================================================================
101 void StdMeshers_ProjectionSource1D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex,
102 GEOM::GEOM_Object_ptr targetVertex)
103 throw ( SALOME::SALOME_Exception )
105 ASSERT( myBaseImpl );
107 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex );
108 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex );
109 this->GetImpl()->SetVertexAssociation( v1, v2 );
111 catch ( SALOME_Exception& S_ex ) {
112 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
114 // Update Python script
115 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
116 << sourceVertex << ", " << targetVertex << " )";
119 //=============================================================================
121 * Sets source <mesh> to take a mesh pattern from
123 //=============================================================================
125 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
126 throw ( SALOME::SALOME_Exception )
128 ASSERT( myBaseImpl );
130 ::SMESH_Mesh* mesh = 0;
132 if ( !CORBA::is_nil( theMesh ))
134 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
136 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
137 mesh = &mesh_i->GetImpl();
141 this->GetImpl()->SetSourceMesh ( mesh );
143 catch ( SALOME_Exception& S_ex ) {
144 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
147 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
149 // Update Python script
150 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
153 //=============================================================================
157 //=============================================================================
159 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
161 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
165 //=============================================================================
167 * Returns the source edge or a group containing edge
169 //=============================================================================
171 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
173 ASSERT( myBaseImpl );
174 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceEdge() );
177 //=============================================================================
179 * Returns the vertex associated with the target vertex.
180 * Result may be nil if association not set
182 //=============================================================================
184 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
186 ASSERT( myBaseImpl );
187 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceVertex() );
190 //=============================================================================
192 * Returns the vertex associated with the source vertex.
193 * Result may be nil if association not set
195 //=============================================================================
197 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
199 ASSERT( myBaseImpl );
200 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetTargetVertex() );
203 //=============================================================================
205 * StdMeshers_ProjectionSource1D_i::GetImpl
209 //=============================================================================
211 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
213 return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
216 //================================================================================
218 * \brief Verify whether hypothesis supports given entity type
219 * \param type - dimension (see SMESH::Dimension enumeration)
220 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
222 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
224 //================================================================================
225 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
227 return type == SMESH::DIM_1D;
230 //================================================================================
232 * \brief Write parameters in a string
233 * \retval char* - resulting string
235 //================================================================================
237 char* StdMeshers_ProjectionSource1D_i::SaveTo()
239 ASSERT( myBaseImpl );
240 std::ostringstream os;
242 TopoDS_Shape s1, s2, s3;
243 GetImpl()->GetStoreParams( s1, s2, s3 );
245 StdMeshers_ObjRefUlils::SaveToStream( s1, os );
246 StdMeshers_ObjRefUlils::SaveToStream( s2, os );
247 StdMeshers_ObjRefUlils::SaveToStream( s3, os );
248 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
250 myBaseImpl->SaveTo( os );
252 return CORBA::string_dup( os.str().c_str() );
255 //================================================================================
257 * \brief Retrieve parameters from the string
258 * \param theStream - the input string
260 //================================================================================
262 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
264 ASSERT( myBaseImpl );
265 std::istringstream is( theStream );
267 TopoDS_Shape s1 = StdMeshers_ObjRefUlils::LoadFromStream( is );
268 TopoDS_Shape s2 = StdMeshers_ObjRefUlils::LoadFromStream( is );
269 TopoDS_Shape s3 = StdMeshers_ObjRefUlils::LoadFromStream( is );
270 SMESH::SMESH_Mesh_var mesh =
271 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
273 ::SMESH_Mesh* meshImpl = 0;
275 if ( !CORBA::is_nil( mesh ))
277 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
279 meshImpl = &mesh_i->GetImpl();
282 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
283 GetImpl()->RestoreParams( s1, s2, s3, meshImpl );
285 myBaseImpl->LoadFrom( is );