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