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