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