Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ProjectionSource2D_i.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
23 //  File   : StdMeshers_ProjectionSource2D_i.cxx
24 //  Author : Edward AGAPOV
25 //  Module : SMESH
26 //  $Header$
27 //
28 #include "StdMeshers_ProjectionSource2D_i.hxx"
29
30 #include "SMESH_Gen_i.hxx"
31 #include "SMESH_Gen.hxx"
32 #include "SMESH_PythonDump.hxx"
33
34 #include "Utils_CorbaException.hxx"
35 #include "utilities.h"
36
37 #include "StdMeshers_ObjRefUlils.hxx"
38
39 using namespace std;
40
41 //=============================================================================
42 /*!
43  *  StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
44  *
45  *  Constructor
46  */
47 //=============================================================================
48
49 StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i
50 ( PortableServer::POA_ptr thePOA,
51   int                     theStudyId,
52   ::SMESH_Gen*            theGenImpl ) : SALOME::GenericObj_i( thePOA ), 
53                                          SMESH_Hypothesis_i( thePOA )
54 {
55   MESSAGE( "StdMeshers_ProjectionSource2D_i::StdMeshers_ProjectionSource2D_i" );
56   myBaseImpl = new ::StdMeshers_ProjectionSource2D( theGenImpl->GetANewId(),
57                                                     theStudyId,
58                                                     theGenImpl );
59 }
60
61 //=============================================================================
62 /*!
63  *  StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i
64  *
65  *  Destructor
66  */
67 //=============================================================================
68
69 StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i()
70 {
71   MESSAGE( "StdMeshers_ProjectionSource2D_i::~StdMeshers_ProjectionSource2D_i" );
72 }
73
74 //=============================================================================
75   /*!
76    * Sets a source <face> to take a mesh pattern from
77    */
78 //=============================================================================
79
80 void StdMeshers_ProjectionSource2D_i::SetSourceFace(GEOM::GEOM_Object_ptr face)
81   throw ( SALOME::SALOME_Exception )
82 {
83   ASSERT( myBaseImpl );
84   try {
85     this->GetImpl()->SetSourceFace( StdMeshers_ObjRefUlils::GeomObjectToShape( face ));
86   }
87   catch ( SALOME_Exception& S_ex ) {
88     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
89   }
90   // Update Python script
91   SMESH::TPythonDump() << _this() << ".SetSourceFace( " << face << " )";
92 }
93
94 //=============================================================================
95 /*!
96  * Sets source <mesh> to take a mesh pattern from
97  */
98 //=============================================================================
99
100 void StdMeshers_ProjectionSource2D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
101   throw ( SALOME::SALOME_Exception )
102 {
103   ASSERT( myBaseImpl );
104
105   ::SMESH_Mesh* mesh = 0;
106
107   if ( !CORBA::is_nil( theMesh ))
108   {
109     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
110     if ( !mesh_i )
111       THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
112     mesh = &mesh_i->GetImpl();
113   }
114
115   try {
116     this->GetImpl()->SetSourceMesh ( mesh );
117   }
118   catch ( SALOME_Exception& S_ex ) {
119     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
120   }
121
122   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
123
124   // Update Python script
125   SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
126 }
127
128 //=============================================================================
129 /*!
130  * Return source mesh
131  */
132 //=============================================================================
133
134 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource2D_i::GetSourceMesh()
135 {
136   SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
137   return mesh._retn();
138 }
139
140 //=============================================================================
141 /*!
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
145  */
146 //=============================================================================
147
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 )
153 {
154   ASSERT( myBaseImpl );
155   try {
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 );
161   }
162   catch ( SALOME_Exception& S_ex ) {
163     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
164   }
165   // Update Python script
166   SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
167                        << sourceVertex1 << ", "
168                        << sourceVertex2 << ", "
169                        << targetVertex1 << ", "
170                        << targetVertex2 << " )";
171 }
172
173 //=============================================================================
174 /*!
175  * Returns the source face
176  */
177 //=============================================================================
178
179 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceFace()
180 {
181   ASSERT( myBaseImpl );
182   return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceFace() );
183 }
184
185 //=============================================================================
186 /*!
187  * Returns the vertex associated with the target vertex.
188  * Result may be nil if association not set
189  */
190 //=============================================================================
191
192 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetSourceVertex(CORBA::Long i)
193 {
194   ASSERT( myBaseImpl );
195   return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetSourceVertex((int) i ));
196 }
197
198 //=============================================================================
199 /*!
200  * Returns the <i>-th target vertex associated with the <i>-th source vertex.
201  * Result may be nil if association not set.
202  */
203 //=============================================================================
204
205 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource2D_i::GetTargetVertex(CORBA::Long i)
206 {
207   ASSERT( myBaseImpl );
208   return StdMeshers_ObjRefUlils::ShapeToGeomObject( this->GetImpl()->GetTargetVertex( (int)i ));
209 }
210
211 //=============================================================================
212 /*!
213  *  StdMeshers_ProjectionSource2D_i::GetImpl
214  *
215  *  Get implementation
216  */
217 //=============================================================================
218
219 ::StdMeshers_ProjectionSource2D* StdMeshers_ProjectionSource2D_i::GetImpl()
220 {
221   return ( ::StdMeshers_ProjectionSource2D* )myBaseImpl;
222 }
223
224 //================================================================================
225 /*!
226  * \brief Verify whether hypothesis supports given entity type 
227   * \param type - dimension (see SMESH::Dimension enumeration)
228   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
229  * 
230  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
231  */
232 //================================================================================  
233 CORBA::Boolean StdMeshers_ProjectionSource2D_i::IsDimSupported( SMESH::Dimension type )
234 {
235   return type == SMESH::DIM_2D;
236 }
237
238 //================================================================================
239 /*!
240  * \brief Write parameters in a string
241   * \retval char* - resulting string
242  */
243 //================================================================================
244
245 char* StdMeshers_ProjectionSource2D_i::SaveTo()
246 {
247   ASSERT( myBaseImpl );
248   std::ostringstream os;
249
250   TopoDS_Shape s1, s2, s3, s4, s5;
251   GetImpl()->GetStoreParams( s1, s2, s3, s4, s5 );
252
253   StdMeshers_ObjRefUlils::SaveToStream( s1, os );
254   StdMeshers_ObjRefUlils::SaveToStream( s2, os );
255   StdMeshers_ObjRefUlils::SaveToStream( s3, os );
256   StdMeshers_ObjRefUlils::SaveToStream( s4, os );
257   StdMeshers_ObjRefUlils::SaveToStream( s5, os );
258   StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
259
260   myBaseImpl->SaveTo( os );
261
262   return CORBA::string_dup( os.str().c_str() );
263 }
264
265 //================================================================================
266 /*!
267  * \brief Retrieve parameters from the string
268   * \param theStream - the input string
269  */
270 //================================================================================
271
272 void StdMeshers_ProjectionSource2D_i::LoadFrom( const char* theStream )
273 {
274   ASSERT( myBaseImpl );
275   std::istringstream is( theStream );
276
277   TopoDS_Shape s1 = StdMeshers_ObjRefUlils::LoadFromStream( is );
278   TopoDS_Shape s2 = StdMeshers_ObjRefUlils::LoadFromStream( is );
279   TopoDS_Shape s3 = StdMeshers_ObjRefUlils::LoadFromStream( is );
280   TopoDS_Shape s4 = StdMeshers_ObjRefUlils::LoadFromStream( is );
281   TopoDS_Shape s5 = StdMeshers_ObjRefUlils::LoadFromStream( is );
282   SMESH::SMESH_Mesh_var mesh = 
283     StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
284
285   ::SMESH_Mesh* meshImpl = 0;
286
287   if ( !CORBA::is_nil( mesh ))
288   {
289     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
290     if ( mesh_i )
291       meshImpl = &mesh_i->GetImpl();
292   }
293
294   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
295   GetImpl()->RestoreParams( s1, s2, s3, s4, s5, meshImpl );
296
297   myBaseImpl->LoadFrom( is );
298 }
299