1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 myBaseImpl = new ::StdMeshers_ProjectionSource1D( theGenImpl->GetANewId(),
60 //=============================================================================
62 * StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i
66 //=============================================================================
68 StdMeshers_ProjectionSource1D_i::~StdMeshers_ProjectionSource1D_i()
72 //=============================================================================
74 * Sets source <edge> or a group containing edges to take a mesh pattern from
76 //=============================================================================
78 void StdMeshers_ProjectionSource1D_i::SetSourceEdge(GEOM::GEOM_Object_ptr edge)
79 throw ( SALOME::SALOME_Exception )
83 this->GetImpl()->SetSourceEdge( StdMeshers_ObjRefUlils::GeomObjectToShape( edge ));
84 CORBA::String_var entry = edge->GetStudyEntry();
85 myShapeEntries[ SRC_EDGE ] = entry.in();
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 myShapeEntries[ SRC_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex );
112 myShapeEntries[ TGT_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex );
114 catch ( SALOME_Exception& S_ex ) {
115 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
117 // Update Python script
118 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
119 << sourceVertex << ", " << targetVertex << " )";
122 //=============================================================================
124 * Sets source <mesh> to take a mesh pattern from
126 //=============================================================================
128 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
129 throw ( SALOME::SALOME_Exception )
131 ASSERT( myBaseImpl );
133 ::SMESH_Mesh* mesh = 0;
135 if ( !CORBA::is_nil( theMesh ))
137 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
139 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
140 mesh = &mesh_i->GetImpl();
144 this->GetImpl()->SetSourceMesh ( mesh );
146 catch ( SALOME_Exception& S_ex ) {
147 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
150 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
152 // Update Python script
153 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
156 //=============================================================================
160 //=============================================================================
162 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
164 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
168 //=============================================================================
170 * Returns the source edge or a group containing edge
172 //=============================================================================
174 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
176 ASSERT( myBaseImpl );
177 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
178 ( myShapeEntries[ SRC_EDGE ],
179 this->GetImpl()->GetSourceEdge() );
182 //=============================================================================
184 * Returns the vertex associated with the target vertex.
185 * Result may be nil if association not set
187 //=============================================================================
189 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
191 ASSERT( myBaseImpl );
192 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
193 ( myShapeEntries[ SRC_VERTEX ],
194 this->GetImpl()->GetSourceVertex() );
197 //=============================================================================
199 * Returns the vertex associated with the source vertex.
200 * Result may be nil if association not set
202 //=============================================================================
204 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
206 ASSERT( myBaseImpl );
207 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
208 ( myShapeEntries[ TGT_VERTEX ],
209 this->GetImpl()->GetTargetVertex() );
212 //=============================================================================
214 * StdMeshers_ProjectionSource1D_i::GetImpl
218 //=============================================================================
220 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
222 return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
225 //================================================================================
227 * \brief Verify whether hypothesis supports given entity type
228 * \param type - dimension (see SMESH::Dimension enumeration)
229 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
231 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
233 //================================================================================
234 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
236 return type == SMESH::DIM_1D;
239 //================================================================================
241 * \brief Write parameters in a string
242 * \retval char* - resulting string
244 //================================================================================
246 char* StdMeshers_ProjectionSource1D_i::SaveTo()
248 ASSERT( myBaseImpl );
249 std::ostringstream os;
251 for ( int i = 0; i < NB_SHAPES; ++i )
252 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
253 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
255 myBaseImpl->SaveTo( os );
257 return CORBA::string_dup( os.str().c_str() );
260 //================================================================================
262 * \brief Retrieve parameters from the string
263 * \param theStream - the input string
265 //================================================================================
267 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
269 ASSERT( myBaseImpl );
270 std::istringstream is( theStream );
272 TopoDS_Shape shapes[ NB_SHAPES ];
273 for ( int i = 0; i < NB_SHAPES; ++i )
274 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
275 SMESH::SMESH_Mesh_var mesh =
276 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
278 ::SMESH_Mesh* meshImpl = 0;
280 if ( !CORBA::is_nil( mesh ))
282 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
284 meshImpl = &mesh_i->GetImpl();
287 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
289 GetImpl()->SetSourceMesh ( meshImpl );
290 GetImpl()->SetSourceEdge ( shapes[ SRC_EDGE ] );
291 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
292 shapes[ TGT_VERTEX ]);
296 myBaseImpl->LoadFrom( is );
298 std::istringstream str( theStream );
299 for ( int i = 0; i < NB_SHAPES; ++i )
300 str >> myShapeEntries[ i ];