Salome HOME
Merge branch 'V8_2_BR' into pre/V8_2_BR
[modules/smesh.git] / src / StdMeshers_I / StdMeshers_ProjectionSource1D_i.cxx
1 // Copyright (C) 2007-2016  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, or (at your option) any later version.
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 //
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     CORBA::String_var entry = edge->GetStudyEntry();
87     myShapeEntries[ SRC_EDGE ] = entry.in();
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     myShapeEntries[ SRC_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( sourceVertex );
114     myShapeEntries[ TGT_VERTEX ] = StdMeshers_ObjRefUlils::GeomObjectToEntry( targetVertex );
115   }
116   catch ( SALOME_Exception& S_ex ) {
117     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
118   }
119   // Update Python script
120   SMESH::TPythonDump() << _this() << ".SetVertexAssociation( "
121                        << sourceVertex << ", " << targetVertex << " )";
122 }
123
124 //=============================================================================
125 /*!
126  * Sets source <mesh> to take a mesh pattern from
127  */
128 //=============================================================================
129
130 void StdMeshers_ProjectionSource1D_i::SetSourceMesh(SMESH::SMESH_Mesh_ptr theMesh)
131   throw ( SALOME::SALOME_Exception )
132 {
133   ASSERT( myBaseImpl );
134
135   ::SMESH_Mesh* mesh = 0;
136
137   if ( !CORBA::is_nil( theMesh ))
138   {
139     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( theMesh );
140     if ( !mesh_i )
141       THROW_SALOME_CORBA_EXCEPTION( "bad mesh", SALOME::BAD_PARAM );
142     mesh = &mesh_i->GetImpl();
143   }
144
145   try {
146     this->GetImpl()->SetSourceMesh ( mesh );
147   }
148   catch ( SALOME_Exception& S_ex ) {
149     THROW_SALOME_CORBA_EXCEPTION( S_ex.what(), SALOME::BAD_PARAM );
150   }
151
152   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( theMesh );
153
154   // Update Python script
155   SMESH::TPythonDump() << _this() << ".SetSourceMesh( " << theMesh << " )";
156 }
157
158 //=============================================================================
159 /*!
160  * Return source mesh
161  */
162 //=============================================================================
163
164 SMESH::SMESH_Mesh_ptr StdMeshers_ProjectionSource1D_i::GetSourceMesh()
165 {
166   SMESH::SMESH_Mesh_var mesh = myCorbaMesh;
167   return mesh._retn();
168 }
169
170 //=============================================================================
171 /*!
172  * Returns the source edge or a group containing edge
173  */
174 //=============================================================================
175
176 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceEdge()
177 {
178   ASSERT( myBaseImpl );
179   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
180     ( myShapeEntries[ SRC_EDGE ],
181       this->GetImpl()->GetSourceEdge() );
182 }
183
184 //=============================================================================
185 /*!
186  * Returns the vertex associated with the target vertex.
187  * Result may be nil if association not set
188  */
189 //=============================================================================
190
191 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetSourceVertex()
192 {
193   ASSERT( myBaseImpl );
194   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
195     ( myShapeEntries[ SRC_VERTEX ],
196       this->GetImpl()->GetSourceVertex() );
197 }
198
199 //=============================================================================
200 /*!
201  * Returns the vertex associated with the source vertex.
202  * Result may be nil if association not set
203  */
204 //=============================================================================
205
206 GEOM::GEOM_Object_ptr StdMeshers_ProjectionSource1D_i::GetTargetVertex()
207 {
208   ASSERT( myBaseImpl );
209   return StdMeshers_ObjRefUlils::EntryOrShapeToGeomObject
210     ( myShapeEntries[ TGT_VERTEX ],
211       this->GetImpl()->GetTargetVertex() );
212 }
213
214 //=============================================================================
215 /*!
216  *  StdMeshers_ProjectionSource1D_i::GetImpl
217  *
218  *  Get implementation
219  */
220 //=============================================================================
221
222 ::StdMeshers_ProjectionSource1D* StdMeshers_ProjectionSource1D_i::GetImpl()
223 {
224   return ( ::StdMeshers_ProjectionSource1D* )myBaseImpl;
225 }
226
227 //================================================================================
228 /*!
229  * \brief Verify whether hypothesis supports given entity type 
230   * \param type - dimension (see SMESH::Dimension enumeration)
231   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
232  * 
233  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
234  */
235 //================================================================================  
236 CORBA::Boolean StdMeshers_ProjectionSource1D_i::IsDimSupported( SMESH::Dimension type )
237 {
238   return type == SMESH::DIM_1D;
239 }
240
241 //================================================================================
242 /*!
243  * \brief Write parameters in a string
244   * \retval char* - resulting string
245  */
246 //================================================================================
247
248 char* StdMeshers_ProjectionSource1D_i::SaveTo()
249 {
250   ASSERT( myBaseImpl );
251   std::ostringstream os;
252
253   for ( int i = 0; i < NB_SHAPES; ++i )
254     StdMeshers_ObjRefUlils::SaveToStream( myShapeEntries[ i ], os );
255   StdMeshers_ObjRefUlils::SaveToStream( GetSourceMesh(), os );
256
257   myBaseImpl->SaveTo( os );
258
259   return CORBA::string_dup( os.str().c_str() );
260 }
261
262 //================================================================================
263 /*!
264  * \brief Retrieve parameters from the string
265   * \param theStream - the input string
266  */
267 //================================================================================
268
269 void StdMeshers_ProjectionSource1D_i::LoadFrom( const char* theStream )
270 {
271   ASSERT( myBaseImpl );
272   std::istringstream is( theStream );
273
274   TopoDS_Shape shapes[ NB_SHAPES ];
275   for ( int i = 0; i < NB_SHAPES; ++i )
276     shapes[ i ] = StdMeshers_ObjRefUlils::LoadFromStream( is );
277   SMESH::SMESH_Mesh_var mesh = 
278     StdMeshers_ObjRefUlils::LoadObjectFromStream< SMESH::SMESH_Mesh >( is );
279
280   ::SMESH_Mesh* meshImpl = 0;
281
282   if ( !CORBA::is_nil( mesh ))
283   {
284     SMESH_Mesh_i* mesh_i = SMESH::DownCast< SMESH_Mesh_i* >( mesh );
285     if ( mesh_i )
286       meshImpl = &mesh_i->GetImpl();
287   }
288
289   myCorbaMesh = SMESH::SMESH_Mesh::_duplicate( mesh );
290   try {
291     GetImpl()->SetSourceMesh       ( meshImpl );
292     GetImpl()->SetSourceEdge       ( shapes[ SRC_EDGE ] );
293     GetImpl()->SetVertexAssociation( shapes[ SRC_VERTEX ],
294                                      shapes[ TGT_VERTEX ]);
295   }
296   catch (...) {
297   }
298   myBaseImpl->LoadFrom( is );
299
300   std::istringstream str( theStream );
301   for ( int i = 0; i < NB_SHAPES; ++i )
302     str >> myShapeEntries[ i ];
303 }
304