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"
43 //=============================================================================
45 * StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
49 //=============================================================================
51 StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i
52 ( PortableServer::POA_ptr thePOA,
54 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
55 SMESH_Hypothesis_i( thePOA )
57 MESSAGE( "StdMeshers_ProjectionSource1D_i::StdMeshers_ProjectionSource1D_i" );
58 myBaseImpl = new ::StdMeshers_ProjectionSource1D( theGenImpl->GetANewId(),
63 //=============================================================================
65 * StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i
69 //=============================================================================
71 StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i()
73 MESSAGE( "StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i" );
76 //=============================================================================
78 * Sets source <edge> or a group containing edges to take a mesh pattern from
80 //=============================================================================
82 void StdMeshers_ProjectionSource1D_i::SetSourceEdge(GEOM::GEOM_Object_ptr edge)
83 throw ( SALOME::SALOME_Exception )
87 this->GetImpl()->SetSourceEdge( StdMeshers_ObjRefUlils::GeomObjectToShape( edge ));
89 catch ( SALOME_Exception& S_ex ) {
90 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
92 // Update Python script
93 SMESH::TPythonDump() << _this() << ".SetSourceEdge( " << edge << " )";
96 //=============================================================================
98 * Sets vertex association between the source edge and the target one.
99 * This parameter is optional
101 //=============================================================================
103 void StdMeshers_ProjectionSource1D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex,
104 GEOM::GEOM_Object_ptr targetVertex)
105 throw ( SALOME::SALOME_Exception )
107 ASSERT( myBaseImpl );
109 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex );
110 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex );
111 this->GetImpl()->SetVertexAssociation( v1, v2 );
113 catch ( SALOME_Exception& S_ex ) {
114 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
116 // Update Python script
117 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
118 << sourceVertex << ", " << targetVertex << " )";
121 //=============================================================================
123 * Sets source <mesh> to take a mesh pattern from
125 //=============================================================================
127 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
128 throw ( SALOME::SALOME_Exception )
130 ASSERT( myBaseImpl );
132 ::SMESH_Mesh* mesh = 0;
134 if ( !CORBA::is_nil( theMesh ))
136 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
138 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
139 mesh = &mesh_i->GetImpl();
143 this->GetImpl()->SetSourceMesh ( mesh );
145 catch ( SALOME_Exception& S_ex ) {
146 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
149 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
151 // Update Python script
152 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
155 //=============================================================================
159 //=============================================================================
161 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
163 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
167 //=============================================================================
169 * Returns the source edge or a group containing edge
171 //=============================================================================
173 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
175 ASSERT( myBaseImpl );
176 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceEdge() );
179 //=============================================================================
181 * Returns the vertex associated with the target vertex.
182 * Result may be nil if association not set
184 //=============================================================================
186 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
188 ASSERT( myBaseImpl );
189 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceVertex() );
192 //=============================================================================
194 * Returns the vertex associated with the source vertex.
195 * Result may be nil if association not set
197 //=============================================================================
199 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
201 ASSERT( myBaseImpl );
202 return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetTargetVertex() );
205 //=============================================================================
207 * StdMeshers_ProjectionSource1D_i::GetImpl
211 //=============================================================================
213 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
215 return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
218 //================================================================================
220 * \brief Verify whether hypothesis supports given entity type
221 * \param type - dimension (see SMESH::Dimension enumeration)
222 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
224 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
226 //================================================================================
227 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
229 return type == SMESH::DIM_1D;
232 //================================================================================
234 * \brief Write parameters in a string
235 * \retval char* - resulting string
237 //================================================================================
239 char* StdMeshers_ProjectionSource1D_i::SaveTo()
241 ASSERT( myBaseImpl );
242 std::ostringstream os;
244 TopoDS_Shape s1, s2, s3;
245 GetImpl()->GetStoreParams( s1, s2, s3 );
247 StdMeshers_ObjRefUlils::SaveToStream( s1, os );
248 StdMeshers_ObjRefUlils::SaveToStream( s2, os );
249 StdMeshers_ObjRefUlils::SaveToStream( s3, os );
250 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
252 myBaseImpl->SaveTo( os );
254 return CORBA::string_dup( os.str().c_str() );
257 //================================================================================
259 * \brief Retrieve parameters from the string
260 * \param theStream - the input string
262 //================================================================================
264 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
266 ASSERT( myBaseImpl );
267 std::istringstream is( theStream );
269 TopoDS_Shape s1 = StdMeshers_ObjRefUlils::LoadFromStream( is );
270 TopoDS_Shape s2 = StdMeshers_ObjRefUlils::LoadFromStream( is );
271 TopoDS_Shape s3 = StdMeshers_ObjRefUlils::LoadFromStream( is );
272 SMESH::SMESH_Mesh_var mesh =
273 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
275 ::SMESH_Mesh* meshImpl = 0;
277 if ( !CORBA::is_nil( mesh ))
279 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
281 meshImpl = &mesh_i->GetImpl();
284 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
285 GetImpl()->RestoreParams( s1, s2, s3, meshImpl );
287 myBaseImpl->LoadFrom( is );