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