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