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