Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionSource1D.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_ProjectionSource1D.cxx
24 //  Author : Edward AGAPOV
25 //  Module : SMESH
26 //
27 #include "StdMeshers_ProjectionSource1D.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 /*!
40  *  StdMeshers_ProjectionSource1D::StdMeshers_ProjectionSource1D
41  *
42  *  Constructor
43  */
44 //=============================================================================
45
46 StdMeshers_ProjectionSource1D::StdMeshers_ProjectionSource1D(int hypId, int studyId,
47                                                              SMESH_Gen * gen)
48   : SMESH_Hypothesis(hypId, studyId, gen)
49 {
50   _name = "ProjectionSource1D"; // used by Projection_1D
51   _param_algo_dim = 1; // 1D
52   _sourceMesh = 0;
53 }
54
55 //=============================================================================
56 /*!
57  *  StdMeshers_ProjectionSource1D::~StdMeshers_ProjectionSource1D
58  *
59  *  Destructor
60  */
61 //=============================================================================
62
63 StdMeshers_ProjectionSource1D::~StdMeshers_ProjectionSource1D()
64 {
65   MESSAGE( "StdMeshers_ProjectionSource1D::~StdMeshers_ProjectionSource1D" );
66 }
67
68 //=============================================================================
69   /*!
70    * Sets source <edge> to take a mesh pattern from
71    */
72 //=============================================================================
73
74 void StdMeshers_ProjectionSource1D::SetSourceEdge(const TopoDS_Shape& edge)
75   throw ( SALOME_Exception )
76 {
77   if ( edge.IsNull() )
78     throw SALOME_Exception(LOCALIZED("Null edge is not allowed"));
79
80   if ( edge.ShapeType() != TopAbs_EDGE && edge.ShapeType() != TopAbs_COMPOUND )
81     throw SALOME_Exception(LOCALIZED("Wrong shape type"));
82
83   if ( !_sourceEdge.IsSame( edge ) )
84   {
85     _sourceEdge = edge;
86
87     NotifySubMeshesHypothesisModification();
88   }
89 }
90
91 //=============================================================================
92 /*!
93  * Sets vertex association between the source edge and the target one.
94  * This parameter is optional
95  */
96 //=============================================================================
97
98 void StdMeshers_ProjectionSource1D::SetVertexAssociation(const TopoDS_Shape& sourceVertex,
99                                                          const TopoDS_Shape& targetVertex)
100   throw ( SALOME_Exception )
101 {
102   if ( sourceVertex.IsNull() != targetVertex.IsNull() )
103     throw SALOME_Exception(LOCALIZED("Two or none vertices must be provided"));
104
105   if ( !sourceVertex.IsNull() ) {
106     if ( sourceVertex.ShapeType() != TopAbs_VERTEX ||
107          targetVertex.ShapeType() != TopAbs_VERTEX )
108       throw SALOME_Exception(LOCALIZED("Wrong shape type"));
109   }
110
111   if ( !_sourceVertex.IsSame( sourceVertex ) ||
112        !_targetVertex.IsSame( targetVertex ) )
113   {
114     _sourceVertex = TopoDS::Vertex( sourceVertex );
115     _targetVertex = TopoDS::Vertex( targetVertex );
116
117     NotifySubMeshesHypothesisModification();
118   }
119 }
120
121 //=============================================================================
122 /*!
123  * Sets source <mesh> to take a mesh pattern from
124  */
125 //=============================================================================
126
127 void StdMeshers_ProjectionSource1D::SetSourceMesh(SMESH_Mesh* mesh)
128 {
129   if ( _sourceMesh != mesh )
130     NotifySubMeshesHypothesisModification();
131   _sourceMesh = mesh;
132 }
133
134 //=============================================================================
135 /*!
136  *  
137  */
138 //=============================================================================
139
140 ostream & StdMeshers_ProjectionSource1D::SaveTo(ostream & save)
141 {
142   // we store it in order to be able to detect that hypo is really modified
143   save << " " << _sourceEdge.TShape().operator->()  ;
144   save << " " << _sourceVertex.TShape().operator->();
145   save << " " << _targetVertex.TShape().operator->();
146   save << " " << ( _sourceMesh ? _sourceMesh->GetId() : -1 );
147   return save;
148 }
149
150 //=============================================================================
151 /*!
152  *  
153  */
154 //=============================================================================
155
156 istream & StdMeshers_ProjectionSource1D::LoadFrom(istream & load)
157 {
158   // impossible to restore w/o any context
159   return load;
160 }
161
162 //=============================================================================
163 /*!
164  *  
165  */
166 //=============================================================================
167
168 ostream & operator <<(ostream & save, StdMeshers_ProjectionSource1D & hyp)
169 {
170   return hyp.SaveTo( save );
171 }
172
173 //=============================================================================
174 /*!
175  *  
176  */
177 //=============================================================================
178
179 istream & operator >>(istream & load, StdMeshers_ProjectionSource1D & hyp)
180 {
181   return hyp.LoadFrom( load );
182 }
183
184 //================================================================================
185 /*!
186  * \brief Initialize start and end length by the mesh built on the geometry
187  * \param theMesh - the built mesh
188  * \param theShape - the geometry of interest
189  * \retval bool - true if parameter values have been successfully defined
190  */
191 //================================================================================
192
193 bool StdMeshers_ProjectionSource1D::SetParametersByMesh(const SMESH_Mesh*   ,
194                                                         const TopoDS_Shape& )
195 {
196   return false;
197 }
198
199 //================================================================================
200 /*!
201  * \brief Return all parameters
202  */
203 //================================================================================
204
205 void StdMeshers_ProjectionSource1D::GetStoreParams(TopoDS_Shape& s1,
206                                                    TopoDS_Shape& s2,
207                                                    TopoDS_Shape& s3) const
208 {
209   s1 = _sourceEdge;
210   s2 = _sourceVertex;
211   s3 = _targetVertex;
212 }
213
214 //================================================================================
215 /*!
216  * \brief Set all parameters without notifying on modification
217  */
218 //================================================================================
219
220 void StdMeshers_ProjectionSource1D::RestoreParams(const TopoDS_Shape& s1,
221                                                   const TopoDS_Shape& s2,
222                                                   const TopoDS_Shape& s3,
223                                                   SMESH_Mesh*         mesh)
224 {
225   _sourceEdge   = s1;
226   _sourceVertex = TopoDS::Vertex( s2 );
227   _targetVertex = TopoDS::Vertex( s3 );
228   _sourceMesh   = mesh;
229 }
230
231 //================================================================================
232 /*!
233  * \brief Initialize my parameter values by default parameters.
234  *  \retval bool - true if parameter values have been successfully defined
235  */
236 //================================================================================
237
238 bool StdMeshers_ProjectionSource1D::SetParametersByDefaults(const TDefaults&  /*dflts*/,
239                                                             const SMESH_Mesh* /*theMesh*/)
240 {
241   return false;
242 }
243