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_ProjectionSource3D_i.cxx
25 // Author : Edward AGAPOV
28 #include "StdMeshers_ProjectionSource3D_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_ProjectionSource3D_i::StdMeshers_ProjectionSource3D_i
47 //=============================================================================
49 StdMeshers_ProjectionSource3D_i::StdMeshers_ProjectionSource3D_i
50 ( PortableServer::POA_ptr thePOA,
52 ::SMESH_Gen* theGenImpl ) : SALOME::GenericObj_i( thePOA ),
53 SMESH_Hypothesis_i( thePOA )
55 MESSAGE( "StdMeshers_ProjectionSource3D_i::StdMeshers_ProjectionSource3D_i" );
56 myBaseImpl = new ::StdMeshers_ProjectionSource3D( theGenImpl->GetANewId(),
61 //=============================================================================
63 * StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i
67 //=============================================================================
69 StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i()
71 MESSAGE( "StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i" );
74 //=============================================================================
76 * Sets a source <face> to take a mesh pattern from
78 //=============================================================================
80 void StdMeshers_ProjectionSource3D_i::SetSource3DShape(GEOM::GEOM_Object_ptr shape)
81 throw ( SALOME::SALOME_Exception )
85 this->GetImpl()->SetSource3DShape( StdMeshers_ObjRefUlils::GeomObjectToShape( shape ));
87 CORBA::String_var entry = shape->GetStudyEntry();
88 myShapeEntries[ SRC_SHAPE3D ] = entry.in();
90 catch ( SALOME_Exception& S_ex ) {
91 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
93 // Update Python script
94 SMESH::TPythonDump() << _this() << ".SetSource3DShape( " << shape << " )";
97 //=============================================================================
99 * Sets source <mesh> to take a mesh pattern from
101 //=============================================================================
103 void StdMeshers_ProjectionSource3D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
104 throw ( SALOME::SALOME_Exception )
106 ASSERT( myBaseImpl );
108 ::SMESH_Mesh* mesh = 0;
110 if ( !CORBA::is_nil( theMesh ))
112 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
114 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
115 mesh = &mesh_i->GetImpl();
119 this->GetImpl()->SetSourceMesh ( mesh );
121 catch ( SALOME_Exception& S_ex ) {
122 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
125 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
127 // Update Python script
128 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
131 //=============================================================================
135 //=============================================================================
137 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource3D_i::GetSourceMesh()
139 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
143 //=============================================================================
145 * Sets vertex association between the source shape and the target one.
146 * This parameter is optional.
147 * Two vertices must belong to one edge of a shape
149 //=============================================================================
151 void StdMeshers_ProjectionSource3D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
152 GEOM::GEOM_Object_ptr sourceVertex2,
153 GEOM::GEOM_Object_ptr targetVertex1,
154 GEOM::GEOM_Object_ptr targetVertex2)
155 throw ( SALOME::SALOME_Exception )
157 ASSERT( myBaseImpl );
159 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
160 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
161 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
162 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
163 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
165 CORBA::String_var entry;
166 entry = sourceVertex1->GetStudyEntry();
167 myShapeEntries[ SRC_VERTEX1 ] = entry.in();
168 entry = sourceVertex2->GetStudyEntry();
169 myShapeEntries[ SRC_VERTEX2 ] = entry.in();
170 entry = targetVertex1->GetStudyEntry();
171 myShapeEntries[ TGT_VERTEX1 ] = entry.in();
172 entry = targetVertex2->GetStudyEntry();
173 myShapeEntries[ TGT_VERTEX2 ] = entry.in();
175 catch ( SALOME_Exception& S_ex ) {
176 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
178 // Update Python script
179 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
180 << sourceVertex1 << ", "
181 << sourceVertex2 << ", "
182 << targetVertex1 << ", "
183 << targetVertex2 << " )";
186 //=============================================================================
188 * Returns the source face
190 //=============================================================================
192 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSource3DShape()
194 ASSERT( myBaseImpl );
195 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
196 ( myShapeEntries[ SRC_SHAPE3D ],
197 this->GetImpl()->GetSource3DShape() );
200 //=============================================================================
202 * Returns the vertex associated with the target vertex.
203 * Result may be nil if association not set
205 //=============================================================================
207 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSourceVertex(CORBA::Long i)
209 ASSERT( myBaseImpl );
210 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
211 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
212 this->GetImpl()->GetSourceVertex((int) i ));
215 //=============================================================================
217 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
218 * Result may be nil if association not set.
220 //=============================================================================
222 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetTargetVertex(CORBA::Long i)
224 ASSERT( myBaseImpl );
225 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
226 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
227 this->GetImpl()->GetTargetVertex( (int)i ));
230 //=============================================================================
232 * StdMeshers_ProjectionSource3D_i::GetImpl
236 //=============================================================================
238 ::StdMeshers_ProjectionSource3D* StdMeshers_ProjectionSource3D_i::GetImpl()
240 return ( ::StdMeshers_ProjectionSource3D* )myBaseImpl;
243 //================================================================================
245 * \brief Verify whether hypothesis supports given entity type
246 * \param type - dimension (see SMESH::Dimension enumeration)
247 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
249 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
251 //================================================================================
252 CORBA::Boolean StdMeshers_ProjectionSource3D_i::IsDimSupported( SMESH::Dimension type )
254 return type == SMESH::DIM_3D;
257 //================================================================================
259 * \brief Write parameters in a string
260 * \retval char* - resulting string
262 //================================================================================
264 char* StdMeshers_ProjectionSource3D_i::SaveTo()
266 ASSERT( myBaseImpl );
267 std::ostringstream os;
269 for ( int i = 0; i < NB_SHAPES; ++i )
270 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
271 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
273 myBaseImpl->SaveTo( os );
275 return CORBA::string_dup( os.str().c_str() );
278 //================================================================================
280 * \brief Retrieve parameters from the string
281 * \param theStream - the input string
283 //================================================================================
285 void StdMeshers_ProjectionSource3D_i::LoadFrom( const char* theStream )
287 ASSERT( myBaseImpl );
288 std::istringstream is( theStream );
290 TopoDS_Shape shapes[ NB_SHAPES ];
291 for ( int i = 0; i < NB_SHAPES; ++i )
292 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
293 SMESH::SMESH_Mesh_var mesh =
294 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
296 ::SMESH_Mesh* meshImpl = 0;
298 if ( !CORBA::is_nil( mesh ))
300 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
302 meshImpl = &mesh_i->GetImpl();
305 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
307 GetImpl()->SetSourceMesh ( meshImpl );
308 GetImpl()->SetSource3DShape ( shapes[ SRC_SHAPE3D ] );
309 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
310 shapes[ SRC_VERTEX2 ],
311 shapes[ TGT_VERTEX1 ],
312 shapes[ TGT_VERTEX2 ]);
314 myBaseImpl->LoadFrom( is );
316 std::istringstream str( theStream );
317 for ( int i = 0; i < NB_SHAPES; ++i )
318 str >> myShapeEntries[ i ];