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_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 myBaseImpl = new ::StdMeshers_ProjectionSource2D( theGenImpl->GetANewId(),
60 //=============================================================================
62 * StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i
66 //=============================================================================
68 StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i()
72 //=============================================================================
74 * Sets a source <face> to take a mesh pattern from
76 //=============================================================================
78 void StdMeshers_ProjectionSource2D_i::SetSourceFace(GEOM::GEOM_Object_ptr face)
79 throw ( SALOME::SALOME_Exception )
83 this->GetImpl()->SetSourceFace( StdMeshers_ObjRefUlils::GeomObjectToShape( face ));
84 CORBA::String_var entry = face->GetStudyEntry();
85 myShapeEntries[ SRC_FACE ] = 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() << ".SetSourceFace( " << face << " )";
94 //=============================================================================
96 * Sets source <mesh> to take a mesh pattern from
98 //=============================================================================
100 void StdMeshers_ProjectionSource2D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
101 throw ( SALOME::SALOME_Exception )
103 ASSERT( myBaseImpl );
105 ::SMESH_Mesh* mesh = 0;
107 if ( !CORBA::is_nil( theMesh ))
109 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
111 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
112 mesh = &mesh_i->GetImpl();
116 this->GetImpl()->SetSourceMesh ( mesh );
118 catch ( SALOME_Exception& S_ex ) {
119 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
122 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
124 // Update Python script
125 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
128 //=============================================================================
132 //=============================================================================
134 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource2D_i::GetSourceMesh()
136 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
140 //=============================================================================
142 * Sets vertex association between the source face and the target one.
143 * This parameter is optional.
144 * Two vertices must belong to one edge of a face
146 //=============================================================================
148 void StdMeshers_ProjectionSource2D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
149 GEOM::GEOM_Object_ptr sourceVertex2,
150 GEOM::GEOM_Object_ptr targetVertex1,
151 GEOM::GEOM_Object_ptr targetVertex2)
152 throw ( SALOME::SALOME_Exception )
154 ASSERT( myBaseImpl );
156 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
157 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
158 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
159 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
160 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
162 myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
163 myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
164 myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
165 myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
167 catch ( SALOME_Exception& S_ex ) {
168 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
170 // Update Python script
171 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
172 << sourceVertex1 << ", "
173 << sourceVertex2 << ", "
174 << targetVertex1 << ", "
175 << targetVertex2 << " )";
178 //=============================================================================
180 * Returns the source face
182 //=============================================================================
184 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceFace()
186 ASSERT( myBaseImpl );
187 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
188 ( myShapeEntries[ SRC_FACE ],
189 this->GetImpl()->GetSourceFace() );
192 //=============================================================================
194 * Returns the vertex associated with the target vertex.
195 * Result may be nil if association not set
197 //=============================================================================
199 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceVertex(CORBA::Long i)
201 ASSERT( myBaseImpl );
202 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
203 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
204 this->GetImpl()->GetSourceVertex((int) i ));
207 //=============================================================================
209 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
210 * Result may be nil if association not set.
212 //=============================================================================
214 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetTargetVertex(CORBA::Long i)
216 ASSERT( myBaseImpl );
217 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
218 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
219 this->GetImpl()->GetTargetVertex( (int)i ));
222 //=============================================================================
224 * StdMeshers_ProjectionSource2D_i::GetImpl
228 //=============================================================================
230 ::StdMeshers_ProjectionSource2D* StdMeshers_ProjectionSource2D_i::GetImpl()
232 return ( ::StdMeshers_ProjectionSource2D* )myBaseImpl;
235 //================================================================================
237 * \brief Verify whether hypothesis supports given entity type
238 * \param type - dimension (see SMESH::Dimension enumeration)
239 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
241 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
243 //================================================================================
244 CORBA::Boolean StdMeshers_ProjectionSource2D_i::IsDimSupported( SMESH::Dimension type )
246 return type == SMESH::DIM_2D;
249 //================================================================================
251 * \brief Write parameters in a string
252 * \retval char* - resulting string
254 //================================================================================
256 char* StdMeshers_ProjectionSource2D_i::SaveTo()
258 ASSERT( myBaseImpl );
259 std::ostringstream os;
261 for ( int i = 0; i < NB_SHAPES; ++i )
262 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
263 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
265 myBaseImpl->SaveTo( os );
267 return CORBA::string_dup( os.str().c_str() );
270 //================================================================================
272 * \brief Retrieve parameters from the string
273 * \param theStream - the input string
275 //================================================================================
277 void StdMeshers_ProjectionSource2D_i::LoadFrom( const char* theStream )
279 ASSERT( myBaseImpl );
280 std::istringstream is( theStream );
282 TopoDS_Shape shapes[ NB_SHAPES ];
283 for ( int i = 0; i < NB_SHAPES; ++i )
284 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
285 SMESH::SMESH_Mesh_var mesh =
286 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
288 ::SMESH_Mesh* meshImpl = 0;
290 if ( !CORBA::is_nil( mesh ))
292 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
294 meshImpl = &mesh_i->GetImpl();
297 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
300 GetImpl()->SetSourceMesh ( meshImpl );
301 GetImpl()->SetSourceFace ( shapes[ SRC_FACE ] );
302 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
303 shapes[ SRC_VERTEX2 ],
304 shapes[ TGT_VERTEX1 ],
305 shapes[ TGT_VERTEX2 ]);
309 myBaseImpl->LoadFrom( is );
311 std::istringstream str( theStream );
312 for ( int i = 0; i < NB_SHAPES; ++i )
313 str >> myShapeEntries[ i ];