1 // Copyright (C) 2007-2011 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
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
24 // File : StdMeshers_ProjectionSource1D_i.cxx
25 // 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 ));
86 CORBA::String_var entry = edge->GetStudyEntry();
87 myShapeEntries[ SRC_EDGE ] = entry.in();
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 CORBA::String_var entry;
114 entry = sourceVertex->GetStudyEntry();
115 myShapeEntries[ SRC_VERTEX ] = entry.in();
116 entry = targetVertex->GetStudyEntry();
117 myShapeEntries[ TGT_VERTEX ] = entry.in();
119 catch ( SALOME_Exception& S_ex ) {
120 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
122 // Update Python script
123 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
124 << sourceVertex << ", " << targetVertex << " )";
127 //=============================================================================
129 * Sets source <mesh> to take a mesh pattern from
131 //=============================================================================
133 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
134 throw ( SALOME::SALOME_Exception )
136 ASSERT( myBaseImpl );
138 ::SMESH_Mesh* mesh = 0;
140 if ( !CORBA::is_nil( theMesh ))
142 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
144 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
145 mesh = &mesh_i->GetImpl();
149 this->GetImpl()->SetSourceMesh ( mesh );
151 catch ( SALOME_Exception& S_ex ) {
152 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
155 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
157 // Update Python script
158 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
161 //=============================================================================
165 //=============================================================================
167 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
169 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
173 //=============================================================================
175 * Returns the source edge or a group containing edge
177 //=============================================================================
179 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
181 ASSERT( myBaseImpl );
182 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
183 ( myShapeEntries[ SRC_EDGE ],
184 this->GetImpl()->GetSourceEdge() );
187 //=============================================================================
189 * Returns the vertex associated with the target vertex.
190 * Result may be nil if association not set
192 //=============================================================================
194 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
196 ASSERT( myBaseImpl );
197 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
198 ( myShapeEntries[ SRC_VERTEX ],
199 this->GetImpl()->GetSourceVertex() );
202 //=============================================================================
204 * Returns the vertex associated with the source vertex.
205 * Result may be nil if association not set
207 //=============================================================================
209 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
211 ASSERT( myBaseImpl );
212 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
213 ( myShapeEntries[ TGT_VERTEX ],
214 this->GetImpl()->GetTargetVertex() );
217 //=============================================================================
219 * StdMeshers_ProjectionSource1D_i::GetImpl
223 //=============================================================================
225 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
227 return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
230 //================================================================================
232 * \brief Verify whether hypothesis supports given entity type
233 * \param type - dimension (see SMESH::Dimension enumeration)
234 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
236 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
238 //================================================================================
239 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
241 return type == SMESH::DIM_1D;
244 //================================================================================
246 * \brief Write parameters in a string
247 * \retval char* - resulting string
249 //================================================================================
251 char* StdMeshers_ProjectionSource1D_i::SaveTo()
253 ASSERT( myBaseImpl );
254 std::ostringstream os;
256 for ( int i = 0; i < NB_SHAPES; ++i )
257 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
258 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
260 myBaseImpl->SaveTo( os );
262 return CORBA::string_dup( os.str().c_str() );
265 //================================================================================
267 * \brief Retrieve parameters from the string
268 * \param theStream - the input string
270 //================================================================================
272 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
274 ASSERT( myBaseImpl );
275 std::istringstream is( theStream );
277 TopoDS_Shape shapes[ NB_SHAPES ];
278 for ( int i = 0; i < NB_SHAPES; ++i )
279 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
280 SMESH::SMESH_Mesh_var mesh =
281 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
283 ::SMESH_Mesh* meshImpl = 0;
285 if ( !CORBA::is_nil( mesh ))
287 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
289 meshImpl = &mesh_i->GetImpl();
292 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
293 GetImpl()->SetSourceMesh ( meshImpl );
294 GetImpl()->SetSourceEdge ( shapes[ SRC_EDGE ] );
295 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
296 shapes[ TGT_VERTEX ]);
298 myBaseImpl->LoadFrom( is );
300 std::istringstream str( theStream );
301 for ( int i = 0; i < NB_SHAPES; ++i )
302 str >> myShapeEntries[ i ];