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