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