Salome HOME
Merging with WPdev
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionSource2D.cxx
1 //  SMESH SMESH : idl implementation based on 'SMESH' unit's classes
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : StdMeshers_ProjectionSource2D.cxx
25 //  Author : Edward AGAPOV
26 //  Module : SMESH
27 //  $Header$
28
29
30 #include "StdMeshers_ProjectionSource2D.hxx"
31
32 #include "SMESH_Mesh.hxx"
33
34 #include "utilities.h"
35
36 #include <TopoDS.hxx>
37
38 using namespace std;
39
40 //=============================================================================
41 /*!
42  *  StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D
43  *
44  *  Constructor
45  */
46 //=============================================================================
47
48 StdMeshers_ProjectionSource2D::StdMeshers_ProjectionSource2D(int hypId, int studyId,
49                                                              SMESH_Gen * gen)
50   : SMESH_Hypothesis(hypId, studyId, gen)
51 {
52   _name = "ProjectionSource2D"; // used by Projection_2D
53   _param_algo_dim = 2; // 2D
54   _sourceMesh = 0;
55 }
56
57 //=============================================================================
58 /*!
59  *  StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D
60  *
61  *  Destructor
62  */
63 //=============================================================================
64
65 StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D()
66 {
67   MESSAGE( "StdMeshers_ProjectionSource2D::~StdMeshers_ProjectionSource2D" );
68 }
69
70 //=============================================================================
71   /*!
72    * Sets a source <face> to take a mesh pattern from
73    */
74 //=============================================================================
75
76 void StdMeshers_ProjectionSource2D::SetSourceFace(const TopoDS_Shape& Face)
77   throw ( SALOME_Exception )
78 {
79   if ( Face.IsNull() )
80     throw SALOME_Exception(LOCALIZED("Null Face is not allowed"));
81
82   if ( Face.ShapeType() != TopAbs_FACE )
83     throw SALOME_Exception(LOCALIZED("Wrong shape type"));
84
85   if ( !_sourceFace.IsSame( Face ) )
86   {
87     _sourceFace = TopoDS::Face( Face );
88
89     NotifySubMeshesHypothesisModification();
90   }
91 }
92
93 //=============================================================================
94 /*!
95  * Sets vertex association between the source face and the target one.
96  * This parameter is optional.
97  * Two vertices must belong to one edge of a face
98  */
99 //=============================================================================
100
101 void StdMeshers_ProjectionSource2D::SetVertexAssociation(const TopoDS_Shape& sourceVertex1,
102                                                          const TopoDS_Shape& sourceVertex2,
103                                                          const TopoDS_Shape& targetVertex1,
104                                                          const TopoDS_Shape& targetVertex2)
105   throw ( SALOME_Exception )
106 {
107   if ( sourceVertex1.IsNull() != targetVertex1.IsNull() ||
108        sourceVertex2.IsNull() != targetVertex2.IsNull() ||
109        sourceVertex1.IsNull() != targetVertex2.IsNull() )
110     throw SALOME_Exception(LOCALIZED("Two or none pairs of vertices must be provided"));
111
112   if ( !sourceVertex1.IsNull() ) {
113     if ( sourceVertex1.ShapeType() != TopAbs_VERTEX ||
114          sourceVertex2.ShapeType() != TopAbs_VERTEX ||
115          targetVertex1.ShapeType() != TopAbs_VERTEX ||
116          targetVertex2.ShapeType() != TopAbs_VERTEX )
117       throw SALOME_Exception(LOCALIZED("Wrong shape type"));
118   }
119
120   if ( !_sourceVertex1.IsSame( sourceVertex1 ) ||
121        !_sourceVertex2.IsSame( sourceVertex2 ) ||
122        !_targetVertex1.IsSame( targetVertex1 ) ||
123        !_targetVertex2.IsSame( targetVertex2 ) )
124   {
125     _sourceVertex1 = TopoDS::Vertex( sourceVertex1 );
126     _sourceVertex2 = TopoDS::Vertex( sourceVertex2 );
127     _targetVertex1 = TopoDS::Vertex( targetVertex1 );
128     _targetVertex2 = TopoDS::Vertex( targetVertex2 );
129
130     NotifySubMeshesHypothesisModification();
131   }
132 }
133
134 //=============================================================================
135 /*!
136  * Sets source <mesh> to take a mesh pattern from
137  */
138 //=============================================================================
139
140 void StdMeshers_ProjectionSource2D::SetSourceMesh(SMESH_Mesh* mesh)
141 {
142   if ( _sourceMesh != mesh )
143     NotifySubMeshesHypothesisModification();
144   _sourceMesh = mesh;
145 }
146
147 //=============================================================================
148 /*!
149  * Returns the source face
150  */
151 //=============================================================================
152
153 TopoDS_Face StdMeshers_ProjectionSource2D::GetSourceFace() const
154 {
155   return _sourceFace;
156 }
157
158 //=============================================================================
159 /*!
160  * Returns the vertex associated with the target vertex.
161  * Result may be nil if association not set
162  */
163 //=============================================================================
164
165 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetSourceVertex(int i) const
166   throw ( SALOME_Exception )
167 {
168   if ( i == 1 )
169     return _sourceVertex1;
170   else if ( i == 2 )
171     return _sourceVertex2;
172   else
173     throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
174 }
175
176 //=============================================================================
177 /*!
178  * Returns the <i>-th target vertex associated with the <i>-th source vertex.
179  * Result may be nil if association not set.
180  */
181 //=============================================================================
182
183 TopoDS_Vertex StdMeshers_ProjectionSource2D::GetTargetVertex(int i) const
184   throw ( SALOME_Exception )
185 {
186   if ( i == 1 )
187     return _targetVertex1;
188   else if ( i == 2 )
189     return _targetVertex2;
190   else
191     throw SALOME_Exception(LOCALIZED("Wrong vertex index"));
192 }
193
194 //=============================================================================
195 /*!
196  *  
197  */
198 //=============================================================================
199
200 ostream & StdMeshers_ProjectionSource2D::SaveTo(ostream & save)
201 {
202   // we store it in order to be able to detect that hypo is really modified
203   save << " " << _sourceFace.TShape().operator->()  ;
204   save << " " << _sourceVertex1.TShape().operator->();
205   save << " " << _targetVertex1.TShape().operator->();
206   save << " " << _sourceVertex2.TShape().operator->();
207   save << " " << _targetVertex2.TShape().operator->();
208   save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
209   return save;
210 }
211
212 //=============================================================================
213 /*!
214  *  
215  */
216 //=============================================================================
217
218 istream & StdMeshers_ProjectionSource2D::LoadFrom(istream & load)
219 {
220   // impossible to restore w/o any context
221   // It is done by servant
222   return load;
223 }
224
225 //=============================================================================
226 /*!
227  *  
228  */
229 //=============================================================================
230
231 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource2D & hyp)
232 {
233   return hyp.SaveTo( save );
234 }
235
236 //=============================================================================
237 /*!
238  *  
239  */
240 //=============================================================================
241
242 istream & operator >>(istream & load, StdMeshers_ProjectionSource2D & hyp)
243 {
244   return hyp.LoadFrom( load );
245 }
246
247 //================================================================================
248 /*!
249  * \brief Initialize start and end length by the mesh built on the geometry
250  * \param theMesh - the built mesh
251  * \param theShape - the geometry of interest
252  * \retval bool - true if parameter values have been successfully defined
253  */
254 //================================================================================
255
256 bool StdMeshers_ProjectionSource2D::SetParametersByMesh(const SMESH_Mesh*   ,
257                                                         const TopoDS_Shape& )
258 {
259   return false;
260 }
261
262 //================================================================================
263 /*!
264  * \brief Return all parameters
265  */
266 //================================================================================
267
268 void StdMeshers_ProjectionSource2D::GetStoreParams(TopoDS_Shape& s1,
269                                                    TopoDS_Shape& s2,
270                                                    TopoDS_Shape& s3,
271                                                    TopoDS_Shape& s4,
272                                                    TopoDS_Shape& s5) const
273 {
274   s1 = _sourceFace;
275   s2 = _sourceVertex1;
276   s3 = _sourceVertex2;
277   s4 = _targetVertex1;
278   s5 = _targetVertex2;
279 }
280
281 //================================================================================
282 /*!
283  * \brief Set all parameters without notifying on modification
284  */
285 //================================================================================
286
287 void StdMeshers_ProjectionSource2D::RestoreParams(const TopoDS_Shape& s1,
288                                                   const TopoDS_Shape& s2,
289                                                   const TopoDS_Shape& s3,
290                                                   const TopoDS_Shape& s4,
291                                                   const TopoDS_Shape& s5,
292                                                   SMESH_Mesh*         mesh)
293 {
294   _sourceFace    = TopoDS::Face( s1 );
295   _sourceVertex1 = TopoDS::Vertex( s2 );
296   _sourceVertex2 = TopoDS::Vertex( s3 );
297   _targetVertex1 = TopoDS::Vertex( s4 );
298   _targetVertex2 = TopoDS::Vertex( s5 );
299   _sourceMesh   = mesh;
300 }