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_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 myBaseImpl = new ::StdMeshers_ProjectionSource3D( theGenImpl->GetANewId(),
60 //=============================================================================
62 * StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i
66 //=============================================================================
68 StdMeshers_ProjectionSource3D_i::~StdMeshers_ProjectionSource3D_i()
72 //=============================================================================
74 * Sets a source <face> to take a mesh pattern from
76 //=============================================================================
78 void StdMeshers_ProjectionSource3D_i::SetSource3DShape(GEOM::GEOM_Object_ptr shape)
79 throw ( SALOME::SALOME_Exception )
83 this->GetImpl()->SetSource3DShape( StdMeshers_ObjRefUlils::GeomObjectToShape( shape ));
85 CORBA::String_var entry = shape->GetStudyEntry();
86 myShapeEntries[ SRC_SHAPE3D ] = entry.in();
88 catch ( SALOME_Exception& S_ex ) {
89 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
91 // Update Python script
92 SMESH::TPythonDump() << _this() << ".SetSource3DShape( " << shape << " )";
95 //=============================================================================
97 * Sets source <mesh> to take a mesh pattern from
99 //=============================================================================
101 void StdMeshers_ProjectionSource3D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
102 throw ( SALOME::SALOME_Exception )
104 ASSERT( myBaseImpl );
106 ::SMESH_Mesh* mesh = 0;
108 if ( !CORBA::is_nil( theMesh ))
110 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
112 THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
113 mesh = &mesh_i->GetImpl();
117 this->GetImpl()->SetSourceMesh ( mesh );
119 catch ( SALOME_Exception& S_ex ) {
120 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
123 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
125 // Update Python script
126 SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
129 //=============================================================================
133 //=============================================================================
135 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource3D_i::GetSourceMesh()
137 SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
141 //=============================================================================
143 * Sets vertex association between the source shape and the target one.
144 * This parameter is optional.
145 * Two vertices must belong to one edge of a shape
147 //=============================================================================
149 void StdMeshers_ProjectionSource3D_i::SetVertexAssociation(GEOM::GEOM_Object_ptr sourceVertex1,
150 GEOM::GEOM_Object_ptr sourceVertex2,
151 GEOM::GEOM_Object_ptr targetVertex1,
152 GEOM::GEOM_Object_ptr targetVertex2)
153 throw ( SALOME::SALOME_Exception )
155 ASSERT( myBaseImpl );
157 TopoDS_Shape v1 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex1 );
158 TopoDS_Shape v2 = StdMeshers_ObjRefUlils::GeomObjectToShape( sourceVertex2 );
159 TopoDS_Shape v3 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex1 );
160 TopoDS_Shape v4 = StdMeshers_ObjRefUlils::GeomObjectToShape( targetVertex2 );
161 this->GetImpl()->SetVertexAssociation( v1, v2, v3, v4 );
163 myShapeEntries[ SRC_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex1 );
164 myShapeEntries[ SRC_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex2 );
165 myShapeEntries[ TGT_VERTEX1 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex1 );
166 myShapeEntries[ TGT_VERTEX2 ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex2 );
168 catch ( SALOME_Exception& S_ex ) {
169 THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
171 // Update Python script
172 SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
173 << sourceVertex1 << ", "
174 << sourceVertex2 << ", "
175 << targetVertex1 << ", "
176 << targetVertex2 << " )";
179 //=============================================================================
181 * Returns the source face
183 //=============================================================================
185 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSource3DShape()
187 ASSERT( myBaseImpl );
188 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
189 ( myShapeEntries[ SRC_SHAPE3D ],
190 this->GetImpl()->GetSource3DShape() );
193 //=============================================================================
195 * Returns the vertex associated with the target vertex.
196 * Result may be nil if association not set
198 //=============================================================================
200 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetSourceVertex(CORBA::Long i)
202 ASSERT( myBaseImpl );
203 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
204 ( myShapeEntries[ i == 1 ? SRC_VERTEX1 : SRC_VERTEX2 ],
205 this->GetImpl()->GetSourceVertex((int) i ));
208 //=============================================================================
210 * Returns the <i>-th target vertex associated with the <i>-th source vertex.
211 * Result may be nil if association not set.
213 //=============================================================================
215 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource3D_i::GetTargetVertex(CORBA::Long i)
217 ASSERT( myBaseImpl );
218 return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
219 ( myShapeEntries[ i == 1 ? TGT_VERTEX1 : TGT_VERTEX2 ],
220 this->GetImpl()->GetTargetVertex( (int)i ));
223 //=============================================================================
225 * StdMeshers_ProjectionSource3D_i::GetImpl
229 //=============================================================================
231 ::StdMeshers_ProjectionSource3D* StdMeshers_ProjectionSource3D_i::GetImpl()
233 return ( ::StdMeshers_ProjectionSource3D* )myBaseImpl;
236 //================================================================================
238 * \brief Verify whether hypothesis supports given entity type
239 * \param type - dimension (see SMESH::Dimension enumeration)
240 * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
242 * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
244 //================================================================================
245 CORBA::Boolean StdMeshers_ProjectionSource3D_i::IsDimSupported( SMESH::Dimension type )
247 return type == SMESH::DIM_3D;
250 //================================================================================
252 * \brief Write parameters in a string
253 * \retval char* - resulting string
255 //================================================================================
257 char* StdMeshers_ProjectionSource3D_i::SaveTo()
259 ASSERT( myBaseImpl );
260 std::ostringstream os;
262 for ( int i = 0; i < NB_SHAPES; ++i )
263 StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
264 StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
266 myBaseImpl->SaveTo( os );
268 return CORBA::string_dup( os.str().c_str() );
271 //================================================================================
273 * \brief Retrieve parameters from the string
274 * \param theStream - the input string
276 //================================================================================
278 void StdMeshers_ProjectionSource3D_i::LoadFrom( const char* theStream )
280 ASSERT( myBaseImpl );
281 std::istringstream is( theStream );
283 TopoDS_Shape shapes[ NB_SHAPES ];
284 for ( int i = 0; i < NB_SHAPES; ++i )
285 shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
286 SMESH::SMESH_Mesh_var mesh =
287 StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
289 ::SMESH_Mesh* meshImpl = 0;
291 if ( !CORBA::is_nil( mesh ))
293 SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
295 meshImpl = &mesh_i->GetImpl();
298 myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
301 GetImpl()->SetSourceMesh ( meshImpl );
302 GetImpl()->SetSource3DShape ( shapes[ SRC_SHAPE3D ] );
303 GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX1 ],
304 shapes[ SRC_VERTEX2 ],
305 shapes[ TGT_VERTEX1 ],
306 shapes[ TGT_VERTEX2 ]);
310 myBaseImpl->LoadFrom( is );
312 std::istringstream str( theStream );
313 for ( int i = 0; i < NB_SHAPES; ++i )
314 str >> myShapeEntries[ i ];