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