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