1 // Copyright (C) 2007-2012 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_ProjectionSource2D_i.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource2D_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_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
50 ( PortableServer::POA_ptr thePOA,
52 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
53 SMESH_Hypothesis_i( thePOA )
55 MESSAGE( "StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i" );
56 myBaseImpl = new ::StdMeshers_ProjectionSource2D( theGenImpl->GetANewId(),
61 //=============================================================================
63 * StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i
67 //=============================================================================
69 StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i()
71 MESSAGE( "StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i" );
74 //=============================================================================
76 * Sets a source <face> to take a mesh pattern from
78 //=============================================================================
80 void StdMeshers_ProjectionSource2D_i::SetSourceFace(GEOM::GEOM_Object_ptr face)
81 throw ( SALOME::SALOME_Exception )
85 this->GetImpl()->SetSourceFace( StdMeshers_ObjRefUlils::GeomObjectToShape( face ));
86 CORBA::String_var entry = face->GetStudyEntry();
87 myShapeEntries[ SRC_FACE ] = 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() << ".SetSourceFace( " << face << " )";
96 //=============================================================================
98 * Sets source <mesh> to take a mesh pattern from
100 //=============================================================================
102 void StdMeshers_ProjectionSource2D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
103 throw ( SALOME::SALOME_Exception )
105 ASSERT( myBaseImpl );
107 ::SMESH_Mesh* mesh = 0;
109 if ( !CORBA::is_nil( theMesh ))
111 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
113 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
114 mesh = &mesh_i->GetImpl();
118 this->GetImpl()->SetSourceMesh ( mesh );
120 catch ( SALOME_Exception& S_ex ) {
121 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
124 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
126 // Update Python script
127 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
130 //=============================================================================
134 //=============================================================================
136 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource2D_i::GetSourceMesh()
138 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
142 //=============================================================================
144 * Sets vertex association between the source face and the target one.
145 * This parameter is optional.
146 * Two vertices must belong to one edge of a face
148 //=============================================================================
150 void StdMeshers_ProjectionSource2D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
151 GEOM::GEOM_Object_ptr sourceVertex2,
152 GEOM::GEOM_Object_ptr targetVertex1,
153 GEOM::GEOM_Object_ptr targetVertex2)
154 throw ( SALOME::SALOME_Exception )
156 ASSERT( myBaseImpl );
158 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
159 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
160 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
161 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
162 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
164 myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
165 myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
166 myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
167 myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
169 catch ( SALOME_Exception& S_ex ) {
170 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
172 // Update Python script
173 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
174 << sourceVertex1 << ", "
175 << sourceVertex2 << ", "
176 << targetVertex1 << ", "
177 << targetVertex2 << " )";
180 //=============================================================================
182 * Returns the source face
184 //=============================================================================
186 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceFace()
188 ASSERT( myBaseImpl );
189 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
190 ( myShapeEntries[ SRC_FACE ],
191 this->GetImpl()->GetSourceFace() );
194 //=============================================================================
196 * Returns the vertex associated with the target vertex.
197 * Result may be nil if association not set
199 //=============================================================================
201 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceVertex(CORBA::Long i)
203 ASSERT( myBaseImpl );
204 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
205 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
206 this->GetImpl()->GetSourceVertex((int) i ));
209 //=============================================================================
211 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
212 * Result may be nil if association not set.
214 //=============================================================================
216 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetTargetVertex(CORBA::Long i)
218 ASSERT( myBaseImpl );
219 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
220 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
221 this->GetImpl()->GetTargetVertex( (int)i ));
224 //=============================================================================
226 * StdMeshers_ProjectionSource2D_i::GetImpl
230 //=============================================================================
232 ::StdMeshers_ProjectionSource2D* StdMeshers_ProjectionSource2D_i::GetImpl()
234 return ( ::StdMeshers_ProjectionSource2D* )myBaseImpl;
237 //================================================================================
239 * \brief Verify whether hypothesis supports given entity type
240 * \param type - dimension (see SMESH::Dimension enumeration)
241 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
243 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
245 //================================================================================
246 CORBA::Boolean StdMeshers_ProjectionSource2D_i::IsDimSupported( SMESH::Dimension type )
248 return type == SMESH::DIM_2D;
251 //================================================================================
253 * \brief Write parameters in a string
254 * \retval char* - resulting string
256 //================================================================================
258 char* StdMeshers_ProjectionSource2D_i::SaveTo()
260 ASSERT( myBaseImpl );
261 std::ostringstream os;
263 for ( int i = 0; i < NB_SHAPES; ++i )
264 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
265 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
267 myBaseImpl->SaveTo( os );
269 return CORBA::string_dup( os.str().c_str() );
272 //================================================================================
274 * \brief Retrieve parameters from the string
275 * \param theStream - the input string
277 //================================================================================
279 void StdMeshers_ProjectionSource2D_i::LoadFrom( const char* theStream )
281 ASSERT( myBaseImpl );
282 std::istringstream is( theStream );
284 TopoDS_Shape shapes[ NB_SHAPES ];
285 for ( int i = 0; i < NB_SHAPES; ++i )
286 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
287 SMESH::SMESH_Mesh_var mesh =
288 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
290 ::SMESH_Mesh* meshImpl = 0;
292 if ( !CORBA::is_nil( mesh ))
294 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
296 meshImpl = &mesh_i->GetImpl();
299 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
301 GetImpl()->SetSourceMesh ( meshImpl );
302 GetImpl()->SetSourceFace ( shapes[ SRC_FACE ] );
303 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
304 shapes[ SRC_VERTEX2 ],
305 shapes[ TGT_VERTEX1 ],
306 shapes[ TGT_VERTEX2 ]);
307 myBaseImpl->LoadFrom( is );
309 std::istringstream str( theStream );
310 for ( int i = 0; i < NB_SHAPES; ++i )
311 str >> myShapeEntries[ i ];